You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/04/29 12:37:08 UTC

[GitHub] [tvm] echuraev commented on a diff in pull request #11180: [OpenCL] Change of OpenCL profiling logic

echuraev commented on code in PR #11180:
URL: https://github.com/apache/tvm/pull/11180#discussion_r861760594


##########
src/runtime/opencl/opencl_common.h:
##########
@@ -422,23 +424,57 @@ class OpenCLTimerNode : public TimerNode {
   virtual void Start() {
     cl::OpenCLWorkspace::Global()->GetEventQueue(dev_).clear();
     this->duration = 0;
+
+    if (!cl::OpenCLWorkspace::Global()->profiling) {
+      // Very first call of Start() leads to the recreation of
+      // OpenCL command queue in profiling mode. This allows to run profile after inference.
+      OPENCL_CALL(clFlush(cl::OpenCLWorkspace::Global()->GetQueue(dev_)));
+      OPENCL_CALL(clFinish(cl::OpenCLWorkspace::Global()->GetQueue(dev_)));
+      OPENCL_CALL(clReleaseCommandQueue(cl::OpenCLWorkspace::Global()->GetQueue(dev_)));
+
+      cl_int err_code;
+      cl_device_id did = cl::OpenCLWorkspace::Global()->devices[dev_.device_id];
+      auto profiling_queue = clCreateCommandQueue(cl::OpenCLWorkspace::Global()->context, did,
+                                                  CL_QUEUE_PROFILING_ENABLE, &err_code);
+      OPENCL_CHECK_ERROR(err_code);
+      cl::OpenCLWorkspace::Global()->queues[dev_.device_id] = profiling_queue;
+      cl::OpenCLWorkspace::Global()->profiling = true;
+    }

Review Comment:
   This code is almost the same as in the destructor. Maybe we could create a private method e.g. `switchProfilingMode()` or `enableProfiling(bool)` and move this logic into this method?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org