Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
device_RAMP_mapping.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_ramp_mapping
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 private
39
40 public :: device_convex_up_ramp_mapping_apply, &
41 device_convex_up_ramp_mapping_apply_backward, &
42 device_convex_down_ramp_mapping_apply, &
43 device_convex_down_ramp_mapping_apply_backward
44
45#if HAVE_HIP
46
47 interface
48 subroutine hip_convex_down_ramp_mapping_apply(f_min, f_max, q, &
49 X_out_d, X_in_d, n) &
50 bind(c, name = 'hip_convex_down_RAMP_mapping_apply')
51 import c_rp, c_ptr, c_int
52 real(c_rp) :: f_min
53 real(c_rp) :: f_max
54 real(c_rp) :: q
55 type(c_ptr), value :: X_out_d
56 type(c_ptr), value :: X_in_d
57 integer(c_int) :: n
58 end subroutine hip_convex_down_ramp_mapping_apply
59 end interface
60
61 interface
62 subroutine hip_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
63 sense_out_d, sens_in_d, X_in_d, n) &
64 bind(c, name = 'hip_convex_down_RAMP_mapping_apply_backward')
65 import c_rp, c_ptr, c_int
66 real(c_rp) :: f_min
67 real(c_rp) :: f_max
68 real(c_rp) :: q
69 type(c_ptr), value :: sense_out_d
70 type(c_ptr), value :: sens_in_d
71 type(c_ptr), value :: X_in_d
72 integer(c_int) :: n
73 end subroutine hip_convex_down_ramp_mapping_apply_backward
74 end interface
75
76 interface
77 subroutine hip_convex_up_ramp_mapping_apply(f_min, f_max, q, &
78 X_out_d, X_in_d, n) &
79 bind(c, name = 'hip_convex_up_RAMP_mapping_apply')
80 import c_rp, c_ptr, c_int
81 real(c_rp) :: f_min
82 real(c_rp) :: f_max
83 real(c_rp) :: q
84 type(c_ptr), value :: X_out_d
85 type(c_ptr), value :: X_in_d
86 integer(c_int) :: n
87 end subroutine hip_convex_up_ramp_mapping_apply
88 end interface
89
90 interface
91 subroutine hip_convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
92 sense_out_d, sens_in_d, X_in_d, n) &
93 bind(c, name = 'hip_convex_up_RAMP_mapping_apply_backward')
94 import c_rp, c_ptr, c_int
95 real(c_rp) :: f_min
96 real(c_rp) :: f_max
97 real(c_rp) :: q
98 type(c_ptr), value :: sense_out_d
99 type(c_ptr), value :: sens_in_d
100 type(c_ptr), value :: X_in_d
101 integer(c_int) :: n
102 end subroutine hip_convex_up_ramp_mapping_apply_backward
103 end interface
104
105#elif HAVE_CUDA
106
107 interface
108 subroutine cuda_convex_down_ramp_mapping_apply(f_min, f_max, q, &
109 X_out_d, X_in_d, n) &
110 bind(c, name = 'cuda_convex_down_RAMP_mapping_apply')
111 import c_rp, c_ptr, c_int
112 real(c_rp) :: f_min
113 real(c_rp) :: f_max
114 real(c_rp) :: q
115 type(c_ptr), value :: X_out_d
116 type(c_ptr), value :: X_in_d
117 integer(c_int) :: n
118 end subroutine cuda_convex_down_ramp_mapping_apply
119 end interface
120
121 interface
122 subroutine cuda_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
123 sense_out_d, sens_in_d, X_in_d, n) &
124 bind(c, name = 'cuda_convex_down_RAMP_mapping_apply_backward')
125 import c_rp, c_ptr, c_int
126 real(c_rp) :: f_min
127 real(c_rp) :: f_max
128 real(c_rp) :: q
129 type(c_ptr), value :: sense_out_d
130 type(c_ptr), value :: sens_in_d
131 type(c_ptr), value :: X_in_d
132 integer(c_int) :: n
133 end subroutine cuda_convex_down_ramp_mapping_apply_backward
134 end interface
135
136 interface
137 subroutine cuda_convex_up_ramp_mapping_apply(f_min, f_max, q, &
138 X_out_d, X_in_d, n) &
139 bind(c, name = 'cuda_convex_up_RAMP_mapping_apply')
140 import c_rp, c_ptr, c_int
141 real(c_rp) :: f_min
142 real(c_rp) :: f_max
143 real(c_rp) :: q
144 type(c_ptr), value :: X_out_d
145 type(c_ptr), value :: X_in_d
146 integer(c_int) :: n
147 end subroutine cuda_convex_up_ramp_mapping_apply
148 end interface
149
150 interface
151 subroutine cuda_convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
152 sense_out_d, sens_in_d, X_in_d, n) &
153 bind(c, name = 'cuda_convex_up_RAMP_mapping_apply_backward')
154 import c_rp, c_ptr, c_int
155 real(c_rp) :: f_min
156 real(c_rp) :: f_max
157 real(c_rp) :: q
158 type(c_ptr), value :: sense_out_d
159 type(c_ptr), value :: sens_in_d
160 type(c_ptr), value :: X_in_d
161 integer(c_int) :: n
162 end subroutine cuda_convex_up_ramp_mapping_apply_backward
163 end interface
164
165#elif HAVE_OPENCL
166
167#endif
168
169contains
170
171 subroutine device_convex_down_ramp_mapping_apply(f_min, f_max, q, &
172 X_out_d, X_in_d, n)
173 real(kind=rp), intent(in) :: f_min
174 real(kind=rp), intent(in) :: f_max
175 real(kind=rp), intent(in) :: q
176 type(c_ptr) :: X_out_d
177 type(c_ptr) :: X_in_d
178 integer :: n
179#if HAVE_HIP
180 call hip_convex_down_ramp_mapping_apply(f_min, f_max, q, &
181 x_out_d, x_in_d, n)
182#elif HAVE_CUDA
183 call cuda_convex_down_ramp_mapping_apply(f_min, f_max, q, &
184 x_out_d, x_in_d, n)
185#else
186 call neko_error('No device backend configured')
187#endif
188 end subroutine device_convex_down_ramp_mapping_apply
189
190 subroutine device_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
191 sense_out_d, sens_in_d, X_in_d, n)
192 real(kind=rp), intent(in) :: f_min
193 real(kind=rp), intent(in) :: f_max
194 real(kind=rp), intent(in) :: q
195 type(c_ptr) :: sense_out_d
196 type(c_ptr) :: sens_in_d
197 type(c_ptr) :: X_in_d
198 integer :: n
199#if HAVE_HIP
200 call hip_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
201 sense_out_d, sens_in_d, x_in_d, n)
202#elif HAVE_CUDA
203 call cuda_convex_down_ramp_mapping_apply_backward(f_min, f_max, q, &
204 sense_out_d, sens_in_d, x_in_d, n)
205#else
206 call neko_error('No device backend configured')
207#endif
208 end subroutine device_convex_down_ramp_mapping_apply_backward
209
210 subroutine device_convex_up_ramp_mapping_apply(f_min, f_max, q, &
211 X_out_d, X_in_d, n)
212 real(kind=rp), intent(in) :: f_min
213 real(kind=rp), intent(in) :: f_max
214 real(kind=rp), intent(in) :: q
215 type(c_ptr) :: X_out_d
216 type(c_ptr) :: X_in_d
217 integer :: n
218#if HAVE_HIP
219 call hip_convex_up_ramp_mapping_apply(f_min, f_max, q, &
220 x_out_d, x_in_d, n)
221#elif HAVE_CUDA
222 call cuda_convex_up_ramp_mapping_apply(f_min, f_max, q, &
223 x_out_d, x_in_d, n)
224#else
225 call neko_error('No device backend configured')
226#endif
227 end subroutine device_convex_up_ramp_mapping_apply
228
229 subroutine device_convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
230 sense_out_d, sens_in_d, X_in_d, n)
231 real(kind=rp), intent(in) :: f_min
232 real(kind=rp), intent(in) :: f_max
233 real(kind=rp), intent(in) :: q
234 type(c_ptr) :: sense_out_d
235 type(c_ptr) :: sens_in_d
236 type(c_ptr) :: X_in_d
237 integer :: n
238#if HAVE_HIP
239 call hip_convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
240 sense_out_d, sens_in_d, x_in_d, n)
241#elif HAVE_CUDA
242 call cuda_convex_up_ramp_mapping_apply_backward(f_min, f_max, q, &
243 sense_out_d, sens_in_d, x_in_d, n)
244#else
245 call neko_error('No device backend configured')
246#endif
247 end subroutine device_convex_up_ramp_mapping_apply_backward
248end module device_ramp_mapping