Просмотр исходного кода

OpenCL Driver: update functions to compile opencl kernel

   Functions starpu_opencl_load_opencl_from_file() and
   starpu_opencl_load_opencl_from_string() have an extra parameter
   'const char* build_options' which can be used to give options to
   the OpenCL library when building the kernel. When set to NULL, the
   default value is '-Werror -cl-mad-enable'.

   Thanks to Jonathan Adamczewski for his feedback on this
   functionnality.
Nathalie Furmento лет назад: 14
Родитель
Сommit
51b04ba8f9

+ 4 - 3
doc/starpu.texi

@@ -926,7 +926,8 @@ int main(int argc, char **argv)
 
 #ifdef STARPU_USE_OPENCL
     starpu_opencl_load_opencl_from_file(
-            "examples/basic_examples/vector_scal_opencl_codelet.cl", &programs);
+            "examples/basic_examples/vector_scal_opencl_codelet.cl",
+            &programs, NULL);
 #endif
 
     vector = malloc(NX*sizeof(vector[0]));
@@ -4190,7 +4191,7 @@ relocation purpose for instance).
 @item @emph{Description}:
 TODO
 @item @emph{Prototype}:
-@code{int starpu_opencl_load_opencl_from_file(char *source_file_name, struct starpu_opencl_program *opencl_programs);}
+@code{int starpu_opencl_load_opencl_from_file(char *source_file_name, struct starpu_opencl_program *opencl_programs, const char* build_options);}
 @end table
 
 @node starpu_opencl_load_opencl_from_string
@@ -4199,7 +4200,7 @@ TODO
 @item @emph{Description}:
 TODO
 @item @emph{Prototype}:
-@code{int starpu_opencl_load_opencl_from_string(char *opencl_program_source, struct starpu_opencl_program *opencl_programs);}
+@code{int starpu_opencl_load_opencl_from_string(char *opencl_program_source, struct starpu_opencl_program *opencl_programs, const char* build_options);}
 @end table
 
 @node starpu_opencl_unload_opencl

+ 1 - 1
doc/vector_scal_c.texi

@@ -49,7 +49,7 @@ int main(int argc, char **argv)
 
 #ifdef STARPU_USE_OPENCL
         starpu_opencl_load_opencl_from_file(
-               "examples/basic_examples/vector_scal_opencl_kernel.cl", &programs);
+               "examples/basic_examples/vector_scal_opencl_kernel.cl", &programs, NULL);
 #endif
 
     /* Tell StaPU to associate the "vector" vector with the "vector_handle"

+ 1 - 1
examples/basic_examples/block.c

@@ -100,7 +100,7 @@ int main(int argc, char **argv)
         ret = execute_on(STARPU_CPU, cpu_codelet, block, nx, ny, nz, 1.0);
         if (!ret) multiplier *= 1.0;
 #ifdef STARPU_USE_OPENCL
-        starpu_opencl_load_opencl_from_file("examples/basic_examples/block_opencl_kernel.cl", &opencl_code);
+        starpu_opencl_load_opencl_from_file("examples/basic_examples/block_opencl_kernel.cl", &opencl_code, NULL);
         ret = execute_on(STARPU_OPENCL, opencl_codelet, block, nx, ny, nz, 2.0);
         if (!ret) multiplier *= 2.0;
 #endif

+ 1 - 1
examples/basic_examples/variable.c

@@ -50,7 +50,7 @@ int main(int argc, char **argv)
                                       (uintptr_t)&foo, sizeof(float));
 
 #ifdef STARPU_USE_OPENCL
-        starpu_opencl_load_opencl_from_file("examples/basic_examples/variable_kernels_opencl_kernel.cl", &opencl_program);
+        starpu_opencl_load_opencl_from_file("examples/basic_examples/variable_kernels_opencl_kernel.cl", &opencl_program, NULL);
 #endif
 
 	cl.where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL;

+ 1 - 1
examples/basic_examples/vector_scal.c

@@ -81,7 +81,7 @@ int main(int argc, char **argv)
 
 #ifdef STARPU_USE_OPENCL
 	starpu_opencl_load_opencl_from_file("examples/basic_examples/vector_scal_opencl_kernel.cl",
-					    &opencl_program);
+					    &opencl_program, NULL);
 #endif
 
 	/* Tell StaPU to associate the "vector" vector with the "vector_handle"

+ 1 - 1
examples/filters/fblock.c

@@ -98,7 +98,7 @@ int main(int argc, char **argv)
         starpu_init(NULL);
 
 #ifdef STARPU_USE_OPENCL
-        starpu_opencl_load_opencl_from_file("examples/filters/fblock_opencl_kernel.cl", &opencl_program);
+        starpu_opencl_load_opencl_from_file("examples/filters/fblock_opencl_kernel.cl", &opencl_program, NULL);
 #endif
 
         /* Declare data to StarPU */

