已合并
[CANNBOT]codecheck扫描修改 #5907
wangweidong创建于 6月9日
[CANNBOT]codecheck扫描修改 #5907
已合并
共 18 个文件变更+91-51
| @@ -67,11 +67,11 @@ using std::vector; | |||
| 67 | input.push_back(tensor_placeholder##intputIndex); \ | 67 | input.push_back(tensor_placeholder##intputIndex); \ |
| 68 | graph.AddOp(placeholder##intputIndex); \ | 68 | graph.AddOp(placeholder##intputIndex); \ |
| 69 | op1.set_input_##intputName(placeholder##intputIndex); \ | 69 | op1.set_input_##intputName(placeholder##intputIndex); \ |
| 70 | - inputs.push_back(placeholder##intputIndex); | 70 | + inputs.push_back(placeholder##intputIndex) |
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ | 73 | TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ |
| 74 | - op1.update_output_desc_##outputName(outputName##outputIndex##_desc); | 74 | + op1.update_output_desc_##outputName(outputName##outputIndex##_desc) |
| 75 | 75 | ||
| 76 | string GetTime() | 76 | string GetTime() |
| 77 | { | 77 | { |
| @@ -67,11 +67,11 @@ using std::vector; | |||
| 67 | input.push_back(tensor_placeholder##intputIndex); \ | 67 | input.push_back(tensor_placeholder##intputIndex); \ |
| 68 | graph.AddOp(placeholder##intputIndex); \ | 68 | graph.AddOp(placeholder##intputIndex); \ |
| 69 | op1.set_input_##intputName(placeholder##intputIndex); \ | 69 | op1.set_input_##intputName(placeholder##intputIndex); \ |
| 70 | - inputs.push_back(placeholder##intputIndex); | 70 | + inputs.push_back(placeholder##intputIndex) |
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ | 73 | TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ |
| 74 | - op1.update_output_desc_##outputName(outputName##outputIndex##_desc); | 74 | + op1.update_output_desc_##outputName(outputName##outputIndex##_desc) |
| 75 | 75 | ||
| 76 | string GetTime() | 76 | string GetTime() |
| 77 | { | 77 | { |
| @@ -29,6 +29,8 @@ constexpr uint32_t WS_SYS_SIZE = 0U; | |||
| 29 | constexpr int64_t COMPUTE_TYPE_SIZE = 4; | 29 | constexpr int64_t COMPUTE_TYPE_SIZE = 4; |
| 30 | constexpr int64_t MIN_SPLIT_THRESHOLD = 1024; | 30 | constexpr int64_t MIN_SPLIT_THRESHOLD = 1024; |
| 31 | constexpr int64_t COMPARE_ALIGN_ELEMENTS = 256 / COMPUTE_TYPE_SIZE; | 31 | constexpr int64_t COMPARE_ALIGN_ELEMENTS = 256 / COMPUTE_TYPE_SIZE; |
| 32 | +constexpr int64_t BUFFER_NUM_DB = 9; // 双缓冲 UB 划分份数 | ||
| 33 | +constexpr int64_t BUFFER_NUM_SB = 7; // 单缓冲 UB 划分份数 | ||
| 32 | 34 | ||
| 33 | static const gert::Shape g_vec_1_shape = {1}; | 35 | static const gert::Shape g_vec_1_shape = {1}; |
| 34 | 36 | ||
| @@ -76,15 +78,15 @@ static ge::graphStatus BNLLTilingFunc(gert::TilingContext* context) | |||
| 76 | OP_CHECK_NULL_WITH_CONTEXT(context, currentWorkspace); | 78 | OP_CHECK_NULL_WITH_CONTEXT(context, currentWorkspace); |
| 77 | 79 | ||
| 78 | int64_t usedCoreNum = 1; | 80 | int64_t usedCoreNum = 1; |
| 79 | - uint64_t useDoubleBuffer = 0; | 81 | + bool useDoubleBuffer = false; |
| 80 | 82 | ||
| 81 | if (totalIdx > 0) { | 83 | if (totalIdx > 0) { |
| 82 | int64_t ubBlockSize = GetUbBlockSize(context); | 84 | int64_t ubBlockSize = GetUbBlockSize(context); |
| 83 | tiling->totalNum = totalIdx; | 85 | tiling->totalNum = totalIdx; |
| 84 | tiling->blockFactor = CeilAlign(CeilDiv(totalIdx, coreNum), ubBlockSize); | 86 | tiling->blockFactor = CeilAlign(CeilDiv(totalIdx, coreNum), ubBlockSize); |
| 85 | usedCoreNum = CeilDiv(totalIdx, tiling->blockFactor); | 87 | usedCoreNum = CeilDiv(totalIdx, tiling->blockFactor); |
| 86 | - useDoubleBuffer = (totalIdx > MIN_SPLIT_THRESHOLD) ? 1 : 0; | 88 | + useDoubleBuffer = (totalIdx > MIN_SPLIT_THRESHOLD); |
| 87 | - int64_t bufferNum = useDoubleBuffer ? 9 : 7; | 89 | + int64_t bufferNum = useDoubleBuffer ? BUFFER_NUM_DB : BUFFER_NUM_SB; |
| 88 | int64_t alignUnit = (ubBlockSize > COMPARE_ALIGN_ELEMENTS) ? ubBlockSize : COMPARE_ALIGN_ELEMENTS; | 90 | int64_t alignUnit = (ubBlockSize > COMPARE_ALIGN_ELEMENTS) ? ubBlockSize : COMPARE_ALIGN_ELEMENTS; |
| 89 | tiling->ubFactor = FloorAlign( | 91 | tiling->ubFactor = FloorAlign( |
| 90 | FloorDiv(static_cast<int64_t>(ubSize) / COMPUTE_TYPE_SIZE, bufferNum), alignUnit); | 92 | FloorDiv(static_cast<int64_t>(ubSize) / COMPUTE_TYPE_SIZE, bufferNum), alignUnit); |
| @@ -94,7 +96,8 @@ static ge::graphStatus BNLLTilingFunc(gert::TilingContext* context) | |||
| 94 | } | 96 | } |
| 95 | 97 | ||
| 96 | context->SetBlockDim(usedCoreNum); | 98 | context->SetBlockDim(usedCoreNum); |
| 97 | - ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(dataType), useDoubleBuffer); | 99 | + uint32_t doubleBufferKey = useDoubleBuffer ? 1U : 0U; |
| 100 | + ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(dataType), doubleBufferKey); | ||
| 98 | return ge::GRAPH_SUCCESS; | 101 | return ge::GRAPH_SUCCESS; |
| 99 | } | 102 | } |
| 100 | 103 | ||
| @@ -13,6 +13,8 @@ | |||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | + | ||
| 17 | + | ||
| 16 | struct BNLLTilingData { | 18 | struct BNLLTilingData { |
| 17 | int64_t totalNum = 0; | 19 | int64_t totalNum = 0; |
| 18 | int64_t blockFactor = 0; | 20 | int64_t blockFactor = 0; |
| @@ -57,7 +57,7 @@ using std::vector; | |||
| 57 | input.push_back(tensor_placeholder##intputIndex); \ | 57 | input.push_back(tensor_placeholder##intputIndex); \ |
| 58 | graph.AddOp(placeholder##intputIndex); \ | 58 | graph.AddOp(placeholder##intputIndex); \ |
| 59 | celu_op.set_input_##intputName(placeholder##intputIndex); \ | 59 | celu_op.set_input_##intputName(placeholder##intputIndex); \ |
| 60 | - inputs.push_back(placeholder##intputIndex); | 60 | + inputs.push_back(placeholder##intputIndex) |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | do { \ | 63 | do { \ |
| @@ -120,8 +120,7 @@ int32_t GenOnesDataFloat32(vector<int64_t> shapes, Tensor &input_tensor, TensorD | |||
| 120 | 120 | ||
| 121 | int32_t WriteDataToFile(string bin_file, uint64_t data_size, uint8_t *inputData) | 121 | int32_t WriteDataToFile(string bin_file, uint64_t data_size, uint8_t *inputData) |
| 122 | { | 122 | { |
| 123 | - FILE *fp; | 123 | + FILE *fp = fopen(bin_file.c_str(), "w"); |
| 124 | - fp = fopen(bin_file.c_str(), "w"); | ||
| 125 | if (fp == nullptr) { | 124 | if (fp == nullptr) { |
| 126 | return FAILED; | 125 | return FAILED; |
| 127 | } | 126 | } |
| @@ -57,7 +57,7 @@ using std::vector; | |||
| 57 | input.push_back(tensor_placeholder##intputIndex); \ | 57 | input.push_back(tensor_placeholder##intputIndex); \ |
| 58 | graph.AddOp(placeholder##intputIndex); \ | 58 | graph.AddOp(placeholder##intputIndex); \ |
| 59 | celu_op.set_input_##intputName(placeholder##intputIndex); \ | 59 | celu_op.set_input_##intputName(placeholder##intputIndex); \ |
| 60 | - inputs.push_back(placeholder##intputIndex); | 60 | + inputs.push_back(placeholder##intputIndex) |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | do { \ | 63 | do { \ |
| @@ -120,8 +120,7 @@ int32_t GenOnesDataFloat32(vector<int64_t> shapes, Tensor &input_tensor, TensorD | |||
| 120 | 120 | ||
| 121 | int32_t WriteDataToFile(string bin_file, uint64_t data_size, uint8_t *inputData) | 121 | int32_t WriteDataToFile(string bin_file, uint64_t data_size, uint8_t *inputData) |
| 122 | { | 122 | { |
| 123 | - FILE *fp; | 123 | + FILE *fp = fopen(bin_file.c_str(), "w"); |
| 124 | - fp = fopen(bin_file.c_str(), "w"); | ||
| 125 | if (fp == nullptr) { | 124 | if (fp == nullptr) { |
| 126 | return FAILED; | 125 | return FAILED; |
| 127 | } | 126 | } |
| @@ -37,6 +37,9 @@ using std::map; | |||
| 37 | using std::string; | 37 | using std::string; |
| 38 | using std::vector; | 38 | using std::vector; |
| 39 | 39 | ||
| 40 | +constexpr uint32_t FP32_BYTE_SIZE = 4; | ||
| 41 | +constexpr uint32_t FP16_BYTE_SIZE = 2; | ||
| 42 | + | ||
| 40 | string GetTime() | 43 | string GetTime() |
| 41 | { | 44 | { |
| 42 | time_t timep; | 45 | time_t timep; |
| @@ -49,11 +52,11 @@ string GetTime() | |||
| 49 | uint32_t GetDataTypeSize(DataType dt) | 52 | uint32_t GetDataTypeSize(DataType dt) |
| 50 | { | 53 | { |
| 51 | if (dt == ge::DT_FLOAT) { | 54 | if (dt == ge::DT_FLOAT) { |
| 52 | - return 4; | 55 | + return FP32_BYTE_SIZE; |
| 53 | } else if (dt == ge::DT_FLOAT16 || dt == ge::DT_BF16) { | 56 | } else if (dt == ge::DT_FLOAT16 || dt == ge::DT_BF16) { |
| 54 | - return 2; | 57 | + return FP16_BYTE_SIZE; |
| 55 | } | 58 | } |
| 56 | - return 4; | 59 | + return FP32_BYTE_SIZE; |
| 57 | } | 60 | } |
| 58 | 61 | ||
| 59 | int32_t GenOnesData(vector<int64_t> shapes, Tensor &input_tensor, TensorDesc &input_tensor_desc, | 62 | int32_t GenOnesData(vector<int64_t> shapes, Tensor &input_tensor, TensorDesc &input_tensor_desc, |
| @@ -37,6 +37,9 @@ using std::map; | |||
| 37 | using std::string; | 37 | using std::string; |
| 38 | using std::vector; | 38 | using std::vector; |
| 39 | 39 | ||
| 40 | +constexpr uint32_t FP32_BYTE_SIZE = 4; | ||
| 41 | +constexpr uint32_t FP16_BYTE_SIZE = 2; | ||
| 42 | + | ||
| 40 | string GetTime() | 43 | string GetTime() |
| 41 | { | 44 | { |
| 42 | time_t timep; | 45 | time_t timep; |
| @@ -49,11 +52,11 @@ string GetTime() | |||
| 49 | uint32_t GetDataTypeSize(DataType dt) | 52 | uint32_t GetDataTypeSize(DataType dt) |
| 50 | { | 53 | { |
| 51 | if (dt == ge::DT_FLOAT) { | 54 | if (dt == ge::DT_FLOAT) { |
| 52 | - return 4; | 55 | + return FP32_BYTE_SIZE; |
| 53 | } else if (dt == ge::DT_FLOAT16 || dt == ge::DT_BF16) { | 56 | } else if (dt == ge::DT_FLOAT16 || dt == ge::DT_BF16) { |
| 54 | - return 2; | 57 | + return FP16_BYTE_SIZE; |
| 55 | } | 58 | } |
| 56 | - return 4; | 59 | + return FP32_BYTE_SIZE; |
| 57 | } | 60 | } |
| 58 | 61 | ||
| 59 | int32_t GenOnesData(vector<int64_t> shapes, Tensor &input_tensor, TensorDesc &input_tensor_desc, | 62 | int32_t GenOnesData(vector<int64_t> shapes, Tensor &input_tensor, TensorDesc &input_tensor_desc, |
| @@ -32,6 +32,12 @@ using Ops::Base::GetUbBlockSize; | |||
| 32 | 32 | ||
| 33 | constexpr uint32_t WS_SYS_SIZE = 0U; | 33 | constexpr uint32_t WS_SYS_SIZE = 0U; |
| 34 | constexpr int64_t MIN_SPLIT_THRESHOLD = 1024; | 34 | constexpr int64_t MIN_SPLIT_THRESHOLD = 1024; |
| 35 | +constexpr int64_t FP32_BYTE_SIZE = 4; | ||
| 36 | +constexpr int64_t FP16_BYTE_SIZE = 2; | ||
| 37 | +constexpr int64_t IO_BUF_NUM = 2; // input + output 队列各 1 块 | ||
| 38 | +constexpr int64_t TMP_BUF_FP32_NUM = 5; // FP16/BF16 路径 5 块 fp32 中间 buffer | ||
| 39 | +constexpr int64_t FP32_BUF_NUM_DB = 7; // FP32 路径双缓冲总块数 | ||
| 40 | +constexpr int64_t FP32_BUF_NUM_SB = 5; // FP32 路径单缓冲总块数 | ||
| 35 | 41 | ||
| 36 | static const gert::Shape g_vec_1_shape = {1}; | 42 | static const gert::Shape g_vec_1_shape = {1}; |
| 37 | 43 | ||
| @@ -104,16 +110,17 @@ static ge::graphStatus CalcTilingParams(gert::TilingContext* context, FastGeluV2 | |||
| 104 | int64_t totalIdx, ge::DataType dataType, int64_t coreNum, uint64_t ubSize) | 110 | int64_t totalIdx, ge::DataType dataType, int64_t coreNum, uint64_t ubSize) |
| 105 | { | 111 | { |
| 106 | int64_t ubBlockSize = GetUbBlockSize(context); | 112 | int64_t ubBlockSize = GetUbBlockSize(context); |
| 107 | - uint64_t useDoubleBuffer = (totalIdx > MIN_SPLIT_THRESHOLD) ? 1 : 0; | 113 | + bool useDoubleBuffer = (totalIdx > MIN_SPLIT_THRESHOLD); |
| 108 | 114 | ||
| 109 | tiling->totalNum = totalIdx; | 115 | tiling->totalNum = totalIdx; |
| 110 | tiling->blockFactor = CeilAlign(CeilDiv(totalIdx, coreNum), ubBlockSize); | 116 | tiling->blockFactor = CeilAlign(CeilDiv(totalIdx, coreNum), ubBlockSize); |
| 111 | 117 | ||
| 112 | int64_t bytesPerElement; | 118 | int64_t bytesPerElement; |
| 113 | if (dataType == ge::DT_FLOAT16 || dataType == ge::DT_BF16) { | 119 | if (dataType == ge::DT_FLOAT16 || dataType == ge::DT_BF16) { |
| 114 | - bytesPerElement = (useDoubleBuffer ? 4 : 2) * 2 + 5 * 4; | 120 | + int64_t ioBufNum = useDoubleBuffer ? IO_BUF_NUM * 2 : IO_BUF_NUM; |
| 121 | + bytesPerElement = ioBufNum * FP16_BYTE_SIZE + TMP_BUF_FP32_NUM * FP32_BYTE_SIZE; | ||
| 115 | } else { | 122 | } else { |
| 116 | - bytesPerElement = (useDoubleBuffer ? 7 : 5) * 4; | 123 | + bytesPerElement = (useDoubleBuffer ? FP32_BUF_NUM_DB : FP32_BUF_NUM_SB) * FP32_BYTE_SIZE; |
| 117 | } | 124 | } |
| 118 | tiling->ubFactor = FloorAlign(FloorDiv(static_cast<int64_t>(ubSize), bytesPerElement), ubBlockSize); | 125 | tiling->ubFactor = FloorAlign(FloorDiv(static_cast<int64_t>(ubSize), bytesPerElement), ubBlockSize); |
| 119 | 126 | ||
| @@ -124,7 +131,8 @@ static ge::graphStatus CalcTilingParams(gert::TilingContext* context, FastGeluV2 | |||
| 124 | OP_LOGE(context, "FastGeluV2: blockFactor is 0"), return ge::GRAPH_FAILED); | 131 | OP_LOGE(context, "FastGeluV2: blockFactor is 0"), return ge::GRAPH_FAILED); |
| 125 | 132 | ||
| 126 | context->SetBlockDim(CeilDiv(totalIdx, tiling->blockFactor)); | 133 | context->SetBlockDim(CeilDiv(totalIdx, tiling->blockFactor)); |
| 127 | - ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(dataType), static_cast<uint32_t>(useDoubleBuffer)); | 134 | + uint32_t doubleBufferKey = useDoubleBuffer ? 1U : 0U; |
| 135 | + ASCENDC_TPL_SEL_PARAM(context, static_cast<uint32_t>(dataType), doubleBufferKey); | ||
| 128 | return ge::GRAPH_SUCCESS; | 136 | return ge::GRAPH_SUCCESS; |
| 129 | } | 137 | } |
| 130 | 138 | ||
| @@ -22,6 +22,8 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | + | ||
| 26 | + | ||
| 25 | struct FastGeluV2TilingData { | 27 | struct FastGeluV2TilingData { |
| 26 | int64_t totalNum = 0; // Total number of input elements across all dimensions | 28 | int64_t totalNum = 0; // Total number of input elements across all dimensions |
| 27 | int64_t blockFactor = 0; // Number of elements assigned to each AI Core (aligned to ubBlockSize) | 29 | int64_t blockFactor = 0; // Number of elements assigned to each AI Core (aligned to ubBlockSize) |
| @@ -57,7 +57,7 @@ using std::vector; | |||
| 57 | input.push_back(tensor_placeholder##intputIndex); \ | 57 | input.push_back(tensor_placeholder##intputIndex); \ |
| 58 | graph.AddOp(placeholder##intputIndex); \ | 58 | graph.AddOp(placeholder##intputIndex); \ |
| 59 | relu6_op.set_input_##intputName(placeholder##intputIndex); \ | 59 | relu6_op.set_input_##intputName(placeholder##intputIndex); \ |
| 60 | - inputs.push_back(placeholder##intputIndex); | 60 | + inputs.push_back(placeholder##intputIndex) |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | do { \ | 63 | do { \ |
| @@ -120,8 +120,7 @@ int32_t GenOnesDataFloat32(vector<int64_t> shapes, Tensor &input_tensor, TensorD | |||
| 120 | 120 | ||
| 121 | int32_t WriteDataToFile(string bin_file, uint64_t data_size, uint8_t *inputData) | 121 | int32_t WriteDataToFile(string bin_file, uint64_t data_size, uint8_t *inputData) |
| 122 | { | 122 | { |
| 123 | - FILE *fp; | 123 | + FILE *fp = fopen(bin_file.c_str(), "w"); |
| 124 | - fp = fopen(bin_file.c_str(), "w"); | ||
| 125 | if (fp == nullptr) { | 124 | if (fp == nullptr) { |
| 126 | return FAILED; | 125 | return FAILED; |
| 127 | } | 126 | } |
| @@ -57,7 +57,7 @@ using std::vector; | |||
| 57 | input.push_back(tensor_placeholder##intputIndex); \ | 57 | input.push_back(tensor_placeholder##intputIndex); \ |
| 58 | graph.AddOp(placeholder##intputIndex); \ | 58 | graph.AddOp(placeholder##intputIndex); \ |
| 59 | relu6_op.set_input_##intputName(placeholder##intputIndex); \ | 59 | relu6_op.set_input_##intputName(placeholder##intputIndex); \ |
| 60 | - inputs.push_back(placeholder##intputIndex); | 60 | + inputs.push_back(placeholder##intputIndex) |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | do { \ | 63 | do { \ |
| @@ -120,8 +120,7 @@ int32_t GenOnesDataFloat32(vector<int64_t> shapes, Tensor &input_tensor, TensorD | |||
| 120 | 120 | ||
| 121 | int32_t WriteDataToFile(string bin_file, uint64_t data_size, uint8_t *inputData) | 121 | int32_t WriteDataToFile(string bin_file, uint64_t data_size, uint8_t *inputData) |
| 122 | { | 122 | { |
| 123 | - FILE *fp; | 123 | + FILE *fp = fopen(bin_file.c_str(), "w"); |
| 124 | - fp = fopen(bin_file.c_str(), "w"); | ||
| 125 | if (fp == nullptr) { | 124 | if (fp == nullptr) { |
| 126 | return FAILED; | 125 | return FAILED; |
| 127 | } | 126 | } |
| @@ -47,6 +47,12 @@ using Ops::Base::GetAivCoreNum; | |||
| 47 | using Ops::Base::GetUbSize; | 47 | using Ops::Base::GetUbSize; |
| 48 | 48 | ||
| 49 | constexpr uint32_t WS_SYS_SIZE = 0U; | 49 | constexpr uint32_t WS_SYS_SIZE = 0U; |
| 50 | +constexpr int64_t BLOCK_ALIGN_BYTES = 32; // UB 32 字节对齐 | ||
| 51 | +constexpr int64_t FP32_BYTE_SIZE = 4; // cast-to-fp32 中间计算字节宽 | ||
| 52 | +constexpr int64_t FP16_BYTE_SIZE = 2; | ||
| 53 | +constexpr int64_t INT8_BYTE_SIZE = 1; | ||
| 54 | +constexpr int64_t IO_BUF_NUM = 2; // inputQueue + outputQueue | ||
| 55 | +constexpr int64_t TMP_BUF_NUM = 2; // tmpBuf1 + tmpBuf2 | ||
| 50 | 56 | ||
| 51 | static const gert::Shape g_vec_1_shape = {1}; | 57 | static const gert::Shape g_vec_1_shape = {1}; |
| 52 | 58 | ||
| @@ -107,30 +113,30 @@ static ge::graphStatus ComputeTiling(gert::TilingContext* context, SeluTilingDat | |||
| 107 | uint64_t ubSize, int64_t coreNum) | 113 | uint64_t ubSize, int64_t coreNum) |
| 108 | { | 114 | { |
| 109 | // 用户约定:所有非 fp32 dtype 中间都走 cast-to-fp32,computeTypeSize 固定为 4 | 115 | // 用户约定:所有非 fp32 dtype 中间都走 cast-to-fp32,computeTypeSize 固定为 4 |
| 110 | - int64_t typeSize = 4; | 116 | + int64_t typeSize = FP32_BYTE_SIZE; |
| 111 | - int64_t computeTypeSize = 4; | 117 | + int64_t computeTypeSize = FP32_BYTE_SIZE; |
| 112 | switch (dataType) { | 118 | switch (dataType) { |
| 113 | case ge::DT_FLOAT: | 119 | case ge::DT_FLOAT: |
| 114 | case ge::DT_INT32: | 120 | case ge::DT_INT32: |
| 115 | - typeSize = 4; | 121 | + typeSize = FP32_BYTE_SIZE; |
| 116 | break; | 122 | break; |
| 117 | case ge::DT_FLOAT16: | 123 | case ge::DT_FLOAT16: |
| 118 | case ge::DT_BF16: | 124 | case ge::DT_BF16: |
| 119 | - typeSize = 2; | 125 | + typeSize = FP16_BYTE_SIZE; |
| 120 | break; | 126 | break; |
| 121 | case ge::DT_INT8: | 127 | case ge::DT_INT8: |
| 122 | - typeSize = 1; | 128 | + typeSize = INT8_BYTE_SIZE; |
| 123 | break; | 129 | break; |
| 124 | default: | 130 | default: |
| 125 | OP_LOGE(context, "Selu: unexpected dtype %d", static_cast<int>(dataType)); | 131 | OP_LOGE(context, "Selu: unexpected dtype %d", static_cast<int>(dataType)); |
| 126 | return ge::GRAPH_FAILED; | 132 | return ge::GRAPH_FAILED; |
| 127 | } | 133 | } |
| 128 | 134 | ||
| 129 | - int64_t ubBlockSize = 32 / typeSize; // 32-byte alignment in elements | 135 | + int64_t ubBlockSize = BLOCK_ALIGN_BYTES / typeSize; // 32-byte alignment in elements |
| 130 | int64_t blockFactor = CeilDiv(totalElements, coreNum); | 136 | int64_t blockFactor = CeilDiv(totalElements, coreNum); |
| 131 | blockFactor = ((blockFactor + ubBlockSize - 1) / ubBlockSize) * ubBlockSize; | 137 | blockFactor = ((blockFactor + ubBlockSize - 1) / ubBlockSize) * ubBlockSize; |
| 132 | int64_t usedCoreNum = CeilDiv(totalElements, blockFactor); | 138 | int64_t usedCoreNum = CeilDiv(totalElements, blockFactor); |
| 133 | - int64_t ubDivisor = (2 * typeSize + 2 * computeTypeSize) / typeSize; | 139 | + int64_t ubDivisor = (IO_BUF_NUM * typeSize + TMP_BUF_NUM * computeTypeSize) / typeSize; |
| 134 | int64_t ubFactor = FloorAlign( | 140 | int64_t ubFactor = FloorAlign( |
| 135 | FloorDiv(static_cast<int64_t>(ubSize) / typeSize, ubDivisor), | 141 | FloorDiv(static_cast<int64_t>(ubSize) / typeSize, ubDivisor), |
| 136 | ubBlockSize); | 142 | ubBlockSize); |
| @@ -21,6 +21,8 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | + | ||
| 25 | + | ||
| 24 | struct SeluTilingData { | 26 | struct SeluTilingData { |
| 25 | int64_t totalElements = 0; // Total number of elements | 27 | int64_t totalElements = 0; // Total number of elements |
| 26 | int64_t blockFactor = 0; // Number of elements per AI Core | 28 | int64_t blockFactor = 0; // Number of elements per AI Core |
| @@ -46,6 +46,9 @@ using std::map; | |||
| 46 | using std::string; | 46 | using std::string; |
| 47 | using std::vector; | 47 | using std::vector; |
| 48 | 48 | ||
| 49 | +constexpr uint32_t FP32_BYTE_SIZE = 4; | ||
| 50 | +constexpr uint32_t FP16_BYTE_SIZE = 2; | ||
| 51 | + | ||
| 49 | 52 | ||
| 50 | vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ | 53 | vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ |
| 51 | auto placeholder##inputIndex = op::Data("placeholder" #inputIndex).set_attr_index(inputIndex - 1); \ | 54 | auto placeholder##inputIndex = op::Data("placeholder" #inputIndex).set_attr_index(inputIndex - 1); \ |
| @@ -65,11 +68,11 @@ using std::vector; | |||
| 65 | input.push_back(tensor_placeholder##inputIndex); \ | 68 | input.push_back(tensor_placeholder##inputIndex); \ |
| 66 | graph.AddOp(placeholder##inputIndex); \ | 69 | graph.AddOp(placeholder##inputIndex); \ |
| 67 | softsignGradOp.set_input_##inputName(placeholder##inputIndex); \ | 70 | softsignGradOp.set_input_##inputName(placeholder##inputIndex); \ |
| 68 | - inputs.push_back(placeholder##inputIndex); | 71 | + inputs.push_back(placeholder##inputIndex) |
| 69 | 72 | ||
| 70 | 73 | ||
| 71 | TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ | 74 | TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ |
| 72 | - softsignGradOp.update_output_desc_##outputName(outputName##outputIndex##_desc); | 75 | + softsignGradOp.update_output_desc_##outputName(outputName##outputIndex##_desc) |
| 73 | 76 | ||
| 74 | string GetTime() | 77 | string GetTime() |
| 75 | { | 78 | { |
| @@ -83,11 +86,11 @@ string GetTime() | |||
| 83 | uint32_t GetDataTypeSize(DataType dt) | 86 | uint32_t GetDataTypeSize(DataType dt) |
| 84 | { | 87 | { |
| 85 | if (dt == ge::DT_FLOAT) { | 88 | if (dt == ge::DT_FLOAT) { |
| 86 | - return 4; | 89 | + return FP32_BYTE_SIZE; |
| 87 | } else if (dt == ge::DT_FLOAT16 || dt == ge::DT_BF16) { | 90 | } else if (dt == ge::DT_FLOAT16 || dt == ge::DT_BF16) { |
| 88 | - return 2; | 91 | + return FP16_BYTE_SIZE; |
| 89 | } | 92 | } |
| 90 | - return 4; | 93 | + return FP32_BYTE_SIZE; |
| 91 | } | 94 | } |
| 92 | 95 | ||
| 93 | int32_t GenInputData( | 96 | int32_t GenInputData( |
| @@ -46,6 +46,9 @@ using std::map; | |||
| 46 | using std::string; | 46 | using std::string; |
| 47 | using std::vector; | 47 | using std::vector; |
| 48 | 48 | ||
| 49 | +constexpr uint32_t FP32_BYTE_SIZE = 4; | ||
| 50 | +constexpr uint32_t FP16_BYTE_SIZE = 2; | ||
| 51 | + | ||
| 49 | 52 | ||
| 50 | vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ | 53 | vector<int64_t> placeholder##inputIndex##_shape = inputShape; \ |
| 51 | auto placeholder##inputIndex = op::Data("placeholder" #inputIndex).set_attr_index(inputIndex - 1); \ | 54 | auto placeholder##inputIndex = op::Data("placeholder" #inputIndex).set_attr_index(inputIndex - 1); \ |
| @@ -65,11 +68,11 @@ using std::vector; | |||
| 65 | input.push_back(tensor_placeholder##inputIndex); \ | 68 | input.push_back(tensor_placeholder##inputIndex); \ |
| 66 | graph.AddOp(placeholder##inputIndex); \ | 69 | graph.AddOp(placeholder##inputIndex); \ |
| 67 | softsignGradOp.set_input_##inputName(placeholder##inputIndex); \ | 70 | softsignGradOp.set_input_##inputName(placeholder##inputIndex); \ |
| 68 | - inputs.push_back(placeholder##inputIndex); | 71 | + inputs.push_back(placeholder##inputIndex) |
| 69 | 72 | ||
| 70 | 73 | ||
| 71 | TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ | 74 | TensorDesc outputName##outputIndex##_desc = TensorDesc(ge::Shape(outputShape), FORMAT_ND, outputDtype); \ |
| 72 | - softsignGradOp.update_output_desc_##outputName(outputName##outputIndex##_desc); | 75 | + softsignGradOp.update_output_desc_##outputName(outputName##outputIndex##_desc) |
| 73 | 76 | ||
| 74 | string GetTime() | 77 | string GetTime() |
| 75 | { | 78 | { |
| @@ -83,11 +86,11 @@ string GetTime() | |||
| 83 | uint32_t GetDataTypeSize(DataType dt) | 86 | uint32_t GetDataTypeSize(DataType dt) |
| 84 | { | 87 | { |
| 85 | if (dt == ge::DT_FLOAT) { | 88 | if (dt == ge::DT_FLOAT) { |
| 86 | - return 4; | 89 | + return FP32_BYTE_SIZE; |
| 87 | } else if (dt == ge::DT_FLOAT16 || dt == ge::DT_BF16) { | 90 | } else if (dt == ge::DT_FLOAT16 || dt == ge::DT_BF16) { |
| 88 | - return 2; | 91 | + return FP16_BYTE_SIZE; |
| 89 | } | 92 | } |
| 90 | - return 4; | 93 | + return FP32_BYTE_SIZE; |
| 91 | } | 94 | } |
| 92 | 95 | ||
| 93 | int32_t GenInputData( | 96 | int32_t GenInputData( |
| @@ -29,6 +29,12 @@ using Ops::NN::OpTiling::EnsureNotScalar; | |||
| 29 | constexpr int64_t FP32_SIZE = 4; | 29 | constexpr int64_t FP32_SIZE = 4; |
| 30 | constexpr int64_t MIN_SPLIT_THRESHOLD = 1024; | 30 | constexpr int64_t MIN_SPLIT_THRESHOLD = 1024; |
| 31 | 31 | ||
| 32 | +// UB 划分份数:按是否需 Cast、是否开启 double buffer 区分缓冲块数 | ||
| 33 | +constexpr int64_t BUFFER_NUM_CAST_DB = 6; | ||
| 34 | +constexpr int64_t BUFFER_NUM_CAST_SB = 5; | ||
| 35 | +constexpr int64_t BUFFER_NUM_NOCAST_DB = 7; | ||
| 36 | +constexpr int64_t BUFFER_NUM_NOCAST_SB = 4; | ||
| 37 | + | ||
| 32 | static ge::graphStatus GetPlatformInfo(gert::TilingContext* context, uint64_t& ubSize, int64_t& coreNum) | 38 | static ge::graphStatus GetPlatformInfo(gert::TilingContext* context, uint64_t& ubSize, int64_t& coreNum) |
| 33 | { | 39 | { |
| 34 | fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo(); | 40 | fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo(); |
| @@ -132,14 +138,14 @@ static ge::graphStatus SoftsignGradTilingFunc(gert::TilingContext* context) | |||
| 132 | int64_t usedCoreNum = CeilDiv(totalNum, tiling->blockFactor); | 138 | int64_t usedCoreNum = CeilDiv(totalNum, tiling->blockFactor); |
| 133 | 139 | ||
| 134 | int64_t ubBlockSize = GetUbBlockSize(context); | 140 | int64_t ubBlockSize = GetUbBlockSize(context); |
| 135 | - uint64_t useDoubleBuffer = (totalNum > MIN_SPLIT_THRESHOLD) ? 1 : 0; | 141 | + bool useDoubleBuffer = (totalNum > MIN_SPLIT_THRESHOLD); |
| 136 | 142 | ||
| 137 | int64_t bufferNum; | 143 | int64_t bufferNum; |
| 138 | bool needsCast = (dataType != ge::DT_FLOAT); | 144 | bool needsCast = (dataType != ge::DT_FLOAT); |
| 139 | if (needsCast) { | 145 | if (needsCast) { |
| 140 | - bufferNum = useDoubleBuffer ? 6 : 5; | 146 | + bufferNum = useDoubleBuffer ? BUFFER_NUM_CAST_DB : BUFFER_NUM_CAST_SB; |
| 141 | } else { | 147 | } else { |
| 142 | - bufferNum = useDoubleBuffer ? 7 : 4; | 148 | + bufferNum = useDoubleBuffer ? BUFFER_NUM_NOCAST_DB : BUFFER_NUM_NOCAST_SB; |
| 143 | } | 149 | } |
| 144 | 150 | ||
| 145 | tiling->ubFactor = FloorAlign( | 151 | tiling->ubFactor = FloorAlign( |
| @@ -148,7 +154,8 @@ static ge::graphStatus SoftsignGradTilingFunc(gert::TilingContext* context) | |||
| 148 | 154 | ||
| 149 | context->SetBlockDim(usedCoreNum); | 155 | context->SetBlockDim(usedCoreNum); |
| 150 | 156 | ||
| 151 | - ASCENDC_TPL_SEL_PARAM(context, useDoubleBuffer); | 157 | + uint64_t bufferModeKey = useDoubleBuffer ? 1U : 0U; |
| 158 | + ASCENDC_TPL_SEL_PARAM(context, bufferModeKey); | ||
| 152 | 159 | ||
| 153 | return ge::GRAPH_SUCCESS; | 160 | return ge::GRAPH_SUCCESS; |
| 154 | } | 161 | } |
| @@ -18,6 +18,8 @@ | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | + | ||
| 22 | + | ||
| 21 | struct SoftsignGradTilingData { | 23 | struct SoftsignGradTilingData { |
| 22 | int64_t totalNum = 0; // 总元素数量 | 24 | int64_t totalNum = 0; // 总元素数量 |
| 23 | int64_t blockFactor = 0; // 每个核处理的元素数量 | 25 | int64_t blockFactor = 0; // 每个核处理的元素数量 |