caffe common cpp: fixed an embarassing bug
authorYangqing Jia <jiayq84@gmail.com>
Mon, 28 Oct 2013 23:18:07 +0000 (16:18 -0700)
committerYangqing Jia <jiayq84@gmail.com>
Mon, 28 Oct 2013 23:18:07 +0000 (16:18 -0700)
src/caffe/common.cpp

index 1fce86a..46d21c9 100644 (file)
@@ -49,11 +49,11 @@ Caffe::Caffe()
 }
 
 Caffe::~Caffe() {
-  if (!cublas_handle_) CUBLAS_CHECK(cublasDestroy(cublas_handle_));
-  if (!curand_generator_) {
+  if (cublas_handle_) CUBLAS_CHECK(cublasDestroy(cublas_handle_));
+  if (curand_generator_) {
     CURAND_CHECK(curandDestroyGenerator(curand_generator_));
   }
-  if (!vsl_stream_) VSL_CHECK(vslDeleteStream(&vsl_stream_));
+  if (vsl_stream_) VSL_CHECK(vslDeleteStream(&vsl_stream_));
 };
 
 void Caffe::set_random_seed(const unsigned int seed) {
@@ -77,7 +77,10 @@ void Caffe::set_random_seed(const unsigned int seed) {
 void Caffe::DeviceQuery() {
   cudaDeviceProp prop;
   int device;
-  CUDA_CHECK(cudaGetDevice(&device));
+  if (cudaSuccess != cudaGetDevice(&device)) {
+    printf("No cuda device present.\n");
+    return;
+  }
   CUDA_CHECK(cudaGetDeviceProperties(&prop, device));
   printf("Major revision number:         %d\n", prop.major);
   printf("Minor revision number:         %d\n", prop.minor);