incrementer.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (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. #define NITER 50000
  19. #ifdef USE_CUDA
  20. extern void cuda_codelet(starpu_data_interface_t *buffers, __attribute__ ((unused)) void *_args);
  21. #endif
  22. extern void cuda_codelet_host(float *tab);
  23. void core_codelet(starpu_data_interface_t *buffers, __attribute__ ((unused)) void *_args)
  24. {
  25. float *val = (float *)buffers[0].vector.ptr;
  26. val[0] += 1.0f; val[1] += 1.0f;
  27. }
  28. int main(int argc, char **argv)
  29. {
  30. starpu_init(NULL);
  31. float float_array[3] __attribute__ ((aligned (16))) = { 0.0f, 0.0f, 0.0f};
  32. starpu_data_handle float_array_handle;
  33. starpu_register_vector_data(&float_array_handle, 0 /* home node */,
  34. (uintptr_t)&float_array, 3, sizeof(float));
  35. starpu_codelet cl =
  36. {
  37. /* CUBLAS stands for CUDA kernels controlled from the host */
  38. .where = CORE|CUDA,
  39. .core_func = core_codelet,
  40. #ifdef USE_CUDA
  41. .cuda_func = cuda_codelet,
  42. #endif
  43. .nbuffers = 1
  44. };
  45. unsigned i;
  46. for (i = 0; i < NITER; i++)
  47. {
  48. struct starpu_task *task = starpu_task_create();
  49. task->cl = &cl;
  50. task->callback_func = NULL;
  51. task->buffers[0].handle = float_array_handle;
  52. task->buffers[0].mode = STARPU_RW;
  53. int ret = starpu_submit_task(task);
  54. if (STARPU_UNLIKELY(ret == -ENODEV))
  55. {
  56. fprintf(stderr, "No worker may execute this task\n");
  57. exit(0);
  58. }
  59. }
  60. starpu_wait_all_tasks();
  61. /* update the array in RAM */
  62. starpu_sync_data_with_mem(float_array_handle, STARPU_R);
  63. fprintf(stderr, "array -> %f, %f, %f\n", float_array[0],
  64. float_array[1], float_array[2]);
  65. if (float_array[0] != float_array[1] + float_array[2])
  66. return 1;
  67. starpu_release_data_from_mem(float_array_handle);
  68. starpu_shutdown();
  69. return 0;
  70. }