block_interface.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2012-2013,2015,2017 CNRS
  5. * Copyright (C) 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. #define NX 16
  22. #define NY NX
  23. #define NZ NX
  24. /* Prototypes */
  25. static void register_data(void);
  26. static void unregister_data(void);
  27. void test_block_cpu_func(void *buffers[], void *args);
  28. #ifdef STARPU_USE_CUDA
  29. extern void test_block_cuda_func(void *buffers[], void *_args);
  30. #endif
  31. #ifdef STARPU_USE_OPENCL
  32. extern void test_block_opencl_func(void *buffers[], void *args);
  33. #endif
  34. static starpu_data_handle_t _block_handle;
  35. static starpu_data_handle_t _block2_handle;
  36. struct test_config block_config =
  37. {
  38. .cpu_func = test_block_cpu_func,
  39. #ifdef STARPU_USE_CUDA
  40. .cuda_func = test_block_cuda_func,
  41. #endif
  42. #ifdef STARPU_USE_OPENCL
  43. .opencl_func = test_block_opencl_func,
  44. #endif
  45. #ifdef STARPU_USE_MIC
  46. .cpu_func_name = "test_block_cpu_func",
  47. #endif
  48. .handle = &_block_handle,
  49. .dummy_handle = &_block2_handle,
  50. .copy_failed = SUCCESS,
  51. .name = "block_interface"
  52. };
  53. static int _block[NX*NY*NZ];
  54. static int _block2[NX*NY*NZ];
  55. static void
  56. register_data(void)
  57. {
  58. /* Initializing data */
  59. int val = 0;
  60. int i, j, k;
  61. for (k = 0; k < NZ; k++)
  62. for (j = 0; j < NY; j++)
  63. for (i = 0; i < NX; i++)
  64. _block[(k*NX*NY)+(j*NX)+i] = val++;
  65. /* Registering data */
  66. starpu_block_data_register(&_block_handle,
  67. STARPU_MAIN_RAM,
  68. (uintptr_t)_block,
  69. NX,
  70. NX * NY,
  71. NX,
  72. NY,
  73. NZ,
  74. sizeof(_block[0]));
  75. starpu_block_data_register(&_block2_handle,
  76. STARPU_MAIN_RAM,
  77. (uintptr_t)_block2,
  78. NX,
  79. NX * NY,
  80. NX,
  81. NY,
  82. NZ,
  83. sizeof(_block2[0]));
  84. }
  85. static void
  86. unregister_data(void)
  87. {
  88. starpu_data_unregister(_block_handle);
  89. starpu_data_unregister(_block2_handle);
  90. }
  91. void test_block_cpu_func(void *buffers[], void *args)
  92. {
  93. STARPU_SKIP_IF_VALGRIND;
  94. int factor = *(int*)args;
  95. int nx = STARPU_BLOCK_GET_NX(buffers[0]);
  96. int ny = STARPU_BLOCK_GET_NY(buffers[0]);
  97. int nz = STARPU_BLOCK_GET_NZ(buffers[0]);
  98. unsigned ldy = STARPU_BLOCK_GET_LDY(buffers[0]);
  99. unsigned ldz = STARPU_BLOCK_GET_LDZ(buffers[0]);
  100. int *block = (int *) STARPU_BLOCK_GET_PTR(buffers[0]);
  101. int i, j, k;
  102. int val = 0;
  103. block_config.copy_failed = SUCCESS;
  104. for (k = 0; k < nz; k++)
  105. {
  106. for (j = 0; j < ny; j++)
  107. {
  108. for (i = 0; i < nx; i++)
  109. {
  110. if (block[(k*ldz)+(j*ldy)+i] != factor * val)
  111. {
  112. block_config.copy_failed = FAILURE;
  113. return;
  114. }
  115. else
  116. {
  117. block[(k*ldz)+(j*ldy)+i] *= -1;
  118. val++;
  119. }
  120. }
  121. }
  122. }
  123. }
  124. int
  125. main(int argc, char **argv)
  126. {
  127. data_interface_test_summary *summary;
  128. struct starpu_conf conf;
  129. starpu_conf_init(&conf);
  130. conf.ncuda = 2;
  131. conf.nopencl = 1;
  132. conf.nmic = -1;
  133. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  134. goto enodev;
  135. register_data();
  136. summary = run_tests(&block_config);
  137. if (!summary)
  138. exit(EXIT_FAILURE);
  139. unregister_data();
  140. starpu_shutdown();
  141. data_interface_test_summary_print(stderr, summary);
  142. return data_interface_test_summary_success(summary);
  143. enodev:
  144. return STARPU_TEST_SKIPPED;
  145. }