test_vector_interface.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 vector_handle;
  29. struct test_config vector_config = {
  30. .cpu_func = test_vector_cpu_func,
  31. #ifdef STARPU_USE_CUDA
  32. .cuda_func = test_vector_cuda_func,
  33. #endif
  34. #ifdef STARPU_USE_OPENCL
  35. .opencl_func = test_vector_opencl_func,
  36. #endif
  37. .handle = &vector_handle,
  38. .copy_failed = 0,
  39. .name = "vector_interface"
  40. };
  41. #define VECTOR_SIZE 123
  42. static int vector[VECTOR_SIZE];
  43. static void
  44. register_data(void)
  45. {
  46. /* Initializing data */
  47. int i;
  48. for (i = 0; i < VECTOR_SIZE; i++)
  49. vector[i] = i;
  50. /* Registering data */
  51. starpu_vector_data_register(&vector_handle,
  52. 0,
  53. (uintptr_t)vector,
  54. VECTOR_SIZE,
  55. sizeof(int));
  56. }
  57. static void
  58. unregister_data(void)
  59. {
  60. starpu_data_unregister(vector_handle);
  61. }
  62. static void test_vector_cpu_func(void *buffers[], void *args)
  63. {
  64. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  65. int *val = (int *) STARPU_VECTOR_GET_PTR(buffers[0]);
  66. int factor = *(int*)args;
  67. unsigned int i;
  68. for (i = 0; i < n; i++) {
  69. if (val[i] != i*factor) {
  70. vector_config.copy_failed = 1;
  71. return;
  72. }
  73. val[i] = -val[i];
  74. }
  75. }
  76. int
  77. main(void)
  78. {
  79. data_interface_test_summary *summary;
  80. struct starpu_conf conf = {
  81. .ncpus = -1,
  82. .ncuda = 2,
  83. .nopencl = 1
  84. };
  85. starpu_init(&conf);
  86. register_data();
  87. summary = run_tests(&vector_config);
  88. if (!summary)
  89. exit(EXIT_FAILURE);
  90. unregister_data();
  91. starpu_shutdown();
  92. data_interface_test_summary_print(stderr, summary);
  93. return data_interface_test_summary_success(summary);
  94. }