Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Making @atomic robust #467

Merged
merged 5 commits into from
Oct 2, 2019
Merged

Making @atomic robust #467

merged 5 commits into from
Oct 2, 2019

Conversation

UmashankarTriforce
Copy link
Contributor

This PR aims to handle various errors encountered by @atomic and report them nicely
Fixes #453

@UmashankarTriforce
Copy link
Contributor Author

I would like to know what other conditions I need to check for. Hence I have added [WIP] in PR.

@maleadt
Copy link
Member

maleadt commented Sep 30, 2019

I'd just flip the condition, requiring rhs to be an expression, because the following still breaks:

@cuda ((a)->(CUDAnative.@atomic a[2] = i; nothing))(CuArray{Int}(undef, 1))
ERROR: LoadError: type Symbol has no field head

Also add a test.

Of course, as I mentioned on Slack it would be nice if this would just work, but that's more work. Improving the error message is a good start.

@UmashankarTriforce
Copy link
Contributor Author

Where and how do I add a test?

@maleadt
Copy link
Member

maleadt commented Sep 30, 2019

Have a look at the tests/ folder, there's a bunch of existing ones for @atomic.

@UmashankarTriforce
Copy link
Contributor Author

I have added a section for exception test and accomodated the previous failing case. Let me know if I have missed out on something

@@ -319,6 +319,9 @@ macro atomic(ex)
if ex.head == :(=)
ref = ex.args[1]
rhs = ex.args[2]
if typeof(rhs) <: Number || typeof(rhs) <: String || typeof(rhs) <: Symbol
Copy link
Member

Choose a reason for hiding this comment

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

That's not what I meant, instead of checking against a blacklist of non-Expr types, it's easier to (whitelist) check for what's allowed: Expr.

Comment on lines 984 to 995
@testset "exceptions" begin
@testset for T in [Int32, Int64, UInt32, UInt64]
a = CuArray([typemax(T)])
function kernal(T, a)
@atomic a[1] = 1
@atomic a[1] = "1"
@atomic a[1] = i
return
end
@cuda threads=32 kernal(T, a)
@test Array(a)[1] == 1
end
Copy link
Member

Choose a reason for hiding this comment

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

Did you run these tests? They are intended to fail, so you can't just run them (the test would fail). Instead, you need to test_throws. Also, you can't put multiple failing atomic expressions in a single test because it'll bail out at the first error.
I'll push a fix, since it's somewhat finicky to use test_throws with macros.

@maleadt
Copy link
Member

maleadt commented Oct 2, 2019

bors try

bors bot added a commit that referenced this pull request Oct 2, 2019
@bors
Copy link
Contributor

bors bot commented Oct 2, 2019

try

Build succeeded

@maleadt
Copy link
Member

maleadt commented Oct 2, 2019

Let's merge this. Thanks for the PR!

@maleadt maleadt changed the title [WIP] Making @atomic robust Making @atomic robust Oct 2, 2019
@maleadt maleadt merged commit 9b72041 into JuliaGPU:master Oct 2, 2019
@UmashankarTriforce UmashankarTriforce deleted the atomic branch October 2, 2019 17:01
maleadt pushed a commit that referenced this pull request Oct 3, 2019
maleadt pushed a commit that referenced this pull request Oct 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@atomic does not error nicely
2 participants