+ 1 - 1
examples/incrementer/incrementer.c

@@ -53,7 +53,7 @@ int main(int argc, char **argv)
 			(uintptr_t)&float_array, 4, sizeof(float));
 
 #ifdef STARPU_USE_OPENCL
-        starpu_opencl_load_opencl_from_file("examples/incrementer/incrementer_kernels_opencl_kernel.cl", &opencl_program);
+        starpu_opencl_load_opencl_from_file("examples/incrementer/incrementer_kernels_opencl_kernel.cl", &opencl_program, NULL);
 #endif
 
 	starpu_codelet cl =

+ 2 - 2
examples/mandelbrot/mandelbrot.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010, 2011  Université de Bordeaux 1
- * Copyright (C) 2010  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -472,7 +472,7 @@ int main(int argc, char **argv)
 	STARPU_ASSERT((height % nblocks) == 0);
 
 #ifdef STARPU_USE_OPENCL
-	starpu_opencl_load_opencl_from_string(mandelbrot_opencl_src, &opencl_programs);
+	starpu_opencl_load_opencl_from_string(mandelbrot_opencl_src, &opencl_programs, NULL);
 #endif
 
 	starpu_data_handle block_handles[nblocks];

+ 1 - 1
examples/matvecmult/matvecmult.c

@@ -159,7 +159,7 @@ int main(int argc, char **argv)
 	starpu_vector_data_register(&mult_handle, 0, (uintptr_t)mult, height, sizeof(float));
 
 #ifdef STARPU_USE_OPENCL
-        starpu_opencl_load_opencl_from_file("examples/matvecmult/matvecmult_kernel.cl", &opencl_code);
+        starpu_opencl_load_opencl_from_file("examples/matvecmult/matvecmult_kernel.cl", &opencl_code, NULL);
 #endif
 
 	cl.where = STARPU_OPENCL;

+ 1 - 1
examples/spmv/dw_spmv.c

