!33521 Modify the printing information of type id

Merge pull request !33521 from huangbingjian/type_id
This commit is contained in:
i-robot 2022-05-07 07:15:07 +00:00 committed by Gitee
commit 723e40b7f1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 62 additions and 129 deletions

View File

@ -85,7 +85,7 @@ static std::map<std::string, std::pair<std::map<size_t, size_t>, std::map<size_t
std::string PrintKernelFormatAndType(const std::string &fmt, const TypeId &type, const std::vector<size_t> &shape) {
std::ostringstream buffer;
buffer << "<" << TypeToShortString(type);
buffer << "<" << TypeIdLabel(type);
if (!fmt.empty()) {
buffer << "x" << fmt << shape;
}

View File

@ -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();

View File

@ -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 {

View File

@ -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();

View File

@ -56,13 +56,12 @@ static constexpr float kSignedMinFloat = -3.402823466e+38F;
// Used by mixprecision, cudnn dtype select
static std::map<std::string, cudnnDataType_t> 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<std::string, cudaDataType_t> 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

View File

@ -32,10 +32,9 @@ namespace mindspore {
namespace kernel {
using NvidiaCollectiveCommLib = device::gpu::NvidiaCollectiveCommLib;
static std::map<std::string, ncclDataType_t> 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 &);

View File

@ -27,61 +27,58 @@
#include "utils/convert_utils_base.h"
namespace mindspore {
#define MS_TYPE2LABLE(type_id) #type_id
static mindspore::HashMap<TypeId, std::string> 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<TypeId, std::string> 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) {

View File

@ -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()