Neko  0.8.1
A portable framework for high-order spectral element flow simulations
ax_helm_device.F90
Go to the documentation of this file.
1 ! Copyright (c) 2021-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 ax_product, only : ax_t
35  use num_types, only : rp
36  use coefs, only : coef_t
37  use space, only : space_t
38  use mesh, only : mesh_t
39  use device_math, only : device_addcol4
40  use device, only : device_get_ptr
41  use num_types, only : rp
42  use, intrinsic :: iso_c_binding, only : c_ptr, c_int
43  implicit none
44  private
45 
46  type, public, extends(ax_t) :: ax_helm_device_t
47  contains
48  procedure, nopass :: compute => ax_helm_device_compute
49  end type ax_helm_device_t
50 
51 #ifdef HAVE_HIP
52  interface
53  subroutine hip_ax_helm(w_d, u_d, &
54  dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
55  h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, nelv, lx) &
56  bind(c, name='hip_ax_helm')
57  use, intrinsic :: iso_c_binding
58  type(c_ptr), value :: w_d, u_d
59  type(c_ptr), value :: dx_d, dy_d, dz_d
60  type(c_ptr), value :: dxt_d, dyt_d, dzt_d
61  type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
62  integer(c_int) :: nel, lx
63  end subroutine hip_ax_helm
64  end interface
65 #elif HAVE_CUDA
66  interface
67  subroutine cuda_ax_helm(w_d, u_d, &
68  dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d,&
69  h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, nelv, lx) &
70  bind(c, name='cuda_ax_helm')
71  use, intrinsic :: iso_c_binding
72  type(c_ptr), value :: w_d, u_d
73  type(c_ptr), value :: dx_d, dy_d, dz_d
74  type(c_ptr), value :: dxt_d, dyt_d, dzt_d
75  type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
76  integer(c_int) :: nel, lx
77  end subroutine cuda_ax_helm
78  end interface
79 #elif HAVE_OPENCL
80  interface
81  subroutine opencl_ax_helm(w_d, u_d, &
82  dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
83  h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, nelv, lx) &
84  bind(c, name='opencl_ax_helm')
85  use, intrinsic :: iso_c_binding
86  type(c_ptr), value :: w_d, u_d
87  type(c_ptr), value :: dx_d, dy_d, dz_d
88  type(c_ptr), value :: dxt_d, dyt_d, dzt_d
89  type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
90  integer(c_int) :: nel, lx
91  end subroutine opencl_ax_helm
92  end interface
93 #endif
94 
95 contains
96 
97  subroutine ax_helm_device_compute(w, u, coef, msh, Xh)
98  type(mesh_t), intent(inout) :: msh
99  type(space_t), intent(inout) :: Xh
100  type(coef_t), intent(inout) :: coef
101  real(kind=rp), intent(inout) :: w(xh%lx, xh%ly, xh%lz, msh%nelv)
102  real(kind=rp), intent(inout) :: u(xh%lx, xh%ly, xh%lz, msh%nelv)
103  type(c_ptr) :: u_d, w_d
104 
105  u_d = device_get_ptr(u)
106  w_d = device_get_ptr(w)
107 
108 #ifdef HAVE_HIP
109  call hip_ax_helm(w_d, u_d, xh%dx_d, xh%dy_d, xh%dz_d, &
110  xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
111  coef%G11_d, coef%G22_d, coef%G33_d, &
112  coef%G12_d, coef%G13_d, coef%G23_d, &
113  msh%nelv, xh%lx)
114 #elif HAVE_CUDA
115  call cuda_ax_helm(w_d, u_d, xh%dx_d, xh%dy_d, xh%dz_d, &
116  xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
117  coef%G11_d, coef%G22_d, coef%G33_d, &
118  coef%G12_d, coef%G13_d, coef%G23_d, &
119  msh%nelv, xh%lx)
120 #elif HAVE_OPENCL
121  call opencl_ax_helm(w_d, u_d, xh%dx_d, xh%dy_d, xh%dz_d, &
122  xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
123  coef%G11_d, coef%G22_d, coef%G33_d, &
124  coef%G12_d, coef%G13_d, coef%G23_d, &
125  msh%nelv, xh%lx)
126 #endif
127 
128  if (coef%ifh2) then
129  call device_addcol4(w_d ,coef%h2_d, coef%B_d, u_d, coef%dof%size())
130  end if
131 
132  end subroutine ax_helm_device_compute
133 
134 end module ax_helm_device
135 
136 
void opencl_ax_helm(void *w, void *u, void *dx, void *dy, void *dz, void *dxt, void *dyt, void *dzt, void *h1, void *g11, void *g22, void *g33, void *g12, void *g13, void *g23, int *nelv, int *lx)
Definition: ax_helm.c:52
void cuda_ax_helm(void *w, void *u, void *dx, void *dy, void *dz, void *dxt, void *dyt, void *dzt, void *h1, void *g11, void *g22, void *g33, void *g12, void *g13, void *g23, int *nelv, int *lx)
Definition: ax_helm.cu:63
Return the device pointer for an associated Fortran array.
Definition: device.F90:81
subroutine ax_helm_device_compute(w, u, coef, msh, Xh)
Defines a Matrix-vector product.
Definition: ax.f90:34
Coefficients.
Definition: coef.f90:34
subroutine, public device_addcol4(a_d, b_d, c_d, d_d, n)
Device abstraction, common interface for various accelerators.
Definition: device.F90:34
Defines a mesh.
Definition: mesh.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Defines a function space.
Definition: space.f90:34
Base type for a matrix-vector product providing .
Definition: ax.f90:43
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition: coef.f90:54
The function space for the SEM solution fields.
Definition: space.f90:62