vector_interface.c 3.3 KB

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