|
|
|
@ -103,7 +103,8 @@ inline cudnnPoolingMode_t GetPoolingMode(const PoolingMode& mode) {
|
|
|
|
|
case PoolingMode::kMaximum:
|
|
|
|
|
return CUDNN_POOLING_MAX;
|
|
|
|
|
default:
|
|
|
|
|
PADDLE_THROW("Unexpected pooling mode.");
|
|
|
|
|
PADDLE_THROW(
|
|
|
|
|
platform::errors::Unimplemented("Unexpected CUDNN pooling mode."));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
@ -119,7 +120,8 @@ inline cudnnPoolingMode_t GetPoolingMode(const PoolingMode& mode) {
|
|
|
|
|
case PoolingMode::kMaximum:
|
|
|
|
|
return CUDNN_POOLING_MAX;
|
|
|
|
|
default:
|
|
|
|
|
PADDLE_THROW("Unexpected pooling mode.");
|
|
|
|
|
PADDLE_THROW(
|
|
|
|
|
platform::errors::Unimplemented("Unexpected CUDNN pooling mode."));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif // CUDNN_VERSION < 6000
|
|
|
|
@ -140,7 +142,8 @@ inline ActivationMode StringToActivationMode(const std::string& str) {
|
|
|
|
|
} else if (str == "bandpass") {
|
|
|
|
|
return ActivationMode::kBandPass;
|
|
|
|
|
} else {
|
|
|
|
|
PADDLE_THROW("Unknown activation string: %s", str);
|
|
|
|
|
PADDLE_THROW(
|
|
|
|
|
platform::errors::Unimplemented("Unknown activation string: %s.", str));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -208,7 +211,8 @@ inline cudnnTensorFormat_t GetCudnnTensorFormat(
|
|
|
|
|
case DataLayout::kNDHWC:
|
|
|
|
|
return CUDNN_TENSOR_NHWC; // add, liyamei
|
|
|
|
|
default:
|
|
|
|
|
PADDLE_THROW("Unknown cudnn equivalent for order");
|
|
|
|
|
PADDLE_THROW(platform::errors::Unimplemented(
|
|
|
|
|
"CUDNN has no equivalent dataLayout for input order."));
|
|
|
|
|
}
|
|
|
|
|
return CUDNN_TENSOR_NCHW;
|
|
|
|
|
}
|
|
|
|
@ -329,18 +333,28 @@ class ScopedConvolutionDescriptor {
|
|
|
|
|
inline cudnnConvolutionDescriptor_t descriptor(
|
|
|
|
|
cudnnDataType_t type, const std::vector<int>& pads,
|
|
|
|
|
const std::vector<int>& strides, const std::vector<int>& dilations) {
|
|
|
|
|
PADDLE_ENFORCE_EQ(pads.size(), strides.size());
|
|
|
|
|
PADDLE_ENFORCE_EQ(pads.size(), dilations.size());
|
|
|
|
|
PADDLE_ENFORCE_EQ(pads.size(), strides.size(),
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of pads and strides should be equal. But "
|
|
|
|
|
"received size of pads is %d, size of strides is %d.",
|
|
|
|
|
pads.size(), strides.size()));
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
pads.size(), dilations.size(),
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of pads and dilations should be equal. But received size "
|
|
|
|
|
"of pads is %d, size of dilations is %d.",
|
|
|
|
|
pads.size(), dilations.size()));
|
|
|
|
|
|
|
|
|
|
#if !CUDNN_VERSION_MIN(6, 0, 0)
|
|
|
|
|
// cudnn v5 does not support dilation conv, the argument is called upscale
|
|
|
|
|
// instead of dilations and it is must be one.
|
|
|
|
|
for (size_t i = 0; i < dilations.size(); ++i) {
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
dilations[i], 1,
|
|
|
|
|
"Dilations conv is not supported in this cuDNN version(%d.%d.%d).",
|
|
|
|
|
CUDNN_VERSION / 1000, CUDNN_VERSION % 1000 / 100,
|
|
|
|
|
CUDNN_VERSION % 100);
|
|
|
|
|
PADDLE_ENFORCE_EQ(dilations[i], 1,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"Dilations conv is not supported in this cuDNN "
|
|
|
|
|
"version(%d.%d.%d).",
|
|
|
|
|
CUDNN_VERSION / 1000, CUDNN_VERSION % 1000 / 100,
|
|
|
|
|
CUDNN_VERSION % 100));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -377,8 +391,17 @@ class ScopedPoolingDescriptor {
|
|
|
|
|
const std::vector<int>& kernel,
|
|
|
|
|
const std::vector<int>& pads,
|
|
|
|
|
const std::vector<int>& strides) {
|
|
|
|
|
PADDLE_ENFORCE_EQ(kernel.size(), pads.size());
|
|
|
|
|
PADDLE_ENFORCE_EQ(kernel.size(), strides.size());
|
|
|
|
|
PADDLE_ENFORCE_EQ(kernel.size(), pads.size(),
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of kernel and pads should be equal. But "
|
|
|
|
|
"received size of kernel is %d, size of pads is %d.",
|
|
|
|
|
kernel.size(), pads.size()));
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
kernel.size(), strides.size(),
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of kernel and strides should be equal. But "
|
|
|
|
|
"received size of kernel is %d, size of strides is %d.",
|
|
|
|
|
kernel.size(), strides.size()));
|
|
|
|
|
PADDLE_ENFORCE_CUDA_SUCCESS(dynload::cudnnSetPoolingNdDescriptor(
|
|
|
|
|
desc_, (GetPoolingMode(mode)),
|
|
|
|
|
CUDNN_PROPAGATE_NAN, // Always propagate nans.
|
|
|
|
@ -456,8 +479,9 @@ class ScopedActivationDescriptor {
|
|
|
|
|
mode = CUDNN_ACTIVATION_TANH;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
PADDLE_THROW("unrecognized activation mode: %d .",
|
|
|
|
|
static_cast<int>(activation_mode));
|
|
|
|
|
PADDLE_THROW(platform::errors::Unimplemented(
|
|
|
|
|
"Unrecognized CUDNN activation mode: %d.",
|
|
|
|
|
static_cast<int>(activation_mode)));
|
|
|
|
|
}
|
|
|
|
|
PADDLE_ENFORCE_CUDA_SUCCESS(dynload::cudnnSetActivationDescriptor(
|
|
|
|
|
desc_, mode, CUDNN_NOT_PROPAGATE_NAN, relu_ceiling));
|
|
|
|
|