Skip to content

Commit

Permalink
use tasks to handle forward and backward
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Dec 13, 2015
1 parent 22c1ecb commit b729dd4
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/nativeops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,45 @@ immutable NativeOpInfo
c_wrapper_infer = cfunction(_wrapper_infer, Void, (Cint, Ptr{Cint}, Ptr{Ptr{Cuint}}, Ptr{Void}))
const c_wrapper_list = cfunction(_wrapper_list, Void, (Ptr{Ptr{Ptr{Cchar}}}, Ptr{Void}))

p_f = pointer_from_objref(forward)
p_b = pointer_from_objref(backwards)
cond_forward = Condition()
cond_backward = Condition()
cb_f = Base.SingleAsyncWork(data -> notify(cond_forward))
cb_b = Base.SingleAsyncWork(data -> notify(cond_backward))

r_forward = Ref(_FB(cb_f.handle))
r_backward = Ref(_FB(cb_f.handle))

p_f = convert(Ptr{Void}, r_forward)
p_f = convert(Ptr{Void}, r_backward)

@schedule begin
try
while true
wait(cond_forward)
cond_forward = Condition()
_entry_forward(r_forward[])
end
catch
rethrow()
finally
Base.close(cb_f)
end
end

@schedule begin
try
while true
wait(cond_backward)
cond_backward = Condition()
_entry_backward(r_backward[])
end
catch
rethrow()
finally
Base.close(cb_f)
end
end

new(c_wrapper_fb, c_wrapper_fb, c_wrapper_infer, c_wrapper_list,
c_wrapper_list, p_f, p_b, p_is, p_lo, p_la)
end
Expand Down Expand Up @@ -105,7 +142,7 @@ immutable _FB
shapes :: Ptr{Ptr{Cuint}}
tags :: Ptr{Cint}
end

_FB(handle :: Ptr{Void}) = _FP(handle, 0, 0, 0, 0, 0)
@assert isbits(_FB)

function _wrapper_fb(size :: Cint, data :: Ptr{Ptr{Cfloat}}, ndims :: Ptr{Cint}, shapes :: Ptr{Ptr{Cuint}}, tags :: Ptr{Cint}, payload :: Ptr{Void})
Expand Down

0 comments on commit b729dd4

Please sign in to comment.