已合并
solve issue 351 352 353 #330
HuangRZzzz创建于 14 天前
solve issue 351 352 353 #330
已合并
共 5 个文件变更+36-24
| @@ -46,6 +46,20 @@ inline aclblasStatus_t StoreLayoutField(void* buf, size_t sizeInBytes, const T& | |||
| 46 | return ACLBLAS_STATUS_SUCCESS; | 46 | return ACLBLAS_STATUS_SUCCESS; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | +template <typename T> | ||
| 50 | +inline aclblasStatus_t StoreLayoutFieldOut(void* buf, size_t sizeInBytes, const T& field, size_t* sizeWritten) | ||
| 51 | +{ | ||
| 52 | + const size_t requiredSize = sizeof(T); | ||
| 53 | + if (sizeWritten != nullptr) { | ||
| 54 | + *sizeWritten = requiredSize; | ||
| 55 | + } | ||
| 56 | + if (sizeInBytes < requiredSize) { | ||
| 57 | + return ACLBLAS_STATUS_INVALID_VALUE; | ||
| 58 | + } | ||
| 59 | + *reinterpret_cast<T*>(buf) = field; | ||
| 60 | + return ACLBLAS_STATUS_SUCCESS; | ||
| 61 | +} | ||
| 62 | + | ||
| 49 | aclblasStatus_t ApplyLayoutSetAttr( | 63 | aclblasStatus_t ApplyLayoutSetAttr( |
| 50 | aclblasLtMatrixLayoutImpl& impl, aclblasLtMatrixLayoutAttribute_t attr, const void* buf, size_t sizeInBytes) | 64 | aclblasLtMatrixLayoutImpl& impl, aclblasLtMatrixLayoutAttribute_t attr, const void* buf, size_t sizeInBytes) |
| 51 | { | 65 | { |
| @@ -71,23 +85,23 @@ aclblasStatus_t ApplyLayoutSetAttr( | |||
| 71 | 85 | ||
| 72 | aclblasStatus_t ReadLayoutGetAttr( | 86 | aclblasStatus_t ReadLayoutGetAttr( |
| 73 | const aclblasLtMatrixLayoutImpl& impl, aclblasLtMatrixLayoutAttribute_t attr, void* buf, size_t sizeInBytes, | 87 | const aclblasLtMatrixLayoutImpl& impl, aclblasLtMatrixLayoutAttribute_t attr, void* buf, size_t sizeInBytes, |
| 74 | - size_t& actualSize) | 88 | + size_t* sizeWritten) |
| 75 | { | 89 | { |
| 76 | switch (attr) { | 90 | switch (attr) { |
| 77 | case ACLBLASLT_MATRIX_LAYOUT_TYPE: | 91 | case ACLBLASLT_MATRIX_LAYOUT_TYPE: |
| 78 | - return StoreLayoutField(buf, sizeInBytes, impl.type, actualSize); | 92 | + return StoreLayoutFieldOut(buf, sizeInBytes, impl.type, sizeWritten); |
| 79 | case ACLBLASLT_MATRIX_LAYOUT_ROWS: | 93 | case ACLBLASLT_MATRIX_LAYOUT_ROWS: |
| 80 | - return StoreLayoutField(buf, sizeInBytes, impl.rows, actualSize); | 94 | + return StoreLayoutFieldOut(buf, sizeInBytes, impl.rows, sizeWritten); |
| 81 | case ACLBLASLT_MATRIX_LAYOUT_COLS: | 95 | case ACLBLASLT_MATRIX_LAYOUT_COLS: |
| 82 | - return StoreLayoutField(buf, sizeInBytes, impl.cols, actualSize); | 96 | + return StoreLayoutFieldOut(buf, sizeInBytes, impl.cols, sizeWritten); |
| 83 | case ACLBLASLT_MATRIX_LAYOUT_LD: | 97 | case ACLBLASLT_MATRIX_LAYOUT_LD: |
| 84 | - return StoreLayoutField(buf, sizeInBytes, impl.ld, actualSize); | 98 | + return StoreLayoutFieldOut(buf, sizeInBytes, impl.ld, sizeWritten); |
| 85 | case ACLBLASLT_MATRIX_LAYOUT_ORDER: | 99 | case ACLBLASLT_MATRIX_LAYOUT_ORDER: |
| 86 | - return StoreLayoutField(buf, sizeInBytes, impl.order, actualSize); | 100 | + return StoreLayoutFieldOut(buf, sizeInBytes, impl.order, sizeWritten); |
| 87 | case ACLBLASLT_MATRIX_LAYOUT_BATCH_COUNT: | 101 | case ACLBLASLT_MATRIX_LAYOUT_BATCH_COUNT: |
| 88 | - return StoreLayoutField(buf, sizeInBytes, impl.batchCount, actualSize); | 102 | + return StoreLayoutFieldOut(buf, sizeInBytes, impl.batchCount, sizeWritten); |
| 89 | case ACLBLASLT_MATRIX_LAYOUT_STRIDED_BATCH_OFFSET: | 103 | case ACLBLASLT_MATRIX_LAYOUT_STRIDED_BATCH_OFFSET: |
| 90 | - return StoreLayoutField(buf, sizeInBytes, impl.stridedBatchOffset, actualSize); | 104 | + return StoreLayoutFieldOut(buf, sizeInBytes, impl.stridedBatchOffset, sizeWritten); |
| 91 | default: | 105 | default: |
| 92 | return ACLBLAS_STATUS_INVALID_VALUE; | 106 | return ACLBLAS_STATUS_INVALID_VALUE; |
| 93 | } | 107 | } |
| @@ -179,17 +193,7 @@ aclblasStatus_t aclblasLtMatrixLayoutGetAttribute( | |||
| 179 | return copyStatus; | 193 | return copyStatus; |
| 180 | } | 194 | } |
| 181 | 195 | ||
| 182 | - size_t actualSize = 0; | 196 | + return ReadLayoutGetAttr(impl, attr, buf, sizeInBytes, sizeWritten); |
| 183 | - const aclblasStatus_t getStatus = ReadLayoutGetAttr(impl, attr, buf, sizeInBytes, actualSize); | ||
| 184 | - if (getStatus != ACLBLAS_STATUS_SUCCESS) { | ||
| 185 | - return getStatus; | ||
| 186 | - } | ||
| 187 | - | ||
| 188 | - if (sizeWritten != nullptr) { | ||
| 189 | - *sizeWritten = actualSize; | ||
| 190 | - } | ||
| 191 | - | ||
| 192 | - return ACLBLAS_STATUS_SUCCESS; | ||
| 193 | } | 197 | } |
| 194 | 198 | ||
| 195 | } // extern "C" | 199 | } // extern "C" |
| @@ -115,6 +115,8 @@ aclblasStatus_t ApplyMatmulDescSetAttr( | |||
| 115 | return SetDescScalePointer(impl.scaleA, buf, sizeInBytes); | 115 | return SetDescScalePointer(impl.scaleA, buf, sizeInBytes); |
| 116 | case ACLBLASLT_MATMUL_DESC_B_SCALE_POINTER: | 116 | case ACLBLASLT_MATMUL_DESC_B_SCALE_POINTER: |
| 117 | return SetDescScalePointer(impl.scaleB, buf, sizeInBytes); | 117 | return SetDescScalePointer(impl.scaleB, buf, sizeInBytes); |
| 118 | + case ACLBLASLT_MATMUL_DESC_POINTER_MODE: | ||
| 119 | + return SetDescEnumFromI32(impl.pointerMode, buf, sizeInBytes); | ||
| 118 | case ACLBLASLT_MATMUL_DESC_A_SCALE_MODE: | 120 | case ACLBLASLT_MATMUL_DESC_A_SCALE_MODE: |
| 119 | case ACLBLASLT_MATMUL_DESC_B_SCALE_MODE: | 121 | case ACLBLASLT_MATMUL_DESC_B_SCALE_MODE: |
| 120 | return ACLBLAS_STATUS_SUCCESS; | 122 | return ACLBLAS_STATUS_SUCCESS; |
| @@ -243,6 +245,11 @@ aclblasStatus_t aclblasLtMatmulDescGetAttribute( | |||
| 243 | srcPtr = &impl.scaleB; | 245 | srcPtr = &impl.scaleB; |
| 244 | break; | 246 | break; |
| 245 | 247 | ||
| 248 | + case ACLBLASLT_MATMUL_DESC_POINTER_MODE: | ||
| 249 | + requiredSize = sizeof(impl.pointerMode); | ||
| 250 | + srcPtr = &impl.pointerMode; | ||
| 251 | + break; | ||
| 252 | + | ||
| 246 | default: | 253 | default: |
| 247 | return ACLBLAS_STATUS_NOT_SUPPORTED; | 254 | return ACLBLAS_STATUS_NOT_SUPPORTED; |
| 248 | } | 255 | } |
| @@ -53,6 +53,7 @@ struct aclblasLtMatmulDescImpl { | |||
| 53 | aclDataType biasDataType = ACL_DT_UNDEFINED; | 53 | aclDataType biasDataType = ACL_DT_UNDEFINED; |
| 54 | const void* scaleA = nullptr; | 54 | const void* scaleA = nullptr; |
| 55 | const void* scaleB = nullptr; | 55 | const void* scaleB = nullptr; |
| 56 | + int32_t pointerMode = 0; // 0 = host | ||
| 56 | }; | 57 | }; |
| 57 | static_assert( | 58 | static_assert( |
| 58 | sizeof(aclblasLtMatmulDescImpl) <= sizeof(aclblasLtMatmulDescOpaque_t), | 59 | sizeof(aclblasLtMatmulDescImpl) <= sizeof(aclblasLtMatmulDescOpaque_t), |
| @@ -510,7 +510,7 @@ aclblasStatus_t aclblasLtMatmulPreferenceSetAttribute(aclblasLtMatmulPreference_ | |||
| 510 | size_t sizeInBytes); | 510 | size_t sizeInBytes); |
| 511 | ``` | 511 | ``` |
| 512 | 512 | ||
| 513 | -设置算法搜索偏好属性,如 `ACLBLASLT_MATMUL_PREF_MAX_WORKSPACE_BYTES`(允许的最大 workspace 字节数,默认 0 表示不允许 workspace)。 | 513 | +设置算法搜索偏好属性,如 `ACLBLASLT_MATMUL_PREF_MAX_WORKSPACE_BYTES`(允许的最大 workspace 字节数,默认 32MB)。 |
| 514 | 514 | ||
| 515 | | 返回值 | 含义 | | 515 | | 返回值 | 含义 | |
| 516 | |---|---| | 516 | |---|---| |
| @@ -1055,7 +1055,7 @@ aclBLASLt 日志掩码位标志枚举,按位组合控制各类消息的输出 | |||
| 1055 | | 取值 | 含义 | 数据类型 | 默认值 | | 1055 | | 取值 | 含义 | 数据类型 | 默认值 | |
| 1056 | |---|---|---|---| | 1056 | |---|---|---|---| |
| 1057 | | `ACLBLASLT_MATMUL_PREF_SEARCH_MODE` (0) | 搜索模式:0=启发式,1=穷举,2=快速。 | `uint32_t` | 0 | | 1057 | | `ACLBLASLT_MATMUL_PREF_SEARCH_MODE` (0) | 搜索模式:0=启发式,1=穷举,2=快速。 | `uint32_t` | 0 | |
| 1058 | -| `ACLBLASLT_MATMUL_PREF_MAX_WORKSPACE_BYTES` (1) | 允许的最大 workspace 字节数。 | `uint64_t` | 0 | | 1058 | +| `ACLBLASLT_MATMUL_PREF_MAX_WORKSPACE_BYTES` (1) | 允许的最大 workspace 字节数。 | `uint64_t` | 32MB(`32*1024*1024`) | |
| 1059 | 1059 | ||
| 1060 | ### aclblasLtMatmulTile_t | 1060 | ### aclblasLtMatmulTile_t |
| 1061 | 1061 | ||
| @@ -1098,8 +1098,8 @@ SplitK 归约方案枚举。映射到 `PackedAlgo.flags` 低 2 位。用于 `ACL | |||
| 1098 | | 取值 | 含义 | 数据类型 | 默认值 | | 1098 | | 取值 | 含义 | 数据类型 | 默认值 | |
| 1099 | |---|---|---|---| | 1099 | |---|---|---|---| |
| 1100 | | `ACLBLASLT_ALGO_CONFIG_ID` (0) | 只读。算法索引,由 AlgoInit / ConfigSet 维护。 | `int32_t` | `0x00808201` | | 1100 | | `ACLBLASLT_ALGO_CONFIG_ID` (0) | 只读。算法索引,由 AlgoInit / ConfigSet 维护。 | `int32_t` | `0x00808201` | |
| 1101 | -| `ACLBLASLT_ALGO_CONFIG_TILE_ID` (1) | L1 Tile M×N 形状,见 `aclblasLtMatmulTile_t`。 | `uint32_t` | `UNDEFINED` | | 1101 | +| `ACLBLASLT_ALGO_CONFIG_TILE_ID` (1) | L1 Tile M×N 形状,见 `aclblasLtMatmulTile_t`。 | `uint32_t` | `TILE_128x128` | |
| 1102 | -| `ACLBLASLT_ALGO_CONFIG_STAGES_ID` (2) | 流水级数,见 `aclblasLtMatmulStages_t`。 | `uint32_t` | `UNDEFINED` | | 1102 | +| `ACLBLASLT_ALGO_CONFIG_STAGES_ID` (2) | 流水级数,见 `aclblasLtMatmulStages_t`。 | `uint32_t` | `STAGES_1` | |
| 1103 | | `ACLBLASLT_ALGO_CONFIG_SPLITK_NUM` (3) | K 维切分数,范围 [1, 255]。 | `uint32_t` | 1 | | 1103 | | `ACLBLASLT_ALGO_CONFIG_SPLITK_NUM` (3) | K 维切分数,范围 [1, 255]。 | `uint32_t` | 1 | |
| 1104 | | `ACLBLASLT_ALGO_CONFIG_REDUCTION_SCHEME` (4) | SplitK 归约方案,见 `aclblasLtReductionScheme_t`。 | `uint32_t` | `NONE` | | 1104 | | `ACLBLASLT_ALGO_CONFIG_REDUCTION_SCHEME` (4) | SplitK 归约方案,见 `aclblasLtReductionScheme_t`。 | `uint32_t` | `NONE` | |
| 1105 | | `ACLBLASLT_ALGO_CONFIG_CUSTOM_OPTION` (5) | dispatch policy(0=sync, 1=pingpong, 2=multi_stage)。 | `uint32_t` | 0 | | 1105 | | `ACLBLASLT_ALGO_CONFIG_CUSTOM_OPTION` (5) | dispatch policy(0=sync, 1=pingpong, 2=multi_stage)。 | `uint32_t` | 0 | |
| @@ -199,7 +199,7 @@ typedef enum aclblasLtMatrixTransformDescAttribute { | |||
| 199 | */ | 199 | */ |
| 200 | typedef enum aclblasLtMatmulPreferenceAttribute { | 200 | typedef enum aclblasLtMatmulPreferenceAttribute { |
| 201 | ACLBLASLT_MATMUL_PREF_SEARCH_MODE = 0, /**<Search mode. Data type: ``uint32_t``. */ | 201 | ACLBLASLT_MATMUL_PREF_SEARCH_MODE = 0, /**<Search mode. Data type: ``uint32_t``. */ |
| 202 | - ACLBLASLT_MATMUL_PREF_MAX_WORKSPACE_BYTES = 1, /**<Maximum allowed workspace memory. Default is 0 (no workspace memory allowed). Data type: ``uint64_t``. */ | 202 | + ACLBLASLT_MATMUL_PREF_MAX_WORKSPACE_BYTES = 1, /**<Maximum allowed workspace memory. Default is 32MB (32*1024*1024 bytes). Data type: ``uint64_t``. */ |
| 203 | ACLBLASLT_MATMUL_PREF_MAX = 2 | 203 | ACLBLASLT_MATMUL_PREF_MAX = 2 |
| 204 | } aclblasLtMatmulPreferenceAttribute_t; | 204 | } aclblasLtMatmulPreferenceAttribute_t; |
| 205 | 205 | ||