variable_interface.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2012,2015,2017 CNRS
  5. * Copyright (C) 2012,2013 Université de Bordeaux
  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. #include "../test_interfaces.h"
  20. static int variable;
  21. static int variable2;
  22. static starpu_data_handle_t variable_handle;
  23. static starpu_data_handle_t variable2_handle;
  24. /* Codelets */
  25. #if defined(STARPU_USE_CPU) || defined(STARPU_USE_MIC)
  26. void test_variable_cpu_func(void *buffers[], void *args);
  27. #endif
  28. #ifdef STARPU_USE_CUDA
  29. extern void test_variable_cuda_func(void *buffers[], void *args);
  30. #endif
  31. #ifdef STARPU_USE_OPENCL
  32. extern void test_variable_opencl_func(void *buffers[], void *args);
  33. #endif
  34. struct test_config variable_config =
  35. {
  36. #ifdef STARPU_USE_CPU
  37. .cpu_func = test_variable_cpu_func,
  38. #endif
  39. #ifdef STARPU_USE_CUDA
  40. .cuda_func = test_variable_cuda_func,
  41. #endif
  42. #ifdef STARPU_USE_OPENCL
  43. .opencl_func = test_variable_opencl_func,
  44. #endif
  45. #ifdef STARPU_USE_MIC
  46. .cpu_func_name = "test_variable_cpu_func",
  47. #endif
  48. .handle = &variable_handle,
  49. .dummy_handle = &variable2_handle,
  50. .copy_failed = SUCCESS,
  51. .name = "variable_interface"
  52. };
  53. void
  54. test_variable_cpu_func(void *buffers[], void *args)
  55. {
  56. STARPU_SKIP_IF_VALGRIND;
  57. int *val;
  58. int factor;
  59. val = (int *) STARPU_VARIABLE_GET_PTR(buffers[0]);
  60. factor = *(int *)args;
  61. if (*val != 42 * factor)
  62. variable_config.copy_failed = FAILURE;
  63. else
  64. *val *= -1;
  65. }
  66. static
  67. void register_data(void)
  68. {
  69. variable = 42;
  70. variable2 = 12;
  71. starpu_variable_data_register(&variable_handle, STARPU_MAIN_RAM,
  72. (uintptr_t) &variable, sizeof(variable));
  73. starpu_variable_data_register(&variable2_handle, STARPU_MAIN_RAM,
  74. (uintptr_t) &variable2, sizeof(variable2));
  75. }
  76. static
  77. void unregister_data(void)
  78. {
  79. starpu_data_unregister(variable_handle);
  80. starpu_data_unregister(variable2_handle);
  81. }
  82. int
  83. main(int argc, char **argv)
  84. {
  85. int ret;
  86. data_interface_test_summary *summary;
  87. struct starpu_conf conf;
  88. starpu_conf_init(&conf);
  89. conf.ncuda = 2;
  90. conf.nopencl = 1;
  91. conf.nmic = -1;
  92. ret = starpu_initialize(&conf, &argc, &argv);
  93. if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0)
  94. return STARPU_TEST_SKIPPED;
  95. register_data();
  96. summary = run_tests(&variable_config);
  97. if (!summary)
  98. exit(EXIT_FAILURE);
  99. unregister_data();
  100. starpu_shutdown();
  101. data_interface_test_summary_print(stderr, summary);
  102. return data_interface_test_summary_success(summary);
  103. }