Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARM CPU] Add ACL deconvolution operation #18655

Merged
merged 45 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b950019
init deconv - draft
allnes Jun 29, 2023
46bb4ae
test commit
allnes Jul 5, 2023
ca7b8b2
save init + exec state
allnes Jul 5, 2023
5b548fc
save init + exec state : same memory
allnes Jul 5, 2023
cd2a4cc
save init + exec state : separate acl and non-acl functions
allnes Jul 5, 2023
d332e8f
save init + exec state : small refactor
allnes Jul 5, 2023
5f3fe57
first working version
allnes Jul 6, 2023
3385e50
simple refactor
allnes Jul 6, 2023
da2303e
Update CMakeLists.txt
allnes Jul 6, 2023
ec9a908
fix merge conflict
allnes Jul 10, 2023
bdb571b
an updated commit message
allnes Jul 19, 2023
9c6f24a
Update quantized_group_convolution_backprop_data.cpp
allnes Jul 19, 2023
9fe32d5
Update convolution_backprop_data.cpp
allnes Jul 19, 2023
878e8a3
update deconvolution - small fixes
allnes Jul 19, 2023
a6f5b3f
Merge branch 'master' into an/exp_deconv_1
allnes Jul 20, 2023
ce2761f
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
allnes Jul 21, 2023
5e8a179
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
allnes Jul 21, 2023
6ae8c6e
update comments
allnes Jul 21, 2023
ad95ec3
Update deconv_list.hpp
allnes Jul 21, 2023
975839a
Update deconv.cpp
allnes Jul 21, 2023
27b42aa
Update deconv.cpp
allnes Jul 21, 2023
2d27add
update comments - remove try - catch
allnes Jul 21, 2023
0d53838
Merge branch 'master' into an/exp_deconv_1
allnes Jul 24, 2023
5c89878
Update deconv.cpp
allnes Jul 24, 2023
7ef0486
Merge branch 'master' into an/exp_deconv_1
allnes Jul 24, 2023
8f0a411
python fix
allnes Jul 24, 2023
29990d8
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
allnes Jul 25, 2023
94ee091
add comments update
allnes Jul 25, 2023
94d67e7
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
allnes Jul 25, 2023
5ea9aa3
Update acl_deconv.hpp
allnes Jul 27, 2023
a8fd03d
Merge branch 'master' into an/exp_deconv_1
allnes Jul 27, 2023
ff3e12c
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
allnes Jul 28, 2023
d76f768
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
allnes Jul 28, 2023
f322131
update strides performance
allnes Jul 28, 2023
104990f
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
allnes Aug 1, 2023
49766ba
fix comments - part 1
allnes Aug 1, 2023
060890c
fix comments - part 2
allnes Aug 1, 2023
a7a7645
fix comments - final
allnes Aug 1, 2023
6524185
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
allnes Aug 1, 2023
36ec08e
fix comments - ci failed
allnes Aug 1, 2023
1019541
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
allnes Aug 2, 2023
03847d2
add changes after new comments
allnes Aug 2, 2023
efa7c76
add changes after new comments - 2
allnes Aug 2, 2023
261e3f8
fix failed test
allnes Aug 2, 2023
8982c77
fix failed test 2
allnes Aug 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Next Next commit
fix merge conflict
add api update

new update

update tests

update comments

update
  • Loading branch information
allnes committed Jul 19, 2023
commit ec9a9084af4ba8d96cf285e4542bd798b36b9f55
787 changes: 507 additions & 280 deletions src/plugins/intel_cpu/src/nodes/deconv.cpp

Large diffs are not rendered by default.

46 changes: 39 additions & 7 deletions src/plugins/intel_cpu/src/nodes/deconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <memory>
#include <string>
#include <vector>
#include "executors/deconv_list.hpp"
#include "common/dnnl_executor.h"

