瀏覽代碼

Make tests/datawizard/handle_to_pointer work with OpenCL.

Cyril Roelandt 13 年之前
父節點
當前提交
8183dd16b1
共有 1 個文件被更改,包括 34 次插入1 次删除
  1. 34 1
      tests/datawizard/handle_to_pointer.c

+ 34 - 1
tests/datawizard/handle_to_pointer.c

@@ -18,6 +18,9 @@
 #include <assert.h>
 
 #include <starpu.h>
+#ifdef STARPU_USE_OPENCL
+#include <starpu_opencl.h>
+#endif
 #include <stdlib.h>
 #include "../helper.h"
 
@@ -53,13 +56,43 @@ static void cuda_task(void **buffers, void *args)
 }
 #endif
 
+#ifdef STARPU_USE_OPENCL
+static void opencl_task(void *buffers[], void *args)
+{
+	cl_command_queue queue;
+	int id = starpu_worker_get_id();
+	int devid = starpu_worker_get_devid(id);
+	starpu_opencl_get_queue(devid, &queue);
+
+	cl_mem numbers = (cl_mem) STARPU_VECTOR_GET_DEV_HANDLE(buffers[0]);
+	unsigned size = STARPU_VECTOR_GET_NX(buffers[0]);
+
+	unsigned i;
+	for (i = 0; i < size; i++)
+	{
+		clEnqueueWriteBuffer(queue,
+				numbers,
+				CL_TRUE,
+				i*sizeof(int),  /* offset */
+				sizeof(int),
+				&i,
+				0,              /* num_events_in_wait_list */
+				NULL,           /* event_wait_list */
+				NULL            /* event */);
+	}
+			
+}
+#endif
+
 static struct starpu_codelet cl =
 {
-	.where = STARPU_CPU | STARPU_CUDA,
 	.cpu_funcs = {cpu_task, NULL},
 #ifdef STARPU_USE_CUDA
 	.cuda_funcs = {cuda_task, NULL},
 #endif
+#ifdef STARPU_USE_OPENCL
+	.opencl_funcs = {opencl_task, NULL},
+#endif
 	.nbuffers = 1,
 	.modes = {STARPU_W}
 };