scratch_reuse.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019 Université de Bordeaux
  4. * Copyright (C) 2019 CNRS
  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. {
  37. .name = "codelet",
  38. .cuda_funcs = { kernel },
  39. .nbuffers = 1,
  40. .modes = { STARPU_SCRATCH },
  41. };
  42. int main(int argc, char *argv[])
  43. {
  44. setenv("STARPU_LIMIT_CUDA_MEM", "50", 1);
  45. int ret = starpu_initialize(NULL, &argc, &argv);
  46. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  48. if (starpu_cuda_worker_get_count() == 0)
  49. {
  50. starpu_shutdown();
  51. return STARPU_TEST_SKIPPED;
  52. }
  53. starpu_data_handle_t handle[ITER];
  54. int i;
  55. for (i = 0; i < ITER; i++)
  56. {
  57. starpu_matrix_data_register(&handle[i], -1, 0, 1024, 1024, 1024, sizeof(float));
  58. ret = starpu_task_insert(&codelet, STARPU_SCRATCH, handle[i], 0);
  59. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  61. }
  62. starpu_task_wait_for_all();
  63. for (i = 0; i < ITER; i++)
  64. starpu_data_unregister(handle[i]);
  65. starpu_shutdown();
  66. return 0;
  67. }
  68. #endif