/* StarPU --- Runtime system for heterogeneous multicore architectures. * * Copyright (C) 2010, 2011 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 #include #include #include #define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0) extern void cpu_codelet(void *descr[], void *_args); #ifdef STARPU_USE_CUDA extern void cuda_codelet(void *descr[], void *_args); #endif #ifdef STARPU_USE_OPENCL extern void opencl_codelet(void *descr[], void *_args); struct starpu_opencl_program opencl_code; #endif typedef void (*device_func)(void **, void *); int execute_on(uint32_t where, device_func func, float *block, int pnx, int pny, int pnz, float multiplier) { struct starpu_codelet cl = {}; starpu_data_handle_t block_handle; int i; starpu_block_data_register(&block_handle, 0, (uintptr_t)block, pnx, pnx*pny, pnx, pny, pnz, sizeof(float)); cl.where = where; cl.cuda_funcs[0] = func; cl.cpu_funcs[0] = func; cl.opencl_funcs[0] = func; cl.nbuffers = 1; cl.modes[0] = STARPU_RW, cl.model = NULL; struct starpu_task *task = starpu_task_create(); task->cl = &cl; task->callback_func = NULL; task->handles[0] = block_handle; task->cl_arg = &multiplier; task->cl_arg_size = sizeof(multiplier); int ret = starpu_task_submit(task); if (STARPU_UNLIKELY(ret == -ENODEV)) { FPRINTF(stderr, "No worker may execute this task\n"); return 1; } starpu_task_wait_for_all(); /* update the array in RAM */ starpu_data_unregister(block_handle); for(i=0 ; i