vector_interface.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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 <starpu.h>
  17. #include "../test_interfaces.h"
  18. #include "../../../helper.h"
  19. /* Prototypes */
  20. static void register_data(void);
  21. static void unregister_data(void);
  22. void test_vector_cpu_func(void *buffers[], void *args);
  23. #ifdef STARPU_USE_CUDA
  24. extern void test_vector_cuda_func(void *buffers[], void *_args);
  25. #endif
  26. #ifdef STARPU_USE_OPENCL
  27. extern void test_vector_opencl_func(void *buffers[], void *args);
  28. #endif
  29. starpu_data_handle_t vector_handle;
  30. starpu_data_handle_t vector2_handle;
  31. struct test_config vector_config =
  32. {
  33. .cpu_func = test_vector_cpu_func,
  34. #ifdef STARPU_USE_CUDA
  35. .cuda_func = test_vector_cuda_func,
  36. #endif
  37. #ifdef STARPU_USE_OPENCL
  38. .opencl_func = test_vector_opencl_func,
  39. #endif
  40. #ifdef STARPU_USE_MIC
  41. .cpu_func_name = "test_vector_cpu_func",
  42. #endif
  43. .handle = &vector_handle,
  44. .dummy_handle = &vector2_handle,
  45. .copy_failed = SUCCESS,
  46. .name = "vector_interface"
  47. };
  48. #define VECTOR_SIZE 123
  49. static int vector[VECTOR_SIZE];
  50. static int vector2[VECTOR_SIZE];
  51. static void register_data(void)
  52. {
  53. /* Initializing data */
  54. int i;
  55. for (i = 0; i < VECTOR_SIZE; i++)
  56. vector[i] = i;
  57. /* Registering data */
  58. starpu_vector_data_register(&vector_handle,
  59. STARPU_MAIN_RAM,
  60. (uintptr_t)vector,
  61. VECTOR_SIZE,
  62. sizeof(int));
  63. starpu_vector_data_register(&vector2_handle,
  64. STARPU_MAIN_RAM,
  65. (uintptr_t)vector2,
  66. VECTOR_SIZE,
  67. sizeof(int));
  68. }
  69. static void unregister_data(void)
  70. {
  71. starpu_data_unregister(vector_handle);
  72. starpu_data_unregister(vector2_handle);
  73. }
  74. void test_vector_cpu_func(void *buffers[], void *args)
  75. {
  76. STARPU_SKIP_IF_VALGRIND;
  77. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  78. int *val = (int *) STARPU_VECTOR_GET_PTR(buffers[0]);
  79. int factor = *(int*)args;
  80. unsigned int i;
  81. for (i = 0; i < n; i++)
  82. {
  83. if (val[i] != (int)i*factor)
  84. {
  85. vector_config.copy_failed = FAILURE;
  86. return;
  87. }
  88. val[i] = -val[i];
  89. }
  90. }
  91. int main(int argc, char **argv)
  92. {
  93. struct data_interface_test_summary summary;
  94. struct starpu_conf conf;
  95. starpu_conf_init(&conf);
  96. conf.ncuda = 2;
  97. conf.nopencl = 1;
  98. conf.nmic = -1;
  99. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  100. goto enodev;
  101. register_data();
  102. run_tests(&vector_config, &summary);
  103. unregister_data();
  104. starpu_shutdown();
  105. data_interface_test_summary_print(stderr, &summary);
  106. return data_interface_test_summary_success(&summary);
  107. enodev:
  108. return STARPU_TEST_SKIPPED;
  109. }