block_interface.c 3.9 KB

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