LCOV - code coverage report
Current view: top level - ut/autofuse/codegen/api_call/elewise - binary_api_tmp_call.cpp Coverage Total Hit
Test: CHG Lines: 100.0 % 2 2
Test Date: 2026-08-20 14:29:00
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 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              : #include "binary_api_tmp_call.h"
      11              : 
      12              : #include <sstream>
      13              : #include "attr_utils.h"
      14              : #include "ascir_ops.h"
      15              : #include "common_utils.h"
      16              : #include "common/ge_common/debug/log.h"
      17              : #include "graph/ascendc_ir/utils//asc_tensor_utils.h"
      18              : #include "common/checker.h"
      19              : #include "api_call/utils/api_call_factory.h"
      20              : #include "codegen/expression_convert_struct.h"
      21              : 
      22              : namespace codegen {
      23              : using namespace std;
      24              : using namespace af::ops;
      25              : using namespace af::ascir_op;
      26              : using namespace ascgen_utils;
      27              : 
      28              : Status BinaryApiTmpCall::Generate(const TPipe &tpipe, const std::vector<ascir::AxisId> &current_axis,
      29              :                                   const std::vector<std::reference_wrapper<const Tensor>> &inputs,
      30              :                                   const std::vector<std::reference_wrapper<const Tensor>> &outputs,
      31              :                                   std::string &result) const {
      32           20 :   const size_t x1_idx = 0;
      33           20 :   const size_t x2_idx = 1;
      34              : 
      35              :   auto x1 = inputs[x1_idx].get();
      36              :   auto x2 = inputs[x2_idx].get();
      37              : 
      38              :   auto y = outputs[0].get();
      39              :   stringstream ss;
      40              :   // 获取tmp_buf复用TBuf的id
      41              :   int64_t life_time_axis_id = -1L;
      42              :   int64_t id = -1L;
      43              :   auto it = this->tmp_buf_id.find(life_time_axis_id);
      44              :   GE_ASSERT_TRUE(it != this->tmp_buf_id.end(), "BinaryApiTmpCall cannot find tmp buffer id to use.");
      45              :   id = it->second;
      46              : 
      47              :   (void)RegisterBasicDumpParam(this->api_name_, inputs, outputs, CombinedExprFactory::SymbolVar(x1.actual_size.Str()),
      48              :                                tpipe.tmp_buf.name + "_" + std::to_string(id));
      49              : 
      50              :   // 如果第2个输入是ub_scalar场景, 初始化x2为ub_scalar对应的变量
      51              :   bool is_scalar_scene = (x2.is_constant) || (x2.is_ub_scalar && x2.need_gen_get_value_of_ub_scalar);
      52              :   if (is_scalar_scene && (this->api_name_ == "LogicalOr" || this->api_name_ == "LogicalAnd")) {
      53              :     std::string dtype_name;
      54              :     GE_CHK_STATUS_RET(Tensor::DtypeName(x2.dtype, dtype_name), "Codegen get data type:%d failed",
      55              :                       static_cast<int32_t>(x2.dtype));
      56              :     std::string x2_scalar =
      57              :         x2.need_gen_get_value_of_ub_scalar ? ("(" + dtype_name + ")" + x2.ub_scalar_name) : x2.Str();
      58              :     ss << this->api_name_ << "ScalarExtend(" << y << "[" << tpipe.tiler.TensorVectorizedOffset(current_axis, y) << "], "
      59              :        << x1 << "[" << tpipe.tiler.TensorVectorizedOffset(current_axis, x1) << "], " << x2_scalar << ", "
      60              :        << tpipe.tmp_buf << "_" << std::to_string(id) << ", " << x1.actual_size << ");" << std::endl;
      61              :   } else {
      62              :     ss << this->api_name_ << "(" << y << "[" << tpipe.tiler.TensorVectorizedOffset(current_axis, y) << "], " << x1
      63              :        << "[" << tpipe.tiler.TensorVectorizedOffset(current_axis, x1) << "], " << x2 << "["
      64              :        << tpipe.tiler.TensorVectorizedOffset(current_axis, x2) << "], " << tpipe.tmp_buf << "_" << std::to_string(id)
      65              :        << ", " << x1.actual_size << ");" << std::endl;
      66              :   }
      67              : 
      68              :   result = ss.str();
      69              :   return af::SUCCESS;
      70              : }
      71              : 
      72              : static ApiCallRegister<BinaryApiTmpCall> register_binary_api_tmp_call("BinaryApiTmpCall");
      73              : 
      74              : }  // namespace codegen
        

Generated by: LCOV version 2.3.2-1