variable.c 2.6 KB

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