Skip to content

Instantly share code, notes, and snippets.

@culurciello
Created April 1, 2015 14:49
Show Gist options
  • Save culurciello/ce3b84219bb438820202 to your computer and use it in GitHub Desktop.
Save culurciello/ce3b84219bb438820202 to your computer and use it in GitHub Desktop.
-- net cpu/gpu speed test
-- E. Culurciello, March 2015
require 'nn'
require('cunn')
torch.setdefaulttensortype('torch.FloatTensor')
net = torch.load('../../models/home-A1l/model.net')
net_gpu = torch.load('../../models/home-A1l/model.net')
net_gpu:cuda()
local batches = {1,2,4,8,16,32,64,128}
for i=1,#batches do
local batch = batches[i]
print('\nBatch size', batch)
img = torch.FloatTensor(batch,3,231,231)
timer = torch.Timer()
timer:reset()
net:forward(img)
t_cpu = timer:time().real
print('CPU test; batch = ', batch, 'time', t_cpu, 'time/batch:', t_cpu/batch)
timer:reset()
img_cuda = img:cuda()
net_gpu:forward(img_cuda)
cutorch.synchronize()
t_gpu = timer:time().real
print('GPU test; batch = ', batch, 'time', t_gpu, 'time/batch:', t_gpu/batch)
print('GPU speedup', t_cpu/t_gpu)
end
@Atcold
Copy link

Atcold commented Apr 1, 2015

Nice script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment