local_pingpong.c 2.7 KB

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