-
Notifications
You must be signed in to change notification settings - Fork 70
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
Base structure for Native Operators #16
Conversation
Great! Thanks! You might want to use an actual object instead of mere type in the API. e.g. function list_output(op::Softmax)
...
end As my impression is that an operator could actually have some properties, like |
Current coverage is
|
I want to formulate it threadsafe from the get go and I don't know how to do that (yet) -> https://groups.google.com/forum/#!topic/julia-dev/9J1GYfCyVpE |
2457a29
to
00e24c6
Compare
I dig a bit into the discussions on mailing list. Just to summarize based on my understanding:
|
@pluskid Exactly. also relevant #18 (comment) I am currently trying to implement async safe callbacks in OpenCL.jl with the ability to pass data along, but I am running into issues. I will keep you updated as it goes. JuliaGPU/OpenCL.jl#87 |
Sorry to keep you wait for a while, this PR apache/mxnet#667 enables asynchronize OP. I would recommend make an update to NativeOp to enable async mode, that exposes a callback to C API, which does some finalization stuffs(e.g. copy data back to TBlob), and call async_on_compelete. |
@tqchen Thanks for adding this! I had a closer look at the nativeop API. It's a bit strange to expose the user some raw pointer to operate with. I think it might be better to use |
@pluskid That was what I was going to do originally, but due to some reason I went this way instead. |
@pluskid @piiswrong I will look into the refactoring today, for both the python side and the julia side. |
@vchuravy remember to set the ctx of the ndarraies to OpContext.ctx |
@piiswrong Thanks! @vchuravy Great! I'll leave it to you now then. |
There was a bit interfacing issue that we did not yet expose ndarray as operator.
So if synchronize copy is introduced in the operator, the operator itself blocks in the memcpy call (of course this could also be ran by another worker thread), which is OK. Current operator was kinda of simplified to assume it actually does the heavy lifting works, copy to CPU and calls kinda of synchronize callback in native language. To support NDArray tracking, we will need to introduce operator interface with NDArray, while most wrapper should still go with the synchronized real action. This complicates a bit with c++11 issues, as c++11 support by nvcc was introduced, but seems not yet perfect, and current cuda related code are not yet c++11. But I am sure we will find a way. For short term, making native julia and numpy op work would be a good first step |
@vchuravy BTW, you probably will be interested in apache/mxnet#668 |
@vchuravy when do you expect to finish C++ side refactor? I also want that feature, maybe we can setup an API standard and divide labor |
@piiswrong I was thinking of later tonight, but if you want go ahead and I focus on the Julia side. |
efd0a3f
to
b729dd4
Compare
@pluskid I made some progress, but this is primarily focused on the conceptual side of how things should work. I am now working on getting it to a state where it actually works. |
@vchuravy Thanks! With the end of the semester settled and coming back from conference, I think I will probably finally be able to resume a relatively stable commitment to the project soon. What is the current status and current blocking item? Let me know if you need any help on this side. |
I still have to write the entire points and the rtc interface. After that On Sun, 13 Dec 2015, 23:59 Chiyuan Zhang [email protected] wrote:
|
e492b57
to
f223c96
Compare
@pluskid Conceptually everything is in place, but currently the following still seqfaults. using MXNet
immutable Softmax <: mx.Native.Operator end
op = Softmax()
info = mx.Native.NDArrayOpInfo(op)
pstring = bytestring("0x", hex(reinterpret(UInt, pointer_from_objref(info))))
mx._NDArray(name = :test, info = pstring) So I will have to do some more testing and debugging. But if you can find time and look over the basic design? |
Initializing a NativeOperator now works without seqfaulting.One major issue where I am unsure how to best handle that is the lifetime of Julia objects that we return via pointers to mxnet. One of those examples would be We will either keep track of all the pointers we hand off to mxnet or get MXNet to allocate memory for us. |
I would like to define function Base.call(op :: Operator; kwargs...)
info = NDArrayOpInfo(op)
pstring = bytestring("0x", hex(reinterpret(UInt, pointer_from_objref(info))))
mx._NDArray(info = pstring, kwargs...)
end So that the following would work immutable SoftmaxOp <: mx.Native.Operator end;
Softmax = SoftmaxOP();
Softmax(name = :Softmax) But the function gets precompiled and it doesn't find |
We need to make sure that `uv_async_send` is only send once at a time and that we block the entry function.
So I think this is actually getting into the realm of the possible. The trick is to use put a lock around Right now I am running into the issue that if I make the entire call blocking, the execution engine seems to stall and because operations on NDArray are blocking. @piiswrong do I see it right that I should build this on top of the TODO:
|
@vchuravy Yes use custom op. The others are deprecated. It's subtle. It can be either blocking or non blocking. However, if you do anything blocking in forward, you need to set the env variables such that there are more than 2 cpu/gpu worker threads |
Non blocking I would have to push a new sync point? Similar to how NVRTC is On Wed, 17 Aug 2016, 20:21 Eric Junyuan Xie, [email protected]
|
No syncing is needed from the frontend side |
Thanks to the help in #15 I managed to get past the initialization stage of _Native.
With the test_enty functions defined in src/nativeops.jl
Works without causing a seqfault 🎉
Todo:
API
I was thinking of something along the lines of