Skip to content
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

Threads.synchronize() fails tensor copy to fail #74

Open
priyaradhakrishnan0 opened this issue Sep 1, 2016 · 0 comments
Open

Threads.synchronize() fails tensor copy to fail #74

priyaradhakrishnan0 opened this issue Sep 1, 2016 · 0 comments

Comments

@priyaradhakrishnan0
Copy link

I want to copy tensors in batches of 5. I created a thread each to copy the tensor. I call Threads.synchronize() to complete the end-callback (i.e copying) before further processing. But calling Threads.synchronize() always causes copy to fail. Is there any way to ensure end-callbacks is completed without calling synchronize()??

require("nn")
local threads = require 'threads'
local nthread = 4
local njob = 10
local batch_size = 5
local contexts_batch = torch.FloatTensor(batch_size,6):zero()

local pool = threads.Threads(
nthread,
function(threadid)
print('starting a new thread/state number ' .. threadid)
end
)
local c = 1
local jobdone = 0
for j=1,20 do
if c<= batch_size then
pool:addjob(
function()
local contexts = torch.FloatTensor(6)
contexts[1] = 2
local i = 0
while i < 5 do
contexts[i+2] = 1
i = i + 1
end
print (string.format('Contexts size %d, from task %d, thread ID is %x', contexts:size()[1], i,__threadid))
return contexts
end,

     function(contexts)
        print(string.format("Ending callback : task %d finished ", j ))
        contexts_batch[c]:copy(contexts)
        jobdone = jobdone + 1
     end
  )
  c = c+1

else
--pool:synchronize() <<<<This causes error
c = 1
end
end

pool:synchronize() <<<<This does not
print(string.format('%d jobs done', jobdone))
pool:terminate()

Error 👍
Ending callback : task 1 finished
Ending callback : task 2 finished
Ending callback : task 3 finished
Ending callback : task 4 finished
Ending callback : task 5 finished
/opt/torch/install/bin/luajit: /opt/torch/install/share/lua/5.1/threads/threads.lua:255:
[thread 1 endcallback] bad argument #2 to '?' (out of range at /opt/torch/pkg/torch/generic/Tensor.c:853)
[thread 2 endcallback] bad argument #2 to '?' (out of range at /opt/torch/pkg/torch/generic/Tensor.c:853)
[thread 1 endcallback] bad argument #2 to '?' (out of range at /opt/torch/pkg/torch/generic/Tensor.c:853)
[thread 2 endcallback] bad argument #2 to '?' (out of range at /opt/torch/pkg/torch/generic/Tensor.c:853)
[thread 1 endcallback] bad argument #2 to '?' (out of range at /opt/torch/pkg/torch/generic/Tensor.c:853)
stack traceback:
[C]: in function 'error'
/opt/torch/install/share/lua/5.1/threads/threads.lua:255: in function 'synchronize'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant