浏览代码

vector scaling example: updates to match the documentation

Nathalie Furmento 15 年之前
父节点
当前提交
e2ae0c2f77

+ 2 - 12
examples/basic_examples/vector_scal.c

@@ -22,9 +22,6 @@
  *  3- how a kernel can manipulate the data (buffers[0].vector.ptr)
  */
 
-
-#include <stdio.h>
-#include <stdint.h>
 #include <starpu.h>
 #include <starpu_opencl.h>
 
@@ -35,14 +32,7 @@ extern void scal_cuda_func(void *buffers[], void *_args);
 extern void scal_opencl_func(void *buffers[], void *_args);
 
 static starpu_codelet cl = {
-	.where = STARPU_CPU
-#ifdef STARPU_USE_CUDA
-		| STARPU_CUDA
-#endif
-#ifdef STARPU_USE_OPENCL
-		| STARPU_OPENCL
-#endif
-		,
+	.where = STARPU_CPU | STARPU_CUDA | STARPU_OPENCL,
 	/* CPU implementation of the codelet */
 	.cpu_func = scal_cpu_func,
 #ifdef STARPU_USE_CUDA
@@ -93,7 +83,7 @@ int main(int argc, char **argv)
 	 *  - the fifth argument is the size of each element.
 	 */
 	starpu_data_handle vector_handle;
-	starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX, sizeof(float));
+	starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX, sizeof(vector[0]));
 
 	float factor = 3.14;
 

+ 1 - 1
examples/basic_examples/vector_scal_cpu.c

@@ -26,7 +26,7 @@ void scal_cpu_func(void *buffers[], void *cl_arg)
 	unsigned i;
 	float *factor = cl_arg;
 
-	/* 
+	/*
 	 * The "buffers" array matches the task->buffers array: for instance
 	 * task->buffers[0].handle is a handle that corresponds to a data with
 	 * vector "interface", so that the first entry of the array in the

+ 2 - 3
examples/basic_examples/vector_scal_cuda.cu

@@ -31,12 +31,11 @@ static __global__ void vector_mult_cuda(float *val, unsigned n,
 extern "C" void scal_cuda_func(void *buffers[], void *_args)
 {
         float *factor = (float *)_args;
-        struct starpu_vector_interface_s *vector = (struct starpu_vector_interface_s *) buffers[0];
 
         /* length of the vector */
-        unsigned n = STARPU_GET_VECTOR_NX(vector);
+        unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
         /* local copy of the vector pointer */
-        float *val = (float *)STARPU_GET_VECTOR_PTR(vector);
+        float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
 
         /* TODO: use more blocks and threads in blocks */
         vector_mult_cuda<<<1,1>>>(val, n, *factor);

+ 5 - 6
examples/basic_examples/vector_scal_opencl.c

@@ -25,16 +25,15 @@ extern struct starpu_opencl_codelet codelet;
 
 void scal_opencl_func(void *buffers[], void *_args)
 {
-	float *factor = (float *)_args;
-	struct starpu_vector_interface_s *vector = (struct starpu_vector_interface_s *) buffers[0];
+	float *factor = _args;
 	int id, devid, err;
 	cl_kernel kernel;
 	cl_command_queue queue;
 
 	/* length of the vector */
-	unsigned n = STARPU_GET_VECTOR_NX(vector);
+	unsigned n = STARPU_GET_VECTOR_NX(buffers[0]);
 	/* local copy of the vector pointer */
-	float *val = (float *)STARPU_GET_VECTOR_PTR(vector);
+	float *val = (float *)STARPU_GET_VECTOR_PTR(buffers[0]);
 
 	id = starpu_worker_get_id();
 	devid = starpu_worker_get_devid(id);
@@ -44,8 +43,8 @@ void scal_opencl_func(void *buffers[], void *_args)
 
 	err = 0;
 	err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);
-	err = clSetKernelArg(kernel, 1, sizeof(int), &n);
-	err |= clSetKernelArg(kernel, 2, sizeof(float), (void*)factor);
+	err = clSetKernelArg(kernel, 1, sizeof(n), &n);
+	err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);
 	if (err) STARPU_OPENCL_REPORT_ERROR(err);
 
 	{