block_test.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* StarPURM --- StarPU Resource Management Layer.
  2. *
  3. * Copyright (C) 2017 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. /* This example shows a basic StarPU vector scale app on top of StarPURM with a nVidia CUDA kernel */
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <assert.h>
  20. #include <starpu.h>
  21. #include <starpurm.h>
  22. static int rm_cpu_type_id = -1;
  23. static int rm_nb_cpu_units = 0;
  24. static void test1();
  25. static void init_rm_infos(void);
  26. static int global_nb_tasks = 100;
  27. static const int nb_random_tests = 10;
  28. /* vector scale codelet */
  29. static void work_func(void *cl_buffers[], void *cl_arg)
  30. {
  31. double timestamp = starpu_timing_now();
  32. double timestamp2;
  33. do
  34. {
  35. timestamp2 = starpu_timing_now();
  36. }
  37. while ((timestamp2 - timestamp) < 1e6);
  38. }
  39. static struct starpu_codelet work_cl =
  40. {
  41. .cpu_funcs = {work_func},
  42. };
  43. /* main routines */
  44. static void test1()
  45. {
  46. int i;
  47. for (i=0; i<global_nb_tasks; i++)
  48. {
  49. int ret = starpu_task_insert(&work_cl,
  50. 0);
  51. assert(ret == 0);
  52. }
  53. starpu_task_wait_for_all();
  54. }
  55. static void init_rm_infos(void)
  56. {
  57. int cpu_type = starpurm_get_device_type_id("cpu");
  58. int nb_cpu_units = starpurm_get_nb_devices_by_type(cpu_type);
  59. if (nb_cpu_units < 1)
  60. {
  61. /* No CPU unit available. */
  62. exit(77);
  63. }
  64. rm_cpu_type_id = cpu_type;
  65. rm_nb_cpu_units = nb_cpu_units;
  66. }
  67. static void disp_selected_cpuset(void)
  68. {
  69. hwloc_cpuset_t selected_cpuset = starpurm_get_selected_cpuset();
  70. int strl = hwloc_bitmap_snprintf(NULL, 0, selected_cpuset);
  71. char str[strl+1];
  72. hwloc_bitmap_snprintf(str, strl+1, selected_cpuset);
  73. printf("selected cpuset = %s\n", str);
  74. }
  75. int main(int argc, char *argv[])
  76. {
  77. srandom(time(NULL));
  78. int drs_enabled;
  79. if (argc > 1)
  80. {
  81. global_nb_tasks = atoi(argv[1]);
  82. }
  83. starpurm_initialize();
  84. init_rm_infos();
  85. printf("using default units\n");
  86. disp_selected_cpuset();
  87. test1();
  88. if (rm_nb_cpu_units > 1)
  89. {
  90. const int nb_cpus = rm_nb_cpu_units;
  91. const int half_nb_cpus = nb_cpus/2;
  92. printf("nb_cpu_units = %d\n", nb_cpus);
  93. starpurm_set_drs_enable(NULL);
  94. drs_enabled = starpurm_drs_enabled_p();
  95. assert(drs_enabled != 0);
  96. printf("withdrawing %d cpus from StarPU\n", half_nb_cpus);
  97. starpurm_withdraw_cpus_from_starpu(NULL, half_nb_cpus);
  98. disp_selected_cpuset();
  99. test1();
  100. printf("assigning %d cpus to StarPU\n", half_nb_cpus);
  101. starpurm_assign_cpus_to_starpu(NULL, half_nb_cpus);
  102. disp_selected_cpuset();
  103. test1();
  104. int i;
  105. for (i=0; i<nb_random_tests; i++)
  106. {
  107. int some_cpus = 1+ random()%nb_cpus;
  108. printf("assigning exactly %d cpus to StarPU\n", some_cpus);
  109. starpurm_withdraw_all_cpus_from_starpu(NULL);
  110. starpurm_assign_cpus_to_starpu(NULL, some_cpus);
  111. disp_selected_cpuset();
  112. test1();
  113. }
  114. starpurm_set_drs_disable(NULL);
  115. drs_enabled = starpurm_drs_enabled_p();
  116. assert(drs_enabled == 0);
  117. }
  118. starpurm_shutdown();
  119. return 0;
  120. }