Neko  0.9.99
A portable framework for high-order spectral element flow simulations
device_projection.F90
Go to the documentation of this file.
1 ! Copyright (c) 2020-2024, 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 !
36  use num_types, only : rp, c_rp
37  use utils, only : neko_error
38  use, intrinsic :: iso_c_binding
39  implicit none
40  private
41 
43 
44 #ifdef HAVE_HIP
45  interface
46  subroutine hip_project_on(a_d, b_d, x_d_d, b_d_d, mult_d, x_d, j, n) &
47  bind(c, name = 'hip_project_on')
48  use, intrinsic :: iso_c_binding
49  import c_rp
50  implicit none
51  type(c_ptr), value :: a_d, b_d, x_d_d, b_d_d, mult_d, x_d
52  integer(c_int) :: j, n
53  end subroutine hip_project_on
54  end interface
55 
56  interface
57  subroutine hip_project_ortho(a_d, b_d, x_d_d, b_d_d, &
58  w_d, xm_d, j, n, nrm) &
59  bind(c, name = 'hip_project_ortho')
60  use, intrinsic :: iso_c_binding
61  import c_rp
62  implicit none
63  type(c_ptr), value :: a_d, b_d, x_d_d, b_d_d, w_d
64  type(c_ptr), value :: xm_d
65  integer(c_int) :: j, n
66  real(c_rp) :: nrm
67  end subroutine hip_project_ortho
68  end interface
69 #elif HAVE_CUDA
70  interface
71  subroutine cuda_project_on(a_d, b_d, x_d_d, b_d_d, mult_d, x_d, j, n) &
72  bind(c, name = 'cuda_project_on')
73  use, intrinsic :: iso_c_binding
74  import c_rp
75  implicit none
76  type(c_ptr), value :: a_d, b_d, x_d_d, b_d_d, mult_d, x_d
77  integer(c_int) :: j, n
78  end subroutine cuda_project_on
79  end interface
80 
81  interface
82  subroutine cuda_project_ortho(a_d, b_d, x_d_d, b_d_d, &
83  w_d, xm_d, j, n, nrm) &
84  bind(c, name = 'cuda_project_ortho')
85  use, intrinsic :: iso_c_binding
86  import c_rp
87  implicit none
88  type(c_ptr), value :: a_d, b_d, x_d_d, b_d_d, w_d
89  type(c_ptr), value :: xm_d
90  integer(c_int) :: j, n
91  real(c_rp) :: nrm
92  end subroutine cuda_project_ortho
93  end interface
94 #endif
95 
96 contains
97 
98  subroutine device_proj_on(alpha_d, b_d, x_d_d, b_d_d, mult_d, xbar_d, j, n)
99  type(c_ptr), value :: alpha_d, b_d, x_d_d, b_d_d, mult_d, xbar_d
100  integer(c_int) :: j, n
101  integer :: ierr
102 #ifdef HAVE_HIP
103  call hip_project_on(alpha_d, b_d, x_d_d, b_d_d, mult_d, xbar_d, j, n)
104 #elif HAVE_CUDA
105  call cuda_project_on(alpha_d, b_d, x_d_d, b_d_d, mult_d, xbar_d, j, n)
106 #else
107  call neko_error('No device backend configured')
108 #endif
109  end subroutine device_proj_on
110 
111  subroutine device_project_ortho(alpha_d, b_d, x_d_d, b_d_d, &
112  w_d, xm_d, j, n, nrm)
113  type(c_ptr), value :: alpha_d, b_d, x_d_d, b_d_d
114  type(c_ptr), value :: w_d, xm_d
115  integer(c_int) :: j, n
116  real(c_rp) :: nrm
117  integer :: ierr
118 #ifdef HAVE_HIP
119  call hip_project_ortho(alpha_d, b_d, x_d_d, b_d_d, w_d, xm_d, j, n, nrm)
120 #elif HAVE_CUDA
121  call cuda_project_ortho(alpha_d, b_d, x_d_d, b_d_d, w_d, xm_d, j, n, nrm)
122 #else
123  call neko_error('No device backend configured')
124 #endif
125  end subroutine device_project_ortho
126 
127 end module device_projection
Interface for device projection.
subroutine, public device_proj_on(alpha_d, b_d, x_d_d, b_d_d, mult_d, xbar_d, j, n)
subroutine, public device_project_ortho(alpha_d, b_d, x_d_d, b_d_d, w_d, xm_d, j, n, nrm)
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 cuda_project_ortho(void *alpha, void *b, void *xx, void *bb, void *w, void *xm, int *j, int *n, real *nrm)
Definition: projection.cu:127
void cuda_project_on(void *alpha, void *b, void *xx, void *bb, void *mult, void *xbar, int *j, int *n)
Definition: projection.cu:53