local_pingpong.c 2.5 KB

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