disk_copy.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Corentin Salingue
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <unistd.h>
  21. #include <math.h>
  22. #include "../helper.h"
  23. /*
  24. * Try to write into disk memory
  25. * Use mechanism to push datas from main ram to disk ram
  26. * Here we make copies between buffers, that StarPU has to evict while
  27. * progressing because there is not enough room for all of them.
  28. */
  29. /* RAM is not enough to hold 6 times NX
  30. * DISK is just enough to hold 6 times NX */
  31. /* size of one vector */
  32. #ifdef STARPU_QUICK_CHECK
  33. # define RAM "1"
  34. # define DISK 64
  35. # define NX (256*1024/sizeof(double))
  36. #else
  37. # define NX (32*1048576/sizeof(double))
  38. # define RAM "160"
  39. # define DISK 200
  40. #endif
  41. #if !defined(STARPU_HAVE_SETENV)
  42. #warning setenv is not defined. Skipping test
  43. int main(void)
  44. {
  45. return STARPU_TEST_SKIPPED;
  46. }
  47. #else
  48. int dotest(struct starpu_disk_ops *ops, void *param)
  49. {
  50. double *A,*B,*C,*D,*E,*F;
  51. int ret;
  52. /* limit main ram to force to push in disk */
  53. setenv("STARPU_LIMIT_CPU_NUMA_MEM", RAM, 1);
  54. /* Initialize StarPU without GPU devices to make sure the memory of the GPU devices will not be used */
  55. // Ignore environment variables as we want to force the exact number of workers
  56. struct starpu_conf conf;
  57. ret = starpu_conf_init(&conf);
  58. if (ret == -EINVAL)
  59. return EXIT_FAILURE;
  60. conf.precedence_over_environment_variables = 1;
  61. conf.ncpus = 1;
  62. conf.ncuda = 0;
  63. conf.nopencl = 0;
  64. conf.nmic = 0;
  65. ret = starpu_init(&conf);
  66. if (ret == -ENODEV) goto enodev;
  67. /* register a disk */
  68. int new_dd = starpu_disk_register(ops, param, 1024*1024*DISK);
  69. /* can't write on /tmp/ */
  70. if (new_dd == -ENOENT) goto enoent;
  71. /* allocate two memory spaces */
  72. starpu_malloc_flags((void **)&A, NX*sizeof(double), STARPU_MALLOC_COUNT);
  73. starpu_malloc_flags((void **)&F, NX*sizeof(double), STARPU_MALLOC_COUNT);
  74. FPRINTF(stderr, "TEST DISK MEMORY \n");
  75. unsigned int j;
  76. /* initialization with bad values */
  77. for(j = 0; j < NX; ++j)
  78. {
  79. A[j] = j;
  80. F[j] = -j;
  81. }
  82. starpu_data_handle_t vector_handleA, vector_handleB, vector_handleC, vector_handleD, vector_handleE, vector_handleF;
  83. /* register vector in starpu */
  84. starpu_vector_data_register(&vector_handleA, STARPU_MAIN_RAM, (uintptr_t)A, NX, sizeof(double));
  85. starpu_vector_data_register(&vector_handleB, -1, (uintptr_t) NULL, NX, sizeof(double));
  86. starpu_vector_data_register(&vector_handleC, -1, (uintptr_t) NULL, NX, sizeof(double));
  87. starpu_vector_data_register(&vector_handleD, -1, (uintptr_t) NULL, NX, sizeof(double));
  88. starpu_vector_data_register(&vector_handleE, -1, (uintptr_t) NULL, NX, sizeof(double));
  89. starpu_vector_data_register(&vector_handleF, STARPU_MAIN_RAM, (uintptr_t)F, NX, sizeof(double));
  90. /* copy vector A->B, B->C... */
  91. starpu_data_cpy(vector_handleB, vector_handleA, 0, NULL, NULL);
  92. starpu_data_cpy(vector_handleC, vector_handleB, 0, NULL, NULL);
  93. starpu_data_cpy(vector_handleD, vector_handleC, 0, NULL, NULL);
  94. starpu_data_cpy(vector_handleE, vector_handleD, 0, NULL, NULL);
  95. starpu_data_cpy(vector_handleF, vector_handleE, 0, NULL, NULL);
  96. /* StarPU does not need to manipulate the array anymore so we can stop
  97. * monitoring it */
  98. /* free them */
  99. starpu_data_unregister(vector_handleA);
  100. starpu_data_unregister(vector_handleB);
  101. starpu_data_unregister(vector_handleC);
  102. starpu_data_unregister(vector_handleD);
  103. starpu_data_unregister(vector_handleE);
  104. starpu_data_unregister(vector_handleF);
  105. /* check if computation is correct */
  106. int try = 1;
  107. for (j = 0; j < NX; ++j)
  108. if (A[j] != F[j])
  109. {
  110. FPRINTF(stderr, "Fail A %f != F %f \n", A[j], F[j]);
  111. try = 0;
  112. }
  113. starpu_free_flags(A, NX*sizeof(double), STARPU_MALLOC_COUNT);
  114. starpu_free_flags(F, NX*sizeof(double), STARPU_MALLOC_COUNT);
  115. /* terminate StarPU, no task can be submitted after */
  116. starpu_shutdown();
  117. if(try)
  118. FPRINTF(stderr, "TEST SUCCESS\n");
  119. else
  120. FPRINTF(stderr, "TEST FAIL\n");
  121. return try ? EXIT_SUCCESS : EXIT_FAILURE;
  122. enodev:
  123. return STARPU_TEST_SKIPPED;
  124. enoent:
  125. FPRINTF(stderr, "Couldn't write data: ENOENT\n");
  126. starpu_shutdown();
  127. return STARPU_TEST_SKIPPED;
  128. }
  129. static int merge_result(int old, int new)
  130. {
  131. if (new == EXIT_FAILURE)
  132. return EXIT_FAILURE;
  133. if (old == 0)
  134. return 0;
  135. return new;
  136. }
  137. int main(void)
  138. {
  139. int ret = 0;
  140. int ret2;
  141. char s[128];
  142. char *ptr;
  143. #ifdef STARPU_HAVE_SETENV
  144. setenv("STARPU_CALIBRATE_MINIMUM", "1", 1);
  145. #endif
  146. snprintf(s, sizeof(s), "/tmp/%s-disk-XXXXXX", getenv("USER"));
  147. ptr = _starpu_mkdtemp(s);
  148. if (!ptr)
  149. {
  150. FPRINTF(stderr, "Cannot make directory <%s>\n", s);
  151. return STARPU_TEST_SKIPPED;
  152. }
  153. ret = merge_result(ret, dotest(&starpu_disk_stdio_ops, s));
  154. ret = merge_result(ret, dotest(&starpu_disk_unistd_ops, s));
  155. #ifdef STARPU_LINUX_SYS
  156. ret = merge_result(ret, dotest(&starpu_disk_unistd_o_direct_ops, s));
  157. #endif
  158. #ifdef STARPU_HAVE_HDF5
  159. ret = merge_result(ret, dotest(&starpu_disk_hdf5_ops, s));
  160. #endif
  161. ret2 = rmdir(s);
  162. if (ret2 < 0)
  163. STARPU_CHECK_RETURN_VALUE(-errno, "rmdir '%s'\n", s);
  164. return ret;
  165. }
  166. #endif