Browse Source

merge fix

Andra Hugo 13 years ago
parent
commit
6b39de6779

+ 18 - 1
src/drivers/opencl/driver_opencl.c

@@ -347,13 +347,15 @@ void _starpu_opencl_init(void)
 	{
                 cl_platform_id platform_id[_STARPU_OPENCL_PLATFORM_MAX];
                 cl_uint nb_platforms;
-                cl_device_type device_type = CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR;
                 cl_int err;
                 unsigned int i;
+                cl_device_type device_type = CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR;
 
                 _STARPU_DEBUG("Initialising OpenCL\n");
 
                 // Get Platforms
+		if (starpu_get_env_number("STARPU_OPENCL_ON_CPUS") > 0)
+		     device_type |= CL_DEVICE_TYPE_CPU;
                 err = clGetPlatformIDs(_STARPU_OPENCL_PLATFORM_MAX, platform_id, &nb_platforms);
                 if (err != CL_SUCCESS) nb_platforms=0;
                 _STARPU_DEBUG("Platforms detected: %d\n", nb_platforms);
@@ -572,6 +574,21 @@ unsigned _starpu_opencl_get_device_count(void)
 	return nb_devices;
 }
 
+cl_device_type _starpu_opencl_get_device_type(int devid)
+{
+	int err;
+	cl_device_type type;
+
+	if (!init_done)
+		_starpu_opencl_init();
+
+	err = clGetDeviceInfo(devices[devid], CL_DEVICE_TYPE, sizeof(cl_device_type), &type, NULL);
+	if (err != CL_SUCCESS)
+		STARPU_OPENCL_REPORT_ERROR(err);
+
+	return type;
+}
+
 static int _starpu_opencl_execute_job(struct _starpu_job *j, struct _starpu_worker *args)
 {
 	int ret;

+ 2 - 0
src/drivers/opencl/driver_opencl.h

@@ -39,6 +39,8 @@ int _starpu_opencl_deinit_context(int devid);
 extern
 unsigned _starpu_opencl_get_device_count(void);
 
+extern
+cl_device_type _starpu_opencl_get_device_type(int devid);
 
 #if 0
 extern

+ 29 - 15
src/drivers/opencl/driver_opencl_utils.c

@@ -113,7 +113,7 @@ cl_int starpu_opencl_load_kernel(cl_kernel *kernel, cl_command_queue *queue, str
         program = opencl_programs->programs[devid];
         if (!program)
 	{
-                _STARPU_DISP("Program not available\n");
+                _STARPU_DISP("Program not available for device <%d>\n", devid);
                 return CL_INVALID_PROGRAM;
         }
 
@@ -200,17 +200,26 @@ int starpu_opencl_load_opencl_from_string(const char *opencl_program_source, str
 
                 // Build the program executable
                 err = clBuildProgram(program, 1, &device, build_options, NULL, NULL);
-                if (err != CL_SUCCESS)
-		{
-                        size_t len;
-                        static char buffer[4096];
 
-                        _STARPU_DISP("Error: Failed to build program executable!\n");
-                        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
+		// Get the status
+		{
+		     cl_build_status status;
+		     size_t len;
+		     static char buffer[4096] = "";
+
+		     clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
+		     if (len > 2)
+			  _STARPU_DISP("Compilation output\n%s\n", buffer);
+
+		     clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_STATUS, sizeof(status), &status, NULL);
+		     if (err != CL_SUCCESS || status != CL_BUILD_SUCCESS)
+		     {
+			  _STARPU_DISP("Error: Failed to build program executable!\n");
+			  _STARPU_DISP("clBuildProgram: %d - clGetProgramBuildInfo: %d\n", err, status);
+			  return EXIT_FAILURE;
+		     }
 
-                        _STARPU_DISP("<%s>\n", buffer);
-                        return EXIT_FAILURE;
-                }
+		}
 
                 // Store program
                 opencl_programs->programs[dev] = program;
@@ -251,22 +260,27 @@ int starpu_opencl_load_opencl_from_file(const char *source_file_name, struct sta
         return starpu_opencl_load_opencl_from_string(opencl_program_source, opencl_programs, new_build_options);
 }
 
-cl_int starpu_opencl_unload_opencl(struct starpu_opencl_program *opencl_programs)
+int starpu_opencl_unload_opencl(struct starpu_opencl_program *opencl_programs)
 {
         unsigned int dev;
         unsigned int nb_devices;
 
 	if (!starpu_opencl_worker_get_count())
-		return CL_SUCCESS;
+		return 0;
 
         nb_devices = _starpu_opencl_get_device_count();
         // Iterate over each device
         for(dev = 0; dev < nb_devices; dev ++)
 	{
-                if (opencl_programs->programs[dev])
-                        clReleaseProgram(opencl_programs->programs[dev]);
+		if (opencl_programs->programs[dev])
+		{
+			cl_int err;
+			err = clReleaseProgram(opencl_programs->programs[dev]);
+			if (err != CL_SUCCESS)
+				STARPU_OPENCL_REPORT_ERROR(err);
+		}
         }
-        return CL_SUCCESS;
+        return 0;
 }
 
 int starpu_opencl_collect_stats(cl_event event STARPU_ATTRIBUTE_UNUSED)

+ 2 - 1
tests/datawizard/mpi_like.c

@@ -224,7 +224,8 @@ int main(int argc, char **argv)
 	}
 
 #ifdef STARPU_USE_OPENCL
-        starpu_opencl_unload_opencl(&opencl_program);
+        ret = starpu_opencl_unload_opencl(&opencl_program);
+        STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
 #endif
 	starpu_shutdown();
 

+ 2 - 1
tests/datawizard/mpi_like_async.c

@@ -390,7 +390,8 @@ int main(int argc, char **argv)
 	}
 
 #ifdef STARPU_USE_OPENCL
