stencil.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  4. * Copyright (C) 2010 Université de Bordeaux 1
  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 __STENCIL_H__
  18. #define __STENCIL_H__
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <starpu.h>
  22. #ifdef STARPU_USE_CUDA
  23. #include <starpu_cuda.h>
  24. #endif
  25. #ifndef __CUDACC__
  26. #ifdef STARPU_USE_MPI
  27. #include <mpi.h>
  28. #include <starpu_mpi.h>
  29. #endif
  30. #endif
  31. #define LIFE
  32. #ifdef LIFE
  33. #define TYPE unsigned char
  34. extern void life_update(int bz, const TYPE *old, TYPE *newp, int nx, int ny, int nz, int ldy, int ldz, int iter);
  35. #else
  36. #define TYPE float
  37. #endif
  38. #define K 1
  39. #define NDIRS 2
  40. /* Split only on the z axis to make things simple */
  41. typedef enum {
  42. B = 0,
  43. T = 1
  44. } direction;
  45. /* Description of a domain block */
  46. struct block_description {
  47. /* Which MPI node should process that block ? */
  48. unsigned mpi_node;
  49. unsigned preferred_worker;
  50. unsigned bz;
  51. /* For each of the following buffers, there are two (0/1) buffers to
  52. * make new/old switch costless. */
  53. /* This is the computation buffer for this block, it includes
  54. * neighbours' border to make computation easier */
  55. TYPE *layers[2];
  56. starpu_data_handle layers_handle[2];
  57. /* This is the "save" buffer, i.e. a copy of our neighbour's border.
  58. * This one is used for CPU/GPU or MPI communication (rather than the
  59. * whole domain block) */
  60. TYPE *boundaries[NDIRS][2];
  61. starpu_data_handle boundaries_handle[NDIRS][2];
  62. /* Shortcut pointer to the neighbours */
  63. struct block_description *boundary_blocks[NDIRS];
  64. };
  65. #define TAG_INIT_TASK ((starpu_tag_t)1)
  66. starpu_tag_t TAG_FINISH(int z);
  67. starpu_tag_t TAG_START(int z, int dir);
  68. int MPI_TAG0(int z, int iter, int dir);
  69. int MPI_TAG1(int z, int iter, int dir);
  70. #define MIN(a,b) ((a)<(b)?(a):(b))
  71. void create_blocks_array(unsigned sizex, unsigned sizey, unsigned sizez, unsigned nbz);
  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 display_memory_consumption(int rank);
  80. unsigned get_block_mpi_node(int z);
  81. unsigned get_block_size(int z);
  82. unsigned get_bind_tasks(void);
  83. unsigned get_nbz(void);
  84. unsigned get_niter(void);
  85. unsigned get_ticks(void);
  86. unsigned global_workerid(unsigned local_workerid);
  87. void create_task_update(unsigned iter, unsigned z, unsigned local_rank);
  88. void create_task_save(unsigned iter, unsigned z, int dir, unsigned local_rank);
  89. extern int starpu_mpi_initialize(void);
  90. extern int starpu_mpi_shutdown(void);
  91. /* kernels */
  92. extern starpu_codelet cl_update;
  93. extern starpu_codelet save_cl_bottom;
  94. extern starpu_codelet save_cl_top;
  95. extern unsigned update_per_worker[STARPU_NMAXWORKERS];
  96. extern unsigned top_per_worker[STARPU_NMAXWORKERS];
  97. extern unsigned bottom_per_worker[STARPU_NMAXWORKERS];
  98. extern struct timeval start;
  99. extern int who_runs_what_len;
  100. extern int *who_runs_what;
  101. extern int *who_runs_what_index;
  102. extern struct timeval *last_tick;
  103. #ifndef _externC
  104. #define _externC
  105. #endif
  106. _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);
  107. _externC void cuda_shadow_host(int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz, int i);
  108. #endif /* __STENCIL_H__ */