Skip to content

Fix CUDA GlobalToGlobal codegen error by raising NotImplementedError #2041

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions dace/codegen/targets/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,13 @@ def _emit_copy(self, state_id: int, src_node: nodes.Node, src_storage: dtypes.St
dims = len(copy_shape)

funcname = 'dace::%sTo%s%dD' % (_get_storagename(src_storage), _get_storagename(dst_storage), dims)

# Check for GlobalToGlobal copies which are not well-defined
if (src_storage == dtypes.StorageType.GPU_Global and dst_storage == dtypes.StorageType.GPU_Global):
raise NotImplementedError(
"GPU global memory to global memory copies need to be more explicitly specified in the code. "
"Consider using shared memory, different memory scopes, or explicit synchronization patterns.")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the not implemented error sound random?
Glb -> Glb being more explicitly specified in a code means that it needs to be copied within a map (e.g. calling copytomap as a transformation)?
As if there is a program that absolutely needs glb to glb memory copy (or the user wants that), I think asking for different memory locations to be used is irrelevant. Different memory scopes wont help and we don't have explicit synchronization patterns in dace (also what will adding a syncthreads will do)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

NotImplementedError(
"GPU global memory to global memory copies need to be more explicitly specified in the code. Considering moving the copy to a map using the CopyToMap transformation or manually. "
)

self._scope_has_collaborative_copy = True
accum = ''
custom_reduction = []
Expand Down
23 changes: 23 additions & 0 deletions tests/codegen/gpu_memcpy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,31 @@ def test_gpu_strided_2D_copy():
assert all(cp.all(ref[k] == res[k]) for k in ref.keys())


@pytest.mark.gpu
def test_global_to_global_error():
"""
Test that Global to Global copies within GPU_Device maps raise a NotImplementedError.
"""
N = dace.symbol('N')

@dace.program
def global_to_global_copy(A: dace.float64[N] @ dace.StorageType.GPU_Global,
B: dace.float64[N] @ dace.StorageType.GPU_Global):
# Create a GPU_Device map that contains a GlobalToGlobal copy
# Using slice assignment to create a direct copy between GPU_Global arrays
for i in dace.map[0:1] @ dace.ScheduleType.GPU_Device:
B[:] = A[:]

sdfg = global_to_global_copy.to_sdfg()

# This should raise NotImplementedError when compiling
with pytest.raises(NotImplementedError, match="GPU global memory to global memory copies"):
sdfg.compile()


if __name__ == '__main__':
test_gpu_shared_to_global_1D()
test_gpu_shared_to_global_1D_accumulate()
test_gpu_1d_copy()
test_gpu_strided_2D_copy()
test_global_to_global_error()
Loading