block_interface.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #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. static 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. .handle = &block_handle,
  44. .dummy_handle = &block2_handle,
  45. .copy_failed = 0,
  46. .name = "block_interface"
  47. };
  48. static int block[NX*NY*NZ];
  49. static int block2[NX*NY*NZ];
  50. static void
  51. register_data(void)
  52. {
  53. /* Initializing data */
  54. int val = 0;
  55. int i, j, k;
  56. for (k = 0; k < NZ; k++)
  57. for (j = 0; j < NY; j++)
  58. for (i = 0; i < NX; i++)
  59. block[(k*NX*NY)+(j*NX)+i] = val++;
  60. /* Registering data */
  61. starpu_block_data_register(&block_handle,
  62. 0,
  63. (uintptr_t)block,
  64. NX,
  65. NX * NY,
  66. NX,
  67. NY,
  68. NZ,
  69. sizeof(block[0]));
  70. starpu_block_data_register(&block2_handle,
  71. 0,
  72. (uintptr_t)block2,
  73. NX,
  74. NX * NY,
  75. NX,
  76. NY,
  77. NZ,
  78. sizeof(block2[0]));
  79. }
  80. static void
  81. unregister_data(void)
  82. {
  83. starpu_data_unregister(block_handle);
  84. starpu_data_unregister(block2_handle);
  85. }
  86. static void test_block_cpu_func(void *buffers[], void *args)
  87. {
  88. int factor = *(int*)args;
  89. int nx = STARPU_BLOCK_GET_NX(buffers[0]);
  90. int ny = STARPU_BLOCK_GET_NY(buffers[0]);
  91. int nz = STARPU_BLOCK_GET_NZ(buffers[0]);
  92. unsigned ldy = STARPU_BLOCK_GET_LDY(buffers[0]);
  93. unsigned ldz = STARPU_BLOCK_GET_LDZ(buffers[0]);
  94. int *block = (int *) STARPU_BLOCK_GET_PTR(buffers[0]);
  95. unsigned int i, j, k;
  96. int val = 0;
  97. block_config.copy_failed = 0;
  98. for (k = 0; k < nz; k++)
  99. {
  100. for (j = 0; j < ny; j++)
  101. {
  102. for (i = 0; i < nx; i++)
  103. {
  104. if (block[(k*ldz)+(j*ldy)+i] != factor * val)
  105. {
  106. block_config.copy_failed = 1;
  107. return;
  108. }
  109. else
  110. {
  111. block[(k*ldz)+(j*ldy)+i] *= -1;
  112. val++;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. int
  119. main(void)
  120. {
  121. data_interface_test_summary *summary;
  122. struct starpu_conf conf =
  123. {
  124. .ncpus = -1,
  125. .ncuda = 2,
  126. .nopencl = 1
  127. };
  128. if (starpu_init(&conf) == -ENODEV)
  129. goto enodev;
  130. register_data();
  131. summary = run_tests(&block_config);
  132. if (!summary)
  133. exit(EXIT_FAILURE);
  134. unregister_data();
  135. starpu_shutdown();
  136. data_interface_test_summary_print(stderr, summary);
  137. return data_interface_test_summary_success(summary);
  138. enodev:
  139. return STARPU_TEST_SKIPPED;
  140. }