已开启
fix: validate MatmulAbftVerify inputs and Crypto example #129
jiyg创建于 9月30日
fix: validate MatmulAbftVerify inputs and Crypto example #129
已开启
共 8 个文件变更+412-138
| @@ -34,7 +34,7 @@ | |||
| 34 | 每个算子分为两段式接口,必须先调用“aclnnCryptoGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnCrypto”接口执行计算。 | 34 | 每个算子分为两段式接口,必须先调用“aclnnCryptoGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnCrypto”接口执行计算。 |
| 35 | 35 | ||
| 36 | ```c++ | 36 | ```c++ |
| 37 | -aclnnStatus aclnnCryptoAicpuGetWorkspaceSize( | 37 | +aclnnStatus aclnnCryptoGetWorkspaceSize( |
| 38 | const aclTensor *key, | 38 | const aclTensor *key, |
| 39 | const aclTensor *inputText, | 39 | const aclTensor *inputText, |
| 40 | aclTensor *outputText, | 40 | aclTensor *outputText, |
| @@ -48,7 +48,7 @@ aclnnStatus aclnnCryptoAicpuGetWorkspaceSize( | |||
| 48 | ``` | 48 | ``` |
| 49 | 49 | ||
| 50 | ```c++ | 50 | ```c++ |
| 51 | -aclnnStatus aclnnCryptoAicpu( | 51 | +aclnnStatus aclnnCrypto( |
| 52 | void *workspace, | 52 | void *workspace, |
| 53 | uint64_t workspaceSize, | 53 | uint64_t workspaceSize, |
| 54 | aclOpExecutor *executor, | 54 | aclOpExecutor *executor, |
| @@ -486,6 +486,10 @@ template <typename T> | |||
| 486 | int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, | 486 | int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 487 | aclDataType dataType, aclTensor** tensor) { | 487 | aclDataType dataType, aclTensor** tensor) { |
| 488 | auto size = GetShapeSize(shape) * sizeof(T); | 488 | auto size = GetShapeSize(shape) * sizeof(T); |
| 489 | + if (hostData.size() != GetShapeSize(shape)) { | ||
| 490 | + LOG_PRINT("host data length does not match tensor shape\n"); | ||
| 491 | + return ACL_ERROR_INVALID_PARAM; | ||
| 492 | + } | ||
| 489 | auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | 493 | auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); |
| 490 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | 494 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); |
| 491 | 495 | ||
| @@ -612,7 +616,7 @@ int main(int argc, char *argv[]) { | |||
| 612 | std::vector<uint8_t> keyHostData(16, 0x11); // key数据 | 616 | std::vector<uint8_t> keyHostData(16, 0x11); // key数据 |
| 613 | std::vector<uint8_t> inputHostData(msg_len, 0x00); // 输入数据 | 617 | std::vector<uint8_t> inputHostData(msg_len, 0x00); // 输入数据 |
| 614 | 618 | ||
| 615 | - std::vector<uint8_t> ivHostData(16, 0x1f); // iv | 619 | + std::vector<uint8_t> ivHostData(32, 0x1f); // iv,长度与 iv_shape_data 一致 |
| 616 | std::vector<uint32_t> opConfigHostData = {1, static_cast<uint32_t>(mode), static_cast<uint32_t>(alg_type), 1, 34, 0}; // 配置version, mode, alg_type, key_type, keyId, device_id | 620 | std::vector<uint32_t> opConfigHostData = {1, static_cast<uint32_t>(mode), static_cast<uint32_t>(alg_type), 1, 34, 0}; // 配置version, mode, alg_type, key_type, keyId, device_id |
| 617 | std::vector<uint8_t> outputHostData(msg_len, 0); // 输出 | 621 | std::vector<uint8_t> outputHostData(msg_len, 0); // 输出 |
| 618 | std::vector<uint32_t> yHostData = {0}; // 输出 | 622 | std::vector<uint32_t> yHostData = {0}; // 输出 |
| @@ -626,16 +630,23 @@ int main(int argc, char *argv[]) { | |||
| 626 | } | 630 | } |
| 627 | 631 | ||
| 628 | // ===================== 创建所有aclTensor ===================== | 632 | // ===================== 创建所有aclTensor ===================== |
| 629 | - CreateAclTensor(keyHostData, key_shape_data, &keyDeviceAddr, ACL_UINT8, &key); | 633 | + ret = CreateAclTensor(keyHostData, key_shape_data, &keyDeviceAddr, ACL_UINT8, &key); |
| 634 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 630 | 635 | ||
| 631 | - CreateAclTensor(inputHostData, input_shape_data, &inputDeviceAddr, ACL_UINT8, &input); | 636 | + ret = CreateAclTensor(inputHostData, input_shape_data, &inputDeviceAddr, ACL_UINT8, &input); |
| 637 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 632 | 638 | ||
| 633 | - CreateAclTensor(ivHostData, iv_shape_data, &ivDeviceAddr, ACL_UINT8, &iv); | 639 | + ret = CreateAclTensor(ivHostData, iv_shape_data, &ivDeviceAddr, ACL_UINT8, &iv); |
| 634 | - CreateAclTensor(opConfigHostData, shape_op_cfg, &opConfigDeviceAddr, ACL_UINT32, &opConfig); | 640 | + CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 635 | - CreateAclTensor(outputHostData, shape_output, &outputDeviceAddr, ACL_UINT8, &output); | 641 | + ret = CreateAclTensor(opConfigHostData, shape_op_cfg, &opConfigDeviceAddr, ACL_UINT32, &opConfig); |
| 636 | - CreateAclTensor(yHostData, shape_y, &yDeviceAddr, ACL_UINT32, &y); | 642 | + CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 643 | + ret = CreateAclTensor(outputHostData, shape_output, &outputDeviceAddr, ACL_UINT8, &output); | ||
| 644 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 645 | + ret = CreateAclTensor(yHostData, shape_y, &yDeviceAddr, ACL_UINT32, &y); | ||
| 646 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 637 | 647 | ||
| 638 | - CreateAclTensor(tagHostData, shape_tag, &tagRefOptionalDeviceAddr, ACL_UINT8, &tagRefOptional); | 648 | + ret = CreateAclTensor(tagHostData, shape_tag, &tagRefOptionalDeviceAddr, ACL_UINT8, &tagRefOptional); |
| 649 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 639 | printf("tensor created\n"); | 650 | printf("tensor created\n"); |
| 640 | // ===================== 3. 调用自定义算子aclnnCrypto ===================== | 651 | // ===================== 3. 调用自定义算子aclnnCrypto ===================== |
| 641 | uint64_t workspaceSize = 0; | 652 | uint64_t workspaceSize = 0; |
| @@ -750,4 +761,4 @@ int main(int argc, char *argv[]) { | |||
| 750 | printf("======================================\n"); | 761 | printf("======================================\n"); |
| 751 | return 0; | 762 | return 0; |
| 752 | } | 763 | } |
| 753 | -``` | 764 | +``` |
| @@ -34,7 +34,7 @@ | |||
| 34 | Each operator uses a two-phase API. Call the "aclnnCryptoGetWorkspaceSize" API to obtain the required workspace size and the executor that contains the operator computation flow, and then call the "aclnnCrypto" API to execute the computation. | 34 | Each operator uses a two-phase API. Call the "aclnnCryptoGetWorkspaceSize" API to obtain the required workspace size and the executor that contains the operator computation flow, and then call the "aclnnCrypto" API to execute the computation. |
| 35 | 35 | ||
| 36 | ```c++ | 36 | ```c++ |
| 37 | -aclnnStatus aclnnCryptoAicpuGetWorkspaceSize( | 37 | +aclnnStatus aclnnCryptoGetWorkspaceSize( |
| 38 | const aclTensor *key, | 38 | const aclTensor *key, |
| 39 | const aclTensor *inputText, | 39 | const aclTensor *inputText, |
| 40 | aclTensor *outputText, | 40 | aclTensor *outputText, |
| @@ -48,7 +48,7 @@ aclnnStatus aclnnCryptoAicpuGetWorkspaceSize( | |||
| 48 | ``` | 48 | ``` |
| 49 | 49 | ||
| 50 | ```c++ | 50 | ```c++ |
| 51 | -aclnnStatus aclnnCryptoAicpu( | 51 | +aclnnStatus aclnnCrypto( |
| 52 | void *workspace, | 52 | void *workspace, |
| 53 | uint64_t workspaceSize, | 53 | uint64_t workspaceSize, |
| 54 | aclOpExecutor *executor, | 54 | aclOpExecutor *executor, |
| @@ -612,7 +612,7 @@ int main(int argc, char *argv[]) { | |||
| 612 | std::vector<uint8_t> keyHostData(16, 0x11); // key data | 612 | std::vector<uint8_t> keyHostData(16, 0x11); // key data |
| 613 | std::vector<uint8_t> inputHostData(msg_len, 0x00); // input data | 613 | std::vector<uint8_t> inputHostData(msg_len, 0x00); // input data |
| 614 | 614 | ||
| 615 | - std::vector<uint8_t> ivHostData(16, 0x1f); // iv | 615 | + std::vector<uint8_t> ivHostData(32, 0x1f); // iv, matching iv_shape_data |
| 616 | std::vector<uint32_t> opConfigHostData = {1, static_cast<uint32_t>(mode), static_cast<uint32_t>(alg_type), 1, 34, 0}; // Configure version, mode, alg_type, key_type, keyId, device_id | 616 | std::vector<uint32_t> opConfigHostData = {1, static_cast<uint32_t>(mode), static_cast<uint32_t>(alg_type), 1, 34, 0}; // Configure version, mode, alg_type, key_type, keyId, device_id |
| 617 | std::vector<uint8_t> outputHostData(msg_len, 0); // output | 617 | std::vector<uint8_t> outputHostData(msg_len, 0); // output |
| 618 | std::vector<uint32_t> yHostData = {0}; // output | 618 | std::vector<uint32_t> yHostData = {0}; // output |
| @@ -238,8 +238,8 @@ aclnnStatus aclnnMatmulAbftVerify( | |||
| 238 | <td>必选输入、输出或者必选属性是空指针。</td> | 238 | <td>必选输入、输出或者必选属性是空指针。</td> |
| 239 | </tr> | 239 | </tr> |
| 240 | <tr> | 240 | <tr> |
| 241 | - <td rowspan="5">ACLNN_ERR_PARAM_INVALID</td> | 241 | + <td rowspan="8">ACLNN_ERR_PARAM_INVALID</td> |
| 242 | - <td rowspan="5">161002</td> | 242 | + <td rowspan="8">161002</td> |
| 243 | <td>a、b、c、weight、eMax、beSplitFactor、compRow的数据类型和数据格式不在支持的范围内。</td> | 243 | <td>a、b、c、weight、eMax、beSplitFactor、compRow的数据类型和数据格式不在支持的范围内。</td> |
| 244 | </tr> | 244 | </tr> |
| 245 | <tr> | 245 | <tr> |
| @@ -251,6 +251,15 @@ aclnnStatus aclnnMatmulAbftVerify( | |||
| 251 | <tr> | 251 | <tr> |
| 252 | <td>eMax为负数。</td> | 252 | <td>eMax为负数。</td> |
| 253 | </tr> | 253 | </tr> |
| 254 | + <tr> | ||
| 255 | + <td>eMax为非有限值。</td> | ||
| 256 | + </tr> | ||
| 257 | + <tr> | ||
| 258 | + <td>a、b和checksumWeight的数据类型组合不受支持,或c的数据类型不是FLOAT32。</td> | ||
| 259 | + </tr> | ||
| 260 | + <tr> | ||
| 261 | + <td>c的shape与[M, N]不匹配,或checksumWeight的shape与[N]不匹配。</td> | ||
| 262 | + </tr> | ||
| 254 | <tr> | 263 | <tr> |
| 255 | <td>reduceCores小于0。</td> | 264 | <td>reduceCores小于0。</td> |
| 256 | </tr> | 265 | </tr> |
| @@ -281,6 +290,7 @@ aclnnStatus aclnnMatmulAbftVerify( | |||
| 281 | - aclnnMatmulAbftVerify默认确定性实现。 | 290 | - aclnnMatmulAbftVerify默认确定性实现。 |
| 282 | - 输入矩阵a、b和c必须为2维,shape分别为[M, K]、[K, N]和[M, N],且a的第1维(K)与b的第0维(K)必须相等。 | 291 | - 输入矩阵a、b和c必须为2维,shape分别为[M, K]、[K, N]和[M, N],且a的第1维(K)与b的第0维(K)必须相等。 |
| 283 | - 输入向量weight的shape必须为[N]。 | 292 | - 输入向量weight的shape必须为[N]。 |
| 293 | +- a、b和checksumWeight必须使用相同的数据类型,c必须为FLOAT32;支持的数据类型组合见下表。 | ||
| 284 | - 支持的数据类型组合为: | 294 | - 支持的数据类型组合为: |
| 285 | 295 | ||
| 286 | | a | b | c | checksumWeight | | 296 | | a | b | c | checksumWeight | |
| @@ -97,7 +97,9 @@ aclnnStatus aclnnMatmulAbftVerify( | |||
| 97 | | ACLNN_ERR_PARAM_INVALID | 161002 | The data type or format of `a`, `b`, `c`, `weight`, `eMax`, `beSplitFactor`, or `compRow` is unsupported. | | 97 | | ACLNN_ERR_PARAM_INVALID | 161002 | The data type or format of `a`, `b`, `c`, `weight`, `eMax`, `beSplitFactor`, or `compRow` is unsupported. | |
| 98 | | ACLNN_ERR_PARAM_INVALID | 161002 | `a` or `b` is not a 2D tensor. | | 98 | | ACLNN_ERR_PARAM_INVALID | 161002 | `a` or `b` is not a 2D tensor. | |
| 99 | | ACLNN_ERR_PARAM_INVALID | 161002 | Dimension 1 (K) of `a` differs from dimension 0 (K) of `b`. | | 99 | | ACLNN_ERR_PARAM_INVALID | 161002 | Dimension 1 (K) of `a` differs from dimension 0 (K) of `b`. | |
| 100 | - | ACLNN_ERR_PARAM_INVALID | 161002 | `eMax` is negative. | | 100 | + | ACLNN_ERR_PARAM_INVALID | 161002 | `eMax` is negative or non-finite. | |
| 101 | + | ACLNN_ERR_PARAM_INVALID | 161002 | The data type combination of `a`, `b`, and `checksumWeight` is unsupported, or `c` is not FLOAT32. | | ||
| 102 | + | ACLNN_ERR_PARAM_INVALID | 161002 | The shape of `c` does not match `[M, N]`, or the shape of `checksumWeight` does not match `[N]`. | | ||
| 101 | | ACLNN_ERR_PARAM_INVALID | 161002 | `reduceCores` is less than 0. | | 103 | | ACLNN_ERR_PARAM_INVALID | 161002 | `reduceCores` is less than 0. | |
| 102 | 104 | ||
| 103 | ## aclnnMatmulAbftVerify | 105 | ## aclnnMatmulAbftVerify |
| @@ -120,6 +122,7 @@ aclnnStatus aclnnMatmulAbftVerify( | |||
| 120 | - Deterministic computation: `aclnnMatmulAbftVerify` uses a deterministic implementation by default. | 122 | - Deterministic computation: `aclnnMatmulAbftVerify` uses a deterministic implementation by default. |
| 121 | - Input matrices `a`, `b`, and `c` must be 2D tensors with shapes `[M, K]`, `[K, N]`, and `[M, N]`, respectively. Dimension 1 (K) of `a` must equal dimension 0 (K) of `b`. | 123 | - Input matrices `a`, `b`, and `c` must be 2D tensors with shapes `[M, K]`, `[K, N]`, and `[M, N]`, respectively. Dimension 1 (K) of `a` must equal dimension 0 (K) of `b`. |
| 122 | - The shape of input vector `checksumWeight` must be `[N]`. | 124 | - The shape of input vector `checksumWeight` must be `[N]`. |
| 125 | +- `a`, `b`, and `checksumWeight` must have the same data type, and `c` must be FLOAT32. Supported combinations are listed below. | ||
| 123 | - The following data type combinations are supported: | 126 | - The following data type combinations are supported: |
| 124 | 127 | ||
| 125 | | a | b | c | checksumWeight | | 128 | | a | b | c | checksumWeight | |
Mreliability/matmul_abft_verify/tests/ut/op_host/test_matmul_abft_verify_tiling.cpp+190-32文件内容审核中,请稍后刷新重试