stencil.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  4. * Copyright (C) 2010-2011 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. #include <starpu_top.h>
  23. #ifdef STARPU_USE_CUDA
  24. #include <starpu_cuda.h>
  25. #endif
  26. #ifndef __CUDACC__
  27. #ifdef STARPU_USE_MPI
  28. #include <mpi.h>
  29. #include <starpu_mpi.h>
  30. #endif
  31. #endif
  32. #define LIFE
  33. #ifdef LIFE
  34. #define TYPE unsigned char
  35. extern void life_update(int bz, const TYPE *old, TYPE *newp, int nx, int ny, int nz, int ldy, int ldz, int iter);
  36. #else
  37. #define TYPE float
  38. #endif
  39. #define K 1
  40. #define NDIRS 2
  41. extern struct starpu_top_data* starpu_top_init_loop;
  42. extern struct starpu_top_data* starpu_top_achieved_loop;
  43. /* Split only on the z axis to make things simple */
  44. typedef enum
  45. {
  46. B = 0,
  47. T = 1
  48. } direction;
  49. /* Description of a domain block */
  50. struct block_description
  51. {
  52. /* Which MPI node should process that block ? */
  53. unsigned mpi_node;
  54. unsigned preferred_worker;
  55. unsigned bz;
  56. /* For each of the following buffers, there are two (0/1) buffers to
  57. * make new/old switch costless. */
  58. /* This is the computation buffer for this block, it includes
  59. * neighbours' border to make computation easier */
  60. TYPE *layers[2];
  61. starpu_data_handle_t layers_handle[2];
  62. /* This is the "save" buffer, i.e. a copy of our neighbour's border.
  63. * This one is used for CPU/GPU or MPI communication (rather than the
  64. * whole domain block) */
  65. TYPE *boundaries[NDIRS][2];
  66. starpu_data_handle_t boundaries_handle[NDIRS][2];
  67. /* Shortcut pointer to the neighbours */
  68. struct block_description *boundary_blocks[NDIRS];
  69. };
  70. #define TAG_INIT_TASK ((starpu_tag_t)1)
  71. starpu_tag_t TAG_FINISH(int z);
  72. starpu_tag_t TAG_START(int z, int dir);
  73. int MPI_TAG0(int z, int iter, int dir);
  74. int MPI_TAG1(int z, int iter, int dir);
  75. #define MIN(a,b) ((a)<(b)?(a):(b))
  76. void create_blocks_array(unsigned sizex, unsigned sizey, unsigned sizez, unsigned nbz);
  77. struct block_description *get_block_description(int z);
  78. void assign_blocks_to_mpi_nodes(int world_size);
  79. void allocate_memory_on_node(int rank);
  80. void assign_blocks_to_workers(int rank);
  81. void create_tasks(int rank);
  82. void wait_end_tasks(int rank);
  83. void check(int rank);
  84. void display_memory_consumption(int rank);
  85. unsigned 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_update(unsigned iter, unsigned z, unsigned local_rank);
  93. void create_task_save(unsigned iter, unsigned z, int dir, unsigned local_rank);
  94. extern int starpu_mpi_initialize(void);
  95. extern int starpu_mpi_shutdown(void);
  96. /* kernels */
  97. extern struct starpu_codelet cl_update;
  98. extern struct starpu_codelet save_cl_bottom;
  99. extern struct starpu_codelet save_cl_top;
  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 struct timeval start;
  104. extern int who_runs_what_len;
  105. extern int *who_runs_what;
  106. extern int *who_runs_what_index;
  107. extern struct timeval *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 /* __STENCIL_H__ */