simgrid.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. /* 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. struct _starpu_pthread_args
  46. {
  47. void *(*f)(void*);
  48. void *arg;
  49. };
  50. #define MAX_TSD 16
  51. #define STARPU_MPI_AS_PREFIX "StarPU-MPI"
  52. #define _starpu_simgrid_running_smpi() (getenv("SMPI_GLOBAL_SIZE") != NULL)
  53. void _starpu_start_simgrid(int *argc, char **argv);
  54. void _starpu_simgrid_init_early(int *argc, char ***argv);
  55. void _starpu_simgrid_init(void);
  56. void _starpu_simgrid_deinit(void);
  57. void _starpu_simgrid_deinit_late(void);
  58. void _starpu_simgrid_actor_setup(void);
  59. void _starpu_simgrid_wait_tasks(int workerid);
  60. struct _starpu_job;
  61. 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);
  62. struct _starpu_data_request;
  63. int _starpu_simgrid_transfer(size_t size, unsigned src_node, unsigned dst_node, struct _starpu_data_request *req);
  64. union _starpu_async_channel_event;
  65. int _starpu_simgrid_wait_transfer_event(union _starpu_async_channel_event *event);
  66. int _starpu_simgrid_test_transfer_event(union _starpu_async_channel_event *event);
  67. void _starpu_simgrid_sync_gpus(void);
  68. /** Return the number of hosts prefixed by PREFIX */
  69. int _starpu_simgrid_get_nbhosts(const char *prefix);
  70. unsigned long long _starpu_simgrid_get_memsize(const char *prefix, unsigned devid);
  71. starpu_sg_host_t _starpu_simgrid_get_host_by_name(const char *name);
  72. starpu_sg_host_t _starpu_simgrid_get_memnode_host(unsigned node);
  73. struct _starpu_worker;
  74. starpu_sg_host_t _starpu_simgrid_get_host_by_worker(struct _starpu_worker *worker);
  75. void _starpu_simgrid_get_platform_path(int version, char *path, size_t maxlen);
  76. #if defined(HAVE_SG_ZONE_GET_BY_NAME) || defined(sg_zone_get_by_name)
  77. sg_netzone_t _starpu_simgrid_get_as_by_name(const char *name);
  78. #else
  79. msg_as_t _starpu_simgrid_get_as_by_name(const char *name);
  80. #endif
  81. #pragma weak starpu_mpi_world_rank
  82. extern int starpu_mpi_world_rank(void);
  83. #pragma weak _starpu_mpi_simgrid_init
  84. int _starpu_mpi_simgrid_init(int argc, char *argv[]);
  85. extern starpu_pthread_queue_t _starpu_simgrid_transfer_queue[STARPU_MAXNODES];
  86. extern starpu_pthread_queue_t _starpu_simgrid_task_queue[STARPU_NMAXWORKERS];
  87. #define _starpu_simgrid_cuda_malloc_cost() starpu_get_env_number_default("STARPU_SIMGRID_CUDA_MALLOC_COST", 1)
  88. #define _starpu_simgrid_queue_malloc_cost() starpu_get_env_number_default("STARPU_SIMGRID_QUEUE_MALLOC_COST", 1)
  89. #define _starpu_simgrid_task_submit_cost() starpu_get_env_number_default("STARPU_SIMGRID_TASK_SUBMIT_COST", 1)
  90. #define _starpu_simgrid_fetching_input_cost() starpu_get_env_number_default("STARPU_SIMGRID_FETCHING_INPUT_COST", 1)
  91. #define _starpu_simgrid_sched_cost() starpu_get_env_number_default("STARPU_SIMGRID_SCHED_COST", 0)
  92. /** Called at initialization to count how many GPUs are interfering with each
  93. * bus */
  94. void _starpu_simgrid_count_ngpus(void);
  95. extern size_t _starpu_default_stack_size;
  96. void _starpu_simgrid_set_stack_size(size_t stack_size);
  97. void _starpu_simgrid_xbt_thread_create(const char *name, starpu_pthread_attr_t *attr, void_f_pvoid_t code,
  98. void *param);
  99. #define _SIMGRID_TIMER_BEGIN(cond) \
  100. { \
  101. xbt_os_timer_t __timer = NULL; \
  102. if (cond) { \
  103. __timer = xbt_os_timer_new(); \
  104. xbt_os_threadtimer_start(__timer); \
  105. }
  106. #define _SIMGRID_TIMER_END \
  107. if (__timer) { \
  108. xbt_os_threadtimer_stop(__timer); \
  109. starpu_sleep(xbt_os_timer_elapsed(__timer));\
  110. xbt_os_timer_free(__timer); \
  111. } \
  112. }
  113. #else // !STARPU_SIMGRID
  114. #define _SIMGRID_TIMER_BEGIN(cond) {
  115. #define _SIMGRID_TIMER_END }
  116. #endif
  117. /** Experimental functions for OOC stochastic analysis */
  118. /* disk <-> MAIN_RAM only */
  119. #if defined(STARPU_SIMGRID) && 0
  120. void _starpu_simgrid_data_new(size_t size);
  121. void _starpu_simgrid_data_increase(size_t size);
  122. void _starpu_simgrid_data_alloc(size_t size);
  123. void _starpu_simgrid_data_free(size_t size);
  124. void _starpu_simgrid_data_transfer(size_t size, unsigned src_node, unsigned dst_node);
  125. #else
  126. #define _starpu_simgrid_data_new(size) (void)0
  127. #define _starpu_simgrid_data_increase(size) (void)0
  128. #define _starpu_simgrid_data_alloc(size) (void)0
  129. #define _starpu_simgrid_data_free(size) (void)0
  130. #define _starpu_simgrid_data_transfer(size, src_node, dst_node) (void)0
  131. #endif
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif // __SIMGRID_H__