@@ -257,7 +257,7 @@ void call_spmv_codelet_filters(void)
 
 #ifdef STARPU_USE_OPENCL
         {
-                int ret = starpu_opencl_load_opencl_from_file("examples/spmv/spmv_opencl.cl", &opencl_codelet);
+                int ret = starpu_opencl_load_opencl_from_file("examples/spmv/spmv_opencl.cl", &opencl_codelet, NULL);
                 if (ret)
 		{
 			FPRINTF(stderr, "Failed to compile OpenCL codelet\n");

+ 1 - 1
examples/stencil/life_opencl.c

@@ -67,7 +67,7 @@ static struct starpu_opencl_program program;
 
 void
 opencl_life_init(void) {
-  starpu_opencl_load_opencl_from_string(src, &program);
+  starpu_opencl_load_opencl_from_string(src, &program, NULL);
 }
 
 void opencl_life_free(void) {

+ 1 - 1
examples/stencil/shadow_opencl.c

@@ -67,7 +67,7 @@ static struct starpu_opencl_program program;
 
 void
 opencl_shadow_init(void) {
-  starpu_opencl_load_opencl_from_string(src, &program);
+  starpu_opencl_load_opencl_from_string(src, &program, NULL);
 }
 
 void opencl_shadow_free(void) {

+ 5 - 3
include/starpu_opencl.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010, 2011  Université de Bordeaux 1
- * Copyright (C) 2010  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -194,8 +194,10 @@ void starpu_opencl_get_queue(int devid, cl_command_queue *queue);
 void starpu_opencl_get_current_context(cl_context *context);
 void starpu_opencl_get_current_queue(cl_command_queue *queue);
 
-int starpu_opencl_load_opencl_from_file(const char *source_file_name, struct starpu_opencl_program *opencl_programs);
-int starpu_opencl_load_opencl_from_string(const char *opencl_program_source, struct starpu_opencl_program *opencl_programs);
+int starpu_opencl_load_opencl_from_file(const char *source_file_name, struct starpu_opencl_program *opencl_programs,
+					const char* build_options);
+int starpu_opencl_load_opencl_from_string(const char *opencl_program_source, struct starpu_opencl_program *opencl_programs,
+					  const char* build_options);
 int starpu_opencl_unload_opencl(struct starpu_opencl_program *opencl_programs);
 
 int starpu_opencl_load_kernel(cl_kernel *kernel, cl_command_queue *queue, struct starpu_opencl_program *opencl_programs, const char *kernel_name, int devid);

+ 9 - 4
src/drivers/opencl/driver_opencl_utils.c

@@ -121,7 +121,8 @@ char *_starpu_opencl_load_program_source(const char *filename)
         return source;
 }
 
-int starpu_opencl_load_opencl_from_string(const char *opencl_program_source, struct starpu_opencl_program *opencl_programs)
+int starpu_opencl_load_opencl_from_string(const char *opencl_program_source, struct starpu_opencl_program *opencl_programs,
+					  const char* build_options)
 {
         unsigned int dev;
         unsigned int nb_devices;
@@ -150,7 +151,10 @@ int starpu_opencl_load_opencl_from_string(const char *opencl_program_source, str
                 if (!program || err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
 
                 // Build the program executable
-                err = clBuildProgram(program, 1, &device, "-Werror -cl-mad-enable", NULL, NULL);
+		if (build_options)
+			err = clBuildProgram(program, 1, &device, build_options, NULL, NULL);
+		else
+			err = clBuildProgram(program, 1, &device, "-Werror -cl-mad-enable", NULL, NULL);
                 if (err != CL_SUCCESS) {
                         size_t len;
                         static char buffer[4096];
@@ -168,7 +172,8 @@ int starpu_opencl_load_opencl_from_string(const char *opencl_program_source, str
         return EXIT_SUCCESS;
 }
 
-int starpu_opencl_load_opencl_from_file(const char *source_file_name, struct starpu_opencl_program *opencl_programs)
+int starpu_opencl_load_opencl_from_file(const char *source_file_name, struct starpu_opencl_program *opencl_programs,
+					const char* build_options)
 {
 	int nb_devices;
         char located_file_name[1024];
@@ -186,7 +191,7 @@ int starpu_opencl_load_opencl_from_file(const char *source_file_name, struct sta
         if(!opencl_program_source)
                 _STARPU_ERROR("Failed to load compute program from file <%s>!\n", located_file_name);
 
-        return starpu_opencl_load_opencl_from_string(opencl_program_source, opencl_programs);
+        return starpu_opencl_load_opencl_from_string(opencl_program_source, opencl_programs, build_options);
 }
 
 cl_int starpu_opencl_unload_opencl(struct starpu_opencl_program *opencl_programs)

+ 1 - 1
tests/datawizard/sync_and_notify_data.c

@@ -90,7 +90,7 @@ int main(int argc, char **argv)
 #endif
 
 #ifdef STARPU_USE_OPENCL
-        starpu_opencl_load_opencl_from_file("tests/datawizard/sync_and_notify_data_opencl_codelet.cl", &opencl_code);
+        starpu_opencl_load_opencl_from_file("tests/datawizard/sync_and_notify_data_opencl_codelet.cl", &opencl_code, NULLx);
 #endif
 
         starpu_vector_data_register(&v_handle, 0, (uintptr_t)v, VECTORSIZE, sizeof(unsigned));

+ 1 - 1
tests/datawizard/sync_and_notify_data_implicit.c

@@ -124,7 +124,7 @@ int main(int argc, char **argv)
 #endif
 
 #ifdef STARPU_USE_OPENCL
-        starpu_opencl_load_opencl_from_file("tests/datawizard/sync_and_notify_data_opencl_codelet.cl", &opencl_code);
+        starpu_opencl_load_opencl_from_file("tests/datawizard/sync_and_notify_data_opencl_codelet.cl", &opencl_code, NULL);
 #endif
 
         starpu_vector_data_register(&v_handle, 0, (uintptr_t)v, VECTORSIZE, sizeof(unsigned));