-
Notifications
You must be signed in to change notification settings - Fork 38
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
Implements event_notify using safe operations #87
Conversation
evt_id = Ref{CL_event}(0) | ||
status = Ref{CL_int}(0) | ||
cb = Base.SingleAsyncWork(data -> callback(evt_id[], status[])) | ||
ptrs = [cb.handle, Base.unsafe_convert(Ptr, evt_id), Base.unsafe_convert(Ptr, status)] |
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.
We need to make sure that this doesn't get GC'd so I am contemplating adding an ObjectIdDict to CLEvent. @jakebolewski Any better Ideas?
A problem that I see with this implementation is that each callback has only one set of return values, but it is entirely possible that |
6c26bb8
to
a6ce169
Compare
This fix only works on Julia v0.4. @jakebolewski Any ideas how to achieve the same with 0.3? I currently don't have a computer with OpenCL around so I am not quite sure why the tests are hanging on the events. Will see if I can try it out during work. |
I am running into a weird seqfault,
Where:
julia> code_llvm(OpenCL.event_notify, (OpenCL.CL_event, OpenCL.CL_int,Ptr{Void}))
define void @julia_event_notify_21517(i8*, i32, i8*) {
top:
%3 = bitcast i8* %2 to i8**
%4 = load i8** %3, align 1
%5 = getelementptr i8* %2, i64 8
%6 = bitcast i8* %5 to i8**
%7 = load i8** %6, align 1
%8 = bitcast i8* %7 to i8**
%9 = getelementptr i8* %2, i64 16
%10 = bitcast i8* %9 to i8**
%11 = load i8** %10, align 1
%12 = bitcast i8* %11 to i32*
store i8* %0, i8** %8, align 1
store i32 %1, i32* %12, align 1
call void inttoptr (i64 140438188430736 to void (i8*)*)(i8* inreg %4)
ret void
} @vtjnash Do you have any insight in what I might be doing wrong/or if this is the right direction/ |
p_status = Base.unsafe_convert(Ptr{CL_int}, r_status) | ||
|
||
cb = Base.SingleAsyncWork(data -> begin | ||
println("Received callback") |
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.
println isn't really allowed here. the SingleAsyncWork callback is being run directly from libuv's callback, so anything that may try to block (such as the flush at the end of printing) could result in a recursive call to the libuv event loop. a better pattern is for the SingleAsyncWork callback to notify a Condition variable, and do the real work on a thread that monitors that variable (a PR to Base to replace the callback with a Condition variable would be a useful improvement to this API).
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.
So instead I would have:
cond = Condition()
cb = Base.SingleAsyncWork(data -> notify(cond))
@async begin
wait(cond)
callback(r_evt_id[], r_status[])
end
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.
Could it be that the main issue I am running into is that I am trying to write memory in a protected address space?
@vtjnash Could you take another look? This is my most promising attempt yet and the callback compiles to:
|
ae570b9
to
6eead50
Compare
I believe this solution should work, although should there be a corresponding |
@jakebolewski Thanks. Before this goes in we would need to bump the minimal version to 0.4 so I will start a PR for that. |
I think dropping support for 0.4 is reasonable. Some parts of the API can be simplified with call overloading. |
I hope you meant dropping support for 0.3 ;) |
https://github.com/JuliaGPU/OpenCL.jl/blob/master/src/context.jl#L32-L38 Should probably receive the same treatment? |
05fb9a6
to
c1e0421
Compare
So rebased and squashed and I will start to fix the callback in context.jl, because baased on the docs [1] the callback can/will happen asynchronously. [1] https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateContext.html |
The callback itself should only use basic and thread-safe operations and should also not block. The result from the callback is stored in a reference to an immutable and a waiting task notify to get the result value and dispatch the user-supplied callback.
c1e0421
to
267266e
Compare
@jakebolewski Take a look at this and if you agree we can merge, after fixing the oom travis error we can go ahead and tag a new release. |
Implements event_notify using safe operations
Fixes #86.