stencil.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2009-2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 __STENCIL_H__
  17. #define __STENCIL_H__
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <starpu.h>
  21. #ifdef STARPU_USE_CUDA
  22. #include <starpu_cuda.h>
  23. #endif
  24. #ifndef __CUDACC__
  25. #ifdef STARPU_USE_MPI
  26. #include <mpi.h>
  27. #include <starpu_mpi.h>
  28. #endif
  29. #endif
  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. /* Split only on the z axis to make things simple */
  40. typedef enum {
  41. B = 0,
  42. T = 1
  43. } direction;
  44. /* Description of a domain block */
  45. struct block_description {
  46. /* Which MPI node should process that block ? */
  47. unsigned 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 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 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. struct block_description *get_block_description(int z);
  72. void assign_blocks_to_mpi_nodes(int world_size);
  73. void allocate_memory_on_node(int rank);
  74. void assign_blocks_to_workers(int rank);
  75. void create_tasks(int rank);
  76. void wait_end_tasks(int rank);
  77. void check(int rank);
  78. void display_memory_consumption(int rank);
  79. unsigned get_block_mpi_node(int z);
  80. unsigned get_block_size(int z);
  81. unsigned get_bind_tasks(void);
  82. unsigned get_nbz(void);
  83. unsigned get_niter(void);
  84. unsigned get_ticks(void);
  85. unsigned global_workerid(unsigned local_workerid);
  86. void create_task_update(unsigned iter, unsigned z, unsigned local_rank);
  87. void create_task_save(unsigned iter, unsigned z, int dir, unsigned local_rank);
  88. extern int starpu_mpi_initialize(void);
  89. extern int starpu_mpi_shutdown(void);
  90. /* kernels */
  91. extern starpu_codelet cl_update;
  92. extern starpu_codelet save_cl_bottom;
  93. extern starpu_codelet save_cl_top;
  94. extern unsigned update_per_worker[STARPU_NMAXWORKERS];
  95. extern unsigned top_per_worker[STARPU_NMAXWORKERS];
  96. extern unsigned bottom_per_worker[STARPU_NMAXWORKERS];
  97. extern struct timeval start;
  98. extern int who_runs_what_len;
  99. extern int *who_runs_what;
  100. extern int *who_runs_what_index;
  101. extern struct timeval *last_tick;
  102. #ifndef _externC
  103. #define _externC
  104. #endif
  105. _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);
  106. _externC void cuda_shadow_host(int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz, int i);
  107. #endif // __STENCIL_H__