disk_copy_unpack.c 4.3 KB

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