From 7cbb23fe41f229a17df145e23a1e148eab6f7397 Mon Sep 17 00:00:00 2001 From: yangyongqiang Date: Tue, 1 Nov 2022 17:12:38 +0000 Subject: [PATCH] !722 code clean Merge pull request !722 from yangyongqiang/code_clean --- inc/external/parser/caffe_parser.h | 2 +- inc/external/parser/onnx_parser.h | 2 +- inc/external/parser/tensorflow_parser.h | 2 +- parser/caffe/caffe_custom_parser_adapter.h | 2 +- parser/caffe/caffe_data_parser.h | 2 +- parser/caffe/caffe_op_parser.h | 2 +- parser/caffe/caffe_parser.cc | 2 +- parser/caffe/caffe_parser.h | 2 +- parser/caffe/caffe_reshape_parser.cc | 2 +- parser/caffe/caffe_reshape_parser.h | 2 +- parser/common/acl_graph_parser_util.cc | 58 ---------------------- parser/common/acl_graph_parser_util.h | 39 +++++++-------- .../common/auto_mapping_subgraph_io_index_func.h | 2 +- tests/st/testcase/test_tensorflow_parser.cc | 21 +------- .../tensorflow_parser_unittest.cc | 21 +------- 15 files changed, 30 insertions(+), 131 deletions(-) diff --git a/inc/external/parser/caffe_parser.h b/inc/external/parser/caffe_parser.h index 5b1799a..964f95f 100644 --- a/inc/external/parser/caffe_parser.h +++ b/inc/external/parser/caffe_parser.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/inc/external/parser/onnx_parser.h b/inc/external/parser/onnx_parser.h index cbfa6a2..88c8d49 100644 --- a/inc/external/parser/onnx_parser.h +++ b/inc/external/parser/onnx_parser.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/inc/external/parser/tensorflow_parser.h b/inc/external/parser/tensorflow_parser.h index e2ede65..fc0389e 100644 --- a/inc/external/parser/tensorflow_parser.h +++ b/inc/external/parser/tensorflow_parser.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/caffe/caffe_custom_parser_adapter.h b/parser/caffe/caffe_custom_parser_adapter.h index 2a821c9..48428e8 100644 --- a/parser/caffe/caffe_custom_parser_adapter.h +++ b/parser/caffe/caffe_custom_parser_adapter.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/caffe/caffe_data_parser.h b/parser/caffe/caffe_data_parser.h index dfa5d5c..6ed38ef 100644 --- a/parser/caffe/caffe_data_parser.h +++ b/parser/caffe/caffe_data_parser.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/caffe/caffe_op_parser.h b/parser/caffe/caffe_op_parser.h index 5cb87d8..a565eca 100644 --- a/parser/caffe/caffe_op_parser.h +++ b/parser/caffe/caffe_op_parser.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/caffe/caffe_parser.cc b/parser/caffe/caffe_parser.cc index 8bad0d2..17a5bbe 100644 --- a/parser/caffe/caffe_parser.cc +++ b/parser/caffe/caffe_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/caffe/caffe_parser.h b/parser/caffe/caffe_parser.h index dd2747b..3614216 100644 --- a/parser/caffe/caffe_parser.h +++ b/parser/caffe/caffe_parser.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/caffe/caffe_reshape_parser.cc b/parser/caffe/caffe_reshape_parser.cc index 44cce1d..16c99e0 100644 --- a/parser/caffe/caffe_reshape_parser.cc +++ b/parser/caffe/caffe_reshape_parser.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/caffe/caffe_reshape_parser.h b/parser/caffe/caffe_reshape_parser.h index 9be90b6..fc05f4c 100644 --- a/parser/caffe/caffe_reshape_parser.h +++ b/parser/caffe/caffe_reshape_parser.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2020~2022. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/parser/common/acl_graph_parser_util.cc b/parser/common/acl_graph_parser_util.cc index 9412baf..7f1261c 100644 --- a/parser/common/acl_graph_parser_util.cc +++ b/parser/common/acl_graph_parser_util.cc @@ -768,64 +768,6 @@ static bool ReadProtoFromCodedInputStream(CodedInputStream &coded_stream, Messag return proto->ParseFromCodedStream(&coded_stream); } -/** @ingroup domi_common - * @brief Read all data from binary file - * @param [in] file_name File path - * @param [out] buffer The address of the output memory, which needs to be released by the caller - * @param [out] length Output memory size - * @return false fail - * @return true success - */ -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadBytesFromBinaryFile(const char *file_name, char **buffer, - int &length) { - if (file_name == nullptr) { - REPORT_INNER_ERROR("E19999", "param file_name is nullptr, check invalid"); - GELOGE(FAILED, "[Check][Param] incorrect parameter. file is nullptr"); - return false; - } - if (buffer == nullptr) { - REPORT_INNER_ERROR("E19999", "param buffer is nullptr, check invalid"); - GELOGE(FAILED, "[Check][Param] incorrect parameter. buffer is nullptr"); - return false; - } - - std::string real_path = RealPath(file_name); - if (real_path.empty()) { - REPORT_INNER_ERROR("E19999", "file path '%s' not valid, realpath failed", file_name); - GELOGE(FAILED, "[Check][Param]file path '%s' not valid, realpath failed", file_name); - return false; - } - - std::ifstream file(real_path.c_str(), std::ios::binary | std::ios::ate); - if (!file.is_open()) { - REPORT_INNER_ERROR("E19999", "read file %s failed", file_name); - GELOGE(ge::FAILED, "[Read][File] %s failed.", file_name); - return false; - } - - length = static_cast(file.tellg()); - if ((length <= 0)) { - file.close(); - REPORT_INNER_ERROR("E19999", "file length <= 0"); - GELOGE(FAILED, "[Check][Param] file length <= 0"); - return false; - } - - file.seekg(0, std::ios::beg); - - *buffer = new(std::nothrow) char[length](); - if (*buffer == nullptr) { - REPORT_INNER_ERROR("E19999", "[Create][Buffer] new an object failed, length=%d.", length); - GELOGE(FAILED, "[Create][Buffer] new an object failed, length=%d.", length); - file.close(); - return false; - } - - file.read(*buffer, length); - file.close(); - return true; -} - FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromBinaryFile(const char *file, Message *proto) { if ((file == nullptr) || (proto == nullptr)) { REPORT_INNER_ERROR("E19999", "param file or proto is nullptr, check invalid"); diff --git a/parser/common/acl_graph_parser_util.h b/parser/common/acl_graph_parser_util.h index bfd6790..6a0676c 100644 --- a/parser/common/acl_graph_parser_util.h +++ b/parser/common/acl_graph_parser_util.h @@ -85,15 +85,6 @@ std::string RealPath(const char *path); uint64_t GetCurrentTimestamp(); /// @ingroup domi_common -/// @brief Reads all data from a binary file. -/// @param [in] file_name path of file -/// @param [out] buffer Output memory address, which needs to be released by the caller. -/// @param [out] length Output memory size -/// @return false fail -/// @return true success -bool ReadBytesFromBinaryFile(const char *file_name, char **buffer, int &length); - -/// @ingroup domi_common /// @brief proto file in bianary format /// @param [in] file path of proto file /// @param [out] proto memory for storing the proto file @@ -195,19 +186,23 @@ inline domi::Status CheckInt64Uint32MulOverflow(int64_t a, uint32_t b) { return domi::SUCCESS; } -#define PARSER_INT64_MULCHECK(a, b) \ - if (ge::parser::Int64MulCheckOverflow((a), (b)) != SUCCESS) { \ - GELOGW("Int64 %ld and %ld multiplication can result in overflow!", static_cast(a), \ - static_cast(b)); \ - return INTERNAL_ERROR; \ - } - -#define PARSER_INT64_UINT32_MULCHECK(a, b) \ - if (ge::parser::CheckInt64Uint32MulOverflow((a), (b)) != SUCCESS) { \ - GELOGW("Int64 %ld and Uint32 %u multiplication can result in overflow!", static_cast(a), \ - static_cast(b)); \ - return INTERNAL_ERROR; \ - } +#define PARSER_INT64_MULCHECK(a, b) \ + do { \ + if (ge::parser::Int64MulCheckOverflow((a), (b)) != SUCCESS) { \ + GELOGW("Int64 %ld and %ld multiplication can result in overflow!", static_cast(a), \ + static_cast(b)); \ + return INTERNAL_ERROR; \ + } \ + } while (0) + +#define PARSER_INT64_UINT32_MULCHECK(a, b) \ + do { \ + if (ge::parser::CheckInt64Uint32MulOverflow((a), (b)) != SUCCESS) { \ + GELOGW("Int64 %ld and Uint32 %u multiplication can result in overflow!", static_cast(a), \ + static_cast(b)); \ + return INTERNAL_ERROR; \ + } \ + } while (0) } // namespace parser } // namespace ge diff --git a/parser/common/auto_mapping_subgraph_io_index_func.h b/parser/common/auto_mapping_subgraph_io_index_func.h index 7a1823d..868644c 100644 --- a/parser/common/auto_mapping_subgraph_io_index_func.h +++ b/parser/common/auto_mapping_subgraph_io_index_func.h @@ -1,5 +1,5 @@ /** - * Copyright (c) Huawei Technologies Co., Ltd. 2019~2021. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/st/testcase/test_tensorflow_parser.cc b/tests/st/testcase/test_tensorflow_parser.cc index e178c71..07eccd9 100644 --- a/tests/st/testcase/test_tensorflow_parser.cc +++ b/tests/st/testcase/test_tensorflow_parser.cc @@ -3750,27 +3750,8 @@ TEST_F(STestTensorflowParser, tensorflow_GetOriginalType_test) EXPECT_EQ(ret, INTERNAL_ERROR); } -TEST_F(STestTensorflowParser, tensorflow_ReadBytesFromBinaryFile_test) +TEST_F(STestTensorflowParser, tensorflow_realpath_test) { - const char *file_name = nullptr; - char *buffer = nullptr; - int length = 1; - bool ret = parser::ReadBytesFromBinaryFile(file_name, &buffer, length); - EXPECT_EQ(ret, false); - - file_name = "./caffe.proto"; - ret = parser::ReadBytesFromBinaryFile(file_name, &buffer, length); - EXPECT_EQ(ret, false); - - std::cout << __FILE__ << std::endl; - std::string caseDir = __FILE__; - std::size_t idx = caseDir.find_last_of("/"); - caseDir = caseDir.substr(0, idx); - std::string proto_file = caseDir + "/origin_models/caffe.proto"; - file_name = proto_file.c_str(); - ret = parser::ReadBytesFromBinaryFile(file_name, &buffer, length); - EXPECT_EQ(ret, true); - char path[4096 + 1] = { 0 }; memset(path, 'a', 4096); std::string realPath = parser::RealPath(path); diff --git a/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc b/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc index 168b409..ab86e2e 100644 --- a/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc +++ b/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc @@ -3854,27 +3854,8 @@ TEST_F(UtestTensorflowParser, tensorflow_GetOriginalType_test) EXPECT_EQ(ret, INTERNAL_ERROR); } -TEST_F(UtestTensorflowParser, tensorflow_ReadBytesFromBinaryFile_test) +TEST_F(UtestTensorflowParser, tensorflow_realpath_test) { - const char *file_name = nullptr; - char *buffer = nullptr; - int length = 1; - bool ret = parser::ReadBytesFromBinaryFile(file_name, &buffer, length); - EXPECT_EQ(ret, false); - - file_name = "./caffe.proto"; - ret = parser::ReadBytesFromBinaryFile(file_name, &buffer, length); - EXPECT_EQ(ret, false); - - std::cout << __FILE__ << std::endl; - std::string caseDir = __FILE__; - std::size_t idx = caseDir.find_last_of("/"); - caseDir = caseDir.substr(0, idx); - std::string proto_file = caseDir + "/tensorflow_model/caffe.proto"; - file_name = proto_file.c_str(); - ret = parser::ReadBytesFromBinaryFile(file_name, &buffer, length); - EXPECT_EQ(ret, true); - char path[4096 + 1] = { 0 }; memset(path, 'a', 4096); std::string realPath = parser::RealPath(path);