Skip to content

Commit 26769f1

Browse files
author
Thomas Jackson
committed
Fix GPU device linkage for surface thermochemistry
1 parent ae12489 commit 26769f1

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

toolchain/mfc/run/input.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,25 @@ def get_cantera_surface(self):
131131

132132
raise common.MFCException(f"Cantera surface file '{surface_file}' with phase " f"'{surface_phase}' could not be loaded. " f"Searched: {', '.join(candidates)}.")
133133

134-
def generate_surface_thermochem(self, sol, surface) -> str:
134+
def generate_surface_thermochem(self, sol, surface, directive_str=None) -> str:
135135
"""Generate the MFC heterogeneous surface-chemistry Fortran module."""
136+
137+
if directive_str == "mp":
138+
gpu_routine_define = "#define GPU_ROUTINE(name) !$omp declare target device_type(any)"
139+
elif directive_str == "acc":
140+
gpu_routine_define = "#define GPU_ROUTINE(name) !$acc routine seq"
141+
else:
142+
gpu_routine_define = "#define GPU_ROUTINE(name) ! name"
143+
136144
if surface is None:
137145
num_species = len(sol.species_names)
138146

139147
lines = [
140148
"! This file is automatically generated by the MFC toolchain.",
141149
"! Do not edit manually.",
142150
"",
151+
gpu_routine_define,
152+
"",
143153
"module m_surface_thermochem",
144154
"",
145155
" use m_precision_select, only: wp",
@@ -155,6 +165,8 @@ def generate_surface_thermochem(self, sol, surface) -> str:
155165
" subroutine get_surface_net_production_rates( &",
156166
" density, temperature, mass_fractions, omega_s)",
157167
"",
168+
" GPU_ROUTINE(get_surface_net_production_rates)",
169+
"",
158170
" real(wp), intent(in) :: density",
159171
" real(wp), intent(in) :: temperature",
160172
f" real(wp), intent(in) :: mass_fractions({num_species})",
@@ -167,6 +179,8 @@ def generate_surface_thermochem(self, sol, surface) -> str:
167179
" subroutine get_surface_reaction_heat_flux( &",
168180
" density, temperature, mass_fractions, q_rxn)",
169181
"",
182+
" GPU_ROUTINE(get_surface_reaction_heat_flux)",
183+
"",
170184
" real(wp), intent(in) :: density",
171185
" real(wp), intent(in) :: temperature",
172186
f" real(wp), intent(in) :: mass_fractions({num_species})",
@@ -257,6 +271,8 @@ def h_rt(a):
257271
"! This file is automatically generated by the MFC toolchain.",
258272
"! Do not edit manually.",
259273
"",
274+
gpu_routine_define,
275+
"",
260276
"module m_surface_thermochem",
261277
"",
262278
" use m_precision_select, only: wp",
@@ -273,6 +289,8 @@ def h_rt(a):
273289
" subroutine get_surface_net_production_rates( &",
274290
" density, temperature, mass_fractions, omega_s)",
275291
"",
292+
" GPU_ROUTINE(get_surface_net_production_rates)",
293+
"",
276294
" real(wp), intent(in) :: density",
277295
" real(wp), intent(in) :: temperature",
278296
f" real(wp), intent(in) :: mass_fractions({len(gas_species)})",
@@ -352,6 +370,8 @@ def append_reaction_rate(lines, reaction_number, reaction):
352370
" subroutine get_surface_reaction_heat_flux( &",
353371
" density, temperature, mass_fractions, q_rxn)",
354372
"",
373+
" GPU_ROUTINE(get_surface_reaction_heat_flux)",
374+
"",
355375
" real(wp), intent(in) :: density",
356376
" real(wp), intent(in) :: temperature",
357377
f" real(wp), intent(in) :: mass_fractions({len(gas_species)})",
@@ -471,6 +491,7 @@ def generate_fpp(self, target) -> None:
471491
surface_thermochem_code = self.generate_surface_thermochem(
472492
sol,
473493
surface,
494+
directive_str,
474495
)
475496

476497
surface_thermochem_path = os.path.join(

0 commit comments

Comments
 (0)