已合并
fix: 修复可选输入索引处理问题,区分必选和可选输入校验 #3075
liangtongxue创建于 6月2日
fix: 修复可选输入索引处理问题,区分必选和可选输入校验 #3075
已合并
共 7 个文件变更+54-34
| @@ -47,7 +47,7 @@ OpTilingConfig DropOutV3Tiling::BuildOpConfig() | |||
| 47 | {OUTPUT_IDX_Y, {{ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16}, -1, {}, nullptr}}}; | 47 | {OUTPUT_IDX_Y, {{ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16}, -1, {}, nullptr}}}; |
| 48 | 48 | ||
| 49 | config.getOutputSize = [](gert::TilingContext* ctx, int64_t& size) { | 49 | config.getOutputSize = [](gert::TilingContext* ctx, int64_t& size) { |
| 50 | - auto inputShape = ctx->GetInputShape(INPUT_IDX_X); | 50 | + auto inputShape = ctx->GetRequiredInputShape(INPUT_IDX_X); |
| 51 | OP_CHECK_NULL_WITH_CONTEXT(ctx, inputShape); | 51 | OP_CHECK_NULL_WITH_CONTEXT(ctx, inputShape); |
| 52 | auto storageShape = inputShape->GetStorageShape(); | 52 | auto storageShape = inputShape->GetStorageShape(); |
| 53 | size = storageShape.IsScalar() ? 1 : storageShape.GetShapeSize(); | 53 | size = storageShape.IsScalar() ? 1 : storageShape.GetShapeSize(); |
| @@ -30,17 +30,13 @@ static constexpr size_t MAX_DIM_NUM = 8; | |||
| 30 | 30 | ||
| 31 | static graphStatus InferShapeDropOutV3(gert::InferShapeContext* context) | 31 | static graphStatus InferShapeDropOutV3(gert::InferShapeContext* context) |
| 32 | { | 32 | { |
| 33 | - const std::unordered_map<std::string, size_t>& inputMap = { | 33 | + const std::unordered_map<std::string, size_t>& requiredInputMap = { |
| 34 | {"x", DropOutV3_X}, {"p", DropOutV3_P}, {"seed", DropOutV3_SEED}, {"offset", DropOutV3_OFFSET}}; | 34 | {"x", DropOutV3_X}, {"p", DropOutV3_P}, {"seed", DropOutV3_SEED}, {"offset", DropOutV3_OFFSET}}; |
| 35 | + const std::unordered_map<std::string, size_t>& optionalInputMap = { | ||
| 36 | + {"noise_shape", DropOutV3_NOISE}}; | ||
| 35 | const std::unordered_map<std::string, size_t>& outputMap = {{"y", DropOutV3_Y}, {"mask", DropOutV3_MASK}}; | 37 | const std::unordered_map<std::string, size_t>& outputMap = {{"y", DropOutV3_Y}, {"mask", DropOutV3_MASK}}; |
| 36 | int32_t mode = ops::randomCommon::MODE_NO_DEPENDENCY; | 38 | int32_t mode = ops::randomCommon::MODE_NO_DEPENDENCY; |
| 37 | - const gert::Shape* noiseInputShape = context->GetOptionalInputShape(DropOutV3_NOISE); | 39 | + return ops::randomCommon::CommonInferShape(context, requiredInputMap, outputMap, mode, optionalInputMap); |
| 38 | - if (noiseInputShape != nullptr) { | ||
| 39 | - if (noiseInputShape->GetDimNum() > MAX_DIM_NUM) { | ||
| 40 | - return ge::GRAPH_FAILED; | ||
| 41 | - } | ||
| 42 | - } | ||
| 43 | - return ops::randomCommon::CommonInferShape(context, inputMap, outputMap, mode); | ||
| 44 | } | 40 | } |
| 45 | IMPL_OP_INFERSHAPE(DropOutV3).InferShape(InferShapeDropOutV3); | 41 | IMPL_OP_INFERSHAPE(DropOutV3).InferShape(InferShapeDropOutV3); |
| 46 | 42 | ||
| @@ -149,29 +149,39 @@ ge::graphStatus RandomTilingArch35::DoTiling() | |||
| 149 | ge::graphStatus RandomTilingArch35::CheckInputsOutputsAndAttrs() | 149 | ge::graphStatus RandomTilingArch35::CheckInputsOutputsAndAttrs() |
| 150 | { | 150 | { |
| 151 | OP_LOGI(opName_, "TilingContext: %s", RandomUtils::GetTilingContext(context_).c_str()); | 151 | OP_LOGI(opName_, "TilingContext: %s", RandomUtils::GetTilingContext(context_).c_str()); |
| 152 | - // 校验输入tensor | ||
| 153 | for (const auto& [idx, rule] : config_.inputCheckRules) { | 152 | for (const auto& [idx, rule] : config_.inputCheckRules) { |
| 154 | - auto tensorDesc = context_->GetInputDesc(idx); | 153 | + auto tensorDesc = context_->GetRequiredInputDesc(idx); |
| 155 | OP_CHECK_NULL_WITH_CONTEXT(context_, tensorDesc); | 154 | OP_CHECK_NULL_WITH_CONTEXT(context_, tensorDesc); |
| 156 | - auto inputShape = context_->GetInputShape(idx); | 155 | + auto inputShape = context_->GetRequiredInputShape(idx); |
| 157 | OP_CHECK_NULL_WITH_CONTEXT(context_, inputShape); | 156 | OP_CHECK_NULL_WITH_CONTEXT(context_, inputShape); |
| 158 | - auto inputTensor = inputShape->GetStorageShape(); | 157 | + auto storageShape = inputShape->GetStorageShape(); |
| 159 | 158 | ||
| 160 | - auto ret = CheckTensor(tensorDesc, inputTensor, rule, "input_" + std::to_string(idx)); | 159 | + auto ret = CheckTensor(tensorDesc, storageShape, rule, "input_" + std::to_string(idx)); |
| 161 | if (ret != ge::GRAPH_SUCCESS) { | 160 | if (ret != ge::GRAPH_SUCCESS) { |
| 162 | return ret; | 161 | return ret; |
| 163 | } | 162 | } |
| 164 | } | 163 | } |
| 165 | 164 | ||
| 166 | - // 校验输出tensor | 165 | + for (const auto& [idx, rule] : config_.optionalInputCheckRules) { |
| 166 | + auto tensorDesc = context_->GetOptionalInputDesc(idx); | ||
| 167 | + auto inputShape = context_->GetOptionalInputShape(idx); | ||
| 168 | + if (tensorDesc != nullptr && inputShape != nullptr) { | ||
| 169 | + auto storageShape = inputShape->GetStorageShape(); | ||
| 170 | + auto ret = CheckTensor(tensorDesc, storageShape, rule, "optional_input_" + std::to_string(idx)); | ||
| 171 | + if (ret != ge::GRAPH_SUCCESS) { | ||
| 172 | + return ret; | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + | ||
| 167 | for (const auto& [idx, rule] : config_.outputCheckRules) { | 177 | for (const auto& [idx, rule] : config_.outputCheckRules) { |
| 168 | auto tensorDesc = context_->GetOutputDesc(idx); | 178 | auto tensorDesc = context_->GetOutputDesc(idx); |
| 169 | OP_CHECK_NULL_WITH_CONTEXT(context_, tensorDesc); | 179 | OP_CHECK_NULL_WITH_CONTEXT(context_, tensorDesc); |
| 170 | auto outputShape = context_->GetOutputShape(idx); | 180 | auto outputShape = context_->GetOutputShape(idx); |
| 171 | OP_CHECK_NULL_WITH_CONTEXT(context_, outputShape); | 181 | OP_CHECK_NULL_WITH_CONTEXT(context_, outputShape); |
| 172 | - auto outputTensor = outputShape->GetStorageShape(); | 182 | + auto storageShape = outputShape->GetStorageShape(); |
| 173 | 183 | ||
| 174 | - auto ret = CheckTensor(tensorDesc, outputTensor, rule, "output_" + std::to_string(idx)); | 184 | + auto ret = CheckTensor(tensorDesc, storageShape, rule, "output_" + std::to_string(idx)); |
| 175 | if (ret != ge::GRAPH_SUCCESS) { | 185 | if (ret != ge::GRAPH_SUCCESS) { |
| 176 | return ret; | 186 | return ret; |
| 177 | } | 187 | } |
| @@ -45,9 +45,8 @@ struct TensorCheckRule { | |||
| 45 | enum class RandomKernelMode {SIMD, SIMT}; | 45 | enum class RandomKernelMode {SIMD, SIMT}; |
| 46 | 46 | ||
| 47 | struct OpTilingConfig { | 47 | struct OpTilingConfig { |
| 48 | - // 输入tensor校验规则(key: 输入索引,value: 校验规则) | ||
| 49 | std::unordered_map<int32_t, TensorCheckRule> inputCheckRules; | 48 | std::unordered_map<int32_t, TensorCheckRule> inputCheckRules; |
| 50 | - // 输出tensor校验规则(key: 输出索引,value: 校验规则) | 49 | + std::unordered_map<int32_t, TensorCheckRule> optionalInputCheckRules; |
| 51 | std::unordered_map<int32_t, TensorCheckRule> outputCheckRules; | 50 | std::unordered_map<int32_t, TensorCheckRule> outputCheckRules; |
| 52 | // // 属性校验规则(key: 属性名,value: 自定义校验函数) | 51 | // // 属性校验规则(key: 属性名,value: 自定义校验函数) |
| 53 | std::unordered_map<int32_t, std::function<bool(gert::TilingContext*)>> attrCheckRules; | 52 | std::unordered_map<int32_t, std::function<bool(gert::TilingContext*)>> attrCheckRules; |
| @@ -88,14 +88,23 @@ bool DependencyMode(const gert::Tensor* inTensor, gert::Shape& outShape, size_t | |||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | bool InputAndOutputCheck( | 90 | bool InputAndOutputCheck( |
| 91 | - gert::InferShapeContext* context, const std::unordered_map<std::string, size_t>& inputMap, | 91 | + gert::InferShapeContext* context, const std::unordered_map<std::string, size_t>& requiredInputMap, |
| 92 | - const std::unordered_map<std::string, size_t>& outputMap, int64_t& maskIndex, int64_t& offsetIndex) | 92 | + const std::unordered_map<std::string, size_t>& outputMap, int64_t& maskIndex, int64_t& offsetIndex, |
| 93 | + const std::unordered_map<std::string, size_t>& optionalInputMap) | ||
| 93 | { | 94 | { |
| 94 | OP_LOGD(context->GetNodeName(), "InputAndOutputCheck start"); | 95 | OP_LOGD(context->GetNodeName(), "InputAndOutputCheck start"); |
| 95 | - for (const auto& item : inputMap) { | 96 | + for (const auto& item : requiredInputMap) { |
| 96 | size_t inputIndex = item.second; | 97 | size_t inputIndex = item.second; |
| 97 | - auto input = context->GetInputTensor(inputIndex); | 98 | + auto inputShape = context->GetRequiredInputShape(inputIndex); |
| 98 | - OP_CHECK_NULL_WITH_CONTEXT(context, input); | 99 | + OP_CHECK_NULL_WITH_CONTEXT(context, inputShape); |
| 100 | + } | ||
| 101 | + | ||
| 102 | + for (const auto& item : optionalInputMap) { | ||
| 103 | + size_t inputIndex = item.second; | ||
| 104 | + auto inputShape = context->GetOptionalInputShape(inputIndex); | ||
| 105 | + if (inputShape != nullptr) { | ||
| 106 | + OP_LOGD(context->GetNodeName(), "Optional input %zu is provided", inputIndex); | ||
| 107 | + } | ||
| 99 | } | 108 | } |
| 100 | 109 | ||
| 101 | for (const auto& item : outputMap) { | 110 | for (const auto& item : outputMap) { |
| @@ -116,15 +125,16 @@ bool InputAndOutputCheck( | |||
| 116 | } | 125 | } |
| 117 | 126 | ||
| 118 | ge::graphStatus CommonInferShape( | 127 | ge::graphStatus CommonInferShape( |
| 119 | - gert::InferShapeContext* context, const std::unordered_map<std::string, size_t>& inputMap, | 128 | + gert::InferShapeContext* context, const std::unordered_map<std::string, size_t>& requiredInputMap, |
| 120 | - const std::unordered_map<std::string, size_t>& outputMap, int32_t mode) | 129 | + const std::unordered_map<std::string, size_t>& outputMap, int32_t mode, |
| 130 | + const std::unordered_map<std::string, size_t>& optionalInputMap) | ||
| 121 | { | 131 | { |
| 122 | if (context == nullptr) { | 132 | if (context == nullptr) { |
| 123 | return ge::GRAPH_FAILED; | 133 | return ge::GRAPH_FAILED; |
| 124 | } | 134 | } |
| 125 | int64_t maskIndex = -1; | 135 | int64_t maskIndex = -1; |
| 126 | int64_t offsetIndex = -1; | 136 | int64_t offsetIndex = -1; |
| 127 | - if (!InputAndOutputCheck(context, inputMap, outputMap, maskIndex, offsetIndex)) { | 137 | + if (!InputAndOutputCheck(context, requiredInputMap, outputMap, maskIndex, offsetIndex, optionalInputMap)) { |
| 128 | return ge::GRAPH_FAILED; | 138 | return ge::GRAPH_FAILED; |
| 129 | } | 139 | } |
| 130 | const gert::Shape* inShape = context->GetInputShape(0); | 140 | const gert::Shape* inShape = context->GetInputShape(0); |
| @@ -33,8 +33,9 @@ static constexpr int32_t MODE_NO_DEPENDENCY = 1; | |||
| 33 | // 使用时默认输入输出的位置为0。mode = 0:只支持int32和int64,输入输出的dim相等,使用时必须有值依赖。 | 33 | // 使用时默认输入输出的位置为0。mode = 0:只支持int32和int64,输入输出的dim相等,使用时必须有值依赖。 |
| 34 | // mode = 1:只支持float,float16和bf16,输出shape直接使用输入shape,可以无需值依赖。 | 34 | // mode = 1:只支持float,float16和bf16,输出shape直接使用输入shape,可以无需值依赖。 |
| 35 | ge::graphStatus CommonInferShape( | 35 | ge::graphStatus CommonInferShape( |
| 36 | - gert::InferShapeContext* context, const std::unordered_map<std::string, size_t>& inputMap, | 36 | + gert::InferShapeContext* context, const std::unordered_map<std::string, size_t>& requiredInputMap, |
| 37 | - const std::unordered_map<std::string, size_t>& outputMap, int32_t mode); | 37 | + const std::unordered_map<std::string, size_t>& outputMap, int32_t mode, |
| 38 | + const std::unordered_map<std::string, size_t>& optionalInputMap = {}); | ||
| 38 | 39 | ||
| 39 | template <typename T> | 40 | template <typename T> |
| 40 | ge::graphStatus HandleShapeTensor(gert::Shape& outputShape, size_t shapeSize, const T* shapeData); | 41 | ge::graphStatus HandleShapeTensor(gert::Shape& outputShape, size_t shapeSize, const T* shapeData); |
| @@ -46,8 +47,9 @@ bool InferShapeForUnknow( | |||
| 46 | bool DependencyMode(const gert::Tensor* inTensor, gert::Shape& outShape, size_t xShapeSize); | 47 | bool DependencyMode(const gert::Tensor* inTensor, gert::Shape& outShape, size_t xShapeSize); |
| 47 | 48 | ||
| 48 | bool InputAndOutputCheck( | 49 | bool InputAndOutputCheck( |
| 49 | - gert::InferShapeContext* context, const std::unordered_map<std::string, size_t>& inputMap, | 50 | + gert::InferShapeContext* context, const std::unordered_map<std::string, size_t>& requiredInputMap, |
| 50 | - const std::unordered_map<std::string, size_t>& outputMap, int64_t& maskIndex, int64_t& offsetIndex); | 51 | + const std::unordered_map<std::string, size_t>& outputMap, int64_t& maskIndex, int64_t& offsetIndex, |
| 52 | + const std::unordered_map<std::string, size_t>& optionalInputMap = {}); | ||
| 51 | 53 | ||
| 52 | } // namespace randomCommon | 54 | } // namespace randomCommon |
| 53 | } // namespace ops | 55 | } // namespace ops |
Mrandom/stateless_drop_out_gen_mask/op_host/arch35/stateless_drop_out_gen_mask_tiling_arch35.cpp+6-3
| @@ -49,7 +49,10 @@ OpTilingConfig StatelessDropOutGenMaskTiling::BuildOpConfig() | |||
| 49 | {1, {{ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16}, 1, {}, nullptr}}, // prob | 49 | {1, {{ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16}, 1, {}, nullptr}}, // prob |
| 50 | {2, {{ge::DT_INT32, ge::DT_INT64}, 1, {}, nullptr}}, // seed | 50 | {2, {{ge::DT_INT32, ge::DT_INT64}, 1, {}, nullptr}}, // seed |
| 51 | {3, {{ge::DT_INT32, ge::DT_INT64}, 1, {}, nullptr}}, // seed1 | 51 | {3, {{ge::DT_INT32, ge::DT_INT64}, 1, {}, nullptr}}, // seed1 |
| 52 | - {4, {{ge::DT_INT64}, -1, {}, nullptr}}, // offset | 52 | + }; |
| 53 | + | ||
| 54 | + config.optionalInputCheckRules = { | ||
| 55 | + {4, {{ge::DT_INT64}, -1, {}, nullptr}}, // offset (可选输入) | ||
| 53 | }; | 56 | }; |
| 54 | 57 | ||
| 55 | config.outputCheckRules = { | 58 | config.outputCheckRules = { |
| @@ -84,7 +87,7 @@ OpTilingConfig StatelessDropOutGenMaskTiling::BuildOpConfig() | |||
| 84 | counter[0] = 0; counter[1] = 0; counter[2] = 0; counter[3] = 0; | 87 | counter[0] = 0; counter[1] = 0; counter[2] = 0; counter[3] = 0; |
| 85 | 88 | ||
| 86 | // offset element count (shape info, no D2H needed) | 89 | // offset element count (shape info, no D2H needed) |
| 87 | - auto offsetTensor = ctx->GetRequiredInputTensor(IN_OFFSET_IDX); | 90 | + auto offsetTensor = ctx->GetOptionalInputTensor(IN_OFFSET_IDX); |
| 88 | uint32_t offsetElemCount = 2; | 91 | uint32_t offsetElemCount = 2; |
| 89 | if (offsetTensor != nullptr) { | 92 | if (offsetTensor != nullptr) { |
| 90 | offsetElemCount = static_cast<uint32_t>(offsetTensor->GetShapeSize()); | 93 | offsetElemCount = static_cast<uint32_t>(offsetTensor->GetShapeSize()); |
| @@ -92,7 +95,7 @@ OpTilingConfig StatelessDropOutGenMaskTiling::BuildOpConfig() | |||
| 92 | key[0] = offsetElemCount; | 95 | key[0] = offsetElemCount; |
| 93 | 96 | ||
| 94 | // seed byte size: 4 for INT32, 8 for INT64 (dtype info, no D2H needed) | 97 | // seed byte size: 4 for INT32, 8 for INT64 (dtype info, no D2H needed) |
| 95 | - auto seedDesc = ctx->GetInputDesc(IN_SEED_IDX); | 98 | + auto seedDesc = ctx->GetRequiredInputDesc(IN_SEED_IDX); |
| 96 | uint32_t seedByteSize = 8; | 99 | uint32_t seedByteSize = 8; |
| 97 | if (seedDesc != nullptr) { | 100 | if (seedDesc != nullptr) { |
| 98 | auto seedDtype = seedDesc->GetDataType(); | 101 | auto seedDtype = seedDesc->GetDataType(); |