Neko 1.99.2
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#endif
131
134
135contains
136 subroutine device_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, &
137 nx, ny, nz, nelv, stream)
138 integer, intent(in) :: l1, l2, nx, ny, nz, nelv
139 type(c_ptr), intent(inout) :: arr1_d, arr2_d
140 real(kind=rp), intent(in) :: f1, f2
141 type(c_ptr), optional :: stream
142 if (.not. present(stream)) then
143 stream = glb_cmd_queue
144 end if
145#ifdef HAVE_HIP
146 call hip_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, nx, nelv, stream)
147#elif HAVE_CUDA
148 call cuda_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, nx, nelv, stream)
149#elif HAVE_OPENCL
150 call opencl_schwarz_extrude(arr1_d, l1, f1, arr2_d, l2, f2, nx, &
151 nelv, stream)
152#else
153 call neko_error('No device backend configured')
154#endif
155 end subroutine device_schwarz_extrude
156
157 subroutine device_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
158 integer, intent(in) :: nx, nelv
159 type(c_ptr) :: a_d, b_d
160 type(c_ptr), optional :: stream
161 if (.not. present(stream)) then
162 stream = glb_cmd_queue
163 end if
164
165#ifdef HAVE_HIP
166 call hip_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
167#elif HAVE_CUDA
168 call cuda_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
169#elif HAVE_OPENCL
170 call opencl_schwarz_toext3d(a_d, b_d, nx, nelv, stream)
171#else
172 call neko_error('No device backend configured')
173#endif
174 end subroutine device_schwarz_toext3d
175
176 subroutine device_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
177 integer, intent(in) :: nx, nelv
178 type(c_ptr) :: a_d, b_d
179 type(c_ptr), optional :: stream
180 if (.not. present(stream)) then
181 stream = glb_cmd_queue
182 end if
183#ifdef HAVE_HIP
184 call hip_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
185#elif HAVE_CUDA
186 call cuda_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
187#elif HAVE_OPENCL
188 call opencl_schwarz_toreg3d(b_d, a_d, nx, nelv, stream)
189#else
190 call neko_error('No device backend configured')
191#endif
192
193 end subroutine device_schwarz_toreg3d
194end 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:51
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