local_pingpong.c 2.8 KB

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