forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CPU][ARM] Add ACL executor for Convert (openvinotoolkit#17323)
* seaprate executors + add acl executor for convert * update convert * enabled tests and lot of changes in acl executor * fixed different signedness comparison * added expectedPrimitiveType method * fixed comments * fp16 WAs * enable fp16 convert tests * Revert "enable fp16 convert tests" This reverts commit 037af67. * Revert "fp16 WAs" This reverts commit 3db3d42. * fixed comments * updated expected privitive to ref * fixed comments * getDescWithType name refactoring * GetPtr to getData refactoring * GetPtr to getData refactoring --------- Co-authored-by: Aleksandr Voron <aleksandr.voron@intel.com>
- Loading branch information
Showing
15 changed files
with
778 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/plugins/intel_cpu/src/nodes/executors/acl/acl_convert.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "acl_convert.hpp" | ||
#include "acl_utils.hpp" | ||
|
||
bool ov::intel_cpu::ACLConvertExecutor::init(const ov::intel_cpu::ConvertParams& convertParams, | ||
const MemoryDescPtr& srcDesc, | ||
const MemoryDescPtr& dstDesc, | ||
const dnnl::primitive_attr& attr) { | ||
aclConvertParams = convertParams; | ||
|
||
auto srcPrecision = precisionToAclDataType(aclConvertParams.srcPrc); | ||
auto dstPrecision = precisionToAclDataType(aclConvertParams.dstPrc); | ||
isCopyOp = aclConvertParams.srcPrc == aclConvertParams.dstPrc; | ||
// NECast does not support S8. It could be replaced with QASYMM8_SIGNED | ||
if (!isCopyOp && srcPrecision == arm_compute::DataType::S8) { | ||
srcPrecision = arm_compute::DataType::QASYMM8_SIGNED; | ||
} | ||
if (!isCopyOp && dstPrecision == arm_compute::DataType::S8) { | ||
dstPrecision = arm_compute::DataType::QASYMM8_SIGNED; | ||
} | ||
auto srcDims = srcDesc->getShape().getStaticDims(); | ||
auto dstDims = dstDesc->getShape().getStaticDims(); | ||
auto srcDataLayout = getAclDataLayoutByMemoryDesc(srcDesc); | ||
auto dstDataLayout = getAclDataLayoutByMemoryDesc(dstDesc); | ||
auto srcTensorInfo = arm_compute::TensorInfo(shapeCast(srcDims), 1, srcPrecision, srcDataLayout); | ||
auto dstTensorInfo = arm_compute::TensorInfo(shapeCast(dstDims), 1, dstPrecision, dstDataLayout); | ||
if (isCopyOp) { | ||
arm_compute::Status s = arm_compute::NECopy::validate(&srcTensorInfo, &dstTensorInfo); | ||
if (!s) { | ||
DEBUG_LOG("NECopy validation failed: ", s.error_description()); | ||
return false; | ||
} | ||
} else { | ||
arm_compute::Status s = arm_compute::NECast::validate(&srcTensorInfo, &dstTensorInfo, arm_compute::ConvertPolicy::SATURATE); | ||
if (!s) { | ||
DEBUG_LOG("NECast validation failed: ", s.error_description()); | ||
return false; | ||
} | ||
} | ||
|
||
srcTensor.allocator()->init(srcTensorInfo); | ||
dstTensor.allocator()->init(dstTensorInfo); | ||
|
||
if (isCopyOp) { | ||
acl_copy = std::make_unique<arm_compute::NECopy>(); | ||
acl_copy->configure(&srcTensor, &dstTensor); | ||
} else { | ||
acl_cast = std::make_unique<arm_compute::NECast>(); | ||
acl_cast->configure(&srcTensor, &dstTensor, arm_compute::ConvertPolicy::SATURATE); | ||
} | ||
return true; | ||
} | ||
|
||
void ov::intel_cpu::ACLConvertExecutor::exec(const MemoryCPtr& src, const MemoryPtr& dst) { | ||
srcTensor.allocator()->import_memory(src->getData()); | ||
dstTensor.allocator()->import_memory(dst->getData()); | ||
|
||
if (isCopyOp) { | ||
acl_copy->run(); | ||
} else { | ||
acl_cast->run(); | ||
} | ||
|
||
srcTensor.allocator()->free(); | ||
dstTensor.allocator()->free(); | ||
} | ||
|
||
bool ov::intel_cpu::ACLConvertExecutorBuilder::isSupported(const ConvertParams& convertParams, | ||
const MemoryDescPtr& srcDesc, | ||
const MemoryDescPtr& dstDesc) const { | ||
if (convertParams.srcPrc != convertParams.dstPrc) { | ||
if (!one_of(convertParams.srcPrc, | ||
InferenceEngine::Precision::I8, | ||
InferenceEngine::Precision::U8, | ||
InferenceEngine::Precision::U16, | ||
InferenceEngine::Precision::I16, | ||
InferenceEngine::Precision::FP16, | ||
InferenceEngine::Precision::I32, | ||
InferenceEngine::Precision::FP32)) { | ||
DEBUG_LOG("NECopy does not support source precision: ", convertParams.srcPrc.name()); | ||
return false; | ||
} | ||
if ((convertParams.srcPrc == InferenceEngine::Precision::I8 && !one_of(convertParams.dstPrc, | ||
InferenceEngine::Precision::I16, | ||
InferenceEngine::Precision::I32, | ||
InferenceEngine::Precision::FP16, | ||
InferenceEngine::Precision::FP32)) || | ||
(convertParams.srcPrc == InferenceEngine::Precision::U8 && !one_of(convertParams.dstPrc, | ||
InferenceEngine::Precision::U16, | ||
InferenceEngine::Precision::I16, | ||
InferenceEngine::Precision::I32, | ||
InferenceEngine::Precision::FP16, | ||
InferenceEngine::Precision::FP32)) || | ||
(convertParams.srcPrc == InferenceEngine::Precision::U16 && !one_of(convertParams.dstPrc, | ||
InferenceEngine::Precision::U8, | ||
InferenceEngine::Precision::U32)) || | ||
(convertParams.srcPrc == InferenceEngine::Precision::I16 && !one_of(convertParams.dstPrc, | ||
InferenceEngine::Precision::I8, | ||
InferenceEngine::Precision::U8, | ||
InferenceEngine::Precision::I32)) || | ||
(convertParams.srcPrc == InferenceEngine::Precision::FP16 && !one_of(convertParams.dstPrc, | ||
InferenceEngine::Precision::I8, | ||
InferenceEngine::Precision::FP32, | ||
InferenceEngine::Precision::I32, | ||
InferenceEngine::Precision::U8)) || | ||
(convertParams.srcPrc == InferenceEngine::Precision::I32 && !one_of(convertParams.dstPrc, | ||
InferenceEngine::Precision::I8, | ||
InferenceEngine::Precision::FP16, | ||
InferenceEngine::Precision::FP32, | ||
InferenceEngine::Precision::U8)) || | ||
(convertParams.srcPrc == InferenceEngine::Precision::FP32 && !one_of(convertParams.dstPrc, | ||
InferenceEngine::Precision::BF16, | ||
InferenceEngine::Precision::FP16, | ||
InferenceEngine::Precision::I32))) { | ||
DEBUG_LOG("NECopy does not support passed combination of source and destination precisions. ", | ||
"source precision: ", convertParams.srcPrc.name(), " destination precsion: ", convertParams.dstPrc.name()); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/plugins/intel_cpu/src/nodes/executors/acl/acl_convert.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "nodes/executors/convert.hpp" | ||
#include "utils/debug_capabilities.h" | ||
#include "arm_compute/runtime/NEON/NEFunctions.h" | ||
|
||
namespace ov { | ||
namespace intel_cpu { | ||
|
||
class ACLConvertExecutor : public ConvertExecutor { | ||
public: | ||
using ConvertExecutor::ConvertExecutor; | ||
bool init(const ConvertParams& convertParams, | ||
const MemoryDescPtr& srcDesc, | ||
const MemoryDescPtr& dstDesc, | ||
const dnnl::primitive_attr &attr) override; | ||
void exec(const MemoryCPtr& src, const MemoryPtr& dst) override; | ||
impl_desc_type getImplType() const override { return implDescType; }; | ||
protected: | ||
ConvertParams aclConvertParams; | ||
bool isCopyOp; | ||
static const impl_desc_type implDescType = impl_desc_type::acl; | ||
arm_compute::Tensor srcTensor, dstTensor; | ||
std::unique_ptr<arm_compute::NECopy> acl_copy; | ||
std::unique_ptr<arm_compute::NECast> acl_cast; | ||
}; | ||
|
||
class ACLConvertExecutorBuilder : public ConvertExecutorBuilder { | ||
public: | ||
bool isSupported(const ConvertParams& convertParams, | ||
const MemoryDescPtr& srcDesc, | ||
const MemoryDescPtr& dstDesc) const override; | ||
ConvertExecutorPtr makeExecutor(const ExecutorContext::CPtr context) const override { | ||
return std::make_shared<ACLConvertExecutor>(context); | ||
} | ||
}; | ||
|
||
} // namespace intel_cpu | ||
} // namespace ov |
23 changes: 23 additions & 0 deletions
23
src/plugins/intel_cpu/src/nodes/executors/common/ref_convert.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "ref_convert.hpp" | ||
#include "nodes/common/cpu_convert.h" | ||
|
||
bool ov::intel_cpu::CommonConvertExecutor::init(const ov::intel_cpu::ConvertParams& convertParams, | ||
const MemoryDescPtr& srcDesc, | ||
const MemoryDescPtr& dstDesc, | ||
const dnnl::primitive_attr& attr) { | ||
commonConvertParams = convertParams; | ||
return true; | ||
} | ||
|
||
void ov::intel_cpu::CommonConvertExecutor::exec(const MemoryCPtr& src, const MemoryPtr& dst) { | ||
cpu_convert(src->getData(), | ||
dst->getData(), | ||
commonConvertParams.srcPrc, | ||
commonConvertParams.origPrc, | ||
commonConvertParams.dstPrc, | ||
commonConvertParams.size); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/plugins/intel_cpu/src/nodes/executors/common/ref_convert.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "nodes/executors/convert.hpp" | ||
|
||
namespace ov { | ||
namespace intel_cpu { | ||
|
||
class CommonConvertExecutor : public ConvertExecutor { | ||
public: | ||
using ConvertExecutor::ConvertExecutor; | ||
bool init(const ConvertParams& convertParams, | ||
const MemoryDescPtr& srcDesc, | ||
const MemoryDescPtr& dstDesc, | ||
const dnnl::primitive_attr &attr) override; | ||
void exec(const MemoryCPtr& src, const MemoryPtr& dst) override; | ||
impl_desc_type getImplType() const override { return implDescType; }; | ||
protected: | ||
ConvertParams commonConvertParams; | ||
static const impl_desc_type implDescType = impl_desc_type::ref; | ||
const ExecutorContext::CPtr convertContext; | ||
}; | ||
|
||
|
||
class CommonConvertExecutorBuilder : public ConvertExecutorBuilder { | ||
public: | ||
~CommonConvertExecutorBuilder() = default; | ||
bool isSupported(const ConvertParams& convertParams, | ||
const MemoryDescPtr& srcDesc, | ||
const MemoryDescPtr& dstDesc) const override { | ||
return true; | ||
} | ||
ConvertExecutorPtr makeExecutor(const ExecutorContext::CPtr context) const override { | ||
return std::make_shared<CommonConvertExecutor>(context); | ||
} | ||
}; | ||
|
||
} // namespace intel_cpu | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "convert.hpp" | ||
|
||
ov::intel_cpu::ConvertExecutor::ConvertExecutor(const ov::intel_cpu::ExecutorContext::CPtr context) : convertContext(context) {} |
Oops, something went wrong.