| 38 | "}\n" }; |
| 39 | |
| 40 | int enqueue_kernel(cl_context context, |
| 41 | const cl_queue_properties_khr *queue_prop_def, |
| 42 | cl_device_id device, clKernelWrapper &kernel, |
| 43 | size_t num_elements) |
| 44 | { |
| 45 | clMemWrapper streams[2]; |
| 46 | int error; |
| 47 | std::vector<int> buf(num_elements); |
| 48 | clCreateCommandQueueWithPropertiesKHR_fn clCreateCommandQueueWithPropertiesKHR = NULL; |
| 49 | cl_platform_id platform; |
| 50 | clEventWrapper event; |
| 51 | |
| 52 | error = clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(cl_platform_id), |
| 53 | &platform, NULL); |
| 54 | test_error(error, "clGetDeviceInfo for CL_DEVICE_PLATFORM failed"); |
| 55 | |
| 56 | clCreateCommandQueueWithPropertiesKHR = (clCreateCommandQueueWithPropertiesKHR_fn) clGetExtensionFunctionAddressForPlatform(platform, "clCreateCommandQueueWithPropertiesKHR"); |
| 57 | if (clCreateCommandQueueWithPropertiesKHR == NULL) |
| 58 | { |
| 59 | log_error("ERROR: clGetExtensionFunctionAddressForPlatform failed\n"); |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | clCommandQueueWrapper queue = clCreateCommandQueueWithPropertiesKHR( |
| 64 | context, device, queue_prop_def, &error); |
| 65 | test_error(error, "clCreateCommandQueueWithPropertiesKHR failed"); |
| 66 | |
| 67 | for (size_t i = 0; i < num_elements; ++i) |
| 68 | { |
| 69 | buf[i] = i; |
| 70 | } |
| 71 | |
| 72 | streams[0] = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, num_elements * sizeof(int), buf.data(), &error); |
| 73 | test_error( error, "clCreateBuffer failed." ); |
| 74 | streams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, num_elements * sizeof(int), NULL, &error); |
| 75 | test_error( error, "clCreateBuffer failed." ); |
| 76 | |
| 77 | error = clSetKernelArg(kernel, 0, sizeof(streams[0]), &streams[0]); |
| 78 | test_error( error, "clSetKernelArg failed." ); |
| 79 | |
| 80 | error = clSetKernelArg(kernel, 1, sizeof(streams[1]), &streams[1]); |
| 81 | test_error( error, "clSetKernelArg failed." ); |
| 82 | |
| 83 | error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &num_elements, NULL, 0, NULL, &event); |
| 84 | test_error( error, "clEnqueueNDRangeKernel failed." ); |
| 85 | |
| 86 | error = clWaitForEvents(1, &event); |
| 87 | test_error(error, "clWaitForEvents failed."); |
| 88 | |
| 89 | error = clEnqueueReadBuffer(queue, streams[1], CL_TRUE, 0, num_elements, buf.data(), 0, NULL, NULL); |
| 90 | test_error( error, "clEnqueueReadBuffer failed." ); |
| 91 | |
| 92 | for (size_t i = 0; i < num_elements; ++i) |
| 93 | { |
| 94 | if (static_cast<size_t>(buf[i]) != i) |
| 95 | { |
| 96 | log_error("ERROR: Incorrect vector copy result."); |
| 97 | return -1; |