0
votes

I have a OpenCL program and I want to do perfomance-measurements of data-transfers and kernel-execution-time.

I tried to do this with the "Create Queue with Profiling enabled", but after the line

command_queue = clCreateCommandQueue(context, CL_DEVICE, CL_QUEUE_PROFILING_ENABLE, &err);

there is the line

cl_device_id device_id = cluInitDevice(CL_DEVICE, &context, &command_queue);

which makes some problems because of the context-constraint.

How do i handle this constraint?

thanks.

1
cl_device_id device_id = cluInitDevice(CL_DEVICE, &context, &command_queue); is not a standard API call, is a custom call. What does that code do? What are the constrains? Please clarify. - DarkZeros

1 Answers

0
votes

Are you from Uni Ibk? The function's from cl_utils.h, which we got from prof. But here's the code.

     cl_device_id cluInitDevice(size_t num, cl_context *out_context, cl_command_queue *out_queue) { 
// get platform ids
cl_uint ret_num_platforms;
CLU_ERRCHECK(clGetPlatformIDs(0, NULL, &ret_num_platforms), "Failed to query number of ocl platforms");
cl_platform_id *ret_platforms = (cl_platform_id*)alloca(sizeof(cl_platform_id)*ret_num_platforms);
CLU_ERRCHECK(clGetPlatformIDs(ret_num_platforms, ret_platforms, NULL), "Failed to retrieve ocl platforms");

// get device id of desired device
cl_device_id device_id = NULL;
for(cl_uint i=0; i<ret_num_platforms; ++i) {
    cl_uint ret_num_devices;
    CLU_ERRCHECK(clGetDeviceIDs(ret_platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &ret_num_devices), "Failed to query number of ocl devices");
    if(num < ret_num_devices) {
        // desired device is on this platform, select
        cl_device_id *ret_devices = (cl_device_id*)alloca(sizeof(cl_device_id)*ret_num_devices);
        CLU_ERRCHECK(clGetDeviceIDs(ret_platforms[i], CL_DEVICE_TYPE_ALL, ret_num_devices, ret_devices, NULL), "Failed to retrieve ocl devices");
        device_id = ret_devices[num];
    }
    num -= ret_num_devices;
}

// create opencl context if requested
if(out_context != NULL) {
    cl_int err;
    *out_context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &err);
    CLU_ERRCHECK(err, "Failed to create ocl context");

    // create command queue if requested
    if(out_queue != NULL) {
        *out_queue = clCreateCommandQueue(*out_context, device_id, 0, &err);
        CLU_ERRCHECK(err, "Failed to create ocl command queue");
    }
}
return device_id;

}