simgrid.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2021 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. /* Note: when changing something here, update the include list in configure.ac
  25. * in the part that tries to enable stdc++11 */
  26. #ifdef STARPU_SIMGRID
  27. #ifdef STARPU_HAVE_SIMGRID_MSG_H
  28. #include <simgrid/msg.h>
  29. #elif defined(STARPU_HAVE_MSG_MSG_H)
  30. #include <msg/msg.h>
  31. #endif
  32. #ifdef STARPU_HAVE_XBT_BASE_H
  33. #include <xbt/base.h>
  34. #endif
  35. #ifdef STARPU_HAVE_SIMGRID_VERSION_H
  36. #include <simgrid/version.h>
  37. #endif
  38. #ifdef STARPU_HAVE_SIMGRID_ZONE_H
  39. #include <simgrid/zone.h>
  40. #endif
  41. #ifdef STARPU_HAVE_SIMGRID_HOST_H
  42. #include <simgrid/host.h>
  43. #endif
  44. #include <xbt/xbt_os_time.h>
  45. #pragma GCC visibility push(hidden)
  46. struct _starpu_pthread_args
  47. {
  48. void *(*f)(void*);
  49. void *arg;
  50. };
  51. #if (SIMGRID_VERSION >= 32600)
  52. typedef void _starpu_simgrid_main_ret;
  53. #define _STARPU_SIMGRID_MAIN_RETURN do { } while (0)
  54. #else
  55. typedef int _starpu_simgrid_main_ret;
  56. #define _STARPU_SIMGRID_MAIN_RETURN return 0
  57. #endif
  58. _starpu_simgrid_main_ret
  59. _starpu_simgrid_thread_start(int argc, char *argv[]);
  60. #define MAX_TSD 16
  61. #define STARPU_MPI_AS_PREFIX "StarPU-MPI"
  62. #define _starpu_simgrid_running_smpi() (getenv("SMPI_GLOBAL_SIZE") != NULL)
  63. void _starpu_start_simgrid(int *argc, char **argv);
  64. void _starpu_simgrid_init_early(int *argc, char ***argv);
  65. void _starpu_simgrid_init(void);
  66. void _starpu_simgrid_deinit(void);
  67. void _starpu_simgrid_deinit_late(void);
  68. void _starpu_simgrid_actor_setup(void);
  69. void _starpu_simgrid_wait_tasks(int workerid);
  70. struct _starpu_job;
  71. void _starpu_simgrid_submit_job(int workerid, int sched_ctx_id, struct _starpu_job *job, struct starpu_perfmodel_arch* perf_arch, double length, double energy, unsigned *finished);
  72. struct _starpu_data_request;
  73. int _starpu_simgrid_transfer(size_t size, unsigned src_node, unsigned dst_node, struct _starpu_data_request *req);
  74. union _starpu_async_channel_event;
  75. int _starpu_simgrid_wait_transfer_event(union _starpu_async_channel_event *event);
  76. int _starpu_simgrid_test_transfer_event(union _starpu_async_channel_event *event);
  77. void _starpu_simgrid_sync_gpus(void);
  78. /** Return the number of hosts prefixed by PREFIX */
  79. int _starpu_simgrid_get_nbhosts(const char *prefix);
  80. unsigned long long _starpu_simgrid_get_memsize(const char *prefix, unsigned devid);
  81. starpu_sg_host_t _starpu_simgrid_get_host_by_name(const char *name);
  82. starpu_sg_host_t _starpu_simgrid_get_memnode_host(unsigned node);
  83. struct _starpu_worker;
  84. starpu_sg_host_t _starpu_simgrid_get_host_by_worker(struct _starpu_worker *worker);
  85. void _starpu_simgrid_get_platform_path(int version, char *path, size_t maxlen);
  86. #if defined(HAVE_SG_ZONE_GET_BY_NAME) || defined(sg_zone_get_by_name)
  87. sg_netzone_t _starpu_simgrid_get_as_by_name(const char *name);
  88. #else
  89. msg_as_t _starpu_simgrid_get_as_by_name(const char *name);
  90. #endif
  91. #pragma weak starpu_mpi_world_rank
  92. extern int starpu_mpi_world_rank(void);
  93. #pragma weak _starpu_mpi_simgrid_init
  94. int _starpu_mpi_simgrid_init(int argc, char *argv[]);
  95. extern starpu_pthread_queue_t _starpu_simgrid_transfer_queue[STARPU_MAXNODES];
  96. extern starpu_pthread_queue_t _starpu_simgrid_task_queue[STARPU_NMAXWORKERS];
  97. #define _starpu_simgrid_cuda_malloc_cost() starpu_get_env_number_default("STARPU_SIMGRID_CUDA_MALLOC_COST", 1)
  98. #define _starpu_simgrid_queue_malloc_cost() starpu_get_env_number_default("STARPU_SIMGRID_QUEUE_MALLOC_COST", 1)
  99. #define _starpu_simgrid_task_submit_cost() starpu_get_env_number_default("STARPU_SIMGRID_TASK_SUBMIT_COST", 1)
  100. #define _starpu_simgrid_fetching_input_cost() starpu_get_env_number_default("STARPU_SIMGRID_FETCHING_INPUT_COST", 1)
  101. #define _starpu_simgrid_sched_cost() starpu_get_env_number_default("STARPU_SIMGRID_SCHED_COST", 0)
  102. /** Called at initialization to count how many GPUs are interfering with each
  103. * bus */
  104. void _starpu_simgrid_count_ngpus(void);
  105. extern size_t _starpu_default_stack_size;
  106. void _starpu_simgrid_set_stack_size(size_t stack_size);
  107. void _starpu_simgrid_xbt_thread_create(const char *name, starpu_pthread_attr_t *attr, void_f_pvoid_t code,
  108. void *param);
  109. #define _SIMGRID_TIMER_BEGIN(cond) \
  110. { \
  111. xbt_os_timer_t __timer = NULL; \
  112. if (cond) { \
  113. __timer = xbt_os_timer_new(); \
  114. xbt_os_threadtimer_start(__timer); \
  115. }
  116. #define _SIMGRID_TIMER_END \
  117. if (__timer) { \
  118. xbt_os_threadtimer_stop(__timer); \
  119. starpu_sleep(xbt_os_timer_elapsed(__timer));\
  120. xbt_os_timer_free(__timer); \
  121. } \
  122. }
  123. #pragma GCC visibility pop
  124. #else // !STARPU_SIMGRID
  125. #define _SIMGRID_TIMER_BEGIN(cond) {
  126. #define _SIMGRID_TIMER_END }
  127. #endif
  128. /** Experimental functions for OOC stochastic analysis */
  129. /* disk <-> MAIN_RAM only */
  130. #if defined(STARPU_SIMGRID) && 0
  131. void _starpu_simgrid_data_new(size_t size);
  132. void _starpu_simgrid_data_increase(size_t size);
  133. void _starpu_simgrid_data_alloc(size_t size);
  134. void _starpu_simgrid_data_free(size_t size);
  135. void _starpu_simgrid_data_transfer(size_t size, unsigned src_node, unsigned dst_node);
  136. #else
  137. #define _starpu_simgrid_data_new(size) (void)0
  138. #define _starpu_simgrid_data_increase(size) (void)0
  139. #define _starpu_simgrid_data_alloc(size) (void)0
  140. #define _starpu_simgrid_data_free(size) (void)0
  141. #define _starpu_simgrid_data_transfer(size, src_node, dst_node) (void)0
  142. #endif
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif // __SIMGRID_H__