瀏覽代碼

SOCL: fix dependency problem with clEnqueueWriteBuffer

From the specification:
"If blocking_write is CL_TRUE, the OpenCL implementation copies the data referred to by ptr
and enqueues the write operation in the command-queue. The memory pointed to by ptr can be
reused by the application after the clEnqueueWriteBuffer call returns."

The data transfer is not completed when clEnqueueWriteBuffer returns, even when blocking_write is set...
Sylvain Henry 12 年之前
父節點
當前提交
a15e772757
共有 4 個文件被更改,包括 21 次插入10 次删除
  1. 6 2
      socl/src/cl_enqueuereadbuffer.c
  2. 7 2
      socl/src/cl_enqueuewritebuffer.c
  3. 3 5
      socl/src/debug.c
  4. 5 1
      socl/src/debug.h

+ 6 - 2
socl/src/cl_enqueuereadbuffer.c

@@ -39,9 +39,13 @@ static void soclEnqueueReadBuffer_opencl_task(void *descr[], void *args) {
    cl_command_queue cq;
    starpu_opencl_get_queue(wid, &cq);
 
-   cl_int ret = clEnqueueReadBuffer(cq, mem, CL_TRUE, cmd->offset, cmd->cb, cmd->ptr, 0, NULL, NULL);
+   cl_event ev;
+   cl_int ret = clEnqueueReadBuffer(cq, mem, CL_TRUE, cmd->offset, cmd->cb, cmd->ptr, 0, NULL, &ev);
    if (ret != CL_SUCCESS)
-      DEBUG_CL("clEnqueueReadBuffer", ret);
+      ERROR_CL("clEnqueueReadBuffer", ret);
+
+   clWaitForEvents(1, &ev);
+   clReleaseEvent(ev);
 
 }
 

+ 7 - 2
socl/src/cl_enqueuewritebuffer.c

@@ -42,9 +42,14 @@ static void soclEnqueueWriteBuffer_opencl_task(void *descr[], void *args) {
    cl_command_queue cq;
    starpu_opencl_get_queue(wid, &cq);
 
-   cl_int err = clEnqueueWriteBuffer(cq, mem, CL_TRUE, cmd->offset, cmd->cb, cmd->ptr, 0, NULL, NULL);
+   cl_event ev;
+
+   cl_int err = clEnqueueWriteBuffer(cq, mem, CL_TRUE, cmd->offset, cmd->cb, cmd->ptr, 0, NULL, &ev);
    if (err != CL_SUCCESS)
-      DEBUG_CL("clEnqueueWriteBuffer", err);
+      ERROR_CL("clEnqueueWriteBuffer", err);
+
+   clWaitForEvents(1, &ev);
+   clReleaseEvent(ev);
 }
 
 static struct starpu_perfmodel write_buffer_perfmodel = {

+ 3 - 5
socl/src/debug.c

@@ -16,9 +16,8 @@
 
 #include "socl.h"
 
-#ifdef STARPU_VERBOSE
-void DEBUG_CL(char *s, cl_int err) {
-   #define ERR_CASE(a) case a: DEBUG_MSG("[OpenCL] %s CL error: %s\n", s, #a); break;
+void ERROR_CL(char *s, cl_int err) {
+   #define ERR_CASE(a) case a: ERROR_MSG("[OpenCL] %s CL error: %s\n", s, #a); break;
    switch(err) {
       case CL_SUCCESS:
          DEBUG_MSG("[OpenCL] %s SUCCESS.\n", s);
@@ -70,7 +69,6 @@ void DEBUG_CL(char *s, cl_int err) {
       ERR_CASE(CL_INVALID_MIP_LEVEL)
       ERR_CASE(CL_INVALID_GLOBAL_WORK_SIZE)
       default:
-         DEBUG_MSG("%s CL error: Error message not supported by DEBUG_CL macro (%d).\n", s, err);
+         ERROR_MSG("%s CL error: Error message not supported by ERROR_CL function (%d).\n", s, err);
    }
 }
-#endif

+ 5 - 1
socl/src/debug.h

@@ -36,10 +36,14 @@
 #define ERROR_MSG_NOHEAD(...) fprintf(stderr, __VA_ARGS__)
 #define ERROR_STOP(...) do { ERROR_MSG(__VA_ARGS__); exit(1); } while(0);
 
+void ERROR_CL(char *s, cl_int err);
+
 #ifdef STARPU_VERBOSE
-void DEBUG_CL(char *s, cl_int err);
+   #define DEBUG_CL(args...) ERROR_CL(args) 
 #else
    #define DEBUG_CL(...) while(0);
 #endif
 
+
+
 #endif /* SOCL_DEBUG_H */