simgrid.h 5.3 KB

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