allocate.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Centre National de la Recherche Scientifique
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include "../helper.h"
  18. #include <stdlib.h>
  19. #include <datawizard/memory_manager.h>
  20. #if !defined(STARPU_HAVE_SETENV)
  21. #warning setenv is not defined. Skipping test
  22. int main(int argc, char **argv)
  23. {
  24. return STARPU_TEST_SKIPPED;
  25. }
  26. #else
  27. int main(int argc, char **argv)
  28. {
  29. int ret;
  30. float *buffer;
  31. float *buffer2;
  32. float *buffer3;
  33. size_t global_size;
  34. setenv("STARPU_LIMIT_CUDA_MEM", "1", 1);
  35. setenv("STARPU_LIMIT_OPENCL_MEM", "1", 1);
  36. setenv("STARPU_LIMIT_CPU_MEM", "1", 1);
  37. ret = starpu_init(NULL);
  38. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  39. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  40. global_size = _starpu_memory_manager_get_global_memory_size(0);
  41. if (global_size == 0)
  42. {
  43. FPRINTF(stderr, "Global memory size unavailable, skip the test\n");
  44. starpu_shutdown();
  45. return STARPU_TEST_SKIPPED;
  46. }
  47. STARPU_CHECK_RETURN_VALUE_IS((int)global_size, 1*1024*1024, "get_global_memory_size");
  48. FPRINTF(stderr, "Available memory size on node 0: %ld\n", global_size);
  49. ret = starpu_malloc((void **)&buffer, 1);
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  51. ret = starpu_malloc((void **)&buffer2, 1*1024*512);
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  53. ret = starpu_malloc((void **)&buffer3, 1*1024*512);
  54. STARPU_CHECK_RETURN_VALUE_IS(ret, -ENOMEM, "starpu_malloc");
  55. #ifdef STARPU_DEVEL
  56. #warning we need to test the reclaim is working by calling starpu_free(buffer2) and re-trying to allocate buffer3
  57. #endif
  58. starpu_shutdown();
  59. return 0;
  60. }
  61. #endif