From: @mengyuanli Reviewed-by: @hangangqiang,@zhanghaibo5 Signed-off-by: @hangangqiangtags/v1.2.0-rc1
| @@ -121,8 +121,7 @@ endif() | |||||
| add_definitions(-DENABLE_V0) | add_definitions(-DENABLE_V0) | ||||
| file(GLOB_RECURSE OPS_SRC ${LITE_DIR}/src/ops/*.cc) | file(GLOB_RECURSE OPS_SRC ${LITE_DIR}/src/ops/*.cc) | ||||
| if(ENABLE_CONVERTER) | if(ENABLE_CONVERTER) | ||||
| file(GLOB_RECURSE CONVERTER_OPS_SRC ${CONVERTER_DIR}/ops/*.cc) | |||||
| set(OPS_SRC ${OPS_SRC} ${CONVERTER_OPS_SRC}) | |||||
| set(OPS_SRC ${OPS_SRC}) | |||||
| endif() | endif() | ||||
| set(TEST_LITE_SRC | set(TEST_LITE_SRC | ||||
| ${TEST_LITE_SRC} | ${TEST_LITE_SRC} | ||||
| @@ -12,8 +12,6 @@ include(${TOP_DIR}/cmake/external_libs/glog.cmake) | |||||
| file(GLOB OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/*.cc | file(GLOB OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/*.cc | ||||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/populate/*.cc) | ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/populate/*.cc) | ||||
| file(GLOB CONVERTER_OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cc) | |||||
| file(GLOB_RECURSE CONVERTER_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} | file(GLOB_RECURSE CONVERTER_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} | ||||
| ${CMAKE_CURRENT_SOURCE_DIR}/../flag/flag_parser.cc | ${CMAKE_CURRENT_SOURCE_DIR}/../flag/flag_parser.cc | ||||
| ${CMAKE_CURRENT_SOURCE_DIR}/converter.cc | ${CMAKE_CURRENT_SOURCE_DIR}/converter.cc | ||||
| @@ -145,7 +143,6 @@ ms_build_flatbuffers_lite(TFLITE_FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/parser/tf | |||||
| set_property(SOURCE ${CONVERTER_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | set_property(SOURCE ${CONVERTER_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | ||||
| set_property(SOURCE ${CCSRC_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | set_property(SOURCE ${CCSRC_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | ||||
| set_property(SOURCE ${OPS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | set_property(SOURCE ${OPS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | ||||
| set_property(SOURCE ${CONVERTER_OPS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | |||||
| set_property(SOURCE ${KERNEL_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | set_property(SOURCE ${KERNEL_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | ||||
| set_property(SOURCE ${LITE_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | set_property(SOURCE ${LITE_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) | ||||
| add_executable(converter_lite | add_executable(converter_lite | ||||
| @@ -153,7 +150,6 @@ add_executable(converter_lite | |||||
| ${CCSRC_SRC} | ${CCSRC_SRC} | ||||
| ${CONVERTER_SRC} | ${CONVERTER_SRC} | ||||
| ${OPS_SRC} | ${OPS_SRC} | ||||
| ${CONVERTER_OPS_SRC} | |||||
| ${KERNEL_SRC} | ${KERNEL_SRC} | ||||
| ${LITE_SRC} | ${LITE_SRC} | ||||
| ) | ) | ||||
| @@ -1,56 +0,0 @@ | |||||
| /** | |||||
| * Copyright 2021 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/ops/enter.h" | |||||
| #include "src/tensorlist.h" | |||||
| namespace mindspore { | |||||
| namespace lite { | |||||
| int Enter::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outputs_) { | |||||
| if (!infer_flag()) { | |||||
| return RET_INFER_INVALID; | |||||
| } | |||||
| for (size_t i = 0; i < inputs_.size(); i++) { | |||||
| auto *input = inputs_[i]; | |||||
| auto *output = outputs_[i]; | |||||
| if (input == nullptr) { | |||||
| MS_LOG(ERROR) << "input tensor is nullptr"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| if (output == nullptr) { | |||||
| MS_LOG(ERROR) << "output tensor is nullptr"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| output->set_data_type(input->data_type()); | |||||
| output->set_shape(input->shape()); | |||||
| output->set_format(input->format()); | |||||
| auto data_type = input->data_type(); | |||||
| if (data_type != kObjectTypeTensorType) { | |||||
| continue; | |||||
| } else { | |||||
| auto input_tensorlist = reinterpret_cast<TensorList *>(input); | |||||
| auto output_tensorlist = reinterpret_cast<TensorList *>(output); | |||||
| output_tensorlist->set_element_shape(input_tensorlist->element_shape()); | |||||
| output_tensorlist->set_max_elements_num(input_tensorlist->max_elements_num()); | |||||
| output_tensorlist->set_tensors_data_type(input_tensorlist->tensors_data_type()); | |||||
| } | |||||
| } | |||||
| return RET_OK; | |||||
| } | |||||
| } // namespace lite | |||||
| } // namespace mindspore | |||||
| @@ -31,7 +31,6 @@ class Enter : public PrimitiveC { | |||||
| ~Enter() = default; | ~Enter() = default; | ||||
| MS_DECLARE_PARENT(Enter, PrimitiveC); | MS_DECLARE_PARENT(Enter, PrimitiveC); | ||||
| explicit Enter(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} | explicit Enter(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} | ||||
| int InferShape(std::vector<lite::Tensor *> inputs_, std::vector<lite::Tensor *> outputs_) override; | |||||
| }; | }; | ||||
| } // namespace lite | } // namespace lite | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| @@ -1,56 +0,0 @@ | |||||
| /** | |||||
| * Copyright 2021 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/ops/exit.h" | |||||
| #include "src/tensorlist.h" | |||||
| namespace mindspore { | |||||
| namespace lite { | |||||
| int Exit::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outputs_) { | |||||
| if (!infer_flag()) { | |||||
| return RET_INFER_INVALID; | |||||
| } | |||||
| for (size_t i = 0; i < inputs_.size(); i++) { | |||||
| auto *input = inputs_[i]; | |||||
| auto *output = outputs_[i]; | |||||
| if (input == nullptr) { | |||||
| MS_LOG(ERROR) << "input tensor is nullptr"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| if (output == nullptr) { | |||||
| MS_LOG(ERROR) << "output tensor is nullptr"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| output->set_data_type(input->data_type()); | |||||
| output->set_shape(input->shape()); | |||||
| output->set_format(input->format()); | |||||
| auto data_type = input->data_type(); | |||||
| if (data_type != kObjectTypeTensorType) { | |||||
| continue; | |||||
| } else { | |||||
| auto input_tensorlist = reinterpret_cast<TensorList *>(input); | |||||
| auto output_tensorlist = reinterpret_cast<TensorList *>(output); | |||||
| output_tensorlist->set_element_shape(input_tensorlist->element_shape()); | |||||
| output_tensorlist->set_max_elements_num(input_tensorlist->max_elements_num()); | |||||
| output_tensorlist->set_tensors_data_type(input_tensorlist->tensors_data_type()); | |||||
| } | |||||
| } | |||||
| return RET_OK; | |||||
| } | |||||
| } // namespace lite | |||||
| } // namespace mindspore | |||||
| @@ -31,7 +31,6 @@ class Exit : public PrimitiveC { | |||||
| ~Exit() = default; | ~Exit() = default; | ||||
| MS_DECLARE_PARENT(Exit, PrimitiveC); | MS_DECLARE_PARENT(Exit, PrimitiveC); | ||||
| explicit Exit(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} | explicit Exit(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} | ||||
| int InferShape(std::vector<lite::Tensor *> inputs_, std::vector<lite::Tensor *> outputs_) override; | |||||
| }; | }; | ||||
| } // namespace lite | } // namespace lite | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| @@ -1,56 +0,0 @@ | |||||
| /** | |||||
| * Copyright 2021 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/ops/loop_cond.h" | |||||
| #include "src/tensorlist.h" | |||||
| namespace mindspore { | |||||
| namespace lite { | |||||
| int LoopCond::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outputs_) { | |||||
| if (!infer_flag()) { | |||||
| return RET_INFER_INVALID; | |||||
| } | |||||
| for (size_t i = 0; i < inputs_.size(); i++) { | |||||
| auto *input = inputs_[i]; | |||||
| auto *output = outputs_[i]; | |||||
| if (input == nullptr) { | |||||
| MS_LOG(ERROR) << "input tensor is nullptr"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| if (output == nullptr) { | |||||
| MS_LOG(ERROR) << "output tensor is nullptr"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| output->set_data_type(input->data_type()); | |||||
| output->set_shape(input->shape()); | |||||
| output->set_format(input->format()); | |||||
| auto data_type = input->data_type(); | |||||
| if (data_type != kObjectTypeTensorType) { | |||||
| continue; | |||||
| } else { | |||||
| auto input_tensorlist = reinterpret_cast<TensorList *>(input); | |||||
| auto output_tensorlist = reinterpret_cast<TensorList *>(output); | |||||
| output_tensorlist->set_element_shape(input_tensorlist->element_shape()); | |||||
| output_tensorlist->set_max_elements_num(input_tensorlist->max_elements_num()); | |||||
| output_tensorlist->set_tensors_data_type(input_tensorlist->tensors_data_type()); | |||||
| } | |||||
| } | |||||
| return RET_OK; | |||||
| } | |||||
| } // namespace lite | |||||
| } // namespace mindspore | |||||
| @@ -31,7 +31,6 @@ class LoopCond : public PrimitiveC { | |||||
| ~LoopCond() = default; | ~LoopCond() = default; | ||||
| MS_DECLARE_PARENT(LoopCond, PrimitiveC); | MS_DECLARE_PARENT(LoopCond, PrimitiveC); | ||||
| explicit LoopCond(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} | explicit LoopCond(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} | ||||
| int InferShape(std::vector<lite::Tensor *> inputs_, std::vector<lite::Tensor *> outputs_) override; | |||||
| }; | }; | ||||
| } // namespace lite | } // namespace lite | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| @@ -1,56 +0,0 @@ | |||||
| /** | |||||
| * Copyright 2021 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/ops/next_iteration.h" | |||||
| #include "src/tensorlist.h" | |||||
| namespace mindspore { | |||||
| namespace lite { | |||||
| int NextIteration::InferShape(std::vector<Tensor *> inputs_, std::vector<Tensor *> outputs_) { | |||||
| if (!infer_flag()) { | |||||
| return RET_INFER_INVALID; | |||||
| } | |||||
| for (size_t i = 0; i < inputs_.size(); i++) { | |||||
| auto *input = inputs_[i]; | |||||
| auto *output = outputs_[i]; | |||||
| if (input == nullptr) { | |||||
| MS_LOG(ERROR) << "input tensor is nullptr"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| if (output == nullptr) { | |||||
| MS_LOG(ERROR) << "output tensor is nullptr"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| output->set_data_type(input->data_type()); | |||||
| output->set_shape(input->shape()); | |||||
| output->set_format(input->format()); | |||||
| auto data_type = input->data_type(); | |||||
| if (data_type != kObjectTypeTensorType) { | |||||
| continue; | |||||
| } else { | |||||
| auto input_tensorlist = reinterpret_cast<TensorList *>(input); | |||||
| auto output_tensorlist = reinterpret_cast<TensorList *>(output); | |||||
| output_tensorlist->set_element_shape(input_tensorlist->element_shape()); | |||||
| output_tensorlist->set_max_elements_num(input_tensorlist->max_elements_num()); | |||||
| output_tensorlist->set_tensors_data_type(input_tensorlist->tensors_data_type()); | |||||
| } | |||||
| } | |||||
| return RET_OK; | |||||
| } | |||||
| } // namespace lite | |||||
| } // namespace mindspore | |||||
| @@ -31,7 +31,6 @@ class NextIteration : public PrimitiveC { | |||||
| ~NextIteration() = default; | ~NextIteration() = default; | ||||
| MS_DECLARE_PARENT(NextIteration, PrimitiveC); | MS_DECLARE_PARENT(NextIteration, PrimitiveC); | ||||
| explicit NextIteration(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} | explicit NextIteration(schema::PrimitiveT *primitive) : PrimitiveC(primitive) {} | ||||
| int InferShape(std::vector<lite::Tensor *> inputs_, std::vector<lite::Tensor *> outputs_) override; | |||||
| }; | }; | ||||
| } // namespace lite | } // namespace lite | ||||
| } // namespace mindspore | } // namespace mindspore | ||||