-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add some docs and/or examples? #16
Comments
Probably after fixing this issue: For now, my plan would be to have a few libraries like Octavian and LoopVectorization use the low level interface. |
Currently, how it works is that you need a function that takes a The |
A complicating problem is that this has to be GC friendly, meaning we need So to automate this, what do we need? anonfunc = _ -> begin
# do stuff
end We could then create a This will allocate memory in general, so we could get fancier and try to turn any arrays into At this point, I'm inclined to just do this as part of the |
I agree that having this functionality in the However, I do think it would be good to also have a high level interface for using this package in settings that do not involve loops. Here's a sketch of what I'm envisioning. It intentionally tries to mimic the user interface of the built in threading. So I think it would be nice for ThreadingUtilities to export a macro @spawnfn foo(ptr)
And of course we don't want this to block. That is, if I have this: @spawnfn foo(ptr1)
@spawnfn foo(ptr2)
@spawnfn foo(ptr3)
@spawnfn foo(ptr4) Each of these lines would return immediately. Actually, it probably makes sense for thing1 = @spawnfn foo(ptr1)
thing2 = @spawnfn foo(ptr2)
thing3 = @spawnfn foo(ptr3)
thing4 = @spawnfn foo(ptr4)
wait(thing1)
wait(thing2)
wait(thing3)
wait(thing4) So we'd spawn all four functions at once, send them off to execute, and then wait until all four have completed. One note: if necessary, we can tell users that they need to do Would this kind of high level convenience interface be possible? Then users would be able to use ThreadingUtilities.jl really easily. |
I think it might work if the thing |
The follow-up question: if that's not possible, what is the simplest high-level convenience API that is possible for this package? |
Does ThreadingUtilities require that you tell it which thread to run the function on? |
Because it would be nice to support "please run this on any thread other than thread 1; I don't care which thread". Of course, we should probably also support "please run this on a specific thread number". |
Instead of returning the thing that needs to be preserved itself, can we return a struct that wraps it? I.e. if struct PreserveWrapper{T}
x::T
end Then we define the method This lets us use the Base |
It could loop through them until it finds one that is either |
Yes, that's what I meant. It'd also need to carry the id to wait on. |
Perfect. So |
I'll probably work on this fairly soon. While I think you can safely nest So I'll add some convenient functions that make it a little easier to use these in outer loops, and also a means of checking which tasks are available to spawn on. |
I'm trying to use this for the |
JuliaSIMD/LoopVectorization.jl#221 I'll try and get back to implementing
When you So the requirements on the function
The requirements on the function pointer are that it returns Be careful to |
from what I understand, the function implemented using Is there a way to get the current thread id inside the thread function, it seems the static array test doesn't use the thread id inside |
Yes. Parametric functors are often a convenient way of specifying some aspects of behavior. In that example,
I added an example using Basically, making offset, (ptry,ptrx) = ThreadingUtilities.load(p, A, 2*sizeof(UInt))
_, (ptry,ptrx) = ThreadingUtilities.load(p, B, offset) where
function setup_mul_svector!(p, tid, y::Base.RefValue{T}, x::Base.RefValue{T}) where {T}
py = Base.unsafe_convert(Ptr{T}, y)
px = Base.unsafe_convert(Ptr{T}, x)
fptr = mul_staticarray_ptr(py, px)
offset = ThreadingUtilities.store!(p, fptr, sizeof(UInt))
offset = ThreadingUtilities.store!(p, (py,px), offset)
ThreadingUtilities.store!(p, tid, offset)
nothing
end
@inline function launch_thread_mul_svector(tid, y, x)
ThreadingUtilities.launch(tid, tid, y, x) do p, tid, y, x
setup_mul_svector!(p, tid, y, x)
end
end and then function (::MulStaticArray{P})(p::Ptr{UInt}) where {P}
offset, (ptry,ptrx) = ThreadingUtilities.load(p, P, 2*sizeof(UInt))
_, tid = ThreadingUtilities.load(p, Int, offset)
unsafe_store!(ptry, unsafe_load(ptrx) * 2.7)
nothing
end |
No description provided.
The text was updated successfully, but these errors were encountered: