variable.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2013 Inria
  4. * Copyright (C) 2010-2011,2013-2016 Université de Bordeaux
  5. * Copyright (C) 2010-2015,2017 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  20. #ifdef STARPU_QUICK_CHECK
  21. static unsigned niter = 500;
  22. #elif !defined(STARPU_LONG_CHECK)
  23. static unsigned niter = 5000;
  24. #else
  25. static unsigned niter = 50000;
  26. #endif
  27. extern void cpu_codelet(void *descr[], void *_args);
  28. #ifdef STARPU_USE_CUDA
  29. extern void cuda_codelet(void *descr[], void *_args);
  30. #endif
  31. #ifdef STARPU_USE_OPENCL
  32. extern void opencl_codelet(void *descr[], void *_args);
  33. struct starpu_opencl_program opencl_program;
  34. #endif
  35. int main(int argc, char **argv)
  36. {
  37. unsigned i;
  38. float foo;
  39. starpu_data_handle_t float_array_handle;
  40. struct starpu_codelet cl;
  41. int ret;
  42. ret = starpu_init(NULL);
  43. if (ret == -ENODEV) goto enodev;
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  45. if (argc == 2) niter = atoi(argv[1]);
  46. foo = 0.0f;
  47. starpu_variable_data_register(&float_array_handle, STARPU_MAIN_RAM /* home node */,
  48. (uintptr_t)&foo, sizeof(float));
  49. #ifdef STARPU_USE_OPENCL
  50. ret = starpu_opencl_load_opencl_from_file("examples/basic_examples/variable_kernels_opencl_kernel.cl", &opencl_program, NULL);
  51. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  52. #endif
  53. starpu_codelet_init(&cl);
  54. cl.cpu_funcs[0] = cpu_codelet;
  55. cl.cpu_funcs_name[0] = "cpu_codelet";
  56. #ifdef STARPU_USE_CUDA
  57. cl.cuda_funcs[0] = cuda_codelet;
  58. #endif
  59. #ifdef STARPU_USE_OPENCL
  60. cl.opencl_funcs[0] = opencl_codelet;
  61. #endif
  62. cl.nbuffers = 1;
  63. cl.modes[0] = STARPU_RW;
  64. cl.model = NULL;
  65. cl.name = "variable_inc";
  66. for (i = 0; i < niter; i++)
  67. {
  68. struct starpu_task *task = starpu_task_create();
  69. task->cl = &cl;
  70. task->callback_func = NULL;
  71. task->handles[0] = float_array_handle;
  72. ret = starpu_task_submit(task);
  73. if (STARPU_UNLIKELY(ret == -ENODEV))
  74. {
  75. FPRINTF(stderr, "No worker may execute this task\n");
  76. starpu_data_unregister(float_array_handle);
  77. goto enodev;
  78. }
  79. }
  80. starpu_task_wait_for_all();
  81. /* update the array in RAM */
  82. starpu_data_unregister(float_array_handle);
  83. FPRINTF(stderr, "variable -> %f\n", foo);
  84. FPRINTF(stderr, "result is %scorrect\n", foo==niter?"":"IN");
  85. starpu_shutdown();
  86. return (foo == niter) ? EXIT_SUCCESS:EXIT_FAILURE;
  87. enodev:
  88. return 77;
  89. }