瀏覽代碼

doc/tutorial: fix code formatting

Nathalie Furmento 12 年之前
父節點
當前提交
dffcfc94c9
共有 3 個文件被更改,包括 59 次插入60 次删除
  1. 22 23
      doc/tutorial/vector_scal_cpu.c
  2. 2 2
      doc/tutorial/vector_scal_cuda.cu
  3. 35 35
      doc/tutorial/vector_scal_opencl.c

+ 22 - 23
doc/tutorial/vector_scal_cpu.c

@@ -20,31 +20,30 @@
 /* This kernel takes a buffer and scales it by a constant factor */
 void vector_scal_cpu(void *buffers[], void *cl_arg)
 {
-    unsigned i;
-    float *factor = cl_arg;
+	unsigned i;
+	float *factor = cl_arg;
 
-    /*
-     * The "buffers" array matches the task->handles array: for instance
-     * task->handles[0] is a handle that corresponds to a data with
-     * vector "interface", so that the first entry of the array in the
-     * codelet  is a pointer to a structure describing such a vector (ie.
-     * struct starpu_vector_interface *). Here, we therefore manipulate
-     * the buffers[0] element as a vector: nx gives the number of elements
-     * in the array, ptr gives the location of the array (that was possibly
-     * migrated/replicated), and elemsize gives the size of each elements.
-     */
-    struct starpu_vector_interface *vector = buffers[0];
+	/*
+	 * The "buffers" array matches the task->handles array: for instance
+	 * task->handles[0] is a handle that corresponds to a data with
+	 * vector "interface", so that the first entry of the array in the
+	 * codelet  is a pointer to a structure describing such a vector (ie.
+	 * struct starpu_vector_interface *). Here, we therefore manipulate
+	 * the buffers[0] element as a vector: nx gives the number of elements
+	 * in the array, ptr gives the location of the array (that was possibly
+	 * migrated/replicated), and elemsize gives the size of each elements.
+	 */
+	struct starpu_vector_interface *vector = buffers[0];
 
-    /* length of the vector */
-    unsigned n = STARPU_VECTOR_GET_NX(vector);
+	/* length of the vector */
+	unsigned n = STARPU_VECTOR_GET_NX(vector);
 
-    /* get a pointer to the local copy of the vector : note that we have to
-     * cast it in (float *) since a vector could contain any type of
-     * elements so that the .ptr field is actually a uintptr_t */
-    float *val = (float *)STARPU_VECTOR_GET_PTR(vector);
+	/* get a pointer to the local copy of the vector : note that we have to
+	 * cast it in (float *) since a vector could contain any type of
+	 * elements so that the .ptr field is actually a uintptr_t */
+	float *val = (float *)STARPU_VECTOR_GET_PTR(vector);
 
-    /* scale the vector */
-    for (i = 0; i < n; i++)
-        val[i] *= *factor;
+	/* scale the vector */
+	for (i = 0; i < n; i++)
+		val[i] *= *factor;
 }
-

+ 2 - 2
doc/tutorial/vector_scal_cuda.cu

@@ -17,7 +17,7 @@
 
 #include <starpu.h>
 
-static __global__ void vector_mult_cuda(float *val, unsigned n, float factor)
+static __global__ void vector_mult_cuda(float *val, unsigned int n, float factor)
 {
         unsigned i =  blockIdx.x*blockDim.x + threadIdx.x;
         if (i < n)
@@ -29,7 +29,7 @@ extern "C" void vector_scal_cuda(void *buffers[], void *_args)
         float *factor = (float *)_args;
 
         /* length of the vector */
-        unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
+        unsigned int n = STARPU_VECTOR_GET_NX(buffers[0]);
         /* local copy of the vector pointer */
         float *val = (float *)STARPU_VECTOR_GET_PTR(buffers[0]);
         unsigned threads_per_block = 64;

+ 35 - 35
doc/tutorial/vector_scal_opencl.c

@@ -21,39 +21,39 @@ extern struct starpu_opencl_program programs;
 
 void vector_scal_opencl(void *buffers[], void *_args)
 {
-    float *factor = _args;
-    int id, devid, err;
-    cl_kernel kernel;
-    cl_command_queue queue;
-    cl_event event;
-
-    /* length of the vector */
-    unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
-    /* OpenCL copy of the vector pointer */
-    cl_mem val = (cl_mem) STARPU_VECTOR_GET_DEV_HANDLE(buffers[0]);
-
-    id = starpu_worker_get_id();
-    devid = starpu_worker_get_devid(id);
-
-    err = starpu_opencl_load_kernel(&kernel, &queue, &programs,
-                    "vector_mult_opencl", devid);   /* Name of the codelet defined above */
-    if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
-
-    err = clSetKernelArg(kernel, 0, sizeof(val), &val);
-    err |= clSetKernelArg(kernel, 1, sizeof(n), &n);
-    err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);
-    if (err) STARPU_OPENCL_REPORT_ERROR(err);
-
-    {
-        size_t global=1;
-        size_t local=1;
-        err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, &event);
-        if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
-    }
-
-    clFinish(queue);
-    starpu_opencl_collect_stats(event);
-    clReleaseEvent(event);
-
-    starpu_opencl_release_kernel(kernel);
+	float *factor = _args;
+	int id, devid, err;
+	cl_kernel kernel;
+	cl_command_queue queue;
+	cl_event event;
+
+	/* length of the vector */
+	unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
+	/* OpenCL copy of the vector pointer */
+	cl_mem val = (cl_mem) STARPU_VECTOR_GET_DEV_HANDLE(buffers[0]);
+
+	id = starpu_worker_get_id();
+	devid = starpu_worker_get_devid(id);
+
+	err = starpu_opencl_load_kernel(&kernel, &queue, &programs,
+					"vector_mult_opencl", devid);   /* Name of the codelet defined above */
+	if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
+
+	err = clSetKernelArg(kernel, 0, sizeof(val), &val);
+	err |= clSetKernelArg(kernel, 1, sizeof(n), &n);
+	err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);
+	if (err) STARPU_OPENCL_REPORT_ERROR(err);
+
+	{
+		size_t global=1;
+		size_t local=1;
+		err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, &event);
+		if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
+	}
+
+	clFinish(queue);
+	starpu_opencl_collect_stats(event);
+	clReleaseEvent(event);
+
+	starpu_opencl_release_kernel(kernel);
 }