Skip to content

Higher than 1-D arrays in dot #468

Open

Description

@jakirkham

Trying to use dot from pygpu with OpenCL. However it seems to throw an error due to the lack of collective operations. Am able to work around this using BLAS functions (e.g. gemm). After looking around in the code was able to find the error and the C function involved, but not exactly how we got to it.

Have a few questions. How are collective operations involved here (higher dimensions?)? Would it make sense to special case some ranks of arrays to avoid collective operations and go straight to BLAS operations? If I'm misunderstanding things here, please feel free to correct me.

Details
In [1]: import pygpu

In [2]: import pygpu.blas

In [3]: import numpy

In [4]: import numpy as np

In [5]: c = pygpu.init("opencl0:1")

In [6]: a = pygpu.gpuarray.zeros((10, 11), dtype=np.float32, context=c, cls=pygpu.ndgpuarray)

In [7]: pygpu.blas.gemm(1, a, a.T, 0)
OpenCL Build Warning : Compiler build log:
<program source>:101:54: warning: double precision constant requires cl_khr_fp64, casting to single precision
      lA[ 0*localAStride ] = ( globalARow(0) >= M) ? 0.0 : A[ GET_GLOBAL_INDEX_A( globalARow(0), globalACol(0) ) ];
                                                     ^
<program source>:104:53: warning: double precision constant requires cl_khr_fp64, casting to single precision
      lB[ 0*localBStride ] = (globalBCol(0) >= N) ? 0.0 : B[ GET_GLOBAL_INDEX_B( globalBRow(0), globalBCol(0) ) ];
                                                    ^


Out[7]: 
gpuarray.array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]], dtype=float32)

In [8]: pygpu.blas.dot(a, a.T)
---------------------------------------------------------------------------
GpuArrayException                         Traceback (most recent call last)
<ipython-input-8-ee1cc1b223fb> in <module>()
----> 1 pygpu.blas.dot(a, a.T)

pygpu/blas.pyx in pygpu.blas.dot (pygpu/blas.c:2400)()

pygpu/blas.pyx in pygpu.blas.pygpu_blas_rdot (pygpu/blas.c:1713)()

GpuArrayException: ('Collectives operations not supported on OpenCL', 2)

Activity

  1. changed the title [-]Dispatch to BLAS if dot can[/-] [+]Collective operations and dot[/+] on Jun 27, 2017
  2. abergeron commented on Jun 27, 2017

    @abergeron
    Member

    The message is most certainly an mistake somewhere. Possibly a reuse of the message from another failure (which is an issue still present on 0.6.5 that should be fixed with 0.6.6).

    Can you try with the current master and see if you get the same problem?

  3. jakirkham commented on Jun 27, 2017

    @jakirkham
    Author

    Sure, retried with 0.6.8, which I built locally. Am getting an error related to dimensionality instead. Looks like 2-D arrays are not supported by dot. Is this expected? If so, what are your thoughts on expanding dot to N-D arrays of rank greater than 1?

    Details
    In [1]: import pygpu
    
    In [2]: import pygpu.blas
    
    In [3]: import numpy
    
    In [4]: import numpy as np
    
    In [5]: c = pygpu.init("opencl0:1")
    
    In [6]: a = pygpu.gpuarray.zeros((10, 11), dtype=np.float32, context=c, cls=pygpu.ndgpuarray)
    
    In [7]: pygpu.blas.gemm(1, a, a.T, 0)
    Out[7]: 
    gpuarray.array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
           [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]], dtype=float32)
    
    In [8]: pygpu.blas.dot(a, a.T)
    ---------------------------------------------------------------------------
    GpuArrayException                         Traceback (most recent call last)
    <ipython-input-8-ee1cc1b223fb> in <module>()
    ----> 1 pygpu.blas.dot(a, a.T)
    
    pygpu/blas.pyx in pygpu.blas.dot (pygpu/blas.c:2568)()
    
    pygpu/blas.pyx in pygpu.blas.pygpu_blas_rdot (pygpu/blas.c:1731)()
    
    GpuArrayException: ('Wrong number of dimensions: X->nd = 2 (expected 1), Y->nd = 2 (expected 1), Z->nd = 0 (expected 0)', 2)
  4. nouiz commented on Jun 27, 2017

    @nouiz
    Member
  5. changed the title [-]Collective operations and dot[/-] [+]Higher than 1-D arrays in dot[/+] on Jun 27, 2017
  6. abergeron commented on Jun 27, 2017

    @abergeron
    Member

    There isn't a pygpu.dot() akin to numpy yet. I welcome patches.

    Otherwise, you're right this it the blas dot, not the numpy dot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions