aclsparseLtMatmulAlgGetAttribute
Product support
| Product |
Supported |
| Ascend 950PR&950DT products |
√ |
| Atlas A3 products |
× |
| Atlas A2 products |
× |
| Atlas 200I/500 A2 inference products |
× |
| Atlas inference products |
× |
| Atlas training products |
× |
Function Description
- Operator function:
aclsparseLtMatmulAlgGetAttribute queries the current values of the attributes of the algorithm selection descriptor (aclsparseLtMatmulAlgSelection_t). It is the query counterpart of aclsparseLtMatmulAlgSetAttribute and corresponds to cusparseLtMatmulAlgGetAttribute in cuSPARSELt.
- Pure host operation: This interface performs a pure host-side metadata query. It starts no device kernel and does not involve Device memory access.
- Operator directory: v2 splits
aclsparseLtMatmulAlgGetAttribute from the alg_set_attribute directory into the independent operator directory alg_get_attribute/arch35/ and decouples it from the alg_set_attribute directory, to facilitate independent maintenance and testing. The header comment of the SetAttribute host implementation file already notes the independent path of GetAttribute.
Queryable attributes
| Attribute enumeration |
Value type |
Description |
ACLSPARSELT_MATMUL_ALG_CONFIG_ID |
int32_t |
Current algorithm configuration ID (0 or 1), which affects cube tiling (baseM/baseN/baseK) |
ACLSPARSELT_MATMUL_ALG_CONFIG_MAX_ID |
int32_t |
Upper limit of the algorithm configuration ID (returns 2, that is, algConfigId 0 and 1 provide 2 configurations in total). This is a read-only attribute and cannot be set through SetAttribute |
ACLSPARSELT_MATMUL_SEARCH_ITERATIONS |
int32_t |
Number of search iterations (5 by default), which is consumed live by the aclsparseLtMatmulSearch search entry |
ACLSPARSELT_MATMUL_SPLIT_K |
int32_t |
splitK split factor; value range [1, K] |
ACLSPARSELT_MATMUL_SPLIT_K_MODE |
int32_t |
splitK mode (0=ONE_KERNEL fused single kernel, 1=TWO_KERNELS matmul+epilogue two kernels) |
ACLSPARSELT_MATMUL_SPLIT_K_BUFFERS |
int32_t |
Number of splitK buffers; value range [0, splitK-1]; currently the value is stored only and does not participate in execution |
Function prototype
aclsparseStatus_t aclsparseLtMatmulAlgGetAttribute(
aclsparseLtConstHandle_t handle,
aclsparseLtConstMatmulAlgSelection_t* algSelection,
aclsparseLtMatmulAlgAttribute_t attr,
void* attrValue,
size_t attrValueSize);
Parameter description
| Parameter |
Input/Output |
Parameter type |
Description |
| handle |
Input |
aclsparseLtConstHandle_t |
const pointer to the library handle; must be non-null, *handle must be non-null; host memory |
| algSelection |
Input |
aclsparseLtConstMatmulAlgSelection_t* |
Algorithm selection descriptor; must be non-null and initialized (*algSelection is not nullptr); host memory |
| attr |
Input |
aclsparseLtMatmulAlgAttribute_t |
Attribute enumeration to query; host memory |
| attrValue |
Output |
void* |
Output buffer of the attribute value; must be non-null; host memory. The data type and size written are determined by attr (both are int32_t, 4 bytes) |
| attrValueSize |
Input |
size_t |
Size of the attrValue buffer (bytes); must equal sizeof(int32_t) (4 bytes); host memory |
The parameter semantics are symmetric to those of aclsparseLtMatmulAlgSetAttribute. The differences are that attrValue is an output and algSelection is const read-only.
Supported data types
This interface performs a pure host-side metadata query and does not involve matrix data types. All queried and returned attribute values are int32_t.
Constraints
- handle validity:
handle must be non-null and *handle must be non-null. Otherwise, ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR is returned.
- algSelection validity:
algSelection must be non-null and initialized by aclsparseLtMatmulAlgSelectionInit (*algSelection is not nullptr). A destroyed descriptor (*algSelection is nullptr) returns ACL_SPARSE_STATUS_INVALID_VALUE.
- attrValue non-null:
attrValue must be non-null. Otherwise, ACL_SPARSE_STATUS_INVALID_VALUE is returned.
- attrValueSize match:
attrValueSize must equal sizeof(int32_t) (4 bytes). Otherwise, ACL_SPARSE_STATUS_INVALID_VALUE is returned.
- attr enumeration range:
attr must be one of the enumeration values listed in the preceding table. Otherwise, ACL_SPARSE_STATUS_NOT_SUPPORTED is returned.
- Query timing: You can query at any time after
aclsparseLtMatmulAlgSelectionInit (before or after PlanInit). A settable attribute always reads the value currently stored in algSelection. If SetAttribute is called successfully again after PlanInit, GetAttribute also returns the updated attribute value instead of the initialization snapshot of an existing plan. The SPLIT_K query returns the stored splitK and does not return the effectiveSplitK computed by PlanInit. Therefore, you cannot use this query interface to read or verify the frozen tiling/workspace configuration of an existing plan.
- Relationship with SetAttribute: The value read by GetAttribute is the value set by the most recent SetAttribute (or the default values of AlgSelectionInit: algConfigId=0, splitK=1, searchIterations=5, splitKMode=0, splitKBuffers=0).
Returns / Error codes
| Return value |
Meaning |
ACL_SPARSE_STATUS_SUCCESS |
The query succeeds |
ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR |
handle is nullptr or *handle is nullptr |
ACL_SPARSE_STATUS_INVALID_VALUE |
algSelection or attrValue is nullptr, *algSelection is nullptr (destroyed), or attrValueSize does not match sizeof(int32_t) |
ACL_SPARSE_STATUS_NOT_SUPPORTED |
The attr enumeration value is not in the supported range |
Invocation example
The following example demonstrates the complete AlgSelectionInit → AlgSetAttribute → AlgGetAttribute → verification flow. It computes D = A_pruned * B (FP32, row-major), sets algConfigId=0 and splitK=2, and then queries and verifies the values.
#include <cstdio>
#include <vector>
#include "acl/acl.h"
#include "cann_ops_sparseLt.h"
#define CHECK_RET(cond, return_expr) \
do { \
if (!(cond)) { \
return_expr; \
} \
} while (0)
#define LOG_PRINT(message, ...) \
do { \
printf(message, ##__VA_ARGS__); \
} while (0)
int aclsparseLtAlgGetAttributeTest()
{
int32_t deviceId = 0;
CHECK_RET(aclInit(nullptr) == ACL_SUCCESS, return -1);
CHECK_RET(aclrtSetDevice(deviceId) == ACL_SUCCESS, aclFinalize(); return -1);
aclsparseLtHandle_t handle = nullptr;
auto ret = aclsparseLtInit(&handle);
CHECK_RET(ret == ACL_SPARSE_STATUS_SUCCESS, LOG_PRINT("aclsparseLtInit failed: %d\n", ret); return ret);
int64_t m = 64, k = 64, n = 128;
aclsparseLtMatDescriptor_t matA = nullptr;
aclsparseLtMatDescriptor_t matB = nullptr, matC = nullptr, matD = nullptr;
aclsparseLtStructuredDescriptorInit(
&handle, &matA, m, k, k, 16, ACL_FLOAT,
ACL_SPARSE_ORDER_ROW, ACL_SPARSE_LT_SPARSITY_50_PERCENT);
aclsparseLtDenseDescriptorInit(&handle, &matB, k, n, n, 16, ACL_FLOAT, ACL_SPARSE_ORDER_ROW);
aclsparseLtDenseDescriptorInit(&handle, &matC, m, n, n, 16, ACL_FLOAT, ACL_SPARSE_ORDER_ROW);
aclsparseLtDenseDescriptorInit(&handle, &matD, m, n, n, 16, ACL_FLOAT, ACL_SPARSE_ORDER_ROW);
aclsparseLtMatmulDescriptor_t matmulDesc = nullptr;
aclsparseLtMatmulDescriptorInit(
&handle, &matmulDesc,
ACL_SPARSE_OP_NON_TRANSPOSE, ACL_SPARSE_OP_NON_TRANSPOSE,
&matA, &matB, &matC, &matD, ACL_SPARSE_COMPUTE_32F);
aclsparseLtMatmulAlgSelection_t algSel = nullptr;
aclsparseLtMatmulAlgSelectionInit(&handle, &algSel, &matmulDesc, ACL_SPARSE_LT_MATMUL_ALG_DEFAULT);
int32_t algConfigId = 0;
int32_t splitK = 2;
aclsparseLtMatmulAlgSetAttribute(&handle, &algSel, ACLSPARSELT_MATMUL_ALG_CONFIG_ID,
&algConfigId, sizeof(int32_t));
aclsparseLtMatmulAlgSetAttribute(&handle, &algSel, ACLSPARSELT_MATMUL_SPLIT_K,
&splitK, sizeof(int32_t));
aclsparseLtConstMatmulAlgSelection_t constAlgSel = algSel;
int32_t queryAlgConfigId = -1;
int32_t querySplitK = -1;
int32_t queryMaxId = -1;
ret = aclsparseLtMatmulAlgGetAttribute(&handle, &constAlgSel, ACLSPARSELT_MATMUL_ALG_CONFIG_ID,
&queryAlgConfigId, sizeof(int32_t));
CHECK_RET(ret == ACL_SPARSE_STATUS_SUCCESS, LOG_PRINT("GetAttribute(ALG_CONFIG_ID) failed: %d\n", ret); return ret);
ret = aclsparseLtMatmulAlgGetAttribute(&handle, &constAlgSel, ACLSPARSELT_MATMUL_SPLIT_K,
&querySplitK, sizeof(int32_t));
CHECK_RET(ret == ACL_SPARSE_STATUS_SUCCESS, LOG_PRINT("GetAttribute(SPLIT_K) failed: %d\n", ret); return ret);
ret = aclsparseLtMatmulAlgGetAttribute(&handle, &constAlgSel, ACLSPARSELT_MATMUL_ALG_CONFIG_MAX_ID,
&queryMaxId, sizeof(int32_t));
CHECK_RET(ret == ACL_SPARSE_STATUS_SUCCESS, LOG_PRINT("GetAttribute(ALG_CONFIG_MAX_ID) failed: %d\n", ret); return ret);
LOG_PRINT("algConfigId=%d (expected 0), splitK=%d (expected 2), maxId=%d (expected 2)\n",
queryAlgConfigId, querySplitK, queryMaxId);
aclsparseLtMatmulAlgSelectionDestroy(&algSel);
aclsparseLtMatmulDescriptorDestroy(&matmulDesc);
aclsparseLtMatDescriptorDestroy(&matA);
aclsparseLtMatDescriptorDestroy(&matB);
aclsparseLtMatDescriptorDestroy(&matC);
aclsparseLtMatDescriptorDestroy(&matD);
aclsparseLtDestroy(&handle);
aclrtResetDevice(deviceId);
aclFinalize();
return 0;
}
int main()
{
return aclsparseLtAlgGetAttributeTest();
}
Supported chips
Ascend 950PR&950DT products (arch35 / DAV_3510)
References