test_vector_interface.c 3.0 KB

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