allocate.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. ret = starpu_malloc_flags((void **)&buffer, 1, STARPU_MALLOC_COUNT);
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc_flags");
  51. FPRINTF(stderr, "Allocation succesfull for 1 b\n");
  52. ret = starpu_malloc_flags((void **)&buffer2, 1*1024*512, STARPU_MALLOC_COUNT);
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc_flags");
  54. FPRINTF(stderr, "Allocation succesfull for %d b\n", 1*1024*512);
  55. ret = starpu_malloc_flags((void **)&buffer3, 1*1024*512, STARPU_MALLOC_COUNT);
  56. STARPU_CHECK_RETURN_VALUE_IS(ret, -ENOMEM, "starpu_malloc_flags");
  57. FPRINTF(stderr, "Allocation failed for %d b\n", 1*1024*512);
  58. ret = starpu_malloc_flags((void **)&buffer3, 1*1024*512, 0);
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc_flags");
  60. FPRINTF(stderr, "Allocation successful for %d b\n", 1*1024*512);
  61. starpu_free_flags(buffer3, 1*1024*512, 0);
  62. starpu_free_flags(buffer2, 1*1024*512, STARPU_MALLOC_COUNT);
  63. FPRINTF(stderr, "Freeing %d b\n", 1*1024*512);
  64. ret = starpu_malloc_flags((void **)&buffer3, 1*1024*512, STARPU_MALLOC_COUNT);
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc_flags");
  66. FPRINTF(stderr, "Allocation succesfull for %d b\n", 1*1024*512);
  67. starpu_free_flags(buffer3, 1*1024*512, STARPU_MALLOC_COUNT);
  68. starpu_free_flags(buffer, 1, STARPU_MALLOC_COUNT);
  69. starpu_shutdown();
  70. return 0;
  71. }
  72. #endif