local_pingpong.c 2.5 KB

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