0

我正在尝试在 GPU 模拟器上实现任务并行性。而不是 EnQueueNDRangeKernel,我正在使用带有乱序执行模式启用的 EnQueueTask(具有 4 个差异内核)。我有两个主机指针,当我在试图将这两个写在全局内存上,由于异步模式,他们做错了..我创建了一个用户事件,比如..

clSetUserEventStatus(user_event, CL_COMPLETE);
ret = clEnqueueWriteBuffer(command_queue, Amobj, CL_TRUE, 0, 16*16*sizeof(float), A, 1, &user_event, NULL);
clSetUserEventStatus(user_event, CL_COMPLETE);
    ret = clEnqueueWriteBuffer(command_queue, Bmobj, CL_TRUE, 0, 16*16*sizeof(float), B, 1, &user_event, NULL);

但它没有给出正确的结果,有时它会停滞不前..

cl_event timing_event1, timing_event2, timing_event3, timing_event4;
cl_ulong starttime1=0,starttime2=0,starttime3=0,starttime4=0,
         endtime1=0,endtime2=0,endtime3=0,endtime4=0,
         time_spent1,time_spent2=0,time_spent3=0,time_spent4=0, time_spent_all_0=0, time_spent_all_1=0;
ret = clEnqueueTask(command_queue, kernel[0], 0, NULL, &timing_event1);
ret = clEnqueueTask(command_queue, kernel[1], 0, NULL, &timing_event2);
ret = clEnqueueTask(command_queue, kernel[2], 0, NULL, &timing_event3);
ret = clEnqueueTask(command_queue, kernel[3], 0, NULL, &timing_event4);

  clGetEventProfilingInfo(timing_event1,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&starttime1,NULL);
clGetEventProfilingInfo(timing_event1,CL_PROFILING_COMMAND_END,sizeof(cl_ulong),&endtime1,NULL);
time_spent1 = endtime1 - starttime1;
  clGetEventProfilingInfo(timing_event2,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&starttime2,NULL);
clGetEventProfilingInfo(timing_event2,CL_PROFILING_COMMAND_END,sizeof(cl_ulong),&endtime2,NULL);
time_spent2 = endtime2 - starttime2;
    clGetEventProfilingInfo(timing_event3,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&starttime3,NULL);
clGetEventProfilingInfo(timing_event3,CL_PROFILING_COMMAND_END,sizeof(cl_ulong),&endtime3,NULL);
time_spent3 = endtime3 - starttime3;
    clGetEventProfilingInfo(timing_event4,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&starttime4,NULL);
clGetEventProfilingInfo(timing_event4,CL_PROFILING_COMMAND_END,sizeof(cl_ulong),&endtime4,NULL);
time_spent4 = endtime4 - starttime4;

time_spent_all_0 = time_spent1 + time_spent2 + time_spent3 + time_spent4;
time_spent_all_1 = endtime4 - starttime1;

printf("\n time_spent1 = %llu", time_spent1);
printf("\n time_spent2 = %llu", time_spent2);
printf("\n time_spent3 = %llu", time_spent3);
printf("\n time_spent4 = %llu", time_spent4);
printf("\n time_spent_all_0 = %llu", time_spent_all_0);
printf("\n time_spent_all_1 = %llu\n", time_spent_all_1);

这样做之后,我得到了全零的..

 size_t resolution;
  clGetDeviceInfo(device, CL_DEVICE_PROFILING_TIMER_RESOLUTION, sizeof(resolution), &resolution, NULL);
  printf("resolution size : %d", resolution);  

这样做之后,我得到了一个像 17145896522 这样的大数字 .. 这是什么意思?

现在我的疑问是。,我需要在我的代码中放置clFlush和放置?clFinish我想要每个单独的内核计时和所有内核计时的总和..?如果这不值得,那么建议我使用任何其他方法来获得以毫秒、微秒或纳秒为单位的准确时间信息。

提前致谢..


我在更正代码后添加了我的结果..

gettimeofday( &t1, NULL );
ret = clEnqueueTask(command_queue, kernel[0], 0, NULL, &kernel_event1);
printf("Enqueue Task 0 successful: %d\n",ret);
gettimeofday( &t2, NULL );
ret = clEnqueueTask(command_queue, kernel[1], 0, NULL, &kernel_event2);
printf("Enqueue Task 1 successful: %d\n",ret);
gettimeofday( &t3, NULL );
ret = clEnqueueTask(command_queue, kernel[2], 0, NULL, &kernel_event3);
printf("Enqueue Task 2 successful: %d\n",ret);
gettimeofday( &t4, NULL );
ret = clEnqueueTask(command_queue, kernel[3], 0, NULL, &kernel_event4);
printf("Enqueue Task 3 successful: %d\n",ret);
gettimeofday( &t5, NULL );
clFinish(command_queue);

ret = clGetEventProfilingInfo(kernel_event1, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &starttime1, NULL);
printf("profiling starttime 1 : %d\n",ret);
ret = clGetEventProfilingInfo(kernel_event1, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endtime1,NULL);
time_spent1 = endtime1 - starttime1;
printf("time_spent 1 = %llu\t profiling endtime 1 = %d\n", time_spent1, ret);

profiling starttime 1 : 0
time_spent 1 = 0
profiling endtime 1 = 0

这些是我得到的结果。那我现在能做什么?

4

1 回答 1

2

在创建命令队列时不要忘记添加CL_QUEUE_PROFILING_ENABLE 。

检查每个 OpenCL 调用的返回码,尤其是clCreateCommandQueue调用,因为您的设备上可能无法进行分析。

在获取分析信息之前,您需要等待排队的命令终止。例如,在 4 个入队之后插入clFinish

于 2013-02-22T16:57:52.530 回答