numa_overflow.c 3.1 KB

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