1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #include <starpu.h>
- #include <pthread.h>
- 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
- #ifdef STARPU_USE_OPENCL
- #include <starpu_opencl.h>
- extern void opencl_codelet(void *descr[], __attribute__ ((unused)) void *_args);
- struct starpu_opencl_program opencl_program;
- #endif
- int main(int argc, char **argv)
- {
- unsigned i;
- float foo;
- starpu_data_handle float_array_handle;
- starpu_codelet cl = {};
- starpu_init(NULL);
- if (argc == 2) niter = atoi(argv[1]);
- foo = 0.0f;
- starpu_variable_data_register(&float_array_handle, 0 ,
- (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);
- #endif
- cl.where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL;
- cl.cpu_func = cpu_codelet;
- #ifdef STARPU_USE_CUDA
- cl.cuda_func = cuda_codelet;
- #endif
- #ifdef STARPU_USE_OPENCL
- cl.opencl_func = opencl_codelet;
- #endif
- cl.nbuffers = 1;
- cl.model = NULL;
- for (i = 0; i < niter; i++)
- {
- struct starpu_task *task = starpu_task_create();
- int ret;
- task->cl = &cl;
- task->callback_func = NULL;
- task->buffers[0].handle = float_array_handle;
- task->buffers[0].mode = STARPU_RW;
- ret = starpu_task_submit(task);
- if (STARPU_UNLIKELY(ret == -ENODEV))
- {
- fprintf(stderr, "No worker may execute this task\n");
- exit(0);
- }
- }
- starpu_task_wait_for_all();
-
- starpu_data_acquire(float_array_handle, STARPU_R);
- fprintf(stderr, "variable -> %f\n", foo);
- starpu_data_release(float_array_handle);
- starpu_shutdown();
- return 0;
- }
|