numa_overflow.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2020-2021 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;
  60. snprintf(s, sizeof(s), "%u", (N*3/4)*SIZE/(1024*1024));
  61. /* We make NUMA nodes not big enough for all data */
  62. setenv("STARPU_LIMIT_CPU_NUMA_MEM", s, 1);
  63. ret = starpu_initialize(NULL, &argc, &argv);
  64. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  66. if (starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, &worker, 1) == 0
  67. || starpu_memory_nodes_get_numa_count() <= 1)
  68. {
  69. /* We need several NUMA nodes */
  70. starpu_shutdown();
  71. return STARPU_TEST_SKIPPED;
  72. }
  73. /* We distribute some data on both NUMA nodes */
  74. for (i = 0; i < N; i++)
  75. {
  76. data[i] = starpu_malloc_on_node(i%2, SIZE);
  77. memset((void*) data[i], 0, SIZE);
  78. starpu_variable_data_register(&handles[i], i%2, data[i], SIZE);
  79. }
  80. /* And now we try to execute all tasks on worker 0, that will fail if
  81. * StarPU doesn't manage to evict some memory */
  82. for (j = 0; j < ITER; j++)
  83. for (i = 0; i < N; i++)
  84. {
  85. if (rand() % 2 == 0)
  86. ret = starpu_task_insert(&cl_r, STARPU_R, handles[i], STARPU_EXECUTE_ON_WORKER, worker, 0);
  87. else
  88. ret = starpu_task_insert(&cl_rw, STARPU_RW, handles[i], STARPU_EXECUTE_ON_WORKER, worker, 0);
  89. if (ret == ENODEV) goto enodev;
  90. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  91. }
  92. for (i = 0; i < N; i++)
  93. {
  94. starpu_data_unregister(handles[i]);
  95. starpu_free_on_node(i%2, data[i], SIZE);
  96. }
  97. starpu_shutdown();
  98. return EXIT_SUCCESS;
  99. enodev:
  100. for (i = 0; i < N; i++)
  101. {
  102. starpu_data_unregister(handles[i]);
  103. starpu_free_on_node(i%2, data[i], SIZE);
  104. }
  105. fprintf(stderr, "WARNING: No one can execute this task\n");
  106. /* yes, we do not perform the computation but we did detect that no one
  107. * could perform the kernel, so this is not an error from StarPU */
  108. starpu_shutdown();
  109. return STARPU_TEST_SKIPPED;
  110. }
  111. #endif