LikeKT's picture

Cloo: ComputeImage3D

int width=32
int height=32
int depth=32
byte[] volumeData = new byte[width*height*depth];  //
IntPtr pVolumeData  = Marshal.AllocHGlobal( width*height*depth);
Marshal.Copy(volumeData  , 0, pVolumeData, width*height*depth);
ComputeImageFormat volume_format = new ComputeImageFormat(
ComputeImage3D volumeArray = new ComputeImage3D(cxGPUContext, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, volume_format,
                                   width, height, depth,
                                    (long)(image_row_pitch), (long)(image_slice_pitch),

a) how do I set the value for
image_row_pitch = width*size of element in bytes
image_slice_pitch = width*height*size of element in bytes

b) what should be the "size of element in bytes" in this case.
c) is this "size of element in bytes" depends on the " ComputeImageChannelType.UnsignedInt8"

d) If the above code work, can I set the argument this way?

 kernel.SetMemoryArgument(0, volumeArray );


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
LikeKT's picture

I checked with the developers and it seems that modify the cloo source code and now it works.

[DllImport(dll, EntryPoint = "clCreateImage2D")]  //change clCreateImage2D=> clCreateImage3D
        public extern static unsafe IntPtr
            IntPtr context,
            ComputeMemoryFlags flags,
            /* const */ ComputeImageFormat* image_format,
            IntPtr image_width,
            IntPtr image_height,
            IntPtr image_depth,
            IntPtr image_row_pitch,
            IntPtr image_slice_pitch,
            /* void* */ IntPtr host_ptr,
            ComputeErrorCode* errcode_ret);
nythrix's picture

a) Leave them zero. OpenCL will compute "the pitches" by itself.

b & c) The size of element in bytes is the number of channels * the size of the channel. In your case one channel (ComputeImageChannelOrder.R) * size of UnsignedInt8 = 1 byte.

d) Yes.

Thanks a lot for catching this! Fix committed to git repository.