disk_copy.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Corentin Salingue
  4. * Copyright (C) 2015 Centre National de la Recherche Scientifique
  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. /* Try to write into disk memory
  18. * Use mechanism to push datas from main ram to disk ram
  19. */
  20. #include <starpu.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <unistd.h>
  24. #include <math.h>
  25. #include <common/config.h>
  26. #include "../helper.h"
  27. #ifdef STARPU_HAVE_WINDOWS
  28. # include <io.h>
  29. # if defined(_WIN32) && !defined(__CYGWIN__)
  30. # define mkdir(path, mode) mkdir(path)
  31. # endif
  32. #endif
  33. /* size of one vector */
  34. #ifdef STARPU_QUICK_CHECK
  35. # if SIZEOF_VOID_P == 4
  36. # define NX (32*128/sizeof(double))
  37. # else
  38. # define NX (32*65536/sizeof(double))
  39. # endif
  40. #else
  41. # if SIZEOF_VOID_P == 4
  42. # define NX (32*1024/sizeof(double))
  43. # else
  44. # define NX (32*1048576/sizeof(double))
  45. # endif
  46. #endif
  47. #if !defined(STARPU_HAVE_SETENV)
  48. #warning setenv is not defined. Skipping test
  49. int main(int argc, char **argv)
  50. {
  51. return STARPU_TEST_SKIPPED;
  52. }
  53. #else
  54. int dotest(struct starpu_disk_ops *ops, void *param)
  55. {
  56. double *A,*B,*C,*D,*E,*F;
  57. int ret;
  58. /* limit main ram to force to push in disk */
  59. setenv("STARPU_LIMIT_CPU_MEM", "160", 1);
  60. /* Initialize StarPU without GPU devices to make sure the memory of the GPU devices will not be used */
  61. struct starpu_conf conf;
  62. ret = starpu_conf_init(&conf);
  63. if (ret == -EINVAL)
  64. return EXIT_FAILURE;
  65. conf.ncuda = 0;
  66. conf.nopencl = 0;
  67. ret = starpu_init(&conf);
  68. if (ret == -ENODEV) goto enodev;
  69. /* register a disk */
  70. int new_dd = starpu_disk_register(ops, param, 1024*1024*200);
  71. /* can't write on /tmp/ */
  72. if (new_dd == -ENOENT) goto enoent;
  73. /* allocate two memory spaces */
  74. starpu_malloc_flags((void **)&A, NX*sizeof(double), STARPU_MALLOC_COUNT);
  75. starpu_malloc_flags((void **)&F, NX*sizeof(double), STARPU_MALLOC_COUNT);
  76. FPRINTF(stderr, "TEST DISK MEMORY \n");
  77. unsigned int j;
  78. /* initialization with bad values */
  79. for(j = 0; j < NX; ++j)
  80. {
  81. A[j] = j;
  82. F[j] = -j;
  83. }
  84. starpu_data_handle_t vector_handleA, vector_handleB, vector_handleC, vector_handleD, vector_handleE, vector_handleF;
  85. /* register vector in starpu */
  86. starpu_vector_data_register(&vector_handleA, STARPU_MAIN_RAM, (uintptr_t)A, NX, sizeof(double));
  87. starpu_vector_data_register(&vector_handleB, -1, (uintptr_t) NULL, NX, sizeof(double));
  88. starpu_vector_data_register(&vector_handleC, -1, (uintptr_t) NULL, NX, sizeof(double));
  89. starpu_vector_data_register(&vector_handleD, -1, (uintptr_t) NULL, NX, sizeof(double));
  90. starpu_vector_data_register(&vector_handleE, -1, (uintptr_t) NULL, NX, sizeof(double));
  91. starpu_vector_data_register(&vector_handleF, STARPU_MAIN_RAM, (uintptr_t)F, NX, sizeof(double));
  92. /* copy vector A->B, B->C... */
  93. starpu_data_cpy(vector_handleB, vector_handleA, 0, NULL, NULL);
  94. starpu_data_cpy(vector_handleC, vector_handleB, 0, NULL, NULL);
  95. starpu_data_cpy(vector_handleD, vector_handleC, 0, NULL, NULL);
  96. starpu_data_cpy(vector_handleE, vector_handleD, 0, NULL, NULL);
  97. starpu_data_cpy(vector_handleF, vector_handleE, 0, NULL, NULL);
  98. /* StarPU does not need to manipulate the array anymore so we can stop
  99. * monitoring it */
  100. /* free them */
  101. starpu_data_unregister(vector_handleA);
  102. starpu_data_unregister(vector_handleB);
  103. starpu_data_unregister(vector_handleC);
  104. starpu_data_unregister(vector_handleD);
  105. starpu_data_unregister(vector_handleE);
  106. starpu_data_unregister(vector_handleF);
  107. /* check if computation is correct */
  108. int try = 1;
  109. for (j = 0; j < NX; ++j)
  110. if (A[j] != F[j])
  111. {
  112. FPRINTF(stderr, "Fail A %f != F %f \n", A[j], F[j]);
  113. try = 0;
  114. }
  115. starpu_free_flags(A, NX*sizeof(double), STARPU_MALLOC_COUNT);
  116. starpu_free_flags(F, NX*sizeof(double), STARPU_MALLOC_COUNT);
  117. /* terminate StarPU, no task can be submitted after */
  118. starpu_shutdown();
  119. if(try)
  120. FPRINTF(stderr, "TEST SUCCESS\n");
  121. else
  122. FPRINTF(stderr, "TEST FAIL\n");
  123. return (try ? EXIT_SUCCESS : EXIT_FAILURE);
  124. enodev:
  125. return STARPU_TEST_SKIPPED;
  126. enoent:
  127. FPRINTF(stderr, "Couldn't write data: ENOENT\n");
  128. starpu_shutdown();
  129. return STARPU_TEST_SKIPPED;
  130. }
  131. static int merge_result(int old, int new)
  132. {
  133. if (new == EXIT_FAILURE)
  134. return EXIT_FAILURE;
  135. if (old == 0)
  136. return 0;
  137. return new;
  138. }
  139. int main(void)
  140. {
  141. int ret = 0;
  142. char s[128];
  143. snprintf(s, sizeof(s), "/tmp/%s-disk-%d", getenv("USER"), getpid());
  144. mkdir(s, 0777);
  145. ret = merge_result(ret, dotest(&starpu_disk_stdio_ops, s));
  146. ret = merge_result(ret, dotest(&starpu_disk_unistd_ops, s));
  147. #ifdef STARPU_LINUX_SYS
  148. ret = merge_result(ret, dotest(&starpu_disk_unistd_o_direct_ops, s));
  149. #endif
  150. rmdir(s);
  151. return ret;
  152. }
  153. #endif