Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,15 @@ ifeq ($(LINUX), 1)
LIBRARIES += boost_thread stdc++
endif

CUDA_VERSION := $(shell $(CUDA_DIR)/bin/nvcc -V | grep -Eo 'release [^,]+' | cut -f2 -d' ')
ifeq ($(shell echo $(CUDA_VERSION) \< 7.0 | bc), 1)
$(error CUDA 7 is required.)
endif

# OS X:
# clang++ instead of g++
# libstdc++ for NVCC compatibility on OS X >= 10.9 with CUDA < 7.0
ifeq ($(OSX), 1)
CXX := /usr/bin/clang++
CUDA_VERSION := $(shell $(CUDA_DIR)/bin/nvcc -V | grep -o 'release \d' | grep -o '\d')
ifeq ($(shell echo $(CUDA_VERSION) \< 7.0 | bc), 1)
CXXFLAGS += -stdlib=libstdc++
LINKFLAGS += -stdlib=libstdc++
endif
# clang throws this warning for cuda headers
WARNINGS += -Wno-unneeded-internal-declaration
# gtest needs to use its own tuple to not conflict with clang
Expand Down Expand Up @@ -339,7 +338,7 @@ CXXFLAGS += -MMD -MP
# Complete build flags.
COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS) --default-stream per-thread
# mex may invoke an older gcc that is too liberal with -Wuninitalized
MATLAB_CXXFLAGS := $(CXXFLAGS) -Wno-uninitialized
LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
Expand Down
4 changes: 4 additions & 0 deletions include/caffe/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ inline Dtype Layer<Dtype>::Forward(const vector<Blob<Dtype>*>& bottom,
case Caffe::GPU:
Forward_gpu(bottom, top);
#ifndef CPU_ONLY
CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));
for (int top_id = 0; top_id < top.size(); ++top_id) {
if (!this->loss(top_id)) { continue; }
const int count = top[top_id]->count();
Expand Down Expand Up @@ -447,6 +448,9 @@ inline void Layer<Dtype>::Backward(const vector<Blob<Dtype>*>& top,
break;
case Caffe::GPU:
Backward_gpu(top, propagate_down, bottom);
#ifndef CPU_ONLY
CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));
#endif
break;
default:
LOG(FATAL) << "Unknown caffe mode.";
Expand Down
1 change: 1 addition & 0 deletions src/caffe/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Caffe::Caffe()
if (cublasCreate(&cublas_handle_) != CUBLAS_STATUS_SUCCESS) {
LOG(ERROR) << "Cannot create Cublas handle. Cublas won't be available.";
}
CUBLAS_CHECK(cublasSetStream(cublas_handle_, cudaStreamPerThread));
// Try to create a curand handler.
if (curandCreateGenerator(&curand_generator_, CURAND_RNG_PSEUDO_DEFAULT)
!= CURAND_STATUS_SUCCESS ||
Expand Down
1 change: 1 addition & 0 deletions src/caffe/layers/cudnn_pooling_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void CuDNNPoolingLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
CHECK_EQ(this->pad_h_, 0);
CHECK_EQ(this->pad_w_, 0);
CUDNN_CHECK(cudnnCreate(&handle_));
CUDNN_CHECK(cudnnSetStream(handle_, cudaStreamPerThread));
cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);
cudnn::createTensor4dDesc<Dtype>(&top_desc_);
cudnn::createPoolingDesc<Dtype>(&pooling_desc_,
Expand Down
1 change: 1 addition & 0 deletions src/caffe/layers/cudnn_relu_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void CuDNNReLULayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
ReLULayer<Dtype>::LayerSetUp(bottom, top);
// initialize cuDNN
CUDNN_CHECK(cudnnCreate(&handle_));
CUDNN_CHECK(cudnnSetStream(handle_, cudaStreamPerThread));
cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);
cudnn::createTensor4dDesc<Dtype>(&top_desc_);
handles_setup_ = true;
Expand Down
1 change: 1 addition & 0 deletions src/caffe/layers/cudnn_softmax_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void CuDNNSoftmaxLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
SoftmaxLayer<Dtype>::LayerSetUp(bottom, top);
// Initialize CUDNN.
CUDNN_CHECK(cudnnCreate(&handle_));
CUDNN_CHECK(cudnnSetStream(handle_, cudaStreamPerThread));
cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);
cudnn::createTensor4dDesc<Dtype>(&top_desc_);
handles_setup_ = true;
Expand Down