|
@@ -0,0 +1,242 @@
|
|
|
+#include <starpu.h>
|
|
|
+#include <pthread.h>
|
|
|
+#ifdef STARPU_USE_OPENCL
|
|
|
+#include <starpu_opencl.h>
|
|
|
+#endif
|
|
|
+
|
|
|
+#include "../../helper.h"
|
|
|
+
|
|
|
+/*
|
|
|
+ * Users can directly control drivers by using the starpu_driver* functions.
|
|
|
+ *
|
|
|
+ * This test makes sure that the starpu_driver_run function works for CPU, CUDA
|
|
|
+ * and OpenCL drivers, and that the starpu_drivers_request_termination function
|
|
|
+ * correctly shuts down all drivers.
|
|
|
+ *
|
|
|
+ * The test_* functions can return:
|
|
|
+ * - 0 (success)
|
|
|
+ * - 1 (failure)
|
|
|
+ * - STARPU_TEST_SKIPPED (non-critical errors)
|
|
|
+ */
|
|
|
+
|
|
|
+#if defined(STARPU_USE_CPU) || defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
|
|
|
+static void
|
|
|
+dummy(void *buffers[], void *args)
|
|
|
+{
|
|
|
+ (void) buffers;
|
|
|
+ (*(int *)args)++;
|
|
|
+}
|
|
|
+
|
|
|
+static struct starpu_codelet cl =
|
|
|
+{
|
|
|
+ .cpu_funcs = { dummy, NULL },
|
|
|
+ .cuda_funcs = { dummy, NULL },
|
|
|
+ .opencl_funcs = { dummy, NULL },
|
|
|
+ .nbuffers = 0
|
|
|
+};
|
|
|
+
|
|
|
+static void *
|
|
|
+run_driver(void *arg)
|
|
|
+{
|
|
|
+ struct starpu_driver *d = (struct starpu_driver *) arg;
|
|
|
+ int ret = starpu_driver_run(d);
|
|
|
+ STARPU_CHECK_RETURN_VALUE(ret, "starpu_driver_run");
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+#endif /* STARPU_USE_CPU || STARPU_USE_CUDA || STARPU_USE_OPENCL */
|
|
|
+
|
|
|
+#ifdef STARPU_USE_CPU
|
|
|
+static int
|
|
|
+test_cpu(void)
|
|
|
+{
|
|
|
+ int ret, var = 0;
|
|
|
+ static pthread_t driver_thread;
|
|
|
+ struct starpu_conf conf;
|
|
|
+ struct starpu_driver d =
|
|
|
+ {
|
|
|
+ .type = STARPU_CPU_WORKER,
|
|
|
+ .id.cpu_id = 0
|
|
|
+ };
|
|
|
+
|
|
|
+ starpu_conf_init(&conf);
|
|
|
+ conf.n_not_launched_drivers = 1;
|
|
|
+ conf.not_launched_drivers = &d;
|
|
|
+ conf.ncpus = 1;
|
|
|
+ ret = starpu_init(&conf);
|
|
|
+ if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0)
|
|
|
+ return STARPU_TEST_SKIPPED;
|
|
|
+
|
|
|
+ ret = pthread_create(&driver_thread, NULL, run_driver, &d);
|
|
|
+ if (ret != 0)
|
|
|
+ {
|
|
|
+ ret = 1;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ struct starpu_task *task;
|
|
|
+ task = starpu_task_create();
|
|
|
+ cl.where = STARPU_CPU;
|
|
|
+ task->cl = &cl;
|
|
|
+ task->cl_arg = &var;
|
|
|
+ task->synchronous = 1;
|
|
|
+ ret = starpu_task_submit(task);
|
|
|
+ if (ret == -ENODEV)
|
|
|
+ {
|
|
|
+ ret = STARPU_TEST_SKIPPED;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ FPRINTF(stderr, "[CPU] Var = %d\n", var);
|
|
|
+ ret = !!(var != 1);
|
|
|
+
|
|
|
+out:
|
|
|
+ starpu_drivers_request_termination();
|
|
|
+ if (pthread_join(driver_thread, NULL) != 0)
|
|
|
+ return 1;
|
|
|
+ starpu_shutdown();
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+#endif /* STARPU_USE_CPU */
|
|
|
+
|
|
|
+#ifdef STARPU_USE_CUDA
|
|
|
+static int
|
|
|
+test_cuda(void)
|
|
|
+{
|
|
|
+ int ret, var = 0;
|
|
|
+ static pthread_t driver_thread;
|
|
|
+ struct starpu_conf conf;
|
|
|
+ struct starpu_driver d =
|
|
|
+ {
|
|
|
+ .type = STARPU_CUDA_WORKER,
|
|
|
+ .id.cuda_id = 0
|
|
|
+ };
|
|
|
+
|
|
|
+ starpu_conf_init(&conf);
|
|
|
+ conf.n_not_launched_drivers = 1;
|
|
|
+ conf.not_launched_drivers = &d;
|
|
|
+ conf.ncuda = 1;
|
|
|
+ ret = starpu_init(&conf);
|
|
|
+ if (ret == -ENODEV || starpu_cuda_worker_get_count() == 0)
|
|
|
+ return STARPU_TEST_SKIPPED;
|
|
|
+
|
|
|
+ ret = pthread_create(&driver_thread, NULL, run_driver, &d);
|
|
|
+ if (ret == -1)
|
|
|
+ {
|
|
|
+ ret = 1;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ struct starpu_task *task;
|
|
|
+ task = starpu_task_create();
|
|
|
+ cl.where = STARPU_CUDA;
|
|
|
+ task->cl = &cl;
|
|
|
+ task->cl_arg = &var;
|
|
|
+ task->synchronous = 1;
|
|
|
+ ret = starpu_task_submit(task);
|
|
|
+ if (ret == -ENODEV)
|
|
|
+ {
|
|
|
+ ret = STARPU_TEST_SKIPPED;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ FPRINTF(stderr, "[CUDA] Var = %d\n", var);
|
|
|
+ ret = !!(var != 1);
|
|
|
+
|
|
|
+out:
|
|
|
+ starpu_drivers_request_termination();
|
|
|
+ if (pthread_join(driver_thread, NULL) != 0)
|
|
|
+ return 1;
|
|
|
+ starpu_shutdown();
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+#endif /* STARPU_USE_CUDA */
|
|
|
+
|
|
|
+#ifdef STARPU_USE_OPENCL
|
|
|
+static int
|
|
|
+test_opencl(void)
|
|
|
+{
|
|
|
+ int ret, var = 0;
|
|
|
+ static pthread_t driver_thread;
|
|
|
+ struct starpu_conf conf;
|
|
|
+
|
|
|
+ cl_int err;
|
|
|
+ cl_uint dummy;
|
|
|
+ cl_platform_id platform;
|
|
|
+ err = clGetPlatformIDs(1, &platform, &dummy);
|
|
|
+ if (err != CL_SUCCESS)
|
|
|
+ return STARPU_TEST_SKIPPED;
|
|
|
+
|
|
|
+ cl_device_id device_id;
|
|
|
+ int device_type = CL_DEVICE_TYPE_GPU; /* TODO Support CPU */
|
|
|
+ err = clGetDeviceIDs(platform, device_type, 1, &device_id, NULL);
|
|
|
+ if (err != CL_SUCCESS)
|
|
|
+ return STARPU_TEST_SKIPPED;
|
|
|
+
|
|
|
+ struct starpu_driver d =
|
|
|
+ {
|
|
|
+ .type = STARPU_OPENCL_WORKER,
|
|
|
+ .id.opencl_id = device_id
|
|
|
+ };
|
|
|
+
|
|
|
+ starpu_conf_init(&conf);
|
|
|
+ conf.n_not_launched_drivers = 1;
|
|
|
+ conf.not_launched_drivers = &d;
|
|
|
+ conf.ncuda = 0;
|
|
|
+ conf.nopencl = 1;
|
|
|
+ ret = starpu_init(&conf);
|
|
|
+ if (ret == -ENODEV || starpu_opencl_worker_get_count() == 0)
|
|
|
+ return STARPU_TEST_SKIPPED;
|
|
|
+
|
|
|
+ ret = pthread_create(&driver_thread, NULL, run_driver, &d);
|
|
|
+ if (ret == -1)
|
|
|
+ {
|
|
|
+ ret = 1;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ struct starpu_task *task;
|
|
|
+ task = starpu_task_create();
|
|
|
+ cl.where = STARPU_OPENCL;
|
|
|
+ task->cl = &cl;
|
|
|
+ task->cl_arg = &var;
|
|
|
+ task->synchronous = 1;
|
|
|
+ ret = starpu_task_submit(task);
|
|
|
+ if (ret == -ENODEV)
|
|
|
+ {
|
|
|
+ ret = STARPU_TEST_SKIPPED;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ FPRINTF(stderr, "[OpenCL] Var = %d\n", var);
|
|
|
+ ret = !!(var != 1);
|
|
|
+
|
|
|
+out:
|
|
|
+ starpu_drivers_request_termination();
|
|
|
+ if (pthread_join(driver_thread, NULL) != 0)
|
|
|
+ return 1;
|
|
|
+ starpu_shutdown();
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+#endif /* STARPU_USE_OPENCL */
|
|
|
+
|
|
|
+int
|
|
|
+main(void)
|
|
|
+{
|
|
|
+ int ret = STARPU_TEST_SKIPPED;
|
|
|
+#ifdef STARPU_USE_CPU
|
|
|
+ ret = test_cpu();
|
|
|
+ if (ret == 1)
|
|
|
+ return 1;
|
|
|
+#endif
|
|
|
+#ifdef STARPU_USE_CUDA
|
|
|
+ ret = test_cuda();
|
|
|
+ if (ret == 1)
|
|
|
+ return 1;
|
|
|
+#endif
|
|
|
+#ifdef STARPU_USE_OPENCL
|
|
|
+ ret = test_opencl();
|
|
|
+ if (ret == 1)
|
|
|
+ return 1;
|
|
|
+#endif
|
|
|
+ return ret;
|
|
|
+}
|