scratch_reuse.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019 Mirko Myllykoski
  4. * Copyright (C) 2019 Université de Bordeaux
  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. #include <starpu.h>
  18. #include "../helper.h"
  19. #if !defined(STARPU_HAVE_UNSETENV) || !defined(STARPU_USE_CPU) || !defined(STARPU_HAVE_HWLOC)
  20. #warning unsetenv is not defined or no cpu are available. Skipping test
  21. int main(void)
  22. {
  23. return STARPU_TEST_SKIPPED;
  24. }
  25. #else
  26. #ifdef STARPU_QUICK_CHECK
  27. #define ITER 32
  28. #else
  29. #define ITER 128
  30. #endif
  31. static void kernel(void *buffers[], void *cl_args)
  32. {
  33. STARPU_ASSERT(STARPU_MATRIX_GET_PTR(buffers[0]) != 0);
  34. }
  35. static struct starpu_codelet codelet = {
  36. .name = "codelet",
  37. .cuda_funcs = { kernel },
  38. .nbuffers = 1,
  39. .modes = { STARPU_SCRATCH },
  40. };
  41. int main(int argc, char *argv[])
  42. {
  43. setenv("STARPU_LIMIT_CUDA_MEM", "50", 1);
  44. int ret = starpu_initialize(NULL, &argc, &argv);
  45. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  46. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  47. if (starpu_cuda_worker_get_count() == 0) {
  48. starpu_shutdown();
  49. return STARPU_TEST_SKIPPED;
  50. }
  51. starpu_data_handle_t handle[ITER];
  52. int i;
  53. for (i = 0; i < ITER; i++) {
  54. starpu_matrix_data_register(&handle[i], -1, 0, 1024, 1024, 1024, sizeof(float));
  55. ret = starpu_task_insert(&codelet, STARPU_SCRATCH, handle[i], 0);
  56. }
  57. starpu_task_wait_for_all();
  58. for (i = 0; i < ITER; i++)
  59. starpu_data_unregister(handle[i]);
  60. starpu_shutdown();
  61. return 0;
  62. }
  63. #endif