Created
April 1, 2015 14:49
-
-
Save culurciello/ce3b84219bb438820202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice script.