local_pingpong.c 2.9 KB

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