variable_interface.c 2.9 KB

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