!45601 [MSLITE] Add tile mapper for ascend.
Merge pull request !45601 from wangshaocong/bugfix
This commit is contained in:
commit
b634724bc7
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Copyright 2022 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "tools/converter/adapter/acl/mapper/tile_fusion_mapper.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "tools/converter/adapter/acl/mapper/primitive_mapper_register.h"
|
||||
#include "tools/converter/adapter/acl/common/utils.h"
|
||||
#include "ops/op_utils.h"
|
||||
#include "ops/tile.h"
|
||||
#include "nnacl/op_base.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
namespace {
|
||||
constexpr auto kNameTileInputNum = 3;
|
||||
} // namespace
|
||||
|
||||
STATUS TileFusionMapper::Mapper(const CNodePtr &cnode) {
|
||||
MS_CHECK_TRUE_RET(cnode != nullptr, RET_ERROR);
|
||||
if (cnode->size() != kNameTileInputNum) {
|
||||
MS_LOG(ERROR) << "The input size of tile must be " << kNameTileInputNum
|
||||
<< ", while the real size is: " << cnode->size();
|
||||
return RET_ERROR;
|
||||
}
|
||||
auto repeats_input = cnode->input(kNameTileInputNum - 1);
|
||||
MS_CHECK_TRUE_RET(repeats_input != nullptr, RET_ERROR);
|
||||
if (!utils::isa<ParameterPtr>(repeats_input)) {
|
||||
MS_LOG(ERROR) << "The repeats node is not parameter.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
ParameterPtr repeats_param = repeats_input->cast<ParameterPtr>();
|
||||
MS_CHECK_TRUE_RET(repeats_param != nullptr, RET_ERROR);
|
||||
auto data = acl::GetIntParameterData(repeats_param);
|
||||
std::vector<int64_t> multiples;
|
||||
std::transform(data.begin(), data.end(), std::back_inserter(multiples),
|
||||
[](int32_t x) -> int64_t { return static_cast<int64_t>(x); });
|
||||
ValueNodePtr value_node = NewValueNode<std::vector<int64_t>>(multiples);
|
||||
MS_CHECK_TRUE_RET(value_node != nullptr, RET_ERROR);
|
||||
std::vector<int64_t> shape_vec_shape = {static_cast<int64_t>(multiples.size())};
|
||||
auto abstract = std::make_shared<abstract::AbstractTensor>(kInt64, shape_vec_shape);
|
||||
value_node->set_abstract(abstract);
|
||||
cnode->set_input(kNameTileInputNum - 1, value_node);
|
||||
|
||||
ops::Tile tile;
|
||||
auto dst_prim = tile.GetPrim();
|
||||
if (MoveAttrMap(cnode, dst_prim) != RET_OK) {
|
||||
MS_LOG(ERROR) << "TileFusion mapper failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_MAPPER(kNameTileFusion, TileFusionMapper)
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Copyright 2022 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_MAPPER_TILE_FUSION_MAPPER_H_
|
||||
#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_MAPPER_TILE_FUSION_MAPPER_H_
|
||||
|
||||
#include "tools/converter/adapter/acl/mapper/primitive_mapper.h"
|
||||
#include "ops/fusion/tile_fusion.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
using mindspore::ops::kNameTileFusion;
|
||||
|
||||
class TileFusionMapper : public PrimitiveMapper {
|
||||
public:
|
||||
TileFusionMapper() : PrimitiveMapper(kNameTileFusion) {}
|
||||
|
||||
~TileFusionMapper() override = default;
|
||||
|
||||
STATUS Mapper(const CNodePtr &cnode) override;
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_MAPPER_TILE_FUSION_MAPPER_H_
|
|
@ -165,6 +165,8 @@ PrimitiveCPtr OnnxConvParser::Parse(const onnx::GraphProto &onnx_graph, const on
|
|||
if (status == RET_OK) {
|
||||
prim->set_in_channel(channel_in);
|
||||
prim->set_out_channel(channel_out);
|
||||
bool is_depth_wise = group == channel_in && channel_in == channel_out;
|
||||
(void)prim_c->AddAttr(ops::kIsDepthWise, MakeValue<bool>(is_depth_wise));
|
||||
} else if (status != RET_NO_CHANGE) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -175,10 +177,6 @@ PrimitiveCPtr OnnxConvParser::Parse(const onnx::GraphProto &onnx_graph, const on
|
|||
prim->set_activation_type(mindspore::ActivationType::RELU);
|
||||
}
|
||||
|
||||
if (group == channel_in && channel_in == channel_out) {
|
||||
(void)prim_c->AddAttr(ops::kIsDepthWise, MakeValue<bool>(true));
|
||||
}
|
||||
|
||||
return prim->GetPrim();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,14 +25,6 @@ PrimitiveCPtr PytorchCumSumParser::Parse(const torch::jit::Node *torch_node, std
|
|||
MS_ASSERT(torch_node != nullptr && input_indices != nullptr);
|
||||
auto prim = std::make_unique<ops::CumSum>();
|
||||
MS_CHECK_TRUE_RET(prim != nullptr, nullptr);
|
||||
|
||||
input_indices->push_back(0);
|
||||
|
||||
if (torch_node->inputs().size() > SECOND_INPUT) {
|
||||
auto dim = PytorchNodeParser::GetValueFromConstNode<int64_t>(torch_node->input(SECOND_INPUT));
|
||||
prim->set_axis(dim);
|
||||
}
|
||||
|
||||
return prim->GetPrim();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue