local_pingpong.c 2.9 KB

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