viennacl / pyviennacl-dev

Developer repository for PyViennaCL. Visit http://viennacl.sourceforge.net/ for latest releases.
MIT License
32 stars 6 forks source link

The scheduler encountered a problem adding two Matrices of the same shape #36

Open davidbp opened 8 years ago

davidbp commented 8 years ago

Hello,

I've was adding a couple of Matrix objects (of the same shape) and stumbled upon an error. Maybe you can give me a hint about what is wrong in my code:

import numpy as np
import pyviennacl as pv

Xbatch_ = np.array(np.random.random([200,784]), dtype="float32")
W_ = np.array(np.random.random([784, 100]), dtype="float32")

Xbatch = pv.Matrix(Xbatch_)
W = pv.Matrix(W_)

ones = pv.Matrix(np.ones(W.shape, dtype="float32"))
energy = pv.ElementExp(-W)
# until here everything works

# the following line returns an error
energy + ones

It returned:

ERROR 2015-11-15 02:02:58,128 pyviennacl.pycore 2844 execute EXCEPTION EXECUTING: Assign(Matrix, Add(ElementExp(Mul(Matrix, HostScalar)=>Matrix)=>Matrix, Matrix)=>Matrix)=>NoResult .... RuntimeError: ViennaCL: Internal error: The scheduler encountered a problem with the operation provided: Cannot deal with unary operations on vectors

karlrupp commented 8 years ago

The statement

energy = pv.ElementExp(-W)

only instantiates a proxy element, so 'energy' does not hold the values of the operation, but merely encodes the operation exp(-W). Try

energy = pv.ElementExp(-W).execute()

and then the last line should evaluate correctly. (You can verify the object's type by e.g. type(energy))

davidbp commented 8 years ago

Thank you Karl,

You are right. I'm sorry for the questions. I'm still getting used to the library. ( It seems to be similar to theano. where the .execute in pyviennacl behaves similar to theano's .eval() )

I just found an estrange behaviour.

class ElementDiv(Node)
 |  Represents the elementwise multiplication of one object by another of the
 |  same type.

nevertheless I get...

import numpy as np
import pyviennacl as pv

### THIS PRODUCES NANS
ones = pv.Matrix(np.ones([800,100], dtype="float32"))
pv.ElementDiv(ones, ones).execute()
array([[  1.,   1.,   1., ...,   1.,   1.,   1.],
       [  1.,   1.,   1., ...,   1.,   1.,   1.],
       [  1.,   1.,   1., ...,   1.,   1.,   1.],
       ..., 
       [  1.,   1.,   1., ...,  nan,  nan,  nan],
       [  1.,   1.,   1., ...,  nan,  nan,  nan],
       [  1.,   1.,   1., ...,  nan,  nan,  nan]], dtype=float32)

### THIS DOES NOT PRODUCE NANS
ones = pv.Matrix(np.ones([800, 800], dtype="float32"))
pv.ElementDiv(ones, ones).execute()
array([[ 1.,  1.,  1., ...,  1.,  1.,  1.],
       [ 1.,  1.,  1., ...,  1.,  1.,  1.],
       [ 1.,  1.,  1., ...,  1.,  1.,  1.],
       ..., 
       [ 1.,  1.,  1., ...,  1.,  1.,  1.],
       [ 1.,  1.,  1., ...,  1.,  1.,  1.],
       [ 1.,  1.,  1., ...,  1.,  1.,  1.]], dtype=float32)
karlrupp commented 8 years ago

Thanks for reporting this odd behavior. Could you please tell me which OpenCL device and which version of PyViennaCL (the released 1.0.3 or built from repo) you are using?

davidbp commented 8 years ago

I can tell my PyViennaCL version is 1.0.3 from

import pyviennacl as pv
>>> pv.__version__
'1.0.3
>>> pyviennacl.__viennacl_version__
 '1.5.2'

I don't know how to tell you which device I'm using. What command can I use to tell you?

davidbp commented 8 years ago

@karlrupp do you have any idea why this might happen? Do you get the same behaviour?

karlrupp commented 8 years ago

@davidbp: Thanks for the reminder. I just tried to reproduce the error with PyViennaCL 1.0.3 as well as by directly running the routines in ViennaCL 1.5.2, 1.6.0, 1.6.2, and 1.7.0. Unfortunately, however, I could not reproduce the issue.

Could you briefly describe the hardware available on your machine? Do you have a discrete GPU? If so, which model? This should help me with reproducing the problem. Thanks!

davidbp commented 8 years ago

@karlrupp, How do you set the context? In pyopencl in the same machine, it appears I can use CPU or 2 gpus. This is what I see:

python test_pyopencl.py 
Choose platform:
[0] <pyopencl.Platform 'Apple' at 0x7fff0000>
Choice [0]:0
Choose device(s):
[0] <pyopencl.Device 'Intel(R) Xeon(R) CPU E5-1620 v2 @ 3.70GHz' on 'Apple' at 0xffffffff>
[1] <pyopencl.Device 'ATI Radeon HD - FirePro D300 Compute Engine' on 'Apple' at 0x1021c00>
[2] <pyopencl.Device 'ATI Radeon HD - FirePro D300 Compute Engine' on 'Apple' at 0x2021c00>

I don't know how can I set context in pyviennacl.

davidbp commented 8 years ago

@karlrupp, to ensure it was not my apple machine I tried the same posted code in an ubuntu 14.04 lts. I got the exact same results. With pyviennacl.version : 1.0.3

karlrupp commented 8 years ago

As far as I know, the 1.0.3 release version does not provide the option of setting the device through Python. The latest code in the repository, however, does.

I'll keep trying to reproduce the issue, please allow for a couple of hours.

karlrupp commented 8 years ago

Success: I was accidentally using a newer version than 1.0.3 for my first tests. With a fresh build of PyViennaCL 1.0.3 I can reproduce the issue.

Given that the issue disappears with the developer version of PyViennaCL, could you please try that? If you encounter any issues, please let me know.