BVLC/caffe — pull request #507 by longjon (2014-06-16 22:28:47+00:00)
Title: Fix Caffe::SetDevice to avoid initializing on default device

This PR addresses #440 by moving the call to `cudaSetDevice` before any calls to `Get`, which may perform GPU memory allocation.

Despite what is written in #440, this _can_ be used in Python without any further changes, provided (somewhat counterintuitively) one calls `Net.set_device` before `Net.set_mode_gpu`.

AFAICT there is no need for the `cu*Destroy` cleanup to come before `cudaSetDevice`; let me know if you think otherwise.