implicit-stencil.h 4.6 KB

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