Closed
feat(nn): 9 个算子支持 InferDataType(op_graph 注册,同步 rt1.0 dtype 推导策略) #10792
zzz2048Add on Sep 20Closed at 23 days ago
feat(nn): 9 个算子支持 InferDataType(op_graph 注册,同步 rt1.0 dtype 推导策略) #10792
Closed
zzz2048Add on Sep 20Closed at 23 days ago
Total: 10 files changed+295-0
@@ -0,0 +1,28 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file confusion_softmax_grad_graph_infer.cpp
13+ * \brief InferDataType for ConfusionSoftmaxGrad synced from rt1.0 (canndev) dtype strategy: y=grad
14+ */
15+ 
16+#include "register/op_impl_registry.h"
17+#include "log/log.h"
18+ 
19+using namespace ge;
20+namespace ops {
21+static ge::graphStatus InferDataTypeForConfusionSoftmaxGrad(gert::InferDataTypeContext* context)
22+{
23+ OP_LOGI("Begin InferDataTypeForConfusionSoftmaxGrad");
24+ context->SetOutputDataType(0, context->GetInputDataType(0));
25+ return ge::GRAPH_SUCCESS;
26+}
27+IMPL_OP(ConfusionSoftmaxGrad).InferDataType(InferDataTypeForConfusionSoftmaxGrad);
28+} // namespace ops
@@ -0,0 +1,28 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file log_softmax_grad_graph_infer.cpp
13+ * \brief InferDataType for LogSoftmaxGrad synced from rt1.0 (canndev) dtype strategy: y=x (grad is input 0)
14+ */
15+ 
16+#include "register/op_impl_registry.h"
17+#include "log/log.h"
18+ 
19+using namespace ge;
20+namespace ops {
21+static ge::graphStatus InferDataTypeForLogSoftmaxGrad(gert::InferDataTypeContext* context)
22+{
23+ OP_LOGI("Begin InferDataTypeForLogSoftmaxGrad");
24+ context->SetOutputDataType(0, context->GetInputDataType(1));
25+ return ge::GRAPH_SUCCESS;
26+}
27+IMPL_OP(LogSoftmaxGrad).InferDataType(InferDataTypeForLogSoftmaxGrad);
28+} // namespace ops
@@ -0,0 +1,28 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file log_softmax_v2_graph_infer.cpp
13+ * \brief InferDataType for LogSoftmaxV2 synced from rt1.0 (canndev) dtype strategy: logsoftmax=logits
14+ */
15+ 
16+#include "register/op_impl_registry.h"
17+#include "log/log.h"
18+ 
19+using namespace ge;
20+namespace ops {
21+static ge::graphStatus InferDataTypeForLogSoftmaxV2(gert::InferDataTypeContext* context)
22+{
23+ OP_LOGI("Begin InferDataTypeForLogSoftmaxV2");
24+ context->SetOutputDataType(0, context->GetInputDataType(0));
25+ return ge::GRAPH_SUCCESS;
26+}
27+IMPL_OP(LogSoftmaxV2).InferDataType(InferDataTypeForLogSoftmaxV2);
28+} // namespace ops
@@ -0,0 +1,32 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file softmax_grad_graph_infer.cpp
13+ * \brief InferDataType for SoftmaxGrad synced from rt1.0 (canndev) dtype strategy: grad_x=softmax
14+ */
15+ 
16+#include "register/op_impl_registry.h"
17+#include "log/log.h"
18+ 
19+using namespace ge;
20+namespace ops {
21+static ge::graphStatus InferDataTypeForSoftmaxGrad(gert::InferDataTypeContext* context)
22+{
23+ OP_LOGI("Begin InferDataTypeForSoftmaxGrad");
24+ auto yGradDtype = context->GetInputDataType(0);
25+ auto yDtype = context->GetInputDataType(1);
26+ OP_CHECK_IF(yGradDtype != yDtype, OP_LOGE(context->GetNodeName(), "yGrad and y datatypes are not the same"),
27+ return ge::GRAPH_FAILED);
28+ context->SetOutputDataType(0, yGradDtype);
29+ return ge::GRAPH_SUCCESS;
30+}
31+IMPL_OP(SoftmaxGrad).InferDataType(InferDataTypeForSoftmaxGrad);
32+} // namespace ops
@@ -0,0 +1,29 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file softmax_grad_infershape.cpp
13+ * \brief
14+ */
15+ 
16+#include "infershape_broadcast_util.h"
17+#include "register/op_impl_registry.h"
18+#include "log/log.h"
19+ 
20+using namespace ge;
21+namespace ops {
22+static ge::graphStatus InferShape4SoftmaxGrad(gert::InferShapeContext* context)
23+{
24+ OP_LOGI("Begin InferShape4SoftmaxGrad");
25+ return Ops::Base::InferShape4Broadcast(context);
26+}
27+ 
28+IMPL_OP_INFERSHAPE(SoftmaxGrad).InferShape(InferShape4SoftmaxGrad);
29+} // namespace ops
@@ -0,0 +1,30 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file layer_norm_graph_infer.cpp
13+ * \brief InferDataType for LayerNorm synced from rt1.0 (canndev) dtype strategy: y=x, mean=gamma, variance=beta
14+ */
15+ 
16+#include "register/op_impl_registry.h"
17+#include "log/log.h"
18+ 
19+using namespace ge;
20+namespace ops {
21+static ge::graphStatus InferDataTypeForLayerNorm(gert::InferDataTypeContext* context)
22+{
23+ OP_LOGI("Begin InferDataTypeForLayerNorm");
24+ context->SetOutputDataType(0, context->GetInputDataType(0));
25+ context->SetOutputDataType(1, context->GetInputDataType(1));
26+ context->SetOutputDataType(2, context->GetInputDataType(2));
27+ return ge::GRAPH_SUCCESS;
28+}
29+IMPL_OP(LayerNorm).InferDataType(InferDataTypeForLayerNorm);
30+} // namespace ops
@@ -0,0 +1,30 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file layer_norm_v3_graph_infer.cpp
13+ * \brief InferDataType for LayerNormV3 synced from rt1.0 (canndev) dtype strategy: y=x, mean=gamma, rstd=beta
14+ */
15+ 
16+#include "register/op_impl_registry.h"
17+#include "log/log.h"
18+ 
19+using namespace ge;
20+namespace ops {
21+static ge::graphStatus InferDataTypeForLayerNormV3(gert::InferDataTypeContext* context)
22+{
23+ OP_LOGI("Begin InferDataTypeForLayerNormV3");
24+ context->SetOutputDataType(0, context->GetInputDataType(0));
25+ context->SetOutputDataType(1, context->GetInputDataType(1));
26+ context->SetOutputDataType(2, context->GetInputDataType(2));
27+ return ge::GRAPH_SUCCESS;
28+}
29+IMPL_OP(LayerNormV3).InferDataType(InferDataTypeForLayerNormV3);
30+} // namespace ops
@@ -0,0 +1,29 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file sync_batch_norm_backward_elemt_graph_infer.cpp
13+ * \brief InferDataType for SyncBatchNormBackwardElemt synced from rt1.0 (canndev) dtype strategy:
14+ * grad_input=grad_output
15+ */
16+ 
17+#include "register/op_impl_registry.h"
18+#include "log/log.h"
19+ 
20+using namespace ge;
21+namespace ops {
22+static ge::graphStatus InferDataTypeForSyncBatchNormBackwardElemt(gert::InferDataTypeContext* context)
23+{
24+ OP_LOGI("Begin InferDataTypeForSyncBatchNormBackwardElemt");
25+ context->SetOutputDataType(0, context->GetInputDataType(0));
26+ return ge::GRAPH_SUCCESS;
27+}
28+IMPL_OP(SyncBatchNormBackwardElemt).InferDataType(InferDataTypeForSyncBatchNormBackwardElemt);
29+} // namespace ops
@@ -0,0 +1,29 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file sync_batch_norm_backward_reduce_graph_infer.cpp
13+ * \brief InferDataType for SyncBatchNormBackwardReduce synced from rt1.0 (canndev) dtype strategy: sum_dy_xmu/y=sum_dy
14+ */
15+ 
16+#include "register/op_impl_registry.h"
17+#include "log/log.h"
18+ 
19+using namespace ge;
20+namespace ops {
21+static ge::graphStatus InferDataTypeForSyncBatchNormBackwardReduce(gert::InferDataTypeContext* context)
22+{
23+ OP_LOGI("Begin InferDataTypeForSyncBatchNormBackwardReduce");
24+ context->SetOutputDataType(0, context->GetInputDataType(0));
25+ context->SetOutputDataType(1, context->GetInputDataType(0));
26+ return ge::GRAPH_SUCCESS;
27+}
28+IMPL_OP(SyncBatchNormBackwardReduce).InferDataType(InferDataTypeForSyncBatchNormBackwardReduce);
29+} // namespace ops
@@ -0,0 +1,32 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software: you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file sync_batch_norm_gather_stats_graph_infer.cpp
13+ * \brief InferDataType for SyncBatchNormGatherStats synced from rt1.0 (canndev) dtype strategy: all outputs
14+ * dtype=variance (input 4)
15+ */
16+ 
17+#include "register/op_impl_registry.h"
18+#include "log/log.h"
19+ 
20+using namespace ge;
21+namespace ops {
22+static ge::graphStatus InferDataTypeForSyncBatchNormGatherStats(gert::InferDataTypeContext* context)
23+{
24+ OP_LOGI("Begin InferDataTypeForSyncBatchNormGatherStats");
25+ context->SetOutputDataType(0, context->GetInputDataType(4));
26+ context->SetOutputDataType(1, context->GetInputDataType(4));
27+ context->SetOutputDataType(2, context->GetInputDataType(4));
28+ context->SetOutputDataType(3, context->GetInputDataType(4));
29+ return ge::GRAPH_SUCCESS;
30+}
31+IMPL_OP(SyncBatchNormGatherStats).InferDataType(InferDataTypeForSyncBatchNormGatherStats);
32+} // namespace ops