* 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.
*/
#include "micro_api_call_factory.h"
#include "ascir_ops.h"
#include "micro_where_api_call.h"
namespace codegen {
Status MicroWhereApiCall::Generate(const codegen::TensorManager &tensor_mng, [[maybe_unused]] const TPipe &tpipe,
CallParam ¶m, string &result) {
std::stringstream ss;
auto mask_tensor = tensor_mng.GetTensor(this->inputs_[0].second);
GE_ASSERT_NOTNULL(mask_tensor);
bool is_mask_reg = mask_tensor->init_as_mask_reg_;
std::string mask_name = is_mask_reg ? mask_tensor->name : (mask_tensor->name + "_temp_mask");
if (!is_mask_reg) {
std::string dtype_name;
Tensor::DtypeName(mask_tensor->dtype_, dtype_name);
ss << "AscendC::Reg::CompareScalar<" << dtype_name << ", AscendC::CMPMODE::NE>(" << mask_name << ", "
<< *mask_tensor << ", static_cast<" << dtype_name << ">(0), " << param.p_reg << ");" << std::endl;
}
ss << "AscendC::MicroAPI::" << this->api_name_ << "(";
for (auto out_arg : this->outputs_) {
GE_ASSERT_NOTNULL(tensor_mng.GetTensor(out_arg.second));
ss << *(tensor_mng.GetTensor(out_arg.second)) << ", ";
}
for (size_t i = 1; i < this->inputs_.size(); ++i) {
GE_ASSERT_NOTNULL(tensor_mng.GetTensor(this->inputs_[i].second));
ss << *(tensor_mng.GetTensor(this->inputs_[i].second)) << ", ";
}
ss << mask_name << ");" << std::endl;
result = ss.str();
return ge::SUCCESS;
}
static MicroApiCallRegister<MicroWhereApiCall> register_micro_where_api_call("MicroWhereApiCall");
}