parent
b8fbabae34
commit
920cbb1e22
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2020 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 "include/errorcode.h"
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
void PrintErrorInfo(STATUS status) {
|
||||
std::map<int, std::string> info_map = {{RET_OK, "No error occurs."},
|
||||
{RET_ERROR, "Common error code."},
|
||||
{RET_NULL_PTR, "NULL pointer returned."},
|
||||
{RET_PARAM_INVALID, "Invalid parameter."},
|
||||
{RET_NO_CHANGE, "No change."},
|
||||
{RET_SUCCESS_EXIT, "No error but exit."},
|
||||
{RET_MEMORY_FAILED, "Fail to create memory."},
|
||||
{RET_NOT_SUPPORT, "Fail to support."},
|
||||
{RET_OUT_OF_TENSOR_RANGE, "Failed to check range."},
|
||||
{RET_INPUT_TENSOR_ERROR, "Failed to check input tensor."},
|
||||
{RET_REENTRANT_ERROR, "Exist executor running."},
|
||||
{RET_GRAPH_FILE_ERR, "Failed to verify graph file."},
|
||||
{RET_NOT_FIND_OP, "Failed to find operator."},
|
||||
{RET_INVALID_OP_NAME, "Invalid operator name."},
|
||||
{RET_INVALID_OP_ATTR, "Invalid operator attr."},
|
||||
{RET_OP_EXECUTE_FAILURE, "Failed to execution operator."},
|
||||
{RET_FORMAT_ERR, "Failed to checking tensor format."},
|
||||
{RET_INFER_ERR, "Failed to infer shape."},
|
||||
{RET_INFER_INVALID, "Invalid infer shape before runtime."},
|
||||
{RET_INPUT_PARAM_INVALID, "Invalid input param by user."}};
|
||||
std::cout << info_map[status] << std::endl;
|
||||
}
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2020 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 "src/ops/primitive_c.h"
|
||||
|
||||
#ifndef LITE_MINDSPORE_LITE_C_OPS_IDENTITY_H_
|
||||
#define LITE_MINDSPORE_LITE_C_OPS_IDENTITY_H_
|
||||
|
||||
namespace mindspore {
|
||||
namespace lite {
|
||||
class Identity : public PrimitiveC {
|
||||
public:
|
||||
MS_DECLARE_PARENT(Identity, PrimitiveC);
|
||||
Identity() = default;
|
||||
explicit Identity(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {}
|
||||
};
|
||||
} // namespace lite
|
||||
} // namespace mindspore
|
||||
#endif // LITE_MINDSPORE_LITE_C_OPS_IDENTITY_H_
|
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2020 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/optimizer/graph/identity_remove_pass.h"
|
||||
#include "tools/optimizer/common/gllo_utils.h"
|
||||
#include "mindspore/lite/include/errorcode.h"
|
||||
#include "src/ops/primitive_c.h"
|
||||
|
||||
namespace mindspore::opt {
|
||||
bool RemoveIdentityOpPass::Run(const FuncGraphPtr &func_graph) {
|
||||
if (this->fmk_type != lite::converter::FmkType_ONNX) {
|
||||
MS_LOG(INFO) << "The framework type of model should be onnx.";
|
||||
return RET_OK;
|
||||
}
|
||||
MS_ASSERT(func_graph != nullptr);
|
||||
auto manager = func_graph->manager();
|
||||
MS_ASSERT(manager != nullptr);
|
||||
auto node_list = TopoSort(func_graph->get_return());
|
||||
for (auto &node : node_list) {
|
||||
if (!utils::isa<CNodePtr>(node)) {
|
||||
continue;
|
||||
}
|
||||
auto type = opt::GetCNodeType(node);
|
||||
if (type != schema::PrimitiveType_Identity) {
|
||||
continue;
|
||||
}
|
||||
auto identity_cnode = node->cast<CNodePtr>();
|
||||
if (identity_cnode->inputs().size() != lite::kDoubleNum) {
|
||||
MS_LOG(ERROR) << "The `node input is a single tensor";
|
||||
return RET_ERROR;
|
||||
}
|
||||
manager->Replace(node, identity_cnode->input(1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace mindspore::opt
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright 2020 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_SRC_PASS_REMOVE_IDENTITY_PASS_H_
|
||||
#define MINDSPORE_LITE_SRC_PASS_REMOVE_IDENTITY_PASS_H_
|
||||
#include <string>
|
||||
#include "backend/optimizer/common/pass.h"
|
||||
#include "tools/converter/converter_flags.h"
|
||||
|
||||
using mindspore::lite::converter::FmkType;
|
||||
namespace mindspore::opt {
|
||||
class RemoveIdentityOpPass : public Pass {
|
||||
public:
|
||||
RemoveIdentityOpPass() : Pass("remove_identity_pass") {}
|
||||
~RemoveIdentityOpPass() override = default;
|
||||
void SetFmkType(FmkType fmkType) { this->fmk_type = fmkType; }
|
||||
bool Run(const FuncGraphPtr &graph) override;
|
||||
|
||||
private:
|
||||
FmkType fmk_type = lite::converter::FmkType_ONNX;
|
||||
};
|
||||
} // namespace mindspore::opt
|
||||
#endif // MINDSPORE_LITE_SRC_PASS_REMOVE_IDENTITY_PASS_H_
|
Loading…
Reference in new issue