specific_node.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2014 Université de Bordeaux
  4. * Copyright (C) 2012, 2013, 2015 CNRS
  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 <config.h>
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <errno.h>
  21. #include <starpu.h>
  22. #include <stdlib.h>
  23. #include "../helper.h"
  24. starpu_data_handle_t data_handle;
  25. unsigned data;
  26. void specific_kernel(STARPU_ATTRIBUTE_UNUSED void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  27. {
  28. /* We do not protect this variable because it is only accessed when the
  29. * "data_handle" piece of data is accessed. */
  30. unsigned *dataptr = (unsigned*) STARPU_VARIABLE_GET_PTR(descr[0]);
  31. STARPU_ASSERT(dataptr == &data);
  32. (*dataptr)++;
  33. }
  34. static struct starpu_codelet specific_cl =
  35. {
  36. .cpu_funcs = {specific_kernel},
  37. .cuda_funcs = {specific_kernel},
  38. .opencl_funcs = {specific_kernel},
  39. .nbuffers = 1,
  40. .modes = {STARPU_RW},
  41. .specific_nodes = 1,
  42. .nodes = {STARPU_MAIN_RAM},
  43. };
  44. #ifdef STARPU_USE_CUDA
  45. void cuda_codelet_unsigned_inc(void *descr[], STARPU_ATTRIBUTE_UNUSED void *cl_arg);
  46. #endif
  47. #ifdef STARPU_USE_OPENCL
  48. void opencl_codelet_unsigned_inc(void *buffers[], void *args);
  49. #endif
  50. static struct starpu_codelet cl =
  51. {
  52. .cpu_funcs = {specific_kernel},
  53. #ifdef STARPU_USE_CUDA
  54. .cuda_funcs = {cuda_codelet_unsigned_inc},
  55. .cuda_flags = {STARPU_CUDA_ASYNC},
  56. #endif
  57. #ifdef STARPU_USE_OPENCL
  58. .opencl_funcs = {opencl_codelet_unsigned_inc},
  59. .opencl_flags = {STARPU_OPENCL_ASYNC},
  60. #endif
  61. .nbuffers = 1,
  62. .modes = {STARPU_RW},
  63. };
  64. #ifdef STARPU_USE_OPENCL
  65. struct starpu_opencl_program opencl_program;
  66. #endif
  67. int main(STARPU_ATTRIBUTE_UNUSED int argc, STARPU_ATTRIBUTE_UNUSED char **argv)
  68. {
  69. #ifdef STARPU_QUICK_CHECK
  70. unsigned ntasks = 10;
  71. #else
  72. unsigned ntasks = 1000;
  73. #endif
  74. int ret, ret2;
  75. ret = starpu_init(NULL);
  76. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  77. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  78. #ifdef STARPU_USE_OPENCL
  79. ret = starpu_opencl_load_opencl_from_file("tests/datawizard/opencl_codelet_unsigned_inc_kernel.cl",
  80. &opencl_program, NULL);
  81. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  82. #endif
  83. data = 0;
  84. /* Create a void data which will be used as an exclusion mechanism. */
  85. starpu_variable_data_register(&data_handle, STARPU_MAIN_RAM, (uintptr_t) &data, sizeof(data));
  86. unsigned i;
  87. for (i = 0; i < ntasks; i++)
  88. {
  89. struct starpu_task *task = starpu_task_create();
  90. if (i%2)
  91. task->cl = &specific_cl;
  92. else
  93. task->cl = &cl;
  94. task->handles[0] = data_handle;
  95. ret = starpu_task_submit(task);
  96. if (ret == -ENODEV) goto enodev;
  97. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  98. }
  99. starpu_data_unregister(data_handle);
  100. ret = (data == ntasks) ? EXIT_SUCCESS : EXIT_FAILURE;
  101. #ifdef STARPU_USE_OPENCL
  102. ret2 = starpu_opencl_unload_opencl(&opencl_program);
  103. STARPU_CHECK_RETURN_VALUE(ret2, "starpu_opencl_unload_opencl");
  104. #endif
  105. starpu_shutdown();
  106. return ret;
  107. enodev:
  108. fprintf(stderr, "WARNING: No one can execute this task\n");
  109. /* yes, we do not perform the computation but we did detect that no one
  110. * could perform the kernel, so this is not an error from StarPU */
  111. starpu_shutdown();
  112. return STARPU_TEST_SKIPPED;
  113. }