variable.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011, 2013, 2015-2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2017 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 <starpu.h>
  18. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  19. #ifdef STARPU_QUICK_CHECK
  20. static unsigned niter = 500;
  21. #elif !defined(STARPU_LONG_CHECK)
  22. static unsigned niter = 5000;
  23. #else
  24. static unsigned niter = 50000;
  25. #endif
  26. extern void cpu_codelet(void *descr[], void *_args);
  27. #ifdef STARPU_USE_CUDA
  28. extern void cuda_codelet(void *descr[], void *_args);
  29. #endif
  30. #ifdef STARPU_USE_OPENCL
  31. extern void opencl_codelet(void *descr[], void *_args);
  32. struct starpu_opencl_program opencl_program;
  33. #endif
  34. int main(int argc, char **argv)
  35. {
  36. unsigned i;
  37. float foo;
  38. starpu_data_handle_t float_array_handle;
  39. struct starpu_codelet cl;
  40. int ret;
  41. ret = starpu_init(NULL);
  42. if (ret == -ENODEV) goto enodev;
  43. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  44. if (argc == 2) niter = atoi(argv[1]);
  45. foo = 0.0f;
  46. starpu_variable_data_register(&float_array_handle, STARPU_MAIN_RAM /* home node */,
  47. (uintptr_t)&foo, sizeof(float));
  48. #ifdef STARPU_USE_OPENCL
  49. ret = starpu_opencl_load_opencl_from_file("examples/basic_examples/variable_kernels_opencl_kernel.cl", &opencl_program, NULL);
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  51. #endif
  52. starpu_codelet_init(&cl);
  53. cl.cpu_funcs[0] = cpu_codelet;
  54. cl.cpu_funcs_name[0] = "cpu_codelet";
  55. #ifdef STARPU_USE_CUDA
  56. cl.cuda_funcs[0] = cuda_codelet;
  57. #endif
  58. #ifdef STARPU_USE_OPENCL
  59. cl.opencl_funcs[0] = opencl_codelet;
  60. #endif
  61. cl.nbuffers = 1;
  62. cl.modes[0] = STARPU_RW;
  63. cl.model = NULL;
  64. cl.name = "variable_inc";
  65. for (i = 0; i < niter; i++)
  66. {
  67. struct starpu_task *task = starpu_task_create();
  68. task->cl = &cl;
  69. task->callback_func = NULL;
  70. task->handles[0] = float_array_handle;
  71. ret = starpu_task_submit(task);
  72. if (STARPU_UNLIKELY(ret == -ENODEV))
  73. {
  74. FPRINTF(stderr, "No worker may execute this task\n");
  75. starpu_data_unregister(float_array_handle);
  76. goto enodev;
  77. }
  78. }
  79. starpu_task_wait_for_all();
  80. /* update the array in RAM */
  81. starpu_data_unregister(float_array_handle);
  82. FPRINTF(stderr, "variable -> %f\n", foo);
  83. FPRINTF(stderr, "result is %scorrect\n", foo==niter?"":"IN");
  84. starpu_shutdown();
  85. return (foo == niter) ? EXIT_SUCCESS:EXIT_FAILURE;
  86. enodev:
  87. return 77;
  88. }