Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
opencl_math.f90
Go to the documentation of this file.
1! Copyright (c) 2024-2025, 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 : rp, c_rp
35 implicit none
36 public
37
38 interface
39 subroutine opencl_copy(a_d, b_d, n, strm) &
40 bind(c, name = 'opencl_copy')
41 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
42 type(c_ptr), value :: a_d, b_d, strm
43 integer(c_int) :: n
44 end subroutine opencl_copy
45
46 subroutine opencl_masked_copy(a_d, b_d, mask_d, n, n_mask, strm) &
47 bind(c, name = 'opencl_masked_copy')
48 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
49 type(c_ptr), value :: a_d, b_d, mask_d, strm
50 integer(c_int) :: n, n_mask
51 end subroutine opencl_masked_copy
52
53 subroutine opencl_masked_gather_copy(a_d, b_d, mask_d, n, n_mask, strm) &
54 bind(c, name = 'opencl_masked_gather_copy')
55 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
56 type(c_ptr), value :: a_d, b_d, mask_d, strm
57 integer(c_int) :: n, n_mask
58 end subroutine opencl_masked_gather_copy
59
60 subroutine opencl_masked_gather_copy_aligned(a_d, b_d, mask_d, n, n_mask, &
61 strm) bind(c, name = 'opencl_masked_gather_copy_aligned')
62 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
63 type(c_ptr), value :: a_d, b_d, mask_d, strm
64 integer(c_int) :: n, n_mask
66
67 subroutine opencl_masked_scatter_copy(a_d, b_d, mask_d, n, n_mask, strm) &
68 bind(c, name = 'opencl_masked_scatter_copy')
69 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
70 type(c_ptr), value :: a_d, b_d, mask_d, strm
71 integer(c_int) :: n, n_mask
72 end subroutine opencl_masked_scatter_copy
73
74 subroutine opencl_cfill_mask(a_d, c, n, mask_d, n_mask, strm) &
75 bind(c, name = 'opencl_cfill_mask')
76 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
77 import c_rp
78 type(c_ptr), value :: a_d
79 real(c_rp) :: c
80 integer(c_int) :: n
81 type(c_ptr), value :: mask_d
82 integer(c_int) :: n_mask
83 type(c_ptr), value :: strm
84 end subroutine opencl_cfill_mask
85
86 subroutine opencl_cmult(a_d, c, n, strm) &
87 bind(c, name = 'opencl_cmult')
88 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
89 import c_rp
90 type(c_ptr), value :: a_d, strm
91 real(c_rp) :: c
92 integer(c_int) :: n
93 end subroutine opencl_cmult
94
95 subroutine opencl_cmult2(a_d, b_d, c, n, strm) &
96 bind(c, name = 'opencl_cmult2')
97 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
98 import c_rp
99 type(c_ptr), value :: a_d, b_d, strm
100 real(c_rp) :: c
101 integer(c_int) :: n
102 end subroutine opencl_cmult2
103
104 subroutine opencl_cdiv(a_d, c, n, strm) &
105 bind(c, name = 'opencl_cdiv')
106 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
107 import c_rp
108 type(c_ptr), value :: a_d, strm
109 real(c_rp) :: c
110 integer(c_int) :: n
111 end subroutine opencl_cdiv
112
113 subroutine opencl_cdiv2(a_d, b_d, c, n, strm) &
114 bind(c, name = 'opencl_cdiv2')
115 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
116 import c_rp
117 type(c_ptr), value :: a_d, b_d, strm
118 real(c_rp) :: c
119 integer(c_int) :: n
120 end subroutine opencl_cdiv2
121
122 subroutine opencl_radd(a_d, c, n, strm) &
123 bind(c, name = 'opencl_radd')
124 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
125 import c_rp
126 type(c_ptr), value :: a_d, strm
127 real(c_rp) :: c
128 integer(c_int) :: n
129 end subroutine opencl_radd
130
131 subroutine opencl_iadd(a_d, c, n, strm) &
132 bind(c, name = 'opencl_iadd')
133 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
134 import c_rp
135 type(c_ptr), value :: a_d, strm
136 integer(c_int) :: c
137 integer(c_int) :: n
138 end subroutine opencl_iadd
139
140 subroutine opencl_cadd2(a_d, b_d, c, n, strm) &
141 bind(c, name = 'opencl_cadd2')
142 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
143 import c_rp
144 type(c_ptr), value :: a_d
145 type(c_ptr), value :: b_d
146 type(c_ptr), value :: strm
147 real(c_rp) :: c
148 integer(c_int) :: n
149 end subroutine opencl_cadd2
150
151 subroutine opencl_cfill(a_d, c, n, strm) &
152 bind(c, name = 'opencl_cfill')
153 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
154 import c_rp
155 type(c_ptr), value :: a_d
156 type(c_ptr), value :: strm
157 real(c_rp) :: c
158 integer(c_int) :: n
159 end subroutine opencl_cfill
160
161 subroutine opencl_rzero(a_d, n, strm) &
162 bind(c, name = 'opencl_rzero')
163 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
164 type(c_ptr), value :: a_d, strm
165 integer(c_int) :: n
166 end subroutine opencl_rzero
167
168 subroutine opencl_rone(a_d, n, strm) &
169 bind(c, name = 'opencl_rone')
170 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
171 type(c_ptr), value :: a_d, strm
172 integer(c_int) :: n
173 end subroutine opencl_rone
174
175 subroutine opencl_add2(a_d, b_d, n, strm) &
176 bind(c, name = 'opencl_add2')
177 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
178 implicit none
179 type(c_ptr), value :: a_d, b_d, strm
180 integer(c_int) :: n
181 end subroutine opencl_add2
182
183 subroutine opencl_add4(a_d, b_d, c_d, d_d, n, strm) &
184 bind(c, name = 'opencl_add4')
185 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
186 implicit none
187 type(c_ptr), value :: a_d, b_d, c_d, d_d, strm
188 integer(c_int) :: n
189 end subroutine opencl_add4
190
191 subroutine opencl_add2s1(a_d, b_d, c1, n, strm) &
192 bind(c, name = 'opencl_add2s1')
193 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
194 import c_rp
195 implicit none
196 type(c_ptr), value :: a_d, b_d, strm
197 real(c_rp) :: c1
198 integer(c_int) :: n
199 end subroutine opencl_add2s1
200
201 subroutine opencl_add2s2(a_d, b_d, c1, n, strm) &
202 bind(c, name = 'opencl_add2s2')
203 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
204 import c_rp
205 implicit none
206 type(c_ptr), value :: a_d, b_d, strm
207 real(c_rp) :: c1
208 integer(c_int) :: n
209 end subroutine opencl_add2s2
210
211 subroutine opencl_add2s2_many(y_d, x_d_d, a_d, j, n, strm) &
212 bind(c, name = 'opencl_add2s2_many')
213 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
214 import c_rp
215 implicit none
216 type(c_ptr), value :: y_d, x_d_d, a_d, strm
217 integer(c_int) :: j, n
218 end subroutine opencl_add2s2_many
219
220 subroutine opencl_addsqr2s2(a_d, b_d, c1, n, strm) &
221 bind(c, name = 'opencl_addsqr2s2')
222 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
223 import c_rp
224 implicit none
225 type(c_ptr), value :: a_d, b_d, strm
226 real(c_rp) :: c1
227 integer(c_int) :: n
228 end subroutine opencl_addsqr2s2
229
230 subroutine opencl_add3s2(a_d, b_d, c_d, c1, c2, n, strm) &
231 bind(c, name = 'opencl_add3s2')
232 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
233 import c_rp
234 implicit none
235 type(c_ptr), value :: a_d, b_d, c_d, strm
236 real(c_rp) :: c1, c2
237 integer(c_int) :: n
238 end subroutine opencl_add3s2
239
240 subroutine opencl_add4s3(a_d, b_d, c_d, d_d, c1, c2, c3, n, strm) &
241 bind(c, name = 'opencl_add4s3')
242 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
243 import c_rp
244 implicit none
245 type(c_ptr), value :: a_d, b_d, c_d, d_d, strm
246 real(c_rp) :: c1, c2, c3
247 integer(c_int) :: n
248 end subroutine opencl_add4s3
249
250 subroutine opencl_add5s4(a_d, b_d, c_d, d_d, e_d, &
251 c1, c2, c3, c4, n, strm) &
252 bind(c, name = 'opencl_add5s4')
253 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
254 import c_rp
255 implicit none
256 type(c_ptr), value :: a_d, b_d, c_d, d_d, e_d, strm
257 real(c_rp) :: c1, c2, c3, c4
258 integer(c_int) :: n
259 end subroutine opencl_add5s4
260
261 subroutine opencl_invcol1(a_d, n, strm) &
262 bind(c, name = 'opencl_invcol1')
263 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
264 implicit none
265 type(c_ptr), value :: a_d, strm
266 integer(c_int) :: n
267 end subroutine opencl_invcol1
268
269 subroutine opencl_invcol2(a_d, b_d, n, strm) &
270 bind(c, name = 'opencl_invcol2')
271 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
272 implicit none
273 type(c_ptr), value :: a_d, b_d, strm
274 integer(c_int) :: n
275 end subroutine opencl_invcol2
276
277 subroutine opencl_col2(a_d, b_d, n, strm) &
278 bind(c, name = 'opencl_col2')
279 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
280 implicit none
281 type(c_ptr), value :: a_d, b_d, strm
282 integer(c_int) :: n
283 end subroutine opencl_col2
284
285 subroutine opencl_col3(a_d, b_d, c_d, n, strm) &
286 bind(c, name = 'opencl_col3')
287 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
288 implicit none
289 type(c_ptr), value :: a_d, b_d, c_d, strm
290 integer(c_int) :: n
291 end subroutine opencl_col3
292
293 subroutine opencl_subcol3(a_d, b_d, c_d, n, strm) &
294 bind(c, name = 'opencl_subcol3')
295 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
296 implicit none
297 type(c_ptr), value :: a_d, b_d, c_d, strm
298 integer(c_int) :: n
299 end subroutine opencl_subcol3
300
301 subroutine opencl_sub2(a_d, b_d, n, strm) &
302 bind(c, name = 'opencl_sub2')
303 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
304 implicit none
305 type(c_ptr), value :: a_d, b_d, strm
306 integer(c_int) :: n
307 end subroutine opencl_sub2
308
309 subroutine opencl_sub3(a_d, b_d, c_d, n, strm) &
310 bind(c, name = 'opencl_sub3')
311 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
312 implicit none
313 type(c_ptr), value :: a_d, b_d, c_d, strm
314 integer(c_int) :: n
315 end subroutine opencl_sub3
316
317 subroutine opencl_add3(a_d, b_d, c_d, n, strm) &
318 bind(c, name = 'opencl_add3')
319 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
320 implicit none
321 type(c_ptr), value :: a_d, b_d, c_d, strm
322 integer(c_int) :: n
323 end subroutine opencl_add3
324
325 subroutine opencl_addcol3(a_d, b_d, c_d, n, strm) &
326 bind(c, name = 'opencl_addcol3')
327 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
328 implicit none
329 type(c_ptr), value :: a_d, b_d, c_d, strm
330 integer(c_int) :: n
331 end subroutine opencl_addcol3
332
333 subroutine opencl_addcol4(a_d, b_d, c_d, d_d, n, strm) &
334 bind(c, name = 'opencl_addcol4')
335 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
336 implicit none
337 type(c_ptr), value :: a_d, b_d, c_d, d_d, strm
338 integer(c_int) :: n
339 end subroutine opencl_addcol4
340
341 subroutine opencl_addcol3s2(a_d, b_d, c_d, s, n, strm) &
342 bind(c, name = 'opencl_addcol3s2')
343 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
344 import c_rp
345 type(c_ptr), value :: a_d, b_d, c_d, strm
346 real(c_rp) :: s
347 integer(c_int) :: n
348 end subroutine opencl_addcol3s2
349
350 subroutine opencl_vdot3(dot_d, u1_d, u2_d, u3_d, v1_d, v2_d, v3_d, &
351 n, strm) &
352 bind(c, name = 'opencl_vdot3')
353 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
354 implicit none
355 type(c_ptr), value :: dot_d, u1_d, u2_d, u3_d, v1_d, v2_d, v3_d
356 type(c_ptr), value :: strm
357 integer(c_int) :: n
358 end subroutine opencl_vdot3
359
360 subroutine opencl_vcross(u1_d, u2_d, u3_d, v1_d, v2_d, v3_d, &
361 w1_d, w2_d, w3_d, n, strm) &
362 bind(c, name = 'opencl_vcross')
363 use, intrinsic :: iso_c_binding, only : c_int, c_ptr
364 type(c_ptr), value :: u1_d, u2_d, u3_d
365 type(c_ptr), value :: v1_d, v2_d, v3_d
366 type(c_ptr), value :: w1_d, w2_d, w3_d
367 type(c_ptr), value :: strm
368 integer(c_int) :: n
369 end subroutine opencl_vcross
370
371 real(c_rp) function opencl_glsc3(a_d, b_d, c_d, n, strm) &
372 bind(c, name = 'opencl_glsc3')
373 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
374 import c_rp
375 implicit none
376 type(c_ptr), value :: a_d, b_d, c_d, strm
377 integer(c_int) :: n
378 end function opencl_glsc3
379
380 subroutine opencl_glsc3_many(h, w_d, v_d_d, mult_d, j, n, strm) &
381 bind(c, name = 'opencl_glsc3_many')
382 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
383 import c_rp
384 implicit none
385 integer(c_int) :: j, n
386 type(c_ptr), value :: w_d, v_d_d, mult_d, strm
387 real(c_rp) :: h(j)
388 end subroutine opencl_glsc3_many
389
390 real(c_rp) function opencl_glsc2(a_d, b_d, n, strm) &
391 bind(c, name = 'opencl_glsc2')
392 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
393 import c_rp
394 implicit none
395 type(c_ptr), value :: a_d, b_d, strm
396 integer(c_int) :: n
397 end function opencl_glsc2
398
399 real(c_rp) function opencl_glsubnorm2(a_d, b_d, n, strm) &
400 bind(c, name = 'opencl_glsubnorm2')
401 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
402 import c_rp
403 implicit none
404 type(c_ptr), value :: a_d, b_d, strm
405 integer(c_int) :: n
406 end function opencl_glsubnorm2
407
408 real(c_rp) function opencl_glsum(a_d, n, strm) &
409 bind(c, name = 'opencl_glsum')
410 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
411 import c_rp
412 implicit none
413 type(c_ptr), value :: a_d, strm
414 integer(c_int) :: n
415 end function opencl_glsum
416
417 subroutine opencl_absval(a_d, n, strm) &
418 bind(c, name = 'opencl_absval')
419 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
420 implicit none
421 type(c_ptr), value :: a_d, strm
422 integer(c_int) :: n
423 end subroutine opencl_absval
424 end interface
425
426 ! ========================================================================== !
427 ! Interfaces for the pointwise operations.
428
429 interface
430 subroutine opencl_pwmax_vec2(a_d, b_d, n, strm) &
431 bind(c, name = 'opencl_pwmax_vec2')
432 use, intrinsic :: iso_c_binding, only : c_int, c_ptr
433 type(c_ptr), value :: a_d, b_d, strm
434 integer(c_int) :: n
435 end subroutine opencl_pwmax_vec2
436
437 subroutine opencl_pwmax_vec3(a_d, b_d, c_d, n, strm) &
438 bind(c, name = 'opencl_pwmax_vec3')
439 use, intrinsic :: iso_c_binding, only : c_int, c_ptr
440 type(c_ptr), value :: a_d, b_d, c_d, strm
441 integer(c_int) :: n
442 end subroutine opencl_pwmax_vec3
443
444 subroutine opencl_pwmax_sca2(a_d, c_d, n, strm) &
445 bind(c, name = 'opencl_pwmax_sca2')
446 use, intrinsic :: iso_c_binding, only : c_int, c_ptr
447 import c_rp
448 type(c_ptr), value :: a_d, strm
449 real(c_rp) :: c_d
450 integer(c_int) :: n
451 end subroutine opencl_pwmax_sca2
452
453 subroutine opencl_pwmax_sca3(a_d, b_d, c_d, n, strm) &
454 bind(c, name = 'opencl_pwmax_sca3')
455 use, intrinsic :: iso_c_binding, only : c_int, c_ptr
456 import c_rp
457 type(c_ptr), value :: a_d, b_d, strm
458 real(c_rp) :: c_d
459 integer(c_int) :: n
460 end subroutine opencl_pwmax_sca3
461
462 subroutine opencl_pwmin_vec2(a_d, b_d, n, strm) &
463 bind(c, name = 'opencl_pwmin_vec2')
464 use, intrinsic :: iso_c_binding, only : c_int, c_ptr
465 type(c_ptr), value :: a_d, b_d, strm
466 integer(c_int) :: n
467 end subroutine opencl_pwmin_vec2
468
469 subroutine opencl_pwmin_vec3(a_d, b_d, c_d, n, strm) &
470 bind(c, name = 'opencl_pwmin_vec3')
471 use, intrinsic :: iso_c_binding, only : c_int, c_ptr
472 type(c_ptr), value :: a_d, b_d, c_d, strm
473 integer(c_int) :: n
474 end subroutine opencl_pwmin_vec3
475
476 subroutine opencl_pwmin_sca2(a_d, c_d, n, strm) &
477 bind(c, name = 'opencl_pwmin_sca2')
478 use, intrinsic :: iso_c_binding, only : c_int, c_ptr
479 import c_rp
480 type(c_ptr), value :: a_d, strm
481 real(c_rp) :: c_d
482 integer(c_int) :: n
483 end subroutine opencl_pwmin_sca2
484
485 subroutine opencl_pwmin_sca3(a_d, b_d, c_d, n, strm) &
486 bind(c, name = 'opencl_pwmin_sca3')
487 use, intrinsic :: iso_c_binding, only : c_int, c_ptr
488 import c_rp
489 type(c_ptr), value :: a_d, b_d, strm
490 real(c_rp) :: c_d
491 integer(c_int) :: n
492 end subroutine opencl_pwmin_sca3
493
494 end interface
495
496end module opencl_math
integer, parameter, public c_rp
Definition num_types.f90:13
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12