block_interface.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #if STARPU_HAVE_VALGRIND_H
  18. #include <valgrind/valgrind.h>
  19. #endif
  20. #include <starpu.h>
  21. #include "../test_interfaces.h"
  22. #include "../../../helper.h"
  23. #define NX 16
  24. #define NY NX
  25. #define NZ NX
  26. /* Prototypes */
  27. static void register_data(void);
  28. static void unregister_data(void);
  29. static void test_block_cpu_func(void *buffers[], void *args);
  30. #ifdef STARPU_USE_CUDA
  31. extern void test_block_cuda_func(void *buffers[], void *_args);
  32. #endif
  33. #ifdef STARPU_USE_OPENCL
  34. extern void test_block_opencl_func(void *buffers[], void *args);
  35. #endif
  36. static starpu_data_handle_t block_handle;
  37. static starpu_data_handle_t block2_handle;
  38. struct test_config block_config =
  39. {
  40. .cpu_func = test_block_cpu_func,
  41. #ifdef STARPU_USE_CUDA
  42. .cuda_func = test_block_cuda_func,
  43. #endif
  44. #ifdef STARPU_USE_OPENCL
  45. .opencl_func = test_block_opencl_func,
  46. #endif
  47. .handle = &block_handle,
  48. .dummy_handle = &block2_handle,
  49. .copy_failed = 0,
  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. 0,
  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. 0,
  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. static 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. unsigned int i, j, k;
  101. int val = 0;
  102. block_config.copy_failed = 0;
  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 = 1;
  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(void)
  125. {
  126. data_interface_test_summary *summary;
  127. struct starpu_conf conf =
  128. {
  129. .ncpus = -1,
  130. .ncuda = 2,
  131. .nopencl = 1
  132. };
  133. if (starpu_init(&conf) == -ENODEV)
  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. }