Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CPU][ACL] Refactor weights packaging in ACL FC executor (#27065)

Aleksandr Voron2f3a93e4fb50
diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_common_executor.cpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_common_executor.cpp
index 5779147a5b3..646cf47c1bc 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_common_executor.cpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_common_executor.cpp
@@ -83,7 +83,6 @@ bool ACLCommonExecutor::update(const MemoryArgs &memory) {
updateTensorsShapes(aclMemoryShapes);
// Initialize arm_compute::TensorInfo objects
- ACLInfos aclMemoryInfos;
for (int i = 0; i < ACLArgs::COUNT_OF_ARGS; i++) {
aclMemoryInfos[i] = initTensorInfo(aclMemoryShapes[i], aclDataType[i], aclDataLayout[i]);
}
diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_common_executor.hpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_common_executor.hpp
index 854130d6f88..1a5a00c7a85 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_common_executor.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_common_executor.hpp
@@ -43,12 +43,16 @@ public:
}
void execute(const MemoryArgs& memory) override;
bool update(const MemoryArgs& memory) override;
+ arm_compute::TensorInfo& getTensorInfo(ACLArgs index) {
+ return *aclMemoryInfos[index].get();
+ }
~ACLCommonExecutor();
protected:
ACLTensorAttrs aclTensorAttrs;
private:
ACLTensors aclMemoryTensors;
+ ACLInfos aclMemoryInfos;
ACLFunction iFunction = nullptr;
};
diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.cpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.cpp
index 6f464abf33d..cc42691950a 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.cpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.cpp
@@ -2,6 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include <cpu/acl/acl_utils.hpp>
+#include <common/primitive_desc_iface.hpp>
+
+#include "ov_optional.hpp"
#include "acl_fullyconnected.hpp"
#include "acl_utils.hpp"
#include "nodes/executors/executor.hpp"
@@ -9,7 +13,10 @@
#include "utils/debug_capabilities.h"
#include "nodes/executors/debug_messages.hpp"
#include "nodes/executors/implementation_utils.hpp"
+#include "nodes/convert.h"
#include "nodes/common/cpu_convert.h"
+#include "nodes/common/cpu_memcpy.h"
+#include "nodes/common/reorder_prim.h"
#include "memory_desc/cpu_memory_desc_utils.h"
namespace ov {
@@ -46,104 +53,133 @@ static VectorDims makeDummyOutputDims(const VectorDims& inShape, const VectorDim
return outputShape;
}
-static MemoryPtr prepareWeightMemory(const MemoryArgs &memory,
- const ExecutorContext::CPtr context,
- const FCAttrs &attrs,
- const ACLFCAttrs& aclfcAttrs,
- const PostOps &postOps) {
- DEBUG_LOG("ACLFullyConnectedExecutor: prepack weights");
- const auto& wgtDims = memory.at(ARG_WEI)->getStaticDims();
- const auto N = wgtDims[0];
- const auto K = wgtDims[1];
+static DnnlMemoryDescPtr makeTransposedWeightDescriptor(const DnnlMemoryDescPtr srcDesc,
+ const DnnlMemoryDescPtr dstDesc) {
+ const auto& weiDesc = srcDesc->getDnnlDesc();
+ const auto reorderedWeiDesc = dnnl::memory::desc{weiDesc.get_dims(), weiDesc.get_data_type(), dnnl::memory::format_tag::ba};
+ const auto transposedWeiDesc = reorderedWeiDesc.reshape(dstDesc->getDnnlDesc().get_dims());
- auto create = [&]() {
- MemoryPtr final_ptr = memory.at(ARG_WEI);
- // Convert weights precision
- if (aclfcAttrs.isConvertedWeights) {
- MemoryArgs memoryArgs;
- memoryArgs[ARG_SRC_0] = memory.at(ARG_WEI);
- memoryArgs[ARG_DST] = std::make_shared<Memory>(context->getEngine(),
- memoryArgs[ARG_SRC_0]->getDescPtr()->cloneWithNewPrecision(
- aclfcAttrs.inputPrecision));
- auto aclWeightsConverter = std::make_shared<acl_fc_executor::ACLWeightsConverter>();
- if (aclWeightsConverter->update(memoryArgs)) {
- aclWeightsConverter->execute(memoryArgs);
- } else {
- auto count_wei_elem = std::accumulate(memoryArgs[ARG_SRC_0]->getStaticDims().begin(),
- memoryArgs[ARG_SRC_0]->getStaticDims().end(),
- 1,
- std::multiplies<>());
- cpu_convert(memoryArgs[ARG_SRC_0]->getData(),
- memoryArgs[ARG_DST]->getData(),
- memoryArgs[ARG_SRC_0]->getPrecision(),
- memoryArgs[ARG_DST]->getPrecision(),
- count_wei_elem);
- }
- final_ptr = memoryArgs[ARG_DST];
+ return DnnlExtensionUtils::makeDescriptor(transposedWeiDesc);
+}
+
+static ov::optional<MemoryPtr> convertWeightPrecision(MemoryPtr input, MemoryPtr output, ov::element::Type weightPrecision) {
+ MemoryArgs memoryArgs;
+ memoryArgs[ARG_SRC] = input;
+ memoryArgs[ARG_DST] = output;
+
+ auto aclWeightsConverter = std::make_shared<acl_fc_executor::ACLWeightsConverter>();
+ if (aclWeightsConverter->update(memoryArgs)) {
+ aclWeightsConverter->execute(memoryArgs);
+ return ov::optional<MemoryPtr>(memoryArgs.at(ARG_DST));
+ }
+
+ if (!node::Convert::isSupportedDesc(input->getDesc()) ||
+ !node::Convert::isSupportedDesc(output->getDesc())) {
+ return {};
+ }
+
+ auto data = static_cast<const uint8_t *>(input->getData());
+ std::vector<uint8_t> tmpBuff;
+ tmpBuff.resize(output->getSize());
+ cpu_convert(data, tmpBuff.data(), DnnlExtensionUtils::DataTypeToElementType(input->getDataType()),
+ weightPrecision, input->getSize() / input->getDesc().getPrecision().size());
+
+ return ov::optional<MemoryPtr>(std::make_shared<Memory>(output->getPrimitive().get_engine(),
+ output->getDesc().cloneWithNewPrecision(weightPrecision),
+ tmpBuff.data()));
+}
+
+static ov::optional<MemoryPtr> reorderDataFallback(MemoryPtr input, MemoryPtr output, ExecutorContext::CPtr context) {
+ if (output->getDataType() == input->getDataType()) {
+ return {};
+ }
+ const auto inPrc = DnnlExtensionUtils::DataTypeToElementType(input->getDataType());
+ auto convertedDstMemoryDesc = output->getDesc().cloneWithNewPrecision(inPrc);
+ dnnl::reorder reorderWithoutConvert = getReorderPrim(context->getRuntimeCache(),
+ output->getPrimitive().get_engine(),
+ input->getPrimitive().get_desc(),
+ MemoryDescUtils::convertToDnnlMemoryDesc(convertedDstMemoryDesc)->getDnnlDesc());
+
+ if (reorderWithoutConvert && parse_impl_name(reorderWithoutConvert.get_primitive_desc()->impl()->name()) != ref_any) {
+ auto convertOutput = convertWeightPrecision(input, output, inPrc);
+ if (!convertOutput) {
+ return {};
+ }
+ input = *convertOutput;
+
+ if (reorderWithoutConvert) {
+ dnnl::stream loc_stream(output->getPrimitive().get_engine(), dnnl::stream::flags::in_order);
+ reorderWithoutConvert.execute(loc_stream, {{DNNL_ARG_FROM, input->getPrimitive()}, {DNNL_ARG_TO, output->getPrimitive()}});
+ return ov::optional<MemoryPtr>(output);
}
- // Packed weights
- {
- arm_compute::WeightFormat expectedWeightFormat;
- bool isNeededReorder;
- {
- MemoryArgs memoryArgs;
- memoryArgs[ARG_BIAS] = memory.at(ARG_BIAS);
- memoryArgs[ARG_WEI] = final_ptr;
- if (memory.at(ARG_SRC_0)->getShape().isDynamic()) {
- const auto& inShape = memory.at(ARG_SRC_0)->getShape();
- const auto& wShape = final_ptr->getShape();
- const auto& inDymmyDims = makeDummyInputDims(inShape, wShape);
- const auto& outDymmyDims = makeDummyOutputDims(inDymmyDims, wShape.getStaticDims(), memory.at(ARG_DST)->getShape().getRank());
- memoryArgs[ARG_SRC_0] = std::make_shared<Memory>(context->getEngine(),
- memory.at(ARG_SRC_0)->getDescPtr()->cloneWithNewDims(inDymmyDims));
- memoryArgs[ARG_DST] = std::make_shared<Memory>(context->getEngine(),
- memory.at(ARG_DST)->getDescPtr()->cloneWithNewDims(outDymmyDims));
- } else {
- memoryArgs[ARG_SRC_0] = memory.at(ARG_SRC_0);
- memoryArgs[ARG_DST] = memory.at(ARG_DST);
- }
- auto aclWeightsRepack = std::make_shared<acl_fc_executor::ACLWeightFormatGenerator>(attrs, postOps, memoryArgs);
- isNeededReorder = aclWeightsRepack->update(memoryArgs);
- expectedWeightFormat = aclWeightsRepack->getOptImplWeightFormat();
- }
- if (isNeededReorder) {
- MemoryArgs memoryArgs;
- memoryArgs[ARG_SRC_0] = final_ptr;
- memoryArgs[ARG_DST] = std::make_shared<Memory>(context->getEngine(),
- memoryArgs[ARG_SRC_0]->getDescPtr()->clone());
- auto aclWeightsReorder = std::make_shared<acl_fc_executor::ACLWeightsReorder>(
- arm_compute::WeightFormat::OHWI, expectedWeightFormat);
- if (aclWeightsReorder->update(memoryArgs)) {
- aclWeightsReorder->execute(memoryArgs);
- final_ptr = memoryArgs[ARG_DST];
- }
- }
+ }
+ return {};
+}
+
+static MemoryPtr reorderData(DnnlMemoryDescPtr srcWeightDesc,
+ DnnlMemoryDescPtr dstWeightDesc,
+ MemoryCPtr weightsMem,
+ ExecutorContext::CPtr context) {
+ MemoryPtr input = std::make_shared<Memory>(context->getEngine(), srcWeightDesc, weightsMem->getData());
+ MemoryPtr output = std::make_shared<Memory>(context->getEngine(), dstWeightDesc);
+ if (!input->getDesc().isDefined() || !output->getDesc().isDefined())
+ OPENVINO_THROW("Can't reorder data with dynamic shapes");
+
+ if (input->getShape().hasZeroDims() || output->getShape().hasZeroDims()) {
+ return output;
+ }
+
+ if (input->getDesc().isCompatible(output->getDesc())) {
+ auto srcPtr = static_cast<uint8_t*>(input->getData());
+ auto dstPtr = static_cast<uint8_t*>(output->getData());
+ auto copySize = output->getSize();
+ cpu_memcpy(dstPtr, srcPtr, copySize);
+ return output;
+ }
+
+ // try directly reorder
+ auto engine = output->getPrimitive().get_engine();
+ dnnl::reorder directReorder = getReorderPrim(context->getRuntimeCache(),
+ engine,
+ input->getPrimitive().get_desc(),
+ output->getPrimitive().get_desc());
+
+ if (!directReorder || parse_impl_name(directReorder.get_primitive_desc()->impl()->name()) == ref_any) {
+ // try precision conversion then do the reorder
+ auto fallbackOutput = reorderDataFallback(input, output, context);
+ if (fallbackOutput) {
+ return *fallbackOutput;
}
- // Transpose weights
- if (!aclfcAttrs.weightsNonTransposed) {
- auto reverse_weights_dims = memory.at(ARG_WEI)->getStaticDims();
- if (reverse_weights_dims.size() == 3) {
- reverse_weights_dims = VectorDims(
- {reverse_weights_dims[0] * reverse_weights_dims[1], reverse_weights_dims[2]});
- }
- std::reverse(reverse_weights_dims.begin(), reverse_weights_dims.end());
- MemoryArgs memoryArgs;
- memoryArgs[ARG_SRC_0] = final_ptr;
- memoryArgs[ARG_DST] = std::make_shared<Memory>(context->getEngine(),
- CpuBlockedMemoryDesc(final_ptr->getPrecision(),
- intel_cpu::Shape(reverse_weights_dims)));
- auto aclWeightsTranspose = std::make_shared<acl_fc_executor::ACLWeightsTranspose>();
- if (aclWeightsTranspose->update(memoryArgs)) {
- aclWeightsTranspose->execute(memoryArgs);
- final_ptr = memoryArgs[ARG_DST];
- }
+ }
+ // if precision conversion does not work then do direct reference reorder
+ if (directReorder) {
+ dnnl::stream loc_stream(engine, dnnl::stream::flags::in_order);
+ directReorder.execute(loc_stream, {{DNNL_ARG_FROM, input->getPrimitive()}, {DNNL_ARG_TO, output->getPrimitive()}});
+ } else {
+ OPENVINO_THROW("Could not make onednn reorder.");
+ }
+ return output;
+}
+
+static MemoryPtr reorderWeights(const MemoryArgs &memory,
+ const ExecutorContext::CPtr context,
+ ACLFCAttrs& aclfcAttrs,
+ DnnlMemoryDescPtr dnnlSrcDesc,
+ DnnlMemoryDescPtr dnnlDstDesc) {
+ auto create = [&]() {
+ MemoryPtr weightsMemory = memory.at(ARG_WEI);
+ if (aclfcAttrs.isWeightsRepacked || aclfcAttrs.isConvertedWeights) {
+ weightsMemory = reorderData(dnnlSrcDesc, dnnlDstDesc, memory.at(ARG_WEI), context);
+ DEBUG_LOG("ACLFullyConnectedExecutor: cache miss, perform packing");
}
- DEBUG_LOG("ACLFullyConnectedExecutor: cache miss, perform packing");
- return final_ptr;
+ return weightsMemory;
};
auto weightCache = context->getWeightsCache();
if (weightCache != nullptr) {
+ const auto& wgtDims = memory.at(ARG_WEI)->getStaticDims();
+ const auto N = wgtDims[0];
+ const auto K = wgtDims[1];
std::string format = "fc_acl_" + std::to_string(N) + "_" + std::to_string(K);
const std::string string_hash = format + "_" + std::to_string(memory.at(ARG_WEI)->getSize()) + "_" +
std::to_string(reinterpret_cast<uint64_t>(memory.at(ARG_WEI)->getData()));
@@ -155,6 +191,63 @@ static MemoryPtr prepareWeightMemory(const MemoryArgs &memory,
return create();
}
+static MemoryPtr prepareWeightMemory(const MemoryArgs &memory,
+ const ExecutorContext::CPtr context,
+ const FCAttrs &attrs,
+ ACLFCAttrs& aclfcAttrs,
+ const PostOps &postOps,
+ arm_compute::WeightFormat& expectedWeightFormat,
+ arm_compute::TensorInfo& weiTensorInfo) {
+ MemoryArgs memoryArgs;
+ memoryArgs[ARG_BIAS] = memory.at(ARG_BIAS);
+ memoryArgs[ARG_WEI] = memory.at(ARG_WEI);
+ if (memory.at(ARG_SRC_0)->getShape().isDynamic()) {
+ const auto& inShape = memory.at(ARG_SRC_0)->getShape();
+ const auto& wShape = memory.at(ARG_WEI)->getShape();
+ const auto& inDymmyDims = makeDummyInputDims(inShape, wShape);
+ const auto& outDymmyDims = makeDummyOutputDims(inDymmyDims, wShape.getStaticDims(), memory.at(ARG_DST)->getShape().getRank());
+ memoryArgs[ARG_SRC_0] = std::make_shared<Memory>(context->getEngine(),
+ memory.at(ARG_SRC_0)->getDescPtr()->cloneWithNewDims(inDymmyDims));
+ memoryArgs[ARG_DST] = std::make_shared<Memory>(context->getEngine(),
+ memory.at(ARG_DST)->getDescPtr()->cloneWithNewDims(outDymmyDims));
+ } else {
+ memoryArgs[ARG_SRC_0] = memory.at(ARG_SRC_0);
+ memoryArgs[ARG_DST] = memory.at(ARG_DST);
+ }
+ // TODO: ACLWeightFormatGenerator should be replaced with Reorder executor
+ // that calls ACL NEReorder + NETranspose or dnnl::reorder depending on backend availability
+ auto aclWeightsRepack = std::make_shared<acl_fc_executor::ACLWeightFormatGenerator>(attrs, postOps, memoryArgs);
+ bool isNeededReorder = aclWeightsRepack->update(memoryArgs);
+ expectedWeightFormat = isNeededReorder ? aclWeightsRepack->getOptImplWeightFormat() : arm_compute::WeightFormat::UNSPECIFIED;
+ weiTensorInfo = aclWeightsRepack->getTensorInfo(ACLArgs::ACL_WEI);
+
+ MemoryPtr dstMemPtr = std::make_shared<Memory>(context->getEngine(),
+ memory.at(ARG_WEI)->getDescPtr()->cloneWithNewPrecision(aclfcAttrs.inputPrecision));
+ auto dstDesc = dstMemPtr->getDescPtr();
+ auto dnnlDstDesc = MemoryDescUtils::convertToDnnlMemoryDesc(dstDesc);
+ auto weiDesc = memory.at(ARG_WEI)->getDescPtr();
+ auto dnnlSrcDesc = MemoryDescUtils::convertToDnnlMemoryDesc(weiDesc);
+
+ if (isNeededReorder) {
+ dnnl::impl::dim_t o_dim = 0;
+ dnnl::impl::dim_t inner_dim = 1;
+ std::vector<dnnl::impl::dim_t> remaining_dims = {};
+ auto weights_md_ = dnnlDstDesc->getDnnlDesc().get();
+ dnnl::impl::cpu::acl::acl_utils::reorder_to_weight_format(weiTensorInfo, *weights_md_, expectedWeightFormat,
+ inner_dim, o_dim, remaining_dims, {});
+ if (aclfcAttrs.weightsNonTransposed) {
+ dnnlSrcDesc = makeTransposedWeightDescriptor(dnnlSrcDesc, dnnlDstDesc);
+ }
+ aclfcAttrs.isWeightsRepacked = true;
+ return reorderWeights(memory, context, aclfcAttrs, dnnlSrcDesc, dnnlDstDesc);
+ }
+ if (!aclfcAttrs.weightsNonTransposed) {
+ dnnlDstDesc = makeTransposedWeightDescriptor(dnnlDstDesc, dnnlSrcDesc);
+ aclfcAttrs.isWeightsRepacked = true;
+ }
+ return reorderWeights(memory, context, aclfcAttrs, dnnlSrcDesc, dnnlDstDesc);
+}
+
static bool checkPostOps(const PostOps &postOps) {
if (postOps.empty()) {
return true;
@@ -199,7 +292,7 @@ ACLFullyConnectedExecutor::ACLFullyConnectedExecutor(const FCAttrs &attrs,
const MemoryArgs &memory,
const ExecutorContext::CPtr context) {
initFCAttrs(attrs, aclTensorAttrs, aclfcAttrs, memory, fullyConnectedLayerInfo, postOps);
- packedWeights = prepareWeightMemory(memory, context, attrs, aclfcAttrs, postOps);
+ packedWeights = prepareWeightMemory(memory, context, attrs, aclfcAttrs, postOps, expectedWeightFormat, weiTensorInfo);
}
bool ACLFullyConnectedExecutor::supports(const FCConfig &config) {
@@ -212,25 +305,15 @@ bool ACLFullyConnectedExecutor::supports(const FCConfig &config) {
return true;
}
-static void updateFCTensorsShapes(ACLShapes& aclMemoryShapes) {
- if (aclMemoryShapes[ACLArgs::ACL_WEI].num_dimensions() == 3U) {
- aclMemoryShapes[ACLArgs::ACL_WEI] = arm_compute::TensorShape(
- {aclMemoryShapes[ACLArgs::ACL_WEI][0] * aclMemoryShapes[ACLArgs::ACL_WEI][1],
- aclMemoryShapes[ACLArgs::ACL_WEI][2]});
- }
-
- if (one_of(aclMemoryShapes[ACLArgs::ACL_SRC_0].num_dimensions(), 3U, 4U)) {
- aclMemoryShapes[ACLArgs::ACL_SRC_0] = arm_compute::TensorShape({
- aclMemoryShapes[ACLArgs::ACL_WEI][0],
- aclMemoryShapes[ACLArgs::ACL_SRC_0].total_size() / aclMemoryShapes[ACLArgs::ACL_WEI][0]});
- }
-
- if (one_of(aclMemoryShapes[ACLArgs::ACL_DST].num_dimensions(), 3U, 4U)) {
- aclMemoryShapes[ACLArgs::ACL_DST] = arm_compute::TensorShape({
- aclMemoryShapes[ACLArgs::ACL_WEI][1],
- aclMemoryShapes[ACLArgs::ACL_SRC_0][1]});
- }
+static arm_compute::TensorShape normalizeDimsTo2D(const arm_compute::TensorShape shape) {
+ size_t norm_dim = std::accumulate(shape.begin() + 1, shape.end(), 1, std::multiplies<size_t>());
+ return arm_compute::TensorShape(shape[0], norm_dim);
+}
+static void updateFCTensorsShapes(ACLShapes& aclMemoryShapes) {
+ aclMemoryShapes[ACLArgs::ACL_WEI] = normalizeDimsTo2D(aclMemoryShapes[ACLArgs::ACL_WEI]);
+ aclMemoryShapes[ACLArgs::ACL_SRC_0] = normalizeDimsTo2D(aclMemoryShapes[ACLArgs::ACL_SRC_0]);
+ aclMemoryShapes[ACLArgs::ACL_DST] = normalizeDimsTo2D(aclMemoryShapes[ACLArgs::ACL_DST]);
std::swap(aclMemoryShapes[ACLArgs::ACL_WEI][0], aclMemoryShapes[ACLArgs::ACL_WEI][1]);
}
@@ -242,26 +325,33 @@ arm_compute::Status ACLFullyConnectedExecutor::validateTensorsInfo(const ACLInfo
if (aclfcAttrs.isConvertedWeights) {
aclMemoryInfos[ACLArgs::ACL_WEI]->set_data_type(aclMemoryInfos[ACLArgs::ACL_SRC_0]->data_type());
}
+ int ic_total = aclMemoryInfos[ACLArgs::ACL_SRC_0]->dimension(0);
return arm_compute::NEFullyConnectedLayer::validate(
aclMemoryInfos[ACLArgs::ACL_SRC_0].get(),
- aclMemoryInfos[ACLArgs::ACL_WEI].get(),
+ &weiTensorInfo,
aclMemoryInfos[ACLArgs::ACL_BIAS].get(),
aclMemoryInfos[ACLArgs::ACL_DST].get(),
fullyConnectedLayerInfo,
- weightsInfo);
+ expectedWeightFormat == arm_compute::WeightFormat::UNSPECIFIED ?
+ arm_compute::WeightsInfo() :
+ arm_compute::WeightsInfo(false, 1, 1, ic_total, false, expectedWeightFormat));
}
ACLFunction ACLFullyConnectedExecutor::configureFunction(const ACLTensors & aclMemoryTensors) {
auto neFC = std::make_unique<arm_compute::NEFullyConnectedLayer>();
+ aclMemoryTensors[ACLArgs::ACL_WEI]->allocator()->init(weiTensorInfo);
+ int icTotal = aclMemoryTensors[ACLArgs::ACL_WEI]->info()->dimension(0);
neFC->configure(
aclMemoryTensors[ACLArgs::ACL_SRC_0].get(),
aclMemoryTensors[ACLArgs::ACL_WEI].get(),
aclMemoryTensors[ACLArgs::ACL_BIAS].get(),
aclMemoryTensors[ACLArgs::ACL_DST].get(),
fullyConnectedLayerInfo,
- weightsInfo);
-
- if (aclfcAttrs.isConvertedWeights || !aclfcAttrs.weightsNonTransposed) {
+ expectedWeightFormat == arm_compute::WeightFormat::UNSPECIFIED ?
+ arm_compute::WeightsInfo() :
+ arm_compute::WeightsInfo(false, 1, 1, icTotal, false, expectedWeightFormat));
+ // TODO: get rid of those flags and decide whether to import memory or not just based on input type
+ if (aclfcAttrs.isWeightsRepacked || aclfcAttrs.isConvertedWeights) {
aclTensorAttrs.memoryUsageIndicator[ACLArgs::ACL_WEI] = false;
aclMemoryTensors[ACLArgs::ACL_WEI]->allocator()->import_memory(packedWeights->getData());
}
@@ -282,19 +372,6 @@ ACLFunction acl_fc_executor::ACLWeightsConverter::configureFunction(const ACLTen
return neCast;
}
-
-arm_compute::Status acl_fc_executor::ACLWeightsTranspose::validateTensorsInfo(const ACLInfos &aclMemoryInfos) {
- return arm_compute::NETranspose::validate(aclMemoryInfos[ACLArgs::ACL_SRC_0].get(),
- aclMemoryInfos[ACLArgs::ACL_DST].get());
-}
-
-ACLFunction acl_fc_executor::ACLWeightsTranspose::configureFunction(const ACLTensors &aclMemoryTensors) {
- auto neTranspose = std::make_unique<arm_compute::NETranspose>();
- neTranspose->configure(aclMemoryTensors[ACLArgs::ACL_SRC_0].get(),
- aclMemoryTensors[ACLArgs::ACL_DST].get());
- return neTranspose;
-}
-
acl_fc_executor::ACLWeightFormatGenerator::ACLWeightFormatGenerator(const FCAttrs &attrs,
const PostOps &postOps,
const MemoryArgs &memory) {
@@ -309,6 +386,7 @@ arm_compute::Status acl_fc_executor::ACLWeightFormatGenerator::validateTensorsIn
if (aclfcAttrs.isConvertedWeights) {
aclMemoryInfos[ACLArgs::ACL_WEI]->set_data_type(aclMemoryInfos[ACLArgs::ACL_SRC_0]->data_type());
}
+ int icTotal = aclMemoryInfos[ACLArgs::ACL_SRC_0]->dimension(0);
return arm_compute::NEFullyConnectedLayer::has_opt_impl(
expectedWeightFormat,
aclMemoryInfos[ACLArgs::ACL_SRC_0].get(),
@@ -316,40 +394,12 @@ arm_compute::Status acl_fc_executor::ACLWeightFormatGenerator::validateTensorsIn
aclMemoryInfos[ACLArgs::ACL_BIAS].get(),
aclMemoryInfos[ACLArgs::ACL_DST].get(),
fullyConnectedLayerInfo,
- weightsInfo);
+ arm_compute::WeightsInfo(false, 1, 1, icTotal, false, arm_compute::WeightFormat::ANY));
}
ACLFunction acl_fc_executor::ACLWeightFormatGenerator::configureFunction(const ACLTensors &aclMemoryTensors) {
return std::make_unique<arm_compute::NEFullyConnectedLayer>();
}
-arm_compute::Status acl_fc_executor::ACLWeightsReorder::validateTensorsInfo(const ACLInfos &aclMemoryInfos) {
-#if defined(OPENVINO_ARCH_ARM64)
- return arm_compute::NEReorderLayer::validate(aclMemoryInfos[ACLArgs::ACL_SRC_0].get(),
- aclMemoryInfos[ACLArgs::ACL_DST].get(),
- inWeightFormat,
- outWeightFormat);
-#else
- return arm_compute::NECopy::validate(aclMemoryInfos[ACLArgs::ACL_SRC_0].get(),
- aclMemoryInfos[ACLArgs::ACL_DST].get());
-#endif
-}
-
-ACLFunction acl_fc_executor::ACLWeightsReorder::configureFunction(const ACLTensors &aclMemoryTensors) {
-#if defined(OPENVINO_ARCH_ARM64)
- auto neReorderLayer = std::make_unique<arm_compute::NEReorderLayer>();
- neReorderLayer->configure(aclMemoryTensors[ACLArgs::ACL_SRC_0].get(),
- aclMemoryTensors[ACLArgs::ACL_DST].get(),
- inWeightFormat,
- outWeightFormat);
- return neReorderLayer;
-#else
- auto neCopy = std::make_unique<arm_compute::NECopy>();
- neCopy->configure(aclMemoryTensors[ACLArgs::ACL_SRC_0].get(),
- aclMemoryTensors[ACLArgs::ACL_DST].get());
- return neCopy;
-#endif
-}
-
} // namespace intel_cpu
} // namespace ov
diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.hpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.hpp
index 4d7f2e5ef91..fcbcb1475ef 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.hpp
@@ -13,6 +13,7 @@ namespace intel_cpu {
struct ACLFCAttrs {
ov::element::Type inputPrecision;
bool isConvertedWeights = false;
+ bool isWeightsRepacked = false;
bool weightsNonTransposed;
};
@@ -26,14 +27,6 @@ public:
ACLFunction configureFunction(const ACLTensors & aclMemoryTensors) override;
};
-class ACLWeightsTranspose : public ACLCommonExecutor {
-public:
- ACLWeightsTranspose() = default;
- void updateTensorsShapes(ACLShapes& aclMemoryShapes) override {}
- arm_compute::Status validateTensorsInfo(const ACLInfos & aclMemoryInfos) override;
- ACLFunction configureFunction(const ACLTensors & aclMemoryTensors) override;
-};
-
class ACLWeightFormatGenerator : public ACLCommonExecutor {
public:
ACLWeightFormatGenerator(const FCAttrs& attrs,
@@ -47,24 +40,10 @@ public:
}
private:
arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo;
- arm_compute::WeightsInfo weightsInfo;
ACLFCAttrs aclfcAttrs;
arm_compute::WeightFormat expectedWeightFormat;
};
-class ACLWeightsReorder : public ACLCommonExecutor {
-public:
- ACLWeightsReorder(arm_compute::WeightFormat inWeightFormat,
- arm_compute::WeightFormat outWeightFormat)
- : inWeightFormat(inWeightFormat), outWeightFormat(outWeightFormat) {}
- void updateTensorsShapes(ACLShapes& aclMemoryShapes) override {}
- arm_compute::Status validateTensorsInfo(const ACLInfos & aclMemoryInfos) override;
- ACLFunction configureFunction(const ACLTensors & aclMemoryTensors) override;
-private:
- arm_compute::WeightFormat inWeightFormat;
- arm_compute::WeightFormat outWeightFormat;
-};
-
} // namespace acl_fc_executor
class ACLFullyConnectedExecutor : public ACLCommonExecutor {
@@ -84,9 +63,10 @@ public:
private:
arm_compute::FullyConnectedLayerInfo fullyConnectedLayerInfo;
- arm_compute::WeightsInfo weightsInfo;
+ arm_compute::WeightFormat expectedWeightFormat;
MemoryCPtr packedWeights;
ACLFCAttrs aclfcAttrs;
+ arm_compute::TensorInfo weiTensorInfo;
};
using ACLFullyConnectedExecutorPtr = std::shared_ptr<ACLFullyConnectedExecutor>;