Neko  0.9.0
A portable framework for high-order spectral element flow simulations
device_schwarz.F90
Go to the documentation of this file.
1 ! Copyright (c) 2022, The Neko Authors
2 ! All rights reserved.
3 !
4 ! Redistribution and use in source and binary forms, with or without
5 ! modification, are permitted provided that the following conditions
6 ! are met:
7 !
8 ! * Redistributions of source code must retain the above copyright
9 ! notice, this list of conditions and the following disclaimer.
10 !
11 ! * Redistributions in binary form must reproduce the above
12 ! copyright notice, this list of conditions and the following
13 ! disclaimer in the documentation and/or other materials provided
14 ! with the distribution.
15 !
16 ! * Neither the name of the authors nor the names of its
17 ! contributors may be used to endorse or promote products derived
18 ! from this software without specific prior written permission.
19 !
20 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 ! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 ! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 ! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 ! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 ! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 ! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 ! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 ! POSSIBILITY OF SUCH DAMAGE.
32 !
34  use num_types, only : c_rp, rp
35  use utils, only : neko_error
36  use device, only : glb_cmd_queue
37  use, intrinsic :: iso_c_binding, only : c_ptr, c_int
38  implicit none
39  private
40 
41 #ifdef HAVE_HIP
42  interface
43  subroutine hip_schwarz_extrude(arr1_d,l1,f1,arr2_d,l2,f2,nx, nelv, stream) &
44  bind(c, name='hip_schwarz_extrude')
45  use, intrinsic :: iso_c_binding
46  import c_rp
47  implicit none
48  type(c_ptr), value :: arr1_d, arr2_d, stream
49  integer(c_int) :: l1, l2, nx, nelv
50  real(c_rp) :: f1, f2
51 
52  end subroutine hip_schwarz_extrude
53  subroutine hip_schwarz_toext3d(a_d,b_d,nx, nelv, stream) &
54  bind(c, name='hip_schwarz_toext3d')
55  use, intrinsic :: iso_c_binding
56  import c_rp
57  implicit none
58  type(c_ptr), value :: a_d, b_d, stream
59  integer(c_int) :: nx, nelv
60  end subroutine hip_schwarz_toext3d
61  subroutine hip_schwarz_toreg3d(b_d,a_d,nx, nelv, stream) &
62  bind(c, name='hip_schwarz_toreg3d')
63  use, intrinsic :: iso_c_binding
64  import c_rp
65  implicit none
66  type(c_ptr), value :: a_d, b_d, stream
67  integer(c_int) :: nx, nelv
68  end subroutine hip_schwarz_toreg3d
69  end interface
70 #elif HAVE_CUDA
71  interface
72  subroutine cuda_schwarz_extrude(arr1_d,l1,f1,arr2_d,l2,f2,nx, nelv, stream) &
73  bind(c, name='cuda_schwarz_extrude')
74  use, intrinsic :: iso_c_binding
75  import c_rp
76  implicit none
77  type(c_ptr), value :: arr1_d, arr2_d, stream
78 
79  integer(c_int) :: l1, l2, nx, nelv
80  real(c_rp) :: f1, f2
81  end subroutine cuda_schwarz_extrude
82  subroutine cuda_schwarz_toext3d(a_d,b_d,nx, nelv, stream) &
83  bind(c, name='cuda_schwarz_toext3d')
84  use, intrinsic :: iso_c_binding
85  import c_rp
86  implicit none
87  type(c_ptr), value :: a_d, b_d , stream
88  integer(c_int) :: nx, nelv
89  end subroutine cuda_schwarz_toext3d
90  subroutine cuda_schwarz_toreg3d(b_d,a_d,nx, nelv, stream) &
91  bind(c, name='cuda_schwarz_toreg3d')
92  use, intrinsic :: iso_c_binding
93  import c_rp
94  implicit none
95  type(c_ptr), value :: a_d, b_d, stream
96  integer(c_int) :: nx, nelv
97  end subroutine cuda_schwarz_toreg3d
98  end interface
99 #elif HAVE_OPENCL
100  interface
101  subroutine opencl_schwarz_extrude(arr1_d,l1,f1,arr2_d,l2,f2,nx, nelv, stream) &
102  bind(c, name='opencl_schwarz_extrude')
103  use, intrinsic :: iso_c_binding
104  import c_rp
105  implicit none
106  type(c_ptr), value :: arr1_d, arr2_d, stream
107  integer(c_int) :: l1, l2, nx, nelv
108  real(c_rp) :: f1, f2
109  end subroutine opencl_schwarz_extrude
110  subroutine opencl_schwarz_toext3d(a_d,b_d,nx, nelv, stream) &
111  bind(c, name='opencl_schwarz_toext3d')
112  use, intrinsic :: iso_c_binding
113  import c_rp
114  implicit none
115  type(c_ptr), value :: a_d, b_d, stream
116  integer(c_int) :: nx, nelv
117  end subroutine opencl_schwarz_toext3d
118  subroutine opencl_schwarz_toreg3d(b_d,a_d,nx, nelv, stream) &
119  bind(c, name='opencl_schwarz_toreg3d')
120  use, intrinsic :: iso_c_binding
121  import c_rp
122  implicit none
123  type(c_ptr), value :: a_d, b_d, stream
124  integer(c_int) :: nx, nelv
125  end subroutine opencl_schwarz_toreg3d
126  end interface
127 #endif
128 
131 
132 contains
133  subroutine device_schwarz_extrude(arr1_d,l1,f1,arr2_d,l2,f2,nx,ny,nz, nelv, stream)
134  integer, intent(in) :: l1,l2,nx,ny,nz, nelv
135  type(c_ptr), intent(inout) :: arr1_d,arr2_d
136  real(kind=rp), intent(in) :: f1,f2
137  type(c_ptr), optional :: stream
138  if (.not. present(stream)) then
139  stream = glb_cmd_queue
140  end if
141 #ifdef HAVE_HIP
142  call hip_schwarz_extrude(arr1_d,l1,f1,arr2_d,l2,f2,nx,nelv, stream)
143 #elif HAVE_CUDA
144  call cuda_schwarz_extrude(arr1_d,l1,f1,arr2_d,l2,f2,nx,nelv, stream)
145 #elif HAVE_OPENCL
146  call opencl_schwarz_extrude(arr1_d,l1,f1,arr2_d,l2,f2,nx,nelv, stream)
147 #else
148  call neko_error('No device backend configured')
149 #endif
150  end subroutine device_schwarz_extrude
151 
152  subroutine device_schwarz_toext3d(a_d,b_d,nx, nelv, stream)
153  integer, intent(in) :: nx, nelv
154  type(c_ptr) :: a_d, b_d
155  type(c_ptr), optional :: stream
156  if (.not. present(stream)) then
157  stream = glb_cmd_queue
158  end if
159 
160 #ifdef HAVE_HIP
161  call hip_schwarz_toext3d(a_d,b_d,nx,nelv, stream)
162 #elif HAVE_CUDA
163  call cuda_schwarz_toext3d(a_d,b_d,nx,nelv, stream)
164 #elif HAVE_OPENCL
165  call opencl_schwarz_toext3d(a_d,b_d,nx,nelv, stream)
166 #else
167  call neko_error('No device backend configured')
168 #endif
169  end subroutine device_schwarz_toext3d
170 
171  subroutine device_schwarz_toreg3d(b_d,a_d,nx, nelv, stream)
172  integer, intent(in) :: nx, nelv
173  type(c_ptr) :: a_d, b_d
174  type(c_ptr), optional :: stream
175  if (.not. present(stream)) then
176  stream = glb_cmd_queue
177  end if
178 #ifdef HAVE_HIP
179  call hip_schwarz_toreg3d(b_d,a_d,nx,nelv, stream)
180 #elif HAVE_CUDA
181  call cuda_schwarz_toreg3d(b_d,a_d,nx,nelv, stream)
182 #elif HAVE_OPENCL
183  call opencl_schwarz_toreg3d(b_d,a_d,nx,nelv, stream)
184 #else
185  call neko_error('No device backend configured')
186 #endif
187 
188  end subroutine device_schwarz_toreg3d
189 end module device_schwarz
subroutine, public device_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
subroutine, public device_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, nx, ny, nz, nelv, stream)
subroutine, public device_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
Device abstraction, common interface for various accelerators.
Definition: device.F90:34
integer, parameter, public c_rp
Definition: num_types.f90:13
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Utilities.
Definition: utils.f90:35
void opencl_schwarz_toreg3d(void *b, void *a, int *nx, int *nel)
Definition: schwarz.c:124
void opencl_schwarz_toext3d(void *a, void *b, int *nx, int *nel)
Definition: schwarz.c:102
void opencl_schwarz_extrude(void *arr1, int *l1, real *f1, void *arr2, int *l2, real *f2, int *nx, int *nel)
Definition: schwarz.c:49
void cuda_schwarz_extrude(void *arr1, int *l1, real *f1, void *arr2, int *l2, real *f2, int *nx, int *nel, cudaStream_t stream)
Definition: schwarz.cu:45
void cuda_schwarz_toreg3d(void *b, void *a, int *nx, int *nel, cudaStream_t stream)
Definition: schwarz.cu:92
void cuda_schwarz_toext3d(void *a, void *b, int *nx, int *nel, cudaStream_t stream)
Definition: schwarz.cu:82