variable.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include <pthread.h>
  18. static unsigned niter = 50000;
  19. extern void cpu_codelet(void *descr[], __attribute__ ((unused)) void *_args);
  20. #ifdef STARPU_USE_CUDA
  21. extern void cuda_codelet(void *descr[], __attribute__ ((unused)) void *_args);
  22. #endif
  23. #ifdef STARPU_USE_OPENCL
  24. #include <starpu_opencl.h>
  25. extern void opencl_codelet(void *descr[], __attribute__ ((unused)) void *_args);
  26. struct starpu_opencl_program opencl_code;
  27. #endif
  28. int main(int argc, char **argv)
  29. {
  30. unsigned i;
  31. float foo;
  32. starpu_data_handle float_array_handle;
  33. starpu_codelet cl;
  34. starpu_init(NULL);
  35. if (argc == 2) niter = atoi(argv[1]);
  36. foo = 0.0f;
  37. starpu_variable_data_register(&float_array_handle, 0 /* home node */,
  38. (uintptr_t)&foo, sizeof(float));
  39. #ifdef STARPU_USE_OPENCL
  40. starpu_opencl_load_opencl_from_file("examples/basic_examples/variable_kernels_opencl_codelet.cl", &opencl_code);
  41. #endif
  42. cl.where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL;
  43. cl.cpu_func = cpu_codelet;
  44. #ifdef STARPU_USE_CUDA
  45. cl.cuda_func = cuda_codelet;
  46. #endif
  47. #ifdef STARPU_USE_OPENCL
  48. cl.opencl_func = opencl_codelet;
  49. #endif
  50. cl.nbuffers = 1;
  51. cl.model = NULL;
  52. for (i = 0; i < niter; i++)
  53. {
  54. struct starpu_task *task = starpu_task_create();
  55. int ret;
  56. task->cl = &cl;
  57. task->callback_func = NULL;
  58. task->buffers[0].handle = float_array_handle;
  59. task->buffers[0].mode = STARPU_RW;
  60. ret = starpu_task_submit(task);
  61. if (STARPU_UNLIKELY(ret == -ENODEV))
  62. {
  63. fprintf(stderr, "No worker may execute this task\n");
  64. exit(0);
  65. }
  66. }
  67. starpu_task_wait_for_all();
  68. /* update the array in RAM */
  69. starpu_data_acquire(float_array_handle, STARPU_R);
  70. fprintf(stderr, "variable -> %f\n", foo);
  71. starpu_data_release(float_array_handle);
  72. starpu_shutdown();
  73. return 0;
  74. }