Hi,
I tried to following code because I was getting very weird errors in my
main program. I create a variable ed which is initialized to zero on
host and then copied over to the device and back to host without any
manipulation. For some reason unknown to me, the value of the variable
changes. Also, is there a better way to copy the variable back other
than creating a numpy array for it? If I try copying it to a simple
variable, it says "TypeError: expected a writeable buffer object".
/ 1 import pycuda.driver as cuda
2 import pycuda.autoinit
3
4 cuda.init()
5 assert cuda.Device.count() >= 1
6
7 dev = cuda.Device(0)
8 ctx = dev.make_context()
9
10 import numpy
11
12 ed = numpy.float32(0.0)
13
14 edd = cuda.mem_alloc(ed.nbytes)
15
16 cuda.memcpy_htod(edd, ed)
17
18 result = numpy.array([0.0])
19 cuda.memcpy_dtoh(result, edd)
20 print ed
21 print result
/
*On running the program, I get the following output*
/
msid ~/python $ python cudaTest.py
0.0
[-0.00476747]
-----------------------------------------------------------
PyCuda WARNING: I'm being asked to destroy a
context that's part of the current context stack.
-----------------------------------------------------------
I will pick the next lower active context from the
context stack. Since this choice is happening
at an unspecified point in time, your code
may be making false assumptions about which
context is active at what point.
Call Context.pop() to avoid this warning.
-----------------------------------------------------------
If Python is terminating abnormally (eg. exiting upon an
unhandled exception), you may ignore this.
-----------------------------------------------------------
terminate called after throwing an instance of 'cuda::error'
what(): cuCtxPushCurrent failed: invalid value
Aborted
/
Could someone please tell me why this is happening(pardon me if this is
common knowledge)
Thank you.
Siddhardh
Show replies by date