-
Notifications
You must be signed in to change notification settings - Fork 133
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
Fix for CUDA codegen #1442
Merged
Merged
Fix for CUDA codegen #1442
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9049210
[bug] Fix for floordiv codegen
edopao 54bf6c1
[fix] Fix lowering to CUDA coda
edopao f4a73f0
[bug] Missing symbols for data access on inter-state edge
edopao 880f247
[test] Add gpu version of indirection test
edopao 47856d8
[test] Add missing import for gpu test
edopao 08a036e
[test] Minor edit
edopao 9de8e60
[cuda] Revert SharedToGlobal1D to old codegen
edopao 0e37b12
Remove extra changes
edopao 87e947a
Different solution which keeps new template
edopao 12b5321
Fix cuda codegen for 1D dynamic copy
edopao 57f8c02
Merge remote-tracking branch 'origin/master' into bug-gpu-codegen
edopao 54d0c67
Fix for broken test
edopao 190f075
Merge remote-tracking branch 'origin/master' into bug-gpu-codegen-wip
edopao 721cb32
Apply type-specialization to template for ifloor
edopao d53d25b
Address review comments
edopao fa967ea
Merge pull request #2 from edopao/bug-gpu-codegen-wip
edopao 140aad4
Revert change for ifloor bugfix
edopao 39ef8e8
Add test case for neighbor reduction
edopao 289fba2
Merge pull request #3 from edopao/bug-gpu-codegen-wip
edopao 12b3cdd
Replace init state with edge assignment
edopao 150b4c4
Update test case for CUDA-codegen (#6)
edopao acf0e2d
Merge branch 'spcl:master' into bug-gpu-codegen
edopao d839089
Merge remote-tracking branch 'origin/master' into bug-gpu-codegen
edopao 8b99971
Correction for is_async arg in gpu memory copies
edopao f5cd14b
Move __syncthreads after thread copy
edopao 0dbaff2
Merge branch 'master' into bug-gpu-codegen
edopao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" Tests code generation for array copy on GPU target. """ | ||
import dace | ||
from dace.transformation.auto import auto_optimize | ||
|
||
import pytest | ||
import re | ||
|
||
# this test requires cupy module | ||
cp = pytest.importorskip("cupy") | ||
|
||
# initialize random number generator | ||
rng = cp.random.default_rng(42) | ||
|
||
|
||
@pytest.mark.gpu | ||
def test_gpu_shared_to_global_1D(): | ||
M = 32 | ||
N = dace.symbol('N') | ||
|
||
@dace.program | ||
def transpose_shared_to_global(A: dace.float64[M, N], B: dace.float64[N, M]): | ||
for i in dace.map[0:N]: | ||
local_gather = dace.define_local([M], A.dtype, storage=dace.StorageType.GPU_Shared) | ||
for j in dace.map[0:M]: | ||
local_gather[j] = A[j, i] | ||
B[i, :] = local_gather | ||
|
||
|
||
sdfg = transpose_shared_to_global.to_sdfg() | ||
auto_optimize.apply_gpu_storage(sdfg) | ||
|
||
size_M = M | ||
size_N = 128 | ||
|
||
A = rng.random((size_M, size_N,)) | ||
B = rng.random((size_N, size_M,)) | ||
|
||
ref = A.transpose() | ||
|
||
sdfg(A, B, N=size_N) | ||
cp.allclose(ref, B) | ||
|
||
code = sdfg.generate_code()[1].clean_code # Get GPU code (second file) | ||
m = re.search('dace::SharedToGlobal1D<.+>::Copy', code) | ||
assert m is not None | ||
|
||
|
||
@pytest.mark.gpu | ||
def test_gpu_shared_to_global_1D_accumulate(): | ||
M = 32 | ||
N = dace.symbol('N') | ||
|
||
@dace.program | ||
def transpose_and_add_shared_to_global(A: dace.float64[M, N], B: dace.float64[N, M]): | ||
for i in dace.map[0:N]: | ||
local_gather = dace.define_local([M], A.dtype, storage=dace.StorageType.GPU_Shared) | ||
for j in dace.map[0:M]: | ||
local_gather[j] = A[j, i] | ||
local_gather[:] >> B(M, lambda x, y: x + y)[i, :] | ||
|
||
|
||
sdfg = transpose_and_add_shared_to_global.to_sdfg() | ||
auto_optimize.apply_gpu_storage(sdfg) | ||
|
||
size_M = M | ||
size_N = 128 | ||
|
||
A = rng.random((size_M, size_N,)) | ||
B = rng.random((size_N, size_M,)) | ||
|
||
ref = A.transpose() + B | ||
|
||
sdfg(A, B, N=size_N) | ||
cp.allclose(ref, B) | ||
|
||
code = sdfg.generate_code()[1].clean_code # Get GPU code (second file) | ||
m = re.search('dace::SharedToGlobal1D<.+>::template Accum', code) | ||
assert m is not None | ||
|
||
|
||
if __name__ == '__main__': | ||
test_gpu_shared_to_global_1D() | ||
test_gpu_shared_to_global_1D_accumulate() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be the other way around (if there is a dependent read after it in the same state, sync).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I did not pay enough attention to
is_async
before. Besides correcting the value of this argument, I have also moved the synchronization point in the template function after the thread-level copy (see my last commit on copy.cuh).