local_pingpong.c 2.6 KB

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