Skip to content

Instantly share code, notes, and snippets.

@torokati44
Created May 28, 2015
Embed
What would you like to do?
#include <iostream>
#include <CL/cl.h>
cl_platform_id platform_id;
cl_device_id device_id;
cl_context context;
cl_command_queue queue;
cl_program program;
cl_kernel kernel;
cl_event event;
const char *program_source =
"kernel void empty() {"
"}";
int main() {
const size_t global_size = 10;
const int num_executions = 100000;
clGetPlatformIDs(1, &platform_id, NULL);
clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
context = clCreateContext(0, 1, &device_id, NULL, NULL, NULL);
queue = clCreateCommandQueue(context, device_id, CL_QUEUE_PROFILING_ENABLE, NULL);
program = clCreateProgramWithSource(context, 1, &program_source, NULL, NULL);
clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
kernel = clCreateKernel(program, "empty", NULL);
for (int i = 0; i < num_executions; ++i) {
std::cout << i << std::endl;
cl_int err;
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global_size, NULL, 0, NULL, &event);
if (err != CL_SUCCESS) {
std::cerr << "Error (" << err << ") at execution " << i << std::endl;
if (err == CL_OUT_OF_RESOURCES) {
std::cerr << "CL_OUT_OF_RESOURCES" << std::endl;
}
break;
}
clWaitForEvents(1, &event);
}
clReleaseKernel(kernel);
clReleaseCommandQueue(queue);
clReleaseContext(context);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment