* 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 opcode.h
* \brief
*/
#pragma once
#include <string>
#include <map>
#include <array>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include "interface/utils/common.h"
#include "tilefwk/error_code.h"
#include "tilefwk/data_type.h"
#include "tilefwk/error.h"
#include "verifier.h"
namespace npu::tile_fwk {
enum class Opcode {
OP_EXP,
OP_EXP2,
OP_EXPM1,
OP_NEG,
OP_RSQRT,
OP_RELU,
OP_LOG1P,
OP_PAD,
OP_FILLPAD,
OP_SQRT,
OP_CEIL,
OP_FLOOR,
OP_TRUNC,
OP_ROUND,
OP_RECIPROCAL,
OP_CAST,
OP_EXPAND,
OP_ONEHOT,
OP_COMPACT,
OP_LOGICALNOT,
OP_ROWMAX,
OP_ROWSUM,
OP_ROWEXPMAX,
OP_ROWEXPSUM,
OP_ROWSUMLINE,
OP_ROWMAXLINE,
OP_ROWMINLINE,
OP_ROWPRODLINE,
OP_ADDS,
OP_SUBS,
OP_MULS,
OP_DIVS,
OP_MODS,
OP_REMS,
OP_REMRS,
OP_MAXS,
OP_MINS,
OP_LRELU,
OP_BITWISEANDS,
OP_BITWISEORS,
OP_BITWISEXORS,
OP_TRIUL,
OP_POW,
OP_POWS,
OP_S_ADDS,
OP_S_SUBS,
OP_S_MULS,
OP_S_DIVS,
OP_S_MAXS,
OP_S_MINS,
OP_TRANSPOSE_MOVEIN,
OP_TRANSPOSE_MOVEOUT,
OP_TRANSPOSE_VNCHWCONV,
OP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TRIBUTED_COMBINE_SEND,
OP_MOE_DISTRIBUTED_COMBINE_RECEIVE,
OP_QUANTIZE_SYM,
OP_QUANTIZE_ASYM,
OP_DEQUANTIZE,
OP_TOPK,
OP_TILEDMRGSORT,
OP_BITSORT,
OP_MRGSORT,
OP_ARGSORT,
OP_EXTRACT,
OP_FUSED_OP,
OP_TWOTILEMRGSORT,
OP_EXTRACT_SINGLE,
OP_SORT_UB,
OP_RADIX_SELECT,
OP_TOPK_SORT,
OP_TOPK_MERGE,
OP_TOPK_EXTRACT,
OP_REDUCE_ACC,
OP_AICPU_CALL_AIC,
OP_AICPU_CALL_AIV,
OP_MAX_POOL,
OP_RANGE,
OP_UNIFORM,
OP_SORT,
OP_COMPARE_SWAP,
OP_MERGE,
OP_UNKNOWN
};
enum class OpCoreType { AIC, AIV, ANY, AICPU, HUB, GMATOMIC };
enum class OpCalcType {
ELMWISE,
CAST,
BROADCAST,
OTHER,
REDUCE,
MATMUL,
CONV,
MOVE_IN,
MOVE_OUT,
MOVE_LOCAL,
SYNC,
DISTRIBUTED,
SYS,
CALC_TYPE_BOTTOM
};
enum class AIVCore;
class TileOpCfg {
public:
TileOpCfg(){};
TileOpCfg(
std ::string code, PipeType pipeIdStart, PipeType pipeIdEnd, CoreType coreType,
AIVCore aivCore = static_cast<AIVCore>(-1))
: tileOpCode_(code), pipeIdStart_(pipeIdStart), pipeIdEnd_(pipeIdEnd), coreType_(coreType), aivCore_(aivCore)
{}
std::string tileOpCode_;
PipeType pipeIdStart_{PipeType::PIPE_S};
PipeType pipeIdEnd_{PipeType::PIPE_S};
CoreType coreType_{CoreType::AIV};
AIVCore aivCore_{static_cast<AIVCore>(-1)};
};
class OpcodeManager {
public:
static OpcodeManager& Inst()
{
static OpcodeManager inst;
return inst;
}
void RegisterInfo(
Opcode opcode, OpCoreType coreType, std::string str, std::vector<MemoryType> inputsMemType,
std::vector<MemoryType> outputsMemType, const TileOpCfg tileOpCfg, OpCalcType calcType,
const std::vector<std::string>& attrs = {}, VerifyOperationEntry verifyOperationEntry = nullptr,
std::unordered_map<std::string, std::vector<std::vector<TileOpFormat>>> supportOpFormatList = {});
void RegisterVectorBinary();
void RegisterVectorUnary();
void RegisterVectorSort();
void RegisterVectorReduction();
void RegisterVectorQuant();
void RegisterVector();
void RegisterCube();
void RegisterDistribute();
void RegisterCommon();
bool HasOpcode(Opcode opcode) const
{
return static_cast<int>(opcode) >= 0 && static_cast<size_t>(opcode) < opcodeInfos_.size();
}
bool HasOpcode(const std::string& str) const { return strToEnum_.count(str) > 0; }
Opcode GetOpcode(const std::string& str) const
{
auto it = strToEnum_.find(str);
ASSERT(VectorErrorCode::ERR_PARAM_INVALID, it != strToEnum_.end()) << "str not found in strToEnum_";
return it->second;
}
const std::string& GetOpcodeStr(Opcode opcode) const
{
ASSERT(VectorErrorCode::ERR_PARAM_INVALID, HasOpcode(opcode)) << "opcode not found";
return opcodeInfos_[static_cast<int>(opcode)].str;
}
OpCoreType GetCoreType(Opcode opcode) const
{
ASSERT(VectorErrorCode::ERR_PARAM_INVALID, HasOpcode(opcode)) << "Can't find op";
return opcodeInfos_[static_cast<int>(opcode)].coreType;
}
const TileOpCfg& GetTileOpCfg(Opcode opcode) const
{
ASSERT(VectorErrorCode::ERR_PARAM_INVALID, HasOpcode(opcode)) << "Can't find op";
return opcodeInfos_[static_cast<int>(opcode)].tileOpCfg;
}
bool MemTypeSensitive(Opcode opcode) const
{
auto& info = opcodeInfos_[static_cast<int>(opcode)];
return !info.inputsMemType.empty() || !info.outputsMemType.empty();
}
const std::vector<MemoryType>& GetInputsMemType(Opcode opcode) const
{
auto& info = opcodeInfos_[static_cast<int>(opcode)];
return info.inputsMemType;
}
const std::vector<MemoryType>& GetOutputsMemType(Opcode opcode) const
{
auto& info = opcodeInfos_[static_cast<int>(opcode)];
return info.outputsMemType;
}
OpCalcType GetOpCalcType(Opcode opcode) const
{
auto& info = opcodeInfos_[static_cast<int>(opcode)];
return info.calcType;
}
const std::vector<std::string>& GetAttrs(Opcode opcode) const
{
auto& info = opcodeInfos_[static_cast<int>(opcode)];
return info.attrs;
}
const std::unordered_map<std::string, std::vector<std::vector<TileOpFormat>>>& GetSupportOpFormatList(
Opcode opcode) const
{
auto& info = opcodeInfos_[static_cast<int>(opcode)];
return info.supportOpFormatList;
}
VerifyOperationEntry GetVerifyOperationEntry(Opcode opcode) const
{
auto& info = opcodeInfos_[static_cast<int>(opcode)];
return info.verifyOperationEntry;
}
bool HasStaticAttribute(Opcode opcode, const std::string& attribute) const
{
if (attribute.empty()) {
return false;
}
std::vector<std::string> attrs = GetAttrs(opcode);
return std::find(attrs.begin(), attrs.end(), attribute) != attrs.end();
}
std::string PrintSupportOpcodes() const
{
std::stringstream ss;
ss << "[";
bool isFirst = true;
for (const auto& info : opcodeInfos_) {
if (!isFirst) {
ss << ", ";
}
isFirst = false;
ss << info.str;
}
ss << "]";
return ss.str();
}
bool IsBoundaryIn(Opcode opcode) const
{
auto& info = opcodeInfos_[static_cast<int>(opcode)];
return info.calcType == OpCalcType::MOVE_IN;
}
bool IsBoundaryOut(Opcode opcode) const
{
auto& info = opcodeInfos_[static_cast<int>(opcode)];
return info.calcType == OpCalcType::MOVE_OUT;
}
inline bool IsCopyIn(Opcode opCode) const
{
return opCode == Opcode::OP_COPY_IN || opCode == Opcode::OP_UB_COPY_IN || opCode == Opcode::OP_L1_COPY_IN ||
opCode == Opcode::OP_TRANSPOSE_MOVEIN || opCode == Opcode::OP_RESHAPE_COPY_IN ||
opCode == Opcode::OP_L1_TO_FIX_QUANT_PRE || opCode == Opcode::OP_L1_TO_BT ||
opCode == Opcode::OP_SHMEM_LOAD || opCode == Opcode::OP_L1_COPY_IN_A_SCALE ||
opCode == Opcode::OP_L1_COPY_IN_B_SCALE || opCode == Opcode::OP_L1_COPY_IN_CONV ||
opCode == Opcode::OP_L1_RESHAPE_COPY_IN;
}
inline bool IsCopyOut(Opcode opCode) const
{
return opCode == Opcode::OP_COPY_OUT || opCode == Opcode::OP_UB_COPY_OUT || opCode == Opcode::OP_L0C_COPY_OUT ||
opCode == Opcode::OP_L1_COPY_OUT || opCode == Opcode::OP_TRANSPOSE_MOVEOUT ||
opCode == Opcode::OP_INDEX_OUTCAST || opCode == Opcode::OP_INDEX_PUT || opCode == Opcode::OP_FFN_SCHED ||
opCode == Opcode::OP_FFN_BATCHING || opCode == Opcode::OP_FFN_COMBINEINFO ||
opCode == Opcode::OP_INDEX_ADD || opCode == Opcode::OP_FFN_VALIDCNT ||
opCode == Opcode::OP_NCHW2NC1HWC0 || opCode == Opcode::OP_NCHW2Fractal_Z ||
opCode == Opcode::OP_NC1HWC02NCHW || opCode == Opcode::OP_NCDHW2NDC1HWC0 ||
opCode == Opcode::OP_NCDHW2FRACTAL_Z_3D || opCode == Opcode::OP_NDC1HWC02NCDHW ||
opCode == Opcode::OP_COPY_TO_LOCAL_EXPERT || opCode == Opcode::OP_SHMEM_PUT ||
opCode == Opcode::OP_SHMEM_SIGNAL || opCode == Opcode::OP_SHMEM_GET ||
opCode == Opcode::OP_SHMEM_STORE || opCode == Opcode::OP_RESHAPE_COPY_OUT ||
opCode == Opcode::OP_MOE_DISTRIBUTED_COMBINE_SEND ||
opCode == Opcode::OP_MOE_DISTRIBUTED_COMBINE_RECEIVE || opCode == Opcode::OP_L0C_COPY_OUT_CONV ||
opCode == Opcode::OP_L0C_RESHAPE_COPY_OUT;
}
inline bool IsCopyInOrOut(Opcode opCode) const { return IsCopyIn(opCode) || IsCopyOut(opCode); }
inline bool IsSync(Opcode opcode) const { return opcode == Opcode::OP_SYNC_SRC || opcode == Opcode::OP_SYNC_DST; }
inline bool IsSharedMemory(Opcode opCode) const
{
return opCode == Opcode::OP_SHMEM_WAIT_UNTIL || opCode == Opcode::OP_SHMEM_PUT ||
opCode == Opcode::OP_SHMEM_SIGNAL || opCode == Opcode::OP_SHMEM_GET ||
opCode == Opcode::OP_FFN_VALIDCNT || opCode == Opcode::OP_SHMEM_SET ||
opCode == Opcode::OP_SHMEM_STORE || opCode == Opcode::OP_SHMEM_LOAD ||
opCode == Opcode::OP_MOE_DISTRIBUTED_COMBINE_SEND ||
opCode == Opcode::OP_MOE_DISTRIBUTED_COMBINE_RECEIVE || opCode == Opcode::OP_FFN_BATCHING ||
opCode == Opcode::OP_SEND_TO_ROUTING_EXPERT || opCode == Opcode::OP_COPY_TO_LOCAL_EXPERT ||
opCode == Opcode::OP_DISPATCH_SET_FLAG || opCode == Opcode::OP_FFN_SCHED ||
opCode == Opcode::OP_FFN_COMBINEINFO;
}
private:
struct OpcodeInfo {
Opcode opcode;
OpCoreType coreType;
std::string str;
std::vector<MemoryType> inputsMemType;
std::vector<MemoryType> outputsMemType;
TileOpCfg tileOpCfg;
OpCalcType calcType;
std::vector<std::string> attrs;
VerifyOperationEntry verifyOperationEntry;
std::unordered_map<std::string, std::vector<std::vector<TileOpFormat>>> supportOpFormatList;
};
private:
OpcodeManager();
private:
std::array<OpcodeInfo, static_cast<int>(Opcode::OP_UNKNOWN)> opcodeInfos_{};
std::unordered_map<std::string, Opcode> strToEnum_;
std::unordered_set<Opcode> registered_;
};
inline Opcode FindOpcode(const std::string& op)
{
std::string originOp = op;
constexpr int32_t END_VALUE_4 = 4;
constexpr int32_t END_VALUE_5 = 5;
if (op.substr(0, END_VALUE_5) == "TILE_") {
originOp = originOp.substr(END_VALUE_5);
}
if (op.substr(0, END_VALUE_4) == "CALL") {
originOp = "CALL";
}
if (!OpcodeManager::Inst().HasOpcode(originOp)) {
ASSERT(OperationErr::OP_INVALID_OPCODE, 0) << "Can't find op " << originOp << "\n"
<< OpcodeManager::Inst().PrintSupportOpcodes();
}
return OpcodeManager::Inst().GetOpcode(originOp);
}
const std::unordered_set<Opcode> ALLOC_OPCODE = {Opcode::OP_UB_ALLOC, Opcode::OP_L1_ALLOC, Opcode::OP_L0A_ALLOC,
Opcode::OP_L0B_ALLOC, Opcode::OP_L0C_ALLOC, Opcode::OP_FIX_ALLOC,
Opcode::OP_BT_ALLOC};
const std::unordered_set<Opcode> BINARY_OPS{
Opcode::OP_ADD,
Opcode::OP_SUB,
Opcode::OP_MUL,
Opcode::OP_DIV,
Opcode::OP_MOD,
Opcode::OP_S_ADD,
Opcode::OP_S_SUB,
Opcode::OP_S_MUL,
Opcode::OP_S_DIV,
Opcode::OP_S_MAX,
Opcode::OP_S_MIN,
Opcode::OP_MAXIMUM,
Opcode::OP_MINIMUM,
Opcode::OP_PAIRSUM,
Opcode::OP_PAIRMAX,
Opcode::OP_PAIRMIN,
Opcode::OP_PAIRPROD,
Opcode::OP_BITWISERIGHTSHIFT,
Opcode::OP_BITWISELEFTSHIFT,
Opcode::OP_BITWISEAND,
Opcode::OP_BITWISEOR,
Opcode::OP_BITWISEXOR,
Opcode::OP_EXPANDEXPDIF,
Opcode::OP_COPYSIGN,
Opcode::OP_FLOORDIV,
Opcode::OP_FLOORDIVS};
const std::unordered_set<Opcode> BINARY_WITH_BRC_OPS{Opcode::OP_ADD_BRC, Opcode::OP_SUB_BRC, Opcode::OP_MUL_BRC,
Opcode::OP_DIV_BRC, Opcode::OP_MAX_BRC, Opcode::OP_MIN_BRC};
const std::unordered_set<Opcode> UNARY_OPS{
Opcode::OP_EXP, Opcode::OP_EXP2, Opcode::OP_EXPM1, Opcode::OP_NEG, Opcode::OP_RSQRT,
Opcode::OP_SQRT, Opcode::OP_RELU, Opcode::OP_CEIL, Opcode::OP_FLOOR, Opcode::OP_TRUNC,
Opcode::OP_EXPAND, Opcode::OP_RECIPROCAL, Opcode::OP_PAD, Opcode::OP_FILLPAD, Opcode::OP_ROWSUM,
Opcode::OP_ROWMAX, Opcode::OP_ROWEXPSUM, Opcode::OP_ROWEXPMAX, Opcode::OP_L1_TO_L1, Opcode::OP_COPY_UB_TO_UB,
Opcode::OP_ROUND, Opcode::OP_ROWSUMLINE, Opcode::OP_ABS, Opcode::OP_LN, Opcode::OP_ISFINITE,
Opcode::OP_HUB, Opcode::OP_BITWISENOT, Opcode::OP_SIGN, Opcode::OP_ROWPRODLINE, Opcode::OP_SIGNBIT,
Opcode::OP_SIN, Opcode::OP_COS, Opcode::OP_ERFC, Opcode::OP_ASIN, Opcode::OP_ACOS,
Opcode::OP_ERF};
const std::unordered_set<Opcode> UNARY_OPS_WITH_TMP{
Opcode::OP_COMPACT,
Opcode::OP_ROWSUM_SINGLE,
Opcode::OP_ROWMAX_SINGLE,
Opcode::OP_ROWMIN_SINGLE,
Opcode::OP_TRANSPOSE_VNCHWCONV,
Opcode::OP_ROWARGMAXWITHVALUE_SINGLE,
Opcode::OP_ROWARGMINWITHVALUE_SINGLE,
Opcode::OP_ROWARGMAXWITHVALUE_LINE,
Opcode::OP_ROWARGMINWITHVALUE_LINE,
Opcode::OP_ROWPROD_SINGLE,
Opcode::OP_ERF,
Opcode::OP_TAN,
Opcode::OP_SIN,
Opcode::OP_COS,
Opcode::OP_SINH,
Opcode::OP_COSH,
Opcode::OP_ERFC,
Opcode::OP_ASINH,
Opcode::OP_ACOSH,
Opcode::OP_TANH,
Opcode::OP_ASIN,
Opcode::OP_ACOS,
Opcode::OP_ATANH};
const std::unordered_set<Opcode> VECTOR_SCALAR_OPS{
Opcode::OP_ADDS,
Opcode::OP_SUBS,
Opcode::OP_MULS,
Opcode::OP_DIVS,
Opcode::OP_MAXS,
Opcode::OP_MINS,
Opcode::OP_BITWISEANDS,
Opcode::OP_BITWISEORS,
Opcode::OP_BITWISEXORS,
Opcode::OP_BITWISERIGHTSHIFTS,
Opcode::OP_BITWISELEFTSHIFTS,
Opcode::OP_SBITWISERIGHTSHIFT,
Opcode::OP_SBITWISELEFTSHIFT,
Opcode::OP_COPYSIGN,
Opcode::OP_LRELU};
const std::unordered_set<Opcode> SCLAR_VECTOR_SCALAR_OPS{Opcode::OP_S_ADDS, Opcode::OP_S_SUBS, Opcode::OP_S_MULS,
Opcode::OP_S_DIVS, Opcode::OP_S_MAXS, Opcode::OP_S_MINS};
const std::unordered_set<Opcode> CAST_OPS{Opcode::OP_CAST};
const std::unordered_set<Opcode> GATHER_OPS{Opcode::OP_GATHER};
const std::unordered_set<Opcode> WHERE_OPS{
Opcode::OP_WHERE_TT, Opcode::OP_WHERE_TS, Opcode::OP_WHERE_ST, Opcode::OP_WHERE_SS};
const std::unordered_set<Opcode> GATHER_ELEMENT_OPS{Opcode::OP_GATHER_ELEMENT};
const std::unordered_set<Opcode> GATHER_MASK_OPS{Opcode::OP_GATHER_MASK};
const std::unordered_set<Opcode> SCATTER_ELEMENT_OPS{Opcode::OP_SCATTER_ELEMENT};
const std::unordered_set<Opcode> SCATTER_OPS{Opcode::OP_SCATTER};
const std::unordered_set<Opcode> INDEX_ADD_OPS{Opcode::OP_INDEX_ADD_UB, Opcode::OP_INDEX_ADD};
const std::unordered_set<Opcode> INDEX_PUT_OPS{Opcode::OP_INDEX_PUT};
const std::unordered_set<Opcode> CUM_SUM_OPS{Opcode::OP_CUM_SUM};
const std::unordered_set<Opcode> SUPPORT_DYNAMIC_UNALIGNED_OPS{
Opcode::OP_RANGE,
Opcode::OP_TRANSPOSE_VNCHWCONV,
Opcode::OP_GATHER_ELEMENT,
Opcode::OP_INDEX_ADD,
Opcode::OP_CUM_SUM,
Opcode::OP_CUM_PROD,
Opcode::OP_TRIUL,
Opcode::OP_COPY_IN,
Opcode::OP_UB_COPY_IN,
Opcode::OP_L1_COPY_IN,
Opcode::OP_COPY_OUT,
Opcode::OP_UB_COPY_OUT,
Opcode::OP_L1_COPY_OUT,
Opcode::OP_L0C_COPY_OUT,
Opcode::OP_TRANSPOSE_MOVEOUT,
Opcode::OP_NCHW2NC1HWC0,
Opcode::OP_NCHW2Fractal_Z,
Opcode::OP_NC1HWC02NCHW,
Opcode::OP_NCDHW2NDC1HWC0,
Opcode::OP_NCDHW2FRACTAL_Z_3D,
Opcode::OP_NDC1HWC02NCDHW,
Opcode::OP_INDEX_OUTCAST,
Opcode::OP_ADD,
Opcode::OP_SUB,
Opcode::OP_MUL,
Opcode::OP_DIV,
Opcode::OP_EXP,
Opcode::OP_EXP2,
Opcode::OP_EXPM1,
Opcode::OP_NEG,
Opcode::OP_LN,
Opcode::OP_HUB,
Opcode::OP_ABS,
Opcode::OP_RSQRT,
Opcode::OP_RELU,
Opcode::OP_LOG1P,
Opcode::OP_CEIL,
Opcode::OP_FLOOR,
Opcode::OP_TRUNC,
Opcode::OP_SQRT,
Opcode::OP_RECIPROCAL,
Opcode::OP_CAST,
Opcode::OP_ISFINITE,
Opcode::OP_ADDS,
Opcode::OP_SUBS,
Opcode::OP_MULS,
Opcode::OP_DIVS,
Opcode::OP_MAXS,
Opcode::OP_MINS,
Opcode::OP_PAD,
Opcode::OP_FILLPAD,
Opcode::OP_PAIRMAX,
Opcode::OP_PAIRSUM,
Opcode::OP_ROWMAX_SINGLE,
Opcode::OP_ROWSUM_SINGLE,
Opcode::OP_EXPAND,
Opcode::OP_VEC_DUP,
Opcode::OP_MAXIMUM,
Opcode::OP_MINIMUM,
Opcode::OP_L1_TO_L0A,
Opcode::OP_LOGICALNOT,
Opcode::OP_LOGICALAND,
Opcode::OP_ONEHOT,
Opcode::OP_INDEX_PUT,
Opcode::OP_L1_TO_L0_BT,
Opcode::OP_L1_TO_L0B,
Opcode::OP_L1_TO_L0_AT,
Opcode::OP_A_MUL_B,
Opcode::OP_A_MULACC_B,
Opcode::OP_A_MUL_BT,
Opcode::OP_AT_MUL_B,
Opcode::OP_AT_MUL_BT,
Opcode::OP_WHERE_TT,
Opcode::OP_WHERE_TS,
Opcode::OP_WHERE_ST,
Opcode::OP_WHERE_SS,
Opcode::OP_ROWSUMLINE,
Opcode::OP_ROWARGMAXWITHVALUE_SINGLE,
Opcode::OP_ROWARGMINWITHVALUE_SINGLE,
Opcode::OP_ROWARGMAXWITHVALUE_LINE,
Opcode::OP_ROWARGMINWITHVALUE_LINE,
Opcode::OP_ADD_BRC,
Opcode::OP_ADD_BRC,
Opcode::OP_SUB_BRC,
Opcode::OP_MUL_BRC,
Opcode::OP_DIV_BRC,
Opcode::OP_MAX_BRC,
Opcode::OP_MIN_BRC,
Opcode::OP_GATHER,
Opcode::OP_INDEX_ADD_UB,
Opcode::OP_HYPOT,
Opcode::OP_S_ADDS,
Opcode::OP_LRELU,
Opcode::OP_REM,
Opcode::OP_REMS,
Opcode::OP_REMRS,
Opcode::OP_S_SUBS,
Opcode::OP_S_DIVS,
Opcode::OP_S_MULS,
Opcode::OP_S_MAXS,
Opcode::OP_S_MINS,
Opcode::OP_ROUND,
Opcode::OP_BITSORT,
Opcode::OP_MRGSORT,
Opcode::OP_CMP,
Opcode::OP_CMPS,
Opcode::OP_EXTRACT,
Opcode::OP_PRELU,
Opcode::OP_SIN,
Opcode::OP_COS,
Opcode::OP_ERFC,
Opcode::OP_ERF,
Opcode::OP_TILEDMRGSORT,
Opcode::OP_ROWMAXLINE,
Opcode::OP_PAIRMIN,
Opcode::OP_ROWMIN_SINGLE,
Opcode::OP_ROWMINLINE,
Opcode::OP_QUANTIZE_SYM,
Opcode::OP_QUANTIZE_ASYM,
Opcode::OP_DEQUANTIZE,
Opcode::OP_TOPK_SORT,
Opcode::OP_TOPK_MERGE,
Opcode::OP_TOPK_EXTRACT,
Opcode::OP_SCATTER_ELEMENT,
Opcode::OP_SIGN,
Opcode::OP_SIGNBIT,
Opcode::OP_TRANSPOSE_MOVEIN,
Opcode::OP_SORT,
Opcode::OP_COMPARE_SWAP,
Opcode::OP_MERGE,
Opcode::OP_L0C_TO_L1,
Opcode::OP_SCATTER,
Opcode::OP_GATHER_FROM_UB,
Opcode::OP_RESHAPE_COPY_IN,
Opcode::OP_RESHAPE_COPY_OUT,
Opcode::OP_L1_TO_FIX_QUANT_PRE,
Opcode::OP_L1_TO_BT,
Opcode::OP_BRCB,
Opcode::OP_MOD,
Opcode::OP_MODS,
Opcode::OP_BITWISEAND,
Opcode::OP_BITWISEOR,
Opcode::OP_BITWISEXOR,
Opcode::OP_BITWISEANDS,
Opcode::OP_BITWISEORS,
Opcode::OP_BITWISEXORS,
Opcode::OP_EXPANDEXPDIF,
Opcode::OP_BITWISENOT,
Opcode::OP_BITWISERIGHTSHIFT,
Opcode::OP_BITWISELEFTSHIFT,
Opcode::OP_BITWISERIGHTSHIFTS,
Opcode::OP_BITWISELEFTSHIFTS,
Opcode::OP_SBITWISERIGHTSHIFT,
Opcode::OP_SBITWISELEFTSHIFT,
Opcode::OP_COPYSIGN,
Opcode::OP_TWOTILEMRGSORT,
Opcode::OP_EXTRACT_SINGLE,
Opcode::OP_SORT_UB,
Opcode::OP_GATHER_MASK,
Opcode::OP_GATHER_MASK_BUILDIN,
Opcode::OP_PAIRPROD,
Opcode::OP_ROWPROD_SINGLE,
Opcode::OP_ROWPRODLINE,
Opcode::OP_FLOORDIV,
Opcode::OP_FLOORDIVS};
const std::unordered_set<Opcode> UNSUPPORT_FP16_OPS{
Opcode::OP_MULS,
Opcode::OP_MUL,
Opcode::OP_ADDS,
Opcode::OP_SUBS,
Opcode::OP_ADD,
Opcode::OP_SUB,
Opcode::OP_MOD,
Opcode::OP_MODS};
const std::unordered_set<Opcode> UNSUPPORT_FP16_ARCH35_OPS{
Opcode::OP_MULS,
Opcode::OP_MUL,
Opcode::OP_ADDS,
Opcode::OP_SUBS,
Opcode::OP_ADD,
Opcode::OP_SUB,
};
const std::unordered_set<Opcode> UNSUPPORT_BF16_OPS{
Opcode::OP_INDEX_ADD,
Opcode::OP_EXP,
Opcode::OP_RSQRT,
Opcode::OP_SQRT,
Opcode::OP_RELU,
Opcode::OP_RECIPROCAL,
Opcode::OP_ABS,
Opcode::OP_LN,
Opcode::OP_LOGICALNOT,
Opcode::OP_TRIUL,
Opcode::OP_REMRS,
Opcode::OP_LOGICALAND,
Opcode::OP_ADDS,
Opcode::OP_SUBS,
Opcode::OP_MULS,
Opcode::OP_DIVS,
Opcode::OP_REM,
Opcode::OP_REMS,
Opcode::OP_MAXS,
Opcode::OP_MINS,
Opcode::OP_S_ADDS,
Opcode::OP_S_SUBS,
Opcode::OP_S_MULS,
Opcode::OP_S_DIVS,
Opcode::OP_S_MAXS,
Opcode::OP_S_MINS,
Opcode::OP_NEG,
Opcode::OP_MAXIMUM,
Opcode::OP_MINIMUM,
Opcode::OP_ADD,
Opcode::OP_SUB,
Opcode::OP_MUL,
Opcode::OP_DIV,
Opcode::OP_ADD_BRC,
Opcode::OP_SUB_BRC,
Opcode::OP_MUL_BRC,
Opcode::OP_DIV_BRC,
Opcode::OP_MAX_BRC,
Opcode::OP_MIN_BRC,
Opcode::OP_S_ADD,
Opcode::OP_S_SUB,
Opcode::OP_S_MUL,
Opcode::OP_S_DIV,
Opcode::OP_S_MAX,
Opcode::OP_S_MIN,
Opcode::OP_WHERE_TT,
Opcode::OP_WHERE_TS,
Opcode::OP_PRELU,
Opcode::OP_WHERE_ST,
Opcode::OP_WHERE_SS,
Opcode::OP_ROWMAX,
Opcode::OP_ROWSUM,
Opcode::OP_ROWEXPMAX,
Opcode::OP_ROWEXPSUM,
Opcode::OP_ROWSUMLINE,
Opcode::OP_ROWMAXLINE,
Opcode::OP_ROWMINLINE,
Opcode::OP_ROWMAX_SINGLE,
Opcode::OP_ROWMIN_SINGLE,
Opcode::OP_ROWSUM_SINGLE,
Opcode::OP_ROWARGMAXWITHVALUE_SINGLE,
Opcode::OP_ROWARGMINWITHVALUE_SINGLE,
Opcode::OP_ROWARGMAXWITHVALUE_LINE,
Opcode::OP_ROWARGMINWITHVALUE_LINE,
Opcode::OP_ROWARGMAX_SINGLE,
Opcode::OP_ROWARGMIN_SINGLE,
Opcode::OP_SIGN,
Opcode::OP_MOD,
Opcode::OP_MODS,
Opcode::OP_BITWISEAND,
Opcode::OP_BITWISEOR,
Opcode::OP_BITWISEXOR,
Opcode::OP_BITWISEANDS,
Opcode::OP_BITWISEORS,
Opcode::OP_BITWISEXORS,
Opcode::OP_EXPANDEXPDIF,
Opcode::OP_BITWISENOT,
Opcode::OP_BITWISERIGHTSHIFT,
Opcode::OP_BITWISELEFTSHIFT,
Opcode::OP_BITWISERIGHTSHIFTS,
Opcode::OP_BITWISELEFTSHIFTS,
Opcode::OP_SBITWISERIGHTSHIFT,
Opcode::OP_SBITWISELEFTSHIFT,
Opcode::OP_COPYSIGN,
Opcode::OP_LRELU,
Opcode::OP_ROWPROD_SINGLE,
Opcode::OP_ROWPRODLINE,
Opcode::OP_FLOORDIV,
Opcode::OP_FLOORDIVS,
Opcode::OP_SINH,
Opcode::OP_COSH};
const std::unordered_set<Opcode> UNSUPPORT_BF16_ARCH35_OPS{
Opcode::OP_MULS,
Opcode::OP_MUL,
Opcode::OP_ADDS,
Opcode::OP_SUBS,
Opcode::OP_ADD,
Opcode::OP_SUB,
Opcode::OP_INDEX_ADD,
Opcode::OP_EXP,
Opcode::OP_RSQRT,
Opcode::OP_SQRT,
Opcode::OP_RELU,
Opcode::OP_RECIPROCAL,
Opcode::OP_ABS,
Opcode::OP_LOGICALNOT,
Opcode::OP_LOGICALAND,
Opcode::OP_DIVS,
Opcode::OP_DIV,
Opcode::OP_EXPANDEXPDIF,
Opcode::OP_ROWSUMLINE,
Opcode::OP_ROWARGMAXWITHVALUE_SINGLE,
Opcode::OP_ROWARGMINWITHVALUE_SINGLE,
Opcode::OP_ROWARGMAXWITHVALUE_LINE,
Opcode::OP_ROWARGMINWITHVALUE_LINE,
Opcode::OP_ROWARGMAX_SINGLE,
Opcode::OP_ROWARGMIN_SINGLE,
Opcode::OP_ROWMAXLINE,
Opcode::OP_ROWMINLINE,
Opcode::OP_ROWMAX_SINGLE,
Opcode::OP_REMRS,
Opcode::OP_REM,
Opcode::OP_ROWMIN_SINGLE,
Opcode::OP_ROWSUM_SINGLE,
Opcode::OP_MOD,
Opcode::OP_MODS,
Opcode::OP_PRELU,
Opcode::OP_ROWPROD_SINGLE,
Opcode::OP_ROWPRODLINE,
Opcode::OP_REMS,
Opcode::OP_LRELU,
};
const std::unordered_set<Opcode> FIX_COPY_IN_OPS{
Opcode::OP_L1_TO_FIX, Opcode::OP_L1_TO_FIX_QUANT_PRE, Opcode::OP_L1_TO_FIX_RELU_PRE,
Opcode::OP_L1_TO_FIX_RELU_POST, Opcode::OP_L1_TO_FIX_QUANT_POST, Opcode::OP_L1_TO_FIX_ELT_ANTIQ,
Opcode::OP_L1_TO_FIX_MTE2_ANTIQ};
const std::unordered_set<Opcode> CROSS_L1_UB_OPS{
Opcode::OP_L1_COPY_UB, Opcode::OP_L0C_COPY_UB, Opcode::OP_UB_COPY_L1, Opcode::OP_UB_COPY_L1_ND,
Opcode::OP_L0C_TO_L1};
const std::unordered_set<Opcode> LOGICALNOT_OPS{Opcode::OP_LOGICALNOT};
const std::unordered_set<Opcode> LOGICALAND_OPS{Opcode::OP_LOGICALAND};
const std::unordered_set<Opcode> DISTRIBUTED_OPS{
Opcode::OP_SEND_TO_ROUTING_EXPERT,
Opcode::OP_SEND_TO_SHARED_EXPERT,
Opcode::OP_COPY_TO_LOCAL_EXPERT,
Opcode::OP_DISPATCH_SET_FLAG,
Opcode::OP_FFN_SCHED,
Opcode::OP_FFN_BATCHING,
Opcode::OP_FFN_COMBINEINFO,
Opcode::OP_FFN_VALIDCNT,
Opcode::OP_SHMEM_PUT,
Opcode::OP_SHMEM_SIGNAL,
Opcode::OP_SHMEM_GET,
Opcode::OP_MOE_DISTRIBUTED_COMBINE_RECEIVE,
Opcode::OP_BIND_TENSOR,
Opcode::OP_SHMEM_STORE,
Opcode::OP_SHMEM_LOAD,
Opcode::OP_SHMEM_SET,
Opcode::OP_MOE_DISTRIBUTED_COMBINE_SEND};
const std::unordered_set<Opcode> LASTUSE_OPS{
Opcode::OP_ADD, Opcode::OP_SUB, Opcode::OP_MUL, Opcode::OP_DIV,
Opcode::OP_ADDS, Opcode::OP_SUBS, Opcode::OP_MULS, Opcode::OP_MAXS,
Opcode::OP_MINS, Opcode::OP_EXP, Opcode::OP_LRELU, Opcode::OP_BRCB,
Opcode::OP_BITWISENOT, Opcode::OP_SORT, Opcode::OP_SQRT, Opcode::OP_RSQRT,
Opcode::OP_RECIPROCAL, Opcode::OP_CONVERT, Opcode::OP_EXPAND, Opcode::OP_ROWEXPMAX,
Opcode::OP_ROWMAX, Opcode::OP_ROWSUM, Opcode::OP_CAST, Opcode::OP_ROWSUM_SINGLE,
Opcode::OP_ROWMAX_SINGLE, Opcode::OP_ROWMIN_SINGLE, Opcode::OP_DIVS, Opcode::OP_ABS,
Opcode::OP_MAXIMUM, Opcode::OP_MINIMUM, Opcode::OP_BITWISEAND, Opcode::OP_BITWISEOR,
Opcode::OP_BITWISEANDS, Opcode::OP_BITWISEORS, Opcode::OP_RELU, Opcode::OP_MODS,
Opcode::OP_MOD, Opcode::OP_SIGN, Opcode::OP_PRELU, Opcode::OP_ROWPROD_SINGLE,
Opcode::OP_SIGNBIT};
inline bool IsAllocOpCode(Opcode opCode) { return (ALLOC_OPCODE.count(opCode) != 0); }
inline bool IsCopyIn(const Opcode opCode)
{
return opCode == Opcode::OP_COPY_IN || opCode == Opcode::OP_UB_COPY_IN || opCode == Opcode::OP_L1_COPY_IN ||
opCode == Opcode::OP_TRANSPOSE_MOVEIN || opCode == Opcode::OP_RESHAPE_COPY_IN ||
opCode == Opcode::OP_SHMEM_LOAD || opCode == Opcode::OP_L1_COPY_IN_A_SCALE ||
opCode == Opcode::OP_L1_COPY_IN_B_SCALE || opCode == Opcode::OP_L1_COPY_IN_CONV ||
opCode == Opcode::OP_L1_RESHAPE_COPY_IN;
}
inline bool IsCopyOut(const Opcode& op)
{
return (
op == Opcode::OP_COPY_OUT || op == Opcode::OP_L0C_COPY_OUT || op == Opcode::OP_TRANSPOSE_MOVEOUT ||
op == Opcode::OP_INDEX_OUTCAST || op == Opcode::OP_FFN_SCHED || op == Opcode::OP_FFN_BATCHING ||
op == Opcode::OP_INDEX_PUT || op == Opcode::OP_FFN_COMBINEINFO || op == Opcode::OP_FFN_VALIDCNT ||
op == Opcode::OP_COPY_TO_LOCAL_EXPERT || op == Opcode::OP_SHMEM_PUT || op == Opcode::OP_SHMEM_SIGNAL ||
op == Opcode::OP_SHMEM_GET || op == Opcode::OP_SHMEM_SET || op == Opcode::OP_RESHAPE_COPY_OUT ||
op == Opcode::OP_SHMEM_STORE || op == Opcode::OP_MOE_DISTRIBUTED_COMBINE_RECEIVE ||
op == Opcode::OP_NCHW2NC1HWC0 || op == Opcode::OP_NCHW2Fractal_Z || op == Opcode::OP_NC1HWC02NCHW ||
op == Opcode::OP_NDC1HWC02NCDHW || op == Opcode::OP_NCDHW2NDC1HWC0 || op == Opcode::OP_NCDHW2FRACTAL_Z_3D ||
op == Opcode::OP_MOE_DISTRIBUTED_COMBINE_SEND || op == Opcode::OP_INDEX_ADD ||
op == Opcode::OP_L0C_COPY_OUT_CONV || op == Opcode::OP_L0C_RESHAPE_COPY_OUT);
}
inline bool IsOpCodeSupportMultiProducers(Opcode opCode)
{
return opCode == Opcode::OP_ASSEMBLE || IsCopyOut(opCode) || opCode == Opcode::OP_CALL ||
opCode == Opcode::OP_INDEX_OUTCAST;
}
extern std::unordered_map<Opcode, std::string> SUPPORT_TILETENSOR_OPS;
extern std::unordered_set<Opcode> SUPPORT_VF_FUSE_OPS;
extern std::unordered_set<Opcode> SKIP_OPCODE_FOR_CODEGEN;
extern std::unordered_set<Opcode> SUPPORT_BRC_INLINE;
}