implicit-stencil.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016-2017 Inria
  4. * Copyright (C) 2010-2013,2017 CNRS
  5. * Copyright (C) 2010-2011,2014 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __IMPLICIT_STENCIL_H__
  19. #define __IMPLICIT_STENCIL_H__
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <starpu.h>
  23. #ifndef __CUDACC__
  24. #if defined(STARPU_USE_MPI) && !defined(STARPU_USE_MPI_MASTER_SLAVE)
  25. #include <mpi.h>
  26. #include <starpu_mpi.h>
  27. #endif
  28. #endif
  29. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  30. #define LIFE
  31. #ifdef LIFE
  32. #define TYPE unsigned char
  33. extern void life_update(int bz, const TYPE *old, TYPE *newp, int nx, int ny, int nz, int ldy, int ldz, int iter);
  34. #else
  35. #define TYPE float
  36. #endif
  37. #define K 1
  38. #define NDIRS 2
  39. extern struct starpu_top_data* starpu_top_init_loop;
  40. extern struct starpu_top_data* starpu_top_achieved_loop;
  41. /* Split only on the z axis to make things simple */
  42. typedef enum
  43. {
  44. B = 0,
  45. T = 1
  46. } direction;
  47. /* Description of a domain block */
  48. struct block_description
  49. {
  50. /* Which MPI node should process that block ? */
  51. int mpi_node;
  52. unsigned preferred_worker;
  53. unsigned bz;
  54. /* For each of the following buffers, there are two (0/1) buffers to
  55. * make new/old switch costless. */
  56. /* This is the computation buffer for this block, it includes
  57. * neighbours' border to make computation easier */
  58. TYPE *layers[2];
  59. starpu_data_handle_t layers_handle[2];
  60. /* This is the "save" buffer, i.e. a copy of our neighbour's border.
  61. * This one is used for CPU/GPU or MPI communication (rather than the
  62. * whole domain block) */
  63. TYPE *boundaries[NDIRS][2];
  64. starpu_data_handle_t boundaries_handle[NDIRS][2];
  65. /* Shortcut pointer to the neighbours */
  66. struct block_description *boundary_blocks[NDIRS];
  67. };
  68. #define TAG_INIT_TASK ((starpu_tag_t)1)
  69. starpu_tag_t TAG_FINISH(int z);
  70. starpu_tag_t TAG_START(int z, int dir);
  71. int MPI_TAG0(int z, int iter, int dir);
  72. int MPI_TAG1(int z, int iter, int dir);
  73. #define MIN(a,b) ((a)<(b)?(a):(b))
  74. void create_blocks_array(unsigned sizex, unsigned sizey, unsigned sizez, unsigned nbz);
  75. void free_blocks_array();
  76. struct block_description *get_block_description(int z);
  77. void assign_blocks_to_mpi_nodes(int world_size);
  78. void allocate_memory_on_node(int rank);
  79. void assign_blocks_to_workers(int rank);
  80. void create_tasks(int rank);
  81. void wait_end_tasks(int rank);
  82. void check(int rank);
  83. void free_memory_on_node(int rank);
  84. void display_memory_consumption(int rank, double time);
  85. int get_block_mpi_node(int z);
  86. unsigned get_block_size(int z);
  87. unsigned get_bind_tasks(void);
  88. unsigned get_nbz(void);
  89. unsigned get_niter(void);
  90. unsigned get_ticks(void);
  91. unsigned global_workerid(unsigned local_workerid);
  92. void create_task_memset(unsigned sizex, unsigned sizey, unsigned z);
  93. void create_task_initlayer(unsigned sizex, unsigned sizey, unsigned z);
  94. void create_task_update(unsigned iter, unsigned z, int local_rank);
  95. void create_task_save(unsigned iter, unsigned z, int dir, int local_rank);
  96. extern int starpu_mpi_initialize(void);
  97. extern int starpu_mpi_shutdown(void);
  98. /* kernels */
  99. extern struct starpu_codelet cl_update;
  100. extern struct starpu_codelet save_cl_bottom;
  101. extern struct starpu_codelet save_cl_top;
  102. extern struct starpu_codelet cl_memset;
  103. extern struct starpu_codelet cl_initlayer;
  104. extern unsigned update_per_worker[STARPU_NMAXWORKERS];
  105. extern unsigned top_per_worker[STARPU_NMAXWORKERS];
  106. extern unsigned bottom_per_worker[STARPU_NMAXWORKERS];
  107. extern double start;
  108. extern int who_runs_what_len;
  109. extern int *who_runs_what;
  110. extern int *who_runs_what_index;
  111. extern double *last_tick;
  112. #ifndef _externC
  113. #define _externC
  114. #endif
  115. _externC void cuda_life_update_host(int bz, const TYPE *old, TYPE *newp, int nx, int ny, int nz, int ldy, int ldz, int iter);
  116. _externC void cuda_shadow_host(int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz, int i);
  117. _externC void opencl_shadow_init(void);
  118. _externC void opencl_shadow_free(void);
  119. _externC void opencl_shadow_host(int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz, int i);
  120. _externC void opencl_life_init(void);
  121. _externC void opencl_life_free(void);
  122. _externC void opencl_life_update_host(int bz, const TYPE *old, TYPE *newp, int nx, int ny, int nz, int ldy, int ldz, int iter);
  123. #endif /* __IMPLICIT_STENCIL_H__ */