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

add gpu selection for opencl/cuda use #49

Merged
merged 4 commits into from
Aug 23, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion train.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cmd:option('--minLR', 0.00001, 'minimum learning rate')
cmd:option('--saturateEpoch', 20, 'epoch at which linear decayed LR will reach minLR')
cmd:option('--maxEpoch', 50, 'maximum number of epochs to run')
cmd:option('--batchSize', 10, 'mini-batch size')
cmd:option('--gpu', 0, 'Zero-indexed ID of the GPU to use; for CPU mode set --gpu = -1')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set to -1 w/ CPU? Isn't the value ignored?

Also, why use a zero-indexed ID if torch starts at one?

I'm not familiar w/ multi GPU support, so sorry if I'm missing something...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I used the code from another project and left the comment unchanged. The -1 has absolutely no effect, in fact the number is only important if you want to use GPU.

The zero-index thing is just because I like to count from zero 😁


cmd:text()
options = cmd:parse(arg)
Expand Down Expand Up @@ -55,10 +56,12 @@ local minMeanError = nil
if options.cuda then
require 'cutorch'
require 'cunn'
cutorch.setDevice(options.gpu + 1)
model:cuda()
elseif options.opencl then
require 'cltorch'
require 'clnn'
cltorch.setDevice(options.gpu + 1)
model:cl()
end

Expand Down Expand Up @@ -125,7 +128,7 @@ for epoch = 1, options.maxEpoch do

for i=1, dataset.examplesCount/options.batchSize do
collectgarbage()

print(optimState)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove that line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was for debugging, sorry. 😅

local _,tloss = optim.adam(feval, params, optimState)
err = tloss[1] -- optim returns a list

Expand Down