From 47ef5629d8ad73aba4a262612ea4c3f537b08c17 Mon Sep 17 00:00:00 2001 From: Jonathan L Long Date: Mon, 16 Jun 2014 15:20:17 -0700 Subject: [PATCH] in Caffe::SetDevice, call cudaSetDevice before Get Otherwise initialization will be performed on whichever device is default. --- src/caffe/common.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/caffe/common.cpp b/src/caffe/common.cpp index 7edb3a4..218feb7 100644 --- a/src/caffe/common.cpp +++ b/src/caffe/common.cpp @@ -69,11 +69,13 @@ void Caffe::SetDevice(const int device_id) { if (current_device == device_id) { return; } + // The call to cudaSetDevice must come before any calls to Get, which + // may perform initialization using the GPU. + CUDA_CHECK(cudaSetDevice(device_id)); if (Get().cublas_handle_) CUBLAS_CHECK(cublasDestroy(Get().cublas_handle_)); if (Get().curand_generator_) { CURAND_CHECK(curandDestroyGenerator(Get().curand_generator_)); } - CUDA_CHECK(cudaSetDevice(device_id)); CUBLAS_CHECK(cublasCreate(&Get().cublas_handle_)); CURAND_CHECK(curandCreateGenerator(&Get().curand_generator_, CURAND_RNG_PSEUDO_DEFAULT)); -- 2.7.4