-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
RFC: use GPUArrays, also for testing #9
Merged
Merged
Changes from 1 commit
Commits
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
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,41 @@ | ||
|
||
# Tests from Flux, probably not the optimal testset organisation! | ||
|
||
@testset "CUDA" begin | ||
x = randn(5, 5) | ||
cx = cu(x) | ||
@test cx isa CuArray | ||
|
||
@test_broken onecold(cu([1.0, 2.0, 3.0])) == 3 # scalar indexing error? | ||
|
||
x = onehotbatch([1, 2, 3], 1:3) | ||
cx = cu(x) | ||
@test cx isa OneHotMatrix && cx.indices isa CuArray | ||
@test (cx .+ 1) isa CuArray | ||
|
||
xs = rand(5, 5) | ||
ys = onehotbatch(1:5,1:5) | ||
@test collect(cu(xs) .+ cu(ys)) ≈ collect(xs .+ ys) | ||
end | ||
|
||
@testset "onehot gpu" begin | ||
y = onehotbatch(ones(3), 1:2) |> cu; | ||
@test (repr("text/plain", y); true) | ||
|
||
gA = rand(3, 2) |> cu; | ||
@test_broken gradient(A -> sum(A * y), gA)[1] isa CuArray # fails with JLArray, bug in Zygote? | ||
end | ||
|
||
@testset "onecold gpu" begin | ||
y = onehotbatch(ones(3), 1:10) |> cu; | ||
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] | ||
@test onecold(y) isa CuArray | ||
@test y[3,:] isa CuArray | ||
@test onecold(y, l) == ['a', 'a', 'a'] | ||
end | ||
|
||
@testset "onehot forward map to broadcast" begin | ||
oa = OneHotArray(rand(1:10, 5, 5), 10) |> cu | ||
@test all(map(identity, oa) .== oa) | ||
@test all(map(x -> 2 * x, oa) .== 2 .* oa) | ||
end |
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
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.
Is this correct? The number of dimensions for T would be <N.
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.
After some confusion: The
N
here is what's calledM
orN+1
elsewhere in this file. The 4th type parameter, not the 3rd. So this line does change the result, although maybe it's not tested?Is there a way around that?
One hack I can think of is relying on all ArrayStyles to be like
CuArrayStyle{N}
and have their N first. It seems pretty unlikely that any AbstractGPUArray is going to deviate from that pattern.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.
That or some hack to swap out the ndims of the index array type to
N
. Then forwarding toBroadcastStyle
would just do the right thing. I'm not sure which is more stable.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.
See what you think of ffb6f00