ghum

2017-08-25 10:03:24 UTC

Hi,

I am trying to extend the sample code for 2D rotation from

https://wiki.tiker.net/PyCuda/Examples/Rotate to 3D. Equation #2 on

http://mathworld.wolfram.com/RotationMatrix.html represents the sample

implementation, I implemented equations #3, #4 and #5 to make it work with

3D data. Here is summary what I tried so far:

- Set 'texture<float, 3> tex;'

- I am not sure about the offset, I put it as 'int didx = z*newih*newid + y

* newiw + x;'

- Changed all text2D for text3D

- The original code uses: 'cuda.matrix_to_texref(a, texref, order="C")' to

generate the 2D cuda texture, but as I want to work with 3D data, this

method does not work. I checked that matrix_to_texref calls the function

matrix_to_array that is explicitly implemented for 2D as you can see here:

'h, w = matrix.shape'. I tried to adapt the code to 3D:

def matrix3D_to_texref(matrix, texref, order):

bind_array_to_texref(matrix3D_to_array(matrix, order), texref)

def matrix3D_to_array(matrix, order, allow_double_hack=False):

if order.upper() == "C":

d, h, w = matrix.shape#TODO: I am not sure about this, it was

previously without 'd', now it should work with 3D data

stride = 0

elif order.upper() == "F":

d, w, h = matrix.shape

stride = -1

else:

raise LogicError("order must be either F or C")

matrix = np.asarray(matrix, order=order)

descr = ArrayDescriptor3D()#TODO: I am not sure about this, it was

previously ArrayDescriptor()

descr.width = w

descr.height = h

descr.depth = d #TODO: I am not sure about this, this was not there

previously

if matrix.dtype == np.float64 and allow_double_hack:

descr.format = array_format.SIGNED_INT32

descr.num_channels = 3

else:

descr.format = dtype_to_array_format(matrix.dtype)

descr.num_channels = 1

ary = Array(descr)

copy = Memcpy3D() #TODO: I am not sure about this, originally it was

Memcpy2D()

copy.set_src_host(matrix)

copy.set_dst_array(ary)

copy.width_in_bytes = copy.src_pitch = copy.dst_pitch = \

matrix.strides[stride]

copy.height = h

copy.depth = d #TODO: I am not sure about this, this was not there

previously

copy(aligned=True)

return ary

Is there another way to generate a 3D pycuda texture? Or maybe I am close to

fix the issue, for now I am getting the following error:

Boost.Python.ArgumentError: Python argument types in

Memcpy3D.__call__(Memcpy3D)

did not match C++ signature:

__call__(struct pycuda::memcpy_3d {lvalue}, class pycuda::stream)

__call__(struct pycuda::memcpy_3d {lvalue})

Best regards,

Gabriel

--

View this message in context: http://pycuda.2962900.n2.nabble.com/3D-rotation-on-PyCuda-tp7575825.html

Sent from the PyCuda mailing list archive at Nabble.com.

I am trying to extend the sample code for 2D rotation from

https://wiki.tiker.net/PyCuda/Examples/Rotate to 3D. Equation #2 on

http://mathworld.wolfram.com/RotationMatrix.html represents the sample

implementation, I implemented equations #3, #4 and #5 to make it work with

3D data. Here is summary what I tried so far:

- Set 'texture<float, 3> tex;'

- I am not sure about the offset, I put it as 'int didx = z*newih*newid + y

* newiw + x;'

- Changed all text2D for text3D

- The original code uses: 'cuda.matrix_to_texref(a, texref, order="C")' to

generate the 2D cuda texture, but as I want to work with 3D data, this

method does not work. I checked that matrix_to_texref calls the function

matrix_to_array that is explicitly implemented for 2D as you can see here:

'h, w = matrix.shape'. I tried to adapt the code to 3D:

def matrix3D_to_texref(matrix, texref, order):

bind_array_to_texref(matrix3D_to_array(matrix, order), texref)

def matrix3D_to_array(matrix, order, allow_double_hack=False):

if order.upper() == "C":

d, h, w = matrix.shape#TODO: I am not sure about this, it was

previously without 'd', now it should work with 3D data

stride = 0

elif order.upper() == "F":

d, w, h = matrix.shape

stride = -1

else:

raise LogicError("order must be either F or C")

matrix = np.asarray(matrix, order=order)

descr = ArrayDescriptor3D()#TODO: I am not sure about this, it was

previously ArrayDescriptor()

descr.width = w

descr.height = h

descr.depth = d #TODO: I am not sure about this, this was not there

previously

if matrix.dtype == np.float64 and allow_double_hack:

descr.format = array_format.SIGNED_INT32

descr.num_channels = 3

else:

descr.format = dtype_to_array_format(matrix.dtype)

descr.num_channels = 1

ary = Array(descr)

copy = Memcpy3D() #TODO: I am not sure about this, originally it was

Memcpy2D()

copy.set_src_host(matrix)

copy.set_dst_array(ary)

copy.width_in_bytes = copy.src_pitch = copy.dst_pitch = \

matrix.strides[stride]

copy.height = h

copy.depth = d #TODO: I am not sure about this, this was not there

previously

copy(aligned=True)

return ary

Is there another way to generate a 3D pycuda texture? Or maybe I am close to

fix the issue, for now I am getting the following error:

Boost.Python.ArgumentError: Python argument types in

Memcpy3D.__call__(Memcpy3D)

did not match C++ signature:

__call__(struct pycuda::memcpy_3d {lvalue}, class pycuda::stream)

__call__(struct pycuda::memcpy_3d {lvalue})

Best regards,

Gabriel

--

View this message in context: http://pycuda.2962900.n2.nabble.com/3D-rotation-on-PyCuda-tp7575825.html

Sent from the PyCuda mailing list archive at Nabble.com.