simgrid.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Thibaut Lambert
  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. #ifndef __SIMGRID_H__
  18. #define __SIMGRID_H__
  19. /** @file */
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. #ifdef STARPU_SIMGRID
  25. #ifdef STARPU_HAVE_SIMGRID_MSG_H
  26. #include <simgrid/msg.h>
  27. #elif defined(STARPU_HAVE_MSG_MSG_H)
  28. #include <msg/msg.h>
  29. #endif
  30. #ifdef STARPU_HAVE_XBT_BASE_H
  31. #include <xbt/base.h>
  32. #endif
  33. #ifdef STARPU_HAVE_SIMGRID_VERSION_H
  34. #include <simgrid/version.h>
  35. #endif
  36. #ifdef STARPU_HAVE_SIMGRID_ZONE_H
  37. #include <simgrid/zone.h>
  38. #endif
  39. #ifdef STARPU_HAVE_SIMGRID_HOST_H
  40. #include <simgrid/host.h>
  41. #endif
  42. #include <xbt/xbt_os_time.h>
  43. struct _starpu_pthread_args
  44. {
  45. void *(*f)(void*);
  46. void *arg;
  47. };
  48. #define MAX_TSD 16
  49. #define STARPU_MPI_AS_PREFIX "StarPU-MPI"
  50. #define _starpu_simgrid_running_smpi() (getenv("SMPI_GLOBAL_SIZE") != NULL)
  51. void _starpu_start_simgrid(int *argc, char **argv);
  52. void _starpu_simgrid_init_early(int *argc, char ***argv);
  53. void _starpu_simgrid_init(void);
  54. void _starpu_simgrid_deinit(void);
  55. void _starpu_simgrid_deinit_late(void);
  56. void _starpu_simgrid_actor_setup(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. extern size_t _starpu_default_stack_size;
  94. void _starpu_simgrid_set_stack_size(size_t stack_size);
  95. void _starpu_simgrid_xbt_thread_create(const char *name, starpu_pthread_attr_t *attr, void_f_pvoid_t code,
  96. void *param);
  97. #define _SIMGRID_TIMER_BEGIN(cond) \
  98. { \
  99. xbt_os_timer_t __timer = NULL; \
  100. if (cond) { \
  101. __timer = xbt_os_timer_new(); \
  102. xbt_os_threadtimer_start(__timer); \
  103. }
  104. #define _SIMGRID_TIMER_END \
  105. if (__timer) { \
  106. xbt_os_threadtimer_stop(__timer); \
  107. starpu_sleep(xbt_os_timer_elapsed(__timer));\
  108. xbt_os_timer_free(__timer); \
  109. } \
  110. }
  111. #else // !STARPU_SIMGRID
  112. #define _SIMGRID_TIMER_BEGIN(cond) {
  113. #define _SIMGRID_TIMER_END }
  114. #endif
  115. /** Experimental functions for OOC stochastic analysis */
  116. /* disk <-> MAIN_RAM only */
  117. #if defined(STARPU_SIMGRID) && 0
  118. void _starpu_simgrid_data_new(size_t size);
  119. void _starpu_simgrid_data_increase(size_t size);
  120. void _starpu_simgrid_data_alloc(size_t size);
  121. void _starpu_simgrid_data_free(size_t size);
  122. void _starpu_simgrid_data_transfer(size_t size, unsigned src_node, unsigned dst_node);
  123. #else
  124. #define _starpu_simgrid_data_new(size) (void)0
  125. #define _starpu_simgrid_data_increase(size) (void)0
  126. #define _starpu_simgrid_data_alloc(size) (void)0
  127. #define _starpu_simgrid_data_free(size) (void)0
  128. #define _starpu_simgrid_data_transfer(size, src_node, dst_node) (void)0
  129. #endif
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif // __SIMGRID_H__