Nico Mkhatvari
Nico Mkhatvari

Reputation: 103

clCreateImage2D (..., void* hst_ptr,..) how to use it?

I read the formal definition on the official site but still I dont understand: What is void* hst-ptr used for? For example here. Why is buffer here so useful, Why buffer is a pointer to char and the size is 4*width*height

Upvotes: 0

Views: 394

Answers (1)

Dithermaster
Dithermaster

Reputation: 6343

host_ptr is used when either of the flags CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR are specified. In those cases, host_ptr points to CPU memory containing an image to use or copy.

In the example code you linked to, buffer is the host-side (CPU memory) image being copied to the device-side (GPU typ.) image (since they are using the CL_MEM_COPY_HOST_PTR flag).

It's not important that they made it a pointer to char since they are using memcpy to fill it in, but it helps the allocation using new char since a char is 1 byte in size.

4 * width * height is because that is the total number of bytes (chars) needed.

  1. 4 is the size of one CL_RGBA CL_UNORM_INT8 pixel (R, G, B, A are each one byte).
  2. width * height because that the total count of pixels.

The code is allocating host-side memory for an image, filling it in with something, then creating a device-side image using those bytes, then processing it using a kernel, then copying the bytes back to the host-side image.

Upvotes: 1

Related Questions