#ifdef USE_CUDNN #include #include "thrust/device_vector.h" #include "caffe/vision_layers.hpp" namespace caffe { template void CuDNNSoftmaxLayer::Forward_gpu(const vector*>& bottom, const vector*>& top) { const Dtype* bottom_data = bottom[0]->gpu_data(); Dtype* top_data = top[0]->mutable_gpu_data(); CUDNN_CHECK(cudnnSoftmaxForward(handle_, CUDNN_SOFTMAX_ACCURATE, CUDNN_SOFTMAX_MODE_CHANNEL, cudnn::dataType::one, bottom_desc_, bottom_data, cudnn::dataType::zero, top_desc_, top_data)); } template void CuDNNSoftmaxLayer::Backward_gpu(const vector*>& top, const vector& propagate_down, const vector*>& bottom) { if (propagate_down[0]) { const Dtype* top_data = top[0]->gpu_data(); const Dtype* top_diff = top[0]->gpu_diff(); const Dtype* bottom_data = bottom[0]->gpu_data(); Dtype* bottom_diff = bottom[0]->mutable_gpu_diff(); CUDNN_CHECK(cudnnSoftmaxBackward(handle_, CUDNN_SOFTMAX_ACCURATE, CUDNN_SOFTMAX_MODE_CHANNEL, cudnn::dataType::one, top_desc_, top_data, top_desc_, top_diff, cudnn::dataType::zero, bottom_desc_, bottom_diff)); } } INSTANTIATE_LAYER_GPU_FUNCS(CuDNNSoftmaxLayer); } // namespace caffe #endif