simgrid.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016,2017 Inria
  4. * Copyright (C) 2013,2017 CNRS
  5. * Copyright (C) 2012-2020 Université de Bordeaux
  6. * Copyright (C) 2013 Thibaut Lambert
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #ifndef __SIMGRID_H__
  20. #define __SIMGRID_H__
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. #ifdef STARPU_SIMGRID
  26. #ifdef STARPU_HAVE_SIMGRID_MSG_H
  27. #include <simgrid/msg.h>
  28. #elif defined(STARPU_HAVE_MSG_MSG_H)
  29. #include <msg/msg.h>
  30. #endif
  31. #ifdef STARPU_HAVE_XBT_BASE_H
  32. #include <xbt/base.h>
  33. #endif
  34. #ifdef STARPU_HAVE_SIMGRID_VERSION_H
  35. #include <simgrid/version.h>
  36. #endif
  37. #ifdef STARPU_HAVE_SIMGRID_ZONE_H
  38. #include <simgrid/zone.h>
  39. #endif
  40. #ifdef STARPU_HAVE_SIMGRID_HOST_H
  41. #include <simgrid/host.h>
  42. #endif
  43. #include <xbt/xbt_os_time.h>
  44. struct _starpu_pthread_args
  45. {
  46. void *(*f)(void*);
  47. void *arg;
  48. };
  49. #define MAX_TSD 16
  50. #define STARPU_MPI_AS_PREFIX "StarPU-MPI"
  51. #define _starpu_simgrid_running_smpi() (getenv("SMPI_GLOBAL_SIZE") != NULL)
  52. void _starpu_start_simgrid(int *argc, char **argv);
  53. void _starpu_simgrid_init_early(int *argc, char ***argv);
  54. void _starpu_simgrid_init(void);
  55. void _starpu_simgrid_deinit(void);
  56. void _starpu_simgrid_deinit_late(void);
  57. void _starpu_simgrid_wait_tasks(int workerid);
  58. struct _starpu_job;
  59. void _starpu_simgrid_submit_job(int workerid, struct _starpu_job *job, struct starpu_perfmodel_arch* perf_arch, double length, unsigned *finished);
  60. struct _starpu_data_request;
  61. int _starpu_simgrid_transfer(size_t size, unsigned src_node, unsigned dst_node, struct _starpu_data_request *req);
  62. union _starpu_async_channel_event;
  63. int _starpu_simgrid_wait_transfer_event(union _starpu_async_channel_event *event);
  64. int _starpu_simgrid_test_transfer_event(union _starpu_async_channel_event *event);
  65. void _starpu_simgrid_sync_gpus(void);
  66. /* Return the number of hosts prefixed by PREFIX */
  67. int _starpu_simgrid_get_nbhosts(const char *prefix);
  68. unsigned long long _starpu_simgrid_get_memsize(const char *prefix, unsigned devid);
  69. starpu_sg_host_t _starpu_simgrid_get_host_by_name(const char *name);
  70. starpu_sg_host_t _starpu_simgrid_get_memnode_host(unsigned node);
  71. struct _starpu_worker;
  72. starpu_sg_host_t _starpu_simgrid_get_host_by_worker(struct _starpu_worker *worker);
  73. void _starpu_simgrid_get_platform_path(int version, char *path, size_t maxlen);
  74. #if defined(HAVE_SG_ZONE_GET_BY_NAME) || defined(sg_zone_get_by_name)
  75. sg_netzone_t _starpu_simgrid_get_as_by_name(const char *name);
  76. #else
  77. msg_as_t _starpu_simgrid_get_as_by_name(const char *name);
  78. #endif
  79. #pragma weak starpu_mpi_world_rank
  80. extern int starpu_mpi_world_rank(void);
  81. #pragma weak _starpu_mpi_simgrid_init
  82. int _starpu_mpi_simgrid_init(int argc, char *argv[]);
  83. extern starpu_pthread_queue_t _starpu_simgrid_transfer_queue[STARPU_MAXNODES];
  84. extern starpu_pthread_queue_t _starpu_simgrid_task_queue[STARPU_NMAXWORKERS];
  85. #define _starpu_simgrid_cuda_malloc_cost() starpu_get_env_number_default("STARPU_SIMGRID_CUDA_MALLOC_COST", 1)
  86. #define _starpu_simgrid_queue_malloc_cost() starpu_get_env_number_default("STARPU_SIMGRID_QUEUE_MALLOC_COST", 1)
  87. #define _starpu_simgrid_task_submit_cost() starpu_get_env_number_default("STARPU_SIMGRID_TASK_SUBMIT_COST", 1)
  88. #define _starpu_simgrid_fetching_input_cost() starpu_get_env_number_default("STARPU_SIMGRID_FETCHING_INPUT_COST", 1)
  89. #define _starpu_simgrid_sched_cost() starpu_get_env_number_default("STARPU_SIMGRID_SCHED_COST", 0)
  90. /* Called at initialization to count how many GPUs are interfering with each
  91. * bus */
  92. void _starpu_simgrid_count_ngpus(void);
  93. void _starpu_simgrid_xbt_thread_create(const char *name, void_f_pvoid_t code,
  94. void *param);
  95. #define _SIMGRID_TIMER_BEGIN(cond) \
  96. { \
  97. xbt_os_timer_t __timer = NULL; \
  98. if (cond) { \
  99. __timer = xbt_os_timer_new(); \
  100. xbt_os_threadtimer_start(__timer); \
  101. }
  102. #define _SIMGRID_TIMER_END \
  103. if (__timer) { \
  104. xbt_os_threadtimer_stop(__timer); \
  105. starpu_sleep(xbt_os_timer_elapsed(__timer));\
  106. xbt_os_timer_free(__timer); \
  107. } \
  108. }
  109. #else // !STARPU_SIMGRID
  110. #define _SIMGRID_TIMER_BEGIN(cond) {
  111. #define _SIMGRID_TIMER_END }
  112. #endif
  113. /* Experimental functions for OOC stochastic analysis */
  114. /* disk <-> MAIN_RAM only */
  115. #if defined(STARPU_SIMGRID) && 0
  116. void _starpu_simgrid_data_new(size_t size);
  117. void _starpu_simgrid_data_increase(size_t size);
  118. void _starpu_simgrid_data_alloc(size_t size);
  119. void _starpu_simgrid_data_free(size_t size);
  120. void _starpu_simgrid_data_transfer(size_t size, unsigned src_node, unsigned dst_node);
  121. #else
  122. #define _starpu_simgrid_data_new(size) (void)0
  123. #define _starpu_simgrid_data_increase(size) (void)0
  124. #define _starpu_simgrid_data_alloc(size) (void)0
  125. #define _starpu_simgrid_data_free(size) (void)0
  126. #define _starpu_simgrid_data_transfer(size, src_node, dst_node) (void)0
  127. #endif
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif // __SIMGRID_H__