* Copyright (c) 2025-2026 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
* \file real_graph_infer.cpp
* \brief Real operator graph infer resource (shape + dtype)
*/
#include "register/op_impl_registry.h"
#include "log/log.h"
using namespace ge;
namespace ops {
static constexpr int64_t INPUT_IDX = 0;
static constexpr int64_t OUTPUT_IDX = 0;
static ge::graphStatus RealInferShapeFunc(gert::InferShapeContext* context)
{
const gert::Shape* inShape = context->GetInputShape(INPUT_IDX);
if (inShape == nullptr) {
return GRAPH_FAILED;
}
gert::Shape* outShape = context->GetOutputShape(OUTPUT_IDX);
if (outShape == nullptr) {
return GRAPH_FAILED;
}
*outShape = *inShape;
return GRAPH_SUCCESS;
}
static ge::graphStatus RealInferDataTypeFunc(gert::InferDataTypeContext* context)
{
OP_LOGD(context, "Begin to do RealInferDataTypeFunc");
auto inputDtype = context->GetInputDataType(INPUT_IDX);
ge::DataType outputDtype = ge::DT_FLOAT;
switch (inputDtype) {
case ge::DT_FLOAT:
outputDtype = ge::DT_FLOAT;
break;
case ge::DT_FLOAT16:
outputDtype = ge::DT_FLOAT16;
break;
case ge::DT_COMPLEX64:
outputDtype = ge::DT_FLOAT;
break;
case ge::DT_COMPLEX32:
outputDtype = ge::DT_FLOAT16;
break;
case ge::DT_COMPLEX128:
outputDtype = ge::DT_DOUBLE;
break;
default:
OP_LOGE(context, "Unsupported input dtype for Real: %d", static_cast<int>(inputDtype));
return GRAPH_FAILED;
}
context->SetOutputDataType(OUTPUT_IDX, outputDtype);
OP_LOGD(context, "End to do RealInferDataTypeFunc");
return GRAPH_SUCCESS;
}
IMPL_OP(Real).InferShape(RealInferShapeFunc).InferDataType(RealInferDataTypeFunc);
}