aclnnBSASelectBlockMask
Applicable Products
Ascend 950PR&950DT products : Supported
Atlas A3 products : Supported
Atlas A2 products : Supported
Atlas 200I/500 A2 inference products : Not supported
Atlas inference products : Not supported
Atlas training products : Not supported
Function
Description: aclnnBSASelectBlockMask is the preceding operator of BSA (BlockSparseAttention). It dynamically generates blockSparseMask based on the content of Query and Key, changing the BSA call chain from "manually providing a mask" to "adaptively selecting the sparse mode based on Q/K content".
Formula:
Let blockShape = [blockShapeX, blockShapeY], Sq be the maximum sequence length of query, and Skv be the maximum sequence length of key. The number of blocks after compression is:
$$ Xblocks = \lceil Sq / blockShapeX \rceil,\quad Yblocks = \lceil Skv / blockShapeY \rceil $$Step1: Mean Pooling Compression
When actualBlockLenQuery / actualBlockLenKey is null (full compression):
$$ q\_compressed[b, n, x, d] = \frac{1}{blockShapeX} \sum_{i=0}^{blockShapeX-1} query[b, n, x \cdot blockShapeX + i, d] $$$$ k\_compressed[b, n, y, d] = \frac{1}{blockShapeY} \sum_{j=0}^{blockShapeY-1} key[b, n, y \cdot blockShapeY + j, d] $$When actualBlockLenQuery / actualBlockLenKey is not null (partial compression), only the first actualBlockLen tokens in each block are used to compute the mean value:
$$ q\_compressed[b, n, x, d] = \frac{1}{actualBlockLenQ[b,x]} \sum_{i=0}^{actualBlockLenQ[b,x]-1} query[b, n, x \cdot blockShapeX + i, d] $$$$ k\_compressed[b, n, y, d] = \frac{1}{actualBlockLenK[b,y]} \sum_{j=0}^{actualBlockLenK[b,y]-1} key[b, n, y \cdot blockShapeY + j, d] $$Step2a: QK Matmul
$$ score[b, n, x, y] = scale \cdot \sum_{d=0}^{D-1} q\_compressed[b, n, x, d] \cdot k\_compressed[b, n, y, d] $$Step2b: Softmax
$$ attn\_score[b, n, x, y] = softmax(score[b, n, x, :]) = \frac{\exp(score[b, n, x, y] - m_{final})}{l_{final}} $$Step2c: Post Pooling Compression (Post-Softmax Mean Pooling)
When postBlockShape is not null, apply post mean pooling to attn_score to generate the coarse-grained pooled_score:
$$ postXBlocks = \lceil Xblocks / postBlockShapeX \rceil,\quad postYBlocks = \lceil Yblocks / postBlockShapeY \rceil $$$$ pooled\_score[b, n, px, py] = \frac{1}{|R_{px,py}|} \sum_{x \in R_x(px)} \sum_{y \in R_y(py)} attn\_score[b, n, x, y] $$When postBlockShape is null, skip this step, and pooled_score = attn_score.
Step3: TopK Selection to Generate Indices
$$ topk\_value = \text{round}(sparsity \times postXBlocks \times postYBlocks) $$$$ \mathcal{indices}= \text{TopK}\left(pooled\_score[b, n, px, py],\; topK\_value\right) $$When postBlockShape is null, postXBlocks=Xblocks, postYBlocks=Yblocks, and pooled_score=attn_score, which is equivalent to performing TopK directly on attn_score.
where indices is the set of indices corresponding to the topk_value largest values in attn_score[b, n, x, y].
Step4: Generate BlockSparseMask
When postBlockShape is not null, the output is the coarse-grained mask directly (with shape [B, N, postXBlocks, postYBlocks], using the secondary pooling split semantics, without expansion):
$$ blockSparseMaskOut[b, n, px, py] = \begin{cases} 1 & (px, py) \in \mathcal{indices} \\ 0 & (px, py) \notin \mathcal{indices} \end{cases} $$When postBlockShape is null, the output is the fine-grained mask (with shape [B, N, Xblocks, Yblocks]) and is generated element-wise directly:
$$ blockSparseMaskOut[b, n, x, y] = \begin{cases} 1 & (b, n, x, y) \in \mathcal{indices} \\ 0 & (b, n, x, y) \notin \mathcal{indices} \end{cases} $$Data format:
The data format of the query and key inputs to BSASelectBlockMask can be interpreted under multiple dimension layouts and is specified through qInputLayout and kvInputLayout. To facilitate understanding of the specific supported formats described later (such as BNSD and TND), the meaning of each dimension represented by the abbreviation letters in the format names is explained here first:
- B: Indicates the batch size of the input samples (Batch).
- T: Indicates the length of B and S concatenated along the axis and tightly packed (Total tokens).
- S: Indicates the sequence length of the input samples (Seq-Length).
- H: Indicates the size of the hidden layer (Head-Size).
- N: Number of heads (Head-Num).
- D: indicates the smallest unit size of the hidden layer and must satisfy D = H / N (Head-Dim)
Currently supported layouts:
- qInputLayout: "TND" "BNSD"
- kvInputLayout: "TND" "BNSD"
Function Prototype
Each operator uses a two-phase API. Call "aclnnBSASelectBlockMaskGetWorkspaceSize" first to obtain the workspace size required for computation and the executor that includes the operator computation flow. Then call "aclnnBSASelectBlockMask" to perform the computation.
aclnnStatus aclnnBSASelectBlockMaskGetWorkspaceSize(
const aclTensor *query,
const aclTensor *key,
const aclIntArray *blockShape,
const aclIntArray *postBlockShape,
const aclIntArray *actualSeqLengths,
const aclIntArray *actualSeqLengthsKV,
const aclIntArray *actualBlockLenQuery,
const aclIntArray *actualBlockLenKey,
char *qInputLayout,
char *kvInputLayout,
int64_t numKeyValueHeads,
double scaleValue,
double sparsity,
aclTensor *blockSparseMaskOut,
uint64_t *workspaceSize,
aclOpExecutor **executor)aclnnStatus aclnnBSASelectBlockMask(
void *workspace,
uint64_t workspaceSize,
aclOpExecutor *executor,
const aclrtStream stream)aclnnBSASelectBlockMaskGetWorkspaceSize
Parameters:
Parameter Input/Output Description Instruction Data Type Data Format Dimension (shape) Non-contiguous Tensor query (aclTensor*) Input Query matrix in the attention computation, i.e., query in the formula. - Does not support empty Tensor.
- Supported shapes:
- TND: [totalQTokens, headNum, headDim].
- BNSD: [batch, headNum, maxQSeqLength, headDim].
FLOAT16, BFLOAT16 ND 3-4 × key (aclTensor*) Input Key matrix in the attention computation, i.e., key in the formula. - Does not support empty tensors.
- Supported shapes:
- TND: [totalKTokens, numKeyValueHeads, headDim].
- BNSD: [batch, numKeyValueHeads, maxKSeqLength, headDim].
FLOAT16, BFLOAT16 ND 3-4 × blockShape (aclIntArray*) Input Sparse block shape array, which specifies the two-dimensional size (rows and columns) of each sparse block, that is, blockShape in the formula. - Element requirements when this input is configured:
- Must contain at least two elements [blockShapeX, blockShapeY].
- blockShapeX: Block size along Q, which must be a multiple of 8 and greater than 0.
- blockShapeY: Block size along KV, which must be a multiple of 8 and greater than 0.
- If not configured (pass in nullptr), the operator will default to blockShapeX = 128, blockShapeY = 128.
INT64 - 1 - postBlockShape(aclIntArray*) Input Post-Softmax pooling block shape array. Specifies the block grouping size (in blocks) of the second pooling after Softmax, that is, postBlockShape in the formula. - Optional input: When `[postBlockShapeX, postBlockShapeY]` is passed in, post-Softmax pooling is enabled, TopK selection is performed on the coarse-grained pooled_score, and the output mask is coarse-grained [B, N, postXBlocks, postYBlocks] (split semantics of post-Softmax pooling; the selection result is directly output without expansion).
- When nullptr is passed in, post-Softmax pooling is disabled (for backward compatibility), TopK selection is performed directly on attn_score, and the output mask is fine-grained [B, N, Xblocks, Yblocks].
- postBlockShapeX/postBlockShapeY are multiples of 8 and indicate the number of block groups.
INT64 - 1 - actualSeqLengths (aclIntArray*) Input Actual sequence length of the query in each batch, that is, the actual effective value of Sq in each batch in the formula.
Describes the number of valid query tokens in each batch in variable-length sequence scenarios (that is, scenarios containing Padding data).- Variable-length sequence scenario (when qInputLayout is "TND"): This input must be configured.
- Fixed-length/variable-length scenario (when qInputLayout is "BNSD"):
- If configured, the operator processes data based on the specified effective length and ignores the Padding data, improving performance.
- If not configured (pass in nullptr), the operator will default to using the S dimension in the query shape as the effective length and process all data.
INT64 - 1 - actualSeqLengthsKV (aclIntArray*) Input Array of actual sequence lengths of key, that is, the actual effective value of Skv in each batch in the formula.
Describes the number of actually valid key tokens in each batch in the variable-length sequence scenario (that is, the scenario containing padding data).- Variable-length sequence scenario (when kvInputLayout is "TND"): this input must be configured.
- >Fixed-length/variable-length scenario (when kvInputLayout is "BNSD"):
- If this item is configured, the operator processes data based on the specified valid length, ignores padding data, and improves performance.
- If not configured (pass nullptr), the operator will default to processing all data, using the S dimension in the key shape as the valid length.
INT64 - 1 - actualBlockLenQuery (aclIntArray*) Input Actual compressed valid seq length within each query block, that is, actualBlockLenQuery in the formula.
This parameter is used for partial compression scenarios (for example, incomplete blocks at the end or compressing only valid tokens).- Optional input:
- BNSD use case: shape is [B, Xblocks].
- TND use case: shape is [TotalBlockNum_Q] (actual effective Xblocks of each batch stacked, validXblocks = ceil(actualSeqQ / blockShapeX)).
- Value range of each element: [0, blockShapeX].
- When actualBlockLen = 0: q_cmp of the corresponding block is filled with a 0 vector and will not be selected by topK.
- When actualBlockLen > 0: the mean value is taken over only the first actualBlockLen tokens.
- If not configured (pass in nullptr): query is fully compressed (using the full blockShapeX length).
INT64 - 1 - actualBlockLenKey (aclIntArray*) Input Actual effective seq length compressed within each key block, that is, actualBlockLenKey in the formula.
This parameter is used for partial compression use cases (such as incomplete blocks at the end or compressing only valid tokens).- Optional input:
- BNSD use case: shape is [B, Yblocks].
- TND use case: shape is [TotalBlockNum_K] (actual effective Yblocks of each batch stacked, validYblocks = ceil(actualSeqK / blockShapeY)).
- Value range of each element: [0, blockShapeY].
- When actualBlockLen = 0: k_cmp of the corresponding block is filled with a 0 vector and will not be selected by topK.
- When actualBlockLen > 0: the mean value is taken over only the first actualBlockLen tokens.
- If not configured (pass in nullptr): key is fully compressed (using the full blockShapeY length).
INT64 - 1 - qInputLayout (char*) Input Data arrangement of query. Indicates the specific arrangement of the input tensor in memory. - This API currently only supports "TND" and "BNSD". qInputLayout must be consistent with kvInputLayout.
- - - - kvInputLayout (char*) Input Data arrangement format of key. Indicates the specific arrangement of the input tensor in memory. - Currently only supports "TND" and "BNSD". qInputLayout and kvInputLayout must be consistent.
- - - - numKeyValueHeads (int64_t) Input The number of attention heads of key, which is the number of heads N of the key tensor in the formula. - Currently only supports MHA. numKeyValueHeads must be equal to numHeads.
- - - - scaleValue (double) Input Scale factor, which is scale in the formula. Used for normalization of attention scores. - Generally set to 1 / sqrt(D).
- - - - sparsity (double) Input Sparsity retention ratio, that is, sparsity in the formula. Specifies the proportion of block positions to retain in attn_score out of all block positions. - Value range (0.0, 1.0).
- - - - blockSparseMaskOut (aclTensor*) Output Block sparse mask output, that is, blockSparseMaskOut in the formula. It represents the sparse pattern adaptively generated based on Q/K content and can be directly used as the blockSparseMask input of the BSA operator. - Does not support empty tensors.
- The shape changes with postBlockShape:
- If postBlockShape is not null: [B, N, postXBlocks, postYBlocks] (coarse granularity, quadratic pooling split semantics), postXBlocks = ceilDiv(Xblocks, postBlockShapeX), postYBlocks = ceilDiv(Yblocks, postBlockShapeY).
- If postBlockShape is null: [B, N, Xblocks, Yblocks] (fine granularity), Xblocks = ceilDiv(maxQSeqlen, blockShapeX), Yblocks = ceilDiv(maxKvSeqlen, blockShapeY).
- A value of 1 indicates that the block participates in attention computation, and a value of 0 indicates that it does not.
INT8 ND 4 × workspaceSize (uint64_t*) Output Returns the workspace size to be applied by the Device. - - - - - executor (aclOpExecutor**) Output Returns the op executor, which includes the operator computation flow. - - - - - Return value:
aclnnStatus: Return status code. For details, see aclnn return code.
The first-phase API performs input parameter validation and returns an error in the following scenarios:
Error Code Error code Description ACLNN_ERR_PARAM_NULLPTR 161001 The query input is a null pointer. The key input is a null pointer. The blockSparseMaskOut input is a null pointer. ACLNN_ERR_PARAM_INVALID 161002 The data type of query, key, or blockSparseMaskOut is not within the supported range. The data types of query and key are inconsistent.
aclnnBSASelectBlockMask
Parameters:
Parameter Input/Output Description workspace Input Workspace memory address applied by the Device side. workspaceSize Input Workspace size applied by the Device side, obtained by calling the first-phase API aclnnBSASelectBlockMaskGetWorkspaceSize. executor Input Op executor, which includes the operator computation flow. stream Input Specifies the AscendCL stream for task execution. Return value
aclnnStatus: return status code. For details, see aclnn return codes.
Constraints
- actualSeqLengths is mandatory when qInputLayout is "TND"; actualSeqLengthsKV is mandatory when kvInputLayout is "TND".
- Based on the input layouts supported by the operator, the size of the head dimension in the query tensor shape is denoted as N1, and the size of the head dimension in the key tensor shape is denoted as N2. N1 = N2 must be satisfied (only MHA is supported).
- headDim = 128.
- blockShapeX and blockShapeY must be a multiple of 8.
- After query and key compression, Xblocks and Yblocks corresponding to query and key must satisfy Xblocks Yblocks > 1; when postBlockShape is not null, the BNSD use case further requires postXBlocks postYBlocks > 1 (no TopK selection semantics when the coarse-grained grid collapses to 1×1, and the host side rejects it; allowed in TND variable-length scenarios).
- The data types of query and key must be the same; only FLOAT16 and BFLOAT16 are supported.
- The data type of blockSparseMaskOut is INT8 (binary: 0 or 1).
- postBlockShape is an optional input. Passing nullptr disables secondary pooling (backward compatible). Passing
[postBlockShapeX, postBlockShapeY]enables secondary pooling; postBlockShapeX/postBlockShapeY must be a multiple of 8, indicating the number of block groups. - If actualBlockLenQuery / actualBlockLenKey is not null, the value range of each element is [0, blockShapeX] / [0, blockShapeY]; if it is null, complete compression is performed.
- Does not involve deterministic computation.
Example
The following sample code is for reference only. For details about compilation and execution, see Compile and Run Samples.
#include <iostream>
#include <vector>
#include <cstring>
#include <cmath>
#include <cstdint>
#include "acl/acl.h"
#include "aclnn/opdev/fp16_t.h"
#include "aclnnop/aclnn_bsa_select_block_mask.h"
using namespace std;
#define CHECK_RET(cond, return_expr) \
do { \
if (!(cond)) { \
return_expr; \
} \
} while (0)
#define LOG_PRINT(message, ...) \
do { \
printf(message, ##__VA_ARGS__); \
} while (0)
int64_t GetShapeSize(const std::vector<int64_t>& shape) {
int64_t shapeSize = 1;
for (auto i : shape) {
shapeSize *= i;
}
return shapeSize;
}
int Init(int32_t deviceId, aclrtStream* stream) {
// Boilerplate: resource initialization.
auto ret = aclInit(nullptr);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
ret = aclrtSetDevice(deviceId);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
ret = aclrtCreateStream(stream);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
return 0;
}
template <typename T>
int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr,
aclDataType dataType, aclTensor** tensor) {
if (shape.empty()) {
LOG_PRINT("CreateAclTensor: ERROR - shape is empty\n");
return -1;
}
for (size_t i = 0; i < shape.size(); ++i) {
if (shape[i] <= 0) {
LOG_PRINT("CreateAclTensor: ERROR - shape[%zu]=%ld is invalid\n", i, shape[i]);
return -1;
}
}
auto size = GetShapeSize(shape) * sizeof(T);
if (hostData.size() != static_cast<size_t>(GetShapeSize(shape))) {
LOG_PRINT("CreateAclTensor: ERROR - hostData size mismatch: %zu vs %ld\n",
hostData.size(), GetShapeSize(shape));
return -1;
}
// Call aclrtMalloc to allocate memory on the device.
*deviceAddr = nullptr;
auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);
// Call aclrtMemcpy to copy host data to the device memory.
ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret);
aclrtFree(*deviceAddr); *deviceAddr = nullptr; return ret);
// Calculate the strides of the contiguous tensor.
std::vector<int64_t> strides(shape.size(), 1);
if (shape.size() > 1) {
for (int64_t i = static_cast<int64_t>(shape.size()) - 2; i >= 0; i--) {
strides[i] = shape[i + 1] * strides[i + 1];
}
}
// Call the aclCreateTensor API to create an aclTensor.
*tensor = nullptr;
*tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND,
shape.data(), shape.size(), *deviceAddr);
CHECK_RET(*tensor != nullptr, LOG_PRINT("aclCreateTensor failed - returned nullptr\n");
aclrtFree(*deviceAddr); *deviceAddr = nullptr; return -1);
return 0;
}
int main() {
// 1.(Boilerplate) Initialize device/stream. For details, see the acl API manual.
// Set deviceId based on the actual device.
int32_t deviceId = 0;
aclrtStream stream;
auto ret = Init(deviceId, &stream);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
// 2. Construct inputs and outputs, (BNSD Layout as an example)
int32_t batch = 1;
int32_t numHeads = 4;
int32_t numKHeads = 4; // Only MHA is supported: N == KN
int32_t qSeqlen = 256 * 1024; // 256K
int32_t kSeqlen = 256 * 1024; // 256K
int32_t headDim = 128;
int32_t blockShapeX = 128;
int32_t blockShapeY = 128;
// Calculate the number of blocks.
int32_t ceilQ = (qSeqlen + blockShapeX - 1) / blockShapeX;
int32_t ceilK = (kSeqlen + blockShapeY - 1) / blockShapeY;
// Build the tensor Shape.
std::vector<int64_t> qShape = {batch, numHeads, qSeqlen, headDim};
std::vector<int64_t> kShape = {batch, numKHeads, kSeqlen, headDim};
std::vector<int64_t> maskShape = {batch, numHeads, ceilQ, ceilK};
// Allocate and initialize the Host data.
int64_t qSize = GetShapeSize(qShape);
int64_t kSize = GetShapeSize(kShape);
std::vector<op::fp16_t> qData(qSize, 0.1f);
std::vector<op::fp16_t> kData(kSize, 0.1f);
// Initialize the mask output to 0.
std::vector<int8_t> maskOutData(GetShapeSize(maskShape), 0);
// Create all aclTensor objects.
void *qAddr = nullptr, *kAddr = nullptr, *maskAddr = nullptr;
aclTensor *qTensor = nullptr, *kTensor = nullptr, *maskTensor = nullptr;
CreateAclTensor(qData, qShape, &qAddr, aclDataType::ACL_FLOAT16, &qTensor);
CreateAclTensor(kData, kShape, &kAddr, aclDataType::ACL_FLOAT16, &kTensor);
CreateAclTensor(maskOutData, maskShape, &maskAddr, aclDataType::ACL_INT8, &maskTensor);
// Create the aclIntArray attribute parameters.
std::vector<int64_t> blockShapeVec = {blockShapeX, blockShapeY};
aclIntArray *blockShapeArr = aclCreateIntArray(blockShapeVec.data(), blockShapeVec.size());
// Configure the scalar and string parameters.
char queryLayoutBuffer[16] = "BNSD";
char keyLayoutBuffer[16] = "BNSD";
double scaleValue = 1.0 / std::sqrt(static_cast<double>(headDim));
double sparsity = 0.5;
// 3. Call the CANN operator library API.
uint64_t workspaceSize = 0;
aclOpExecutor* executor = nullptr;
// Call the first-phase API of aclnnBSASelectBlockMask.
LOG_PRINT("Calling aclnnBSASelectBlockMaskGetWorkspaceSize...\n");
ret = aclnnBSASelectBlockMaskGetWorkspaceSize(
qTensor,
kTensor,
blockShapeArr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
queryLayoutBuffer,
keyLayoutBuffer,
static_cast<int64_t>(numKHeads),
scaleValue,
sparsity,
maskTensor,
&workspaceSize,
&executor
);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("GetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
CHECK_RET(executor != nullptr, LOG_PRINT("executor is null after GetWorkspaceSize\n"); return -1);
LOG_PRINT("Workspace size required: %lu bytes\n", workspaceSize);
// Allocate device memory according to the workspaceSize calculated by the first-phase API.
void* workspaceAddr = nullptr;
if (workspaceSize > 0) {
ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
}
// Call the second-phase API of aclnnBSASelectBlockMask.
LOG_PRINT("Calling aclnnBSASelectBlockMask...\n");
ret = aclnnBSASelectBlockMask(workspaceAddr, workspaceSize, executor, stream);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnBSASelectBlockMask failed. ERROR: %d\n", ret); return ret);
// 4.(boilerplate) Synchronize and wait for task execution to complete.
ret = aclrtSynchronizeStream(stream);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
// 5.Obtain the output value and copy the result on the device memory to the host memory.
int64_t maskSize = GetShapeSize(maskShape);
ret = aclrtMemcpy(maskOutData.data(), maskSize * sizeof(int8_t), maskAddr, maskSize * sizeof(int8_t), ACL_MEMCPY_DEVICE_TO_HOST);
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed.\n"); return ret);
LOG_PRINT("Execution Success! BlockSparseMask output (first 20 elements):\n");
int64_t displayCount = (maskSize < 20) ? maskSize : 20;
for (int64_t i = 0; i < displayCount; i++) {
LOG_PRINT(" mask index %ld: %u\n", i, static_cast<unsigned int>(maskOutData[i]));
}
// 6.Release aclTensor and aclIntArray.
LOG_PRINT("Cleaning up resources...\n");
aclDestroyTensor(qTensor);
aclDestroyTensor(kTensor);
aclDestroyTensor(maskTensor);
aclDestroyIntArray(blockShapeArr);
// 7.Release device resources.
aclrtFree(qAddr);
aclrtFree(kAddr);
aclrtFree(maskAddr);
if (workspaceAddr) {
aclrtFree(workspaceAddr);
}
aclrtDestroyStream(stream);
aclrtResetDevice(deviceId);
aclFinalize();
LOG_PRINT("BSASelectBlockMask Test completed successfully!\n");
return 0;
}