local_pingpong.c 2.9 KB

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