Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alvoron committed Mar 2, 2023
1 parent 39ed616 commit effdb09
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 189 deletions.
48 changes: 9 additions & 39 deletions src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "acl_pooling.hpp"
#include "acl_utils.hpp"
#include "arm_compute/core/utils/misc/ShapeCalculator.h"

namespace ov {
namespace intel_cpu {
Expand All @@ -19,51 +18,27 @@ bool AclPoolingExecutor::init(const PoolingAttrs& poolingAttrs,
const dnnl::primitive_attr &attr) {
auto srcDims = srcDescs[0]->getShape().getStaticDims();
auto dstDims = dstDescs[0]->getShape().getStaticDims();
/*if (poolingAttrs.dilation != ov::Strides{1, 1}) {
std::cout << "AclPoolingExecutor::init unsupported dilation!" << std::endl;
}*/

if (srcDims.size() != 4) {
std::cout << "AclPoolingExecutor::init only 4D input tensors are supported. Tensor rank: " << srcDims.size() << std::endl;
//return false;
}

/*VectorDims srcDimsReduced;
VectorDims dstDimsReduced;
if (srcDims.size() == 5) {
srcDimsReduced.push_back(srcDims[0] * srcDims[1]);
srcDimsReduced.push_back(srcDims[2]);
srcDimsReduced.push_back(srcDims[3]);
srcDimsReduced.push_back(srcDims[4]);
dstDimsReduced.push_back(dstDims[0] * dstDims[1]);
dstDimsReduced.push_back(dstDims[2]);
dstDimsReduced.push_back(dstDims[3]);
dstDimsReduced.push_back(dstDims[4]);
}*/

TensorInfo srcTensorInfo = TensorInfo(shapeCast(srcDims), 1,
precisionToAclDataType(srcDescs[0]->getPrecision()), /*getAclDataLayoutByMemoryDesc(srcDescs[0])*/arm_compute::DataLayout::NCHW);
precisionToAclDataType(srcDescs[0]->getPrecision()), getAclDataLayoutByMemoryDesc(srcDescs[0]));
TensorInfo dstTensorInfo = TensorInfo(shapeCast(dstDims), 1,
precisionToAclDataType(dstDescs[0]->getPrecision()), /*getAclDataLayoutByMemoryDesc(dstDescs[0])*/arm_compute::DataLayout::NCHW);

precisionToAclDataType(dstDescs[0]->getPrecision()), getAclDataLayoutByMemoryDesc(dstDescs[0]));

arm_compute::PoolingLayerInfo pool_info;
unsigned int pad_left = (poolingAttrs.data_pad_begin.size() == 2) ? poolingAttrs.data_pad_begin[1] : 0;//poolingAttrs.data_pad_begin[0];
unsigned int pad_right = (poolingAttrs.data_pad_end.size() == 2) ? poolingAttrs.data_pad_end[1] : 0;//poolingAttrs.data_pad_end[0];
unsigned int pad_left = (poolingAttrs.data_pad_begin.size() == 2) ? poolingAttrs.data_pad_begin[1] : 0;
unsigned int pad_right = (poolingAttrs.data_pad_end.size() == 2) ? poolingAttrs.data_pad_end[1] : 0;
unsigned int pad_top = poolingAttrs.data_pad_begin[0];
unsigned int pad_bottom = poolingAttrs.data_pad_end[0];
unsigned int kernel_w = (poolingAttrs.kernel.size() == 2) ? poolingAttrs.kernel[1] : poolingAttrs.kernel[0];
unsigned int kernel_h = poolingAttrs.kernel[0];
unsigned int stride_x = (poolingAttrs.stride.size() == 2) ? poolingAttrs.stride[1] : poolingAttrs.stride[0];
unsigned int stride_y = poolingAttrs.stride[0];

arm_compute::PoolingLayerInfo pool_info;
arm_compute::DimensionRoundingType round = (poolingAttrs.rounding == op::RoundingType::CEIL) ?
arm_compute::DimensionRoundingType::CEIL : arm_compute::DimensionRoundingType::FLOOR;

pool_info.data_layout = arm_compute::DataLayout::NCHW;//getAclDataLayoutByMemoryDesc(srcDescs[0]);
pool_info.data_layout = getAclDataLayoutByMemoryDesc(srcDescs[0]);
pool_info.pool_size = arm_compute::Size2D(kernel_w, kernel_h);
pool_info.pad_stride_info = arm_compute::PadStrideInfo(stride_x, stride_y, pad_left, pad_right, pad_top, pad_bottom, round);
//pool_info.is_global_pooling = false;

if (poolingAttrs.algorithm == Algorithm::PoolingMax) {
pool_info.pool_type = arm_compute::PoolingType::MAX;
Expand All @@ -72,27 +47,23 @@ bool AclPoolingExecutor::init(const PoolingAttrs& poolingAttrs,
pool_info.pool_type = arm_compute::PoolingType::AVG;
pool_info.exclude_padding = poolingAttrs.exclude_pad;
} else {
DEBUG_LOG("Unknown pooling algorithm: ", static_cast<int>(poolingAttrs.algorithm));
return false;
}

/*arm_compute::TensorInfo ti = arm_compute::TensorInfo(arm_compute::misc::shape_calculator::compute_pool_shape(srcTensorInfo, pool_info),
1, dstTensorInfo.data_type());*/

TensorInfo indTensorInfo;
if (dstDescs.size() > 1) {
std::cout << "AclPoolingExecutor::init - indices branch" << std::endl;
auto indDims = dstDescs[1]->getShape().getStaticDims();
indTensorInfo = TensorInfo(shapeCast(indDims), 1, arm_compute::DataType::U32, getAclDataLayoutByMemoryDesc(srcDescs[0]));
arm_compute::Status s = arm_compute::NEPoolingLayer::validate(&srcTensorInfo, &dstTensorInfo, pool_info, &indTensorInfo);
if (!s) {
std::cout << "validate failed (ind): " << s.error_description() << std::endl;
DEBUG_LOG("NEPoolingLayer validation with indices failed: ", s.error_description());
return false;
}
} else {
std::cout << "AclPoolingExecutor::init - no indices branch" << std::endl;
arm_compute::Status s = arm_compute::NEPoolingLayer::validate(&srcTensorInfo, &dstTensorInfo, pool_info);
if (!s) {
std::cout << "validate failed (no ind): " << s.error_description() << std::endl;
DEBUG_LOG("NEPoolingLayer validation without indices failed: ", s.error_description());
return false;
}
}
Expand All @@ -104,7 +75,6 @@ bool AclPoolingExecutor::init(const PoolingAttrs& poolingAttrs,
if (dstDescs.size() > 1) {
indTensor.allocator()->init(indTensorInfo);
pooling->configure(&srcTensor, &dstTensor, pool_info, &indTensor);
std::cout << "INDICES!" << std::endl;
} else {
pooling->configure(&srcTensor, &dstTensor, pool_info);
}
Expand Down
14 changes: 6 additions & 8 deletions src/plugins/intel_cpu/src/nodes/executors/acl/acl_pooling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// TODO: remove relative path
#include "../pooling.hpp"
#include "arm_compute/runtime/NEON/NEFunctions.h"
#include "utils/debug_capabilities.h"

namespace ov {
namespace intel_cpu {
Expand Down Expand Up @@ -46,21 +47,18 @@ class AclPoolingExecutorBuilder : public PoolingExecutorBuilder {
dstDescs[0]->getPrecision() != InferenceEngine::Precision::FP32) &&
(srcDescs[0]->getPrecision() != InferenceEngine::Precision::FP16 &&
dstDescs[0]->getPrecision() != InferenceEngine::Precision::FP16)) {
std::cout << "AclPoolingExecutorBuilder::isSupported - presicion is not supported: src=" <<
srcDescs[0]->getPrecision() << "src=" << dstDescs[0]->getPrecision() << std::endl;
DEBUG_LOG("AclPoolingExecutor does not support precisions: input precision=",
srcDescs[0]->getPrecision(), " output precision=", dstDescs[0]->getPrecision());
return false;
}

if (!(srcDescs[0]->hasLayoutType(LayoutType::ncsp) &&
dstDescs[0]->hasLayoutType(LayoutType::ncsp)) &&
!(srcDescs[0]->hasLayoutType(LayoutType::nspc) &&
dstDescs[0]->hasLayoutType(LayoutType::nspc))) {
std::cout << "AclPoolingExecutorBuilder::isSupported - layout is not supported" <<
srcDescs[0]->hasLayoutType(LayoutType::ncsp) << dstDescs[0]->hasLayoutType(LayoutType::ncsp)
<< srcDescs[0]->hasLayoutType(LayoutType::nspc) << dstDescs[0]->hasLayoutType(LayoutType::nspc) << std::endl;
//TODO: understand why hasLayoutType returns false in all 4 cases above
//return false;
}
DEBUG_LOG("AclPoolingExecutor does not support such layouts");
return false;
}

return true;
}
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/intel_cpu/src/nodes/executors/acl/acl_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ inline VectorDims dimsCast(const VectorDims& dims, size_t requiredSize) {
if (dims.size() == requiredSize)
return dims;
VectorDims returnDims;
std::cout << "dimsCast: Original VectorDims: "; for (auto i : dims) std::cout << i << " "; std::cout << std::endl;
if (dims.size() > requiredSize) {
Dim dim = dims[0];
for (int i = 1; i < dims.size() - requiredSize + 1; i++) {
Expand All @@ -26,23 +25,18 @@ inline VectorDims dimsCast(const VectorDims& dims, size_t requiredSize) {
returnDims.push_back(1);
}
}
std::cout << "dimsCast: Final VectorDims: "; for (auto i : returnDims) std::cout << i << " "; std::cout << std::endl;
return returnDims;
}

inline arm_compute::TensorShape shapeCast(const VectorDims& dims) {
arm_compute::TensorShape tensorShape;
std::cout << "shapeCast: after creation VectorDims: "; for (auto i : tensorShape) std::cout << i << " "; std::cout << std::endl;
std::cout << "shapeCast: Original VectorDims: "; for (auto i : dims) std::cout << i << " "; std::cout << std::endl;
for (std::size_t i = 0; i < dims.size(); ++i) {
tensorShape.set(dims.size() - i - 1, dims[i], false);
std::cout << "shapeCast: intermidiate VectorDims: "; for (auto i : tensorShape) std::cout << i << " "; std::cout << std::endl;
}
if (tensorShape.num_dimensions() == 0) {
tensorShape.set(0, 1, false);
tensorShape.set_num_dimensions(1);
}
std::cout << "shapeCast: Final VectorDims: "; for (auto i : tensorShape) std::cout << i << " "; std::cout << std::endl;
return tensorShape;
}

Expand Down
Loading

0 comments on commit effdb09

Please sign in to comment.