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

[CPU] [ARM] [INT8] FullyConnected #25171

Merged
merged 35 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8212473
[CPU] [ARM] FullyConnected: int8 support
eshoguli Jun 26, 2024
7dd226e
[CPU] [ACL] FullyConnected fp32 executor refactoring
eshoguli Aug 13, 2024
d4c30c6
cleanup and refactoring
eshoguli Aug 16, 2024
5dbd319
address comments #1
alvoron Nov 14, 2024
03315bf
Merge branch 'master' into es/aarch64/int8
alvoron Nov 14, 2024
e6d4880
fixed build
alvoron Nov 14, 2024
8189730
fix merge
alvoron Nov 15, 2024
c743709
removed generate_values
alvoron Nov 15, 2024
c40e695
removed MatMulWithDequantizationTransformation
alvoron Nov 18, 2024
ff886c4
revert network_helper changes
alvoron Nov 19, 2024
39fcf09
delete empty DQScales check and moved test skip
alvoron Nov 19, 2024
2e9a2a0
return empty dequantizationScales check
alvoron Nov 19, 2024
1c639ef
added test case with bias
alvoron Nov 20, 2024
5df26e4
test with bias is added to x64 scope
alvoron Nov 22, 2024
b9df131
removed FusedWithMatMulI8 and MM transformation logic
alvoron Nov 22, 2024
b5f3487
fixed test and apply the last comment
alvoron Nov 25, 2024
ceff99e
simplified isSuitableChildForFC logic
alvoron Nov 25, 2024
459519b
update aclLowpFCTypeMapping
alvoron Nov 26, 2024
3688201
revert StaticMemory changes
alvoron Nov 27, 2024
1e95bb6
Merge branch 'master' into es/aarch64/int8
alvoron Nov 27, 2024
5d8c67d
Merge branch 'master' into es/aarch64/int8
alvoron Dec 11, 2024
7a07337
changes required after #26239
alvoron Dec 12, 2024
aeca18e
Merge branch 'master' into es/aarch64/int8
alvoron Dec 12, 2024
44e04cf
fix code style and warnings
alvoron Dec 12, 2024
fddd3f4
rollback dq scales fusing
alvoron Dec 13, 2024
55e0d0d
removed DQ check
alvoron Dec 13, 2024
9226262
stop wrapping FQ with Convert
alvoron Dec 16, 2024
aa64460
Revert "stop wrapping FQ with Convert"
alvoron Dec 16, 2024
0079f5f
mark getDeQuantizedScales as OV_CPU_MAYBE_UNUSED_FUNCTION
alvoron Dec 16, 2024
5455c1b
added missed code to prepareWeightMemory
alvoron Dec 16, 2024
118cfa8
fix fuse condition
alvoron Dec 16, 2024
f782508
Merge branch 'master' into es/aarch64/int8
alvoron Dec 17, 2024
5721c63
clang-format fix
alvoron Dec 17, 2024
bf9f2f6
Merge branch 'master' into es/aarch64/int8
alvoron Dec 17, 2024
83bc0c3
fix x64 expected nodes
alvoron Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1897,4 +1897,4 @@ bool NetworkHelper::checkConstantNotInf(const std::shared_ptr<Node> constant_nod
}
} // namespace low_precision
} // namespace pass
} // namespace ov
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() {
std::vector<element::Type> weights_types{ov::element::i8};

auto activations_m = pattern::any_input(ov::pass::pattern::type_matches_any(activation_types));
auto weights_m = wrap_type<ov::op::v0::Constant>(ov::pass::pattern::type_matches_any(weights_types));
auto weights_m = pattern::any_input();
auto bias_m = pattern::any_input();

auto fully_connected_m = wrap_type<ov::op::internal::FullyConnected>({activations_m, weights_m, bias_m});
Expand All @@ -43,7 +43,8 @@ ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() {
const auto& fc_output_shape = fc_output.get_partial_shape();
const auto& multiply_output_shape = multiply.get_partial_shape();

if (*fc_output_shape.rbegin() != *multiply_output_shape.rbegin()) {
if (*fc_output_shape.rbegin() != *multiply_output_shape.rbegin() ||
!ov::op::util::is_on_constant_path(weights)) {
return false;
}

Expand Down
47 changes: 1 addition & 46 deletions src/plugins/intel_cpu/src/dnnl_postops_composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "cpu_types.h"
#include "memory_desc/dnnl_blocked_memory_desc.h"
#include "nodes/executors/common/common_utils.hpp"
#include "nodes/executors/memory_arguments.hpp"
#include "openvino/core/type/element_type.hpp"
#include "utils/cpu_utils.hpp"
Expand All @@ -21,52 +22,6 @@
namespace ov {
namespace intel_cpu {

static std::vector<float> getDeQuantizedScales(const MemoryArgs& memory) {
if (!memory.count(ARG_DST_DEQ_SCALE))
return {};

auto scalesMemory = memory.at(ARG_DST_DEQ_SCALE);

auto scalesData = static_cast<const float*>(scalesMemory->getData());

if (!scalesData)
return {};

auto dstShape = memory.at(ARG_DST)->getShape();
auto dqScalesShape = scalesMemory->getShape();

auto scalesDims = getNormalizedDimsBySize(dqScalesShape.getDims(), dstShape.getDims().size());

auto scaleSize = std::accumulate(scalesDims.begin(), scalesDims.end(), std::size_t(1), std::multiplies<size_t>());

std::vector<float> DQScales(scaleSize, 1.0);

OPENVINO_ASSERT(scaleSize == 1 || DQScales.size() == 1 || DQScales.size() == scaleSize,
"set invalid scales size , DQScales vector size: ",
DQScales.size(),
", scale data size: ",
scaleSize);

// @todo do we really need to broadcast dq scales and then resize them back?
if (scaleSize > DQScales.size())
DQScales.resize(scaleSize, DQScales[0]);
if (1 == scaleSize) {
std::transform(DQScales.begin(), DQScales.end(), DQScales.begin(), [=](float val) {
return (scalesData[0] * val);
});
} else {
for (size_t i = 0; i < DQScales.size(); i++) {
DQScales[i] *= scalesData[i];
}
}
if (std::all_of(DQScales.begin(), DQScales.end(), [&](float val) {
return (val == DQScales[0]);
}))
DQScales.resize(1);

return DQScales;
}

DnnlPostOpsComposer::DnnlPostOpsComposer(const PostOps& postOps,
const dnnl::engine& engine,
const VectorDims& outputDims,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
namespace ov {
namespace intel_cpu {

static const std::unordered_map<int, ACLArgs> argConvert = {
{ARG_SRC_0, ACL_SRC_0},
{ARG_SRC_1, ACL_SRC_1},
{ARG_SRC_2, ACL_SRC_2},
{ARG_BIAS, ACL_BIAS},
{ARG_WEI, ACL_WEI},
{ARG_DST, ACL_DST},
};
static const std::unordered_map<int, ACLArgs> argConvert = {{ARG_SRC_0, ACL_SRC_0},
{ARG_SRC_1, ACL_SRC_1},
{ARG_SRC_2, ACL_SRC_2},
{ARG_BIAS, ACL_BIAS},
{ARG_WEI, ACL_WEI},
{ARG_DST, ACL_DST},
{ARG_DST_DEQ_SCALE, ACL_DST_DEQ_SCALE}};

using ACLTypes = std::array<arm_compute::DataType, ACLArgs::COUNT_OF_ARGS>;
using ACLLayouts = std::array<arm_compute::DataLayout, ACLArgs::COUNT_OF_ARGS>;
Expand All @@ -39,9 +38,9 @@ static void initACLTensorParams(const MemoryPtr& memoryPtr,
}
}

static std::shared_ptr<arm_compute::TensorInfo> initTensorInfo(const arm_compute::TensorShape& tensorShape,
const arm_compute::DataType& dataType,
const arm_compute::DataLayout& dataLayout) {
std::shared_ptr<arm_compute::TensorInfo> ACLCommonExecutor::initTensorInfo(const arm_compute::TensorShape& tensorShape,
const arm_compute::DataType& dataType,
const arm_compute::DataLayout& dataLayout) {
std::shared_ptr<arm_compute::TensorInfo> aclMemoryInfo = nullptr;
if (dataType != arm_compute::DataType::UNKNOWN) {
aclMemoryInfo = std::make_shared<arm_compute::TensorInfo>(tensorShape, 1, dataType, dataLayout);
Expand Down Expand Up @@ -70,6 +69,9 @@ bool ACLCommonExecutor::update(const MemoryArgs& memory) {
ACLTypes aclDataType{};
ACLLayouts aclDataLayout{};
for (auto& cpu_mem_ptr : memory) {
if (cpu_mem_ptr.second->getSize() == 0) {
continue;
}
const ACLArgs index = argConvert.at(cpu_mem_ptr.first);
initACLTensorParams(cpu_mem_ptr.second,
aclTensorAttrs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace ov {
namespace intel_cpu {

enum ACLArgs { ACL_SRC_0, ACL_SRC_1, ACL_SRC_2, ACL_BIAS, ACL_WEI, ACL_DST, COUNT_OF_ARGS };
enum ACLArgs { ACL_SRC_0, ACL_SRC_1, ACL_SRC_2, ACL_BIAS, ACL_WEI, ACL_DST, ACL_DST_DEQ_SCALE, COUNT_OF_ARGS };

using ACLFunction = std::unique_ptr<arm_compute::IFunction>;
using ACLShapes = std::array<arm_compute::TensorShape, ACLArgs::COUNT_OF_ARGS>;
Expand Down Expand Up @@ -42,6 +42,9 @@ class ACLCommonExecutor : public Executor {

protected:
ACLTensorAttrs aclTensorAttrs;
virtual std::shared_ptr<arm_compute::TensorInfo> initTensorInfo(const arm_compute::TensorShape& tensorShape,
const arm_compute::DataType& dataType,
const arm_compute::DataLayout& dataLayout);

private:
ACLTensors aclMemoryTensors;
Expand Down
Loading
Loading