Merged
Fix Docs: Correct Parameter Directions and Array Length in aclnnTransConvolutionWeight Example #464
LiuZongguAdd on Dec 23, 2025
Fix Docs: Correct Parameter Directions and Array Length in aclnnTransConvolutionWeight Example #464
Merged
Total: 1 files changed+16-16
| @@ -171,12 +171,12 @@ aclnnStatus aclnnTransConvolutionWeight( | |||
| 171 | </tr> | 171 | </tr> |
| 172 | <tr> | 172 | <tr> |
| 173 | <td>executor</td> | 173 | <td>executor</td> |
| 174 | - <td>输出</td> | 174 | + <td>输入</td> |
| 175 | - <td>返回op执行器,包含了算子计算流程。</td> | 175 | + <td>op执行器,包含了算子计算流程,由第一段接口aclnnTransConvolutionWeightGetWorkspaceSize获取。</td> |
| 176 | </tr> | 176 | </tr> |
| 177 | <tr> | 177 | <tr> |
| 178 | <td>stream</td> | 178 | <td>stream</td> |
| 179 | - <td>输出</td> | 179 | + <td>输入</td> |
| 180 | <td>指定执行任务的Stream。</td> | 180 | <td>指定执行任务的Stream。</td> |
| 181 | </tr> | 181 | </tr> |
| 182 | </table> | 182 | </table> |
| @@ -327,7 +327,7 @@ int aclnnTransConvolutionWeightTest(int32_t deviceId, aclrtStream& stream) { | |||
| 327 | std::vector<float> biasHostData(2, 1); | 327 | std::vector<float> biasHostData(2, 1); |
| 328 | std::vector<float> outHostData(162, 0); | 328 | std::vector<float> outHostData(162, 0); |
| 329 | uint64_t transWeightSize = 0; | 329 | uint64_t transWeightSize = 0; |
| 330 | - | 330 | + |
| 331 | // 创建input aclTensor | 331 | // 创建input aclTensor |
| 332 | ret = CreateAclTensor(inputHostData, inputShape, &inputDeviceAddr, aclDataType::ACL_FLOAT, &input); | 332 | ret = CreateAclTensor(inputHostData, inputShape, &inputDeviceAddr, aclDataType::ACL_FLOAT, &input); |
| 333 | std::unique_ptr<aclTensor, aclnnStatus (*)(const aclTensor *)> selfTensorPtr(input, aclDestroyTensor); | 333 | std::unique_ptr<aclTensor, aclnnStatus (*)(const aclTensor *)> selfTensorPtr(input, aclDestroyTensor); |
| @@ -352,7 +352,7 @@ int aclnnTransConvolutionWeightTest(int32_t deviceId, aclrtStream& stream) { | |||
| 352 | std::unique_ptr<aclTensor, aclnnStatus (*)(const aclTensor *)> outTensorPtr(out, aclDestroyTensor); | 352 | std::unique_ptr<aclTensor, aclnnStatus (*)(const aclTensor *)> outTensorPtr(out, aclDestroyTensor); |
| 353 | std::unique_ptr<void, aclError (*)(void *)> outDeviceAddrPtr(outDeviceAddr, aclrtFree); | 353 | std::unique_ptr<void, aclError (*)(void *)> outDeviceAddrPtr(outDeviceAddr, aclrtFree); |
| 354 | CHECK_FREE_RET(ret == ACL_SUCCESS, return ret); | 354 | CHECK_FREE_RET(ret == ACL_SUCCESS, return ret); |
| 355 | - | 355 | + |
| 356 | // 创建Transweight acltensor | 356 | // 创建Transweight acltensor |
| 357 | void* transWeightDeviceAddr = nullptr; | 357 | void* transWeightDeviceAddr = nullptr; |
| 358 | uint64_t size = transWeightSize * sizeof(float) / 2; | 358 | uint64_t size = transWeightSize * sizeof(float) / 2; |
| @@ -379,7 +379,7 @@ int aclnnTransConvolutionWeightTest(int32_t deviceId, aclrtStream& stream) { | |||
| 379 | std::unique_ptr<aclTensor, aclnnStatus (*)(const aclTensor *)> transWeightTensorPtr(transWeight, aclDestroyTensor); | 379 | std::unique_ptr<aclTensor, aclnnStatus (*)(const aclTensor *)> transWeightTensorPtr(transWeight, aclDestroyTensor); |
| 380 | std::unique_ptr<void, aclError (*)(void *)> transWeightDeviceAddrAddrPtr(transWeightDeviceAddr, aclrtFree); | 380 | std::unique_ptr<void, aclError (*)(void *)> transWeightDeviceAddrAddrPtr(transWeightDeviceAddr, aclrtFree); |
| 381 | 381 | ||
| 382 | - // 3. 调用CANN算子库API,需要修改为具体的API名称 | 382 | + // 3. 调用 aclnnTransConvolutionWeight |
| 383 | int8_t cubeMathType = 2; // USE_FP16 | 383 | int8_t cubeMathType = 2; // USE_FP16 |
| 384 | uint64_t workspaceSize = 0; | 384 | uint64_t workspaceSize = 0; |
| 385 | aclOpExecutor* executor; | 385 | aclOpExecutor* executor; |
| @@ -401,26 +401,26 @@ int aclnnTransConvolutionWeightTest(int32_t deviceId, aclrtStream& stream) { | |||
| 401 | // 调用aclnnTransConvolutionWeight第二段接口 | 401 | // 调用aclnnTransConvolutionWeight第二段接口 |
| 402 | ret = aclnnTransConvolutionWeight(workspaceAddr, workspaceSize, executor, stream); | 402 | ret = aclnnTransConvolutionWeight(workspaceAddr, workspaceSize, executor, stream); |
| 403 | CHECK_FREE_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnTransConvolutionWeight failed. ERROR: %d\n", ret); return ret); | 403 | CHECK_FREE_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnTransConvolutionWeight failed. ERROR: %d\n", ret); return ret); |
| 404 | - | ||
| 405 | - std::vector<int64_t> convStrides = {1, 1, 1, 1}; | ||
| 406 | - std::vector<int64_t> convPads = {0, 0, 0, 0}; | ||
| 407 | - std::vector<int64_t> convOutPads = {1, 1, 1, 1}; | ||
| 408 | - std::vector<int64_t> convDilations = {1, 1, 1, 1}; | ||
| 409 | 404 | ||
| 410 | - aclIntArray *strides = aclCreateIntArray(convStrides.data(), 2); | 405 | + std::vector<int64_t> convStrides = {1, 1}; |
| 406 | + std::vector<int64_t> convPads = {0, 0}; | ||
| 407 | + std::vector<int64_t> convOutPads = {1, 1}; | ||
| 408 | + std::vector<int64_t> convDilations = {1, 1}; | ||
| 409 | + | ||
| 410 | + aclIntArray *strides = aclCreateIntArray(convStrides.data(), convStrides.size()); | ||
| 411 | std::unique_ptr<aclIntArray, aclnnStatus (*)(const aclIntArray *)> stridesPtr(strides, aclDestroyIntArray); | 411 | std::unique_ptr<aclIntArray, aclnnStatus (*)(const aclIntArray *)> stridesPtr(strides, aclDestroyIntArray); |
| 412 | CHECK_FREE_RET(strides != nullptr, return ACL_ERROR_INTERNAL_ERROR); | 412 | CHECK_FREE_RET(strides != nullptr, return ACL_ERROR_INTERNAL_ERROR); |
| 413 | - aclIntArray *pads = aclCreateIntArray(convPads.data(), 2); | 413 | + aclIntArray *pads = aclCreateIntArray(convPads.data(), convPads.size()); |
| 414 | std::unique_ptr<aclIntArray, aclnnStatus (*)(const aclIntArray *)> padsPtr(pads, aclDestroyIntArray); | 414 | std::unique_ptr<aclIntArray, aclnnStatus (*)(const aclIntArray *)> padsPtr(pads, aclDestroyIntArray); |
| 415 | CHECK_FREE_RET(pads != nullptr, return ACL_ERROR_INTERNAL_ERROR); | 415 | CHECK_FREE_RET(pads != nullptr, return ACL_ERROR_INTERNAL_ERROR); |
| 416 | - aclIntArray *outPads = aclCreateIntArray(convOutPads.data(), 2); | 416 | + aclIntArray *outPads = aclCreateIntArray(convOutPads.data(), convOutPads.size()); |
| 417 | std::unique_ptr<aclIntArray, aclnnStatus (*)(const aclIntArray *)> outPadsPtr(outPads, aclDestroyIntArray); | 417 | std::unique_ptr<aclIntArray, aclnnStatus (*)(const aclIntArray *)> outPadsPtr(outPads, aclDestroyIntArray); |
| 418 | CHECK_FREE_RET(outPads != nullptr, return ACL_ERROR_INTERNAL_ERROR); | 418 | CHECK_FREE_RET(outPads != nullptr, return ACL_ERROR_INTERNAL_ERROR); |
| 419 | - aclIntArray *dilations = aclCreateIntArray(convDilations.data(), 2); | 419 | + aclIntArray *dilations = aclCreateIntArray(convDilations.data(), convDilations.size()); |
| 420 | std::unique_ptr<aclIntArray, aclnnStatus (*)(const aclIntArray *)> dilationsPtr(dilations, aclDestroyIntArray); | 420 | std::unique_ptr<aclIntArray, aclnnStatus (*)(const aclIntArray *)> dilationsPtr(dilations, aclDestroyIntArray); |
| 421 | CHECK_FREE_RET(dilations != nullptr, return ACL_ERROR_INTERNAL_ERROR); | 421 | CHECK_FREE_RET(dilations != nullptr, return ACL_ERROR_INTERNAL_ERROR); |
| 422 | 422 | ||
| 423 | - // 3. 调用CANN算子库API,需要修改为具体的API | 423 | + // 4. 调用 aclnnConvolution |
| 424 | workspaceSize = 0; | 424 | workspaceSize = 0; |
| 425 | // 调用aclnnConvolution第一段接口 | 425 | // 调用aclnnConvolution第一段接口 |
| 426 | ret = aclnnConvolutionGetWorkspaceSize(input, transWeight, bias, strides, pads, dilations, false, outPads, groups, | 426 | ret = aclnnConvolutionGetWorkspaceSize(input, transWeight, bias, strides, pads, dilations, false, outPads, groups, |