@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -768,64 +768,6 @@ static bool ReadProtoFromCodedInputStream(CodedInputStream &coded_stream, Messag | |||||
return proto->ParseFromCodedStream(&coded_stream); | 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<int>(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) { | FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromBinaryFile(const char *file, Message *proto) { | ||||
if ((file == nullptr) || (proto == nullptr)) { | if ((file == nullptr) || (proto == nullptr)) { | ||||
REPORT_INNER_ERROR("E19999", "param file or proto is nullptr, check invalid"); | REPORT_INNER_ERROR("E19999", "param file or proto is nullptr, check invalid"); | ||||
@@ -85,15 +85,6 @@ std::string RealPath(const char *path); | |||||
uint64_t GetCurrentTimestamp(); | uint64_t GetCurrentTimestamp(); | ||||
/// @ingroup domi_common | /// @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 | /// @brief proto file in bianary format | ||||
/// @param [in] file path of proto file | /// @param [in] file path of proto file | ||||
/// @param [out] proto memory for storing the 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; | 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<int64_t>(a), \ | |||||
static_cast<int64_t>(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<uint64_t>(a), \ | |||||
static_cast<uint32_t>(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<int64_t>(a), \ | |||||
static_cast<int64_t>(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<uint64_t>(a), \ | |||||
static_cast<uint32_t>(b)); \ | |||||
return INTERNAL_ERROR; \ | |||||
} \ | |||||
} while (0) | |||||
} // namespace parser | } // namespace parser | ||||
} // namespace ge | } // namespace ge | ||||
@@ -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"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -3750,27 +3750,8 @@ TEST_F(STestTensorflowParser, tensorflow_GetOriginalType_test) | |||||
EXPECT_EQ(ret, INTERNAL_ERROR); | 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 }; | char path[4096 + 1] = { 0 }; | ||||
memset(path, 'a', 4096); | memset(path, 'a', 4096); | ||||
std::string realPath = parser::RealPath(path); | std::string realPath = parser::RealPath(path); | ||||
@@ -3854,27 +3854,8 @@ TEST_F(UtestTensorflowParser, tensorflow_GetOriginalType_test) | |||||
EXPECT_EQ(ret, INTERNAL_ERROR); | 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 }; | char path[4096 + 1] = { 0 }; | ||||
memset(path, 'a', 4096); | memset(path, 'a', 4096); | ||||
std::string realPath = parser::RealPath(path); | std::string realPath = parser::RealPath(path); | ||||