* Copyright (c) 2025 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 cummax.cpp
* \brief
*/
#include "cummax.h"
#include "opdev/aicpu/aicpu_task.h"
#include "opdev/data_type_utils.h"
#include "opdev/format_utils.h"
#include "opdev/make_op_executor.h"
#include "opdev/op_def.h"
#include "opdev/op_dfx.h"
#include "opdev/op_executor.h"
#include "opdev/op_log.h"
#include "opdev/shape_utils.h"
using namespace op;
namespace l0op {
OP_TYPE_REGISTER(Cummax);
static inline std::tuple<aclTensor*, aclTensor*> CummaxAiCpu(const aclTensor* self, int64_t dim, aclTensor* valuesOut,
aclTensor* indicesOut, aclOpExecutor* executor) {
L0_DFX(CummaxAiCpu, self, dim, valuesOut, indicesOut);
static internal::AicpuTaskSpace space("Cummax");
auto ret = ADD_TO_LAUNCHER_LIST_AICPU(Cummax, OP_ATTR_NAMES({"dim"}), OP_INPUT(self), OP_OUTPUT(valuesOut, indicesOut),
OP_ATTR(dim));
if (ret != ACL_SUCCESS) {
OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "CummaxAiCpu ADD_TO_LAUNCHER_LIST_AICPU failed.");
return std::tuple<aclTensor*, aclTensor*>(nullptr, nullptr);
}
return {valuesOut, indicesOut};
}
static inline std::tuple<aclTensor*, aclTensor*> CummaxExec(const aclTensor* self, int64_t dim, aclTensor* valuesOut,
aclTensor* indicesOut, aclOpExecutor* executor) {
if (valuesOut == nullptr || indicesOut == nullptr) {
OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "alloc out tensor failed.");
return {nullptr, nullptr};
}
return CummaxAiCpu(self, dim, valuesOut, indicesOut, executor);
}
std::tuple<aclTensor*, aclTensor*> CummaxOutInt32(const aclTensor* self, int64_t dim, aclOpExecutor* executor) {
auto valuesOut = executor->AllocTensor(self->GetViewShape(), self->GetDataType(), self->GetViewFormat());
auto indicesOut = executor->AllocTensor(self->GetViewShape(), DataType::DT_INT32, self->GetViewFormat());
return CummaxExec(self, dim, valuesOut, indicesOut, executor);
}
std::tuple<aclTensor*, aclTensor*> CummaxOutInt64(const aclTensor* self, int64_t dim, aclOpExecutor* executor) {
auto valuesOut = executor->AllocTensor(self->GetViewShape(), self->GetDataType(), self->GetViewFormat());
auto indicesOut = executor->AllocTensor(self->GetViewShape(), DataType::DT_INT64, self->GetViewFormat());
return CummaxExec(self, dim, valuesOut, indicesOut, executor);
}
}