Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
device_math_ext.f90
1! Copyright (c) 2021-2023, 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!
33module device_math_ext
34 use utils, only: neko_error
35 use num_types, only: rp, c_rp
36 use, intrinsic :: iso_c_binding, only: c_ptr, c_int
37 implicit none
38
39#if HAVE_HIP
40
41 interface
42 subroutine hip_copy_mask(a_d, b_d, size, mask_d, mask_size) &
43 bind(c, name = 'hip_copy_mask')
44 import c_rp, c_int, c_ptr
45 type(c_ptr), value :: a_d
46 type(c_ptr), value :: b_d
47 integer(c_int) :: size
48 type(c_ptr), value :: mask_d
49 integer(c_int) :: mask_size
50 end subroutine hip_copy_mask
51 end interface
52 interface
53 subroutine hip_cadd_mask(a_d, c, size, mask_d, mask_size) &
54 bind(c, name = 'hip_cadd_mask')
55 import c_rp, c_int, c_ptr
56 type(c_ptr), value :: a_d
57 real(c_rp) :: c
58 integer(c_int) :: size
59 type(c_ptr), value :: mask_d
60 integer(c_int) :: mask_size
61 end subroutine hip_cadd_mask
62 end interface
63 interface
64 subroutine hip_invcol1_mask(a_d, size, mask_d, mask_size) &
65 bind(c, name = 'hip_invcol1_mask')
66 import c_rp, c_int, c_ptr
67 type(c_ptr), value :: a_d
68 integer(c_int) :: size
69 type(c_ptr), value :: mask_d
70 integer(c_int) :: mask_size
71 end subroutine hip_invcol1_mask
72 end interface
73 interface
74 subroutine hip_col2_mask(a_d, b_d, size, mask_d, mask_size) &
75 bind(c, name = 'hip_col2_mask')
76 import c_rp, c_int, c_ptr
77 type(c_ptr), value :: a_d
78 type(c_ptr), value :: b_d
79 integer(c_int) :: size
80 type(c_ptr), value :: mask_d
81 integer(c_int) :: mask_size
82 end subroutine hip_col2_mask
83 end interface
84 interface
85 subroutine hip_col3_mask(a_d, b_d, c_d, size, mask_d, mask_size) &
86 bind(c, name = 'hip_col3_mask')
87 import c_rp, c_int, c_ptr
88 type(c_ptr), value :: a_d
89 type(c_ptr), value :: b_d
90 type(c_ptr), value :: c_d
91 integer(c_int) :: size
92 type(c_ptr), value :: mask_d
93 integer(c_int) :: mask_size
94 end subroutine hip_col3_mask
95 end interface
96 interface
97 subroutine hip_sub3_mask(a_d, b_d, c_d, size, mask_d, mask_size) &
98 bind(c, name = 'hip_sub3_mask')
99 import c_rp, c_int, c_ptr
100 type(c_ptr), value :: a_d
101 type(c_ptr), value :: b_d
102 type(c_ptr), value :: c_d
103 integer(c_int) :: size
104 type(c_ptr), value :: mask_d
105 integer(c_int) :: mask_size
106 end subroutine hip_sub3_mask
107 end interface
108
109#elif HAVE_CUDA
110
111 interface
112 subroutine cuda_copy_mask(a_d, b_d, size, mask_d, mask_size) &
113 bind(c, name = 'cuda_copy_mask')
114 import c_rp, c_int, c_ptr
115 type(c_ptr), value :: a_d
116 type(c_ptr), value :: b_d
117 integer(c_int) :: size
118 type(c_ptr), value :: mask_d
119 integer(c_int) :: mask_size
120 end subroutine cuda_copy_mask
121 end interface
122 interface
123 subroutine cuda_cadd_mask(a_d, c, size, mask_d, mask_size) &
124 bind(c, name = 'cuda_cadd_mask')
125 import c_rp, c_int, c_ptr
126 type(c_ptr), value :: a_d
127 real(c_rp) :: c
128 integer(c_int) :: size
129 type(c_ptr), value :: mask_d
130 integer(c_int) :: mask_size
131 end subroutine cuda_cadd_mask
132 end interface
133 interface
134 subroutine cuda_invcol1_mask(a_d, size, mask_d, mask_size) &
135 bind(c, name = 'cuda_invcol1_mask')
136 import c_rp, c_int, c_ptr
137 type(c_ptr), value :: a_d
138 integer(c_int) :: size
139 type(c_ptr), value :: mask_d
140 integer(c_int) :: mask_size
141 end subroutine cuda_invcol1_mask
142 end interface
143 interface
144 subroutine cuda_col2_mask(a_d, b_d, size, mask_d, mask_size) &
145 bind(c, name = 'cuda_col2_mask')
146 import c_rp, c_int, c_ptr
147 type(c_ptr), value :: a_d
148 type(c_ptr), value :: b_d
149 integer(c_int) :: size
150 type(c_ptr), value :: mask_d
151 integer(c_int) :: mask_size
152 end subroutine cuda_col2_mask
153 end interface
154 interface
155 subroutine cuda_col3_mask(a_d, b_d, c_d, size, mask_d, mask_size) &
156 bind(c, name = 'cuda_col3_mask')
157 import c_rp, c_int, c_ptr
158 type(c_ptr), value :: a_d
159 type(c_ptr), value :: b_d
160 type(c_ptr), value :: c_d
161 integer(c_int) :: size
162 type(c_ptr), value :: mask_d
163 integer(c_int) :: mask_size
164 end subroutine cuda_col3_mask
165 end interface
166 interface
167 subroutine cuda_sub3_mask(a_d, b_d, c_d, size, mask_d, mask_size) &
168 bind(c, name = 'cuda_sub3_mask')
169 import c_rp, c_int, c_ptr
170 type(c_ptr), value :: a_d
171 type(c_ptr), value :: b_d
172 type(c_ptr), value :: c_d
173 integer(c_int) :: size
174 type(c_ptr), value :: mask_d
175 integer(c_int) :: mask_size
176 end subroutine cuda_sub3_mask
177 end interface
178
179#elif HAVE_OPENCL
180
181#endif
182
183contains
184
185 subroutine device_copy_mask(a_d, b_d, size, mask_d, mask_size)
186 type(c_ptr) :: a_d
187 type(c_ptr) :: b_d
188 integer :: size
189 type(c_ptr) :: mask_d
190 integer :: mask_size
191#if HAVE_HIP
192 call hip_copy_mask(a_d, b_d, size, mask_d, mask_size)
193#elif HAVE_CUDA
194 call cuda_copy_mask(a_d, b_d, size, mask_d, mask_size)
195#else
196 call neko_error('No device backend configured for device_copy_mask')
197#endif
198 end subroutine device_copy_mask
199
200 subroutine device_cadd_mask(a_d, c, size, mask_d, mask_size)
201 type(c_ptr) :: a_d
202 real(kind=rp), intent(in) :: c
203 integer :: size
204 type(c_ptr) :: mask_d
205 integer :: mask_size
206#if HAVE_HIP
207 call hip_cadd_mask(a_d, c, size, mask_d, mask_size)
208#elif HAVE_CUDA
209 call cuda_cadd_mask(a_d, c, size, mask_d, mask_size)
210#else
211 call neko_error('No device backend configured for device_cadd_mask')
212#endif
213 end subroutine device_cadd_mask
214
215 subroutine device_invcol1_mask(a_d, size, mask_d, mask_size)
216 type(c_ptr) :: a_d
217 integer :: size
218 type(c_ptr) :: mask_d
219 integer :: mask_size
220#if HAVE_HIP
221 call hip_invcol1_mask(a_d, size, mask_d, mask_size)
222#elif HAVE_CUDA
223 call cuda_invcol1_mask(a_d, size, mask_d, mask_size)
224#else
225 call neko_error('No device backend configured for device_invcol1_mask')
226#endif
227 end subroutine device_invcol1_mask
228
229 subroutine device_col2_mask(a_d, b_d, size, mask_d, mask_size)
230 type(c_ptr) :: a_d
231 type(c_ptr) :: b_d
232 integer :: size
233 type(c_ptr) :: mask_d
234 integer :: mask_size
235#if HAVE_HIP
236 call hip_col2_mask(a_d, b_d, size, mask_d, mask_size)
237#elif HAVE_CUDA
238 call cuda_col2_mask(a_d, b_d, size, mask_d, mask_size)
239#else
240 call neko_error('No device backend configured for device_col2_mask')
241#endif
242 end subroutine device_col2_mask
243
244 subroutine device_col3_mask(a_d, b_d, c_d, size, mask_d, mask_size)
245 type(c_ptr) :: a_d
246 type(c_ptr) :: b_d
247 type(c_ptr) :: c_d
248 integer :: size
249 type(c_ptr) :: mask_d
250 integer :: mask_size
251#if HAVE_HIP
252 call hip_col3_mask(a_d, b_d, c_d, size, mask_d, mask_size)
253#elif HAVE_CUDA
254 call cuda_col3_mask(a_d, b_d, c_d, size, mask_d, mask_size)
255#else
256 call neko_error('No device backend configured for device_col3_mask')
257#endif
258 end subroutine device_col3_mask
259
260 subroutine device_sub3_mask(a_d, b_d, c_d, size, mask_d, mask_size)
261 type(c_ptr) :: a_d
262 type(c_ptr) :: b_d
263 type(c_ptr) :: c_d
264 integer :: size
265 type(c_ptr) :: mask_d
266 integer :: mask_size
267#if HAVE_HIP
268 call hip_sub3_mask(a_d, b_d, c_d, size, mask_d, mask_size)
269#elif HAVE_CUDA
270 call cuda_sub3_mask(a_d, b_d, c_d, size, mask_d, mask_size)
271#else
272 call neko_error('No device backend configured for device_sub3_mask')
273#endif
274 end subroutine device_sub3_mask
275
276end module device_math_ext