Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataOffload: fix generation of offload pragmas #442

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions loki/transformations/data_offload.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def transform_module(self, module, **kwargs):
offload_variables = offload_variables - declared_variables
if offload_variables:
module.spec.append(
Pragma(keyword='acc', content=f'declare create({",".join(v.name for v in offload_variables)})')
Pragma(keyword='acc', content=f'declare create({", ".join(v.name for v in offload_variables)})')
)

def transform_subroutine(self, routine, **kwargs):
Expand Down Expand Up @@ -575,11 +575,11 @@ def process_driver(self, routine, successors):
copyin_variables = {v for v, _ in uses_symbols if v.parent}
if update_variables:
update_device += (
Pragma(keyword='acc', content=f'update device({",".join(v.name for v in update_variables)})'),
Pragma(keyword='acc', content=f'update device({", ".join(v.name for v in update_variables)})'),
)
if copyin_variables:
update_device += (
Pragma(keyword='acc', content=f'enter data copyin({",".join(v.name for v in copyin_variables)})'),
Pragma(keyword='acc', content=f'enter data copyin({", ".join(v.name for v in copyin_variables)})'),
)

# All variables that are written in a kernel need a device-to-host transfer
Expand All @@ -592,15 +592,15 @@ def process_driver(self, routine, successors):
}
if update_variables:
update_host += (
Pragma(keyword='acc', content=f'update self({",".join(v.name for v in update_variables)})'),
Pragma(keyword='acc', content=f'update self({", ".join(v.name for v in update_variables)})'),
)
if copyout_variables:
update_host += (
Pragma(keyword='acc', content=f'exit data copyout({",".join(v.name for v in copyout_variables)})'),
Pragma(keyword='acc', content=f'exit data copyout({", ".join(v.name for v in copyout_variables)})'),
)
if create_variables:
update_device += (
Pragma(keyword='acc', content=f'enter data create({",".join(v.name for v in create_variables)})'),
Pragma(keyword='acc', content=f'enter data create({", ".join(v.name for v in create_variables)})'),
)

# Replace Loki pragmas with acc data/update pragmas
Expand Down
6 changes: 3 additions & 3 deletions loki/transformations/tests/test_data_offload.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,11 @@ def test_global_variable_offload(frontend, key, config, global_variable_analysis
for pragma in acc_pragmas[:len(expected_h2d_pragmas)]:
command, variables = pragma.content.lower().split('(')
assert command.strip() in expected_h2d_pragmas
assert set(variables.strip()[:-1].strip().split(',')) == expected_h2d_pragmas[command.strip()]
assert set(variables.strip()[:-1].strip().split(', ')) == expected_h2d_pragmas[command.strip()]
for pragma in acc_pragmas[len(expected_h2d_pragmas):]:
command, variables = pragma.content.lower().split('(')
assert command.strip() in expected_d2h_pragmas
assert set(variables.strip()[:-1].strip().split(',')) == expected_d2h_pragmas[command.strip()]
assert set(variables.strip()[:-1].strip().split(', ')) == expected_d2h_pragmas[command.strip()]

# Verify declarations have been added to the header modules
expected_declarations = {
Expand All @@ -591,7 +591,7 @@ def test_global_variable_offload(frontend, key, config, global_variable_analysis
variables = {
v.strip()
for pragma in acc_pragmas
for v in pragma.content.lower().split('(')[-1].strip()[:-1].split(',')
for v in pragma.content.lower().split('(')[-1].strip()[:-1].split(', ')
}
assert variables == expected_declarations[name]

Expand Down
Loading