Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
device_steepest_descent.f90
Go to the documentation of this file.
1
34
41 use utils, only: neko_error
42 use num_types, only: rp, c_rp
43 use, intrinsic :: iso_c_binding, only: c_ptr, c_int
44 implicit none
45 private
46
49
50#if HAVE_HIP
51
52 interface
53 subroutine hip_sd_direction(s_d, x_d, xmin, xmax, n) &
54 bind(c, name = 'hip_sd_direction')
55 import c_rp, c_ptr, c_int
56 type(c_ptr), value :: s_d
57 type(c_ptr), value :: x_d
58 real(c_rp) :: xmin
59 real(c_rp) :: xmax
60 integer(c_int) :: n
61 end subroutine hip_sd_direction
62 end interface
63
64 interface
65 subroutine hip_sd_update_move_limits(delta_d, x_d, x1_d, x2_d, &
66 dec, inc, dmin, dmax, n) &
67 bind(c, name = 'hip_sd_update_move_limits')
68 import c_rp, c_ptr, c_int
69 type(c_ptr), value :: delta_d
70 type(c_ptr), value :: x_d
71 type(c_ptr), value :: x1_d
72 type(c_ptr), value :: x2_d
73 real(c_rp) :: dec
74 real(c_rp) :: inc
75 real(c_rp) :: dmin
76 real(c_rp) :: dmax
77 integer(c_int) :: n
78 end subroutine hip_sd_update_move_limits
79 end interface
80
81 interface
82 subroutine hip_sd_update_design(x_new_d, x_d, s_d, delta_d, &
83 psi, smax, xmin, xmax, n) &
84 bind(c, name = 'hip_sd_update_design')
85 import c_rp, c_ptr, c_int
86 type(c_ptr), value :: x_new_d
87 type(c_ptr), value :: x_d
88 type(c_ptr), value :: s_d
89 type(c_ptr), value :: delta_d
90 real(c_rp) :: psi
91 real(c_rp) :: smax
92 real(c_rp) :: xmin
93 real(c_rp) :: xmax
94 integer(c_int) :: n
95 end subroutine hip_sd_update_design
96 end interface
97
98#elif HAVE_CUDA
99
100 interface
101 subroutine cuda_sd_direction(s_d, x_d, xmin, xmax, n) &
102 bind(c, name = 'cuda_sd_direction')
103 import c_rp, c_ptr, c_int
104 type(c_ptr), value :: s_d
105 type(c_ptr), value :: x_d
106 real(c_rp) :: xmin
107 real(c_rp) :: xmax
108 integer(c_int) :: n
109 end subroutine cuda_sd_direction
110 end interface
111
112 interface
113 subroutine cuda_sd_update_move_limits(delta_d, x_d, x1_d, x2_d, &
114 dec, inc, dmin, dmax, n) &
115 bind(c, name = 'cuda_sd_update_move_limits')
116 import c_rp, c_ptr, c_int
117 type(c_ptr), value :: delta_d
118 type(c_ptr), value :: x_d
119 type(c_ptr), value :: x1_d
120 type(c_ptr), value :: x2_d
121 real(c_rp) :: dec
122 real(c_rp) :: inc
123 real(c_rp) :: dmin
124 real(c_rp) :: dmax
125 integer(c_int) :: n
126 end subroutine cuda_sd_update_move_limits
127 end interface
128
129 interface
130 subroutine cuda_sd_update_design(x_new_d, x_d, s_d, delta_d, &
131 psi, smax, xmin, xmax, n) &
132 bind(c, name = 'cuda_sd_update_design')
133 import c_rp, c_ptr, c_int
134 type(c_ptr), value :: x_new_d
135 type(c_ptr), value :: x_d
136 type(c_ptr), value :: s_d
137 type(c_ptr), value :: delta_d
138 real(c_rp) :: psi
139 real(c_rp) :: smax
140 real(c_rp) :: xmin
141 real(c_rp) :: xmax
142 integer(c_int) :: n
143 end subroutine cuda_sd_update_design
144 end interface
145
146#endif
147
148contains
149
158 subroutine device_sd_direction(s_d, x_d, xmin, xmax, n)
159 type(c_ptr) :: s_d
160 type(c_ptr) :: x_d
161 real(kind=rp), intent(in) :: xmin
162 real(kind=rp), intent(in) :: xmax
163 integer, intent(in) :: n
164#if HAVE_HIP
165 call hip_sd_direction(s_d, x_d, xmin, xmax, n)
166#elif HAVE_CUDA
167 call cuda_sd_direction(s_d, x_d, xmin, xmax, n)
168#else
169 call neko_error('No device backend configured')
170#endif
171 end subroutine device_sd_direction
172
184 subroutine device_sd_update_move_limits(delta_d, x_d, x1_d, x2_d, &
185 dec, inc, dmin, dmax, n)
186 type(c_ptr) :: delta_d
187 type(c_ptr) :: x_d
188 type(c_ptr) :: x1_d
189 type(c_ptr) :: x2_d
190 real(kind=rp), intent(in) :: dec
191 real(kind=rp), intent(in) :: inc
192 real(kind=rp), intent(in) :: dmin
193 real(kind=rp), intent(in) :: dmax
194 integer, intent(in) :: n
195#if HAVE_HIP
196 call hip_sd_update_move_limits(delta_d, x_d, x1_d, x2_d, &
197 dec, inc, dmin, dmax, n)
198#elif HAVE_CUDA
199 call cuda_sd_update_move_limits(delta_d, x_d, x1_d, x2_d, &
200 dec, inc, dmin, dmax, n)
201#else
202 call neko_error('No device backend configured')
203#endif
204 end subroutine device_sd_update_move_limits
205
217 subroutine device_sd_update_design(x_new_d, x_d, s_d, delta_d, &
218 psi, smax, xmin, xmax, n)
219 type(c_ptr) :: x_new_d
220 type(c_ptr) :: x_d
221 type(c_ptr) :: s_d
222 type(c_ptr) :: delta_d
223 real(kind=rp), intent(in) :: psi
224 real(kind=rp), intent(in) :: smax
225 real(kind=rp), intent(in) :: xmin
226 real(kind=rp), intent(in) :: xmax
227 integer, intent(in) :: n
228#if HAVE_HIP
229 call hip_sd_update_design(x_new_d, x_d, s_d, delta_d, &
230 psi, smax, xmin, xmax, n)
231#elif HAVE_CUDA
232 call cuda_sd_update_design(x_new_d, x_d, s_d, delta_d, &
233 psi, smax, xmin, xmax, n)
234#else
235 call neko_error('No device backend configured')
236#endif
237 end subroutine device_sd_update_design
238
Device backend dispatch for the steepest-descent optimizer kernels.
subroutine, public device_sd_update_move_limits(delta_d, x_d, x1_d, x2_d, dec, inc, dmin, dmax, n)
Adapt the move limits on the device (Eq. D23).
subroutine, public device_sd_update_design(x_new_d, x_d, s_d, delta_d, psi, smax, xmin, xmax, n)
Move-limited, box-constrained design update on the device (Eq. D24).
subroutine, public device_sd_direction(s_d, x_d, xmin, xmax, n)
Bound-projected steepest-descent direction on the device (Eq. D22).
void cuda_sd_direction(void *s_d, void *x_d, real *xmin, real *xmax, int *n)
void cuda_sd_update_design(void *x_new_d, void *x_d, void *s_d, void *delta_d, real *psi, real *smax, real *xmin, real *xmax, int *n)
void cuda_sd_update_move_limits(void *delta_d, void *x_d, void *x1_d, void *x2_d, real *dec, real *inc, real *dmin, real *dmax, int *n)
void hip_sd_update_move_limits(void *delta_d, void *x_d, void *x1_d, void *x2_d, real *dec, real *inc, real *dmin, real *dmax, int *n)
void hip_sd_update_design(void *x_new_d, void *x_d, void *s_d, void *delta_d, real *psi, real *smax, real *xmin, real *xmax, int *n)
void hip_sd_direction(void *s_d, void *x_d, real *xmin, real *xmax, int *n)