local_pingpong.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2011,2013,2014,2016 Université de Bordeaux
  4. * Copyright (C) 2013 Inria
  5. * Copyright (C) 2010-2013,2015,2017 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <errno.h>
  21. #include <starpu.h>
  22. #include <stdlib.h>
  23. #include <debug/starpu_debug_helpers.h>
  24. #include "../helper.h"
  25. /*
  26. * Trigger a ping-pong test between two CUDA GPUs
  27. */
  28. static size_t vector_size = 1;
  29. static int niter = 1000;
  30. //static unsigned cnt;
  31. //static unsigned finished = 0;
  32. starpu_data_handle_t v_handle;
  33. static unsigned *v;
  34. static char worker_0_name[128];
  35. static char worker_1_name[128];
  36. static unsigned memory_node_0;
  37. static unsigned memory_node_1;
  38. double start;
  39. double end;
  40. int main(int argc, char **argv)
  41. {
  42. int ret;
  43. ret = starpu_initialize(NULL, &argc, &argv);
  44. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  46. /* Create a piece of data */
  47. ret = starpu_malloc((void **)&v, vector_size);
  48. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  49. starpu_vector_data_register(&v_handle, STARPU_MAIN_RAM, (uintptr_t)v, vector_size, 1);
  50. /* Find a pair of memory nodes */
  51. if (starpu_cuda_worker_get_count() > 1)
  52. {
  53. /* Take the two devices that come first */
  54. int nworkers = (int)starpu_worker_get_count();
  55. unsigned found_node_0 = 0;
  56. int w;
  57. for (w = 0; w < nworkers; w++)
  58. {
  59. if (starpu_worker_get_type(w) == STARPU_CUDA_WORKER)
  60. {
  61. if (!found_node_0)
  62. {
  63. memory_node_0 = starpu_worker_get_memory_node(w);
  64. starpu_worker_get_name(w, worker_0_name, 128);
  65. found_node_0 = 1;
  66. }
  67. else
  68. {
  69. memory_node_1 = starpu_worker_get_memory_node(w);
  70. starpu_worker_get_name(w, worker_1_name, 128);
  71. break;
  72. }
  73. }
  74. }
  75. fprintf(stderr, "Ping-pong will be done between %s (node %u) and %s (node %u)\n",
  76. worker_0_name, memory_node_0, worker_1_name, memory_node_1);
  77. }
  78. // unsigned iter;
  79. /* warm up */
  80. // unsigned nwarmupiter = 128;
  81. _starpu_benchmark_ping_pong(v_handle, memory_node_0, memory_node_1, 128);
  82. start = starpu_timing_now();
  83. _starpu_benchmark_ping_pong(v_handle, memory_node_0, memory_node_1, niter);
  84. end = starpu_timing_now();
  85. double timing = end - start;
  86. fprintf(stderr, "Took %f ms\n", timing/1000);
  87. fprintf(stderr, "Avg. transfer time : %f us\n", timing/(2*niter));
  88. starpu_data_unregister(v_handle);
  89. starpu_free(v);
  90. starpu_shutdown();
  91. return EXIT_SUCCESS;
  92. }