local_pingpong.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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 <debug/starpu_debug_helpers.h>
  22. #include "../helper.h"
  23. /*
  24. * Trigger a ping-pong test between two CUDA GPUs
  25. */
  26. static size_t vector_size = 1;
  27. static int niter = 1000;
  28. //static unsigned cnt;
  29. //static unsigned finished = 0;
  30. starpu_data_handle_t v_handle;
  31. static unsigned *v;
  32. static char worker_0_name[128];
  33. static char worker_1_name[128];
  34. static unsigned memory_node_0;
  35. static unsigned memory_node_1;
  36. double start;
  37. double end;
  38. int main(int argc, char **argv)
  39. {
  40. int ret;
  41. ret = starpu_initialize(NULL, &argc, &argv);
  42. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  43. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  44. /* Create a piece of data */
  45. ret = starpu_malloc((void **)&v, vector_size);
  46. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  47. starpu_vector_data_register(&v_handle, STARPU_MAIN_RAM, (uintptr_t)v, vector_size, 1);
  48. /* Find a pair of memory nodes */
  49. if (starpu_cuda_worker_get_count() > 1)
  50. {
  51. /* Take the two devices that come first */
  52. int nworkers = (int)starpu_worker_get_count();
  53. unsigned found_node_0 = 0;
  54. int w;
  55. for (w = 0; w < nworkers; w++)
  56. {
  57. if (starpu_worker_get_type(w) == STARPU_CUDA_WORKER)
  58. {
  59. if (!found_node_0)
  60. {
  61. memory_node_0 = starpu_worker_get_memory_node(w);
  62. starpu_worker_get_name(w, worker_0_name, 128);
  63. found_node_0 = 1;
  64. }
  65. else
  66. {
  67. memory_node_1 = starpu_worker_get_memory_node(w);
  68. starpu_worker_get_name(w, worker_1_name, 128);
  69. break;
  70. }
  71. }
  72. }
  73. fprintf(stderr, "Ping-pong will be done between %s (node %u) and %s (node %u)\n",
  74. worker_0_name, memory_node_0, worker_1_name, memory_node_1);
  75. }
  76. // unsigned iter;
  77. /* warm up */
  78. // unsigned nwarmupiter = 128;
  79. _starpu_benchmark_ping_pong(v_handle, memory_node_0, memory_node_1, 128);
  80. start = starpu_timing_now();
  81. _starpu_benchmark_ping_pong(v_handle, memory_node_0, memory_node_1, niter);
  82. end = starpu_timing_now();
  83. double timing = end - start;
  84. fprintf(stderr, "Took %f ms\n", timing/1000);
  85. fprintf(stderr, "Avg. transfer time : %f us\n", timing/(2*niter));
  86. starpu_data_unregister(v_handle);
  87. starpu_free(v);
  88. starpu_shutdown();
  89. return EXIT_SUCCESS;
  90. }