Skip to content

Instantly share code, notes, and snippets.

@Kaixhin
Created June 6, 2016 13:14
Show Gist options
  • Save Kaixhin/68ffc5a2d1a69cc1556f1b2d2f1ae345 to your computer and use it in GitHub Desktop.
Save Kaixhin/68ffc5a2d1a69cc1556f1b2d2f1ae345 to your computer and use it in GitHub Desktop.
Basic Torch cuDNN example
require 'cunn'
local cudnn = require 'cudnn'
local X = torch.rand(32, 3, 24, 24):cuda()
local Y = torch.ones(32):cuda()
local net = nn.Sequential()
net:add(cudnn.SpatialConvolution(3, 8, 5, 5))
net:add(nn.View(8*20*20))
net:add(nn.Linear(8*20*20, 10))
net:add(nn.LogSoftMax())
net:cuda()
local criterion = nn.ClassNLLCriterion():cuda()
local output = net:forward(X)
local loss = criterion:forward(output, Y)
print(loss)
@karandwivedi42
Copy link

karandwivedi42 commented Jun 6, 2016

Just wondering: does this use cudnn..because cudnn.convert(net,cudnn) is not called.

@Kaixhin
Copy link
Author

Kaixhin commented Jul 10, 2016

@karandwivedi42 yes - a cudnn module is used in line 8. You can add cudnn modules manually rather than having to call cudnn.convert.

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