* Copyright (c) 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 population_count_infer.cpp
* \brief PopulationCount operator graph infer datatype resource
*/
#include "register/op_impl_registry.h"
#include <set>
#include "population_count_proto.h"
#include "graph/utils/type_utils.h"
#include "op_common/log/log.h"
#include "log/log.h"
using namespace ge;
namespace ge {
IMPLEMT_VERIFIER(PopulationCount, VerifyPopulationCount)
{
const auto& inputDesc = op.GetInputDescByName("x");
const ge::DataType inputDtype = inputDesc.GetDataType();
const std::string inputDtypeStr = ge::TypeUtils::DataTypeToSerialString(inputDtype);
OP_LOGI("PopulationCount", "[VerifyPopulationCount] current input dtype of x = %s", inputDtypeStr.c_str());
static const std::set<ge::DataType> supportedDtypes = {ge::DT_INT8, ge::DT_INT16, ge::DT_INT32, ge::DT_INT64,
ge::DT_UINT8, ge::DT_UINT16, ge::DT_UINT32, ge::DT_UINT64};
if (supportedDtypes.count(inputDtype) == 0) {
ge::AscendString opName;
const char* entityName = "PopulationCount";
if (op.GetName(opName) == GRAPH_SUCCESS && opName.GetString() != nullptr) {
entityName = opName.GetString();
}
OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(
entityName, "x", inputDtypeStr.c_str(),
"only integer dtypes are supported; the Ascend950 AICore implementation supports "
"DT_INT16/DT_UINT16");
return GRAPH_FAILED;
}
return GRAPH_SUCCESS;
}
VERIFY_FUNC_REG(PopulationCount, VerifyPopulationCount);
}
namespace ops {
static ge::graphStatus InferDataType4PopulationCount(gert::InferDataTypeContext* context)
{
OP_LOGD(context->GetNodeName(), "Begin to do InferDataType4PopulationCount");
context->SetOutputDataType(0, ge::DT_UINT8);
OP_LOGD(context->GetNodeName(), "End to do InferDataType4PopulationCount");
return GRAPH_SUCCESS;
}
IMPL_OP(PopulationCount).InferDataType(InferDataType4PopulationCount);
}