namespace ov {
namespace intel_cpu {
Expand All @@ -20,7 +20,6 @@ class Deconvolution : public Node {
Deconvolution(const std::shared_ptr<ngraph::Node>& op, const GraphContext::CPtr context);

void getSupportedDescriptors() override;
void initSupportedPrimitiveDescriptors() override;
void createDescriptor(const std::vector<MemoryDescPtr>& inputDesc,
const std::vector<MemoryDescPtr>& outputDesc) override;
void createPrimitive() override;
Expand All @@ -42,7 +41,7 @@ class Deconvolution : public Node {
bool canFuse(const NodePtr& node) const override;

const VectorDims& getWeightDims() const { return getInputShapeAtPort(1).getStaticDims(); }
const std::vector<ptrdiff_t>& getStride() const { return deconvAttrs.stride; }
const std::vector<ptrdiff_t>& getStride() const { return stride; }

void prepareParams() override;
void execute(dnnl::stream strm) override;
Expand All @@ -59,14 +58,46 @@ class Deconvolution : public Node {

private:
using executorPtr = std::shared_ptr<DnnlExecutor>;
std::shared_ptr<DeconvExecutor> execPtrDeconv = nullptr;

executorPtr execPtr = nullptr;

class DeconvExecutorDefault : public DnnlExecutor {
public:
DeconvExecutorDefault(const dnnl::convolution_backward_data::primitive_desc& pd,
const dnnl::memory::desc& inMemDesc,
const dnnl::memory::desc& weightMemDesc,
const dnnl::memory::desc& outMemDesc,
const dnnl::engine& engine);
};

class DeconvExecutorInt8 : public DnnlExecutor {
public:
DeconvExecutorInt8(const dnnl::deconvolution_forward::primitive_desc& pd,
const dnnl::memory::desc& inMemDesc,
const dnnl::memory::desc& weightMemDesc,
const dnnl::memory::desc& outMemDesc,
const dnnl::engine& engine);
};
// have to hold reference (shared_ptr) to forward convolution primitive_desc
// since backward one uses the reference to it as a hint
std::vector<dnnl::convolution_forward::primitive_desc> fwdConvPD;

bool useACL = false;
DeconvAttrs deconvAttrs;
bool withGroups = false;
bool isDW = false;
bool isInt8 = false;
bool autoPad = false;
bool externOutShape = false;
size_t groupNum = 1;
size_t IC = 0;
size_t OC = 0;
std::vector<ptrdiff_t> kernel;
std::vector<ptrdiff_t> stride;
std::vector<ptrdiff_t> dilation;
ov::CoordinateDiff paddingL;
ov::CoordinateDiff paddingR;
ov::CoordinateDiff outputPadding;
std::vector<int32_t> lastOutputSpatialDims;
VectorDims int8WeightDims;
VectorDims expectedBiasDims {};

Shape inShape;

Expand All @@ -81,6 +112,7 @@ class Deconvolution : public Node {
void initPaddingR(const Shape &inShape, const Shape &outShape);
std::vector<int32_t> readOutputSpatialDims() const;
std::pair<VectorDims, VectorDims> makeDummyInOutShape();
bool withBiases = false;
size_t biasPort;

std::string errorPrefix;
Expand Down
21 changes: 8 additions & 13 deletions src/plugins/intel_cpu/src/nodes/executors/acl/acl_deconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ bool AclDeconvExecutor::init(const DeconvAttrs& deconvAttrs,
unsigned int pad_b = deconvAttrs.paddingR.at(0);
unsigned int stride_x = deconvAttrs.stride.at(1);
unsigned int stride_y = deconvAttrs.stride.at(0);
unsigned int dilation_x = deconvAttrs.dilation.at(1) + 1;
unsigned int dilation_y = deconvAttrs.dilation.at(0) + 1;

arm_compute::PadStrideInfo deconv_info(stride_x, stride_y, pad_l, pad_r, pad_t, pad_b, arm_compute::DimensionRoundingType::FLOOR);
arm_compute::Size2D dilation(dilation_x, dilation_y);

arm_compute::Status status = arm_compute::NEDeconvolutionLayer::validate(&srcTensorInfo,
&weiTensorInfo,
deconvAttrs.withBiases ? &biasTensorInfo : nullptr,
&dstTensorInfo,
deconv_info);
&weiTensorInfo,
deconvAttrs.withBiases ? &biasTensorInfo : nullptr,
&dstTensorInfo,
deconv_info);
if (!status) {
DEBUG_LOG("NEDeconvolutionLayer validation failed: ", status.error_description());
return false;
Expand All @@ -77,7 +73,7 @@ bool AclDeconvExecutor::init(const DeconvAttrs& deconvAttrs,
}

static void transpose_to_1023(const MemoryCPtr& srcMemPtr, std::vector<float>& dst_data) {
const auto src_data = reinterpret_cast<float*>(srcMemPtr->GetPtr());
const auto src_data = reinterpret_cast<float*>(srcMemPtr->getData());

const int DIM0 = srcMemPtr->getStaticDims()[0];
const int DIM1 = srcMemPtr->getStaticDims()[1];
Expand Down Expand Up @@ -109,12 +105,11 @@ void AclDeconvExecutor::exec(const std::vector<MemoryCPtr>& src, const std::vect
src[1]->getStaticDims()[3]);
transpose_to_1023(src[1], weiBuffer);

srcTensor.allocator()->import_memory(src[0]->GetPtr());
dstTensor.allocator()->import_memory(dst[0]->GetPtr());
srcTensor.allocator()->import_memory(src[0]->getData());
dstTensor.allocator()->import_memory(dst[0]->getData());
weiTensor.allocator()->import_memory(weiBuffer.data());
if (deconvAttrs.withBiases)
biasTensor.allocator()->import_memory(src[2]->GetPtr());

biasTensor.allocator()->import_memory(src[2]->getData());
deconv->run();

srcTensor.allocator()->free();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ class AclDeconvExecutorBuilder : public DeconvExecutorBuilder {
" dst[0]=", dstDescs[0]->getPrecision());
return false;
}
if ((srcDescs[0]->getPrecision() != InferenceEngine::Precision::FP32 &&
srcDescs[1]->getPrecision() != InferenceEngine::Precision::FP32 &&
dstDescs[0]->getPrecision() != InferenceEngine::Precision::FP32) &&
(srcDescs[0]->getPrecision() != InferenceEngine::Precision::FP16 &&
srcDescs[1]->getPrecision() != InferenceEngine::Precision::FP16 &&
dstDescs[0]->getPrecision() != InferenceEngine::Precision::FP16)) {
if (!(one_of(srcDescs[0]->getPrecision(), InferenceEngine::Precision::FP16, InferenceEngine::Precision::FP32) &&
srcDescs[0]->getPrecision() == srcDescs[1]->getPrecision() &&
srcDescs[1]->getPrecision() == dstDescs[0]->getPrecision())) {
DEBUG_LOG("AclDeconvExecutor does not support precisions:",
" src[0]=", srcDescs[0]->getPrecision(),
" src[1]=", srcDescs[1]->getPrecision(),
Expand Down
87 changes: 46 additions & 41 deletions src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_deconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
namespace ov {
namespace intel_cpu {

DefaultDeconvDescs createDescriptorInternalDefault(const dnnl::memory::desc& in_candidate,
const dnnl::memory::desc& wgh_candidate,
const dnnl::memory::desc& out_candidate,
namespace {
DefaultDeconvDescs createDescriptorInternalDefault(const dnnl::memory::desc &in_candidate,
const dnnl::memory::desc &wgh_candidate,
const dnnl::memory::desc &out_candidate,
const dnnl::algorithm alg,
const std::vector<ptrdiff_t>& stride,
const std::vector<ptrdiff_t>& dilation,
const ov::CoordinateDiff& paddingL,
const ov::CoordinateDiff& paddingR,
const dnnl::primitive_attr& attr,
const dnnl::engine& engine) {
auto convertDims = [] (const std::vector<ptrdiff_t>& orig_dims) {
const std::vector<ptrdiff_t> &stride,
const std::vector<ptrdiff_t> &dilation,
const ov::CoordinateDiff &paddingL,
const ov::CoordinateDiff &paddingR,
const dnnl::primitive_attr &attr,
const dnnl::engine &engine) {
auto convertDims = [](const std::vector<ptrdiff_t> &orig_dims) {
return dnnl::memory::dims(orig_dims.begin(), orig_dims.end());
};

Expand Down Expand Up @@ -60,18 +61,18 @@ DefaultDeconvDescs createDescriptorInternalDefault(const dnnl::memory::desc& in_
return {deconv_desc, conv_desc};
}

dnnl::primitive_desc createDescriptorInternalInt8(const dnnl::memory::desc& in_candidate,
const dnnl::memory::desc& wgh_candidate,
const dnnl::memory::desc& bias_candidate,
const dnnl::memory::desc& out_candidate,
dnnl::primitive_desc createDescriptorInternalInt8(const dnnl::memory::desc &in_candidate,
const dnnl::memory::desc &wgh_candidate,
const dnnl::memory::desc &bias_candidate,
const dnnl::memory::desc &out_candidate,
const bool with_bias,
const std::vector<ptrdiff_t>& stride,
const std::vector<ptrdiff_t>& dilation,
const ov::CoordinateDiff& paddingL,
const ov::CoordinateDiff& paddingR,
const dnnl::primitive_attr& attr,
const dnnl::engine& engine) {
auto convertDims = [] (const std::vector<ptrdiff_t>& orig_dims) {
const std::vector<ptrdiff_t> &stride,
const std::vector<ptrdiff_t> &dilation,
const ov::CoordinateDiff &paddingL,
const ov::CoordinateDiff &paddingR,
const dnnl::primitive_attr &attr,
const dnnl::engine &engine) {
auto convertDims = [](const std::vector<ptrdiff_t> &orig_dims) {
return dnnl::memory::dims(orig_dims.begin(), orig_dims.end());
};

Expand All @@ -96,42 +97,46 @@ dnnl::primitive_desc createDescriptorInternalInt8(const dnnl::memory::desc& in_c
}
}

DefaultDeconvDescs createDefaultMkldnnDeconvDesc(const dnnl::memory::desc& srcDesc,
const dnnl::memory::desc& wghDesc,
const dnnl::memory::desc& dstDesc,
DefaultDeconvDescs createDefaultMkldnnDeconvDesc(const dnnl::memory::desc &srcDesc,
const dnnl::memory::desc &wghDesc,
const dnnl::memory::desc &dstDesc,
bool isWinograd,
const std::vector<ptrdiff_t>& stride,
const std::vector<ptrdiff_t>& dilation,
const ov::CoordinateDiff& paddingL,
const ov::CoordinateDiff& paddingR,
const dnnl::primitive_attr& attr,
const dnnl::engine& engine) {
const std::vector<ptrdiff_t> &stride,
const std::vector<ptrdiff_t> &dilation,
const ov::CoordinateDiff &paddingL,
const ov::CoordinateDiff &paddingR,
const dnnl::primitive_attr &attr,
const dnnl::engine &engine) {
dnnl::algorithm alg = isWinograd ? dnnl::algorithm::convolution_winograd : dnnl::algorithm::convolution_direct;
dnnl::convolution_backward_data::primitive_desc deconv_desc;
dnnl::convolution_forward::primitive_desc fwd_conv_pd;
std::tie(deconv_desc, fwd_conv_pd) = createDescriptorInternalDefault(srcDesc, wghDesc, dstDesc, alg, stride, dilation, paddingL, paddingR, attr, engine);
std::tie(deconv_desc, fwd_conv_pd) = createDescriptorInternalDefault(srcDesc, wghDesc, dstDesc, alg, stride,
dilation, paddingL, paddingR, attr,
engine);
if (fwd_conv_pd.get(true) == nullptr) {
IE_THROW() << "Forward convolution primitive descriptor is nullable";
}

return {deconv_desc, fwd_conv_pd};
}

dnnl::primitive_desc createInt8MkldnnDeconvDesc(const dnnl::memory::desc& srcDesc,
const dnnl::memory::desc& wghDesc,
const dnnl::memory::desc& biasDesc,
const dnnl::memory::desc& dstDesc,
dnnl::primitive_desc createInt8MkldnnDeconvDesc(const dnnl::memory::desc &srcDesc,
const dnnl::memory::desc &wghDesc,
const dnnl::memory::desc &biasDesc,
const dnnl::memory::desc &dstDesc,
const bool withBias,
const std::vector<ptrdiff_t>& stride,
const std::vector<ptrdiff_t>& dilation,
const ov::CoordinateDiff& paddingL,
const ov::CoordinateDiff& paddingR,
const dnnl::primitive_attr& attr,
const dnnl::engine& engine) {
const std::vector<ptrdiff_t> &stride,
const std::vector<ptrdiff_t> &dilation,
const ov::CoordinateDiff &paddingL,
const ov::CoordinateDiff &paddingR,
const dnnl::primitive_attr &attr,
const dnnl::engine &engine) {
return createDescriptorInternalInt8(
srcDesc, wghDesc, biasDesc, dstDesc, withBias, stride, dilation, paddingL, paddingR, attr, engine);
}

} // namespace

DNNLDeconvExecutor::DeconvExecutorDefault::DeconvExecutorDefault(const dnnl::convolution_backward_data::primitive_desc& pd,
const dnnl::memory::desc& inMemDesc,
const dnnl::memory::desc& weightMemDesc,
Expand Down
Loading