* Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
* MindIE is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* 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 FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef __ADDRESS_CONST_H__
#define __ADDRESS_CONST_H__
namespace Address {
const int SIZE_128 = 128;
const int SIZE_256 = 256;
const int BASE_BLOCK_LENGTH = SIZE_128;
const int QUERY_BLOCK_SIZE = SIZE_128 * BASE_BLOCK_LENGTH;
const int KEY_BLOCK_SIZE = SIZE_128 * BASE_BLOCK_LENGTH;
const int VALUE_BLOCK_SIZE = SIZE_128 * BASE_BLOCK_LENGTH;
const int ATTENTION_SCORE_BLOCK_SIZE = BASE_BLOCK_LENGTH * BASE_BLOCK_LENGTH;
const int ROWSUM_BLOCK_SIZE = SIZE_128;
const int OUTPUT_BLOCK_SIZE = SIZE_128 * BASE_BLOCK_LENGTH;
const int MAX_LENGTH = 16;
struct BackWardAddr {
int32_t b;
int32_t n;
int32_t iR;
int32_t iC;
int32_t kx;
int32_t ky;
int32_t k;
};
template <typename T_LEFT, typename T_RIGHT, typename T_OUTPUT>
struct PhyAddrBackwardCube1 {
__gm__ T_LEFT *left;
__gm__ T_RIGHT *right;
__gm__ T_OUTPUT *out;
int32_t kx = 0;
int32_t ky = 0;
int32_t k = 0;
int32_t lineStride = 0;
bool lowerLeft;
bool upperRight;
};
template <typename T_LEFT, typename T_RIGHT, typename T_OUTPUT>
struct PhyAddrBackwardCube2 {
__gm__ T_LEFT *left;
__gm__ T_RIGHT *right;
__gm__ T_OUTPUT *out;
int32_t kx = 0;
int32_t ky = 0;
int32_t k = 0;
int32_t lineStride = 0;
bool lowerLeft;
bool upperRight;
};
template <typename T_LEFT, typename T_RIGHT, typename T_OUTPUT>
struct PhyAddrBackwardCube3 {
__gm__ T_LEFT *left;
__gm__ T_RIGHT *right;
__gm__ T_OUTPUT *out;
int32_t kx = 0;
int32_t ky = 0;
int32_t k = 0;
int32_t lineStride = 0;
bool lowerLeft;
bool upperRight;
};
struct VectorAddr {
int32_t b = 0;
int32_t n = 0;
int32_t iR = 0;
int32_t iC = 0;
int32_t kx = 0;
int32_t ky = 0;
int32_t k = 0;
};
struct ForWardAddrOnline {
int32_t b;
int32_t n;
int32_t iR;
int32_t iC;
int32_t kx;
int32_t ky;
int32_t k;
};
struct GLOBAL_INFO {
int64_t cubeNum = 0;
int64_t blockNumPerCube = 0;
int64_t headNum = 0;
int64_t batchNum = 0;
int64_t seqLenQ = 0;
int64_t seqLenK = 0;
int64_t headDim = 0;
bool triMatix = false;
int32_t blockRows = 0;
int32_t blockCols = 0;
int64_t blockNumPerRow = 0;
int64_t blockNumPerCol = 0;
int64_t blockNumPerLoop = 0;
int64_t blockNumPerHead = 0;
int64_t blockNumPerBatch = 0;
int64_t loopTimes = 0;
int64_t tailBlockNum = 0;
int64_t isSparse = 0;
int64_t windowLength = 0;
int64_t windowsBlockNum = 0;
};
struct LOCAL_INFO {
int64_t cubeIndex = 0;
int64_t vectorIdx = 0;
int64_t startLineInBaseBlock = 0;
bool procTail = false;
int64_t procTailBlockNum = 0;
};
const int MAX_SWITCH_TIME = 8;
struct SECTION_INFO {
int64_t sectionNum = 0;
int64_t sectionStartBlock[MAX_SWITCH_TIME] = {0};
int64_t headSkipBlock[MAX_SWITCH_TIME] = {0};
int64_t tailSkipBlock[MAX_SWITCH_TIME] = {0};
int64_t globalLinesInHeads[MAX_SWITCH_TIME] = {0};
int64_t len[MAX_SWITCH_TIME] = {0};
bool headApplyMask[MAX_SWITCH_TIME] = {false};
bool tailApplyMask[MAX_SWITCH_TIME] = {false};
int64_t oDOOffset[MAX_SWITCH_TIME] = {0};
int64_t sDPOffset[MAX_SWITCH_TIME] = {0};
int64_t processLines = {0};
};
const int FORWARD_MAX_SWITCH_TIME = 8;
struct FORWARD_SECTION_INFO {
int64_t sectionNum = 0;
int64_t sectionBlockNums[FORWARD_MAX_SWITCH_TIME] = {0};
int64_t sectionBlockOffset[FORWARD_MAX_SWITCH_TIME] = {0};
int64_t rowmaxOffset[FORWARD_MAX_SWITCH_TIME] = {0};
int64_t maskNum;
int64_t matrixMaskOffset;
int64_t processLineNum;
bool sparseFlag = false;
bool isTriangle = false;
int64_t attentionScoreOffset;
int64_t diagOffset[FORWARD_MAX_SWITCH_TIME] = {0};
bool isHeadSection[FORWARD_MAX_SWITCH_TIME] = {false};
bool isTailSection[FORWARD_MAX_SWITCH_TIME] = {false};
};
template<typename T_LEFT, typename T_RIGHT, typename T_OUTPUT>
struct PhyAddrForwardCube1 {
__gm__ T_LEFT *left;
__gm__ T_RIGHT *right;
__gm__ T_OUTPUT *out;
int32_t k = 0;
};
template<typename T_LEFT, typename T_RIGHT, typename T_OUTPUT>
struct PhyAddrForwardCube2Rowsum {
__gm__ T_LEFT *left;
__gm__ T_RIGHT *right;
__gm__ T_OUTPUT *out;
__gm__ T_OUTPUT *rowsum_out;
int32_t k = 0;
};
template <typename T_LEFT, typename T_RIGHT, typename T_OUTPUT>
struct PhyAddrForwardCube1Online {
__gm__ T_LEFT *left;
__gm__ T_RIGHT *right;
__gm__ T_OUTPUT *out;
int32_t kx = 0;
int32_t ky = 0;
int32_t k = 0;
int32_t lineStride = 0;
bool lowerLeft;
bool upperRight;
bool onStartSection;
bool onEndSection;
};
template <typename T_LEFT, typename T_RIGHT, typename T_OUTPUT>
struct PhyAddrForwardCube2Online {
__gm__ T_LEFT *left;
__gm__ T_RIGHT *right;
__gm__ T_OUTPUT *out;
int32_t kx = 0;
int32_t ky = 0;
int32_t k = 0;
int32_t lineStride = 0;
bool lowerLeft;
bool upperRight;
bool onStartSection;
bool onEndSection;
};
}
#endif