@@ -24,6 +24,7 @@ | |||
#include "common/fp16_t.h" | |||
#include "common/ge/ge_util.h" | |||
#include "framework/common/debug/ge_log.h" | |||
#include "framework/common/debug/log.h" | |||
#include "graph/utils/type_utils.h" | |||
#include "securec.h" | |||
@@ -123,9 +124,9 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result | |||
std::pair<DataType, DataType> trans_info(args.src_data_type, args.dst_data_type); | |||
auto iter = trans_mode_map.find(trans_info); | |||
if (iter == trans_mode_map.end()) { | |||
std::string error = "Failed to trans data from datatype [" + | |||
TypeUtils::FormatToSerialString(args.src_data_type) + "] to " + "[" + | |||
TypeUtils::FormatToSerialString(args.dst_data_type) + "], it is not supported."; | |||
std::string error = "Failed to trans data from datatype " + | |||
FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)) + " to " + | |||
FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)) + " , it is not supported."; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
@@ -133,14 +134,14 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result | |||
int size = GetSizeByDataType(args.dst_data_type); | |||
if (size <= 0) { | |||
std::string error = "Failed to calc size from data type[" + | |||
TypeUtils::DataTypeToSerialString(args.dst_data_type) + "], it is not supported."; | |||
std::string error = "Failed to calc size from data type" + | |||
FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)) + ", it is not supported."; | |||
GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
return PARAM_INVALID; | |||
} | |||
if (args.src_data_size > static_cast<size_t>(SIZE_MAX / size)) { | |||
std::string error = "args.src_data_size[" + std::to_string(args.src_data_size) + | |||
"] or data type size[" + std::to_string(size) + "is too big"; | |||
std::string error = "args.src_data_size" + FmtToStr(args.src_data_size) + | |||
" or data type size" + FmtToStr(std::to_string(size)) + " is too big"; | |||
GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
return PARAM_INVALID; | |||
} | |||
@@ -158,9 +159,10 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result | |||
} | |||
if (CastKernel(args, dst.get(), args.src_data_size, trans_mode) != SUCCESS) { | |||
std::string error = "Failed to cast data from datatype [" + | |||
TypeUtils::FormatToSerialString(args.src_data_type) + "] to " + "[" + | |||
TypeUtils::FormatToSerialString(args.dst_data_type) + "], data size is " + std::to_string(args.src_data_size); | |||
std::string error = "Failed to cast data from datatype " + | |||
FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)) + " to " + | |||
FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)) + ", data size is " + | |||
FmtToStr(std::to_string(args.src_data_size)); | |||
GE_ERRORLOG_AND_ERRORMSG(INTERNAL_ERROR, error.c_str()); | |||
return INTERNAL_ERROR; | |||
} | |||
@@ -36,16 +36,14 @@ Status CheckArgsForC1hwncoc0ToHwcn(const TransArgs &args) { | |||
auto dst_shape = args.dst_shape; | |||
if (args.src_format != FORMAT_C1HWNCoC0 || args.dst_format != FORMAT_HWCN) { | |||
std::string error = "Dose not support trans format from " + | |||
FmtEgStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtEgStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", | |||
TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
TypeUtils::FormatToSerialString(args.dst_format).c_str()); | |||
FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
if (!CheckDataTypeSupported(args.src_data_type)) { | |||
std::string error = "Failed to trans shape from NC1HWNCoC0 to HWCN, invalid data type[" + | |||
TypeUtils::DataTypeToSerialString(args.src_data_type).c_str() + "]"; | |||
std::string error = "Failed to trans shape from NC1HWNCoC0 to HWCN, invalid data type" + | |||
FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)); | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
@@ -62,8 +60,8 @@ Status CheckArgsForC1hwncoc0ToHwcn(const TransArgs &args) { | |||
src_shape.at(kC1hwncoc0H) != dst_shape.at(kHwcnH) || src_shape.at(kC1hwncoc0W) != dst_shape.at(kHwcnW) || | |||
src_shape.at(kC1hwncoc0N) != dst_shape.at(kHwcnN) || src_shape.at(kC1hwncoc0Co) != cube_size || | |||
src_shape.at(kC1hwncoc0C0) != cube_size) { | |||
std::string error = "Failed to check relationship between src and dst shape, src shape[" + | |||
ShapeToString(src_shape) + "], dst shape[" + ShapeToString(dst_shape) + "]"; | |||
std::string error = "Failed to check relationship between src and dst shape, src shape" + | |||
FmtToStr(ShapeToString(src_shape)) + ", dst shape" + FmtToStr(ShapeToString(dst_shape)); | |||
GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
return PARAM_INVALID; | |||
} | |||
@@ -74,10 +72,9 @@ Status CheckArgsForC1hwncoc0ToHwcn(const TransArgs &args) { | |||
Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, int size, int64_t total_size) { | |||
std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[total_size], std::default_delete<uint8_t[]>()); | |||
if (dst == nullptr) { | |||
std::string error = "Failed to trans format from[" + TypeUtils::FormatToSerialString(args.src_format).c_str() + | |||
"] to [" + TypeUtils::FormatToSerialString(args.dst_format) + "], can not alloc the memory for dst buf[" + | |||
std::to_string(total_size) + "], shape[" + ShapeToString(args.dst_shape) + "]"; | |||
GE_ERRORLOG_AND_ERRORMSG(OUT_OF_MEMORY, error.c_str()); | |||
GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
TypeUtils::FormatToSerialString(args.dst_format).c_str(), total_size, ShapeToString(args.dst_shape).c_str()); | |||
return OUT_OF_MEMORY; | |||
} | |||
@@ -159,8 +159,8 @@ Status TransFormatFromNchwToFz(const TransArgs &args, TransResult &result) { | |||
ret = memset_s(dst.get() + offset, static_cast<size_t>(protected_size), 0, static_cast<size_t>(size)); | |||
} else { | |||
if (protected_size < size) { | |||
std::string error = "Failed to operate the dst memory, protected_size is[" + | |||
std::to_string(protected_size) + "] and size is [" + std::to_string(size) + "]"; | |||
std::string error = "Failed to operate the dst memory, protected_size is " + | |||
FmtToStr(protected_size) + " and size is " + FmtToStr(size); | |||
GE_ERRORLOG_AND_ERRORMSG(INTERNAL_ERROR, error.c_str()); | |||
return INTERNAL_ERROR; | |||
} | |||
@@ -39,8 +39,8 @@ bool CheckShape(Format format, const ShapeVector &shape) { | |||
case FORMAT_NHWC: | |||
return CheckShapeValid(shape, kDimSize4D); | |||
default: | |||
std::string error = "Trans format between[" + TypeUtils::FormatToSerialString(format) + | |||
"] and FORMAT_FRACTAL_ZZ is not supported."; | |||
std::string error = "Trans format between " + FmtToStr(TypeUtils::FormatToSerialString(format)) + | |||
" and FORMAT_FRACTAL_ZZ is not supported."; | |||
GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
return false; | |||
} | |||
@@ -33,9 +33,10 @@ Status CheckArgsForFracZToHwcn(const TransArgs &args) { | |||
auto src_shape = args.src_shape; | |||
auto dst_shape = args.dst_shape; | |||
if (args.src_format != FORMAT_FRACTAL_Z || args.dst_format != FORMAT_HWCN) { | |||
std::string error = "Dose not support trans format from [" + | |||
TypeUtils::FormatToSerialString(args.src_format) + "] to " + "[" + | |||
TypeUtils::FormatToSerialString(args.dst_format) + "]"; | |||
std::string error = "Dose not support trans format from " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
if (!CheckDataTypeSupported(args.src_data_type)) { | |||
@@ -59,8 +60,10 @@ Status CheckArgsForFracZToHwcn(const TransArgs &args) { | |||
int64_t n0 = Ceil(dst_shape.at(kHwcnN), static_cast<int64_t>(kNiSize)); | |||
if (src_shape.at(kFracZHWC1) != dst_shape.at(kHwcnH) * dst_shape.at(kHwcnW) * c1 || src_shape.at(kFracZC0) != c0 || | |||
src_shape.at(kFracZNi) != kNiSize || src_shape.at(kFracZN0) != n0) { | |||
GELOGE(PARAM_INVALID, "Failed to check relationship between src and dst shape, src shape %s, dst shape %s", | |||
ShapeToString(src_shape).c_str(), ShapeToString(dst_shape).c_str()); | |||
std::string error = "Failed to check relationship between src shape" + | |||
FmtToStr(ShapeToString(src_shape)) + " and dst shape" + | |||
FmtToStr(ShapeToString(dst_shape)) + ; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return PARAM_INVALID; | |||
} | |||
@@ -33,9 +33,10 @@ Status CheckArgsForFracZToNchw(const TransArgs &args) { | |||
auto src_shape = args.src_shape; | |||
auto dst_shape = args.dst_shape; | |||
if (args.src_format != FORMAT_FRACTAL_Z || args.dst_format != FORMAT_NCHW) { | |||
GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", | |||
TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
TypeUtils::FormatToSerialString(args.dst_format).c_str()); | |||
std::string error = "Dose not support trans format from " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
if (!CheckDataTypeSupported(args.src_data_type)) { | |||
@@ -33,9 +33,10 @@ Status CheckArgsForFracZToNhwc(const TransArgs &args) { | |||
auto src_shape = args.src_shape; | |||
auto dst_shape = args.dst_shape; | |||
if (args.src_format != FORMAT_FRACTAL_Z || args.dst_format != FORMAT_NHWC) { | |||
GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", | |||
TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
TypeUtils::FormatToSerialString(args.dst_format).c_str()); | |||
std::string error = "Dose not support trans format from " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
if (!CheckDataTypeSupported(args.src_data_type)) { | |||
@@ -50,9 +50,10 @@ Status TransShapeHwcnToC1hwncoc0(const DataType &data_type, const std::vector<in | |||
Status CheckArgsForHwcnToC1hwncoc0(const TransArgs &args) { | |||
if (args.src_format != FORMAT_HWCN || args.dst_format != FORMAT_C1HWNCoC0) { | |||
GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", | |||
TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
TypeUtils::FormatToSerialString(args.dst_format).c_str()); | |||
std::string error = "Dose not support trans format from " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
if (!CheckDataTypeSupported(args.src_data_type)) { | |||
@@ -33,9 +33,10 @@ Status CheckArgsForNc1hwc0ToNchw(const TransArgs &args) { | |||
auto src_shape = args.src_shape; | |||
auto dst_shape = args.dst_shape; | |||
if (args.src_format != FORMAT_NC1HWC0 || args.dst_format != FORMAT_NCHW) { | |||
GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", | |||
TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
TypeUtils::FormatToSerialString(args.dst_format).c_str()); | |||
std::string error = "Dose not support trans format from " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
if (!CheckDataTypeSupported(args.src_data_type)) { | |||
@@ -33,9 +33,10 @@ Status CheckArgsForNc1hwc0ToNhwc(const TransArgs &args) { | |||
auto src_shape = args.src_shape; | |||
auto dst_shape = args.dst_shape; | |||
if (args.src_format != FORMAT_NC1HWC0 || args.dst_format != FORMAT_NHWC) { | |||
GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", | |||
TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
TypeUtils::FormatToSerialString(args.dst_format).c_str()); | |||
std::string error = "Dose not support trans format from " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
if (!CheckDataTypeSupported(args.src_data_type)) { | |||
@@ -53,9 +53,10 @@ Status TransShapeNchwToNc1hwc0(const std::vector<int64_t> &src_shape, DataType d | |||
Status CheckArgsForNchwToNc1hwc0(const TransArgs &args) { | |||
if (args.src_format != FORMAT_NCHW || args.dst_format != FORMAT_NC1HWC0) { | |||
GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", | |||
TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
TypeUtils::FormatToSerialString(args.dst_format).c_str()); | |||
std::string error = "Dose not support trans format from " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
std::vector<int64_t> expect_5d_shape; | |||
@@ -51,9 +51,10 @@ Status TransShapeNhwcToNc1hwc0(const std::vector<int64_t> &src_shape, DataType d | |||
Status CheckArgsForNhwcToNc1hwc0(const TransArgs &args) { | |||
if (args.src_format != FORMAT_NHWC || args.dst_format != FORMAT_NC1HWC0) { | |||
GELOGE(UNSUPPORTED, "Does not support trans format from %s to %s", | |||
TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
TypeUtils::FormatToSerialString(args.dst_format).c_str()); | |||
std::string error = "Dose not support trans format from " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)) + ; | |||
GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
return UNSUPPORTED; | |||
} | |||
if (!CheckDataTypeSupported(args.src_data_type)) { | |||
@@ -223,7 +223,7 @@ Status FormatTransferTranspose::TransFormat(const TransArgs &args, TransResult & | |||
if (ret != SUCCESS) { | |||
return ret; | |||
} | |||
if (!IsTransShapeDstCorrect(args, expect_shape)) { | |||
if (!IsTransShapeDstCorrect(args, expected_shape)) { | |||
return PARAM_INVALID; | |||
} | |||
@@ -20,6 +20,7 @@ | |||
#include "common/formats/utils/formats_definitions.h" | |||
#include "framework/common/debug/ge_log.h" | |||
#include "framework/common/debug/log.h" | |||
#include "framework/common/ge_inner_error_codes.h" | |||
#include "graph/utils/type_utils.h" | |||
@@ -58,9 +59,8 @@ int64_t GetItemNumByShape(const std::vector<int64_t> &shape) { | |||
bool CheckShapeValid(const std::vector<int64_t> &shape, const int64_t expect_dims) { | |||
if (expect_dims <= 0 || shape.size() != static_cast<size_t>(expect_dims)) { | |||
std::string error = " Invalid shape, dims num [" + std::to_string(shape.size()) + | |||
"], expect [" + std::to_string(expect_dims) + "]"; | |||
TypeUtils::DataTypeToSerialString(data_type) + "] is invalid"; | |||
std::string error = " Invalid shape, dims num " + FmtToStr(shape.size()) + | |||
", expect " + FmtToStr(expect_dims); | |||
GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
return false; | |||
} | |||
@@ -74,13 +74,12 @@ bool IsShapeValid(const std::vector<int64_t> &shape) { | |||
int64_t num = 1; | |||
for (auto dim : shape) { | |||
if (dim < 0) { | |||
std::string error = "Invalid negative dims in the shape [" + ShapeToString(shape).c_str() + "]"; | |||
std::string error = "Invalid negative dims in the shape " + FmtToStr(ShapeToString(shape)); | |||
GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
return false; | |||
} | |||
if (dim != 0 && kShapeItemNumMAX / dim < num) { | |||
std::string error = "Shape overflow, the total count should be less than [" + | |||
std::to_string(kShapeItemNumMAX) + "]"; | |||
std::string error = "Shape overflow, the total count should be less than " + FmtToStr(kShapeItemNumMAX); | |||
GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
return false; | |||
} | |||
@@ -271,7 +271,7 @@ | |||
} while (0) | |||
template <typename T> | |||
std::string FmtEgStr(const T &t) { | |||
std::string FmtToStr(const T &t) { | |||
std::string fmt; | |||
std::stringstream st; | |||
st << "[" << t << "]"; | |||