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