block_interface.c 3.8 KB

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