You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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,
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'
The text was updated successfully, but these errors were encountered:
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,
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'
The text was updated successfully, but these errors were encountered: