disk_copy_unpack.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017 CNRS
  4. * Copyright (C) 2017 Inria
  5. * Copyright (C) 2019 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <unistd.h>
  22. #include <math.h>
  23. #include "../helper.h"
  24. /*
  25. * Test pack / unpack methods before pushing data on disk with async read/write.
  26. */
  27. /* size of one vector */
  28. #ifdef STARPU_QUICK_CHECK
  29. # define DISK 64
  30. # define NX (256*1024/sizeof(double))
  31. #else
  32. # define NX (32*1048576/sizeof(double))
  33. # define DISK 200
  34. #endif
  35. #if !defined(STARPU_HAVE_SETENV)
  36. #warning setenv is not defined. Skipping test
  37. int main(void)
  38. {
  39. return STARPU_TEST_SKIPPED;
  40. }
  41. #else
  42. int dotest(struct starpu_disk_ops *ops, void *param)
  43. {
  44. unsigned *A;
  45. int ret;
  46. /* Initialize StarPU without GPU devices to make sure the memory of the GPU devices will not be used */
  47. // Ignore environment variables as we want to force the exact number of workers
  48. unsetenv("STARPU_NCUDA");
  49. unsetenv("STARPU_NOPENCL");
  50. unsetenv("STARPU_NMIC");
  51. unsetenv("STARPU_NSCC");
  52. struct starpu_conf conf;
  53. ret = starpu_conf_init(&conf);
  54. if (ret == -EINVAL)
  55. return EXIT_FAILURE;
  56. conf.ncuda = 0;
  57. conf.nopencl = 0;
  58. conf.nmic = 0;
  59. conf.nscc = 0;
  60. ret = starpu_init(&conf);
  61. if (ret == -ENODEV) goto enodev;
  62. /* register a disk */
  63. int new_dd = starpu_disk_register(ops, param, 1024*1024*DISK);
  64. /* can't write on /tmp/ */
  65. if (new_dd == -ENOENT) goto enoent;
  66. /* allocate two memory spaces */
  67. starpu_malloc_flags((void **)&A, NX*sizeof(unsigned), STARPU_MALLOC_COUNT);
  68. FPRINTF(stderr, "TEST DISK MEMORY \n");
  69. unsigned int j;
  70. /* initialization with bad values */
  71. for(j = 0; j < NX; ++j)
  72. {
  73. A[j] = j;
  74. }
  75. starpu_data_handle_t vector_handleA;
  76. static const struct starpu_data_copy_methods my_vector_copy_data_methods_s =
  77. {
  78. .any_to_any = NULL,
  79. };
  80. starpu_interface_vector_ops.copy_methods = &my_vector_copy_data_methods_s;
  81. /* register vector in starpu */
  82. starpu_vector_data_register(&vector_handleA, STARPU_MAIN_RAM, (uintptr_t)A, NX, sizeof(unsigned));
  83. /* Move and invalidate copy to an other disk */
  84. starpu_data_acquire_on_node(vector_handleA, new_dd, STARPU_RW);
  85. starpu_data_release_on_node(vector_handleA, new_dd);
  86. starpu_data_acquire_on_node(vector_handleA, new_dd, STARPU_RW);
  87. starpu_data_release_on_node(vector_handleA, new_dd);
  88. /* free them */
  89. starpu_data_unregister(vector_handleA);
  90. /* check if computation is correct */
  91. int try = 1;
  92. for (j = 0; j < NX; ++j)
  93. if (A[j] != j)
  94. {
  95. FPRINTF(stderr, "Fail A %u != %u \n", A[j], j);
  96. try = 0;
  97. }
  98. starpu_free_flags(A, NX*sizeof(unsigned), STARPU_MALLOC_COUNT);
  99. /* terminate StarPU, no task can be submitted after */
  100. starpu_shutdown();
  101. if(try)
  102. FPRINTF(stderr, "TEST SUCCESS\n");
  103. else
  104. FPRINTF(stderr, "TEST FAIL\n");
  105. return try ? EXIT_SUCCESS : EXIT_FAILURE;
  106. enodev:
  107. return STARPU_TEST_SKIPPED;
  108. enoent:
  109. FPRINTF(stderr, "Couldn't write data: ENOENT\n");
  110. starpu_shutdown();
  111. return STARPU_TEST_SKIPPED;
  112. }
  113. static int merge_result(int old, int new)
  114. {
  115. if (new == EXIT_FAILURE)
  116. return EXIT_FAILURE;
  117. if (old == 0)
  118. return 0;
  119. return new;
  120. }
  121. int main(void)
  122. {
  123. int ret = 0;
  124. int ret2;
  125. char s[128];
  126. char *ptr;
  127. #ifdef STARPU_HAVE_SETENV
  128. setenv("STARPU_CALIBRATE_MINIMUM", "1", 1);
  129. #endif
  130. snprintf(s, sizeof(s), "/tmp/%s-disk-XXXXXX", getenv("USER"));
  131. ptr = _starpu_mkdtemp(s);
  132. if (!ptr)
  133. {
  134. FPRINTF(stderr, "Cannot make directory <%s>\n", s);
  135. return STARPU_TEST_SKIPPED;
  136. }
  137. ret = merge_result(ret, dotest(&starpu_disk_stdio_ops, s));
  138. ret = merge_result(ret, dotest(&starpu_disk_unistd_ops, s));
  139. #ifdef STARPU_LINUX_SYS
  140. ret = merge_result(ret, dotest(&starpu_disk_unistd_o_direct_ops, s));
  141. #endif
  142. #ifdef STARPU_HAVE_HDF5
  143. ret = merge_result(ret, dotest(&starpu_disk_hdf5_ops, s));
  144. #endif
  145. ret2 = rmdir(s);
  146. if (ret2 < 0)
  147. STARPU_CHECK_RETURN_VALUE(-errno, "rmdir '%s'\n", s);
  148. return ret;
  149. }
  150. #endif