test_vector_interface.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2011-2013,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. #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. static starpu_data_handle_t vector_handle;
  32. static 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
  54. register_data(void)
  55. {
  56. /* Initializing data */
  57. int i;
  58. for (i = 0; i < VECTOR_SIZE; i++)
  59. vector[i] = i;
  60. /* Registering data */
  61. starpu_vector_data_register(&vector_handle,
  62. STARPU_MAIN_RAM,
  63. (uintptr_t)vector,
  64. VECTOR_SIZE,
  65. sizeof(int));
  66. starpu_vector_data_register(&vector2_handle,
  67. STARPU_MAIN_RAM,
  68. (uintptr_t)vector2,
  69. VECTOR_SIZE,
  70. sizeof(int));
  71. }
  72. static void
  73. unregister_data(void)
  74. {
  75. starpu_data_unregister(vector_handle);
  76. starpu_data_unregister(vector2_handle);
  77. }
  78. void test_vector_cpu_func(void *buffers[], void *args)
  79. {
  80. STARPU_SKIP_IF_VALGRIND;
  81. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  82. int *val = (int *) STARPU_VECTOR_GET_PTR(buffers[0]);
  83. int factor = *(int*)args;
  84. unsigned int i;
  85. for (i = 0; i < n; i++)
  86. {
  87. if (val[i] != (int)i*factor)
  88. {
  89. vector_config.copy_failed = FAILURE;
  90. return;
  91. }
  92. val[i] = -val[i];
  93. }
  94. }
  95. int
  96. main(int argc, char **argv)
  97. {
  98. data_interface_test_summary *summary;
  99. struct starpu_conf conf;
  100. starpu_conf_init(&conf);
  101. conf.ncuda = 2;
  102. conf.nopencl = 1;
  103. conf.nmic = -1;
  104. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  105. goto enodev;
  106. register_data();
  107. summary = run_tests(&vector_config);
  108. if (!summary)
  109. exit(EXIT_FAILURE);
  110. unregister_data();
  111. starpu_shutdown();
  112. data_interface_test_summary_print(stderr, summary);
  113. return data_interface_test_summary_success(summary);
  114. enodev:
  115. return STARPU_TEST_SKIPPED;
  116. }