Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
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, &
44 nx, nelv, stream) &
45 bind(c, name = 'hip_schwarz_extrude')
46 use, intrinsic :: iso_c_binding
47 import c_rp
48 implicit none
49 type(c_ptr), value :: arr1_d, arr2_d, stream
50 integer(c_int) :: l1, l2, nx, nelv
51 real(c_rp) :: f1, f2
52
53 end subroutine hip_schwarz_extrude
54 subroutine hip_schwarz_toext3d(a_d, b_d, nx, nelv, stream) &
55 bind(c, name = 'hip_schwarz_toext3d')
56 use, intrinsic :: iso_c_binding
57 import c_rp
58 implicit none
59 type(c_ptr), value :: a_d, b_d, stream
60 integer(c_int) :: nx, nelv
61 end subroutine hip_schwarz_toext3d
62 subroutine hip_schwarz_toreg3d(b_d, a_d, nx, nelv, stream) &
63 bind(c, name = 'hip_schwarz_toreg3d')
64 use, intrinsic :: iso_c_binding
65 import c_rp
66 implicit none
67 type(c_ptr), value :: a_d, b_d, stream
68 integer(c_int) :: nx, nelv
69 end subroutine hip_schwarz_toreg3d
70 end interface
71#elif HAVE_CUDA
72 interface
73 subroutine cuda_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, &
74 nx, nelv, stream) &
75 bind(c, name = 'cuda_schwarz_extrude')
76 use, intrinsic :: iso_c_binding
77 import c_rp
78 implicit none
79 type(c_ptr), value :: arr1_d, arr2_d, stream
80
81 integer(c_int) :: l1, l2, nx, nelv
82 real(c_rp) :: f1, f2
83 end subroutine cuda_schwarz_extrude
84 subroutine cuda_schwarz_toext3d(a_d, b_d, nx, nelv, stream) &
85 bind(c, name = 'cuda_schwarz_toext3d')
86 use, intrinsic :: iso_c_binding
87 import c_rp
88 implicit none
89 type(c_ptr), value :: a_d, b_d, stream
90 integer(c_int) :: nx, nelv
91 end subroutine cuda_schwarz_toext3d
92 subroutine cuda_schwarz_toreg3d(b_d, a_d, nx, nelv, stream) &
93 bind(c, name = 'cuda_schwarz_toreg3d')
94 use, intrinsic :: iso_c_binding
95 import c_rp
96 implicit none
97 type(c_ptr), value :: a_d, b_d, stream
98 integer(c_int) :: nx, nelv
99 end subroutine cuda_schwarz_toreg3d
100 end interface
101#elif HAVE_OPENCL
102 interface
103 subroutine opencl_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, &
104 nx, nelv, stream) &
105 bind(c, name = 'opencl_schwarz_extrude')
106 use, intrinsic :: iso_c_binding
107 import c_rp
108 implicit none
109 type(c_ptr), value :: arr1_d, arr2_d, stream
110 integer(c_int) :: l1, l2, nx, nelv
111 real(c_rp) :: f1, f2
112 end subroutine opencl_schwarz_extrude
113 subroutine opencl_schwarz_toext3d(a_d, b_d, nx, nelv, stream) &
114 bind(c, name = 'opencl_schwarz_toext3d')
115 use, intrinsic :: iso_c_binding
116 import c_rp
117 implicit none
118 type(c_ptr), value :: a_d, b_d, stream
119 integer(c_int) :: nx, nelv
120 end subroutine opencl_schwarz_toext3d
121 subroutine opencl_schwarz_toreg3d(b_d, a_d, nx, nelv, stream) &
122 bind(c, name = 'opencl_schwarz_toreg3d')
123 use, intrinsic :: iso_c_binding
124 import c_rp
125 implicit none
126 type(c_ptr), value :: a_d, b_d, stream
127 integer(c_int) :: nx, nelv
128 end subroutine opencl_schwarz_toreg3d
129 end interface
130#elif HAVE_METAL
131 interface
132 subroutine metal_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, &
133 nx, nelv, stream) &
134 bind(c, name = 'metal_schwarz_extrude')
135 use, intrinsic :: iso_c_binding
136 import c_rp
137 implicit none
138 type(c_ptr), value :: arr1_d, arr2_d, stream
139 integer(c_int) :: l1, l2, nx, nelv
140 real(c_rp) :: f1, f2
141 end subroutine metal_schwarz_extrude
142 subroutine metal_schwarz_toext3d(a_d, b_d, nx, nelv, stream) &
143 bind(c, name = 'metal_schwarz_toext3d')
144 use, intrinsic :: iso_c_binding
145 import c_rp
146 implicit none
147 type(c_ptr), value :: a_d, b_d, stream
148 integer(c_int) :: nx, nelv
149 end subroutine metal_schwarz_toext3d
150 subroutine metal_schwarz_toreg3d(b_d, a_d, nx, nelv, stream) &
151 bind(c, name = 'metal_schwarz_toreg3d')
152 use, intrinsic :: iso_c_binding
153 import c_rp
154 implicit none
155 type(c_ptr), value :: a_d, b_d, stream
156 integer(c_int) :: nx, nelv
157 end subroutine metal_schwarz_toreg3d
158 end interface
159#endif
160
163
164contains
165 subroutine device_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, &
166 nx, ny, nz, nelv, stream)
167 integer, intent(in) :: l1, l2, nx, ny, nz, nelv
168 type(c_ptr), intent(inout) :: arr1_d, arr2_d
169 real(kind=rp), intent(in) :: f1, f2
170 type(c_ptr), optional :: stream
171 if (.not. present(stream)) then
172 stream = glb_cmd_queue
173 end if
174#ifdef HAVE_HIP
175 call hip_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, nx, nelv, stream)
176#elif HAVE_CUDA
177 call cuda_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, nx, nelv, stream)
178#elif HAVE_OPENCL
179 call opencl_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, nx, &
180 nelv, stream)
181#elif HAVE_METAL
182 call metal_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, nx, &
183 nelv, stream)
184#else
185 call neko_error('No device backend configured')
186#endif
187 end subroutine device_schwarz_extrude
188
189 subroutine device_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
190 integer, intent(in) :: nx, nelv
191 type(c_ptr) :: a_d, b_d
192 type(c_ptr), optional :: stream
193 if (.not. present(stream)) then
194 stream = glb_cmd_queue
195 end if
196
197#ifdef HAVE_HIP
198 call hip_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
199#elif HAVE_CUDA
200 call cuda_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
201#elif HAVE_OPENCL
202 call opencl_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
203#elif HAVE_METAL
204 call metal_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
205#else
206 call neko_error('No device backend configured')
207#endif
208 end subroutine device_schwarz_toext3d
209
210 subroutine device_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
211 integer, intent(in) :: nx, nelv
212 type(c_ptr) :: a_d, b_d
213 type(c_ptr), optional :: stream
214 if (.not. present(stream)) then
215 stream = glb_cmd_queue
216 end if
217#ifdef HAVE_HIP
218 call hip_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
219#elif HAVE_CUDA
220 call cuda_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
221#elif HAVE_OPENCL
222 call opencl_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
223#elif HAVE_METAL
224 call metal_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
225#else
226 call neko_error('No device backend configured')
227#endif
228
229 end subroutine device_schwarz_toreg3d
230end 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
type(c_ptr), bind(C), public glb_cmd_queue
Global command queue.
Definition device.F90:52
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_toext3d(void *a, void *b, int *nx, int *nel, cl_command_queue command_queue)
Definition schwarz.c:105
void opencl_schwarz_extrude(void *arr1, int *l1, real *f1, void *arr2, int *l2, real *f2, int *nx, int *nel, cl_command_queue command_queue)
Definition schwarz.c:49
void opencl_schwarz_toreg3d(void *b, void *a, int *nx, int *nel, cl_command_queue command_queue)
Definition schwarz.c:129
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