Skip to content
Open
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Fix std::vector undefined reference + Various debug
  • Loading branch information
Guillaume Bono committed Jul 7, 2015
commit 995b97ad97c490f8238c231732859fbf0e314ac9
25 changes: 13 additions & 12 deletions include/caffe/util/cudnn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ inline void createTensor4dDesc(cudnnTensorDescriptor_t* desc) {
}

template <typename Dtype>
inline void createTensorNdDesc(cudnnTensorDescriptor_t* desc) {
inline void createTensorDesc(cudnnTensorDescriptor_t* desc) {
CUDNN_CHECK(cudnnCreateTensorDescriptor(desc));
}

Expand All @@ -80,11 +80,11 @@ inline void setTensor4dDesc(cudnnTensorDescriptor_t* desc,

template <typename Dtype>
inline void setTensorNdDesc(cudnnTensorDescriptor_t* desc,
vector<int> shape,
vector<int> stride) {
std::vector<int> shape,
std::vector<int> stride) {
CHECK_EQ(shape.size(), stride.size()) << "Dimensions of shape and stride don't match !";
CUDNN_CHECK(cudnnSetTensorNdDescriptor(*desc, dataType<Dtype>::type,
shape.size(), shape.data(), stride.data());
shape.size(), shape.data(), stride.data()));
}

template <typename Dtype>
Expand All @@ -100,8 +100,8 @@ inline void setTensor4dDesc(cudnnTensorDescriptor_t* desc,

template <typename Dtype>
inline void setTensorNdDesc(cudnnTensorDescriptor_t* desc,
vector<int> shape) {
vector<int> stride(shape.size(), 1);
std::vector<int> shape) {
std::vector<int> stride(shape.size(), 1);
for(int i = stride.size()-2; i >= 0; --i) {
stride[i] = shape[i+1] * stride[i+1];
}
Expand All @@ -118,7 +118,7 @@ inline void createFilterDesc(cudnnFilterDescriptor_t* desc,

template <typename Dtype>
inline void createNdFilterDesc(cudnnFilterDescriptor_t* desc,
vector<int> shape) {
std::vector<int> shape) {
CUDNN_CHECK(cudnnCreateFilterDescriptor(desc));
CUDNN_CHECK(cudnnSetFilterNdDescriptor(*desc, dataType<Dtype>::type,
shape.size(), shape.data()));
Expand All @@ -140,13 +140,14 @@ inline void setConvolutionDesc(cudnnConvolutionDescriptor_t* conv,
template <typename Dtype>
inline void setNdConvolutionDesc(cudnnConvolutionDescriptor_t* conv,
cudnnTensorDescriptor_t bottom, cudnnFilterDescriptor_t filter,
vector<int> pad, vector<int> stride) {
std::vector<int> pad, std::vector<int> stride) {
int nbDims;
vector<int> shape(pad.size()+2);
cudnnGetFilterNdDescriptor(filter, shape.size(), dataType<Dtype>::type, &nbDims, shape.data());
std::vector<int> shape(pad.size()+2);
cudnnDataType_t cudnn_type;
cudnnGetFilterNdDescriptor(filter, shape.size(), &cudnn_type, &nbDims, shape.data());
CHECK_EQ(nbDims, pad.size()+2) << "Dimensions of filters and pad don't match !";
CHECK_EQ(nbDims, stride.size()+2) << "Dimensions of filters and stride don't match !";
vector<int> upscale(pad.size(), 1);
std::vector<int> upscale(pad.size(), 1);
CUDNN_CHECK(cudnnSetConvolutionNdDescriptor(*conv,
pad.size(), pad.data(), stride.data(), upscale.data(), CUDNN_CROSS_CORRELATION));
}
Expand All @@ -173,7 +174,7 @@ inline void createPoolingDesc(cudnnPoolingDescriptor_t* pool_desc,
template <typename Dtype>
inline void createNdPoolingDesc(cudnnPoolingDescriptor_t* pool_desc,
PoolingParameter_PoolMethod poolmethod, cudnnPoolingMode_t* mode,
vector<int> shape, vector<int> pad, vector<int> stride) {
std::vector<int> shape, std::vector<int> pad, std::vector<int> stride) {
CHECK_EQ(shape.size(), pad.size()) << "Dimensions of shape and pad don't match !";
CHECK_EQ(shape.size(), stride.size()) << "Dimensions of shape and stride don't match !";
switch (poolmethod) {
Expand Down
3 changes: 1 addition & 2 deletions include/caffe/vision_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ class CudnnNdConvolutionLayer : public Layer<Dtype> {

int conv_out_spatial_dim_;
int kernel_dim_;
int weight_offset_;
int output_offset_;

Blob<Dtype> bias_multiplier_;
Expand Down Expand Up @@ -529,7 +528,7 @@ class CudnnNdPoolingLayer : public Layer<Dtype> {
vector<int> stride_shape_;
vector<int> pad_shape_;
int channels_;
vector<int> shape_in_;
vector<int> input_shape_;
vector<int> pooled_shape_;
bool global_pooling_;
Blob<Dtype> rand_idx_;
Expand Down
34 changes: 18 additions & 16 deletions src/caffe/layers/cudnn_ndconv_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ void CudnnNdConvolutionLayer<Dtype>::LayerSetUp(
&& conv_param.has_pad_shape()
&& conv_param.has_stride_shape())
<< "Kernel, Pad and Stride shape are required.";
CHECK_EQ(conv_param.kernel_shape.dim_size(), conv_param.pad_shape.dim_size())
CHECK_EQ(conv_param.kernel_shape().dim_size(), conv_param.pad_shape().dim_size())
<< "Kernel and Pad shape don't match !";
CHECK_EQ(conv_param.kernel_shape.dim_size(), conv_param.stride_shape.dim_size())
CHECK_EQ(conv_param.kernel_shape().dim_size(), conv_param.stride_shape().dim_size())
<< "Kernel and Stride shape don't match !";
for(int i = 0; i < conv_param.kernel_shape.dim_size(); ++i) {
kernel_shape_.push_back(conv_param.kernel_shape.dim(i));
for(int i = 0; i < conv_param.kernel_shape().dim_size(); ++i) {
kernel_shape_.push_back(conv_param.kernel_shape().dim(i));
CHECK_GT(kernel_shape_[i], 0) << "Filter dimensions cannot be zero.";
pad_shape_.push_back(conv_param.pad_shape.dim(i));
stride_shape_.push_back(conv_param.stride_shape.dim(i));
pad_shape_.push_back(conv_param.pad_shape().dim(i));
stride_shape_.push_back(conv_param.stride_shape().dim(i));
}

// Configure output channels and groups.
Expand All @@ -50,6 +50,11 @@ void CudnnNdConvolutionLayer<Dtype>::LayerSetUp(
// - blobs_[0] holds the filter weights
// - blobs_[1] holds the biases (optional)
bias_term_ = this->layer_param_.convolution_param().bias_term();

vector<int> weight_shape(kernel_shape_);
weight_shape.insert(weight_shape.begin(), channels_ / group_);
weight_shape.insert(weight_shape.begin(), num_output_);

if (this->blobs_.size() > 0) {
LOG(INFO) << "Skipping parameter initialization";
} else {
Expand All @@ -60,10 +65,7 @@ void CudnnNdConvolutionLayer<Dtype>::LayerSetUp(
}
// Initialize and fill the weights:
// output channels x input channels per-group x kernel height x kernel width
vector<int> weight_shape(kernel_shape_);
weight_shape_.insert(weight_shape_.begin(), channels_ / group_);
weight_shape_.insert(weight_shape_.begin(), num_output_);
this->blobs_[0].reset(new Blob<Dtype>(weight_shape_));
this->blobs_[0].reset(new Blob<Dtype>(weight_shape));
shared_ptr<Filler<Dtype> > weight_filler(GetFiller<Dtype>(
this->layer_param_.convolution_param().weight_filler()));
weight_filler->Fill(this->blobs_[0].get());
Expand Down Expand Up @@ -95,8 +97,8 @@ void CudnnNdConvolutionLayer<Dtype>::LayerSetUp(
// Set the indexing parameters.
weight_shape[0] /= group_;
weight_offset_ = 1;
for(int i = 0; i < weight_shape_.size(); ++i) {
weight_offset_ *= weight_shape_[i];
for(int i = 0; i < weight_shape.size(); ++i) {
weight_offset_ *= weight_shape[i];
}
bias_offset_ = weight_shape[0];

Expand All @@ -106,10 +108,10 @@ void CudnnNdConvolutionLayer<Dtype>::LayerSetUp(
// Create tensor descriptor(s) for data and corresponding convolution(s).
for (int i = 0; i < bottom.size(); i++) {
cudnnTensorDescriptor_t bottom_desc;
cudnn::createTensorNdDesc<Dtype>(&bottom_desc);
cudnn::createTensorDesc<Dtype>(&bottom_desc);
bottom_descs_.push_back(bottom_desc);
cudnnTensorDescriptor_t top_desc;
cudnn::createTensorNdDesc<Dtype>(&top_desc);
cudnn::createTensorDesc<Dtype>(&top_desc);
top_descs_.push_back(top_desc);
cudnnConvolutionDescriptor_t conv_desc;
cudnn::createConvolutionDesc<Dtype>(&conv_desc);
Expand All @@ -118,7 +120,7 @@ void CudnnNdConvolutionLayer<Dtype>::LayerSetUp(

// Tensor descriptor for bias.
if (this->bias_term_) {
cudnn::createTensorNdDesc<Dtype>(&bias_desc_);
cudnn::createTensorDesc<Dtype>(&bias_desc_);
}

handles_setup_ = true;
Expand All @@ -136,7 +138,7 @@ void CudnnNdConvolutionLayer<Dtype>::Reshape(
<< "Inputs must have same num.";
CHECK_EQ(channels_, bottom[bottom_id]->channels())
<< "Inputs must have same channels.";
for(int i = 0; i < bottom[0]->num_axis(); ++i) {
for(int i = 0; i < bottom[0]->num_axes(); ++i) {
CHECK_EQ(input_shape_[i], bottom[bottom_id]->shape(i)) << "Inputs must have same shape.";
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/caffe/layers/cudnn_ndconv_layer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

namespace caffe {

__global__ void sync_conv_groups() { }
__global__ void sync_ndconv_groups() { }

template <typename Dtype>
void CuDNNConvolutionLayer<Dtype>::Forward_gpu(
void CudnnNdConvolutionLayer<Dtype>::Forward_gpu(
const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {
for (int i = 0; i < bottom.size(); ++i) {
const Dtype* bottom_data = bottom[i]->gpu_data();
Dtype* top_data = top[i]->mutable_gpu_data();
const Dtype* weight = this->blobs_[0]->gpu_data();

size_t workspace_limit_bytes = this->channels_*sizeof(int);
for(int i = 0; i < this->kernel_shape_.size(); ++i) {
workspace_limit_bytes *= kernel_shape_[i];
for(int j = 0; j < this->kernel_shape_.size(); ++j) {
workspace_limit_bytes *= kernel_shape_[j];
}
++workspace_limit_bytes;

Expand Down Expand Up @@ -90,12 +90,12 @@ void CuDNNConvolutionLayer<Dtype>::Forward_gpu(
// Synchronize the work across groups, each of which went into its own
// stream, by launching an empty kernel into the default (null) stream.
// NOLINT_NEXT_LINE(whitespace/operators)
sync_conv_groups<<<1, 1>>>();
sync_ndconv_groups<<<1, 1>>>();
}
}

template <typename Dtype>
void CuDNNConvolutionLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
void CudnnNdConvolutionLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
const Dtype* weight = NULL;
Dtype* weight_diff = NULL;
Expand Down Expand Up @@ -151,11 +151,11 @@ void CuDNNConvolutionLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
// Synchronize the work across groups, each of which went into its own
// stream, by launching an empty kernel into the default (null) stream.
// NOLINT_NEXT_LINE(whitespace/operators)
sync_conv_groups<<<1, 1>>>();
sync_ndconv_groups<<<1, 1>>>();
}
}

INSTANTIATE_LAYER_GPU_FUNCS(CuDNNConvolutionLayer);
INSTANTIATE_LAYER_GPU_FUNCS(CudnnNdConvolutionLayer);

} // namespace caffe
#endif
32 changes: 16 additions & 16 deletions src/caffe/layers/cudnn_ndpooling_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ void CudnnNdPoolingLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
CHECK(pool_param.has_kernel_shape()
&& pool_param.has_pad_shape()
&& pool_param.has_stride_shape())
<< "Kernel, Pad and Stride shape required."
CHECK_EQ(pool_param.kernel_shape.dim_size(), pool_param.pad_shape.dim_size())
<< "Kernel, Pad and Stride shape required.";
CHECK_EQ(pool_param.kernel_shape().dim_size(), pool_param.pad_shape().dim_size())
<< "Kernel and Pad shape don't match !";
CHECK_EQ(pool_param.kernel_shape.dim_size(), pool_param.stride_shape.dim_size())
CHECK_EQ(pool_param.kernel_shape().dim_size(), pool_param.stride_shape().dim_size())
<< "Kernel and Stride shape don't match !";
global_pooling_ = pool_param.global_pooling();

if(global_pooling_) {
kernel_shape_ = vector<int>(bottom[0]->shape().begin()+2, bottom->shape().end());
} else {
for(int i = 0; i < pool_param.kernel_shape.dim_size(); ++i) {
kernel_shape_.push_back(pool_param.kernel_shape.dim(i));
kernel_shape_ = vector<int>(bottom[0]->shape().begin()+2, bottom[0]->shape().end());
} else {
for(int i = 0; i < pool_param.kernel_shape().dim_size(); ++i) {
kernel_shape_.push_back(pool_param.kernel_shape().dim(i));
CHECK_GT(kernel_shape_[i], 0) << "Filter dimensions cannot be zero.";
}
}
for(int i = 0; i < pool_param.kernel_shape.dim_size(); ++i) {
pad_shape_.push_back(pool_param.pad_shape.dim(i));
stride_shape_.push_back(pool_param.stride_shape.dim(i));
for(int i = 0; i < pool_param.kernel_shape().dim_size(); ++i) {
pad_shape_.push_back(pool_param.pad_shape().dim(i));
stride_shape_.push_back(pool_param.stride_shape().dim(i));
}

CUDNN_CHECK(cudnnCreate(&handle_));
cudnn::createTensorNdDesc<Dtype>(&bottom_desc_);
cudnn::createTensorNdDesc<Dtype>(&top_desc_);
cudnn::createPoolingNdDesc<Dtype>(&pooling_desc_,
layer_param_.pooling_param().pool(), &mode_,
cudnn::createTensorDesc<Dtype>(&bottom_desc_);
cudnn::createTensorDesc<Dtype>(&top_desc_);
cudnn::createNdPoolingDesc<Dtype>(&pooling_desc_,
this->layer_param_.pooling_param().pool(), &mode_,
kernel_shape_, pad_shape_, stride_shape_);
handles_setup_ = true;
}
Expand All @@ -52,7 +52,7 @@ void CudnnNdPoolingLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
channels_ = bottom[0]->channels();
input_shape_ = bottom[0]->shape();
if(global_pooling_) {
kernel_shape_ = vector<int>(bottom[0]->shape().begin()+2, bottom->shape().end());
kernel_shape_ = vector<int>(bottom[0]->shape().begin()+2, bottom[0]->shape().end());
}

pooled_shape_ = input_shape_;
Expand All @@ -62,7 +62,7 @@ void CudnnNdPoolingLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
++pooled_shape_[i];

if(pad_shape_[i-2] > 0) {
if ((pooled_shape_[i] - 1) * stride_shape_[i-2] >= input_shape_[i] + pad_shape[i-2]) {
if ((pooled_shape_[i] - 1) * stride_shape_[i-2] >= input_shape_[i] + pad_shape_[i-2]) {
--pooled_shape_[i];
}
CHECK_LT((pooled_shape_[i] - 1) * stride_shape_[i-2], input_shape_[i] + pad_shape_[i-2]);
Expand Down
6 changes: 3 additions & 3 deletions src/caffe/layers/cudnn_ndpooling_layer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace caffe {

template <typename Dtype>
void CuDNNPoolingLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
void CudnnNdPoolingLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
const Dtype* bottom_data = bottom[0]->gpu_data();
Dtype* top_data = top[0]->mutable_gpu_data();
Expand All @@ -22,7 +22,7 @@ void CuDNNPoolingLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
}

template <typename Dtype>
void CuDNNPoolingLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
void CudnnNdPoolingLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
if (!propagate_down[0]) {
return;
Expand All @@ -39,7 +39,7 @@ void CuDNNPoolingLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
bottom_desc_, bottom_diff));
}

INSTANTIATE_LAYER_GPU_FUNCS(CuDNNPoolingLayer);
INSTANTIATE_LAYER_GPU_FUNCS(CudnnNdPoolingLayer);

} // namespace caffe
#endif