123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /* StarPU --- Runtime system for heterogeneous multicore architectures.
- *
- * Copyright (C) 2010-2011 Université de Bordeaux 1
- * 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
- * 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>
- #include "../common/helper.h"
- #define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
- static unsigned nloops = 1000;
- static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
- {
- }
- static starpu_codelet cpu_codelet =
- {
- .where = STARPU_CPU,
- .cpu_func = dummy_func,
- .model = NULL,
- .nbuffers = 1
- };
- static starpu_codelet gpu_codelet =
- {
- .where = STARPU_CUDA|STARPU_OPENCL,
- .cuda_func = dummy_func,
- .opencl_func = dummy_func,
- .model = NULL,
- .nbuffers = 1
- };
- int main(int argc, char **argv)
- {
- float foo;
- starpu_data_handle float_array_handle;
- int i, ret;
- ret = starpu_init(NULL);
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
- if (starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) == 0 && starpu_worker_get_count_by_type(STARPU_OPENCL_WORKER) == 0)
- {
- FPRINTF(stderr, "This application requires a CUDA or OpenCL Worker\n");
- starpu_shutdown();
- return 77;
- }
- foo = 0.0f;
- starpu_variable_data_register(&float_array_handle, 0, (uintptr_t)&foo, sizeof(foo));
- for (i = 0; i < nloops; i++)
- {
- struct starpu_task *task_cpu, *task_gpu;
- int ret;
- task_cpu = starpu_task_create();
- task_gpu = starpu_task_create();
- task_cpu->cl = &cpu_codelet;
- task_cpu->callback_func = NULL;
- task_cpu->buffers[0].handle = float_array_handle;
- task_cpu->buffers[0].mode = STARPU_RW;
- task_gpu->cl = &gpu_codelet;
- task_gpu->callback_func = NULL;
- task_gpu->buffers[0].handle = float_array_handle;
- task_gpu->buffers[0].mode = STARPU_RW;
- ret = starpu_task_submit(task_cpu);
- if (ret == -ENODEV) goto enodev;
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
- ret = starpu_task_submit(task_gpu);
- if (ret == -ENODEV) goto enodev;
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
- }
- ret = starpu_task_wait_for_all();
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
- starpu_data_unregister(float_array_handle);
- starpu_shutdown();
- return 0;
- enodev:
- starpu_data_unregister(float_array_handle);
- fprintf(stderr, "WARNING: No one can execute this task\n");
- /* 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 */
- starpu_shutdown();
- return 77;
- }
|