test_vector_interface.c 3.2 KB

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