【问题标题】:OpenCL Kernel-timingOpenCL 内核计时
【发布时间】:2016-10-18 19:56:24
【问题描述】:

我有一个 OpenCL 程序,我想对数据传输和内核执行时间进行性能测量。

我尝试使用 “创建启用分析的队列” 来执行此操作,但在该行之后

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

有行

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

由于上下文约束,这会产生一些问题。

我该如何处理这个约束?

谢谢。

【问题讨论】:

  • cl_device_id device_id = cluInitDevice(CL_DEVICE, &context, &command_queue); 不是标准 API 调用,是自定义调用。那个代码有什么作用?有什么限制?请澄清。

标签: performance opencl


【解决方案1】:

你是 Uni Ibk 的吗?该函数来自 cl_utils.h,我们从 prof 获得。但这是代码。

     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;

}

【讨论】:

    猜你喜欢
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 2018-02-08
    • 2013-04-24
    • 2013-05-01
    相关资源
    最近更新 更多