-        starpu_opencl_unload_opencl(&opencl_program);
+        ret = starpu_opencl_unload_opencl(&opencl_program);
+        STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
 #endif
 	starpu_shutdown();
 

+ 74 - 0
tests/datawizard/readonly.c

@@ -0,0 +1,74 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2010  Université de Bordeaux 1
+ * Copyright (C) 2010, 2011, 2012  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
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU 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>
+#ifdef STARPU_USE_OPENCL
+#include <starpu_opencl.h>
+#endif
+#include "../helper.h"
+
+static void codelet(void *descr[], __attribute__ ((unused)) void *_args)
+{
+     FPRINTF(stderr, "codelet\n");
+}
+
+static struct starpu_codelet cl =
+{
+#ifdef STARPU_USE_OPENCL
+     .opencl_funcs = {codelet, NULL},
+#endif
+     .nbuffers = 1,
+     .modes = {STARPU_R}
+};
+
+int main(int argc, char **argv)
+{
+     int ret;
+     int var = 42;
+     starpu_data_handle_t handle;
+
+     ret = starpu_init(NULL);
+     if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
+     STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+
+     int copy = starpu_disable_asynchronous_copy();
+     FPRINTF(stderr, "copy %d\n", copy);
+
+     starpu_variable_data_register(&handle, 0, (uintptr_t)&var, sizeof(var));
+
+     ret = starpu_insert_task(&cl,
+			      STARPU_R, handle,
+			      0);
+     if (ret == -ENODEV) goto enodev;
+     STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
+
+     starpu_task_wait_for_all();
+
+     starpu_data_unregister(handle);
+
+     starpu_shutdown();
+
+     return 0;
+
+enodev:
+     starpu_data_unregister(handle);
+     starpu_shutdown();
+     /* yes, we do not perform the computation but we did detect that no one
+      * could perform the kernel, so this is not an error from StarPU */
+     fprintf(stderr, "WARNING: No one can execute this task\n");
+     return STARPU_TEST_SKIPPED;
+}