pinned_memory.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011,2013,2014,2016 Université de Bordeaux
  4. * Copyright (C) 2010-2012,2015,2017 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 <stdio.h>
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Test calling starpu_malloc, i.e. allocating pinned memory
  22. */
  23. #define NITER 10
  24. #define SIZE (4*1024*1024*sizeof(float))
  25. static float *data = NULL;
  26. int main(int argc, char **argv)
  27. {
  28. int ret;
  29. ret = starpu_initialize(NULL, &argc, &argv);
  30. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  31. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  32. unsigned iter;
  33. for (iter = 0; iter < NITER; iter++)
  34. {
  35. ret = starpu_malloc((void **)&data, SIZE);
  36. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  37. starpu_free(data);
  38. }
  39. starpu_shutdown();
  40. return EXIT_SUCCESS;
  41. }