123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #include <starpu.h>
- #define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
- #warning todo: fix cuda and opencl
- void cpu_codelet(void *descr[], __attribute__ ((unused)) void *_args)
- {
- float *val = (float *)STARPU_VECTOR_GET_PTR(descr[0]);
- val[0] += 1.0f; val[1] += 1.0f;
- }
- int main(int argc, char **argv)
- {
- int ret = 0;
- starpu_data_handle_t float_array_handle;
- float float_array[4] __attribute__ ((aligned (16))) = { 0.0f, 0.0f, 0.0f, 0.0f};
- struct starpu_codelet cl;
- unsigned i;
- unsigned niter = 50;
- ret = starpu_init(NULL);
- if (ret == -ENODEV) return 77;
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
- starpu_vector_data_register(&float_array_handle, 0, (uintptr_t)&float_array, 4, sizeof(float));
- starpu_codelet_init(&cl);
- cl.where = STARPU_CPU;
- cl.cpu_funcs[0] = cpu_codelet;
- cl.nbuffers = 1;
- cl.modes[0] = STARPU_RW;
- for (i = 0; i < niter; i++)
- {
- ret = starpu_insert_task(&cl,
- STARPU_RW, float_array_handle,
- 0);
- if (STARPU_UNLIKELY(ret == -ENODEV))
- {
- FPRINTF(stderr, "No worker may execute this task\n");
- exit(77);
- }
- }
- starpu_task_wait_for_all();
-
- starpu_data_unregister(float_array_handle);
- FPRINTF(stderr, "array -> %f, %f, %f, %f\n", float_array[0],
- float_array[1], float_array[2], float_array[3]);
- if (float_array[0] != niter || float_array[0] != float_array[1] + float_array[2] + float_array[3])
- {
- FPRINTF(stderr, "Incorrect result\n");
- ret = 1;
- }
- starpu_shutdown();
- return ret;
- }
|