From 087b9f67502103437ca4ead3db21c38ccd362592 Mon Sep 17 00:00:00 2001 From: huangbingjian Date: Fri, 6 May 2022 11:31:44 +0800 Subject: [PATCH] Modify the printing information of type id --- .../common/session/anf_runtime_algorithm.cc | 2 +- .../ccsrc/common/debug/anf_dump_utils.cc | 18 --- .../include/common/debug/anf_dump_utils.h | 1 - mindspore/ccsrc/kernel/kernel_build_info.cc | 4 +- .../device/gpu/kernel/kernel_constants.h | 9 +- .../device/gpu/kernel/nccl/nccl_gpu_kernel.h | 7 +- mindspore/core/ir/dtype/type.cc | 107 +++++++++--------- tests/ut/cpp/ir/dtype_test.cc | 43 ------- 8 files changed, 62 insertions(+), 129 deletions(-) diff --git a/mindspore/ccsrc/backend/common/session/anf_runtime_algorithm.cc b/mindspore/ccsrc/backend/common/session/anf_runtime_algorithm.cc index 730e0972d2f..c60f68bee0e 100644 --- a/mindspore/ccsrc/backend/common/session/anf_runtime_algorithm.cc +++ b/mindspore/ccsrc/backend/common/session/anf_runtime_algorithm.cc @@ -85,7 +85,7 @@ static std::map, std::map &shape) { std::ostringstream buffer; - buffer << "<" << TypeToShortString(type); + buffer << "<" << TypeIdLabel(type); if (!fmt.empty()) { buffer << "x" << fmt << shape; } diff --git a/mindspore/ccsrc/common/debug/anf_dump_utils.cc b/mindspore/ccsrc/common/debug/anf_dump_utils.cc index 03fb1f1ede4..1f08e600c05 100644 --- a/mindspore/ccsrc/common/debug/anf_dump_utils.cc +++ b/mindspore/ccsrc/common/debug/anf_dump_utils.cc @@ -73,24 +73,6 @@ std::string GetNodeFuncStr(const AnfNodePtr &nd) { return GetAbstractFuncStr(abs_func); } -std::string TypeToShortString(const TypeId &typeId) { - std::string label = TypeIdLabel(typeId); - std::string prefix = "kNumberType"; - if (prefix.length() > label.length()) { - return label; - } - auto position = label.find(prefix); - // Position is 0 when label begins with prefix - if (position != 0) { - return label; - } - auto sub_position = position + prefix.length(); - if (sub_position >= label.length()) { - return label; - } - return label.substr(sub_position); -} - std::string GetKernelNodeName(const AnfNodePtr &anf_node) { MS_EXCEPTION_IF_NULL(anf_node); std::string kernel_name = anf_node->fullname_with_scope(); diff --git a/mindspore/ccsrc/include/common/debug/anf_dump_utils.h b/mindspore/ccsrc/include/common/debug/anf_dump_utils.h index 7edee3614b2..ad4520c0c5f 100644 --- a/mindspore/ccsrc/include/common/debug/anf_dump_utils.h +++ b/mindspore/ccsrc/include/common/debug/anf_dump_utils.h @@ -27,7 +27,6 @@ namespace mindspore { COMMON_EXPORT std::string GetNodeFuncStr(const AnfNodePtr &nd); -COMMON_EXPORT std::string TypeToShortString(const TypeId &typeId); COMMON_EXPORT std::string GetKernelNodeName(const AnfNodePtr &anf_node); class COMMON_EXPORT AnfDumpHandler { diff --git a/mindspore/ccsrc/kernel/kernel_build_info.cc b/mindspore/ccsrc/kernel/kernel_build_info.cc index 90c1e3b2c43..442bc8459f3 100644 --- a/mindspore/ccsrc/kernel/kernel_build_info.cc +++ b/mindspore/ccsrc/kernel/kernel_build_info.cc @@ -136,14 +136,14 @@ std::string KernelBuildInfo::ToString() const { if (index != 0) { output_buffer << ", "; } - output_buffer << "<" << TypeToShortString(GetInputDeviceType(index)) << "x" << GetInputFormat(index) << ">"; + output_buffer << "<" << TypeIdLabel(GetInputDeviceType(index)) << "x" << GetInputFormat(index) << ">"; } output_buffer << ") -> ("; for (size_t index = 0; index < GetOutputNum(); ++index) { if (index != 0) { output_buffer << ", "; } - output_buffer << "<" << TypeToShortString(GetOutputDeviceType(index)) << "x" << GetOutputFormat(index) << ">"; + output_buffer << "<" << TypeIdLabel(GetOutputDeviceType(index)) << "x" << GetOutputFormat(index) << ">"; } output_buffer << ")"; return output_buffer.str(); diff --git a/mindspore/ccsrc/plugin/device/gpu/kernel/kernel_constants.h b/mindspore/ccsrc/plugin/device/gpu/kernel/kernel_constants.h index 280f50fa4d2..a3d7d03996b 100644 --- a/mindspore/ccsrc/plugin/device/gpu/kernel/kernel_constants.h +++ b/mindspore/ccsrc/plugin/device/gpu/kernel/kernel_constants.h @@ -56,13 +56,12 @@ static constexpr float kSignedMinFloat = -3.402823466e+38F; // Used by mixprecision, cudnn dtype select static std::map kCudnnDtypeMap = { - {"kNumberTypeFloat32", CUDNN_DATA_FLOAT}, {"kNumberTypeFloat16", CUDNN_DATA_HALF}, - {"kNumberTypeFloat64", CUDNN_DATA_DOUBLE}, {"kNumberTypeInt32", CUDNN_DATA_INT32}, - {"kNumberTypeBool", CUDNN_DATA_INT8}, {"kNumberTypeInt8", CUDNN_DATA_INT8}, - {"kNumberTypeUInt8", CUDNN_DATA_UINT8}}; + {"Float32", CUDNN_DATA_FLOAT}, {"Float16", CUDNN_DATA_HALF}, {"Float64", CUDNN_DATA_DOUBLE}, + {"Int32", CUDNN_DATA_INT32}, {"Bool", CUDNN_DATA_INT8}, {"Int8", CUDNN_DATA_INT8}, + {"UInt8", CUDNN_DATA_UINT8}}; // Used by mixprecision, cuda dtype select static std::map kCudaDtypeMap = { - {"kNumberTypeFloat64", CUDA_R_64F}, {"kNumberTypeFloat32", CUDA_R_32F}, {"kNumberTypeFloat16", CUDA_R_16F}}; + {"Float64", CUDA_R_64F}, {"Float32", CUDA_R_32F}, {"Float16", CUDA_R_16F}}; } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/plugin/device/gpu/kernel/nccl/nccl_gpu_kernel.h b/mindspore/ccsrc/plugin/device/gpu/kernel/nccl/nccl_gpu_kernel.h index c65e5c894f6..44d79c19fed 100644 --- a/mindspore/ccsrc/plugin/device/gpu/kernel/nccl/nccl_gpu_kernel.h +++ b/mindspore/ccsrc/plugin/device/gpu/kernel/nccl/nccl_gpu_kernel.h @@ -32,10 +32,9 @@ namespace mindspore { namespace kernel { using NvidiaCollectiveCommLib = device::gpu::NvidiaCollectiveCommLib; static std::map kNcclDtypeMap = { - {"kNumberTypeBool", ncclUint8}, {"kNumberTypeInt8", ncclInt8}, {"kNumberTypeInt32", ncclInt32}, - {"kNumberTypeInt64", ncclInt64}, {"kNumberTypeUInt8", ncclUint8}, {"kNumberTypeUInt32", ncclUint32}, - {"kNumberTypeUInt64", ncclUint64}, {"kNumberTypeFloat16", ncclFloat16}, {"kNumberTypeFloat32", ncclFloat32}, - {"kNumberTypeFloat64", ncclFloat64}}; + {"Bool", ncclUint8}, {"Int8", ncclInt8}, {"Int32", ncclInt32}, {"Int64", ncclInt64}, + {"UInt8", ncclUint8}, {"UInt32", ncclUint32}, {"UInt64", ncclUint64}, {"Float16", ncclFloat16}, + {"Float32", ncclFloat32}, {"Float64", ncclFloat64}}; typedef ncclResult_t (*AllReduce)(const void *, void *, size_t, ncclDataType_t, ncclRedOp_t, cudaStream_t, const std::string &); diff --git a/mindspore/core/ir/dtype/type.cc b/mindspore/core/ir/dtype/type.cc index e63d20f0e55..2b94a3b06dc 100644 --- a/mindspore/core/ir/dtype/type.cc +++ b/mindspore/core/ir/dtype/type.cc @@ -27,61 +27,58 @@ #include "utils/convert_utils_base.h" namespace mindspore { -#define MS_TYPE2LABLE(type_id) #type_id -static mindspore::HashMap g_type_2_lable{ - {kTypeUnknown, MS_TYPE2LABLE(kTypeUnknown)}, - {kMetaTypeType, MS_TYPE2LABLE(kMetaTypeType)}, - {kMetaTypeAnything, MS_TYPE2LABLE(kMetaTypeAnything)}, - {kMetaTypeObject, MS_TYPE2LABLE(kMetaTypeObject)}, - {kMetaTypeTypeType, MS_TYPE2LABLE(kMetaTypeTypeType)}, - {kMetaTypeProblem, MS_TYPE2LABLE(kMetaTypeProblem)}, - {kMetaTypeExternal, MS_TYPE2LABLE(kMetaTypeExternal)}, - {kMetaTypeNone, MS_TYPE2LABLE(kMetaTypeNone)}, - {kMetaTypeNull, MS_TYPE2LABLE(kMetaTypeNull)}, - {kMetaTypeEllipsis, MS_TYPE2LABLE(kMetaTypeEllipsis)}, - {kMetaTypeEnd, MS_TYPE2LABLE(kMetaTypeEnd)}, - {kObjectTypeNumber, MS_TYPE2LABLE(kObjectTypeNumber)}, - {kObjectTypeString, MS_TYPE2LABLE(kObjectTypeString)}, - {kObjectTypeList, MS_TYPE2LABLE(kObjectTypeList)}, - {kObjectTypeTuple, MS_TYPE2LABLE(kObjectTypeTuple)}, - {kObjectTypeSlice, MS_TYPE2LABLE(kObjectTypeSlice)}, - {kObjectTypeKeyword, MS_TYPE2LABLE(kObjectTypeKeyword)}, - {kObjectTypeTensorType, MS_TYPE2LABLE(kObjectTypeTensorType)}, - {kObjectTypeRowTensorType, MS_TYPE2LABLE(kObjectTypeRowTensorType)}, - {kObjectTypeCOOTensorType, MS_TYPE2LABLE(kObjectTypeCOOTensorType)}, - {kObjectTypeCSRTensorType, MS_TYPE2LABLE(kObjectTypeCSRTensorType)}, - {kObjectTypeUndeterminedType, MS_TYPE2LABLE(kObjectTypeUndeterminedType)}, - {kObjectTypeClass, MS_TYPE2LABLE(kObjectTypeClass)}, - {kObjectTypeDictionary, MS_TYPE2LABLE(kObjectTypeDictionary)}, - {kObjectTypeFunction, MS_TYPE2LABLE(kObjectTypeFunction)}, - {kObjectTypeJTagged, MS_TYPE2LABLE(kObjectTypeJTagged)}, - {kObjectTypeSymbolicKeyType, MS_TYPE2LABLE(kObjectTypeSymbolicKeyType)}, - {kObjectTypeEnvType, MS_TYPE2LABLE(kObjectTypeEnvType)}, - {kObjectTypeRefKey, MS_TYPE2LABLE(kObjectTypeRefKey)}, - {kObjectTypeRef, MS_TYPE2LABLE(kObjectTypeRef)}, - {kObjectTypeEnd, MS_TYPE2LABLE(kObjectTypeEnd)}, - {kNumberTypeBool, MS_TYPE2LABLE(kNumberTypeBool)}, - {kNumberTypeInt, MS_TYPE2LABLE(kNumberTypeInt)}, - {kNumberTypeInt8, MS_TYPE2LABLE(kNumberTypeInt8)}, - {kNumberTypeInt16, MS_TYPE2LABLE(kNumberTypeInt16)}, - {kNumberTypeInt32, MS_TYPE2LABLE(kNumberTypeInt32)}, - {kNumberTypeInt64, MS_TYPE2LABLE(kNumberTypeInt64)}, - {kNumberTypeUInt, MS_TYPE2LABLE(kNumberTypeUInt)}, - {kNumberTypeUInt8, MS_TYPE2LABLE(kNumberTypeUInt8)}, - {kNumberTypeUInt16, MS_TYPE2LABLE(kNumberTypeUInt16)}, - {kNumberTypeUInt32, MS_TYPE2LABLE(kNumberTypeUInt32)}, - {kNumberTypeUInt64, MS_TYPE2LABLE(kNumberTypeUInt64)}, - {kNumberTypeFloat, MS_TYPE2LABLE(kNumberTypeFloat)}, - {kNumberTypeFloat16, MS_TYPE2LABLE(kNumberTypeFloat16)}, - {kNumberTypeFloat32, MS_TYPE2LABLE(kNumberTypeFloat32)}, - {kNumberTypeFloat64, MS_TYPE2LABLE(kNumberTypeFloat64)}, - {kNumberTypeComplex64, MS_TYPE2LABLE(kNumberTypeComplex64)}, - {kNumberTypeComplex128, MS_TYPE2LABLE(kNumberTypeComplex128)}, - {kNumberTypeEnd, MS_TYPE2LABLE(kNumberTypeEnd)}, - {kObjectTypeMonad, MS_TYPE2LABLE(kObjectTypeMonad)}, - {kObjectTypeUMonad, MS_TYPE2LABLE(kObjectTypeUMonad)}, - {kObjectTypeIOMonad, MS_TYPE2LABLE(kObjectTypeIOMonad)}, - {kMonadTypeEnd, MS_TYPE2LABLE(kMonadTypeEnd)}}; +static mindspore::HashMap g_type_2_lable{{kTypeUnknown, "Unknown"}, + {kMetaTypeType, "Type"}, + {kMetaTypeAnything, "Anything"}, + {kMetaTypeObject, "Object"}, + {kMetaTypeTypeType, "TypeType"}, + {kMetaTypeProblem, "Problem"}, + {kMetaTypeExternal, "External"}, + {kMetaTypeNone, "None"}, + {kMetaTypeNull, "Null"}, + {kMetaTypeEllipsis, "Ellipsis"}, + {kObjectTypeNumber, "Number"}, + {kObjectTypeString, "String"}, + {kObjectTypeList, "List"}, + {kObjectTypeTuple, "Tuple"}, + {kObjectTypeSlice, "Slice"}, + {kObjectTypeKeyword, "Keyword"}, + {kObjectTypeTensorType, "Tensor"}, + {kObjectTypeRowTensorType, "RowTensor"}, + {kObjectTypeCOOTensorType, "COOTensor"}, + {kObjectTypeCSRTensorType, "CSRTensor"}, + {kObjectTypeUndeterminedType, "Undetermined"}, + {kObjectTypeClass, "Class"}, + {kObjectTypeDictionary, "Dictionary"}, + {kObjectTypeFunction, "Function"}, + {kObjectTypeJTagged, "JTagged"}, + {kObjectTypeSymbolicKeyType, "SymbolicKey"}, + {kObjectTypeEnvType, "EnvType"}, + {kObjectTypeRefKey, "RefKey"}, + {kObjectTypeRef, "Ref"}, + {kNumberTypeBool, "Bool"}, + {kNumberTypeInt, "Int"}, + {kNumberTypeInt8, "Int8"}, + {kNumberTypeInt16, "Int16"}, + {kNumberTypeInt32, "Int32"}, + {kNumberTypeInt64, "Int64"}, + {kNumberTypeUInt, "UInt"}, + {kNumberTypeUInt8, "UInt8"}, + {kNumberTypeUInt16, "UInt16"}, + {kNumberTypeUInt32, "UInt32"}, + {kNumberTypeUInt64, "UInt64"}, + {kNumberTypeFloat, "Float"}, + {kNumberTypeFloat16, "Float16"}, + {kNumberTypeFloat32, "Float32"}, + {kNumberTypeFloat64, "Float64"}, + {kNumberTypeComplex, "Complex"}, + {kNumberTypeComplex64, "Complex64"}, + {kNumberTypeComplex128, "Complex128"}, + {kNumberTypeInt4, "Int4"}, + {kNumberTypeGLUInt, "GLUInt"}, + {kObjectTypeMonad, "Monad"}, + {kObjectTypeUMonad, "UMonad"}, + {kObjectTypeIOMonad, "IOMonad"}}; TypeId IntBitsToTypeId(const int nbits) { switch (nbits) { diff --git a/tests/ut/cpp/ir/dtype_test.cc b/tests/ut/cpp/ir/dtype_test.cc index d15abf395cb..fdb0cce9400 100644 --- a/tests/ut/cpp/ir/dtype_test.cc +++ b/tests/ut/cpp/ir/dtype_test.cc @@ -191,49 +191,6 @@ TEST_F(TestDType, TestTypeIdNormalize) { ASSERT_EQ(kNumberTypeBool, NormalizeTypeId(kNumberTypeBool)); } - -TEST_F(TestDType, TestTypeIdLabel) { -#define TEST_DTYPE_LABEL(type) ASSERT_EQ((#type), std::string(TypeIdLabel(type))) - - TEST_DTYPE_LABEL(kMetaTypeType); - TEST_DTYPE_LABEL(kMetaTypeAnything); - TEST_DTYPE_LABEL(kMetaTypeObject); - TEST_DTYPE_LABEL(kMetaTypeTypeType); - TEST_DTYPE_LABEL(kMetaTypeProblem); - TEST_DTYPE_LABEL(kMetaTypeExternal); - TEST_DTYPE_LABEL(kMetaTypeNone); - - // Object types - TEST_DTYPE_LABEL(kObjectTypeNumber); - TEST_DTYPE_LABEL(kObjectTypeList); - TEST_DTYPE_LABEL(kObjectTypeTuple); - TEST_DTYPE_LABEL(kObjectTypeTensorType); - TEST_DTYPE_LABEL(kObjectTypeClass); - TEST_DTYPE_LABEL(kObjectTypeFunction); - TEST_DTYPE_LABEL(kObjectTypeJTagged); - TEST_DTYPE_LABEL(kObjectTypeSymbolicKeyType); - TEST_DTYPE_LABEL(kObjectTypeEnvType); - TEST_DTYPE_LABEL(kObjectTypeRefKey); - TEST_DTYPE_LABEL(kObjectTypeRef); - - // Number Types - TEST_DTYPE_LABEL(kNumberTypeBool); - TEST_DTYPE_LABEL(kNumberTypeInt); - TEST_DTYPE_LABEL(kNumberTypeInt8); - TEST_DTYPE_LABEL(kNumberTypeInt16); - TEST_DTYPE_LABEL(kNumberTypeInt32); - TEST_DTYPE_LABEL(kNumberTypeInt64); - TEST_DTYPE_LABEL(kNumberTypeUInt); - TEST_DTYPE_LABEL(kNumberTypeUInt8); - TEST_DTYPE_LABEL(kNumberTypeUInt16); - TEST_DTYPE_LABEL(kNumberTypeUInt32); - TEST_DTYPE_LABEL(kNumberTypeUInt64); - TEST_DTYPE_LABEL(kNumberTypeFloat); - TEST_DTYPE_LABEL(kNumberTypeFloat16); - TEST_DTYPE_LABEL(kNumberTypeFloat32); - TEST_DTYPE_LABEL(kNumberTypeFloat64); -} - } // namespace mindspore // test_type_cloner()