Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
device_SIMP_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_simp_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_simp_mapping_apply, device_simp_mapping_apply_backward
41
42#if HAVE_HIP
43
44 interface
45 subroutine hip_simp_mapping_apply(f_min, f_max, p, &
46 X_out_d, X_in_d, n) &
47 bind(c, name = 'hip_SIMP_mapping_apply')
48 import c_rp, c_ptr, c_int
49 real(c_rp) :: f_min
50 real(c_rp) :: f_max
51 real(c_rp) :: p
52 type(c_ptr), value :: X_out_d
53 type(c_ptr), value :: X_in_d
54 integer(c_int) :: n
55 end subroutine hip_simp_mapping_apply
56 end interface
57
58 interface
59 subroutine hip_simp_mapping_apply_backward(f_min, f_max, p, &
60 sense_out_d, sens_in_d, X_in_d, n) &
61 bind(c, name = 'hip_SIMP_mapping_apply_backward')
62 import c_rp, c_ptr, c_int
63 real(c_rp) :: f_min
64 real(c_rp) :: f_max
65 real(c_rp) :: p
66 type(c_ptr), value :: sense_out_d
67 type(c_ptr), value :: sens_in_d
68 type(c_ptr), value :: X_in_d
69 integer(c_int) :: n
70 end subroutine hip_simp_mapping_apply_backward
71 end interface
72
73#elif HAVE_CUDA
74
75 interface
76 subroutine cuda_simp_mapping_apply(f_min, f_max, p, &
77 X_out_d, X_in_d, n) &
78 bind(c, name = 'cuda_SIMP_mapping_apply')
79 import c_rp, c_ptr, c_int
80 real(c_rp) :: f_min
81 real(c_rp) :: f_max
82 real(c_rp) :: p
83 type(c_ptr), value :: X_out_d
84 type(c_ptr), value :: X_in_d
85 integer(c_int) :: n
86 end subroutine cuda_simp_mapping_apply
87 end interface
88
89 interface
90 subroutine cuda_simp_mapping_apply_backward(f_min, f_max, p, &
91 sense_out_d, sens_in_d, X_in_d, n) &
92 bind(c, name = 'cuda_SIMP_mapping_apply_backward')
93 import c_rp, c_ptr, c_int
94 real(c_rp) :: f_min
95 real(c_rp) :: f_max
96 real(c_rp) :: p
97 type(c_ptr), value :: sense_out_d
98 type(c_ptr), value :: sens_in_d
99 type(c_ptr), value :: X_in_d
100 integer(c_int) :: n
101 end subroutine cuda_simp_mapping_apply_backward
102 end interface
103
104#elif HAVE_OPENCL
105
106#endif
107
108contains
109
110 subroutine device_simp_mapping_apply(f_min, f_max, p, &
111 X_out_d, X_in_d, n)
112 real(kind=rp), intent(in) :: f_min
113 real(kind=rp), intent(in) :: f_max
114 real(kind=rp), intent(in) :: p
115 type(c_ptr) :: X_out_d
116 type(c_ptr) :: X_in_d
117 integer :: n
118#if HAVE_HIP
119 call hip_simp_mapping_apply(f_min, f_max, p, &
120 x_out_d, x_in_d, n)
121#elif HAVE_CUDA
122 call cuda_simp_mapping_apply(f_min, f_max, p, &
123 x_out_d, x_in_d, n)
124#else
125 call neko_error('No device backend configured')
126#endif
127 end subroutine device_simp_mapping_apply
128
129 subroutine device_simp_mapping_apply_backward(f_min, f_max, p, &
130 sense_out_d, sens_in_d, X_in_d, n)
131 real(kind=rp), intent(in) :: f_min
132 real(kind=rp), intent(in) :: f_max
133 real(kind=rp), intent(in) :: p
134 type(c_ptr) :: sense_out_d
135 type(c_ptr) :: sens_in_d
136 type(c_ptr) :: X_in_d
137 integer :: n
138#if HAVE_HIP
139 call hip_simp_mapping_apply_backward(f_min, f_max, p, &
140 sense_out_d, sens_in_d, x_in_d, n)
141#elif HAVE_CUDA
142 call cuda_simp_mapping_apply_backward(f_min, f_max, p, &
143 sense_out_d, sens_in_d, x_in_d, n)
144#else
145 call neko_error('No device backend configured')
146#endif
147 end subroutine device_simp_mapping_apply_backward
148
149end module device_simp_mapping