|
|
@ -210,13 +210,15 @@ class MKLDNNHandler {
|
|
|
|
dst_memory.reset(new mkldnn::memory(*dst_pd, to_void_cast<T>(output_data)));
|
|
|
|
dst_memory.reset(new mkldnn::memory(*dst_pd, to_void_cast<T>(output_data)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void AppendKey(
|
|
|
|
static void AppendKey(std::string* key,
|
|
|
|
std::string* key, const mkldnn::memory::dims& input_dims,
|
|
|
|
const mkldnn::memory::dims& input_dims,
|
|
|
|
const mkldnn::memory::dims& weights_dims, const std::vector<int>& strides,
|
|
|
|
const mkldnn::memory::dims& weights_dims,
|
|
|
|
const std::vector<int>& paddings, const std::vector<int>& dilations,
|
|
|
|
const std::vector<int>& strides,
|
|
|
|
const int& groups, const mkldnn::memory::data_type& srcdt,
|
|
|
|
const std::vector<int>& paddings,
|
|
|
|
const mkldnn::memory::format& format,
|
|
|
|
const std::vector<int>& dilations, const int& groups,
|
|
|
|
const mkldnn::memory::data_type& dstdt, const std::string& suffix) {
|
|
|
|
const mkldnn::memory::data_type& srcdt,
|
|
|
|
|
|
|
|
const mkldnn::memory::format& format, const bool& relu,
|
|
|
|
|
|
|
|
const bool& residual, const std::string& suffix) {
|
|
|
|
AppendKeyDims(key, input_dims);
|
|
|
|
AppendKeyDims(key, input_dims);
|
|
|
|
AppendKeyDims(key, weights_dims);
|
|
|
|
AppendKeyDims(key, weights_dims);
|
|
|
|
AppendKeyVec(key, strides);
|
|
|
|
AppendKeyVec(key, strides);
|
|
|
@ -225,7 +227,8 @@ class MKLDNNHandler {
|
|
|
|
AppendKey(key, std::to_string(groups));
|
|
|
|
AppendKey(key, std::to_string(groups));
|
|
|
|
AppendKey(key, std::to_string(srcdt));
|
|
|
|
AppendKey(key, std::to_string(srcdt));
|
|
|
|
AppendKey(key, std::to_string(format));
|
|
|
|
AppendKey(key, std::to_string(format));
|
|
|
|
AppendKey(key, std::to_string(dstdt));
|
|
|
|
AppendKey(key, std::to_string(relu));
|
|
|
|
|
|
|
|
AppendKey(key, std::to_string(residual));
|
|
|
|
AppendKey(key, suffix);
|
|
|
|
AppendKey(key, suffix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -664,15 +667,35 @@ static std::shared_ptr<mkldnn::memory> SetDstMemory(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
static std::shared_ptr<mkldnn::memory> SetDstMemoryHandler(
|
|
|
|
static std::shared_ptr<mkldnn::memory> SetDstMemory(
|
|
|
|
const framework::ExecutionContext& ctx, framework::Tensor* output,
|
|
|
|
const framework::ExecutionContext& ctx, framework::Tensor* output,
|
|
|
|
const std::shared_ptr<ConvMKLDNNHandler>& handler) {
|
|
|
|
const framework::Tensor* residual_param,
|
|
|
|
|
|
|
|
const mkldnn::memory::desc& user_residual_md,
|
|
|
|
|
|
|
|
const std::shared_ptr<ConvMKLDNNHandler>& handler,
|
|
|
|
|
|
|
|
std::vector<mkldnn::primitive>* pipeline) {
|
|
|
|
|
|
|
|
const T* residual_param_data = residual_param->data<T>();
|
|
|
|
|
|
|
|
PADDLE_ENFORCE(residual_param_data != nullptr,
|
|
|
|
|
|
|
|
"Provide data if you want MKLDNN conv+elementwise_add fusion");
|
|
|
|
|
|
|
|
std::shared_ptr<mkldnn::memory> user_residual_memory_p =
|
|
|
|
|
|
|
|
handler->AcquireResidualDataMemory(user_residual_md,
|
|
|
|
|
|
|
|
to_void_cast<T>(residual_param_data));
|
|
|
|
|
|
|
|
T* output_data = output->mutable_data<T>(ctx.GetPlace());
|
|
|
|
|
|
|
|
std::shared_ptr<mkldnn::memory> dst_memory_p =
|
|
|
|
|
|
|
|
handler->AcquireDstMemoryFromResidualDataMemory(
|
|
|
|
|
|
|
|
user_residual_memory_p, to_void_cast<T>(output_data), *pipeline);
|
|
|
|
|
|
|
|
return dst_memory_p;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
|
|
|
static void SetDstMemoryHandler(
|
|
|
|
|
|
|
|
const framework::ExecutionContext& ctx, framework::Tensor* output,
|
|
|
|
|
|
|
|
const std::shared_ptr<ConvMKLDNNHandler>& handler,
|
|
|
|
|
|
|
|
std::shared_ptr<mkldnn::memory>* dst_memory_p) {
|
|
|
|
T* output_data = output->mutable_data<T>(
|
|
|
|
T* output_data = output->mutable_data<T>(
|
|
|
|
ctx.GetPlace(), ::paddle::memory::Allocator::kDefault,
|
|
|
|
ctx.GetPlace(), ::paddle::memory::Allocator::kDefault,
|
|
|
|
handler->GetDstMemorySize());
|
|
|
|
handler->GetDstMemorySize());
|
|
|
|
std::shared_ptr<mkldnn::memory> dst_memory_p;
|
|
|
|
(*dst_memory_p)->set_data_handle(to_void_cast<T>(output_data));
|
|
|
|
dst_memory_p->set_data_handle(to_void_cast<T>(output_data));
|
|
|
|
|
|
|
|
return dst_memory_p;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace platform
|
|
|
|
} // namespace platform
|
|
|
|
} // namespace paddle
|
|
|
|
} // namespace paddle
|
|
|
|