Skip to content

Commit

Permalink
[ARM CPU] Remove configure from exec func in eltwise, reduce and pool…
Browse files Browse the repository at this point in the history
  • Loading branch information
allnes authored Aug 30, 2023
1 parent 6b57360 commit f2167a9
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 71 deletions.
112 changes: 57 additions & 55 deletions src/plugins/intel_cpu/src/nodes/executors/acl/acl_eltwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,123 +226,124 @@ bool AclEltwiseExecutor::init(const EltwiseAttrs &eltwiseAttrs, const std::vecto
dstTensors[i].allocator()->init(dstTensorsInfo[i]);
}

std::function<std::unique_ptr<IFunction>(void)> exec_func;
switch (aclEltwiseAttrs.algorithm) {
case Algorithm::EltwiseAdd:
if (!NEArithmeticAddition::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0], ConvertPolicy::SATURATE))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEArithmeticAddition>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0], ConvertPolicy::SATURATE);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseMultiply:
if (!NEPixelWiseMultiplication::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0],
1.0f, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEPixelWiseMultiplication>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0], 1.0f, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseSubtract:
if (!NEArithmeticSubtraction::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0], ConvertPolicy::SATURATE))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEArithmeticSubtraction>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0], ConvertPolicy::SATURATE);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseDivide:
if (!NEElementwiseDivision::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0]))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseDivision>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0]);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseMaximum:
if (!NEElementwiseMax::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0]))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseMax>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0]);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseMinimum:
if (!NEElementwiseMin::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0]))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseMin>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0]);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseSquaredDifference:
if (!NEElementwiseSquaredDiff::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0]))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseSquaredDiff>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0]);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseEqual:
if (!NEElementwiseComparison::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0], ComparisonOperation::Equal))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseComparison>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0], ComparisonOperation::Equal);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseNotEqual:
if (!NEElementwiseComparison::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0], ComparisonOperation::NotEqual))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseComparison>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0], ComparisonOperation::NotEqual);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseGreater:
if (!NEElementwiseComparison::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0], ComparisonOperation::Greater))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseComparison>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0], ComparisonOperation::Greater);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseGreaterEqual:
if (!NEElementwiseComparison::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0], ComparisonOperation::GreaterEqual))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseComparison>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0], ComparisonOperation::GreaterEqual);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseLess:
if (!NEElementwiseComparison::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0], ComparisonOperation::Less))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseComparison>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0], ComparisonOperation::Less);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseLessEqual:
if (!NEElementwiseComparison::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0], ComparisonOperation::LessEqual))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEElementwiseComparison>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0], ComparisonOperation::LessEqual);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseRelu:
Expand All @@ -355,144 +356,145 @@ bool AclEltwiseExecutor::init(const EltwiseAttrs &eltwiseAttrs, const std::vecto
{ActivationLayerInfo::ActivationFunction::LEAKY_RELU, aclEltwiseAttrs.alpha}))
return false;
}
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
if (aclEltwiseAttrs.alpha == 0) {
acl_op->configure(&srcTensors[0], &dstTensors[0], ActivationLayerInfo::ActivationFunction::RELU);
} else {
acl_op->configure(&srcTensors[0], &dstTensors[0],
{ActivationLayerInfo::ActivationFunction::LEAKY_RELU, aclEltwiseAttrs.alpha});
}
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseGeluErf:
if (!NEActivationLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0], ActivationLayerInfo::ActivationFunction::GELU))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0], ActivationLayerInfo::ActivationFunction::GELU);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseElu:
if (!NEActivationLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0],
{ActivationLayerInfo::ActivationFunction::ELU, aclEltwiseAttrs.alpha}))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0], {ActivationLayerInfo::ActivationFunction::ELU, aclEltwiseAttrs.alpha});
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseTanh:
if (!NEActivationLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0],
{ActivationLayerInfo::ActivationFunction::TANH, 1.f, 1.f}))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0],
{ActivationLayerInfo::ActivationFunction::TANH, 1.f, 1.f});
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseSigmoid:
if (!NEActivationLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0], ActivationLayerInfo::ActivationFunction::LOGISTIC))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0], ActivationLayerInfo::ActivationFunction::LOGISTIC);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseAbs:
if (!NEAbsLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0]))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEAbsLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0]);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseSqrt:
if (!NEActivationLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0], ActivationLayerInfo::ActivationFunction::SQRT))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0], ActivationLayerInfo::ActivationFunction::SQRT);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseSoftRelu:
if (!NEActivationLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0], ActivationLayerInfo::ActivationFunction::SOFT_RELU))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0], ActivationLayerInfo::ActivationFunction::SOFT_RELU);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseExp:
if (!NEExpLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0]))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEExpLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0]);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseClamp:
if (!NEActivationLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0],
{ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, aclEltwiseAttrs.beta, aclEltwiseAttrs.alpha}))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0],
{ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, aclEltwiseAttrs.beta, aclEltwiseAttrs.alpha});
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseSwish:
if (!NEActivationLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0],
{ActivationLayerInfo::ActivationFunction::SWISH, aclEltwiseAttrs.alpha}))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0],
{ActivationLayerInfo::ActivationFunction::SWISH, aclEltwiseAttrs.alpha});
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwisePrelu:
if (!NEPReluLayer::validate(&srcTensorsInfo[0], &srcTensorsInfo[1], &dstTensorsInfo[0]))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEPReluLayer>();
acl_op->configure(&srcTensors[0], &srcTensors[1], &dstTensors[0]);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseHswish:
if (!NEActivationLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0], ActivationLayerInfo::ActivationFunction::HARD_SWISH))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NEActivationLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0], ActivationLayerInfo::ActivationFunction::HARD_SWISH);
acl_op->run();
return acl_op;
};
break;
case Algorithm::EltwiseLog:
if (!NELogLayer::validate(&srcTensorsInfo[0], &dstTensorsInfo[0]))
return false;
exec_func = [this]{
exec_func = [this]() -> std::unique_ptr<IFunction> {
auto acl_op = std::make_unique<NELogLayer>();
acl_op->configure(&srcTensors[0], &dstTensors[0]);
acl_op->run();
return acl_op;
};
break;
default:
IE_THROW() << "Unsupported operation type for ACL Eltwise executor: " << static_cast<int>(aclEltwiseAttrs.algorithm);
}
ifunc = exec_func();
return true;
}

Expand All @@ -505,7 +507,7 @@ void AclEltwiseExecutor::exec(const std::vector<MemoryCPtr> &src, const std::vec
dstTensors[i].allocator()->import_memory(dst[i]->getData());
}

exec_func();
ifunc->run();

for (size_t i = 0; i < src.size(); i++) {
srcTensors[i].allocator()->free();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AclEltwiseExecutor : public EltwiseExecutor {
EltwiseAttrs aclEltwiseAttrs{};
impl_desc_type implType = impl_desc_type::acl;
std::vector<arm_compute::Tensor> srcTensors, dstTensors;
std::function<void()> exec_func;
std::unique_ptr<arm_compute::IFunction> ifunc;
};

class AclEltwiseExecutorBuilder : public EltwiseExecutorBuilder {
Expand Down
Loading

0 comments on commit f2167a9

Please sign in to comment.