* 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.
*/
*
* NOTE: Portions of this code were AI-generated and have been
* technically reviewed for functional accuracy and security
*/
* @file asin_with_agent.cpp
* @brief ACLNN L0 API 实现 - AsinWithAgent 算子
*
* L0 API 职责:形状推导、dtype 支持检查、Kernel 调度
*
* 输出 dtype 规则:
* - 输入 FLOAT/FLOAT16/DOUBLE -> 输出与输入相同 dtype
* - 输入 INT8/INT16/INT32/INT64/UINT8/BOOL -> 输出 FLOAT32
*
* 迭代二:激活全部 9 种 dtype(TilingKey 0-8)
*
* 注意:DOUBLE 类型在 aclnn_asin_with_agent.cpp(L2 API)层已完成 Host 端 fp64->fp32 转换,
* L0 API 接收到的已是 fp32 tensor,此处仍注册 DOUBLE 支持以保持接口一致性。
*/
#include "asin_with_agent.h"
#include "opdev/op_log.h"
#include "opdev/op_dfx.h"
#include "opdev/shape_utils.h"
#include "opdev/make_op_executor.h"
using namespace op;
namespace l0op {
OP_TYPE_REGISTER(AsinWithAgent);
static const std::initializer_list<op::DataType> AICORE_DTYPE_SUPPORT_LIST = {
DataType::DT_FLOAT,
DataType::DT_FLOAT16,
DataType::DT_DOUBLE,
DataType::DT_INT8,
DataType::DT_INT16,
DataType::DT_INT32,
DataType::DT_INT64,
DataType::DT_UINT8,
DataType::DT_BOOL,
};
static op::DataType GetOutputDtype(op::DataType inputDtype)
{
switch (inputDtype) {
case DataType::DT_FLOAT: return DataType::DT_FLOAT;
case DataType::DT_FLOAT16: return DataType::DT_FLOAT16;
case DataType::DT_DOUBLE: return DataType::DT_DOUBLE;
case DataType::DT_INT8:
case DataType::DT_INT16:
case DataType::DT_INT32:
case DataType::DT_INT64:
case DataType::DT_UINT8:
case DataType::DT_BOOL:
return DataType::DT_FLOAT;
default:
return DataType::DT_FLOAT;
}
}
static bool IsAiCoreSupport(const aclTensor* x)
{
return CheckType(x->GetDataType(), AICORE_DTYPE_SUPPORT_LIST);
}
static bool AsinWithAgentInferShape(const op::Shape& xShape, op::Shape& outShape)
{
outShape = xShape;
return true;
}
static const aclTensor* AsinWithAgentAiCore(
const aclTensor* x,
const aclTensor* out,
aclOpExecutor* executor)
{
L0_DFX(AsinWithAgentAiCore, x, out);
auto ret = ADD_TO_LAUNCHER_LIST_AICORE(AsinWithAgent,
OP_INPUT(x), OP_OUTPUT(out));
OP_CHECK(
ret == ACLNN_SUCCESS,
OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "AsinWithAgentAiCore failed."),
return nullptr);
return out;
}
* @brief L0 API 入口
*
* 流程:
* 1. InferShape - 形状推导
* 2. IsAiCoreSupport - 判断执行路径
* 3. AllocTensor - 分配输出 Tensor(dtype 根据输入 dtype 确定)
* 4. AsinWithAgentAiCore - 调用 Kernel
*/
const aclTensor* AsinWithAgent(const aclTensor* x, aclOpExecutor* executor)
{
Shape outShape;
const aclTensor* out = nullptr;
if (!AsinWithAgentInferShape(x->GetViewShape(), outShape)) {
OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Infer shape failed.");
return nullptr;
}
if (!IsAiCoreSupport(x)) {
OP_LOGE(ACLNN_ERR_PARAM_INVALID,
"AsinWithAgent not supported: dtype=%d.",
static_cast<int>(x->GetDataType()));
return nullptr;
}
op::DataType outDtype = GetOutputDtype(x->GetDataType());
out = executor->AllocTensor(outShape, outDtype);
if (out == nullptr) {
OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "AllocTensor for output failed.");
return nullptr;
}
return AsinWithAgentAiCore(x, out, executor);
}
}