MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCL-CTS / test_readimage

Function test_readimage

test_conformance/basic/test_readimage.cpp:207–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205
206template <cl_mem_object_type IMG_TYPE, typename T>
207static int test_readimage(cl_device_id device, cl_context context,
208 cl_command_queue queue,
209 const cl_image_format *img_format)
210{
211 clMemWrapper streams[2];
212 clProgramWrapper program;
213 clKernelWrapper kernel;
214 clSamplerWrapper sampler;
215
216 std::string kernel_name("test_");
217
218 size_t img_width = TEST_IMAGE_WIDTH(IMG_TYPE);
219 size_t img_height = TEST_IMAGE_HEIGHT(IMG_TYPE);
220 size_t img_depth = TEST_IMAGE_DEPTH(IMG_TYPE);
221
222 int err;
223
224 const size_t origin[3] = { 0, 0, 0 };
225 const size_t region[3] = { img_width, img_height, img_depth };
226
227 const size_t num_elements = img_width * img_height * img_depth * 4;
228 const size_t length = num_elements * sizeof(T);
229
230 PASSIVE_REQUIRE_IMAGE_SUPPORT(device)
231
232 std::vector<T> input(num_elements);
233 std::vector<T> output(num_elements);
234
235 generate_random_inputs(input);
236
237 streams[0] =
238 create_image_xd(context, CL_MEM_READ_ONLY, IMG_TYPE, img_format,
239 img_width, img_height, img_depth, &err);
240 test_error(err, "create_image failed.");
241
242 streams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, length, NULL, &err);
243 test_error(err, "clCreateBuffer failed.");
244
245 sampler = clCreateSampler(context, CL_FALSE, CL_ADDRESS_CLAMP_TO_EDGE,
246 CL_FILTER_NEAREST, &err);
247 test_error(err, "clCreateSampler failed");
248
249 err = clEnqueueWriteImage(queue, streams[0], CL_TRUE, origin, region, 0, 0,
250 input.data(), 0, NULL, NULL);
251 test_error(err, "clEnqueueWriteImage failed.");
252
253 kernel_name += GetChannelOrderName(img_format->image_channel_order);
254 kernel_name += GetChannelTypeName(img_format->image_channel_data_type);
255
256 const char **kernel_source = (CL_MEM_OBJECT_IMAGE2D == IMG_TYPE)
257 ? &kernel_source_2d
258 : &kernel_source_3d;
259
260 err = create_single_kernel_helper(context, &program, &kernel, 1,
261 kernel_source, kernel_name.c_str());
262 test_error(err, "create_single_kernel_helper failed.");
263
264 err = clSetKernelArg(kernel, 0, sizeof(streams[0]), &streams[0]);

Callers

nothing calls this directly

Calls 5

create_image_xdFunction · 0.85
GetChannelOrderNameFunction · 0.85
GetChannelTypeNameFunction · 0.85
generate_random_inputsFunction · 0.70

Tested by

no test coverage detected