Procházet zdrojové kódy

examples/variable: reorganise source code

Nathalie Furmento před 15 roky
rodič
revize
04f934750e

+ 7 - 5
examples/Makefile.am

@@ -468,18 +468,20 @@ check_PROGRAMS +=				\
 examplebin_PROGRAMS +=				\
 	variable/variable
 
-variable_variable_SOURCES =	\
-	variable/variable.c
+variable_variable_SOURCES =			\
+	variable/variable.c			\
+	variable/variable_kernels_cpu.c
+
 if STARPU_USE_CUDA
-variable_variable_SOURCES +=	\
+variable_variable_SOURCES +=			\
 	variable/variable_kernels.cu
 endif
 if STARPU_USE_OPENCL
-variable_variable_SOURCES +=	\
+variable_variable_SOURCES +=			\
 	variable/variable_kernels_opencl.c
 endif
 
-nobase_STARPU_OPENCL_DATA_DATA += \
+nobase_STARPU_OPENCL_DATA_DATA += 		\
 	variable/variable_kernels_opencl_codelet.cl
 
 

+ 2 - 9
examples/variable/variable.c

@@ -19,6 +19,8 @@
 
 static unsigned niter = 50000;
 
+extern void cpu_codelet(void *descr[], __attribute__ ((unused)) void *_args);
+
 #ifdef STARPU_USE_CUDA
 extern void cuda_codelet(void *descr[], __attribute__ ((unused)) void *_args);
 #endif
@@ -29,15 +31,6 @@ extern void opencl_codelet(void *descr[], __attribute__ ((unused)) void *_args);
 struct starpu_opencl_program opencl_code;
 #endif
 
-extern void cuda_codelet_host(float *tab);
-
-void cpu_codelet(void *descr[], __attribute__ ((unused)) void *_args)
-{
-	float *val = (float *)STARPU_VECTOR_GET_PTR(descr[0]);
-
-	*val += 1.0f;
-}
-
 int main(int argc, char **argv)
 {
 	unsigned i;

+ 2 - 2
examples/variable/variable_kernels.cu

@@ -18,13 +18,13 @@
 
 static __global__ void cuda_variable(float * tab)
 {
-	*tab += 2;
+	*tab += 1.0;
 	return;
 }
 
 extern "C" void cuda_codelet(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
 {
-	float *val = (float *)STARPU_VECTOR_GET_PTR(descr[0]);
+	float *val = (float *)STARPU_VARIABLE_GET_PTR(descr[0]);
 
 	cuda_variable<<<1,1>>>(val);
 }

+ 25 - 0
examples/variable/variable_kernels_cpu.c

@@ -0,0 +1,25 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu.h>
+
+void cpu_codelet(void *descr[], __attribute__ ((unused)) void *_args)
+{
+	float *val = (float *)STARPU_VARIABLE_GET_PTR(descr[0]);
+
+	*val += 1.0f;
+}
+

+ 1 - 1
examples/variable/variable_kernels_opencl.c

@@ -20,7 +20,7 @@
 extern struct starpu_opencl_program opencl_code;
 void opencl_codelet(void *descr[], void *_args)
 {
-	float *val = (float *)STARPU_VECTOR_GET_PTR(descr[0]);
+	float *val = (float *)STARPU_VARIABLE_GET_PTR(descr[0]);
 	cl_kernel kernel;
 	cl_command_queue queue;
 	int id, devid, err;

+ 1 - 1
examples/variable/variable_kernels_opencl_codelet.cl

@@ -18,6 +18,6 @@ __kernel void variable(__global float* input)
 {
 	const int i = get_global_id(0);
 	if (i == 0)
-		input[i] = input[i] + 4.0;
+		input[i] = input[i] + 1.0;
 }