disk_copy_unpack.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017, 2019 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. struct starpu_conf conf;
  52. ret = starpu_conf_init(&conf);
  53. if (ret == -EINVAL)
  54. return EXIT_FAILURE;
  55. conf.ncuda = 0;
  56. conf.nopencl = 0;
  57. conf.nmic = 0;
  58. ret = starpu_init(&conf);
  59. if (ret == -ENODEV) goto enodev;
  60. /* register a disk */
  61. int new_dd = starpu_disk_register(ops, param, 1024*1024*DISK);
  62. /* can't write on /tmp/ */
  63. if (new_dd == -ENOENT) goto enoent;
  64. /* allocate two memory spaces */
  65. starpu_malloc_flags((void **)&A, NX*sizeof(unsigned), STARPU_MALLOC_COUNT);
  66. FPRINTF(stderr, "TEST DISK MEMORY \n");
  67. unsigned int j;
  68. /* initialization with bad values */
  69. for(j = 0; j < NX; ++j)
  70. {
  71. A[j] = j;
  72. }
  73. starpu_data_handle_t vector_handleA;
  74. static const struct starpu_data_copy_methods my_vector_copy_data_methods_s =
  75. {
  76. .any_to_any = NULL,
  77. };
  78. starpu_interface_vector_ops.copy_methods = &my_vector_copy_data_methods_s;
  79. /* register vector in starpu */
  80. starpu_vector_data_register(&vector_handleA, STARPU_MAIN_RAM, (uintptr_t)A, NX, sizeof(unsigned));
  81. /* Move and invalidate copy to an other disk */
  82. starpu_data_acquire_on_node(vector_handleA, new_dd, STARPU_RW);
  83. starpu_data_release_on_node(vector_handleA, new_dd);
  84. starpu_data_acquire_on_node(vector_handleA, new_dd, STARPU_RW);
  85. starpu_data_release_on_node(vector_handleA, new_dd);
  86. /* free them */
  87. starpu_data_unregister(vector_handleA);
  88. /* check if computation is correct */
  89. int try = 1;
  90. for (j = 0; j < NX; ++j)
  91. if (A[j] != j)
  92. {
  93. FPRINTF(stderr, "Fail A %u != %u \n", A[j], j);
  94. try = 0;
  95. }
  96. starpu_free_flags(A, NX*sizeof(unsigned), STARPU_MALLOC_COUNT);
  97. /* terminate StarPU, no task can be submitted after */
  98. starpu_shutdown();
  99. if(try)
  100. FPRINTF(stderr, "TEST SUCCESS\n");
  101. else
  102. FPRINTF(stderr, "TEST FAIL\n");
  103. return try ? EXIT_SUCCESS : EXIT_FAILURE;
  104. enodev:
  105. return STARPU_TEST_SKIPPED;
  106. enoent:
  107. FPRINTF(stderr, "Couldn't write data: ENOENT\n");
  108. starpu_shutdown();
  109. return STARPU_TEST_SKIPPED;
  110. }
  111. static int merge_result(int old, int new)
  112. {
  113. if (new == EXIT_FAILURE)
  114. return EXIT_FAILURE;
  115. if (old == 0)
  116. return 0;
  117. return new;
  118. }
  119. int main(void)
  120. {
  121. int ret = 0;
  122. int ret2;
  123. char s[128];
  124. char *ptr;
  125. #ifdef STARPU_HAVE_SETENV
  126. setenv("STARPU_CALIBRATE_MINIMUM", "1", 1);
  127. #endif
  128. snprintf(s, sizeof(s), "/tmp/%s-disk-XXXXXX", getenv("USER"));
  129. ptr = _starpu_mkdtemp(s);
  130. if (!ptr)
  131. {
  132. FPRINTF(stderr, "Cannot make directory <%s>\n", s);
  133. return STARPU_TEST_SKIPPED;
  134. }
  135. ret = merge_result(ret, dotest(&starpu_disk_stdio_ops, s));
  136. ret = merge_result(ret, dotest(&starpu_disk_unistd_ops, s));
  137. #ifdef STARPU_LINUX_SYS
  138. ret = merge_result(ret, dotest(&starpu_disk_unistd_o_direct_ops, s));
  139. #endif
  140. #ifdef STARPU_HAVE_HDF5
  141. ret = merge_result(ret, dotest(&starpu_disk_hdf5_ops, s));
  142. #endif
  143. ret2 = rmdir(s);
  144. if (ret2 < 0)
  145. STARPU_CHECK_RETURN_VALUE(-errno, "rmdir '%s'\n", s);
  146. return ret;
  147. }
  148. #endif