numa_overflow.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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 <stdio.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #include "../helper.h"
  22. #if !defined(STARPU_HAVE_SETENV)
  23. #warning setenv is not defined. Skipping test
  24. int main(void)
  25. {
  26. return STARPU_TEST_SKIPPED;
  27. }
  28. #else
  29. #define ITER 10
  30. #define N 10
  31. #define SIZE (10*1024*1024)
  32. /*
  33. * Check that when overflowing a NUMA node we manage to revert to other nodes.
  34. */
  35. static void nop(void *descr[], void *arg)
  36. {
  37. (void)descr;
  38. (void)arg;
  39. }
  40. static struct starpu_codelet cl_r =
  41. {
  42. .cpu_funcs = { nop },
  43. .nbuffers = 1,
  44. .modes = { STARPU_R },
  45. };
  46. static struct starpu_codelet cl_rw =
  47. {
  48. .cpu_funcs = { nop },
  49. .nbuffers = 1,
  50. .modes = { STARPU_RW },
  51. };
  52. int main(int argc, char **argv)
  53. {
  54. starpu_data_handle_t handles[N];
  55. uintptr_t data[N];
  56. int ret;
  57. unsigned i, j;
  58. char s[16];
  59. int worker, numa;
  60. snprintf(s, sizeof(s), "%u", (N*3/4)*SIZE/(1024*1024));
  61. /* We make NUMA nodes not big enough for all data */
  62. numa = starpu_get_env_number_default("STARPU_USE_NUMA", 0);
  63. if (numa == 1)
  64. setenv("STARPU_LIMIT_CPU_NUMA_MEM", s, 1);
  65. else
  66. setenv("STARPU_LIMIT_CPU_MEM", s, 1);
  67. ret = starpu_initialize(NULL, &argc, &argv);
  68. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  69. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  70. if (starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, &worker, 1) == 0
  71. || starpu_memory_nodes_get_numa_count() <= 1)
  72. {
  73. /* We need several NUMA nodes */
  74. starpu_shutdown();
  75. return STARPU_TEST_SKIPPED;
  76. }
  77. /* We distribute some data on both NUMA nodes */
  78. for (i = 0; i < N; i++)
  79. {
  80. data[i] = starpu_malloc_on_node(i%2, SIZE);
  81. memset((void*) data[i], 0, SIZE);
  82. starpu_variable_data_register(&handles[i], i%2, data[i], SIZE);
  83. }
  84. /* And now we try to execute all tasks on worker 0, that will fail if
  85. * StarPU doesn't manage to evict some memory */
  86. for (j = 0; j < ITER; j++)
  87. for (i = 0; i < N; i++)
  88. {
  89. if (rand() % 2 == 0)
  90. ret = starpu_task_insert(&cl_r, STARPU_R, handles[i], STARPU_EXECUTE_ON_WORKER, worker, 0);
  91. else
  92. ret = starpu_task_insert(&cl_rw, STARPU_RW, handles[i], STARPU_EXECUTE_ON_WORKER, worker, 0);
  93. if (ret == ENODEV) goto enodev;
  94. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  95. }
  96. for (i = 0; i < N; i++)
  97. {
  98. starpu_data_unregister(handles[i]);
  99. starpu_free_on_node(i%2, data[i], SIZE);
  100. }
  101. starpu_shutdown();
  102. return EXIT_SUCCESS;
  103. enodev:
  104. for (i = 0; i < N; i++)
  105. {
  106. starpu_data_unregister(handles[i]);
  107. starpu_free_on_node(i%2, data[i], SIZE);
  108. }
  109. fprintf(stderr, "WARNING: No one can execute this task\n");
  110. /* yes, we do not perform the computation but we did detect that no one
  111. * could perform the kernel, so this is not an error from StarPU */
  112. starpu_shutdown();
  113. return STARPU_TEST_SKIPPED;
  114. }
  115. #endif