disk_copy.c 4.7 KB

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