allocate.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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, "_starpu_memory_manager_get_global_memory_size");
  48. FPRINTF(stderr, "Available memory size on node 0: %ld\n", global_size);
  49. starpu_malloc_set_flags(STARPU_MALLOC_COUNT);
  50. ret = starpu_malloc((void **)&buffer, 1);
  51. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  52. FPRINTF(stderr, "Allocation succesfull for 1 b\n");
  53. ret = starpu_malloc((void **)&buffer2, 1*1024*512);
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  55. FPRINTF(stderr, "Allocation succesfull for %d b\n", 1*1024*512);
  56. ret = starpu_malloc((void **)&buffer3, 1*1024*512);
  57. STARPU_CHECK_RETURN_VALUE_IS(ret, -ENOMEM, "starpu_malloc");
  58. FPRINTF(stderr, "Allocation failed for %d b\n", 1*1024*512);
  59. starpu_malloc_set_flags(0);
  60. ret = starpu_malloc((void **)&buffer3, 1*1024*512);
  61. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  62. FPRINTF(stderr, "Allocation successful for %d b\n", 1*1024*512);
  63. starpu_free(buffer3);
  64. starpu_malloc_set_flags(STARPU_MALLOC_COUNT);
  65. starpu_free_count(buffer2, 1*1024*512);
  66. FPRINTF(stderr, "Freeing %d b\n", 1*1024*512);
  67. ret = starpu_malloc((void **)&buffer3, 1*1024*512);
  68. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  69. FPRINTF(stderr, "Allocation succesfull for %d b\n", 1*1024*512);
  70. starpu_free_count(buffer3, 1*1024*512);
  71. starpu_free_count(buffer, 1);
  72. starpu_shutdown();
  73. return 0;
  74. }
  75. #endif