已合并
fix: 修复代码审查发现的健壮性与文档问题(#96-#105) #113
syy_3597创建于 8月20日
fix: 修复代码审查发现的健壮性与文档问题(#96-#105) #113
已合并
共 66 个文件变更+1449-1452
| @@ -31,3 +31,9 @@ output/ | |||
| 31 | oat_reports/ | 31 | oat_reports/ |
| 32 | 32 | ||
| 33 | log/ | 33 | log/ |
| 34 | + | ||
| 35 | +# coverage tool and lint caches | ||
| 36 | +lcov/ | ||
| 37 | +lcov-1.16/ | ||
| 38 | +.ruff_cache/ | ||
| 39 | +oat_reports*/ | ||
| @@ -8,6 +8,7 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | + | ||
| 11 | 12 | ||
| 12 | 13 | ||
| 13 | 14 | ||
| @@ -22,7 +23,7 @@ using namespace AsdSip; | |||
| 22 | 23 | ||
| 23 | namespace AsdSip { | 24 | namespace AsdSip { |
| 24 | 25 | ||
| 25 | -AspbStatus SwapLast2AxesDtypeCheck(const aclTensor *inTensor, aclTensor *outTensor) | 26 | +AspbStatus SwapLast2AxesDtypeCheck(const aclTensor* inTensor, aclTensor* outTensor) |
| 26 | { | 27 | { |
| 27 | auto ret = ErrorType::ACL_ERROR_UNSUPPORTED_DATA_TYPE; | 28 | auto ret = ErrorType::ACL_ERROR_UNSUPPORTED_DATA_TYPE; |
| 28 | SIP_OP_CHECK_DTYPE_NOT_MATCH(inTensor, aclDataType::ACL_COMPLEX64, ret); | 29 | SIP_OP_CHECK_DTYPE_NOT_MATCH(inTensor, aclDataType::ACL_COMPLEX64, ret); |
| @@ -31,28 +32,28 @@ AspbStatus SwapLast2AxesDtypeCheck(const aclTensor *inTensor, aclTensor *outTens | |||
| 31 | return ErrorType::ACL_SUCCESS; | 32 | return ErrorType::ACL_SUCCESS; |
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | -AspbStatus SwapLast2AxesShapeCheck( | 35 | +AspbStatus SwapLast2AxesShapeCheck(const aclTensor* inTensor, aclTensor* outTensor, int64_t*& storageDims, |
| 35 | - const aclTensor *inTensor, aclTensor *outTensor, int64_t *&storageDims, uint64_t &inStorageDimsNum) | 36 | + uint64_t& inStorageDimsNum) |
| 36 | { | 37 | { |
| 37 | uint64_t outStorageDimsNum = 0; | 38 | uint64_t outStorageDimsNum = 0; |
| 38 | - CHECK_STATUS_WITH_ACL_RETURN( | 39 | + CHECK_STATUS_WITH_ACL_RETURN(aclGetStorageShape(outTensor, &storageDims, &outStorageDimsNum), |
| 39 | - aclGetStorageShape(outTensor, &storageDims, &outStorageDimsNum), "swapLast2Axes: aclGetStorageShape"); | 40 | + "swapLast2Axes: aclGetStorageShape"); |
| 40 | - int64_t outNum = GetTensorNum(outStorageDimsNum, storageDims); | 41 | + std::optional<int64_t> outNumOpt = GetTensorNum(outStorageDimsNum, storageDims); |
| 41 | 42 | ||
| 42 | delete[] storageDims; | 43 | delete[] storageDims; |
| 43 | storageDims = nullptr; | 44 | storageDims = nullptr; |
| 44 | 45 | ||
| 45 | - CHECK_STATUS_WITH_ACL_RETURN( | 46 | + CHECK_STATUS_WITH_ACL_RETURN(aclGetStorageShape(inTensor, &storageDims, &inStorageDimsNum), |
| 46 | - aclGetStorageShape(inTensor, &storageDims, &inStorageDimsNum), "swapLast2Axes: aclGetStorageShape"); | 47 | + "swapLast2Axes: aclGetStorageShape"); |
| 47 | 48 | ||
| 48 | // element num check | 49 | // element num check |
| 49 | - int64_t inNum = GetTensorNum(inStorageDimsNum, storageDims); | 50 | + std::optional<int64_t> inNumOpt = GetTensorNum(inStorageDimsNum, storageDims); |
| 50 | - if (outNum < inNum) { | 51 | + if (!outNumOpt.has_value() || !inNumOpt.has_value() || outNumOpt.value() < inNumOpt.value()) { |
| 51 | delete[] storageDims; | 52 | delete[] storageDims; |
| 52 | storageDims = nullptr; | 53 | storageDims = nullptr; |
| 53 | - ASDSIP_LOG(ERROR) << "swapLast2Axes get wrong inTensor or ouTensor num." | 54 | + ASDSIP_LOG(ERROR) << "swapLast2Axes get wrong inTensor or outTensor num." |
| 54 | - << "In element num is " << inNum << " , and out element num is " << outNum | 55 | + << "In element num is " << inNumOpt.value_or(-1) << " , and out element num is " |
| 55 | - << " . Out num must be no less than in num"; | 56 | + << outNumOpt.value_or(-1) << " . Out num must be no less than in num"; |
| 56 | return ErrorType::ACL_ERROR_INVALID_PARAM; | 57 | return ErrorType::ACL_ERROR_INVALID_PARAM; |
| 57 | } | 58 | } |
| 58 | 59 | ||
| @@ -67,14 +68,14 @@ AspbStatus SwapLast2AxesShapeCheck( | |||
| 67 | return ErrorType::ACL_SUCCESS; | 68 | return ErrorType::ACL_SUCCESS; |
| 68 | } | 69 | } |
| 69 | 70 | ||
| 70 | -AspbStatus swapLast2Axes(const aclTensor *inTensor, aclTensor *outTensor, void *stream, void *workspace) | 71 | +AspbStatus swapLast2Axes(const aclTensor* inTensor, aclTensor* outTensor, void* stream, void* workspace) |
| 71 | { | 72 | { |
| 72 | auto ret = SwapLast2AxesDtypeCheck(inTensor, outTensor); | 73 | auto ret = SwapLast2AxesDtypeCheck(inTensor, outTensor); |
| 73 | if (ret != ErrorType::ACL_SUCCESS) { | 74 | if (ret != ErrorType::ACL_SUCCESS) { |
| 74 | return ret; | 75 | return ret; |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | - int64_t *storageDims = nullptr; | 78 | + int64_t* storageDims = nullptr; |
| 78 | uint64_t inStorageDimsNum = 0; | 79 | uint64_t inStorageDimsNum = 0; |
| 79 | ret = SwapLast2AxesShapeCheck(inTensor, outTensor, storageDims, inStorageDimsNum); | 80 | ret = SwapLast2AxesShapeCheck(inTensor, outTensor, storageDims, inStorageDimsNum); |
| 80 | if (ret != ErrorType::ACL_SUCCESS) { | 81 | if (ret != ErrorType::ACL_SUCCESS) { |
| @@ -96,24 +97,24 @@ AspbStatus swapLast2Axes(const aclTensor *inTensor, aclTensor *outTensor, void * | |||
| 96 | opDesc.specificParam = param; | 97 | opDesc.specificParam = param; |
| 97 | ASDSIP_LOG(DEBUG) << "OpDesc: " << opDesc.opName << "; OpDesc info: " << param.ToString(); | 98 | ASDSIP_LOG(DEBUG) << "OpDesc: " << opDesc.opName << "; OpDesc info: " << param.ToString(); |
| 98 | 99 | ||
| 99 | - SVector<aclTensor *> inTensors = {const_cast<aclTensor *>(inTensor)}; | 100 | + SVector<aclTensor*> inTensors = {const_cast<aclTensor*>(inTensor)}; |
| 100 | - SVector<aclTensor *> outTensors = {outTensor}; | 101 | + SVector<aclTensor*> outTensors = {outTensor}; |
| 101 | 102 | ||
| 102 | if (storageDims != nullptr) { | 103 | if (storageDims != nullptr) { |
| 103 | delete[] storageDims; | 104 | delete[] storageDims; |
| 104 | storageDims = nullptr; | 105 | storageDims = nullptr; |
| 105 | } | 106 | } |
| 106 | 107 | ||
| 107 | - Status status = RunAsdOpsV2(stream, opDesc, inTensors, outTensors, (uint8_t *)workspace); | 108 | + Status status = RunAsdOpsV2(stream, opDesc, inTensors, outTensors, (uint8_t*)workspace); |
| 108 | ASDSIP_ECHECK(status.Ok(), status.Message(), ErrorType::ACL_ERROR_INTERNAL_ERROR); | 109 | ASDSIP_ECHECK(status.Ok(), status.Message(), ErrorType::ACL_ERROR_INTERNAL_ERROR); |
| 109 | 110 | ||
| 110 | ASDSIP_LOG(INFO) << "Execute swapLast2Axes success."; | 111 | ASDSIP_LOG(INFO) << "Execute swapLast2Axes success."; |
| 111 | return ErrorType::ACL_SUCCESS; | 112 | return ErrorType::ACL_SUCCESS; |
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | -AsdSip::AspbStatus swapLast2AxesGetWorkspaceSize(size_t &size) | 115 | +AsdSip::AspbStatus swapLast2AxesGetWorkspaceSize(size_t& size) |
| 115 | { | 116 | { |
| 116 | size = ASYNC_WORKSPACE_SIZE; | 117 | size = ASYNC_WORKSPACE_SIZE; |
| 117 | return ErrorType::ACL_SUCCESS; | 118 | return ErrorType::ACL_SUCCESS; |
| 118 | } | 119 | } |
| 119 | -} // namespace AsdSip | 120 | +} // namespace AsdSip |
| @@ -12,7 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | namespace AsdSip { | 14 | namespace AsdSip { |
| 15 | -AspbStatus asdBlasCreate(asdBlasHandle &handle) | 15 | +AspbStatus asdBlasCreate(asdBlasHandle& handle) |
| 16 | { | 16 | { |
| 17 | std::lock_guard<std::mutex> lock(blas_mtx); | 17 | std::lock_guard<std::mutex> lock(blas_mtx); |
| 18 | handle = BlasPlanCache::InitHandle(); | 18 | handle = BlasPlanCache::InitHandle(); |
| @@ -20,13 +20,13 @@ AspbStatus asdBlasCreate(asdBlasHandle &handle) | |||
| 20 | return ErrorType::ACL_SUCCESS; | 20 | return ErrorType::ACL_SUCCESS; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | -AspbStatus asdBlasSetStream(asdBlasHandle handle, void *stream) | 23 | +AspbStatus asdBlasSetStream(asdBlasHandle handle, void* stream) |
| 24 | { | 24 | { |
| 25 | std::lock_guard<std::mutex> lock(blas_mtx); | 25 | std::lock_guard<std::mutex> lock(blas_mtx); |
| 26 | - ASDSIP_ECHECK( | 26 | + ASDSIP_ECHECK(BlasPlanCache::doesPlanExist(handle), "blas plan does not exist.", |
| 27 | - BlasPlanCache::doesPlanExist(handle), "blas plan does not exist.", ErrorType::ACL_ERROR_INTERNAL_ERROR); | 27 | + ErrorType::ACL_ERROR_INTERNAL_ERROR); |
| 28 | ASDSIP_ECHECK(stream != nullptr, "stream is empty.", ErrorType::ACL_ERROR_INTERNAL_ERROR); | 28 | ASDSIP_ECHECK(stream != nullptr, "stream is empty.", ErrorType::ACL_ERROR_INTERNAL_ERROR); |
| 29 | - BlasPlan &plan = BlasPlanCache::getPlan(handle); | 29 | + BlasPlan& plan = BlasPlanCache::getPlan(handle); |
| 30 | 30 | ||
| 31 | plan.SetStream(stream); | 31 | plan.SetStream(stream); |
| 32 | ASDSIP_LOG(INFO) << "Blas set stream success."; | 32 | ASDSIP_LOG(INFO) << "Blas set stream success."; |
| @@ -41,7 +41,7 @@ AspbStatus asdBlasDestroy(asdBlasHandle handle) | |||
| 41 | return ErrorType::ACL_ERROR_INVALID_PARAM; | 41 | return ErrorType::ACL_ERROR_INVALID_PARAM; |
| 42 | } | 42 | } |
| 43 | BlasPlanCache::destroy_plan(handle); | 43 | BlasPlanCache::destroy_plan(handle); |
| 44 | - delete static_cast<int *>(handle); | 44 | + delete static_cast<int*>(handle); |
| 45 | ASDSIP_LOG(INFO) << "BlasHandle destroy."; | 45 | ASDSIP_LOG(INFO) << "BlasHandle destroy."; |
| 46 | return ErrorType::ACL_SUCCESS; | 46 | return ErrorType::ACL_SUCCESS; |
| 47 | } | 47 | } |
| @@ -49,33 +49,33 @@ AspbStatus asdBlasDestroy(asdBlasHandle handle) | |||
| 49 | AspbStatus asdBlasSynchronize(asdBlasHandle handle) | 49 | AspbStatus asdBlasSynchronize(asdBlasHandle handle) |
| 50 | { | 50 | { |
| 51 | std::lock_guard<std::mutex> lock(blas_mtx); | 51 | std::lock_guard<std::mutex> lock(blas_mtx); |
| 52 | - ASDSIP_ECHECK( | 52 | + ASDSIP_ECHECK(BlasPlanCache::doesPlanExist(handle), "blas plan does not exist.", |
| 53 | - BlasPlanCache::doesPlanExist(handle), "blas plan does not exist.", ErrorType::ACL_ERROR_INTERNAL_ERROR); | 53 | + ErrorType::ACL_ERROR_INTERNAL_ERROR); |
| 54 | - BlasPlan &plan = BlasPlanCache::getPlan(handle); | 54 | + BlasPlan& plan = BlasPlanCache::getPlan(handle); |
| 55 | Mki::MkiRtStreamSynchronize(plan.GetStream()); | 55 | Mki::MkiRtStreamSynchronize(plan.GetStream()); |
| 56 | - ASDSIP_LOG(INFO) << "Blas get synchronized."; | 56 | + ASDSIP_LOG(INFO) << "Blas stream synchronized."; |
| 57 | return ErrorType::ACL_SUCCESS; | 57 | return ErrorType::ACL_SUCCESS; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | -AspbStatus asdBlasGetWorkspaceSize(asdBlasHandle handle, size_t &workspaceSize) | 60 | +AspbStatus asdBlasGetWorkspaceSize(asdBlasHandle handle, size_t& workspaceSize) |
| 61 | { | 61 | { |
| 62 | std::lock_guard<std::mutex> lock(blas_mtx); | 62 | std::lock_guard<std::mutex> lock(blas_mtx); |
| 63 | - ASDSIP_ECHECK( | 63 | + ASDSIP_ECHECK(BlasPlanCache::doesPlanExist(handle), "blas plan does not exist.", |
| 64 | - BlasPlanCache::doesPlanExist(handle), "blas plan does not exist.", ErrorType::ACL_ERROR_INTERNAL_ERROR); | 64 | + ErrorType::ACL_ERROR_INTERNAL_ERROR); |
| 65 | - BlasPlan &plan = BlasPlanCache::getPlan(handle); | 65 | + BlasPlan& plan = BlasPlanCache::getPlan(handle); |
| 66 | workspaceSize = static_cast<size_t>(plan.GetWorkspaceSize()); | 66 | workspaceSize = static_cast<size_t>(plan.GetWorkspaceSize()); |
| 67 | ASDSIP_LOG(INFO) << "Blas get workspaceSize success."; | 67 | ASDSIP_LOG(INFO) << "Blas get workspaceSize success."; |
| 68 | return ErrorType::ACL_SUCCESS; | 68 | return ErrorType::ACL_SUCCESS; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | -AspbStatus asdBlasSetWorkspace(asdBlasHandle handle, void *workSpace) | 71 | +AspbStatus asdBlasSetWorkspace(asdBlasHandle handle, void* workSpace) |
| 72 | { | 72 | { |
| 73 | std::lock_guard<std::mutex> lock(blas_mtx); | 73 | std::lock_guard<std::mutex> lock(blas_mtx); |
| 74 | - ASDSIP_ECHECK( | 74 | + ASDSIP_ECHECK(BlasPlanCache::doesPlanExist(handle), "blas plan does not exist.", |
| 75 | - BlasPlanCache::doesPlanExist(handle), "blas plan does not exist.", ErrorType::ACL_ERROR_INTERNAL_ERROR); | 75 | + ErrorType::ACL_ERROR_INTERNAL_ERROR); |
| 76 | - BlasPlan &plan = BlasPlanCache::getPlan(handle); | 76 | + BlasPlan& plan = BlasPlanCache::getPlan(handle); |
| 77 | - plan.SetWorkspace((uint8_t *)workSpace); | 77 | + plan.SetWorkspace((uint8_t*)workSpace); |
| 78 | ASDSIP_LOG(INFO) << "Blas set workspace success."; | 78 | ASDSIP_LOG(INFO) << "Blas set workspace success."; |
| 79 | return ErrorType::ACL_SUCCESS; | 79 | return ErrorType::ACL_SUCCESS; |
| 80 | } | 80 | } |
| 81 | -} // namespace AsdSip | 81 | +} // namespace AsdSip |
| @@ -13,7 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | -constexpr uint32_t MAX_LENG_PER_UB_PROC = 6144; // 单次处理的最大数据量(复数) 6.75k ( 6912 -> 对齐32个complex元素) | 16 | +constexpr uint32_t MAX_LENG_PER_UB_PROC = 6144; // 单次处理的最大数据量(复数) 6.75k ( 6912 -> 对齐32个complex元素) |
| 17 | constexpr uint32_t ELEMENTS_EACH_COMPLEX64 = 2; | 17 | constexpr uint32_t ELEMENTS_EACH_COMPLEX64 = 2; |
| 18 | constexpr uint32_t PING_PONG_NUM = 2; | 18 | constexpr uint32_t PING_PONG_NUM = 2; |
| 19 | constexpr uint32_t BLAS_SCAL_WORKSPACE_SIZE = 16 * 1024; | 19 | constexpr uint32_t BLAS_SCAL_WORKSPACE_SIZE = 16 * 1024; |
| @@ -27,10 +27,7 @@ BlasCalPlan::BlasCalPlan() : m(0), n(0), incy(1), transA('N') | |||
| 27 | maskTensor.hostData = nullptr; | 27 | maskTensor.hostData = nullptr; |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | -AsdSip::AspbStatus BlasCalPlan::CreateTensor() | 30 | +AsdSip::AspbStatus BlasCalPlan::CreateTensor() { return SetMaskTensor(); } |
| 31 | -{ | ||
| 32 | - return SetMaskTensor(); | ||
| 33 | -} | ||
| 34 | 31 | ||
| 35 | AsdSip::AspbStatus BlasCalPlan::SetMaskTensor() | 32 | AsdSip::AspbStatus BlasCalPlan::SetMaskTensor() |
| 36 | { | 33 | { |
| @@ -38,7 +35,7 @@ AsdSip::AspbStatus BlasCalPlan::SetMaskTensor() | |||
| 38 | MAX_LENG_PER_UB_PROC * sizeof(std::complex<float>) * PING_PONG_NUM; | 35 | MAX_LENG_PER_UB_PROC * sizeof(std::complex<float>) * PING_PONG_NUM; |
| 39 | uint32_t realBaseAddr = imagBaseAddr + MAX_LENG_PER_UB_PROC * sizeof(uint32_t); | 36 | uint32_t realBaseAddr = imagBaseAddr + MAX_LENG_PER_UB_PROC * sizeof(uint32_t); |
| 40 | 37 | ||
| 41 | - uint32_t *maskData = nullptr; | 38 | + uint32_t* maskData = nullptr; |
| 42 | try { | 39 | try { |
| 43 | maskData = new uint32_t[MAX_LENG_PER_UB_PROC * ELEMENTS_EACH_COMPLEX64]; | 40 | maskData = new uint32_t[MAX_LENG_PER_UB_PROC * ELEMENTS_EACH_COMPLEX64]; |
| 44 | } catch (std::bad_alloc& e) { | 41 | } catch (std::bad_alloc& e) { |
| @@ -56,14 +53,13 @@ AsdSip::AspbStatus BlasCalPlan::SetMaskTensor() | |||
| 56 | maskTensor.dataSize = MAX_LENG_PER_UB_PROC * ELEMENTS_EACH_COMPLEX64 * sizeof(uint32_t); | 53 | maskTensor.dataSize = MAX_LENG_PER_UB_PROC * ELEMENTS_EACH_COMPLEX64 * sizeof(uint32_t); |
| 57 | 54 | ||
| 58 | if (!MallocTensorInDevice(maskTensor).Ok()) { | 55 | if (!MallocTensorInDevice(maskTensor).Ok()) { |
| 59 | - ASDSIP_LOG(ERROR) << "BlasCalPlan maskTensor malloc failed: "; | 56 | + ASDSIP_LOG(ERROR) << "BlasCalPlan maskTensor malloc failed"; |
| 60 | delete[] maskData; | 57 | delete[] maskData; |
| 61 | maskData = nullptr; | 58 | maskData = nullptr; |
| 62 | maskTensor.hostData = nullptr; | 59 | maskTensor.hostData = nullptr; |
| 63 | return ErrorType::ACL_ERROR_INTERNAL_ERROR; | 60 | return ErrorType::ACL_ERROR_INTERNAL_ERROR; |
| 64 | } | 61 | } |
| 65 | toAclTensor(maskTensor, maskAclTensor); | 62 | toAclTensor(maskTensor, maskAclTensor); |
| 66 | - maskData = nullptr; | ||
| 67 | return ErrorType::ACL_SUCCESS; | 63 | return ErrorType::ACL_SUCCESS; |
| 68 | }; | 64 | }; |
| 69 | 65 | ||
| @@ -74,19 +70,13 @@ AsdSip::AspbStatus BlasCalPlan::FreeTensor() | |||
| 74 | maskTensor.data = nullptr; | 70 | maskTensor.data = nullptr; |
| 75 | } | 71 | } |
| 76 | if (maskTensor.hostData != nullptr) { | 72 | if (maskTensor.hostData != nullptr) { |
| 77 | - delete[] static_cast<uint32_t *>(maskTensor.hostData); | 73 | + delete[] static_cast<uint32_t*>(maskTensor.hostData); |
| 78 | maskTensor.hostData = nullptr; | 74 | maskTensor.hostData = nullptr; |
| 79 | } | 75 | } |
| 80 | return ErrorType::ACL_SUCCESS; | 76 | return ErrorType::ACL_SUCCESS; |
| 81 | } | 77 | } |
| 82 | 78 | ||
| 83 | -BlasCalPlan::~BlasCalPlan() | 79 | +BlasCalPlan::~BlasCalPlan() { BlasPlan::DestroyPlanData(); } |
| 84 | -{ | ||
| 85 | - BlasPlan::DestroyPlanData(); | ||
| 86 | -} | ||
| 87 | 80 | ||
| 88 | -int64_t BlasCalPlan::GetWorkspaceSize() | 81 | +int64_t BlasCalPlan::GetWorkspaceSize() { return BLAS_SCAL_WORKSPACE_SIZE; } |
| 89 | -{ | 82 | +} // namespace AsdSip |
| 90 | - return BLAS_SCAL_WORKSPACE_SIZE; | ||
| 91 | -} | ||
| 92 | -} | ||
| @@ -33,11 +33,11 @@ size_t DftR2CCore::EstimateWorkspaceSize() | |||
| 33 | ASDSIP_LOG(INFO) << "ASCEND_950 DftR2CCore workspace size."; | 33 | ASDSIP_LOG(INFO) << "ASCEND_950 DftR2CCore workspace size."; |
| 34 | return MATMUL_WORKSIZE; | 34 | return MATMUL_WORKSIZE; |
| 35 | } | 35 | } |
| 36 | - const KernelInfo &kernelInfo = kernel->GetKernelInfo(); | 36 | + const KernelInfo& kernelInfo = kernel->GetKernelInfo(); |
| 37 | return getAlignedSize(kernelInfo.GetTotalScratchSize()); | 37 | return getAlignedSize(kernelInfo.GetTotalScratchSize()); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | -void DftR2CCore::Run(void *input, void *output, void *stream, workspace::Workspace &workspace) | 40 | +void DftR2CCore::Run(void* input, void* output, void* stream, workspace::Workspace& workspace) |
| 41 | { | 41 | { |
| 42 | if (Mki::PlatformInfo::Instance().GetPlatformType() == Mki::PlatformType::ASCEND_910B) { | 42 | if (Mki::PlatformInfo::Instance().GetPlatformType() == Mki::PlatformType::ASCEND_910B) { |
| 43 | FftOperation::Run(input, output, stream, workspace); | 43 | FftOperation::Run(input, output, stream, workspace); |
| @@ -51,7 +51,7 @@ void DftR2CCore::Run(void *input, void *output, void *stream, workspace::Workspa | |||
| 51 | void DftR2CCore::DestroyInDevice() const | 51 | void DftR2CCore::DestroyInDevice() const |
| 52 | { | 52 | { |
| 53 | // destroy tiling data in device | 53 | // destroy tiling data in device |
| 54 | - uint8_t *deviceLaunchBuffer = nullptr; | 54 | + uint8_t* deviceLaunchBuffer = nullptr; |
| 55 | deviceLaunchBuffer = runInfo.GetTilingDeviceAddr(); | 55 | deviceLaunchBuffer = runInfo.GetTilingDeviceAddr(); |
| 56 | if (deviceLaunchBuffer != nullptr) { | 56 | if (deviceLaunchBuffer != nullptr) { |
| 57 | MkiRtMemFreeDevice(deviceLaunchBuffer); | 57 | MkiRtMemFreeDevice(deviceLaunchBuffer); |
| @@ -64,17 +64,17 @@ AspbStatus DftR2CCore::InitRotationMatrix() | |||
| 64 | int64_t inSize = fftN; | 64 | int64_t inSize = fftN; |
| 65 | int64_t outSize = 2 * (fftN / 2 + 1); | 65 | int64_t outSize = 2 * (fftN / 2 + 1); |
| 66 | 66 | ||
| 67 | - std::function<AsdSip::FFTensor *()> func = [=]() -> AsdSip::FFTensor* { | 67 | + std::function<AsdSip::FFTensor*()> func = [=]() -> AsdSip::FFTensor* { |
| 68 | - AsdSip::FFTensor *rotationMatrixPtr = new AsdSip::FFTensor; | 68 | + AsdSip::FFTensor* rotationMatrixPtr = new AsdSip::FFTensor; |
| 69 | - AsdSip::FFTensor &rotationMatrix_ = *rotationMatrixPtr; | 69 | + AsdSip::FFTensor& rotationMatrix_ = *rotationMatrixPtr; |
| 70 | 70 | ||
| 71 | - float *rotationMatrixHost = nullptr; | 71 | + float* rotationMatrixHost = nullptr; |
| 72 | try { | 72 | try { |
| 73 | rotationMatrixHost = new float[outSize * inSize]; | 73 | rotationMatrixHost = new float[outSize * inSize]; |
| 74 | - } catch(std::bad_alloc& e) { | 74 | + } catch (std::bad_alloc& e) { |
| 75 | delete rotationMatrixPtr; | 75 | delete rotationMatrixPtr; |
| 76 | - ASDSIP_LOG(ERROR) << "rotationMatrixHost nalloc failed: " << e.what(); | 76 | + ASDSIP_LOG(ERROR) << "rotationMatrixHost alloc failed: " << e.what(); |
| 77 | - throw std::runtime_error("rotationMatrixHost nalloc failed:."); | 77 | + throw std::runtime_error("rotationMatrixHost alloc failed:."); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | float cosTable[fftN]; | 80 | float cosTable[fftN]; |
| @@ -86,8 +86,8 @@ AspbStatus DftR2CCore::InitRotationMatrix() | |||
| 86 | for (int64_t i = 0; i < inSize; i++) { | 86 | for (int64_t i = 0; i < inSize; i++) { |
| 87 | for (int64_t j = 0; j < (fftN / 2 + 1); j++) { | 87 | for (int64_t j = 0; j < (fftN / 2 + 1); j++) { |
| 88 | *(rotationMatrixHost + i * outSize + 2 * j) = *(cosTable + (i * j) % fftN); | 88 | *(rotationMatrixHost + i * outSize + 2 * j) = *(cosTable + (i * j) % fftN); |
| 89 | - *(rotationMatrixHost + i * outSize + 2 * j + 1) = | 89 | + *(rotationMatrixHost + i * outSize + 2 * j + 1) = (problemDesc.forward ? (-1.0) : (1.0)) * |
| 90 | - (problemDesc.forward ? (-1.0) : (1.0)) * (*(sinTable + (i * j) % fftN)); | 90 | + (*(sinTable + (i * j) % fftN)); |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | 93 | ||
| @@ -133,19 +133,19 @@ AspbStatus DftR2CCore::InitTactic() | |||
| 133 | Tensor tensorIn; | 133 | Tensor tensorIn; |
| 134 | Tensor tensorOut; | 134 | Tensor tensorOut; |
| 135 | tensorIn.desc = {TENSOR_DTYPE_FLOAT, TENSOR_FORMAT_ND, {problemDesc.batch, problemDesc.nDoing}, {}, 0}; | 135 | tensorIn.desc = {TENSOR_DTYPE_FLOAT, TENSOR_FORMAT_ND, {problemDesc.batch, problemDesc.nDoing}, {}, 0}; |
| 136 | - tensorIn.dataSize = | 136 | + tensorIn.dataSize = problemDesc.batch * problemDesc.nDoing * |
| 137 | - problemDesc.batch * problemDesc.nDoing * GetTensorElementSize(AsdSip::TensorDType::TENSOR_DTYPE_FLOAT); | 137 | + GetTensorElementSize(AsdSip::TensorDType::TENSOR_DTYPE_FLOAT); |
| 138 | 138 | ||
| 139 | unsigned outputN = problemDesc.nDoing / 2 + 1; | 139 | unsigned outputN = problemDesc.nDoing / 2 + 1; |
| 140 | - tensorOut.dataSize = | 140 | + tensorOut.dataSize = problemDesc.batch * outputN * |
| 141 | - problemDesc.batch * outputN * GetTensorElementSize(AsdSip::TensorDType::TENSOR_DTYPE_COMPLEX64); | 141 | + GetTensorElementSize(AsdSip::TensorDType::TENSOR_DTYPE_COMPLEX64); |
| 142 | 142 | ||
| 143 | launchParam.SetParam(param); | 143 | launchParam.SetParam(param); |
| 144 | launchParam.AddInTensor(tensorIn); | 144 | launchParam.AddInTensor(tensorIn); |
| 145 | launchParam.AddInTensor(*rotationMatrix); | 145 | launchParam.AddInTensor(*rotationMatrix); |
| 146 | launchParam.AddOutTensor(tensorOut); | 146 | launchParam.AddOutTensor(tensorOut); |
| 147 | 147 | ||
| 148 | - Operation *op = Ops::Instance().GetOperationByName(std::string("DftR2COperation")); | 148 | + Operation* op = Ops::Instance().GetOperationByName(std::string("DftR2COperation")); |
| 149 | if (op == nullptr) { | 149 | if (op == nullptr) { |
| 150 | return AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR; | 150 | return AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR; |
| 151 | } | 151 | } |
| @@ -154,7 +154,7 @@ AspbStatus DftR2CCore::InitTactic() | |||
| 154 | ASDSIP_ECHECK(kernel != nullptr, "Get best kernel failed", AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR); | 154 | ASDSIP_ECHECK(kernel != nullptr, "Get best kernel failed", AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR); |
| 155 | 155 | ||
| 156 | // allocate and initialize tiling workspace | 156 | // allocate and initialize tiling workspace |
| 157 | - uint8_t *deviceLaunchBuffer = nullptr; | 157 | + uint8_t* deviceLaunchBuffer = nullptr; |
| 158 | kernel->SetLaunchWithTiling(false); | 158 | kernel->SetLaunchWithTiling(false); |
| 159 | uint32_t launchBufferSize = kernel->GetTilingSize(launchParam); | 159 | uint32_t launchBufferSize = kernel->GetTilingSize(launchParam); |
| 160 | if (launchBufferSize == 0) { | 160 | if (launchBufferSize == 0) { |
| @@ -171,7 +171,7 @@ AspbStatus DftR2CCore::InitTactic() | |||
| 171 | ASDSIP_LOG(ERROR) << "malloc device memory fail"; | 171 | ASDSIP_LOG(ERROR) << "malloc device memory fail"; |
| 172 | return AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR; | 172 | return AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR; |
| 173 | } | 173 | } |
| 174 | - deviceLaunchBuffer = static_cast<uint8_t *>(tempDevicePtr); | 174 | + deviceLaunchBuffer = static_cast<uint8_t*>(tempDevicePtr); |
| 175 | st = MkiRtMemCopy(deviceLaunchBuffer, launchBufferSize, hostLaunchBuffer, launchBufferSize, | 175 | st = MkiRtMemCopy(deviceLaunchBuffer, launchBufferSize, hostLaunchBuffer, launchBufferSize, |
| 176 | MKIRT_MEMCOPY_HOST_TO_DEVICE); | 176 | MKIRT_MEMCOPY_HOST_TO_DEVICE); |
| 177 | if (st != MKIRT_SUCCESS) { | 177 | if (st != MKIRT_SUCCESS) { |
| @@ -28,11 +28,11 @@ | |||
| 28 | using namespace AsdSip; | 28 | using namespace AsdSip; |
| 29 | 29 | ||
| 30 | constexpr int RADIXVEC_SIZE_THREE = 3; | 30 | constexpr int RADIXVEC_SIZE_THREE = 3; |
| 31 | -constexpr int N_DOING_24 = 16777216; // pow(2, 24) | 31 | +constexpr int N_DOING_24 = 16777216; // pow(2, 24) |
| 32 | constexpr int N_DOING_27 = 134217728; // pow(2, 27) | 32 | constexpr int N_DOING_27 = 134217728; // pow(2, 27) |
| 33 | -constexpr int N_DOING_15 = 32768; // pow(2, 15) | 33 | +constexpr int N_DOING_15 = 32768; // pow(2, 15) |
| 34 | -constexpr int N_DOING_19 = 524288; // pow(2, 19) | 34 | +constexpr int N_DOING_19 = 524288; // pow(2, 19) |
| 35 | -constexpr int N_DOING_25 = 33554432; // pow(2, 25) | 35 | +constexpr int N_DOING_25 = 33554432; // pow(2, 25) |
| 36 | constexpr int RADIX_INDEX2 = 2; | 36 | constexpr int RADIX_INDEX2 = 2; |
| 37 | constexpr int RADIX_INDEX3 = 3; | 37 | constexpr int RADIX_INDEX3 = 3; |
| 38 | constexpr int RADIX_INDEX4 = 4; | 38 | constexpr int RADIX_INDEX4 = 4; |
| @@ -60,16 +60,16 @@ constexpr int LOGN_27 = 27; | |||
| 60 | 60 | ||
| 61 | size_t FFTCoreN::EstimateWorkspaceSize() | 61 | size_t FFTCoreN::EstimateWorkspaceSize() |
| 62 | { | 62 | { |
| 63 | - const KernelInfo &kernelInfo = kernel->GetKernelInfo(); | 63 | + const KernelInfo& kernelInfo = kernel->GetKernelInfo(); |
| 64 | return getAlignedSize(kernelInfo.GetTotalScratchSize()); | 64 | return getAlignedSize(kernelInfo.GetTotalScratchSize()); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | -void FFTCoreN::Run(Tensor &input, Tensor &output, void *stream, workspace::Workspace &workspace) | 67 | +void FFTCoreN::Run(Tensor& input, Tensor& output, void* stream, workspace::Workspace& workspace) |
| 68 | { | 68 | { |
| 69 | - const KernelInfo &kernelInfo = kernel->GetKernelInfo(); | 69 | + const KernelInfo& kernelInfo = kernel->GetKernelInfo(); |
| 70 | // set workspace | 70 | // set workspace |
| 71 | size_t bufferSize = kernelInfo.GetTotalScratchSize(); | 71 | size_t bufferSize = kernelInfo.GetTotalScratchSize(); |
| 72 | - runInfo.SetScratchDeviceAddr((uint8_t *)workspace.allocate(bufferSize)); | 72 | + runInfo.SetScratchDeviceAddr((uint8_t*)workspace.allocate(bufferSize)); |
| 73 | 73 | ||
| 74 | runInfo.SetStream(stream); | 74 | runInfo.SetStream(stream); |
| 75 | launchParam.GetInTensor(0).data = input.data; | 75 | launchParam.GetInTensor(0).data = input.data; |
| @@ -119,7 +119,7 @@ void FFTCoreN::InitTilingArgs() | |||
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | float batchDataSize = float(n) * 2 * 4 / 1024 / 1024; | 121 | float batchDataSize = float(n) * 2 * 4 / 1024 / 1024; |
| 122 | - float l2CacheSize = 92; // 910B4 cache size | 122 | + float l2CacheSize = 92; // 910B4 cache size |
| 123 | repeatBatchSize = static_cast<uint32_t>(floor((l2CacheSize - 10 - CALCUL_TWO) / CALCUL_TWO / batchDataSize)); | 123 | repeatBatchSize = static_cast<uint32_t>(floor((l2CacheSize - 10 - CALCUL_TWO) / CALCUL_TWO / batchDataSize)); |
| 124 | repeatBatchSize = repeatBatchSize < 1 ? problemDesc.batch : repeatBatchSize; | 124 | repeatBatchSize = repeatBatchSize < 1 ? problemDesc.batch : repeatBatchSize; |
| 125 | } | 125 | } |
| @@ -149,7 +149,7 @@ AspbStatus FFTCoreN::InitTactic() | |||
| 149 | ssyncTilingNum.push_back(x); | 149 | ssyncTilingNum.push_back(x); |
| 150 | } | 150 | } |
| 151 | OpParam::FftN param = {problemDesc.nDoing, problemDesc.batch, repeatBatchSize, problemDesc.forward, sradixVec, | 151 | OpParam::FftN param = {problemDesc.nDoing, problemDesc.batch, repeatBatchSize, problemDesc.forward, sradixVec, |
| 152 | - saicInputAddr, saivOutputAddr, slessTCopy, ssyncTilingNum}; | 152 | + saicInputAddr, saivOutputAddr, slessTCopy, ssyncTilingNum}; |
| 153 | 153 | ||
| 154 | Tensor tensorIn; | 154 | Tensor tensorIn; |
| 155 | Tensor tensorOut; | 155 | Tensor tensorOut; |
| @@ -163,7 +163,7 @@ AspbStatus FFTCoreN::InitTactic() | |||
| 163 | launchParam.AddInTensor(*index); | 163 | launchParam.AddInTensor(*index); |
| 164 | launchParam.AddOutTensor(tensorOut); | 164 | launchParam.AddOutTensor(tensorOut); |
| 165 | 165 | ||
| 166 | - Operation *op = Ops::Instance().GetOperationByName(std::string("FftNOperation")); | 166 | + Operation* op = Ops::Instance().GetOperationByName(std::string("FftNOperation")); |
| 167 | if (op == nullptr) { | 167 | if (op == nullptr) { |
| 168 | return AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR; | 168 | return AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR; |
| 169 | } | 169 | } |
| @@ -172,7 +172,7 @@ AspbStatus FFTCoreN::InitTactic() | |||
| 172 | ASDSIP_ECHECK(kernel != nullptr, "Get best kernel failed", AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR); | 172 | ASDSIP_ECHECK(kernel != nullptr, "Get best kernel failed", AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR); |
| 173 | 173 | ||
| 174 | // allocate and initialize tiling workspace | 174 | // allocate and initialize tiling workspace |
| 175 | - uint8_t *deviceLaunchBuffer = nullptr; | 175 | + uint8_t* deviceLaunchBuffer = nullptr; |
| 176 | kernel->SetLaunchWithTiling(false); | 176 | kernel->SetLaunchWithTiling(false); |
| 177 | uint32_t launchBufferSize = kernel->GetTilingSize(launchParam); | 177 | uint32_t launchBufferSize = kernel->GetTilingSize(launchParam); |
| 178 | if (launchBufferSize == 0) { | 178 | if (launchBufferSize == 0) { |
| @@ -189,7 +189,7 @@ AspbStatus FFTCoreN::InitTactic() | |||
| 189 | ASDSIP_LOG(ERROR) << "malloc device memory fail"; | 189 | ASDSIP_LOG(ERROR) << "malloc device memory fail"; |
| 190 | return AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR; | 190 | return AsdSip::ErrorType::ACL_ERROR_INTERNAL_ERROR; |
| 191 | } | 191 | } |
| 192 | - deviceLaunchBuffer = static_cast<uint8_t *>(tempDevicePtr); | 192 | + deviceLaunchBuffer = static_cast<uint8_t*>(tempDevicePtr); |
| 193 | st = MkiRtMemCopy(deviceLaunchBuffer, launchBufferSize, hostLaunchBuffer, launchBufferSize, | 193 | st = MkiRtMemCopy(deviceLaunchBuffer, launchBufferSize, hostLaunchBuffer, launchBufferSize, |
| 194 | MKIRT_MEMCOPY_HOST_TO_DEVICE); | 194 | MKIRT_MEMCOPY_HOST_TO_DEVICE); |
| 195 | if (st != MKIRT_SUCCESS) { | 195 | if (st != MKIRT_SUCCESS) { |
| @@ -282,26 +282,26 @@ AspbStatus FFTCoreN::InitIndex() | |||
| 282 | tN = tN < N0 ? tN : N0; | 282 | tN = tN < N0 ? tN : N0; |
| 283 | int64_t tilingNum = (tM / 2) * tN; | 283 | int64_t tilingNum = (tM / 2) * tN; |
| 284 | 284 | ||
| 285 | - std::function<AsdSip::FFTensor *()> func = [=]() -> AsdSip::FFTensor* { | 285 | + std::function<AsdSip::FFTensor*()> func = [=]() -> AsdSip::FFTensor* { |
| 286 | - AsdSip::FFTensor *indexMatrixPtr = new(std::nothrow) AsdSip::FFTensor; | 286 | + AsdSip::FFTensor* indexMatrixPtr = new (std::nothrow) AsdSip::FFTensor; |
| 287 | if (indexMatrixPtr == nullptr) { | 287 | if (indexMatrixPtr == nullptr) { |
| 288 | ASDSIP_LOG(ERROR) << "indexMatrixPtr new failed"; | 288 | ASDSIP_LOG(ERROR) << "indexMatrixPtr new failed"; |
| 289 | throw std::runtime_error("indexMatrixPtr new failed"); | 289 | throw std::runtime_error("indexMatrixPtr new failed"); |
| 290 | } | 290 | } |
| 291 | - AsdSip::FFTensor &indexMatrix = *indexMatrixPtr; | 291 | + AsdSip::FFTensor& indexMatrix = *indexMatrixPtr; |
| 292 | 292 | ||
| 293 | indexMatrix.desc.dtype = TENSOR_DTYPE_INT32; | 293 | indexMatrix.desc.dtype = TENSOR_DTYPE_INT32; |
| 294 | indexMatrix.desc.format = TENSOR_FORMAT_ND; | 294 | indexMatrix.desc.format = TENSOR_FORMAT_ND; |
| 295 | indexMatrix.desc.dims = {tilingNum}; | 295 | indexMatrix.desc.dims = {tilingNum}; |
| 296 | indexMatrix.dataSize = sizeof(int32_t) * tilingNum; | 296 | indexMatrix.dataSize = sizeof(int32_t) * tilingNum; |
| 297 | 297 | ||
| 298 | - int32_t *indexMatrixHost = nullptr; | 298 | + int32_t* indexMatrixHost = nullptr; |
| 299 | try { | 299 | try { |
| 300 | - indexMatrixHost = new int32_t[tilingNum]; | 300 | + indexMatrixHost = new int32_t[tilingNum]; |
| 301 | - } catch(std::bad_alloc& e) { | 301 | + } catch (std::bad_alloc& e) { |
| 302 | delete indexMatrixPtr; | 302 | delete indexMatrixPtr; |
| 303 | - ASDSIP_LOG(ERROR) << "indexMatrixHost nalloc failed: " << e.what(); | 303 | + ASDSIP_LOG(ERROR) << "indexMatrixHost alloc failed: " << e.what(); |
| 304 | - throw std::runtime_error("indexMatrixHost nalloc failed:."); | 304 | + throw std::runtime_error("indexMatrixHost alloc failed:."); |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | for (int64_t i = 0; i < tilingNum / 2; i++) { | 307 | for (int64_t i = 0; i < tilingNum / 2; i++) { |
| @@ -355,7 +355,7 @@ bool FFTCoreN::PreAllocateInDevice() | |||
| 355 | 355 | ||
| 356 | void FFTCoreN::DestroyInDevice() const | 356 | void FFTCoreN::DestroyInDevice() const |
| 357 | { | 357 | { |
| 358 | - uint8_t *deviceBuffer = runInfo.GetTilingDeviceAddr(); | 358 | + uint8_t* deviceBuffer = runInfo.GetTilingDeviceAddr(); |
| 359 | if (deviceBuffer != nullptr) { | 359 | if (deviceBuffer != nullptr) { |
| 360 | MkiRtMemFreeDevice(deviceBuffer); | 360 | MkiRtMemFreeDevice(deviceBuffer); |
| 361 | } | 361 | } |
| @@ -8,42 +8,41 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | + | ||
| 11 | 12 | ||
| 12 | 13 | ||
| 13 | 14 | ||
| 14 | using namespace AsdSip; | 15 | using namespace AsdSip; |
| 15 | 16 | ||
| 16 | -int64_t GetTensorNum(uint64_t dimsNum, int64_t *storageDims) | 17 | +std::optional<int64_t> GetTensorNum(uint64_t dimsNum, int64_t* storageDims) |
| 17 | { | 18 | { |
| 18 | if (storageDims == nullptr) { | 19 | if (storageDims == nullptr) { |
| 19 | - return -1; | 20 | + return std::nullopt; |
| 20 | } | 21 | } |
| 21 | - int64_t elenmentNum = 1; | 22 | + int64_t elementNum = 1; |
| 22 | for (size_t i = 0; i < dimsNum; i++) { | 23 | for (size_t i = 0; i < dimsNum; i++) { |
| 23 | - elenmentNum *= storageDims[i]; | 24 | + elementNum *= storageDims[i]; |
| 24 | } | 25 | } |
| 25 | - return elenmentNum; | 26 | + return elementNum; |
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | -AsdSip::AspbStatus AsdTensorDtypeCheck(const aclTensor *tensor, const aclDataType expectedDtype) | 29 | +AsdSip::AspbStatus AsdTensorDtypeCheck(const aclTensor* tensor, const aclDataType expectedDtype) |
| 29 | { | 30 | { |
| 30 | aclDataType dataType = aclDataType::ACL_DT_UNDEFINED; | 31 | aclDataType dataType = aclDataType::ACL_DT_UNDEFINED; |
| 31 | CHECK_STATUS_WITH_ACL_RETURN(aclGetDataType(tensor, &dataType), "aclGetDataType"); | 32 | CHECK_STATUS_WITH_ACL_RETURN(aclGetDataType(tensor, &dataType), "aclGetDataType"); |
| 32 | if (dataType != expectedDtype) { | 33 | if (dataType != expectedDtype) { |
| 33 | - ASDSIP_LOG(ERROR) << "Tensor expected dtype is " << expectedDtype | 34 | + ASDSIP_LOG(ERROR) << "Tensor expected dtype is " << expectedDtype << " , but found is: " << dataType; |
| 34 | - << " , but found is: " << dataType; | ||
| 35 | return AsdSip::ErrorType::ACL_ERROR_UNSUPPORTED_DATA_TYPE; | 35 | return AsdSip::ErrorType::ACL_ERROR_UNSUPPORTED_DATA_TYPE; |
| 36 | } | 36 | } |
| 37 | return AsdSip::ErrorType::ACL_SUCCESS; | 37 | return AsdSip::ErrorType::ACL_SUCCESS; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | -AsdSip::AspbStatus AsdTensorShapeCheck(const aclTensor *tensor, const std::vector<int64_t> expectedDims) | 40 | +AsdSip::AspbStatus AsdTensorShapeCheck(const aclTensor* tensor, const std::vector<int64_t> expectedDims) |
| 41 | { | 41 | { |
| 42 | - int64_t *storageDims = nullptr; | 42 | + int64_t* storageDims = nullptr; |
| 43 | uint64_t storageDimsNum = 0; | 43 | uint64_t storageDimsNum = 0; |
| 44 | uint64_t expectedDimNum = expectedDims.size(); | 44 | uint64_t expectedDimNum = expectedDims.size(); |
| 45 | - CHECK_STATUS_WITH_ACL_RETURN(aclGetStorageShape(tensor, &storageDims, &storageDimsNum), | 45 | + CHECK_STATUS_WITH_ACL_RETURN(aclGetStorageShape(tensor, &storageDims, &storageDimsNum), "aclGetStorageShape"); |
| 46 | - "aclGetStorageShape"); | ||
| 47 | if (storageDimsNum != expectedDimNum) { | 46 | if (storageDimsNum != expectedDimNum) { |
| 48 | delete[] storageDims; | 47 | delete[] storageDims; |
| 49 | storageDims = nullptr; | 48 | storageDims = nullptr; |
| @@ -54,7 +53,7 @@ AsdSip::AspbStatus AsdTensorShapeCheck(const aclTensor *tensor, const std::vecto | |||
| 54 | for (size_t i = 0; i < expectedDimNum; i++) { | 53 | for (size_t i = 0; i < expectedDimNum; i++) { |
| 55 | if (*(storageDims + i) != expectedDims[i]) { | 54 | if (*(storageDims + i) != expectedDims[i]) { |
| 56 | ASDSIP_LOG(ERROR) << "Tensor dim [" << i << "] value is " << *(storageDims + i) | 55 | ASDSIP_LOG(ERROR) << "Tensor dim [" << i << "] value is " << *(storageDims + i) |
| 57 | - << " , wthich is not be expected"; | 56 | + << " , which is not as expected"; |
| 58 | delete[] storageDims; | 57 | delete[] storageDims; |
| 59 | storageDims = nullptr; | 58 | storageDims = nullptr; |
| 60 | return AsdSip::ErrorType::ACL_ERROR_INVALID_PARAM; | 59 | return AsdSip::ErrorType::ACL_ERROR_INVALID_PARAM; |
| @@ -66,17 +65,17 @@ AsdSip::AspbStatus AsdTensorShapeCheck(const aclTensor *tensor, const std::vecto | |||
| 66 | return AsdSip::ErrorType::ACL_SUCCESS; | 65 | return AsdSip::ErrorType::ACL_SUCCESS; |
| 67 | } | 66 | } |
| 68 | 67 | ||
| 69 | -AsdSip::AspbStatus AsdTensorNumCheck(const aclTensor *tensor, int64_t expectedNum) | 68 | +AsdSip::AspbStatus AsdTensorNumCheck(const aclTensor* tensor, int64_t expectedNum) |
| 70 | { | 69 | { |
| 71 | - int64_t *storageDims = nullptr; | 70 | + int64_t* storageDims = nullptr; |
| 72 | uint64_t storageDimsNum = 0; | 71 | uint64_t storageDimsNum = 0; |
| 73 | - CHECK_STATUS_WITH_ACL_RETURN(aclGetStorageShape(tensor, &storageDims, &storageDimsNum), | 72 | + CHECK_STATUS_WITH_ACL_RETURN(aclGetStorageShape(tensor, &storageDims, &storageDimsNum), "aclGetStorageShape"); |
| 74 | - "aclGetStorageShape"); | 73 | + std::optional<int64_t> numOpt = GetTensorNum(storageDimsNum, storageDims); |
| 75 | - int64_t num = GetTensorNum(storageDimsNum, storageDims); | 74 | + if (!numOpt.has_value() || numOpt.value() != expectedNum) { |
| 76 | - if (num != expectedNum) { | ||
| 77 | delete[] storageDims; | 75 | delete[] storageDims; |
| 78 | storageDims = nullptr; | 76 | storageDims = nullptr; |
| 79 | - ASDSIP_LOG(ERROR) << "Tensor num is " << num << " , which is not be expected."; | 77 | + ASDSIP_LOG(ERROR) << "Tensor num is " << (numOpt.has_value() ? std::to_string(numOpt.value()) : "invalid") |
| 78 | + << " , which is not as expected."; | ||
| 80 | return AsdSip::ErrorType::ACL_ERROR_INVALID_PARAM; | 79 | return AsdSip::ErrorType::ACL_ERROR_INVALID_PARAM; |
| 81 | } | 80 | } |
| 82 | delete[] storageDims; | 81 | delete[] storageDims; |
| @@ -84,20 +83,26 @@ AsdSip::AspbStatus AsdTensorNumCheck(const aclTensor *tensor, int64_t expectedNu | |||
| 84 | return AsdSip::ErrorType::ACL_SUCCESS; | 83 | return AsdSip::ErrorType::ACL_SUCCESS; |
| 85 | } | 84 | } |
| 86 | 85 | ||
| 87 | -AsdSip::AspbStatus AsdTensorInvalidShapeCheck(const aclTensor *tensor) | 86 | +AsdSip::AspbStatus AsdTensorInvalidShapeCheck(const aclTensor* tensor) |
| 88 | { | 87 | { |
| 89 | - int64_t *storageDims = nullptr; | 88 | + int64_t* storageDims = nullptr; |
| 90 | uint64_t storageDimsNum = 0; | 89 | uint64_t storageDimsNum = 0; |
| 91 | - CHECK_STATUS_WITH_ACL_RETURN(aclGetStorageShape(tensor, &storageDims, &storageDimsNum), | 90 | + CHECK_STATUS_WITH_ACL_RETURN(aclGetStorageShape(tensor, &storageDims, &storageDimsNum), "aclGetStorageShape"); |
| 92 | - "aclGetStorageShape"); | 91 | + // 防护: 0 维张量(rank=0)时 storageDims 可能为 nullptr, 直接解引用会崩溃 |
| 93 | - if (*storageDims <= 0) { | 92 | + if (storageDims == nullptr || storageDimsNum == 0) { |
| 94 | - delete[] storageDims; | 93 | + ASDSIP_LOG(ERROR) << "Tensor shape is invalid, storage dims is empty."; |
| 95 | - storageDims = nullptr; | ||
| 96 | - ASDSIP_LOG(ERROR) << "Tensor shape is invalid."; | ||
| 97 | return AsdSip::ErrorType::ACL_ERROR_INVALID_PARAM; | 94 | return AsdSip::ErrorType::ACL_ERROR_INVALID_PARAM; |
| 98 | } | 95 | } |
| 96 | + for (uint64_t i = 0; i < storageDimsNum; i++) { | ||
| 97 | + if (storageDims[i] <= 0) { | ||
| 98 | + delete[] storageDims; | ||
| 99 | + storageDims = nullptr; | ||
| 100 | + ASDSIP_LOG(ERROR) << "Tensor shape is invalid."; | ||
| 101 | + return AsdSip::ErrorType::ACL_ERROR_INVALID_PARAM; | ||
| 102 | + } | ||
| 103 | + } | ||
| 99 | 104 | ||
| 100 | delete[] storageDims; | 105 | delete[] storageDims; |
| 101 | storageDims = nullptr; | 106 | storageDims = nullptr; |
| 102 | return AsdSip::ErrorType::ACL_SUCCESS; | 107 | return AsdSip::ErrorType::ACL_SUCCESS; |
| 103 | -} | 108 | +} |
| @@ -11,43 +11,44 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | + | ||
| 14 | 15 | ||
| 15 | 16 | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | 20 | ||
| 20 | -int64_t GetTensorNum(uint64_t dimsNum, int64_t *storageDims); | 21 | +std::optional<int64_t> GetTensorNum(uint64_t dimsNum, int64_t* storageDims); |
| 21 | 22 | ||
| 22 | -AsdSip::AspbStatus AsdTensorDtypeCheck(const aclTensor *tensor, const aclDataType expectedDtype); | 23 | +AsdSip::AspbStatus AsdTensorDtypeCheck(const aclTensor* tensor, const aclDataType expectedDtype); |
| 23 | 24 | ||
| 24 | -AsdSip::AspbStatus AsdTensorShapeCheck(const aclTensor *tensor, const std::vector<int64_t> expectedDims); | 25 | +AsdSip::AspbStatus AsdTensorShapeCheck(const aclTensor* tensor, const std::vector<int64_t> expectedDims); |
| 25 | 26 | ||
| 26 | -AsdSip::AspbStatus AsdTensorNumCheck(const aclTensor *tensor, int64_t expectedNum); | 27 | +AsdSip::AspbStatus AsdTensorNumCheck(const aclTensor* tensor, int64_t expectedNum); |
| 27 | 28 | ||
| 28 | -AsdSip::AspbStatus AsdTensorInvalidShapeCheck(const aclTensor *tensor); | 29 | +AsdSip::AspbStatus AsdTensorInvalidShapeCheck(const aclTensor* tensor); |
| 29 | 30 | ||
| 30 | -#define SIP_OP_CHECK_DTYPE_NOT_MATCH(tensor, expectedDtype, ret) \ | 31 | +#define SIP_OP_CHECK_DTYPE_NOT_MATCH(tensor, expectedDtype, ret) \ |
| 31 | if (AsdTensorDtypeCheck(tensor, expectedDtype) != ErrorType::ACL_SUCCESS) { \ | 32 | if (AsdTensorDtypeCheck(tensor, expectedDtype) != ErrorType::ACL_SUCCESS) { \ |
| 32 | - ASDSIP_ELOG(ret) << #tensor << " get wrong dtype."; \ | 33 | + ASDSIP_ELOG(ret) << #tensor << " get wrong dtype."; \ |
| 33 | - return ret; \ | 34 | + return ret; \ |
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | -#define SIP_OP_CHECK_SHAPE_NOT_MATCH(tensor, expectedDims, ret) \ | 37 | +#define SIP_OP_CHECK_SHAPE_NOT_MATCH(tensor, expectedDims, ret) \ |
| 37 | if (AsdTensorShapeCheck(tensor, expectedDims) != ErrorType::ACL_SUCCESS) { \ | 38 | if (AsdTensorShapeCheck(tensor, expectedDims) != ErrorType::ACL_SUCCESS) { \ |
| 38 | - ASDSIP_ELOG(ret) << #tensor << " get wrong shape."; \ | 39 | + ASDSIP_ELOG(ret) << #tensor << " get wrong shape."; \ |
| 39 | - return ret; \ | 40 | + return ret; \ |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | -#define SIP_OP_CHECK_NUM_NOT_MATCH(tensor, expectedNum, ret) \ | 43 | +#define SIP_OP_CHECK_NUM_NOT_MATCH(tensor, expectedNum, ret) \ |
| 43 | if (AsdTensorNumCheck(tensor, expectedNum) != ErrorType::ACL_SUCCESS) { \ | 44 | if (AsdTensorNumCheck(tensor, expectedNum) != ErrorType::ACL_SUCCESS) { \ |
| 44 | - ASDSIP_ELOG(ret) << #tensor << " get wrong element num."; \ | 45 | + ASDSIP_ELOG(ret) << #tensor << " get wrong element num."; \ |
| 45 | - return ret; \ | 46 | + return ret; \ |
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | -#define SIP_OP_CHECK_INVALID_SHAPE(tensor, ret) \ | 49 | +#define SIP_OP_CHECK_INVALID_SHAPE(tensor, ret) \ |
| 49 | if (AsdTensorInvalidShapeCheck(tensor) != ErrorType::ACL_SUCCESS) { \ | 50 | if (AsdTensorInvalidShapeCheck(tensor) != ErrorType::ACL_SUCCESS) { \ |
| 50 | - ASDSIP_ELOG(ret) << #tensor << " get invalid shape."; \ | 51 | + ASDSIP_ELOG(ret) << #tensor << " get invalid shape."; \ |
| 51 | - return ret; \ | 52 | + return ret; \ |
| 52 | } | 53 | } |
| 53 | -#endif | 54 | +#endif |
| @@ -18,24 +18,21 @@ namespace wten { | |||
| 18 | template <typename T> | 18 | template <typename T> |
| 19 | class TheTensor { | 19 | class TheTensor { |
| 20 | public: | 20 | public: |
| 21 | - TheTensor(const std::vector<int64_t> &shape) | 21 | + // 禁用拷贝: data_ 为裸指针, 浅拷贝会导致析构时 double-free |
| 22 | - : shape_(shape), | 22 | + TheTensor(const TheTensor&) = delete; |
| 23 | - strides_(std::vector<int64_t>(shape.size())), | 23 | + TheTensor& operator=(const TheTensor&) = delete; |
| 24 | - size_(compute_size(shape)), | 24 | + |
| 25 | - data_(new T[size_]) | 25 | + TheTensor(const std::vector<int64_t>& shape) |
| 26 | + : shape_(shape), strides_(std::vector<int64_t>(shape.size())), size_(compute_size(shape)), data_(new T[size_]) | ||
| 26 | { | 27 | { |
| 27 | update_strides(); | 28 | update_strides(); |
| 28 | } | 29 | } |
| 29 | 30 | ||
| 30 | - TheTensor(TheTensor &&tensor) | 31 | + TheTensor(TheTensor&& tensor) |
| 31 | - : shape_(tensor.shape_), | 32 | + : shape_(tensor.shape_), strides_(tensor.strides_), size_(tensor.size_), data_(tensor.move_data()) |
| 32 | - strides_(tensor.strides_), | 33 | + {} |
| 33 | - size_(tensor.size_), | ||
| 34 | - data_(tensor.move_data()) | ||
| 35 | - { | ||
| 36 | - } | ||
| 37 | 34 | ||
| 38 | - TheTensor<T> &operator=(TheTensor<T> &&tensor) | 35 | + TheTensor<T>& operator=(TheTensor<T>&& tensor) |
| 39 | { | 36 | { |
| 40 | delete[] data_; | 37 | delete[] data_; |
| 41 | data_ = tensor.data_; | 38 | data_ = tensor.data_; |
| @@ -46,49 +43,28 @@ public: | |||
| 46 | return *this; | 43 | return *this; |
| 47 | } | 44 | } |
| 48 | 45 | ||
| 49 | - T &operator[](size_t index) const | 46 | + T& operator[](size_t index) const { return data_[index]; } |
| 50 | - { | ||
| 51 | - return data_[index]; | ||
| 52 | - } | ||
| 53 | 47 | ||
| 54 | - T *data() const | 48 | + T* data() const { return data_; } |
| 55 | - { | ||
| 56 | - return data_; | ||
| 57 | - } | ||
| 58 | 49 | ||
| 59 | - T *move_data() | 50 | + T* move_data() |
| 60 | { | 51 | { |
| 61 | - T *data = data_; | 52 | + T* data = data_; |
| 62 | data_ = nullptr; | 53 | data_ = nullptr; |
| 63 | return data; | 54 | return data; |
| 64 | } | 55 | } |
| 65 | 56 | ||
| 66 | - void free_data() | 57 | + void free_data() { delete[] move_data(); } |
| 67 | - { | ||
| 68 | - delete[] move_data(); | ||
| 69 | - } | ||
| 70 | 58 | ||
| 71 | - size_t size() const | 59 | + size_t size() const { return size_; } |
| 72 | - { | ||
| 73 | - return size_; | ||
| 74 | - } | ||
| 75 | 60 | ||
| 76 | - size_t ndim() const | 61 | + size_t ndim() const { return shape_.size(); } |
| 77 | - { | ||
| 78 | - return shape_.size(); | ||
| 79 | - } | ||
| 80 | 62 | ||
| 81 | - const std::vector<int64_t> &shape() const | 63 | + const std::vector<int64_t>& shape() const { return shape_; } |
| 82 | - { | ||
| 83 | - return shape_; | ||
| 84 | - } | ||
| 85 | 64 | ||
| 86 | - const std::vector<int64_t> &strides() const | 65 | + const std::vector<int64_t>& strides() const { return strides_; } |
| 87 | - { | ||
| 88 | - return strides_; | ||
| 89 | - } | ||
| 90 | 66 | ||
| 91 | - void reshape(const std::vector<int64_t> &shape) | 67 | + void reshape(const std::vector<int64_t>& shape) |
| 92 | { | 68 | { |
| 93 | if (size_ != compute_size(shape)) { | 69 | if (size_ != compute_size(shape)) { |
| 94 | ASDSIP_LOG(ERROR) << "Invalid shape."; | 70 | ASDSIP_LOG(ERROR) << "Invalid shape."; |
| @@ -99,18 +75,15 @@ public: | |||
| 99 | update_strides(); | 75 | update_strides(); |
| 100 | } | 76 | } |
| 101 | 77 | ||
| 102 | - ~TheTensor() | 78 | + ~TheTensor() { delete[] data_; }; |
| 103 | - { | ||
| 104 | - delete [] data_; | ||
| 105 | - }; | ||
| 106 | 79 | ||
| 107 | private: | 80 | private: |
| 108 | std::vector<int64_t> shape_; | 81 | std::vector<int64_t> shape_; |
| 109 | std::vector<int64_t> strides_; | 82 | std::vector<int64_t> strides_; |
| 110 | size_t size_; | 83 | size_t size_; |
| 111 | - T *data_; | 84 | + T* data_; |
| 112 | 85 | ||
| 113 | - size_t compute_size(const std::vector<int64_t> &shape) const | 86 | + size_t compute_size(const std::vector<int64_t>& shape) const |
| 114 | { | 87 | { |
| 115 | size_t size = 1; | 88 | size_t size = 1; |
| 116 | for (size_t dim : shape) { | 89 | for (size_t dim : shape) { |
| @@ -131,4 +104,4 @@ private: | |||
| 131 | } | 104 | } |
| 132 | }; | 105 | }; |
| 133 | 106 | ||
| 134 | -} | 107 | +} // namespace wten |
| @@ -50,8 +50,12 @@ | |||
| 50 | <td>设置应用类日志的日志级别及各模块日志级别,仅支持调试日志。</td> | 50 | <td>设置应用类日志的日志级别及各模块日志级别,仅支持调试日志。</td> |
| 51 | </tr> | 51 | </tr> |
| 52 | <tr> | 52 | <tr> |
| 53 | - <td>ASCEND_MODULE_LOG_LEVEL</td> | 53 | + <td>ASCEND_MODULE_LOG_LEVEL</td> |
| 54 | - <td>设置应用类日志的各模块日志级别,仅支持调试日志。</td> | 54 | + <td>设置应用类日志的各模块日志级别,仅支持调试日志。</td> |
| 55 | - </tr> | 55 | + </tr> |
| 56 | - </tbody> | 56 | + </tbody> |
| 57 | - </table> | 57 | + </table> |
| 58 | + | ||
| 59 | +- **环境变量长度限制:** | ||
| 60 | + | ||
| 61 | + 环境变量值的长度上限为 **12800 字节**。超长的环境变量将被忽略(不影响其它变量),并在日志中输出 WARN 级别提示。若发现设置的环境变量未生效,请检查是否超出长度限制。 | ||
| @@ -77,6 +77,20 @@ | |||
| 77 | 77 | ||
| 78 | 信号处理加速库的日志系统支持日志分级、日志输出到标准输出、日志输出到文件。 | 78 | 信号处理加速库的日志系统支持日志分级、日志输出到标准输出、日志输出到文件。 |
| 79 | 79 | ||
| 80 | +> **说明**:不同接口对同类错误场景返回的错误码可能不同。例如,对无效 handle 场景, | ||
| 81 | +> `asdBlasSetStream` 返回 `ACL_ERROR_INTERNAL_ERROR`,而 `asdFftSetStream` 返回 `ACL_ERROR_INVALID_PARAM`。 | ||
| 82 | +> 排查问题时请以各接口的日志输出为准。 | ||
| 83 | + | ||
| 84 | +## 日志文件运维参数 | ||
| 85 | + | ||
| 86 | +| 参数 | 值 | 说明 | | ||
| 87 | +|------|----|------| | ||
| 88 | +| 单个日志文件大小上限 | 20MB | 超过后自动滚动创建新文件 | | ||
| 89 | +| 日志文件保留个数 | 50 个 | 超过后删除最旧的日志文件 | | ||
| 90 | +| 磁盘剩余空间门限 | 1GB | 磁盘剩余空间低于该值时停止写入日志 | | ||
| 91 | + | ||
| 92 | +注:日志文件默认保存路径由环境变量 `ASCEND_PROCESS_LOG_PATH` 控制;环境变量值的长度上限为 12800 字节,超长的环境变量将被忽略并输出 WARN 日志。 | ||
| 93 | + | ||
| 80 | - **日志分级**: | 94 | - **日志分级**: |
| 81 | 95 | ||
| 82 | 日志的严重级别从高到低分为ERROR、WARN、INFO、DEBUG四个级别,如下表所示。日志级别由环境变量“ASCEND_GLOBAL_LOG_LEVEL”控制,默认为“INFO”。\ | 96 | 日志的严重级别从高到低分为ERROR、WARN、INFO、DEBUG四个级别,如下表所示。日志级别由环境变量“ASCEND_GLOBAL_LOG_LEVEL”控制,默认为“INFO”。\ |
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } \ | 26 | } \ |
| 27 | } while (0) | 27 | } while (0) |
| 28 | 28 | ||
| @@ -38,7 +38,7 @@ using namespace AsdSip; | |||
| 38 | printf(message, ##__VA_ARGS__); \ | 38 | printf(message, ##__VA_ARGS__); \ |
| 39 | } while (0) | 39 | } while (0) |
| 40 | 40 | ||
| 41 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 41 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 42 | { | 42 | { |
| 43 | int64_t shapeSize = 1; | 43 | int64_t shapeSize = 1; |
| 44 | for (auto i : shape) { | 44 | for (auto i : shape) { |
| @@ -47,7 +47,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 47 | return shapeSize; | 47 | return shapeSize; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | -int Init(int32_t deviceId, aclrtStream *stream) | 50 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 51 | { | 51 | { |
| 52 | // 固定写法,acl初始化 | 52 | // 固定写法,acl初始化 |
| 53 | auto ret = aclInit(nullptr); | 53 | auto ret = aclInit(nullptr); |
| @@ -60,8 +60,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | template <typename T> | 62 | template <typename T> |
| 63 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 63 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 64 | - aclDataType dataType, aclTensor **tensor) | 64 | + aclDataType dataType, aclTensor** tensor) |
| 65 | { | 65 | { |
| 66 | auto size = GetShapeSize(shape) * sizeof(T); | 66 | auto size = GetShapeSize(shape) * sizeof(T); |
| 67 | // 调用aclrtMalloc申请device侧内存 | 67 | // 调用aclrtMalloc申请device侧内存 |
| @@ -78,19 +78,12 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | // 调用aclCreateTensor接口创建aclTensor | 80 | // 调用aclCreateTensor接口创建aclTensor |
| 81 | - *tensor = aclCreateTensor(shape.data(), | 81 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 82 | - shape.size(), | 82 | + shape.data(), shape.size(), *deviceAddr); |
| 83 | - dataType, | ||
| 84 | - strides.data(), | ||
| 85 | - 0, | ||
| 86 | - aclFormat::ACL_FORMAT_ND, | ||
| 87 | - shape.data(), | ||
| 88 | - shape.size(), | ||
| 89 | - *deviceAddr); | ||
| 90 | return 0; | 83 | return 0; |
| 91 | } | 84 | } |
| 92 | 85 | ||
| 93 | -void printTensor(const std::complex<op::fp16_t> *tensorData, int64_t nums) | 86 | +void printTensor(const std::complex<op::fp16_t>* tensorData, int64_t nums) |
| 94 | { | 87 | { |
| 95 | for (int64_t i = 0; i < nums; i++) { | 88 | for (int64_t i = 0; i < nums; i++) { |
| 96 | std::cout << "(" << (float)tensorData[i].real() << "," << (float)tensorData[i].imag() << ")" << " "; | 89 | std::cout << "(" << (float)tensorData[i].real() << "," << (float)tensorData[i].imag() << ")" << " "; |
| @@ -98,7 +91,7 @@ void printTensor(const std::complex<op::fp16_t> *tensorData, int64_t nums) | |||
| 98 | std::cout << std::endl; | 91 | std::cout << std::endl; |
| 99 | } | 92 | } |
| 100 | 93 | ||
| 101 | -int main(int argc, char **argv) | 94 | +int main(int argc, char** argv) |
| 102 | { | 95 | { |
| 103 | int deviceId = 0; | 96 | int deviceId = 0; |
| 104 | 97 | ||
| @@ -119,8 +112,7 @@ int main(int argc, char **argv) | |||
| 119 | for (int64_t i = 0; i < vecSize; i++) { | 112 | for (int64_t i = 0; i < vecSize; i++) { |
| 120 | tensorInYData.push_back({(op::fp16_t)(22.0f + i), (op::fp16_t)(33.0f * (i + 1))}); | 113 | tensorInYData.push_back({(op::fp16_t)(22.0f + i), (op::fp16_t)(33.0f * (i + 1))}); |
| 121 | } | 114 | } |
| 122 | - std::vector<std::complex<op::fp16_t>> tensorOutZData( | 115 | + std::vector<std::complex<op::fp16_t>> tensorOutZData(vecSize, {(op::fp16_t)0.0f, (op::fp16_t)0.0f}); |
| 123 | - vecSize, {(op::fp16_t)0.0f, (op::fp16_t)0.0f}); | ||
| 124 | 116 | ||
| 125 | std::cout << "------- input X -------" << std::endl; | 117 | std::cout << "------- input X -------" << std::endl; |
| 126 | printTensor(tensorInXData.data(), vecSize); | 118 | printTensor(tensorInXData.data(), vecSize); |
| @@ -131,12 +123,12 @@ int main(int argc, char **argv) | |||
| 131 | std::vector<int64_t> yShape = {vecSize}; | 123 | std::vector<int64_t> yShape = {vecSize}; |
| 132 | std::vector<int64_t> zShape = {vecSize}; | 124 | std::vector<int64_t> zShape = {vecSize}; |
| 133 | 125 | ||
| 134 | - aclTensor *inputX = nullptr; | 126 | + aclTensor* inputX = nullptr; |
| 135 | - aclTensor *inputY = nullptr; | 127 | + aclTensor* inputY = nullptr; |
| 136 | - aclTensor *outputZ = nullptr; | 128 | + aclTensor* outputZ = nullptr; |
| 137 | - void *inputXDeviceAddr = nullptr; | 129 | + void* inputXDeviceAddr = nullptr; |
| 138 | - void *inputYDeviceAddr = nullptr; | 130 | + void* inputYDeviceAddr = nullptr; |
| 139 | - void *outputZDeviceAddr = nullptr; | 131 | + void* outputZDeviceAddr = nullptr; |
| 140 | ret = CreateAclTensor(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_COMPLEX32, &inputX); | 132 | ret = CreateAclTensor(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_COMPLEX32, &inputX); |
| 141 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 133 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 142 | ret = CreateAclTensor(tensorInYData, yShape, &inputYDeviceAddr, aclDataType::ACL_COMPLEX32, &inputY); | 134 | ret = CreateAclTensor(tensorInYData, yShape, &inputYDeviceAddr, aclDataType::ACL_COMPLEX32, &inputY); |
| @@ -149,11 +141,8 @@ int main(int argc, char **argv) | |||
| 149 | ret = aclrtSynchronizeStream(stream); | 141 | ret = aclrtSynchronizeStream(stream); |
| 150 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | 142 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); |
| 151 | 143 | ||
| 152 | - ret = aclrtMemcpy(tensorOutZData.data(), | 144 | + ret = aclrtMemcpy(tensorOutZData.data(), vecSize * sizeof(std::complex<op::fp16_t>), outputZDeviceAddr, |
| 153 | - vecSize * sizeof(std::complex<op::fp16_t>), | 145 | + vecSize * sizeof(std::complex<op::fp16_t>), ACL_MEMCPY_DEVICE_TO_HOST); |
| 154 | - outputZDeviceAddr, | ||
| 155 | - vecSize * sizeof(std::complex<op::fp16_t>), | ||
| 156 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 157 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy z from device to host failed. ERROR: %d\n", ret); return ret); | 146 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy z from device to host failed. ERROR: %d\n", ret); return ret); |
| 158 | std::cout << "------- output Z -------" << std::endl; | 147 | std::cout << "------- output Z -------" << std::endl; |
| 159 | 148 | ||
| @@ -170,4 +159,4 @@ int main(int argc, char **argv) | |||
| 170 | aclrtResetDevice(deviceId); | 159 | aclrtResetDevice(deviceId); |
| 171 | aclFinalize(); | 160 | aclFinalize(); |
| 172 | return 0; | 161 | return 0; |
| 173 | -} | 162 | +} |
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } \ | 26 | } \ |
| 27 | } while (0) | 27 | } while (0) |
| 28 | 28 | ||
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -23,7 +23,7 @@ using namespace AsdSip; | |||
| 23 | AsdSip::AspbStatus err_ = (err); \ | 23 | AsdSip::AspbStatus err_ = (err); \ |
| 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 25 | std::cout << "Execute failed." << std::endl; \ | 25 | std::cout << "Execute failed." << std::endl; \ |
| 26 | - exit(-1); \ | 26 | + return -1; \ |
| 27 | } \ | 27 | } \ |
| 28 | } while (0) | 28 | } while (0) |
| 29 | 29 | ||
| @@ -39,7 +39,7 @@ using namespace AsdSip; | |||
| 39 | printf(message, ##__VA_ARGS__); \ | 39 | printf(message, ##__VA_ARGS__); \ |
| 40 | } while (0) | 40 | } while (0) |
| 41 | 41 | ||
| 42 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 42 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 43 | { | 43 | { |
| 44 | int64_t shapeSize = 1; | 44 | int64_t shapeSize = 1; |
| 45 | for (auto i : shape) { | 45 | for (auto i : shape) { |
| @@ -48,7 +48,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 48 | return shapeSize; | 48 | return shapeSize; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | -int Init(int32_t deviceId, aclrtStream *stream) | 51 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 52 | { | 52 | { |
| 53 | // 固定写法,acl初始化 | 53 | // 固定写法,acl初始化 |
| 54 | auto ret = aclInit(nullptr); | 54 | auto ret = aclInit(nullptr); |
| @@ -61,8 +61,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | template <typename T> | 63 | template <typename T> |
| 64 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 64 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 65 | - aclDataType dataType, aclTensor **tensor) | 65 | + aclDataType dataType, aclTensor** tensor) |
| 66 | { | 66 | { |
| 67 | auto size = GetShapeSize(shape) * sizeof(T); | 67 | auto size = GetShapeSize(shape) * sizeof(T); |
| 68 | // 调用aclrtMalloc申请device侧内存 | 68 | // 调用aclrtMalloc申请device侧内存 |
| @@ -79,19 +79,12 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | // 调用aclCreateTensor接口创建aclTensor | 81 | // 调用aclCreateTensor接口创建aclTensor |
| 82 | - *tensor = aclCreateTensor(shape.data(), | 82 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 83 | - shape.size(), | 83 | + shape.data(), shape.size(), *deviceAddr); |
| 84 | - dataType, | ||
| 85 | - strides.data(), | ||
| 86 | - 0, | ||
| 87 | - aclFormat::ACL_FORMAT_ND, | ||
| 88 | - shape.data(), | ||
| 89 | - shape.size(), | ||
| 90 | - *deviceAddr); | ||
| 91 | return 0; | 84 | return 0; |
| 92 | } | 85 | } |
| 93 | 86 | ||
| 94 | -int main(int argc, char **argv) | 87 | +int main(int argc, char** argv) |
| 95 | { | 88 | { |
| 96 | int deviceId = 0; | 89 | int deviceId = 0; |
| 97 | 90 | ||
| @@ -127,10 +120,10 @@ int main(int argc, char **argv) | |||
| 127 | std::vector<int64_t> xShape = {xSize}; | 120 | std::vector<int64_t> xShape = {xSize}; |
| 128 | std::vector<int64_t> yShape = {ySize}; | 121 | std::vector<int64_t> yShape = {ySize}; |
| 129 | 122 | ||
| 130 | - aclTensor *inputX = nullptr; | 123 | + aclTensor* inputX = nullptr; |
| 131 | - aclTensor *inputY = nullptr; | 124 | + aclTensor* inputY = nullptr; |
| 132 | - void *inputXDeviceAddr = nullptr; | 125 | + void* inputXDeviceAddr = nullptr; |
| 133 | - void *inputYDeviceAddr = nullptr; | 126 | + void* inputYDeviceAddr = nullptr; |
| 134 | 127 | ||
| 135 | ret = CreateAclTensor<float>(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_FLOAT, &inputX); | 128 | ret = CreateAclTensor<float>(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_FLOAT, &inputX); |
| 136 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 129 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| @@ -142,7 +135,7 @@ int main(int argc, char **argv) | |||
| 142 | asdBlasCreate(handle); | 135 | asdBlasCreate(handle); |
| 143 | 136 | ||
| 144 | size_t lwork = 0; | 137 | size_t lwork = 0; |
| 145 | - void *buffer = nullptr; | 138 | + void* buffer = nullptr; |
| 146 | asdBlasMakeAsumPlan(handle); | 139 | asdBlasMakeAsumPlan(handle); |
| 147 | asdBlasGetWorkspaceSize(handle, lwork); | 140 | asdBlasGetWorkspaceSize(handle, lwork); |
| 148 | std::cout << "lwork = " << lwork << std::endl; | 141 | std::cout << "lwork = " << lwork << std::endl; |
| @@ -157,12 +150,9 @@ int main(int argc, char **argv) | |||
| 157 | 150 | ||
| 158 | asdBlasSynchronize(handle); | 151 | asdBlasSynchronize(handle); |
| 159 | asdBlasDestroy(handle); | 152 | asdBlasDestroy(handle); |
| 160 | - | 153 | + |
| 161 | - ret = aclrtMemcpy(tensorInYData.data(), | 154 | + ret = aclrtMemcpy(tensorInYData.data(), ySize * sizeof(float), inputYDeviceAddr, ySize * sizeof(float), |
| 162 | - ySize * sizeof(float), | 155 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 163 | - inputYDeviceAddr, | ||
| 164 | - ySize * sizeof(float), | ||
| 165 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 166 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 156 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 167 | 157 | ||
| 168 | std::cout << "------- result -------" << std::endl; | 158 | std::cout << "------- result -------" << std::endl; |
| @@ -178,4 +168,4 @@ int main(int argc, char **argv) | |||
| 178 | aclrtResetDevice(deviceId); | 168 | aclrtResetDevice(deviceId); |
| 179 | aclFinalize(); | 169 | aclFinalize(); |
| 180 | return 0; | 170 | return 0; |
| 181 | -} | 171 | +} |
| @@ -23,7 +23,7 @@ using namespace AsdSip; | |||
| 23 | AsdSip::AspbStatus err_ = (err); \ | 23 | AsdSip::AspbStatus err_ = (err); \ |
| 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 25 | std::cout << "Execute failed." << std::endl; \ | 25 | std::cout << "Execute failed." << std::endl; \ |
| 26 | - exit(-1); \ | 26 | + return -1; \ |
| 27 | } \ | 27 | } \ |
| 28 | } while (0) | 28 | } while (0) |
| 29 | 29 | ||
| @@ -39,7 +39,7 @@ using namespace AsdSip; | |||
| 39 | printf(message, ##__VA_ARGS__); \ | 39 | printf(message, ##__VA_ARGS__); \ |
| 40 | } while (0) | 40 | } while (0) |
| 41 | 41 | ||
| 42 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 42 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 43 | { | 43 | { |
| 44 | int64_t shapeSize = 1; | 44 | int64_t shapeSize = 1; |
| 45 | for (auto i : shape) { | 45 | for (auto i : shape) { |
| @@ -48,7 +48,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 48 | return shapeSize; | 48 | return shapeSize; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | -int Init(int32_t deviceId, aclrtStream *stream) | 51 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 52 | { | 52 | { |
| 53 | // 固定写法,acl初始化 | 53 | // 固定写法,acl初始化 |
| 54 | auto ret = aclInit(nullptr); | 54 | auto ret = aclInit(nullptr); |
| @@ -61,8 +61,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | template <typename T> | 63 | template <typename T> |
| 64 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 64 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 65 | - aclDataType dataType, aclTensor **tensor) | 65 | + aclDataType dataType, aclTensor** tensor) |
| 66 | { | 66 | { |
| 67 | auto size = GetShapeSize(shape) * sizeof(T); | 67 | auto size = GetShapeSize(shape) * sizeof(T); |
| 68 | // 调用aclrtMalloc申请device侧内存 | 68 | // 调用aclrtMalloc申请device侧内存 |
| @@ -79,19 +79,12 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | // 调用aclCreateTensor接口创建aclTensor | 81 | // 调用aclCreateTensor接口创建aclTensor |
| 82 | - *tensor = aclCreateTensor(shape.data(), | 82 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 83 | - shape.size(), | 83 | + shape.data(), shape.size(), *deviceAddr); |
| 84 | - dataType, | ||
| 85 | - strides.data(), | ||
| 86 | - 0, | ||
| 87 | - aclFormat::ACL_FORMAT_ND, | ||
| 88 | - shape.data(), | ||
| 89 | - shape.size(), | ||
| 90 | - *deviceAddr); | ||
| 91 | return 0; | 84 | return 0; |
| 92 | } | 85 | } |
| 93 | 86 | ||
| 94 | -int main(int argc, char **argv) | 87 | +int main(int argc, char** argv) |
| 95 | { | 88 | { |
| 96 | int deviceId = 0; | 89 | int deviceId = 0; |
| 97 | 90 | ||
| @@ -127,10 +120,10 @@ int main(int argc, char **argv) | |||
| 127 | std::vector<int64_t> xShape = {xSize}; | 120 | std::vector<int64_t> xShape = {xSize}; |
| 128 | std::vector<int64_t> yShape = {ySize}; | 121 | std::vector<int64_t> yShape = {ySize}; |
| 129 | 122 | ||
| 130 | - aclTensor *inputX = nullptr; | 123 | + aclTensor* inputX = nullptr; |
| 131 | - aclTensor *inputY = nullptr; | 124 | + aclTensor* inputY = nullptr; |
| 132 | - void *inputXDeviceAddr = nullptr; | 125 | + void* inputXDeviceAddr = nullptr; |
| 133 | - void *inputYDeviceAddr = nullptr; | 126 | + void* inputYDeviceAddr = nullptr; |
| 134 | 127 | ||
| 135 | ret = CreateAclTensor(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_COMPLEX64, &inputX); | 128 | ret = CreateAclTensor(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_COMPLEX64, &inputX); |
| 136 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 129 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| @@ -142,7 +135,7 @@ int main(int argc, char **argv) | |||
| 142 | asdBlasCreate(handle); | 135 | asdBlasCreate(handle); |
| 143 | 136 | ||
| 144 | size_t lwork = 0; | 137 | size_t lwork = 0; |
| 145 | - void *buffer = nullptr; | 138 | + void* buffer = nullptr; |
| 146 | asdBlasMakeAsumPlan(handle); | 139 | asdBlasMakeAsumPlan(handle); |
| 147 | asdBlasGetWorkspaceSize(handle, lwork); | 140 | asdBlasGetWorkspaceSize(handle, lwork); |
| 148 | std::cout << "lwork = " << lwork << std::endl; | 141 | std::cout << "lwork = " << lwork << std::endl; |
| @@ -158,11 +151,8 @@ int main(int argc, char **argv) | |||
| 158 | asdBlasSynchronize(handle); | 151 | asdBlasSynchronize(handle); |
| 159 | asdBlasDestroy(handle); | 152 | asdBlasDestroy(handle); |
| 160 | 153 | ||
| 161 | - ret = aclrtMemcpy(tensorInYData.data(), | 154 | + ret = aclrtMemcpy(tensorInYData.data(), ySize * sizeof(float), inputYDeviceAddr, ySize * sizeof(float), |
| 162 | - ySize * sizeof(float), | 155 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 163 | - inputYDeviceAddr, | ||
| 164 | - ySize * sizeof(float), | ||
| 165 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 166 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 156 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 167 | 157 | ||
| 168 | std::cout << "------- result -------" << std::endl; | 158 | std::cout << "------- result -------" << std::endl; |
| @@ -178,4 +168,4 @@ int main(int argc, char **argv) | |||
| 178 | aclrtResetDevice(deviceId); | 168 | aclrtResetDevice(deviceId); |
| 179 | aclFinalize(); | 169 | aclFinalize(); |
| 180 | return 0; | 170 | return 0; |
| 181 | -} | 171 | +} |
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } else { \ | 26 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 27 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 28 | } \ |
| @@ -24,7 +24,7 @@ using namespace AsdSip; | |||
| 24 | AsdSip::AspbStatus err_ = (err); \ | 24 | AsdSip::AspbStatus err_ = (err); \ |
| 25 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 25 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 26 | std::cout << "Execute failed." << std::endl; \ | 26 | std::cout << "Execute failed." << std::endl; \ |
| 27 | - exit(-1); \ | 27 | + return -1; \ |
| 28 | } else { \ | 28 | } else { \ |
| 29 | std::cout << "Execute successfully." << std::endl; \ | 29 | std::cout << "Execute successfully." << std::endl; \ |
| 30 | } \ | 30 | } \ |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -20,7 +20,7 @@ using namespace AsdSip; | |||
| 20 | AsdSip::AspbStatus err_ = (err); \ | 20 | AsdSip::AspbStatus err_ = (err); \ |
| 21 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 21 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 22 | std::cout << "Execute failed." << std::endl; \ | 22 | std::cout << "Execute failed." << std::endl; \ |
| 23 | - exit(-1); \ | 23 | + return -1; \ |
| 24 | } \ | 24 | } \ |
| 25 | } while (0) | 25 | } while (0) |
| 26 | 26 | ||
| @@ -36,7 +36,7 @@ using namespace AsdSip; | |||
| 36 | printf(message, ##__VA_ARGS__); \ | 36 | printf(message, ##__VA_ARGS__); \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,acl初始化 | 50 | // 固定写法,acl初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,15 +76,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| @@ -96,9 +89,8 @@ void printTensor(std::vector<std::complex<float>> tensorData, int64_t tensorSize | |||
| 96 | std::cout << std::endl; | 89 | std::cout << std::endl; |
| 97 | } | 90 | } |
| 98 | 91 | ||
| 99 | -int main(int argc, char **argv) | 92 | +int main(int argc, char** argv) |
| 100 | { | 93 | { |
| 101 | - | ||
| 102 | int deviceId = 0; | 94 | int deviceId = 0; |
| 103 | 95 | ||
| 104 | aclrtStream stream; | 96 | aclrtStream stream; |
| @@ -129,24 +121,24 @@ int main(int argc, char **argv) | |||
| 129 | std::vector<int64_t> vecShape = {vecSize}; | 121 | std::vector<int64_t> vecShape = {vecSize}; |
| 130 | std::vector<int64_t> resultShape = {resultSize}; | 122 | std::vector<int64_t> resultShape = {resultSize}; |
| 131 | 123 | ||
| 132 | - aclTensor *inVec = nullptr; | 124 | + aclTensor* inVec = nullptr; |
| 133 | - aclTensor *outResult = nullptr; | 125 | + aclTensor* outResult = nullptr; |
| 134 | - void *inpVecDeviceAddr = nullptr; | 126 | + void* inpVecDeviceAddr = nullptr; |
| 135 | - void *outResultDeviceAddr = nullptr; | 127 | + void* outResultDeviceAddr = nullptr; |
| 136 | 128 | ||
| 137 | - ret = CreateAclTensor<std::complex<float>>( | 129 | + ret = CreateAclTensor<std::complex<float>>(tensorInVecData, vecShape, &inpVecDeviceAddr, aclDataType::ACL_COMPLEX64, |
| 138 | - tensorInVecData, vecShape, &inpVecDeviceAddr, aclDataType::ACL_COMPLEX64, &inVec); | 130 | + &inVec); |
| 139 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 131 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 140 | 132 | ||
| 141 | - ret = CreateAclTensor<std::complex<float>>( | 133 | + ret = CreateAclTensor<std::complex<float>>(tensorResultData, resultShape, &outResultDeviceAddr, |
| 142 | - tensorResultData, resultShape, &outResultDeviceAddr, aclDataType::ACL_COMPLEX64, &outResult); | 134 | + aclDataType::ACL_COMPLEX64, &outResult); |
| 143 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 135 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 144 | 136 | ||
| 145 | asdBlasHandle handle; | 137 | asdBlasHandle handle; |
| 146 | asdBlasCreate(handle); | 138 | asdBlasCreate(handle); |
| 147 | 139 | ||
| 148 | size_t lwork = 0; | 140 | size_t lwork = 0; |
| 149 | - void *buffer = nullptr; | 141 | + void* buffer = nullptr; |
| 150 | asdBlasMakeCaxpyPlan(handle); | 142 | asdBlasMakeCaxpyPlan(handle); |
| 151 | asdBlasGetWorkspaceSize(handle, lwork); | 143 | asdBlasGetWorkspaceSize(handle, lwork); |
| 152 | std::cout << "lwork = " << lwork << std::endl; | 144 | std::cout << "lwork = " << lwork << std::endl; |
| @@ -162,11 +154,8 @@ int main(int argc, char **argv) | |||
| 162 | asdBlasSynchronize(handle); | 154 | asdBlasSynchronize(handle); |
| 163 | asdBlasDestroy(handle); | 155 | asdBlasDestroy(handle); |
| 164 | 156 | ||
| 165 | - ret = aclrtMemcpy(tensorResultData.data(), | 157 | + ret = aclrtMemcpy(tensorResultData.data(), resultSize * sizeof(std::complex<float>), outResultDeviceAddr, |
| 166 | - resultSize * sizeof(std::complex<float>), | 158 | + resultSize * sizeof(std::complex<float>), ACL_MEMCPY_DEVICE_TO_HOST); |
| 167 | - outResultDeviceAddr, | ||
| 168 | - resultSize * sizeof(std::complex<float>), | ||
| 169 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 170 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 159 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 171 | 160 | ||
| 172 | std::cout << "------- result -------" << std::endl; | 161 | std::cout << "------- result -------" << std::endl; |
| @@ -181,4 +170,4 @@ int main(int argc, char **argv) | |||
| 181 | aclrtResetDevice(deviceId); | 170 | aclrtResetDevice(deviceId); |
| 182 | aclFinalize(); | 171 | aclFinalize(); |
| 183 | return 0; | 172 | return 0; |
| 184 | -} | 173 | +} |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } else { \ | 25 | } else { \ |
| 26 | std::cout << "Execute successfully." << std::endl; \ | 26 | std::cout << "Execute successfully." << std::endl; \ |
| 27 | } \ | 27 | } \ |
| @@ -39,7 +39,7 @@ using namespace AsdSip; | |||
| 39 | printf(message, ##__VA_ARGS__); \ | 39 | printf(message, ##__VA_ARGS__); \ |
| 40 | } while (0) | 40 | } while (0) |
| 41 | 41 | ||
| 42 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 42 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 43 | { | 43 | { |
| 44 | int64_t shapeSize = 1; | 44 | int64_t shapeSize = 1; |
| 45 | for (auto i : shape) { | 45 | for (auto i : shape) { |
| @@ -48,7 +48,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 48 | return shapeSize; | 48 | return shapeSize; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | -int Init(int32_t deviceId, aclrtStream *stream) | 51 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 52 | { | 52 | { |
| 53 | // 固定写法,acl初始化 | 53 | // 固定写法,acl初始化 |
| 54 | auto ret = aclInit(nullptr); | 54 | auto ret = aclInit(nullptr); |
| @@ -61,8 +61,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | template <typename T> | 63 | template <typename T> |
| 64 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 64 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 65 | - aclDataType dataType, aclTensor **tensor) | 65 | + aclDataType dataType, aclTensor** tensor) |
| 66 | { | 66 | { |
| 67 | auto size = GetShapeSize(shape) * sizeof(T); | 67 | auto size = GetShapeSize(shape) * sizeof(T); |
| 68 | // 调用aclrtMalloc申请device侧内存 | 68 | // 调用aclrtMalloc申请device侧内存 |
| @@ -79,15 +79,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | // 调用aclCreateTensor接口创建aclTensor | 81 | // 调用aclCreateTensor接口创建aclTensor |
| 82 | - *tensor = aclCreateTensor(shape.data(), | 82 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 83 | - shape.size(), | 83 | + shape.data(), shape.size(), *deviceAddr); |
| 84 | - dataType, | ||
| 85 | - strides.data(), | ||
| 86 | - 0, | ||
| 87 | - aclFormat::ACL_FORMAT_ND, | ||
| 88 | - shape.data(), | ||
| 89 | - shape.size(), | ||
| 90 | - *deviceAddr); | ||
| 91 | return 0; | 84 | return 0; |
| 92 | } | 85 | } |
| 93 | 86 | ||
| @@ -101,7 +94,7 @@ void printTensor(std::vector<std::complex<float>> tensorData, int64_t rows, int6 | |||
| 101 | } | 94 | } |
| 102 | } | 95 | } |
| 103 | 96 | ||
| 104 | -int main(int argc, char **argv) | 97 | +int main(int argc, char** argv) |
| 105 | { | 98 | { |
| 106 | int deviceId = 0; | 99 | int deviceId = 0; |
| 107 | 100 | ||
| @@ -147,23 +140,23 @@ int main(int argc, char **argv) | |||
| 147 | std::vector<int64_t> matBShape = {k, n}; | 140 | std::vector<int64_t> matBShape = {k, n}; |
| 148 | std::vector<int64_t> matCShape = {m, n}; | 141 | std::vector<int64_t> matCShape = {m, n}; |
| 149 | 142 | ||
| 150 | - aclTensor *matA = nullptr; | 143 | + aclTensor* matA = nullptr; |
| 151 | - aclTensor *matB = nullptr; | 144 | + aclTensor* matB = nullptr; |
| 152 | - aclTensor *matC = nullptr; | 145 | + aclTensor* matC = nullptr; |
| 153 | - void *matADeviceAddr = nullptr; | 146 | + void* matADeviceAddr = nullptr; |
| 154 | - void *matBDeviceAddr = nullptr; | 147 | + void* matBDeviceAddr = nullptr; |
| 155 | - void *matCDeviceAddr = nullptr; | 148 | + void* matCDeviceAddr = nullptr; |
| 156 | 149 | ||
| 157 | - ret = CreateAclTensor<std::complex<float>>( | 150 | + ret = CreateAclTensor<std::complex<float>>(tensorInAData, matAShape, &matADeviceAddr, aclDataType::ACL_COMPLEX64, |
| 158 | - tensorInAData, matAShape, &matADeviceAddr, aclDataType::ACL_COMPLEX64, &matA); | 151 | + &matA); |
| 159 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 152 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 160 | 153 | ||
| 161 | - ret = CreateAclTensor<std::complex<float>>( | 154 | + ret = CreateAclTensor<std::complex<float>>(tensorInBData, matBShape, &matBDeviceAddr, aclDataType::ACL_COMPLEX64, |
| 162 | - tensorInBData, matBShape, &matBDeviceAddr, aclDataType::ACL_COMPLEX64, &matB); | 155 | + &matB); |
| 163 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 156 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 164 | 157 | ||
| 165 | - ret = CreateAclTensor<std::complex<float>>( | 158 | + ret = CreateAclTensor<std::complex<float>>(tensorInCData, matCShape, &matCDeviceAddr, aclDataType::ACL_COMPLEX64, |
| 166 | - tensorInCData, matCShape, &matCDeviceAddr, aclDataType::ACL_COMPLEX64, &matC); | 159 | + &matC); |
| 167 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 160 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 168 | 161 | ||
| 169 | std::cout << "alpha = " << alpha << std::endl; | 162 | std::cout << "alpha = " << alpha << std::endl; |
| @@ -177,7 +170,7 @@ int main(int argc, char **argv) | |||
| 177 | asdBlasCreate(handle); | 170 | asdBlasCreate(handle); |
| 178 | 171 | ||
| 179 | size_t lwork = 0; | 172 | size_t lwork = 0; |
| 180 | - void *buffer = nullptr; | 173 | + void* buffer = nullptr; |
| 181 | asdBlasMakeCgemmPlan(handle, transA, transB, m, n, k, lda, ldb, ldc); | 174 | asdBlasMakeCgemmPlan(handle, transA, transB, m, n, k, lda, ldb, ldc); |
| 182 | asdBlasGetWorkspaceSize(handle, lwork); | 175 | asdBlasGetWorkspaceSize(handle, lwork); |
| 183 | std::cout << "lwork = " << lwork << std::endl; | 176 | std::cout << "lwork = " << lwork << std::endl; |
| @@ -193,11 +186,8 @@ int main(int argc, char **argv) | |||
| 193 | asdBlasSynchronize(handle); | 186 | asdBlasSynchronize(handle); |
| 194 | asdBlasDestroy(handle); | 187 | asdBlasDestroy(handle); |
| 195 | 188 | ||
| 196 | - ret = aclrtMemcpy(tensorInCData.data(), | 189 | + ret = aclrtMemcpy(tensorInCData.data(), tensorCSize * sizeof(std::complex<float>), matCDeviceAddr, |
| 197 | - tensorCSize * sizeof(std::complex<float>), | 190 | + tensorCSize * sizeof(std::complex<float>), ACL_MEMCPY_DEVICE_TO_HOST); |
| 198 | - matCDeviceAddr, | ||
| 199 | - tensorCSize * sizeof(std::complex<float>), | ||
| 200 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 201 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 191 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 202 | 192 | ||
| 203 | std::cout << "------- output TensorInC -------" << std::endl; | 193 | std::cout << "------- output TensorInC -------" << std::endl; |
| @@ -214,4 +204,4 @@ int main(int argc, char **argv) | |||
| 214 | aclrtResetDevice(deviceId); | 204 | aclrtResetDevice(deviceId); |
| 215 | aclFinalize(); | 205 | aclFinalize(); |
| 216 | return 0; | 206 | return 0; |
| 217 | -} | 207 | +} |
| @@ -14,7 +14,6 @@ | |||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | - | ||
| 18 | using namespace AsdSip; | 17 | using namespace AsdSip; |
| 19 | 18 | ||
| 20 | 19 | ||
| @@ -22,7 +21,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 24 | + return -1; \ |
| 26 | } else { \ | 25 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 26 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 27 | } \ |
| @@ -40,7 +39,7 @@ using namespace AsdSip; | |||
| 40 | printf(message, ##__VA_ARGS__); \ | 39 | printf(message, ##__VA_ARGS__); \ |
| 41 | } while (0) | 40 | } while (0) |
| 42 | 41 | ||
| 43 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 42 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 44 | { | 43 | { |
| 45 | int64_t shapeSize = 1; | 44 | int64_t shapeSize = 1; |
| 46 | for (auto i : shape) { | 45 | for (auto i : shape) { |
| @@ -49,7 +48,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 49 | return shapeSize; | 48 | return shapeSize; |
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | -int Init(int32_t deviceId, aclrtStream *stream) | 51 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 53 | { | 52 | { |
| 54 | // 固定写法,acl初始化 | 53 | // 固定写法,acl初始化 |
| 55 | auto ret = aclInit(nullptr); | 54 | auto ret = aclInit(nullptr); |
| @@ -62,8 +61,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | template <typename T> | 63 | template <typename T> |
| 65 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 64 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 66 | - aclDataType dataType, aclTensor **tensor) | 65 | + aclDataType dataType, aclTensor** tensor) |
| 67 | { | 66 | { |
| 68 | auto size = GetShapeSize(shape) * sizeof(T); | 67 | auto size = GetShapeSize(shape) * sizeof(T); |
| 69 | // 调用aclrtMalloc申请device侧内存 | 68 | // 调用aclrtMalloc申请device侧内存 |
| @@ -80,15 +79,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | // 调用aclCreateTensor接口创建aclTensor | 81 | // 调用aclCreateTensor接口创建aclTensor |
| 83 | - *tensor = aclCreateTensor(shape.data(), | 82 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 84 | - shape.size(), | 83 | + shape.data(), shape.size(), *deviceAddr); |
| 85 | - dataType, | ||
| 86 | - strides.data(), | ||
| 87 | - 0, | ||
| 88 | - aclFormat::ACL_FORMAT_ND, | ||
| 89 | - shape.data(), | ||
| 90 | - shape.size(), | ||
| 91 | - *deviceAddr); | ||
| 92 | return 0; | 84 | return 0; |
| 93 | } | 85 | } |
| 94 | 86 | ||
| @@ -106,7 +98,7 @@ void printTensor(std::vector<std::complex<float>> tensorData, int64_t batch, int | |||
| 106 | } | 98 | } |
| 107 | } | 99 | } |
| 108 | 100 | ||
| 109 | -int main(int argc, char **argv) | 101 | +int main(int argc, char** argv) |
| 110 | { | 102 | { |
| 111 | int deviceId = 0; | 103 | int deviceId = 0; |
| 112 | 104 | ||
| @@ -153,26 +145,26 @@ int main(int argc, char **argv) | |||
| 153 | std::vector<int64_t> matBShape = {batch, k, n}; | 145 | std::vector<int64_t> matBShape = {batch, k, n}; |
| 154 | std::vector<int64_t> matCShape = {batch, m, n}; | 146 | std::vector<int64_t> matCShape = {batch, m, n}; |
| 155 | 147 | ||
| 156 | - aclTensor *matA = nullptr; | 148 | + aclTensor* matA = nullptr; |
| 157 | - aclTensor *matB = nullptr; | 149 | + aclTensor* matB = nullptr; |
| 158 | - aclTensor *matC = nullptr; | 150 | + aclTensor* matC = nullptr; |
| 159 | - void *matADeviceAddr = nullptr; | 151 | + void* matADeviceAddr = nullptr; |
| 160 | - void *matBDeviceAddr = nullptr; | 152 | + void* matBDeviceAddr = nullptr; |
| 161 | - void *matCDeviceAddr = nullptr; | 153 | + void* matCDeviceAddr = nullptr; |
| 162 | 154 | ||
| 163 | - ret = CreateAclTensor<std::complex<float>>( | 155 | + ret = CreateAclTensor<std::complex<float>>(tensorInAData, matAShape, &matADeviceAddr, aclDataType::ACL_COMPLEX64, |
| 164 | - tensorInAData, matAShape, &matADeviceAddr, aclDataType::ACL_COMPLEX64, &matA); | 156 | + &matA); |
| 165 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 157 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 166 | 158 | ||
| 167 | - ret = CreateAclTensor<std::complex<float>>( | 159 | + ret = CreateAclTensor<std::complex<float>>(tensorInBData, matBShape, &matBDeviceAddr, aclDataType::ACL_COMPLEX64, |
| 168 | - tensorInBData, matBShape, &matBDeviceAddr, aclDataType::ACL_COMPLEX64, &matB); | 160 | + &matB); |
| 169 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 161 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 170 | 162 | ||
| 171 | - ret = CreateAclTensor<std::complex<float>>( | 163 | + ret = CreateAclTensor<std::complex<float>>(tensorInCData, matCShape, &matCDeviceAddr, aclDataType::ACL_COMPLEX64, |
| 172 | - tensorInCData, matCShape, &matCDeviceAddr, aclDataType::ACL_COMPLEX64, &matC); | 164 | + &matC); |
| 173 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 165 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 174 | - std::cout << "alpha = " << "(" << (float) alpha.real() << "," << (float) alpha.imag() << ")" << std::endl; | 166 | + std::cout << "alpha = " << "(" << (float)alpha.real() << "," << (float)alpha.imag() << ")" << std::endl; |
| 175 | - std::cout << "beta = " << "(" << (float) beta.real() << "," << (float) beta.imag() << ")" << std::endl; | 167 | + std::cout << "beta = " << "(" << (float)beta.real() << "," << (float)beta.imag() << ")" << std::endl; |
| 176 | std::cout << "------- input TensorInA -------" << std::endl; | 168 | std::cout << "------- input TensorInA -------" << std::endl; |
| 177 | printTensor(tensorInAData, batch, m, k); | 169 | printTensor(tensorInAData, batch, m, k); |
| 178 | std::cout << "------- input TensorInB -------" << std::endl; | 170 | std::cout << "------- input TensorInB -------" << std::endl; |
| @@ -182,7 +174,7 @@ int main(int argc, char **argv) | |||
| 182 | asdBlasCreate(handle); | 174 | asdBlasCreate(handle); |
| 183 | 175 | ||
| 184 | size_t lwork = 0; | 176 | size_t lwork = 0; |
| 185 | - void *buffer = nullptr; | 177 | + void* buffer = nullptr; |
| 186 | asdBlasMakeCgemmBatchedPlan(handle); | 178 | asdBlasMakeCgemmBatchedPlan(handle); |
| 187 | asdBlasGetWorkspaceSize(handle, lwork); | 179 | asdBlasGetWorkspaceSize(handle, lwork); |
| 188 | std::cout << "lwork = " << lwork << std::endl; | 180 | std::cout << "lwork = " << lwork << std::endl; |
| @@ -193,16 +185,14 @@ int main(int argc, char **argv) | |||
| 193 | asdBlasSetWorkspace(handle, buffer); | 185 | asdBlasSetWorkspace(handle, buffer); |
| 194 | asdBlasSetStream(handle, stream); | 186 | asdBlasSetStream(handle, stream); |
| 195 | 187 | ||
| 196 | - ASD_STATUS_CHECK(asdBlasCgemmBatched(handle, transA, transB, m, n, k, alpha, matA, lda, matB, ldb, beta, matC, ldc, batch)); | 188 | + ASD_STATUS_CHECK( |
| 189 | + asdBlasCgemmBatched(handle, transA, transB, m, n, k, alpha, matA, lda, matB, ldb, beta, matC, ldc, batch)); | ||
| 197 | 190 | ||
| 198 | asdBlasSynchronize(handle); | 191 | asdBlasSynchronize(handle); |
| 199 | asdBlasDestroy(handle); | 192 | asdBlasDestroy(handle); |
| 200 | 193 | ||
| 201 | - ret = aclrtMemcpy(tensorInCData.data(), | 194 | + ret = aclrtMemcpy(tensorInCData.data(), tensorCSize * sizeof(std::complex<float>), matCDeviceAddr, |
| 202 | - tensorCSize * sizeof(std::complex<float>), | 195 | + tensorCSize * sizeof(std::complex<float>), ACL_MEMCPY_DEVICE_TO_HOST); |
| 203 | - matCDeviceAddr, | ||
| 204 | - tensorCSize * sizeof(std::complex<float>), | ||
| 205 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 206 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 196 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 207 | 197 | ||
| 208 | std::cout << "------- output TensorInC -------" << std::endl; | 198 | std::cout << "------- output TensorInC -------" << std::endl; |
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } else { \ | 26 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 27 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 28 | } \ |
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } else { \ | 26 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 27 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 28 | } \ |
| @@ -23,7 +23,7 @@ using namespace AsdSip; | |||
| 23 | AsdSip::AspbStatus err_ = (err); \ | 23 | AsdSip::AspbStatus err_ = (err); \ |
| 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 25 | std::cout << "Execute failed." << std::endl; \ | 25 | std::cout << "Execute failed." << std::endl; \ |
| 26 | - exit(-1); \ | 26 | + return -1; \ |
| 27 | } else { \ | 27 | } else { \ |
| 28 | std::cout << "Execute successfully." << std::endl; \ | 28 | std::cout << "Execute successfully." << std::endl; \ |
| 29 | } \ | 29 | } \ |
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } else { \ | 26 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 27 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 28 | } \ |
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } else { \ | 26 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 27 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 28 | } \ |
| @@ -23,7 +23,7 @@ using namespace AsdSip; | |||
| 23 | AsdSip::AspbStatus err_ = (err); \ | 23 | AsdSip::AspbStatus err_ = (err); \ |
| 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 25 | std::cout << "Execute failed." << std::endl; \ | 25 | std::cout << "Execute failed." << std::endl; \ |
| 26 | - exit(-1); \ | 26 | + return -1; \ |
| 27 | } else { \ | 27 | } else { \ |
| 28 | std::cout << "Execute successfully." << std::endl; \ | 28 | std::cout << "Execute successfully." << std::endl; \ |
| 29 | } \ | 29 | } \ |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } else { \ | 26 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 27 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 28 | } \ |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -25,7 +25,7 @@ using namespace AsdSip; | |||
| 25 | AsdSip::AspbStatus err_ = (err); \ | 25 | AsdSip::AspbStatus err_ = (err); \ |
| 26 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 26 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 27 | std::cout << "Execute failed." << std::endl; \ | 27 | std::cout << "Execute failed." << std::endl; \ |
| 28 | - exit(-1); \ | 28 | + return -1; \ |
| 29 | } else { \ | 29 | } else { \ |
| 30 | std::cout << "Execute successfully." << std::endl; \ | 30 | std::cout << "Execute successfully." << std::endl; \ |
| 31 | } \ | 31 | } \ |
| @@ -25,7 +25,7 @@ using namespace AsdSip; | |||
| 25 | AsdSip::AspbStatus err_ = (err); \ | 25 | AsdSip::AspbStatus err_ = (err); \ |
| 26 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 26 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 27 | std::cout << "Execute failed." << std::endl; \ | 27 | std::cout << "Execute failed." << std::endl; \ |
| 28 | - exit(-1); \ | 28 | + return -1; \ |
| 29 | } else { \ | 29 | } else { \ |
| 30 | std::cout << "Execute successfully." << std::endl; \ | 30 | std::cout << "Execute successfully." << std::endl; \ |
| 31 | } \ | 31 | } \ |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -14,7 +14,6 @@ | |||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | - | ||
| 18 | using namespace AsdSip; | 17 | using namespace AsdSip; |
| 19 | 18 | ||
| 20 | 19 | ||
| @@ -22,7 +21,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 24 | + return -1; \ |
| 26 | } else { \ | 25 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 26 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 27 | } \ |
| @@ -40,7 +39,7 @@ using namespace AsdSip; | |||
| 40 | printf(message, ##__VA_ARGS__); \ | 39 | printf(message, ##__VA_ARGS__); \ |
| 41 | } while (0) | 40 | } while (0) |
| 42 | 41 | ||
| 43 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 42 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 44 | { | 43 | { |
| 45 | int64_t shapeSize = 1; | 44 | int64_t shapeSize = 1; |
| 46 | for (auto i : shape) { | 45 | for (auto i : shape) { |
| @@ -49,7 +48,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 49 | return shapeSize; | 48 | return shapeSize; |
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | -int Init(int32_t deviceId, aclrtStream *stream) | 51 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 53 | { | 52 | { |
| 54 | // 固定写法,acl初始化 | 53 | // 固定写法,acl初始化 |
| 55 | auto ret = aclInit(nullptr); | 54 | auto ret = aclInit(nullptr); |
| @@ -62,8 +61,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | template <typename T> | 63 | template <typename T> |
| 65 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 64 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 66 | - aclDataType dataType, aclTensor **tensor) | 65 | + aclDataType dataType, aclTensor** tensor) |
| 67 | { | 66 | { |
| 68 | auto size = GetShapeSize(shape) * sizeof(T); | 67 | auto size = GetShapeSize(shape) * sizeof(T); |
| 69 | // 调用aclrtMalloc申请device侧内存 | 68 | // 调用aclrtMalloc申请device侧内存 |
| @@ -80,15 +79,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | // 调用aclCreateTensor接口创建aclTensor | 81 | // 调用aclCreateTensor接口创建aclTensor |
| 83 | - *tensor = aclCreateTensor(shape.data(), | 82 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 84 | - shape.size(), | 83 | + shape.data(), shape.size(), *deviceAddr); |
| 85 | - dataType, | ||
| 86 | - strides.data(), | ||
| 87 | - 0, | ||
| 88 | - aclFormat::ACL_FORMAT_ND, | ||
| 89 | - shape.data(), | ||
| 90 | - shape.size(), | ||
| 91 | - *deviceAddr); | ||
| 92 | return 0; | 84 | return 0; |
| 93 | } | 85 | } |
| 94 | 86 | ||
| @@ -106,7 +98,7 @@ void printTensor(std::vector<std::complex<op::fp16_t>> tensorData, int64_t batch | |||
| 106 | } | 98 | } |
| 107 | } | 99 | } |
| 108 | 100 | ||
| 109 | -int main(int argc, char **argv) | 101 | +int main(int argc, char** argv) |
| 110 | { | 102 | { |
| 111 | int deviceId = 0; | 103 | int deviceId = 0; |
| 112 | 104 | ||
| @@ -153,26 +145,26 @@ int main(int argc, char **argv) | |||
| 153 | std::vector<int64_t> matBShape = {batch, k, n}; | 145 | std::vector<int64_t> matBShape = {batch, k, n}; |
| 154 | std::vector<int64_t> matCShape = {batch, m, n}; | 146 | std::vector<int64_t> matCShape = {batch, m, n}; |
| 155 | 147 | ||
| 156 | - aclTensor *matA = nullptr; | 148 | + aclTensor* matA = nullptr; |
| 157 | - aclTensor *matB = nullptr; | 149 | + aclTensor* matB = nullptr; |
| 158 | - aclTensor *matC = nullptr; | 150 | + aclTensor* matC = nullptr; |
| 159 | - void *matADeviceAddr = nullptr; | 151 | + void* matADeviceAddr = nullptr; |
| 160 | - void *matBDeviceAddr = nullptr; | 152 | + void* matBDeviceAddr = nullptr; |
| 161 | - void *matCDeviceAddr = nullptr; | 153 | + void* matCDeviceAddr = nullptr; |
| 162 | 154 | ||
| 163 | - ret = CreateAclTensor<std::complex<op::fp16_t>>( | 155 | + ret = CreateAclTensor<std::complex<op::fp16_t>>(tensorInAData, matAShape, &matADeviceAddr, |
| 164 | - tensorInAData, matAShape, &matADeviceAddr, aclDataType::ACL_COMPLEX32, &matA); | 156 | + aclDataType::ACL_COMPLEX32, &matA); |
| 165 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 157 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 166 | 158 | ||
| 167 | - ret = CreateAclTensor<std::complex<op::fp16_t>>( | 159 | + ret = CreateAclTensor<std::complex<op::fp16_t>>(tensorInBData, matBShape, &matBDeviceAddr, |
| 168 | - tensorInBData, matBShape, &matBDeviceAddr, aclDataType::ACL_COMPLEX32, &matB); | 160 | + aclDataType::ACL_COMPLEX32, &matB); |
| 169 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 161 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 170 | 162 | ||
| 171 | - ret = CreateAclTensor<std::complex<op::fp16_t>>( | 163 | + ret = CreateAclTensor<std::complex<op::fp16_t>>(tensorInCData, matCShape, &matCDeviceAddr, |
| 172 | - tensorInCData, matCShape, &matCDeviceAddr, aclDataType::ACL_COMPLEX32, &matC); | 164 | + aclDataType::ACL_COMPLEX32, &matC); |
| 173 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 165 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 174 | - std::cout << "alpha = " << "(" << (float) alpha.real() << "," << (float) alpha.imag() << ")" << std::endl; | 166 | + std::cout << "alpha = " << "(" << (float)alpha.real() << "," << (float)alpha.imag() << ")" << std::endl; |
| 175 | - std::cout << "beta = " << "(" << (float) beta.real() << "," << (float) beta.imag() << ")" << std::endl; | 167 | + std::cout << "beta = " << "(" << (float)beta.real() << "," << (float)beta.imag() << ")" << std::endl; |
| 176 | std::cout << "------- input TensorInA -------" << std::endl; | 168 | std::cout << "------- input TensorInA -------" << std::endl; |
| 177 | printTensor(tensorInAData, batch, m, k); | 169 | printTensor(tensorInAData, batch, m, k); |
| 178 | std::cout << "------- input TensorInB -------" << std::endl; | 170 | std::cout << "------- input TensorInB -------" << std::endl; |
| @@ -182,7 +174,7 @@ int main(int argc, char **argv) | |||
| 182 | asdBlasCreate(handle); | 174 | asdBlasCreate(handle); |
| 183 | 175 | ||
| 184 | size_t lwork = 0; | 176 | size_t lwork = 0; |
| 185 | - void *buffer = nullptr; | 177 | + void* buffer = nullptr; |
| 186 | asdBlasMakeHCgemmBatchedPlan(handle); | 178 | asdBlasMakeHCgemmBatchedPlan(handle); |
| 187 | asdBlasGetWorkspaceSize(handle, lwork); | 179 | asdBlasGetWorkspaceSize(handle, lwork); |
| 188 | std::cout << "lwork = " << lwork << std::endl; | 180 | std::cout << "lwork = " << lwork << std::endl; |
| @@ -193,16 +185,14 @@ int main(int argc, char **argv) | |||
| 193 | asdBlasSetWorkspace(handle, buffer); | 185 | asdBlasSetWorkspace(handle, buffer); |
| 194 | asdBlasSetStream(handle, stream); | 186 | asdBlasSetStream(handle, stream); |
| 195 | 187 | ||
| 196 | - ASD_STATUS_CHECK(asdBlasHCgemmBatched(handle, transA, transB, m, n, k, alpha, matA, lda, matB, ldb, beta, matC, ldc, batch)); | 188 | + ASD_STATUS_CHECK( |
| 189 | + asdBlasHCgemmBatched(handle, transA, transB, m, n, k, alpha, matA, lda, matB, ldb, beta, matC, ldc, batch)); | ||
| 197 | 190 | ||
| 198 | asdBlasSynchronize(handle); | 191 | asdBlasSynchronize(handle); |
| 199 | asdBlasDestroy(handle); | 192 | asdBlasDestroy(handle); |
| 200 | 193 | ||
| 201 | - ret = aclrtMemcpy(tensorInCData.data(), | 194 | + ret = aclrtMemcpy(tensorInCData.data(), tensorCSize * sizeof(std::complex<op::fp16_t>), matCDeviceAddr, |
| 202 | - tensorCSize * sizeof(std::complex<op::fp16_t>), | 195 | + tensorCSize * sizeof(std::complex<op::fp16_t>), ACL_MEMCPY_DEVICE_TO_HOST); |
| 203 | - matCDeviceAddr, | ||
| 204 | - tensorCSize * sizeof(std::complex<op::fp16_t>), | ||
| 205 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 206 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 196 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 207 | 197 | ||
| 208 | std::cout << "------- output TensorInC -------" << std::endl; | 198 | std::cout << "------- output TensorInC -------" << std::endl; |
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } else { \ | 26 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 27 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 28 | } \ |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -37,7 +37,7 @@ using namespace AsdSip; | |||
| 37 | printf(message, ##__VA_ARGS__); \ | 37 | printf(message, ##__VA_ARGS__); \ |
| 38 | } while (0) | 38 | } while (0) |
| 39 | 39 | ||
| 40 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 40 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 41 | { | 41 | { |
| 42 | int64_t shapeSize = 1; | 42 | int64_t shapeSize = 1; |
| 43 | for (auto i : shape) { | 43 | for (auto i : shape) { |
| @@ -46,7 +46,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 46 | return shapeSize; | 46 | return shapeSize; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | -int Init(int32_t deviceId, aclrtStream *stream) | 49 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 50 | { | 50 | { |
| 51 | // 固定写法,acl初始化 | 51 | // 固定写法,acl初始化 |
| 52 | auto ret = aclInit(nullptr); | 52 | auto ret = aclInit(nullptr); |
| @@ -59,8 +59,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | template <typename T> | 61 | template <typename T> |
| 62 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 62 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 63 | - aclDataType dataType, aclTensor **tensor) | 63 | + aclDataType dataType, aclTensor** tensor) |
| 64 | { | 64 | { |
| 65 | auto size = GetShapeSize(shape) * sizeof(T); | 65 | auto size = GetShapeSize(shape) * sizeof(T); |
| 66 | // 调用aclrtMalloc申请device侧内存 | 66 | // 调用aclrtMalloc申请device侧内存 |
| @@ -77,19 +77,12 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | // 调用aclCreateTensor接口创建aclTensor | 79 | // 调用aclCreateTensor接口创建aclTensor |
| 80 | - *tensor = aclCreateTensor(shape.data(), | 80 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 81 | - shape.size(), | 81 | + shape.data(), shape.size(), *deviceAddr); |
| 82 | - dataType, | ||
| 83 | - strides.data(), | ||
| 84 | - 0, | ||
| 85 | - aclFormat::ACL_FORMAT_ND, | ||
| 86 | - shape.data(), | ||
| 87 | - shape.size(), | ||
| 88 | - *deviceAddr); | ||
| 89 | return 0; | 82 | return 0; |
| 90 | } | 83 | } |
| 91 | 84 | ||
| 92 | -int main(int argc, char **argv) | 85 | +int main(int argc, char** argv) |
| 93 | { | 86 | { |
| 94 | int deviceId = 0; | 87 | int deviceId = 0; |
| 95 | 88 | ||
| @@ -136,10 +129,10 @@ int main(int argc, char **argv) | |||
| 136 | std::vector<int64_t> xShape = {n}; | 129 | std::vector<int64_t> xShape = {n}; |
| 137 | std::vector<int64_t> matAShape = {n, n}; | 130 | std::vector<int64_t> matAShape = {n, n}; |
| 138 | 131 | ||
| 139 | - aclTensor *inputX = nullptr; | 132 | + aclTensor* inputX = nullptr; |
| 140 | - aclTensor *inputA = nullptr; | 133 | + aclTensor* inputA = nullptr; |
| 141 | - void *inputXDeviceAddr = nullptr; | 134 | + void* inputXDeviceAddr = nullptr; |
| 142 | - void *inputADeviceAddr = nullptr; | 135 | + void* inputADeviceAddr = nullptr; |
| 143 | 136 | ||
| 144 | ret = CreateAclTensor<float>(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_FLOAT, &inputX); | 137 | ret = CreateAclTensor<float>(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_FLOAT, &inputX); |
| 145 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 138 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| @@ -151,7 +144,7 @@ int main(int argc, char **argv) | |||
| 151 | asdBlasCreate(handle); | 144 | asdBlasCreate(handle); |
| 152 | 145 | ||
| 153 | size_t lwork = 0; | 146 | size_t lwork = 0; |
| 154 | - void *buffer = nullptr; | 147 | + void* buffer = nullptr; |
| 155 | asdBlasMakeSsyrPlan(handle); | 148 | asdBlasMakeSsyrPlan(handle); |
| 156 | asdBlasGetWorkspaceSize(handle, lwork); | 149 | asdBlasGetWorkspaceSize(handle, lwork); |
| 157 | std::cout << "lwork = " << lwork << std::endl; | 150 | std::cout << "lwork = " << lwork << std::endl; |
| @@ -168,11 +161,8 @@ int main(int argc, char **argv) | |||
| 168 | asdBlasSynchronize(handle); | 161 | asdBlasSynchronize(handle); |
| 169 | asdBlasDestroy(handle); | 162 | asdBlasDestroy(handle); |
| 170 | 163 | ||
| 171 | - ret = aclrtMemcpy(tensorInAData.data(), | 164 | + ret = aclrtMemcpy(tensorInAData.data(), n * n * sizeof(float), inputADeviceAddr, n * n * sizeof(float), |
| 172 | - n * n * sizeof(float), | 165 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 173 | - inputADeviceAddr, | ||
| 174 | - n * n * sizeof(float), | ||
| 175 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 176 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 166 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 177 | 167 | ||
| 178 | std::cout << "------- output A -------" << std::endl; | 168 | std::cout << "------- output A -------" << std::endl; |
| @@ -193,4 +183,4 @@ int main(int argc, char **argv) | |||
| 193 | aclrtResetDevice(deviceId); | 183 | aclrtResetDevice(deviceId); |
| 194 | aclFinalize(); | 184 | aclFinalize(); |
| 195 | return 0; | 185 | return 0; |
| 196 | -} | 186 | +} |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -37,7 +37,7 @@ using namespace AsdSip; | |||
| 37 | printf(message, ##__VA_ARGS__); \ | 37 | printf(message, ##__VA_ARGS__); \ |
| 38 | } while (0) | 38 | } while (0) |
| 39 | 39 | ||
| 40 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 40 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 41 | { | 41 | { |
| 42 | int64_t shapeSize = 1; | 42 | int64_t shapeSize = 1; |
| 43 | for (auto i : shape) { | 43 | for (auto i : shape) { |
| @@ -46,7 +46,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 46 | return shapeSize; | 46 | return shapeSize; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | -int Init(int32_t deviceId, aclrtStream *stream) | 49 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 50 | { | 50 | { |
| 51 | // 固定写法,acl初始化 | 51 | // 固定写法,acl初始化 |
| 52 | auto ret = aclInit(nullptr); | 52 | auto ret = aclInit(nullptr); |
| @@ -59,8 +59,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | template <typename T> | 61 | template <typename T> |
| 62 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 62 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 63 | - aclDataType dataType, aclTensor **tensor) | 63 | + aclDataType dataType, aclTensor** tensor) |
| 64 | { | 64 | { |
| 65 | auto size = GetShapeSize(shape) * sizeof(T); | 65 | auto size = GetShapeSize(shape) * sizeof(T); |
| 66 | // 调用aclrtMalloc申请device侧内存 | 66 | // 调用aclrtMalloc申请device侧内存 |
| @@ -77,19 +77,12 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | // 调用aclCreateTensor接口创建aclTensor | 79 | // 调用aclCreateTensor接口创建aclTensor |
| 80 | - *tensor = aclCreateTensor(shape.data(), | 80 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 81 | - shape.size(), | 81 | + shape.data(), shape.size(), *deviceAddr); |
| 82 | - dataType, | ||
| 83 | - strides.data(), | ||
| 84 | - 0, | ||
| 85 | - aclFormat::ACL_FORMAT_ND, | ||
| 86 | - shape.data(), | ||
| 87 | - shape.size(), | ||
| 88 | - *deviceAddr); | ||
| 89 | return 0; | 82 | return 0; |
| 90 | } | 83 | } |
| 91 | 84 | ||
| 92 | -int main(int argc, char **argv) | 85 | +int main(int argc, char** argv) |
| 93 | { | 86 | { |
| 94 | int deviceId = 0; | 87 | int deviceId = 0; |
| 95 | 88 | ||
| @@ -151,12 +144,12 @@ int main(int argc, char **argv) | |||
| 151 | std::vector<int64_t> yShape = {n}; | 144 | std::vector<int64_t> yShape = {n}; |
| 152 | std::vector<int64_t> matAShape = {n, n}; | 145 | std::vector<int64_t> matAShape = {n, n}; |
| 153 | 146 | ||
| 154 | - aclTensor *inputX = nullptr; | 147 | + aclTensor* inputX = nullptr; |
| 155 | - aclTensor *inputY = nullptr; | 148 | + aclTensor* inputY = nullptr; |
| 156 | - aclTensor *inputA = nullptr; | 149 | + aclTensor* inputA = nullptr; |
| 157 | - void *inputXDeviceAddr = nullptr; | 150 | + void* inputXDeviceAddr = nullptr; |
| 158 | - void *inputYDeviceAddr = nullptr; | 151 | + void* inputYDeviceAddr = nullptr; |
| 159 | - void *inputADeviceAddr = nullptr; | 152 | + void* inputADeviceAddr = nullptr; |
| 160 | 153 | ||
| 161 | ret = CreateAclTensor<float>(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_FLOAT, &inputX); | 154 | ret = CreateAclTensor<float>(tensorInXData, xShape, &inputXDeviceAddr, aclDataType::ACL_FLOAT, &inputX); |
| 162 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 155 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| @@ -171,7 +164,7 @@ int main(int argc, char **argv) | |||
| 171 | asdBlasCreate(handle); | 164 | asdBlasCreate(handle); |
| 172 | 165 | ||
| 173 | size_t lwork = 0; | 166 | size_t lwork = 0; |
| 174 | - void *buffer = nullptr; | 167 | + void* buffer = nullptr; |
| 175 | asdBlasMakeSsyr2Plan(handle); | 168 | asdBlasMakeSsyr2Plan(handle); |
| 176 | asdBlasGetWorkspaceSize(handle, lwork); | 169 | asdBlasGetWorkspaceSize(handle, lwork); |
| 177 | std::cout << "lwork = " << lwork << std::endl; | 170 | std::cout << "lwork = " << lwork << std::endl; |
| @@ -187,11 +180,8 @@ int main(int argc, char **argv) | |||
| 187 | asdBlasSynchronize(handle); | 180 | asdBlasSynchronize(handle); |
| 188 | asdBlasDestroy(handle); | 181 | asdBlasDestroy(handle); |
| 189 | 182 | ||
| 190 | - ret = aclrtMemcpy(tensorInAData.data(), | 183 | + ret = aclrtMemcpy(tensorInAData.data(), n * n * sizeof(float), inputADeviceAddr, n * n * sizeof(float), |
| 191 | - n * n * sizeof(float), | 184 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 192 | - inputADeviceAddr, | ||
| 193 | - n * n * sizeof(float), | ||
| 194 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 195 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 185 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 196 | 186 | ||
| 197 | std::cout << "------- output A -------" << std::endl; | 187 | std::cout << "------- output A -------" << std::endl; |
| @@ -214,4 +204,4 @@ int main(int argc, char **argv) | |||
| 214 | aclrtResetDevice(deviceId); | 204 | aclrtResetDevice(deviceId); |
| 215 | aclFinalize(); | 205 | aclFinalize(); |
| 216 | return 0; | 206 | return 0; |
| 217 | -} | 207 | +} |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -37,7 +37,7 @@ using namespace AsdSip; | |||
| 37 | printf(message, ##__VA_ARGS__); \ | 37 | printf(message, ##__VA_ARGS__); \ |
| 38 | } while (0) | 38 | } while (0) |
| 39 | 39 | ||
| 40 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 40 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 41 | { | 41 | { |
| 42 | int64_t shapeSize = 1; | 42 | int64_t shapeSize = 1; |
| 43 | for (auto i : shape) { | 43 | for (auto i : shape) { |
| @@ -46,7 +46,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 46 | return shapeSize; | 46 | return shapeSize; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | -int Init(int32_t deviceId, aclrtStream *stream) | 49 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 50 | { | 50 | { |
| 51 | // 固定写法,acl初始化 | 51 | // 固定写法,acl初始化 |
| 52 | auto ret = aclInit(nullptr); | 52 | auto ret = aclInit(nullptr); |
| @@ -59,8 +59,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | template <typename T> | 61 | template <typename T> |
| 62 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 62 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 63 | - aclDataType dataType, aclTensor **tensor) | 63 | + aclDataType dataType, aclTensor** tensor) |
| 64 | { | 64 | { |
| 65 | auto size = GetShapeSize(shape) * sizeof(T); | 65 | auto size = GetShapeSize(shape) * sizeof(T); |
| 66 | // 调用aclrtMalloc申请device侧内存 | 66 | // 调用aclrtMalloc申请device侧内存 |
| @@ -77,19 +77,12 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | // 调用aclCreateTensor接口创建aclTensor | 79 | // 调用aclCreateTensor接口创建aclTensor |
| 80 | - *tensor = aclCreateTensor(shape.data(), | 80 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 81 | - shape.size(), | 81 | + shape.data(), shape.size(), *deviceAddr); |
| 82 | - dataType, | ||
| 83 | - strides.data(), | ||
| 84 | - 0, | ||
| 85 | - aclFormat::ACL_FORMAT_ND, | ||
| 86 | - shape.data(), | ||
| 87 | - shape.size(), | ||
| 88 | - *deviceAddr); | ||
| 89 | return 0; | 82 | return 0; |
| 90 | } | 83 | } |
| 91 | 84 | ||
| 92 | -int main(int argc, char **argv) | 85 | +int main(int argc, char** argv) |
| 93 | { | 86 | { |
| 94 | int deviceId = 0; | 87 | int deviceId = 0; |
| 95 | 88 | ||
| @@ -150,12 +143,12 @@ int main(int argc, char **argv) | |||
| 150 | std::vector<int64_t> bShape = {tensorBSize}; | 143 | std::vector<int64_t> bShape = {tensorBSize}; |
| 151 | std::vector<int64_t> cShape = {tensorCSize}; | 144 | std::vector<int64_t> cShape = {tensorCSize}; |
| 152 | 145 | ||
| 153 | - aclTensor *inputA = nullptr; | 146 | + aclTensor* inputA = nullptr; |
| 154 | - aclTensor *inputB = nullptr; | 147 | + aclTensor* inputB = nullptr; |
| 155 | - aclTensor *outputC = nullptr; | 148 | + aclTensor* outputC = nullptr; |
| 156 | - void *inputADeviceAddr = nullptr; | 149 | + void* inputADeviceAddr = nullptr; |
| 157 | - void *inputBDeviceAddr = nullptr; | 150 | + void* inputBDeviceAddr = nullptr; |
| 158 | - void *outputCDeviceAddr = nullptr; | 151 | + void* outputCDeviceAddr = nullptr; |
| 159 | 152 | ||
| 160 | ret = CreateAclTensor(tensorInAData, aShape, &inputADeviceAddr, aclDataType::ACL_FLOAT, &inputA); | 153 | ret = CreateAclTensor(tensorInAData, aShape, &inputADeviceAddr, aclDataType::ACL_FLOAT, &inputA); |
| 161 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 154 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| @@ -168,7 +161,7 @@ int main(int argc, char **argv) | |||
| 168 | asdBlasCreate(handle); | 161 | asdBlasCreate(handle); |
| 169 | 162 | ||
| 170 | size_t lwork = 0; | 163 | size_t lwork = 0; |
| 171 | - void *buffer = nullptr; | 164 | + void* buffer = nullptr; |
| 172 | asdBlasMakeStrmmPlan(handle); | 165 | asdBlasMakeStrmmPlan(handle); |
| 173 | asdBlasGetWorkspaceSize(handle, lwork); | 166 | asdBlasGetWorkspaceSize(handle, lwork); |
| 174 | std::cout << "lwork = " << lwork << std::endl; | 167 | std::cout << "lwork = " << lwork << std::endl; |
| @@ -185,11 +178,8 @@ int main(int argc, char **argv) | |||
| 185 | asdBlasSynchronize(handle); | 178 | asdBlasSynchronize(handle); |
| 186 | asdBlasDestroy(handle); | 179 | asdBlasDestroy(handle); |
| 187 | 180 | ||
| 188 | - ret = aclrtMemcpy(tensorCData.data(), | 181 | + ret = aclrtMemcpy(tensorCData.data(), tensorCSize * sizeof(float), outputCDeviceAddr, tensorCSize * sizeof(float), |
| 189 | - tensorCSize * sizeof(float), | 182 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 190 | - outputCDeviceAddr, | ||
| 191 | - tensorCSize * sizeof(float), | ||
| 192 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 193 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 183 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 194 | 184 | ||
| 195 | std::cout << "------- output C -------" << std::endl; | 185 | std::cout << "------- output C -------" << std::endl; |
| @@ -212,4 +202,4 @@ int main(int argc, char **argv) | |||
| 212 | aclrtResetDevice(deviceId); | 202 | aclrtResetDevice(deviceId); |
| 213 | aclFinalize(); | 203 | aclFinalize(); |
| 214 | return 0; | 204 | return 0; |
| 215 | -} | 205 | +} |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -22,7 +22,7 @@ using namespace AsdSip; | |||
| 22 | AsdSip::AspbStatus err_ = (err); \ | 22 | AsdSip::AspbStatus err_ = (err); \ |
| 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 23 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 24 | std::cout << "Execute failed." << std::endl; \ | 24 | std::cout << "Execute failed." << std::endl; \ |
| 25 | - exit(-1); \ | 25 | + return -1; \ |
| 26 | } else { \ | 26 | } else { \ |
| 27 | std::cout << "Execute successfully." << std::endl; \ | 27 | std::cout << "Execute successfully." << std::endl; \ |
| 28 | } \ | 28 | } \ |
| @@ -21,7 +21,7 @@ using namespace AsdSip; | |||
| 21 | AsdSip::AspbStatus err_ = (err); \ | 21 | AsdSip::AspbStatus err_ = (err); \ |
| 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 22 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 23 | std::cout << "Execute failed." << std::endl; \ | 23 | std::cout << "Execute failed." << std::endl; \ |
| 24 | - exit(-1); \ | 24 | + return -1; \ |
| 25 | } \ | 25 | } \ |
| 26 | } while (0) | 26 | } while (0) |
| 27 | 27 | ||
| @@ -23,7 +23,7 @@ using namespace AsdSip; | |||
| 23 | AsdSip::AspbStatus err_ = (err); \ | 23 | AsdSip::AspbStatus err_ = (err); \ |
| 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 24 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 25 | std::cout << "Execute failed." << std::endl; \ | 25 | std::cout << "Execute failed." << std::endl; \ |
| 26 | - exit(-1); \ | 26 | + return -1; \ |
| 27 | } \ | 27 | } \ |
| 28 | } while (0) | 28 | } while (0) |
| 29 | 29 | ||
| @@ -32,11 +32,11 @@ using namespace AsdSip; | |||
| 32 | AsdSip::AspbStatus err_ = (err); \ | 32 | AsdSip::AspbStatus err_ = (err); \ |
| 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 34 | std::cout << "Execute failed." << std::endl; \ | 34 | std::cout << "Execute failed." << std::endl; \ |
| 35 | - exit(-1); \ | 35 | + return -1; \ |
| 36 | } \ | 36 | } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,AscendCL初始化 | 50 | // 固定写法,AscendCL初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,15 +76,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| @@ -96,7 +89,7 @@ int main() | |||
| 96 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | 89 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); |
| 97 | 90 | ||
| 98 | // 创造tensor的Host侧数据 | 91 | // 创造tensor的Host侧数据 |
| 99 | - int batch = 32, Nfft = 128; // c2c dft | 92 | + int batch = 32, Nfft = 128; // c2c dft |
| 100 | // int batch = 32, Nfft = 8192; // c2c fftb | 93 | // int batch = 32, Nfft = 8192; // c2c fftb |
| 101 | // int batch = 32, Nfft = 15000; // c2c mixed | 94 | // int batch = 32, Nfft = 15000; // c2c mixed |
| 102 | // int batch = 32, Nfft = 32768; // c2c fftn | 95 | // int batch = 32, Nfft = 32768; // c2c fftn |
| @@ -109,10 +102,10 @@ int main() | |||
| 109 | inputHostData[i] = std::complex<float>(i, i + 1); | 102 | inputHostData[i] = std::complex<float>(i, i + 1); |
| 110 | } | 103 | } |
| 111 | std::vector<std::complex<float>> outHostData(tensorInSize, std::complex<float>(0, 0)); | 104 | std::vector<std::complex<float>> outHostData(tensorInSize, std::complex<float>(0, 0)); |
| 112 | - void *inputDeviceAddr = nullptr; | 105 | + void* inputDeviceAddr = nullptr; |
| 113 | - void *outDeviceAddr = nullptr; | 106 | + void* outDeviceAddr = nullptr; |
| 114 | - aclTensor *input = nullptr; | 107 | + aclTensor* input = nullptr; |
| 115 | - aclTensor *out = nullptr; | 108 | + aclTensor* out = nullptr; |
| 116 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); | 109 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); |
| 117 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 110 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 118 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); | 111 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); |
| @@ -125,12 +118,12 @@ int main() | |||
| 125 | 118 | ||
| 126 | size_t work_size; | 119 | size_t work_size; |
| 127 | asdFftGetWorkspaceSize(handle, work_size); | 120 | asdFftGetWorkspaceSize(handle, work_size); |
| 128 | - void *workspaceAddr = nullptr; | 121 | + void* workspaceAddr = nullptr; |
| 129 | if (work_size > 0) { | 122 | if (work_size > 0) { |
| 130 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 123 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 131 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 124 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 132 | } | 125 | } |
| 133 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 126 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 134 | 127 | ||
| 135 | asdFftSetStream(handle, stream); | 128 | asdFftSetStream(handle, stream); |
| 136 | ASD_STATUS_CHECK(asdFftExecC2C(handle, input, out)); | 129 | ASD_STATUS_CHECK(asdFftExecC2C(handle, input, out)); |
| @@ -142,11 +135,8 @@ int main() | |||
| 142 | 135 | ||
| 143 | auto size = GetShapeSize(outShape); | 136 | auto size = GetShapeSize(outShape); |
| 144 | std::vector<std::complex<float>> outData(size, 0); | 137 | std::vector<std::complex<float>> outData(size, 0); |
| 145 | - ret = aclrtMemcpy(outData.data(), | 138 | + ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(outData[0]), |
| 146 | - outData.size() * sizeof(outData[0]), | 139 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 147 | - outDeviceAddr, | ||
| 148 | - size * sizeof(outData[0]), | ||
| 149 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 150 | 140 | ||
| 151 | // 打印输出tensor值中前16个 | 141 | // 打印输出tensor值中前16个 |
| 152 | for (int64_t i = 0; i < 16; i++) { | 142 | for (int64_t i = 0; i < 16; i++) { |
| @@ -32,11 +32,11 @@ using namespace AsdSip; | |||
| 32 | AsdSip::AspbStatus err_ = (err); \ | 32 | AsdSip::AspbStatus err_ = (err); \ |
| 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 34 | std::cout << "Execute failed." << std::endl; \ | 34 | std::cout << "Execute failed." << std::endl; \ |
| 35 | - exit(-1); \ | 35 | + return -1; \ |
| 36 | } \ | 36 | } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,AscendCL初始化 | 50 | // 固定写法,AscendCL初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,15 +76,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| @@ -115,10 +108,10 @@ int main() | |||
| 115 | inputHostData[i] = std::complex<float>(i, i + 1); | 108 | inputHostData[i] = std::complex<float>(i, i + 1); |
| 116 | } | 109 | } |
| 117 | std::vector<float> outHostData(tensorOutSize, 0); | 110 | std::vector<float> outHostData(tensorOutSize, 0); |
| 118 | - void *inputDeviceAddr = nullptr; | 111 | + void* inputDeviceAddr = nullptr; |
| 119 | - void *outDeviceAddr = nullptr; | 112 | + void* outDeviceAddr = nullptr; |
| 120 | - aclTensor *input = nullptr; | 113 | + aclTensor* input = nullptr; |
| 121 | - aclTensor *out = nullptr; | 114 | + aclTensor* out = nullptr; |
| 122 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); | 115 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); |
| 123 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 116 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 124 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | 117 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); |
| @@ -131,12 +124,12 @@ int main() | |||
| 131 | 124 | ||
| 132 | size_t work_size; | 125 | size_t work_size; |
| 133 | asdFftGetWorkspaceSize(handle, work_size); | 126 | asdFftGetWorkspaceSize(handle, work_size); |
| 134 | - void *workspaceAddr = nullptr; | 127 | + void* workspaceAddr = nullptr; |
| 135 | if (work_size > 0) { | 128 | if (work_size > 0) { |
| 136 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 129 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 137 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 130 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 138 | } | 131 | } |
| 139 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 132 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 140 | 133 | ||
| 141 | asdFftSetStream(handle, stream); | 134 | asdFftSetStream(handle, stream); |
| 142 | ASD_STATUS_CHECK(asdFftExecC2R(handle, input, out)); | 135 | ASD_STATUS_CHECK(asdFftExecC2R(handle, input, out)); |
| @@ -148,11 +141,8 @@ int main() | |||
| 148 | 141 | ||
| 149 | auto size = GetShapeSize(outShape); | 142 | auto size = GetShapeSize(outShape); |
| 150 | std::vector<float> outData(size, 0); | 143 | std::vector<float> outData(size, 0); |
| 151 | - ret = aclrtMemcpy(outData.data(), | 144 | + ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(outData[0]), |
| 152 | - outData.size() * sizeof(outData[0]), | 145 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 153 | - outDeviceAddr, | ||
| 154 | - size * sizeof(outData[0]), | ||
| 155 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 156 | 146 | ||
| 157 | // 打印输出tensor值中前16个 | 147 | // 打印输出tensor值中前16个 |
| 158 | for (int64_t i = 0; i < 16; i++) { | 148 | for (int64_t i = 0; i < 16; i++) { |
| @@ -32,11 +32,11 @@ using namespace AsdSip; | |||
| 32 | AsdSip::AspbStatus err_ = (err); \ | 32 | AsdSip::AspbStatus err_ = (err); \ |
| 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 34 | std::cout << "Execute failed." << std::endl; \ | 34 | std::cout << "Execute failed." << std::endl; \ |
| 35 | - exit(-1); \ | 35 | + return -1; \ |
| 36 | } \ | 36 | } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,AscendCL初始化 | 50 | // 固定写法,AscendCL初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,15 +76,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| @@ -109,10 +102,10 @@ int main() | |||
| 109 | inputHostData[i] = i; | 102 | inputHostData[i] = i; |
| 110 | } | 103 | } |
| 111 | std::vector<std::complex<float>> outHostData(tensorOutSize, std::complex<float>(0, 0)); | 104 | std::vector<std::complex<float>> outHostData(tensorOutSize, std::complex<float>(0, 0)); |
| 112 | - void *inputDeviceAddr = nullptr; | 105 | + void* inputDeviceAddr = nullptr; |
| 113 | - void *outDeviceAddr = nullptr; | 106 | + void* outDeviceAddr = nullptr; |
| 114 | - aclTensor *input = nullptr; | 107 | + aclTensor* input = nullptr; |
| 115 | - aclTensor *out = nullptr; | 108 | + aclTensor* out = nullptr; |
| 116 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_FLOAT, &input); | 109 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_FLOAT, &input); |
| 117 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 110 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 118 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); | 111 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); |
| @@ -125,12 +118,12 @@ int main() | |||
| 125 | 118 | ||
| 126 | size_t work_size; | 119 | size_t work_size; |
| 127 | asdFftGetWorkspaceSize(handle, work_size); | 120 | asdFftGetWorkspaceSize(handle, work_size); |
| 128 | - void *workspaceAddr = nullptr; | 121 | + void* workspaceAddr = nullptr; |
| 129 | if (work_size > 0) { | 122 | if (work_size > 0) { |
| 130 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 123 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 131 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 124 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 132 | } | 125 | } |
| 133 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 126 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 134 | 127 | ||
| 135 | asdFftSetStream(handle, stream); | 128 | asdFftSetStream(handle, stream); |
| 136 | ASD_STATUS_CHECK(asdFftExecR2C(handle, input, out)); | 129 | ASD_STATUS_CHECK(asdFftExecR2C(handle, input, out)); |
| @@ -142,11 +135,8 @@ int main() | |||
| 142 | 135 | ||
| 143 | auto size = GetShapeSize(outShape); | 136 | auto size = GetShapeSize(outShape); |
| 144 | std::vector<std::complex<float>> outData(size, 0); | 137 | std::vector<std::complex<float>> outData(size, 0); |
| 145 | - ret = aclrtMemcpy(outData.data(), | 138 | + ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(outData[0]), |
| 146 | - outData.size() * sizeof(outData[0]), | 139 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 147 | - outDeviceAddr, | ||
| 148 | - size * sizeof(outData[0]), | ||
| 149 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 150 | 140 | ||
| 151 | // 打印输出tensor值中前16个 | 141 | // 打印输出tensor值中前16个 |
| 152 | for (int64_t i = 0; i < 16; i++) { | 142 | for (int64_t i = 0; i < 16; i++) { |
| @@ -32,11 +32,11 @@ using namespace AsdSip; | |||
| 32 | AsdSip::AspbStatus err_ = (err); \ | 32 | AsdSip::AspbStatus err_ = (err); \ |
| 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 34 | std::cout << "Execute failed." << std::endl; \ | 34 | std::cout << "Execute failed." << std::endl; \ |
| 35 | - exit(-1); \ | 35 | + return -1; \ |
| 36 | } \ | 36 | } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,AscendCL初始化 | 50 | // 固定写法,AscendCL初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,15 +76,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| @@ -109,10 +102,10 @@ int main() | |||
| 109 | inputHostData[i] = std::complex<float>(i, i + 1); | 102 | inputHostData[i] = std::complex<float>(i, i + 1); |
| 110 | } | 103 | } |
| 111 | std::vector<std::complex<float>> outHostData(tensorOutSize, std::complex<float>(0, 0)); | 104 | std::vector<std::complex<float>> outHostData(tensorOutSize, std::complex<float>(0, 0)); |
| 112 | - void *inputDeviceAddr = nullptr; | 105 | + void* inputDeviceAddr = nullptr; |
| 113 | - void *outDeviceAddr = nullptr; | 106 | + void* outDeviceAddr = nullptr; |
| 114 | - aclTensor *input = nullptr; | 107 | + aclTensor* input = nullptr; |
| 115 | - aclTensor *out = nullptr; | 108 | + aclTensor* out = nullptr; |
| 116 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); | 109 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); |
| 117 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 110 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 118 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); | 111 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); |
| @@ -123,12 +116,12 @@ int main() | |||
| 123 | asdFftMakePlan2D(handle, Nfft1, Nfft2, asdFftType::ASCEND_FFT_C2C, asdFftDirection::ASCEND_FFT_FORWARD, batch); | 116 | asdFftMakePlan2D(handle, Nfft1, Nfft2, asdFftType::ASCEND_FFT_C2C, asdFftDirection::ASCEND_FFT_FORWARD, batch); |
| 124 | size_t work_size; | 117 | size_t work_size; |
| 125 | asdFftGetWorkspaceSize(handle, work_size); | 118 | asdFftGetWorkspaceSize(handle, work_size); |
| 126 | - void *workspaceAddr = nullptr; | 119 | + void* workspaceAddr = nullptr; |
| 127 | if (work_size > 0) { | 120 | if (work_size > 0) { |
| 128 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 121 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 129 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 122 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 130 | } | 123 | } |
| 131 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 124 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 132 | asdFftSetStream(handle, stream); | 125 | asdFftSetStream(handle, stream); |
| 133 | ASD_STATUS_CHECK(asdFftExecC2C(handle, input, out)); | 126 | ASD_STATUS_CHECK(asdFftExecC2C(handle, input, out)); |
| 134 | ret = aclrtSynchronizeStream(stream); | 127 | ret = aclrtSynchronizeStream(stream); |
| @@ -137,11 +130,8 @@ int main() | |||
| 137 | 130 | ||
| 138 | auto size = GetShapeSize(outShape); | 131 | auto size = GetShapeSize(outShape); |
| 139 | std::vector<std::complex<float>> outData(size, 0); | 132 | std::vector<std::complex<float>> outData(size, 0); |
| 140 | - ret = aclrtMemcpy(outData.data(), | 133 | + ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(outData[0]), |
| 141 | - outData.size() * sizeof(outData[0]), | 134 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 142 | - outDeviceAddr, | ||
| 143 | - size * sizeof(outData[0]), | ||
| 144 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 145 | 135 | ||
| 146 | // 打印输出tensor值中前16个 | 136 | // 打印输出tensor值中前16个 |
| 147 | for (int64_t i = 0; i < 16; i++) { | 137 | for (int64_t i = 0; i < 16; i++) { |
| @@ -32,11 +32,11 @@ using namespace AsdSip; | |||
| 32 | AsdSip::AspbStatus err_ = (err); \ | 32 | AsdSip::AspbStatus err_ = (err); \ |
| 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 34 | std::cout << "Execute failed." << std::endl; \ | 34 | std::cout << "Execute failed." << std::endl; \ |
| 35 | - exit(-1); \ | 35 | + return -1; \ |
| 36 | } \ | 36 | } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,AscendCL初始化 | 50 | // 固定写法,AscendCL初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,15 +76,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| @@ -113,10 +106,10 @@ int main() | |||
| 113 | inputHostData[i] = std::complex<float>(i, i + 1); | 106 | inputHostData[i] = std::complex<float>(i, i + 1); |
| 114 | } | 107 | } |
| 115 | std::vector<float> outHostData(tensorOutSize, 0); | 108 | std::vector<float> outHostData(tensorOutSize, 0); |
| 116 | - void *inputDeviceAddr = nullptr; | 109 | + void* inputDeviceAddr = nullptr; |
| 117 | - void *outDeviceAddr = nullptr; | 110 | + void* outDeviceAddr = nullptr; |
| 118 | - aclTensor *input = nullptr; | 111 | + aclTensor* input = nullptr; |
| 119 | - aclTensor *out = nullptr; | 112 | + aclTensor* out = nullptr; |
| 120 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); | 113 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); |
| 121 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 114 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 122 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | 115 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); |
| @@ -127,12 +120,12 @@ int main() | |||
| 127 | asdFftMakePlan2D(handle, Nfft1, Nfft2, asdFftType::ASCEND_FFT_C2R, asdFftDirection::ASCEND_FFT_FORWARD, batch); | 120 | asdFftMakePlan2D(handle, Nfft1, Nfft2, asdFftType::ASCEND_FFT_C2R, asdFftDirection::ASCEND_FFT_FORWARD, batch); |
| 128 | size_t work_size; | 121 | size_t work_size; |
| 129 | asdFftGetWorkspaceSize(handle, work_size); | 122 | asdFftGetWorkspaceSize(handle, work_size); |
| 130 | - void *workspaceAddr = nullptr; | 123 | + void* workspaceAddr = nullptr; |
| 131 | if (work_size > 0) { | 124 | if (work_size > 0) { |
| 132 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 125 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 133 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 126 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 134 | } | 127 | } |
| 135 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 128 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 136 | asdFftSetStream(handle, stream); | 129 | asdFftSetStream(handle, stream); |
| 137 | ASD_STATUS_CHECK(asdFftExecC2R(handle, input, out)); | 130 | ASD_STATUS_CHECK(asdFftExecC2R(handle, input, out)); |
| 138 | ret = aclrtSynchronizeStream(stream); | 131 | ret = aclrtSynchronizeStream(stream); |
| @@ -141,11 +134,8 @@ int main() | |||
| 141 | 134 | ||
| 142 | auto size = GetShapeSize(outShape); | 135 | auto size = GetShapeSize(outShape); |
| 143 | std::vector<float> outData(size, 0); | 136 | std::vector<float> outData(size, 0); |
| 144 | - ret = aclrtMemcpy(outData.data(), | 137 | + ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(outData[0]), |
| 145 | - outData.size() * sizeof(outData[0]), | 138 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 146 | - outDeviceAddr, | ||
| 147 | - size * sizeof(outData[0]), | ||
| 148 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 149 | 139 | ||
| 150 | // 打印输出tensor值中前16个 | 140 | // 打印输出tensor值中前16个 |
| 151 | for (int64_t i = 0; i < 16; i++) { | 141 | for (int64_t i = 0; i < 16; i++) { |
| @@ -32,11 +32,11 @@ using namespace AsdSip; | |||
| 32 | AsdSip::AspbStatus err_ = (err); \ | 32 | AsdSip::AspbStatus err_ = (err); \ |
| 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 33 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 34 | std::cout << "Execute failed." << std::endl; \ | 34 | std::cout << "Execute failed." << std::endl; \ |
| 35 | - exit(-1); \ | 35 | + return -1; \ |
| 36 | } \ | 36 | } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,AscendCL初始化 | 50 | // 固定写法,AscendCL初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,15 +76,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| @@ -108,10 +101,10 @@ int main() | |||
| 108 | inputHostData[i] = i; | 101 | inputHostData[i] = i; |
| 109 | } | 102 | } |
| 110 | std::vector<std::complex<float>> outHostData(tensorOutSize, std::complex<float>(0, 0)); | 103 | std::vector<std::complex<float>> outHostData(tensorOutSize, std::complex<float>(0, 0)); |
| 111 | - void *inputDeviceAddr = nullptr; | 104 | + void* inputDeviceAddr = nullptr; |
| 112 | - void *outDeviceAddr = nullptr; | 105 | + void* outDeviceAddr = nullptr; |
| 113 | - aclTensor *input = nullptr; | 106 | + aclTensor* input = nullptr; |
| 114 | - aclTensor *out = nullptr; | 107 | + aclTensor* out = nullptr; |
| 115 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_FLOAT, &input); | 108 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_FLOAT, &input); |
| 116 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 109 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 117 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); | 110 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); |
| @@ -122,12 +115,12 @@ int main() | |||
| 122 | asdFftMakePlan2D(handle, Nfft1, Nfft2, asdFftType::ASCEND_FFT_R2C, asdFftDirection::ASCEND_FFT_FORWARD, batch); | 115 | asdFftMakePlan2D(handle, Nfft1, Nfft2, asdFftType::ASCEND_FFT_R2C, asdFftDirection::ASCEND_FFT_FORWARD, batch); |
| 123 | size_t work_size; | 116 | size_t work_size; |
| 124 | asdFftGetWorkspaceSize(handle, work_size); | 117 | asdFftGetWorkspaceSize(handle, work_size); |
| 125 | - void *workspaceAddr = nullptr; | 118 | + void* workspaceAddr = nullptr; |
| 126 | if (work_size > 0) { | 119 | if (work_size > 0) { |
| 127 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 120 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 128 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 121 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 129 | } | 122 | } |
| 130 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 123 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 131 | asdFftSetStream(handle, stream); | 124 | asdFftSetStream(handle, stream); |
| 132 | ASD_STATUS_CHECK(asdFftExecR2C(handle, input, out)); | 125 | ASD_STATUS_CHECK(asdFftExecR2C(handle, input, out)); |
| 133 | ret = aclrtSynchronizeStream(stream); | 126 | ret = aclrtSynchronizeStream(stream); |
| @@ -136,11 +129,8 @@ int main() | |||
| 136 | 129 | ||
| 137 | auto size = GetShapeSize(outShape); | 130 | auto size = GetShapeSize(outShape); |
| 138 | std::vector<std::complex<float>> outData(size, 0); | 131 | std::vector<std::complex<float>> outData(size, 0); |
| 139 | - ret = aclrtMemcpy(outData.data(), | 132 | + ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(outData[0]), |
| 140 | - outData.size() * sizeof(outData[0]), | 133 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 141 | - outDeviceAddr, | ||
| 142 | - size * sizeof(outData[0]), | ||
| 143 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 144 | 134 | ||
| 145 | // 打印输出tensor值中前16个 | 135 | // 打印输出tensor值中前16个 |
| 146 | for (int64_t i = 0; i < 16; i++) { | 136 | for (int64_t i = 0; i < 16; i++) { |
| @@ -27,16 +27,16 @@ using namespace AsdSip; | |||
| 27 | printf(message, ##__VA_ARGS__); \ | 27 | printf(message, ##__VA_ARGS__); \ |
| 28 | } while (0) | 28 | } while (0) |
| 29 | 29 | ||
| 30 | -#define ASD_STATUS_CHECK(err) \ | 30 | +#define ASD_STATUS_CHECK(err) \ |
| 31 | - do { \ | 31 | + do { \ |
| 32 | - AsdSip::AspbStatus err_ = (err); \ | 32 | + AsdSip::AspbStatus err_ = (err); \ |
| 33 | - if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 33 | + if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 34 | std::cout << "Execute failed." << std::endl; \ | 34 | std::cout << "Execute failed." << std::endl; \ |
| 35 | - exit(-1); \ | 35 | + return -1; \ |
| 36 | - } \ | 36 | + } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,AscendCL初始化 | 50 | // 固定写法,AscendCL初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,20 +76,13 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| 91 | - | 84 | +int main() |
| 92 | -int main() { | 85 | +{ |
| 93 | int32_t deviceId = 0; | 86 | int32_t deviceId = 0; |
| 94 | aclrtStream stream; | 87 | aclrtStream stream; |
| 95 | auto ret = Init(deviceId, &stream); | 88 | auto ret = Init(deviceId, &stream); |
| @@ -107,10 +100,10 @@ int main() { | |||
| 107 | } | 100 | } |
| 108 | std::vector<std::complex<float>> outHostData(tensorInSize, std::complex<float>(0, 0)); | 101 | std::vector<std::complex<float>> outHostData(tensorInSize, std::complex<float>(0, 0)); |
| 109 | 102 | ||
| 110 | - void *inputDeviceAddr = nullptr; | 103 | + void* inputDeviceAddr = nullptr; |
| 111 | - void *outDeviceAddr = nullptr; | 104 | + void* outDeviceAddr = nullptr; |
| 112 | - aclTensor *input = nullptr; | 105 | + aclTensor* input = nullptr; |
| 113 | - aclTensor *out = nullptr; | 106 | + aclTensor* out = nullptr; |
| 114 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); | 107 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); |
| 115 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 108 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 116 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); | 109 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); |
| @@ -119,16 +112,17 @@ int main() { | |||
| 119 | asdFftHandle handle; | 112 | asdFftHandle handle; |
| 120 | asdFftCreate(handle); | 113 | asdFftCreate(handle); |
| 121 | 114 | ||
| 122 | - asdFftMakePlan3D(handle, Nfft1, Nfft2, Nfft3, asdFftType::ASCEND_FFT_C2C, asdFftDirection::ASCEND_FFT_FORWARD, batch); | 115 | + asdFftMakePlan3D(handle, Nfft1, Nfft2, Nfft3, asdFftType::ASCEND_FFT_C2C, asdFftDirection::ASCEND_FFT_FORWARD, |
| 116 | + batch); | ||
| 123 | 117 | ||
| 124 | size_t work_size; | 118 | size_t work_size; |
| 125 | asdFftGetWorkspaceSize(handle, work_size); | 119 | asdFftGetWorkspaceSize(handle, work_size); |
| 126 | - void *workspaceAddr = nullptr; | 120 | + void* workspaceAddr = nullptr; |
| 127 | if (work_size > 0) { | 121 | if (work_size > 0) { |
| 128 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 122 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 129 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 123 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 130 | } | 124 | } |
| 131 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 125 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 132 | 126 | ||
| 133 | asdFftSetStream(handle, stream); | 127 | asdFftSetStream(handle, stream); |
| 134 | ASD_STATUS_CHECK(asdFftExecC2C(handle, input, out)); | 128 | ASD_STATUS_CHECK(asdFftExecC2C(handle, input, out)); |
| @@ -140,11 +134,8 @@ int main() { | |||
| 140 | 134 | ||
| 141 | auto size = GetShapeSize(outShape); | 135 | auto size = GetShapeSize(outShape); |
| 142 | std::vector<std::complex<float>> outData(size, 0); | 136 | std::vector<std::complex<float>> outData(size, 0); |
| 143 | - ret = aclrtMemcpy(outData.data(), | 137 | + ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(outData[0]), |
| 144 | - outData.size() * sizeof(outData[0]), | 138 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 145 | - outDeviceAddr, | ||
| 146 | - size * sizeof(outData[0]), | ||
| 147 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 148 | 139 | ||
| 149 | // 打印输出tensor值中前16个 | 140 | // 打印输出tensor值中前16个 |
| 150 | for (int64_t i = 0; i < std::min(static_cast<int64_t>(16), tensorInSize); i++) { | 141 | for (int64_t i = 0; i < std::min(static_cast<int64_t>(16), tensorInSize); i++) { |
| @@ -165,4 +156,4 @@ int main() { | |||
| 165 | aclrtResetDevice(deviceId); | 156 | aclrtResetDevice(deviceId); |
| 166 | aclFinalize(); | 157 | aclFinalize(); |
| 167 | return 0; | 158 | return 0; |
| 168 | -} | 159 | +} |
| @@ -29,16 +29,16 @@ using namespace AsdSip; | |||
| 29 | printf(message, ##__VA_ARGS__); \ | 29 | printf(message, ##__VA_ARGS__); \ |
| 30 | } while (0) | 30 | } while (0) |
| 31 | 31 | ||
| 32 | -#define ASD_STATUS_CHECK(err) \ | 32 | +#define ASD_STATUS_CHECK(err) \ |
| 33 | - do { \ | 33 | + do { \ |
| 34 | - AsdSip::AspbStatus err_ = (err); \ | 34 | + AsdSip::AspbStatus err_ = (err); \ |
| 35 | - if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 35 | + if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 36 | std::cout << "Execute failed." << std::endl; \ | 36 | std::cout << "Execute failed." << std::endl; \ |
| 37 | - exit(-1); \ | 37 | + return -1; \ |
| 38 | - } \ | 38 | + } \ |
| 39 | } while (0) | 39 | } while (0) |
| 40 | 40 | ||
| 41 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 41 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 42 | { | 42 | { |
| 43 | int64_t shapeSize = 1; | 43 | int64_t shapeSize = 1; |
| 44 | for (auto i : shape) { | 44 | for (auto i : shape) { |
| @@ -47,7 +47,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 47 | return shapeSize; | 47 | return shapeSize; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | -int Init(int32_t deviceId, aclrtStream *stream) | 50 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 51 | { | 51 | { |
| 52 | // 固定写法,AscendCL初始化 | 52 | // 固定写法,AscendCL初始化 |
| 53 | auto ret = aclInit(nullptr); | 53 | auto ret = aclInit(nullptr); |
| @@ -60,8 +60,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | template <typename T> | 62 | template <typename T> |
| 63 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 63 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 64 | - aclDataType dataType, aclTensor **tensor) | 64 | + aclDataType dataType, aclTensor** tensor) |
| 65 | { | 65 | { |
| 66 | auto size = GetShapeSize(shape) * sizeof(T); | 66 | auto size = GetShapeSize(shape) * sizeof(T); |
| 67 | // 调用aclrtMalloc申请device侧内存 | 67 | // 调用aclrtMalloc申请device侧内存 |
| @@ -78,15 +78,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | // 调用aclCreateTensor接口创建aclTensor | 80 | // 调用aclCreateTensor接口创建aclTensor |
| 81 | - *tensor = aclCreateTensor(shape.data(), | 81 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 82 | - shape.size(), | 82 | + shape.data(), shape.size(), *deviceAddr); |
| 83 | - dataType, | ||
| 84 | - strides.data(), | ||
| 85 | - 0, | ||
| 86 | - aclFormat::ACL_FORMAT_ND, | ||
| 87 | - shape.data(), | ||
| 88 | - shape.size(), | ||
| 89 | - *deviceAddr); | ||
| 90 | return 0; | 83 | return 0; |
| 91 | } | 84 | } |
| 92 | 85 | ||
| @@ -123,15 +116,15 @@ int main() | |||
| 123 | inputImagHostData[i] = dis(gen); | 116 | inputImagHostData[i] = dis(gen); |
| 124 | } | 117 | } |
| 125 | 118 | ||
| 126 | - void *inputRealDeviceAddr = nullptr; | 119 | + void* inputRealDeviceAddr = nullptr; |
| 127 | - void *inputImagDeviceAddr = nullptr; | 120 | + void* inputImagDeviceAddr = nullptr; |
| 128 | - void *outputRealDeviceAddr = nullptr; | 121 | + void* outputRealDeviceAddr = nullptr; |
| 129 | - void *outputImagDeviceAddr = nullptr; | 122 | + void* outputImagDeviceAddr = nullptr; |
| 130 | 123 | ||
| 131 | - aclTensor *inputReal = nullptr; | 124 | + aclTensor* inputReal = nullptr; |
| 132 | - aclTensor *inputImag = nullptr; | 125 | + aclTensor* inputImag = nullptr; |
| 133 | - aclTensor *outputReal = nullptr; | 126 | + aclTensor* outputReal = nullptr; |
| 134 | - aclTensor *outputImag = nullptr; | 127 | + aclTensor* outputImag = nullptr; |
| 135 | 128 | ||
| 136 | ret = CreateAclTensor(inputRealHostData, selfShape, &inputRealDeviceAddr, aclDataType::ACL_FLOAT, &inputReal); | 129 | ret = CreateAclTensor(inputRealHostData, selfShape, &inputRealDeviceAddr, aclDataType::ACL_FLOAT, &inputReal); |
| 137 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 130 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| @@ -146,16 +139,17 @@ int main() | |||
| 146 | asdFftHandle handle; | 139 | asdFftHandle handle; |
| 147 | asdFftCreate(handle); | 140 | asdFftCreate(handle); |
| 148 | 141 | ||
| 149 | - asdFftMakePlan3D(handle, Nfft1, Nfft2, Nfft3, asdFftType::ASCEND_FFT_C2C_SEP, asdFftDirection::ASCEND_FFT_FORWARD, batch); | 142 | + asdFftMakePlan3D(handle, Nfft1, Nfft2, Nfft3, asdFftType::ASCEND_FFT_C2C_SEP, asdFftDirection::ASCEND_FFT_FORWARD, |
| 143 | + batch); | ||
| 150 | 144 | ||
| 151 | size_t work_size; | 145 | size_t work_size; |
| 152 | asdFftGetWorkspaceSize(handle, work_size); | 146 | asdFftGetWorkspaceSize(handle, work_size); |
| 153 | - void *workspaceAddr = nullptr; | 147 | + void* workspaceAddr = nullptr; |
| 154 | if (work_size > 0) { | 148 | if (work_size > 0) { |
| 155 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 149 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 156 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 150 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 157 | } | 151 | } |
| 158 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 152 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 159 | 153 | ||
| 160 | asdFftSetStream(handle, stream); | 154 | asdFftSetStream(handle, stream); |
| 161 | ASD_STATUS_CHECK(asdFftExecC2CSeparated(handle, inputReal, inputImag, outputReal, outputImag)); | 155 | ASD_STATUS_CHECK(asdFftExecC2CSeparated(handle, inputReal, inputImag, outputReal, outputImag)); |
| @@ -170,23 +164,14 @@ int main() | |||
| 170 | std::vector<float> outImagData(size, 0); | 164 | std::vector<float> outImagData(size, 0); |
| 171 | std::vector<float> workspaceData(size * 2, -1); | 165 | std::vector<float> workspaceData(size * 2, -1); |
| 172 | 166 | ||
| 173 | - ret = aclrtMemcpy(outRealData.data(), | 167 | + ret = aclrtMemcpy(outRealData.data(), outRealData.size() * sizeof(outRealData[0]), outputRealDeviceAddr, |
| 174 | - outRealData.size() * sizeof(outRealData[0]), | 168 | + size * sizeof(outRealData[0]), ACL_MEMCPY_DEVICE_TO_HOST); |
| 175 | - outputRealDeviceAddr, | ||
| 176 | - size * sizeof(outRealData[0]), | ||
| 177 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 178 | 169 | ||
| 179 | - ret = aclrtMemcpy(outImagData.data(), | 170 | + ret = aclrtMemcpy(outImagData.data(), outImagData.size() * sizeof(outImagData[0]), outputImagDeviceAddr, |
| 180 | - outImagData.size() * sizeof(outImagData[0]), | 171 | + size * sizeof(outImagData[0]), ACL_MEMCPY_DEVICE_TO_HOST); |
| 181 | - outputImagDeviceAddr, | ||
| 182 | - size * sizeof(outImagData[0]), | ||
| 183 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 184 | 172 | ||
| 185 | - ret = aclrtMemcpy(workspaceData.data(), | 173 | + ret = aclrtMemcpy(workspaceData.data(), workspaceData.size() * sizeof(workspaceData[0]), workspaceAddr, |
| 186 | - workspaceData.size() * sizeof(workspaceData[0]), | 174 | + workspaceData.size() * sizeof(workspaceData[0]), ACL_MEMCPY_DEVICE_TO_HOST); |
| 187 | - workspaceAddr, | ||
| 188 | - workspaceData.size() * sizeof(workspaceData[0]), | ||
| 189 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 190 | 175 | ||
| 191 | // 打印输出tensor值中前16个 | 176 | // 打印输出tensor值中前16个 |
| 192 | std::cout << "real part:" << std::endl; | 177 | std::cout << "real part:" << std::endl; |
| @@ -227,4 +212,4 @@ int main() | |||
| 227 | aclrtResetDevice(deviceId); | 212 | aclrtResetDevice(deviceId); |
| 228 | aclFinalize(); | 213 | aclFinalize(); |
| 229 | return 0; | 214 | return 0; |
| 230 | -} | 215 | +} |
| @@ -27,16 +27,16 @@ using namespace AsdSip; | |||
| 27 | printf(message, ##__VA_ARGS__); \ | 27 | printf(message, ##__VA_ARGS__); \ |
| 28 | } while (0) | 28 | } while (0) |
| 29 | 29 | ||
| 30 | -#define ASD_STATUS_CHECK(err) \ | 30 | +#define ASD_STATUS_CHECK(err) \ |
| 31 | - do { \ | 31 | + do { \ |
| 32 | - AsdSip::AspbStatus err_ = (err); \ | 32 | + AsdSip::AspbStatus err_ = (err); \ |
| 33 | - if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 33 | + if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 34 | std::cout << "Execute failed." << std::endl; \ | 34 | std::cout << "Execute failed." << std::endl; \ |
| 35 | - exit(-1); \ | 35 | + return -1; \ |
| 36 | - } \ | 36 | + } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,AscendCL初始化 | 50 | // 固定写法,AscendCL初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,19 +76,11 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| 91 | - | ||
| 92 | int main() | 84 | int main() |
| 93 | { | 85 | { |
| 94 | int32_t deviceId = 0; | 86 | int32_t deviceId = 0; |
| @@ -109,10 +101,10 @@ int main() | |||
| 109 | inputHostData[i] = std::complex<float>(i, i + 1); | 101 | inputHostData[i] = std::complex<float>(i, i + 1); |
| 110 | } | 102 | } |
| 111 | std::vector<float> outHostData(tensorOutSize, 0); | 103 | std::vector<float> outHostData(tensorOutSize, 0); |
| 112 | - void *inputDeviceAddr = nullptr; | 104 | + void* inputDeviceAddr = nullptr; |
| 113 | - void *outDeviceAddr = nullptr; | 105 | + void* outDeviceAddr = nullptr; |
| 114 | - aclTensor *input = nullptr; | 106 | + aclTensor* input = nullptr; |
| 115 | - aclTensor *out = nullptr; | 107 | + aclTensor* out = nullptr; |
| 116 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); | 108 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_COMPLEX64, &input); |
| 117 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 109 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 118 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | 110 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); |
| @@ -120,16 +112,17 @@ int main() | |||
| 120 | asdFftHandle handle; | 112 | asdFftHandle handle; |
| 121 | asdFftCreate(handle); | 113 | asdFftCreate(handle); |
| 122 | 114 | ||
| 123 | - asdFftMakePlan3D(handle, Nfft1, Nfft2, Nfft3, asdFftType::ASCEND_FFT_C2R, asdFftDirection::ASCEND_FFT_FORWARD, batch); | 115 | + asdFftMakePlan3D(handle, Nfft1, Nfft2, Nfft3, asdFftType::ASCEND_FFT_C2R, asdFftDirection::ASCEND_FFT_FORWARD, |
| 116 | + batch); | ||
| 124 | 117 | ||
| 125 | size_t work_size; | 118 | size_t work_size; |
| 126 | asdFftGetWorkspaceSize(handle, work_size); | 119 | asdFftGetWorkspaceSize(handle, work_size); |
| 127 | - void *workspaceAddr = nullptr; | 120 | + void* workspaceAddr = nullptr; |
| 128 | if (work_size > 0) { | 121 | if (work_size > 0) { |
| 129 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 122 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 130 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 123 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 131 | } | 124 | } |
| 132 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 125 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 133 | 126 | ||
| 134 | asdFftSetStream(handle, stream); | 127 | asdFftSetStream(handle, stream); |
| 135 | ASD_STATUS_CHECK(asdFftExecC2R(handle, input, out)); | 128 | ASD_STATUS_CHECK(asdFftExecC2R(handle, input, out)); |
| @@ -141,11 +134,8 @@ int main() | |||
| 141 | 134 | ||
| 142 | auto size = GetShapeSize(outShape); | 135 | auto size = GetShapeSize(outShape); |
| 143 | std::vector<float> outData(size, 0); | 136 | std::vector<float> outData(size, 0); |
| 144 | - ret = aclrtMemcpy(outData.data(), | 137 | + ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(outData[0]), |
| 145 | - outData.size() * sizeof(outData[0]), | 138 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 146 | - outDeviceAddr, | ||
| 147 | - size * sizeof(outData[0]), | ||
| 148 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 149 | 139 | ||
| 150 | // 打印输出tensor值中前16个 | 140 | // 打印输出tensor值中前16个 |
| 151 | for (int64_t i = 0; i < std::min(static_cast<int64_t>(16), tensorOutSize); i++) { | 141 | for (int64_t i = 0; i < std::min(static_cast<int64_t>(16), tensorOutSize); i++) { |
| @@ -166,4 +156,4 @@ int main() | |||
| 166 | aclrtResetDevice(deviceId); | 156 | aclrtResetDevice(deviceId); |
| 167 | aclFinalize(); | 157 | aclFinalize(); |
| 168 | return 0; | 158 | return 0; |
| 169 | -} | 159 | +} |
| @@ -27,16 +27,16 @@ using namespace AsdSip; | |||
| 27 | printf(message, ##__VA_ARGS__); \ | 27 | printf(message, ##__VA_ARGS__); \ |
| 28 | } while (0) | 28 | } while (0) |
| 29 | 29 | ||
| 30 | -#define ASD_STATUS_CHECK(err) \ | 30 | +#define ASD_STATUS_CHECK(err) \ |
| 31 | - do { \ | 31 | + do { \ |
| 32 | - AsdSip::AspbStatus err_ = (err); \ | 32 | + AsdSip::AspbStatus err_ = (err); \ |
| 33 | - if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 33 | + if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 34 | std::cout << "Execute failed." << std::endl; \ | 34 | std::cout << "Execute failed." << std::endl; \ |
| 35 | - exit(-1); \ | 35 | + return -1; \ |
| 36 | - } \ | 36 | + } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | -int64_t GetShapeSize(const std::vector<int64_t> &shape) | 39 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 40 | { | 40 | { |
| 41 | int64_t shapeSize = 1; | 41 | int64_t shapeSize = 1; |
| 42 | for (auto i : shape) { | 42 | for (auto i : shape) { |
| @@ -45,7 +45,7 @@ int64_t GetShapeSize(const std::vector<int64_t> &shape) | |||
| 45 | return shapeSize; | 45 | return shapeSize; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int Init(int32_t deviceId, aclrtStream *stream) | 48 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 49 | { | 49 | { |
| 50 | // 固定写法,AscendCL初始化 | 50 | // 固定写法,AscendCL初始化 |
| 51 | auto ret = aclInit(nullptr); | 51 | auto ret = aclInit(nullptr); |
| @@ -58,8 +58,8 @@ int Init(int32_t deviceId, aclrtStream *stream) | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | -int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> &shape, void **deviceAddr, | 61 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 62 | - aclDataType dataType, aclTensor **tensor) | 62 | + aclDataType dataType, aclTensor** tensor) |
| 63 | { | 63 | { |
| 64 | auto size = GetShapeSize(shape) * sizeof(T); | 64 | auto size = GetShapeSize(shape) * sizeof(T); |
| 65 | // 调用aclrtMalloc申请device侧内存 | 65 | // 调用aclrtMalloc申请device侧内存 |
| @@ -76,15 +76,8 @@ int CreateAclTensor(const std::vector<T> &hostData, const std::vector<int64_t> & | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // 调用aclCreateTensor接口创建aclTensor | 78 | // 调用aclCreateTensor接口创建aclTensor |
| 79 | - *tensor = aclCreateTensor(shape.data(), | 79 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 80 | - shape.size(), | 80 | + shape.data(), shape.size(), *deviceAddr); |
| 81 | - dataType, | ||
| 82 | - strides.data(), | ||
| 83 | - 0, | ||
| 84 | - aclFormat::ACL_FORMAT_ND, | ||
| 85 | - shape.data(), | ||
| 86 | - shape.size(), | ||
| 87 | - *deviceAddr); | ||
| 88 | return 0; | 81 | return 0; |
| 89 | } | 82 | } |
| 90 | 83 | ||
| @@ -108,10 +101,10 @@ int main() | |||
| 108 | } | 101 | } |
| 109 | std::vector<std::complex<float>> outHostData(tensorInSize, std::complex<float>(0, 0)); | 102 | std::vector<std::complex<float>> outHostData(tensorInSize, std::complex<float>(0, 0)); |
| 110 | 103 | ||
| 111 | - void *inputDeviceAddr = nullptr; | 104 | + void* inputDeviceAddr = nullptr; |
| 112 | - void *outDeviceAddr = nullptr; | 105 | + void* outDeviceAddr = nullptr; |
| 113 | - aclTensor *input = nullptr; | 106 | + aclTensor* input = nullptr; |
| 114 | - aclTensor *out = nullptr; | 107 | + aclTensor* out = nullptr; |
| 115 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_FLOAT, &input); | 108 | ret = CreateAclTensor(inputHostData, selfShape, &inputDeviceAddr, aclDataType::ACL_FLOAT, &input); |
| 116 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); | 109 | CHECK_RET(ret == ::ACL_SUCCESS, return ret); |
| 117 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); | 110 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_COMPLEX64, &out); |
| @@ -120,16 +113,17 @@ int main() | |||
| 120 | asdFftHandle handle; | 113 | asdFftHandle handle; |
| 121 | asdFftCreate(handle); | 114 | asdFftCreate(handle); |
| 122 | 115 | ||
| 123 | - asdFftMakePlan3D(handle, Nfft1, Nfft2, Nfft3, asdFftType::ASCEND_FFT_R2C, asdFftDirection::ASCEND_FFT_FORWARD, batch); | 116 | + asdFftMakePlan3D(handle, Nfft1, Nfft2, Nfft3, asdFftType::ASCEND_FFT_R2C, asdFftDirection::ASCEND_FFT_FORWARD, |
| 117 | + batch); | ||
| 124 | 118 | ||
| 125 | size_t work_size; | 119 | size_t work_size; |
| 126 | asdFftGetWorkspaceSize(handle, work_size); | 120 | asdFftGetWorkspaceSize(handle, work_size); |
| 127 | - void *workspaceAddr = nullptr; | 121 | + void* workspaceAddr = nullptr; |
| 128 | if (work_size > 0) { | 122 | if (work_size > 0) { |
| 129 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); | 123 | ret = aclrtMalloc(&workspaceAddr, static_cast<int64_t>(work_size), ACL_MEM_MALLOC_HUGE_FIRST); |
| 130 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 124 | CHECK_RET(ret == ::ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 131 | } | 125 | } |
| 132 | - asdFftSetWorkspace(handle, (uint8_t *)workspaceAddr); | 126 | + asdFftSetWorkspace(handle, (uint8_t*)workspaceAddr); |
| 133 | 127 | ||
| 134 | asdFftSetStream(handle, stream); | 128 | asdFftSetStream(handle, stream); |
| 135 | ASD_STATUS_CHECK(asdFftExecR2C(handle, input, out)); | 129 | ASD_STATUS_CHECK(asdFftExecR2C(handle, input, out)); |
| @@ -141,11 +135,8 @@ int main() | |||
| 141 | 135 | ||
| 142 | auto size = GetShapeSize(outShape); | 136 | auto size = GetShapeSize(outShape); |
| 143 | std::vector<std::complex<float>> outData(size, 0); | 137 | std::vector<std::complex<float>> outData(size, 0); |
| 144 | - ret = aclrtMemcpy(outData.data(), | 138 | + ret = aclrtMemcpy(outData.data(), outData.size() * sizeof(outData[0]), outDeviceAddr, size * sizeof(outData[0]), |
| 145 | - outData.size() * sizeof(outData[0]), | 139 | + ACL_MEMCPY_DEVICE_TO_HOST); |
| 146 | - outDeviceAddr, | ||
| 147 | - size * sizeof(outData[0]), | ||
| 148 | - ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 149 | 140 | ||
| 150 | // 打印输出tensor值中前16个 | 141 | // 打印输出tensor值中前16个 |
| 151 | for (int64_t i = 0; i < std::min(static_cast<int64_t>(16), tensorOutSize); i++) { | 142 | for (int64_t i = 0; i < std::min(static_cast<int64_t>(16), tensorOutSize); i++) { |
| @@ -166,4 +157,4 @@ int main() | |||
| 166 | aclrtResetDevice(deviceId); | 157 | aclrtResetDevice(deviceId); |
| 167 | aclFinalize(); | 158 | aclFinalize(); |
| 168 | return 0; | 159 | return 0; |
| 169 | -} | 160 | +} |
| @@ -25,7 +25,7 @@ using half = op::fp16_t; | |||
| 25 | AsdSip::AspbStatus err_ = (err); \ | 25 | AsdSip::AspbStatus err_ = (err); \ |
| 26 | if (err_ != AsdSip::ACL_SUCCESS) { \ | 26 | if (err_ != AsdSip::ACL_SUCCESS) { \ |
| 27 | std::cout << "Execute failed." << std::endl; \ | 27 | std::cout << "Execute failed." << std::endl; \ |
| 28 | - exit(-1); \ | 28 | + return -1; \ |
| 29 | } \ | 29 | } \ |
| 30 | } while (0) | 30 | } while (0) |
| 31 | 31 | ||
| @@ -24,7 +24,7 @@ using namespace AsdSip; | |||
| 24 | AsdSip::AspbStatus err_ = (err); \ | 24 | AsdSip::AspbStatus err_ = (err); \ |
| 25 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ | 25 | if (err_ != AsdSip::ErrorType::ACL_SUCCESS) { \ |
| 26 | std::cout << "Execute failed." << std::endl; \ | 26 | std::cout << "Execute failed." << std::endl; \ |
| 27 | - exit(-1); \ | 27 | + return -1; \ |
| 28 | } \ | 28 | } \ |
| 29 | } while (0) | 29 | } while (0) |
| 30 | 30 | ||
| @@ -362,8 +362,7 @@ install_dos2unix() { | |||
| 362 | if command -v dos2unix &> /dev/null; then | 362 | if command -v dos2unix &> /dev/null; then |
| 363 | echo "dos2unix installed successfully" | 363 | echo "dos2unix installed successfully" |
| 364 | else | 364 | else |
| 365 | - echo "dos2unix installation failed" | 365 | + echo "dos2unix installation failed, can be ignored" |
| 366 | - exit 1 | ||
| 367 | fi | 366 | fi |
| 368 | } | 367 | } |
| 369 | 368 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | # -*- coding: UTF-8 -*- | 1 | # -*- coding: UTF-8 -*- |
| 2 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 3 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 4 | # CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | # CANN Open Software License Agreement Version 2.0 (the "License"). |
| 5 | # Please refer to the License for details. You may not use this file except in compliance with the License. | 5 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -7,45 +7,46 @@ | |||
| 7 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 7 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 8 | # See LICENSE in the root of the software repository for the full text of the License. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 9 | 9 | ||
| 10 | -import os | ||
| 11 | import configparser | 10 | import configparser |
| 12 | import json | 11 | import json |
| 13 | import logging | 12 | import logging |
| 13 | +import os | ||
| 14 | import shutil | 14 | import shutil |
| 15 | import stat | 15 | import stat |
| 16 | -import re | 16 | +import sys |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | # sycl-target --show-targets | 19 | # sycl-target --show-targets |
| 20 | def get_build_target_list(): | 20 | def get_build_target_list(): |
| 21 | - usr_config_file_path = os.getenv("BUILD_CONFIG_FILE", '') | 21 | + usr_config_file_path = os.getenv("BUILD_CONFIG_FILE", "") |
| 22 | - if usr_config_file_path == '': | 22 | + if usr_config_file_path == "": |
| 23 | script_file_path = os.path.realpath(__file__) | 23 | script_file_path = os.path.realpath(__file__) |
| 24 | - build_config_json_file_path = os.path.join(os.path.dirname( | 24 | + build_config_json_file_path = os.path.join( |
| 25 | - script_file_path), "../configs/build_config.json") | 25 | + os.path.dirname(script_file_path), "../configs/build_config.json" |
| 26 | + ) | ||
| 26 | else: | 27 | else: |
| 27 | build_config_json_file_path = usr_config_file_path | 28 | build_config_json_file_path = usr_config_file_path |
| 28 | device_list = [] | 29 | device_list = [] |
| 29 | try: | 30 | try: |
| 30 | with open(build_config_json_file_path) as conf_file: | 31 | with open(build_config_json_file_path) as conf_file: |
| 31 | conf = json.load(conf_file) | 32 | conf = json.load(conf_file) |
| 32 | - target_option = conf['targets'] | 33 | + target_option = conf["targets"] |
| 33 | for target, switch in target_option.items(): | 34 | for target, switch in target_option.items(): |
| 34 | if switch is True: | 35 | if switch is True: |
| 35 | device_list.append(target) | 36 | device_list.append(target) |
| 36 | except FileNotFoundError: | 37 | except FileNotFoundError: |
| 37 | logging.error("file %s is not found!", build_config_json_file_path) | 38 | logging.error("file %s is not found!", build_config_json_file_path) |
| 38 | - exit(1) | 39 | + sys.exit(1) |
| 39 | except json.decoder.JSONDecodeError: | 40 | except json.decoder.JSONDecodeError: |
| 40 | logging.error("file %s is not json file!", build_config_json_file_path) | 41 | logging.error("file %s is not json file!", build_config_json_file_path) |
| 41 | - exit(1) | 42 | + sys.exit(1) |
| 42 | except KeyError: | 43 | except KeyError: |
| 43 | logging.error("key 'targets' is not found in %s!", build_config_json_file_path) | 44 | logging.error("key 'targets' is not found in %s!", build_config_json_file_path) |
| 44 | - exit(1) | 45 | + sys.exit(1) |
| 45 | 46 | ||
| 46 | if len(device_list) == 0: | 47 | if len(device_list) == 0: |
| 47 | logging.error("no target device is set") | 48 | logging.error("no target device is set") |
| 48 | - exit(1) | 49 | + sys.exit(1) |
| 49 | 50 | ||
| 50 | device_list = list(set(device_list)) | 51 | device_list = list(set(device_list)) |
| 51 | return device_list | 52 | return device_list |
| @@ -53,10 +54,12 @@ def get_build_target_list(): | |||
| 53 | 54 | ||
| 54 | def get_info_from_file(file_path): | 55 | def get_info_from_file(file_path): |
| 55 | result = True | 56 | result = True |
| 56 | - tactic_info = dict() | 57 | + tactic_info = {} |
| 57 | - magic_dict = {"RT_DEV_BINARY_MAGIC_ELF": str(0x43554245), | 58 | + magic_dict = { |
| 58 | - "RT_DEV_BINARY_MAGIC_ELF_AIVEC": str(0x41415246), | 59 | + "RT_DEV_BINARY_MAGIC_ELF": str(0x43554245), |
| 59 | - "RT_DEV_BINARY_MAGIC_ELF_AICUBE": str(0x41494343)} | 60 | + "RT_DEV_BINARY_MAGIC_ELF_AIVEC": str(0x41415246), |
| 61 | + "RT_DEV_BINARY_MAGIC_ELF_AICUBE": str(0x41494343), | ||
| 62 | + } | ||
| 60 | try: | 63 | try: |
| 61 | with open(file_path) as f: | 64 | with open(file_path) as f: |
| 62 | text = json.load(f) | 65 | text = json.load(f) |
| @@ -71,7 +74,7 @@ def get_info_from_file(file_path): | |||
| 71 | else: | 74 | else: |
| 72 | tactic_info["magic"] = magic_dict[magic] | 75 | tactic_info["magic"] = magic_dict[magic] |
| 73 | if "kernelList" in text: | 76 | if "kernelList" in text: |
| 74 | - tactic_info["kernelList"] = ','.join( | 77 | + tactic_info["kernelList"] = ",".join( |
| 75 | item["kernelName"] for item in text["kernelList"] | 78 | item["kernelName"] for item in text["kernelList"] |
| 76 | ) | 79 | ) |
| 77 | else: | 80 | else: |
| @@ -89,8 +92,10 @@ def get_info_from_file(file_path): | |||
| 89 | 92 | ||
| 90 | 93 | ||
| 91 | def write_meta(meta_info, output_path, target_version): | 94 | def write_meta(meta_info, output_path, target_version): |
| 92 | - meta_path = os.path.join(output_path, 'meta.ini') | 95 | + meta_path = os.path.join(output_path, "meta.ini") |
| 93 | - with os.fdopen(os.open(meta_path, os.O_WRONLY | os.O_CREAT, stat.S_IWUSR | stat.S_IRUSR), 'w+') as fmeta: | 96 | + with os.fdopen( |
| 97 | + os.open(meta_path, os.O_WRONLY | os.O_CREAT, stat.S_IWUSR | stat.S_IRUSR), "w+" | ||
| 98 | + ) as fmeta: | ||
| 94 | fmeta.write("$Version=1.0\n") | 99 | fmeta.write("$Version=1.0\n") |
| 95 | fmeta.write(f"DeviceKernelVersion={target_version}\n") | 100 | fmeta.write(f"DeviceKernelVersion={target_version}\n") |
| 96 | fmeta.write(f"$Object.Count={len(meta_info)}\n") | 101 | fmeta.write(f"$Object.Count={len(meta_info)}\n") |
| @@ -107,8 +112,7 @@ def write_meta(meta_info, output_path, target_version): | |||
| 107 | 112 | ||
| 108 | # 目前只支持一个tactic文件夹下一个.o和.json文件 | 113 | # 目前只支持一个tactic文件夹下一个.o和.json文件 |
| 109 | def copy_ascendc_code(meta_info, env_cache_dir, target_version, output_path): | 114 | def copy_ascendc_code(meta_info, env_cache_dir, target_version, output_path): |
| 110 | - op_kernels_version_dir = os.path.join( | 115 | + op_kernels_version_dir = os.path.join(env_cache_dir, "op_kernels", target_version) |
| 111 | - env_cache_dir, "op_kernels", target_version) | ||
| 112 | if not os.path.exists(op_kernels_version_dir): | 116 | if not os.path.exists(op_kernels_version_dir): |
| 113 | return 0 | 117 | return 0 |
| 114 | code_file_count = 0 | 118 | code_file_count = 0 |
| @@ -120,28 +124,34 @@ def copy_ascendc_code(meta_info, env_cache_dir, target_version, output_path): | |||
| 120 | for tactic in os.listdir(operation_dir): | 124 | for tactic in os.listdir(operation_dir): |
| 121 | tactic_dir = os.path.join(operation_dir, tactic) | 125 | tactic_dir = os.path.join(operation_dir, tactic) |
| 122 | for file in os.listdir(tactic_dir): | 126 | for file in os.listdir(tactic_dir): |
| 123 | - if not file.endswith('.json'): | 127 | + if not file.endswith(".json"): |
| 124 | continue | 128 | continue |
| 125 | - code_file = os.path.join(tactic_dir, file[:-4] + 'o') | 129 | + code_file = os.path.join(tactic_dir, file[:-4] + "o") |
| 126 | if not os.path.exists(code_file): | 130 | if not os.path.exists(code_file): |
| 127 | logging.error("file %s has no object file.", file) | 131 | logging.error("file %s has no object file.", file) |
| 128 | - exit(1) | 132 | + sys.exit(1) |
| 129 | json_file = os.path.join(tactic_dir, file) | 133 | json_file = os.path.join(tactic_dir, file) |
| 130 | tactic_info, result = get_info_from_file(json_file) | 134 | tactic_info, result = get_info_from_file(json_file) |
| 131 | if not result: | 135 | if not result: |
| 132 | logging.error("failed to parse file %s.", json_file) | 136 | logging.error("failed to parse file %s.", json_file) |
| 133 | - exit(1) | 137 | + sys.exit(1) |
| 134 | relative_to_path = os.path.join(operation, file) | 138 | relative_to_path = os.path.join(operation, file) |
| 135 | to_path = os.path.join(output_operation_dir, file) | 139 | to_path = os.path.join(output_operation_dir, file) |
| 136 | shutil.copyfile(code_file, to_path) | 140 | shutil.copyfile(code_file, to_path) |
| 137 | try: | 141 | try: |
| 138 | compile_info_str = json.dumps(tactic_info["compileInfo"]) | 142 | compile_info_str = json.dumps(tactic_info["compileInfo"]) |
| 139 | meta_info[tactic] = ( | 143 | meta_info[tactic] = ( |
| 140 | - relative_to_path, tactic, tactic_info["kernelList"], compile_info_str, | 144 | + relative_to_path, |
| 141 | - tactic_info["opParaSize"], tactic_info["coreType"], tactic_info["magic"]) | 145 | + tactic, |
| 146 | + tactic_info["kernelList"], | ||
| 147 | + compile_info_str, | ||
| 148 | + tactic_info["opParaSize"], | ||
| 149 | + tactic_info["coreType"], | ||
| 150 | + tactic_info["magic"], | ||
| 151 | + ) | ||
| 142 | except KeyError: | 152 | except KeyError: |
| 143 | logging.error("%s get compile or meta info error", tactic) | 153 | logging.error("%s get compile or meta info error", tactic) |
| 144 | - exit(1) | 154 | + sys.exit(1) |
| 145 | code_file_count += 1 | 155 | code_file_count += 1 |
| 146 | return code_file_count | 156 | return code_file_count |
| 147 | 157 | ||
| @@ -149,13 +159,13 @@ def copy_ascendc_code(meta_info, env_cache_dir, target_version, output_path): | |||
| 149 | def copy_tbe_code_all_version(input_paras): | 159 | def copy_tbe_code_all_version(input_paras): |
| 150 | tbe_sections = input_paras["tbe_ini"].sections() | 160 | tbe_sections = input_paras["tbe_ini"].sections() |
| 151 | for target_version in input_paras["target_version_list"]: | 161 | for target_version in input_paras["target_version_list"]: |
| 152 | - output_path = os.path.join( | 162 | + output_path = os.path.join(input_paras["env_cache_dir"], "obj", target_version) |
| 153 | - input_paras["env_cache_dir"], "obj", target_version) | ||
| 154 | if not os.path.exists(output_path): | 163 | if not os.path.exists(output_path): |
| 155 | os.makedirs(output_path) | 164 | os.makedirs(output_path) |
| 156 | meta_info = {} | 165 | meta_info = {} |
| 157 | target_version_path = os.path.join( | 166 | target_version_path = os.path.join( |
| 158 | - input_paras["tbe_kernel_path"], target_version) | 167 | + input_paras["tbe_kernel_path"], target_version |
| 168 | + ) | ||
| 159 | 169 | ||
| 160 | for op_name in tbe_sections: | 170 | for op_name in tbe_sections: |
| 161 | op_dir_path = os.path.join(output_path, op_name) | 171 | op_dir_path = os.path.join(output_path, op_name) |
| @@ -163,19 +173,21 @@ def copy_tbe_code_all_version(input_paras): | |||
| 163 | os.mkdir(op_dir_path) | 173 | os.mkdir(op_dir_path) |
| 164 | items = dict(input_paras["tbe_ini"].items(op_name)) | 174 | items = dict(input_paras["tbe_ini"].items(op_name)) |
| 165 | for op_key, relative_op_path in items.items(): | 175 | for op_key, relative_op_path in items.items(): |
| 166 | - if '.' in op_key: | 176 | + if "." in op_key: |
| 167 | - op_key, version_op_key = op_key.split('.') | 177 | + op_key, version_op_key = op_key.split(".") |
| 168 | if version_op_key != target_version: | 178 | if version_op_key != target_version: |
| 169 | continue | 179 | continue |
| 170 | 180 | ||
| 171 | - tactic_info, ret = get_info_from_file(os.path.join( | 181 | + tactic_info, ret = get_info_from_file( |
| 172 | - target_version_path, relative_op_path)) | 182 | + os.path.join(target_version_path, relative_op_path) |
| 183 | + ) | ||
| 173 | if not ret: | 184 | if not ret: |
| 174 | logging.error("failed to parse json file %s", relative_op_path) | 185 | logging.error("failed to parse json file %s", relative_op_path) |
| 175 | - exit(1) | 186 | + sys.exit(1) |
| 176 | 187 | ||
| 177 | from_path = os.path.join( | 188 | from_path = os.path.join( |
| 178 | - target_version_path, relative_op_path[:-4] + 'o') | 189 | + target_version_path, relative_op_path[:-4] + "o" |
| 190 | + ) | ||
| 179 | object_name = os.path.basename(from_path) | 191 | object_name = os.path.basename(from_path) |
| 180 | to_path = os.path.join(op_dir_path, object_name) | 192 | to_path = os.path.join(op_dir_path, object_name) |
| 181 | relative_to_path = os.path.join(op_name, object_name) | 193 | relative_to_path = os.path.join(op_name, object_name) |
| @@ -184,16 +196,22 @@ def copy_tbe_code_all_version(input_paras): | |||
| 184 | try: | 196 | try: |
| 185 | compile_info_str = json.dumps(tactic_info["compileInfo"]) | 197 | compile_info_str = json.dumps(tactic_info["compileInfo"]) |
| 186 | meta_info[op_key] = ( | 198 | meta_info[op_key] = ( |
| 187 | - relative_to_path, op_name, tactic_info["kernelList"], compile_info_str, | 199 | + relative_to_path, |
| 188 | - tactic_info["opParaSize"], tactic_info["coreType"], tactic_info["magic"]) | 200 | + op_name, |
| 201 | + tactic_info["kernelList"], | ||
| 202 | + compile_info_str, | ||
| 203 | + tactic_info["opParaSize"], | ||
| 204 | + tactic_info["coreType"], | ||
| 205 | + tactic_info["magic"], | ||
| 206 | + ) | ||
| 189 | except KeyError: | 207 | except KeyError: |
| 190 | logging.error("%s get compile or meta info error", op_name) | 208 | logging.error("%s get compile or meta info error", op_name) |
| 191 | - exit(1) | 209 | + sys.exit(1) |
| 192 | 210 | ||
| 193 | ascendc_file_count = copy_ascendc_code( | 211 | ascendc_file_count = copy_ascendc_code( |
| 194 | - meta_info, input_paras["env_cache_dir"], target_version, output_path) | 212 | + meta_info, input_paras["env_cache_dir"], target_version, output_path |
| 195 | - logging.info( | 213 | + ) |
| 196 | - f"{target_version} has {ascendc_file_count} AscendC tactics.") | 214 | + logging.info(f"{target_version} has {ascendc_file_count} AscendC tactics.") |
| 197 | 215 | ||
| 198 | write_meta(meta_info, output_path, target_version) | 216 | write_meta(meta_info, output_path, target_version) |
| 199 | 217 | ||
| @@ -203,31 +221,34 @@ def copy_tbe_device_code(): | |||
| 203 | env_cache_dir = os.getenv("CACHE_DIR") | 221 | env_cache_dir = os.getenv("CACHE_DIR") |
| 204 | tbe_kernel_path = os.getenv("ASDOPS_KERNEL_PATH") | 222 | tbe_kernel_path = os.getenv("ASDOPS_KERNEL_PATH") |
| 205 | if not (env_code_root and env_cache_dir and tbe_kernel_path): | 223 | if not (env_code_root and env_cache_dir and tbe_kernel_path): |
| 206 | - logging.error( | 224 | + logging.error("env CODE_ROOT | OUTPUT_DIR | ASDOPS_SOURCE_DIR not exist!") |
| 207 | - "env CODE_ROOT | OUTPUT_DIR | ASDOPS_SOURCE_DIR not exist!") | 225 | + sys.exit(1) |
| 208 | - exit(1) | ||
| 209 | logging.info(f"tbe_kernel_path: {tbe_kernel_path}") | 226 | logging.info(f"tbe_kernel_path: {tbe_kernel_path}") |
| 210 | input_path = os.path.join(env_code_root, "configs/tbe_tactic_json.ini") | 227 | input_path = os.path.join(env_code_root, "configs/tbe_tactic_json.ini") |
| 211 | if not os.path.exists(input_path): | 228 | if not os.path.exists(input_path): |
| 212 | logging.error("ini file: %s not exist!", input_path) | 229 | logging.error("ini file: %s not exist!", input_path) |
| 213 | - exit(1) | 230 | + sys.exit(1) |
| 214 | tbe_ini = configparser.RawConfigParser() | 231 | tbe_ini = configparser.RawConfigParser() |
| 215 | tbe_ini.optionxform = lambda option: option | 232 | tbe_ini.optionxform = lambda option: option |
| 216 | try: | 233 | try: |
| 217 | tbe_ini.read(input_path) | 234 | tbe_ini.read(input_path) |
| 218 | except configparser.MissingSectionHeaderError: | 235 | except configparser.MissingSectionHeaderError: |
| 219 | logging.error("ini file: %s format error!", input_path) | 236 | logging.error("ini file: %s format error!", input_path) |
| 220 | - exit(1) | 237 | + sys.exit(1) |
| 221 | except configparser.ParsingError: | 238 | except configparser.ParsingError: |
| 222 | logging.error("ini file: %s format error!", input_path) | 239 | logging.error("ini file: %s format error!", input_path) |
| 223 | - exit(1) | 240 | + sys.exit(1) |
| 224 | 241 | ||
| 225 | target_version_list = get_build_target_list() | 242 | target_version_list = get_build_target_list() |
| 226 | - copy_tbe_code_all_version({"env_code_root": env_code_root, | 243 | + copy_tbe_code_all_version( |
| 227 | - "target_version_list": target_version_list, | 244 | + { |
| 228 | - "env_cache_dir": env_cache_dir, | 245 | + "env_code_root": env_code_root, |
| 229 | - "tbe_kernel_path": tbe_kernel_path, | 246 | + "target_version_list": target_version_list, |
| 230 | - "tbe_ini": tbe_ini}) | 247 | + "env_cache_dir": env_cache_dir, |
| 248 | + "tbe_kernel_path": tbe_kernel_path, | ||
| 249 | + "tbe_ini": tbe_ini, | ||
| 250 | + } | ||
| 251 | + ) | ||
| 231 | os.remove(input_path) | 252 | os.remove(input_path) |
| 232 | 253 | ||
| 233 | 254 | ||
| @@ -1,6 +1,6 @@ | |||
| 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: UTF-8 -*- | 2 | # -*- coding: UTF-8 -*- |
| 3 | -# Copyright (c) 2024 Huawei Technologies Co., Ltd. | 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 4 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 4 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | # CANN Open Software License Agreement Version 2.0 (the "License"). | 5 | # CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # Please refer to the License for details. You may not use this file except in compliance with the License. | 6 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -10,47 +10,62 @@ | |||
| 10 | 10 | ||
| 11 | import argparse | 11 | import argparse |
| 12 | import json | 12 | import json |
| 13 | +import logging | ||
| 13 | import os | 14 | import os |
| 14 | import re | 15 | import re |
| 15 | import stat | 16 | import stat |
| 16 | -import logging | 17 | +import sys |
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | def parse_args(): | 20 | def parse_args(): |
| 20 | parser = argparse.ArgumentParser() | 21 | parser = argparse.ArgumentParser() |
| 21 | - parser.add_argument('--soc', type=str, required=True) | 22 | + parser.add_argument("--soc", type=str, required=True) |
| 22 | - parser.add_argument('--channel', type=str, required=True) | 23 | + parser.add_argument("--channel", type=str, required=True) |
| 23 | - parser.add_argument('--srcs', type=str, required=True) | 24 | + parser.add_argument("--srcs", type=str, required=True) |
| 24 | - parser.add_argument('--dst', type=str, required=True) | 25 | + parser.add_argument("--dst", type=str, required=True) |
| 25 | - parser.add_argument('--code_root', type=str, required=True) | 26 | + parser.add_argument("--code_root", type=str, required=True) |
| 26 | - parser.add_argument('--kernel', type=str, required=True) | 27 | + parser.add_argument("--kernel", type=str, required=True) |
| 27 | - parser.add_argument('--use_msdebug', type=str) | 28 | + parser.add_argument("--use_msdebug", type=str) |
| 28 | - parser.add_argument('--use_mssanitizer', type=str, required=True) | 29 | + parser.add_argument("--use_mssanitizer", type=str, required=True) |
| 29 | - parser.add_argument('--no_warning', action='store_true') | 30 | + parser.add_argument("--no_warning", action="store_true") |
| 30 | - parser.add_argument('--include_directories', type=str, required=False, nargs="+") | 31 | + parser.add_argument("--include_directories", type=str, required=False, nargs="+") |
| 31 | - parser.add_argument('--use_ascendc_dump', action='store_true') | 32 | + parser.add_argument("--use_ascendc_dump", action="store_true") |
| 32 | return parser.parse_args() | 33 | return parser.parse_args() |
| 33 | 34 | ||
| 34 | 35 | ||
| 35 | def gen_compile_cmd(args, dst: str, sub_arch: str, compile_options): | 36 | def gen_compile_cmd(args, dst: str, sub_arch: str, compile_options): |
| 36 | - compile_cmd = [os.path.join(args.code_root, '3rdparty', 'compiler', | 37 | + compile_cmd = [ |
| 37 | - 'ccec_compiler', 'bin', 'ccec'), | 38 | + os.path.join( |
| 38 | - '-c'] | 39 | + args.code_root, "3rdparty", "compiler", "ccec_compiler", "bin", "ccec" |
| 40 | + ), | ||
| 41 | + "-c", | ||
| 42 | + ] | ||
| 39 | if args.use_msdebug == "ON": | 43 | if args.use_msdebug == "ON": |
| 40 | - compile_cmd += ['-O0', '-g', '--cce-ignore-always-inline=true'] | 44 | + compile_cmd += ["-O0", "-g", "--cce-ignore-always-inline=true"] |
| 41 | else: | 45 | else: |
| 42 | - compile_cmd += ['-O2'] | 46 | + compile_cmd += ["-O2"] |
| 43 | compile_cmd += compile_options | 47 | compile_cmd += compile_options |
| 44 | - compile_cmd += [args.srcs, "--cce-aicore-arch=%s" % sub_arch, | 48 | + compile_cmd += [ |
| 45 | - "--cce-aicore-only", "-o", dst, | 49 | + args.srcs, |
| 46 | - "-mllvm", "-cce-aicore-fp-ceiling=2"] | 50 | + "--cce-aicore-arch=%s" % sub_arch, |
| 51 | + "--cce-aicore-only", | ||
| 52 | + "-o", | ||
| 53 | + dst, | ||
| 54 | + "-mllvm", | ||
| 55 | + "-cce-aicore-fp-ceiling=2", | ||
| 56 | + ] | ||
| 47 | if args.use_mssanitizer == "ON" and args.soc in ["ascend310p", "ascend910b"]: | 57 | if args.use_mssanitizer == "ON" and args.soc in ["ascend310p", "ascend910b"]: |
| 48 | - compile_cmd += ["-g", "--cce-enable-sanitizer", | 58 | + compile_cmd += [ |
| 49 | - "-mllvm", "-cce-aicore-long-call", | 59 | + "-g", |
| 50 | - "-mllvm", "-cce-aicore-jump-expand=true"] | 60 | + "--cce-enable-sanitizer", |
| 61 | + "-mllvm", | ||
| 62 | + "-cce-aicore-long-call", | ||
| 63 | + "-mllvm", | ||
| 64 | + "-cce-aicore-jump-expand=true", | ||
| 65 | + ] | ||
| 51 | compile_cmd += ["-std=c++17"] | 66 | compile_cmd += ["-std=c++17"] |
| 52 | compile_cmd += ["--cce-mask-opt"] | 67 | compile_cmd += ["--cce-mask-opt"] |
| 53 | - if (args.use_ascendc_dump): | 68 | + if args.use_ascendc_dump: |
| 54 | compile_cmd += ["-mllvm", "-cce-aicore-function-stack-size=0x4000"] | 69 | compile_cmd += ["-mllvm", "-cce-aicore-function-stack-size=0x4000"] |
| 55 | compile_cmd += ["--cce-long-call=true"] | 70 | compile_cmd += ["--cce-long-call=true"] |
| 56 | compile_cmd += ["-DASCENDC_DUMP=1"] | 71 | compile_cmd += ["-DASCENDC_DUMP=1"] |
| @@ -59,27 +74,45 @@ def gen_compile_cmd(args, dst: str, sub_arch: str, compile_options): | |||
| 59 | 74 | ||
| 60 | 75 | ||
| 61 | def gen_compile_cmd_v220(args, dst: str, sub_arch: str, compile_options): | 76 | def gen_compile_cmd_v220(args, dst: str, sub_arch: str, compile_options): |
| 62 | - compile_cmd = [os.path.join(args.code_root, '3rdparty', 'compiler', | 77 | + compile_cmd = [ |
| 63 | - 'ccec_compiler', 'bin', 'ccec'), | 78 | + os.path.join( |
| 64 | - '-c'] | 79 | + args.code_root, "3rdparty", "compiler", "ccec_compiler", "bin", "ccec" |
| 80 | + ), | ||
| 81 | + "-c", | ||
| 82 | + ] | ||
| 65 | if args.use_msdebug == "ON": | 83 | if args.use_msdebug == "ON": |
| 66 | - compile_cmd += ['-O0', '-g', '--cce-ignore-always-inline=true'] | 84 | + compile_cmd += ["-O0", "-g", "--cce-ignore-always-inline=true"] |
| 67 | else: | 85 | else: |
| 68 | - compile_cmd += ['-O3'] | 86 | + compile_cmd += ["-O3"] |
| 69 | compile_cmd += compile_options | 87 | compile_cmd += compile_options |
| 70 | - compile_cmd += [args.srcs, "--cce-aicore-arch=%s" % sub_arch, | 88 | + compile_cmd += [ |
| 71 | - "--cce-aicore-only", "-o", dst, | 89 | + args.srcs, |
| 72 | - "-mllvm", "-cce-aicore-stack-size=0x8000", | 90 | + "--cce-aicore-arch=%s" % sub_arch, |
| 73 | - "-mllvm", "-cce-aicore-function-stack-size=0x8000", | 91 | + "--cce-aicore-only", |
| 74 | - "-mllvm", "-cce-aicore-record-overflow=true", | 92 | + "-o", |
| 75 | - "-mllvm", "-cce-aicore-addr-transform", | 93 | + dst, |
| 76 | - "-mllvm", "-cce-aicore-dcci-insert-for-scalar=false"] | 94 | + "-mllvm", |
| 95 | + "-cce-aicore-stack-size=0x8000", | ||
| 96 | + "-mllvm", | ||
| 97 | + "-cce-aicore-function-stack-size=0x8000", | ||
| 98 | + "-mllvm", | ||
| 99 | + "-cce-aicore-record-overflow=true", | ||
| 100 | + "-mllvm", | ||
| 101 | + "-cce-aicore-addr-transform", | ||
| 102 | + "-mllvm", | ||
| 103 | + "-cce-aicore-dcci-insert-for-scalar=false", | ||
| 104 | + ] | ||
| 77 | if args.use_mssanitizer == "ON": | 105 | if args.use_mssanitizer == "ON": |
| 78 | - compile_cmd += ["-g", "--cce-enable-sanitizer", | 106 | + compile_cmd += [ |
| 79 | - "-mllvm", "-cce-aicore-long-call", | 107 | + "-g", |
| 80 | - "-mllvm", "-cce-aicore-jump-expand=true"] | 108 | + "--cce-enable-sanitizer", |
| 109 | + "-mllvm", | ||
| 110 | + "-cce-aicore-long-call", | ||
| 111 | + "-mllvm", | ||
| 112 | + "-cce-aicore-jump-expand=true", | ||
| 113 | + ] | ||
| 81 | compile_cmd += ["-std=c++17"] | 114 | compile_cmd += ["-std=c++17"] |
| 82 | - if (args.use_ascendc_dump): | 115 | + if args.use_ascendc_dump: |
| 83 | compile_cmd += ["--cce-long-call=true"] | 116 | compile_cmd += ["--cce-long-call=true"] |
| 84 | compile_cmd += ["-DASCENDC_DUMP=1"] | 117 | compile_cmd += ["-DASCENDC_DUMP=1"] |
| 85 | compile_cmd += ["-DASCENDC_DEBUG"] | 118 | compile_cmd += ["-DASCENDC_DEBUG"] |
| @@ -87,24 +120,38 @@ def gen_compile_cmd_v220(args, dst: str, sub_arch: str, compile_options): | |||
| 87 | 120 | ||
| 88 | 121 | ||
| 89 | def gen_compile_cmd_v300(args, dst: str, sub_arch: str, compile_options): | 122 | def gen_compile_cmd_v300(args, dst: str, sub_arch: str, compile_options): |
| 90 | - compile_cmd = [os.path.join(args.code_root, '3rdparty', 'compiler', | 123 | + compile_cmd = [ |
| 91 | - 'ccec_compiler', 'bin', 'ccec'), | 124 | + os.path.join( |
| 92 | - '-c'] | 125 | + args.code_root, "3rdparty", "compiler", "ccec_compiler", "bin", "ccec" |
| 126 | + ), | ||
| 127 | + "-c", | ||
| 128 | + ] | ||
| 93 | if args.use_msdebug == "ON": | 129 | if args.use_msdebug == "ON": |
| 94 | - compile_cmd += ['-O0', '-g', '--cce-ignore-always-inline=true'] | 130 | + compile_cmd += ["-O0", "-g", "--cce-ignore-always-inline=true"] |
| 95 | else: | 131 | else: |
| 96 | - compile_cmd += ['-O3'] | 132 | + compile_cmd += ["-O3"] |
| 97 | compile_cmd += compile_options | 133 | compile_cmd += compile_options |
| 98 | - compile_cmd += [args.srcs, "--cce-aicore-arch=%s" % sub_arch, | 134 | + compile_cmd += [ |
| 99 | - "--cce-aicore-only", "-o", dst, | 135 | + args.srcs, |
| 100 | - "-mllvm", "-cce-aicore-function-stack-size=0x4000", | 136 | + "--cce-aicore-arch=%s" % sub_arch, |
| 101 | - "-mllvm", "-cce-aicore-addr-transform", | 137 | + "--cce-aicore-only", |
| 102 | - "-mllvm", "--cce-aicore-or-combine=false", | 138 | + "-o", |
| 103 | - "-mllvm", "-instcombine-code-sinking=false", | 139 | + dst, |
| 104 | - "-mllvm", "-cce-aicore-jump-expand=false", | 140 | + "-mllvm", |
| 105 | - "-mllvm", "-cce-aicore-mask-opt=false"] | 141 | + "-cce-aicore-function-stack-size=0x4000", |
| 142 | + "-mllvm", | ||
| 143 | + "-cce-aicore-addr-transform", | ||
| 144 | + "-mllvm", | ||
| 145 | + "--cce-aicore-or-combine=false", | ||
| 146 | + "-mllvm", | ||
| 147 | + "-instcombine-code-sinking=false", | ||
| 148 | + "-mllvm", | ||
| 149 | + "-cce-aicore-jump-expand=false", | ||
| 150 | + "-mllvm", | ||
| 151 | + "-cce-aicore-mask-opt=false", | ||
| 152 | + ] | ||
| 106 | compile_cmd += ["-std=c++17"] | 153 | compile_cmd += ["-std=c++17"] |
| 107 | - if (args.use_ascendc_dump): | 154 | + if args.use_ascendc_dump: |
| 108 | compile_cmd += ["--cce-long-call=true"] | 155 | compile_cmd += ["--cce-long-call=true"] |
| 109 | compile_cmd += ["-DASCENDC_DUMP=1"] | 156 | compile_cmd += ["-DASCENDC_DUMP=1"] |
| 110 | compile_cmd += ["-DASCENDC_DEBUG"] | 157 | compile_cmd += ["-DASCENDC_DEBUG"] |
| @@ -112,29 +159,49 @@ def gen_compile_cmd_v300(args, dst: str, sub_arch: str, compile_options): | |||
| 112 | 159 | ||
| 113 | 160 | ||
| 114 | def gen_compile_cmd_c310(args, dst: str, sub_arch: str, compile_options): | 161 | def gen_compile_cmd_c310(args, dst: str, sub_arch: str, compile_options): |
| 115 | - compile_cmd = [os.path.join(args.code_root, '3rdparty', 'compiler', | 162 | + compile_cmd = [ |
| 116 | - 'ccec_compiler', 'bin', 'bisheng'), | 163 | + os.path.join( |
| 117 | - '-c'] | 164 | + args.code_root, "3rdparty", "compiler", "ccec_compiler", "bin", "bisheng" |
| 165 | + ), | ||
| 166 | + "-c", | ||
| 167 | + ] | ||
| 118 | compile_cmd += compile_options | 168 | compile_cmd += compile_options |
| 119 | - compile_cmd += [args.srcs, "--cce-aicore-arch=%s" % sub_arch, | 169 | + compile_cmd += [ |
| 120 | - "--cce-aicore-only", "-o", dst, | 170 | + args.srcs, |
| 121 | - "-mllvm", "-cce-aicore-stack-size=0x8000", | 171 | + "--cce-aicore-arch=%s" % sub_arch, |
| 122 | - "-mllvm", "-cce-aicore-function-stack-size=0x8000", | 172 | + "--cce-aicore-only", |
| 123 | - "-mllvm", "-cce-aicore-record-overflow=true", | 173 | + "-o", |
| 124 | - "-mllvm", "-cce-aicore-addr-transform", | 174 | + dst, |
| 125 | - "-mllvm", "-cce-aicore-jump-expand=true", | 175 | + "-mllvm", |
| 126 | - "-mllvm", "-cce-aicore-dcci-insert-for-scalar=false", | 176 | + "-cce-aicore-stack-size=0x8000", |
| 127 | - "-mllvm", "-cce-aicore-dcci-before-kernel-end=false"] | 177 | + "-mllvm", |
| 178 | + "-cce-aicore-function-stack-size=0x8000", | ||
| 179 | + "-mllvm", | ||
| 180 | + "-cce-aicore-record-overflow=true", | ||
| 181 | + "-mllvm", | ||
| 182 | + "-cce-aicore-addr-transform", | ||
| 183 | + "-mllvm", | ||
| 184 | + "-cce-aicore-jump-expand=true", | ||
| 185 | + "-mllvm", | ||
| 186 | + "-cce-aicore-dcci-insert-for-scalar=false", | ||
| 187 | + "-mllvm", | ||
| 188 | + "-cce-aicore-dcci-before-kernel-end=false", | ||
| 189 | + ] | ||
| 128 | compile_cmd += ["-std=c++17"] | 190 | compile_cmd += ["-std=c++17"] |
| 129 | return compile_cmd | 191 | return compile_cmd |
| 130 | 192 | ||
| 131 | 193 | ||
| 132 | def gen_fatbin_cmd(args, obj_file: list, dst_file: str): | 194 | def gen_fatbin_cmd(args, obj_file: list, dst_file: str): |
| 133 | - compile_cmd = [os.path.join(args.code_root, '3rdparty', 'compiler', | 195 | + compile_cmd = [ |
| 134 | - 'ccec_compiler', 'bin', 'ld.lld'), | 196 | + os.path.join( |
| 135 | - '-m', 'aicorelinux', '-Ttext=0'] | 197 | + args.code_root, "3rdparty", "compiler", "ccec_compiler", "bin", "ld.lld" |
| 198 | + ), | ||
| 199 | + "-m", | ||
| 200 | + "aicorelinux", | ||
| 201 | + "-Ttext=0", | ||
| 202 | + ] | ||
| 136 | compile_cmd += obj_file | 203 | compile_cmd += obj_file |
| 137 | - compile_cmd += ['-static', '-o', "%s" % dst_file] | 204 | + compile_cmd += ["-static", "-o", "%s" % dst_file] |
| 138 | return compile_cmd | 205 | return compile_cmd |
| 139 | 206 | ||
| 140 | 207 | ||
| @@ -152,7 +219,7 @@ def gen_json(args, kernels): | |||
| 152 | "parameters": [], | 219 | "parameters": [], |
| 153 | "sha256": "", | 220 | "sha256": "", |
| 154 | "kernelList": [], | 221 | "kernelList": [], |
| 155 | - "compileInfo": {} | 222 | + "compileInfo": {}, |
| 156 | } | 223 | } |
| 157 | json_template["binFileName"] = args.kernel | 224 | json_template["binFileName"] = args.kernel |
| 158 | for kernel in kernels: | 225 | for kernel in kernels: |
| @@ -174,14 +241,20 @@ def gen_json(args, kernels): | |||
| 174 | json_template["core_type"] = "MIX" | 241 | json_template["core_type"] = "MIX" |
| 175 | json_template["magic"] = "RT_DEV_BINARY_MAGIC_ELF" | 242 | json_template["magic"] = "RT_DEV_BINARY_MAGIC_ELF" |
| 176 | 243 | ||
| 177 | - with os.fdopen(os.open(os.path.splitext(args.dst)[0] + ".json", | 244 | + with os.fdopen( |
| 178 | - os.O_TRUNC | os.O_WRONLY | os.O_CREAT, stat.S_IWUSR | stat.S_IRUSR), 'w') as f: | 245 | + os.open( |
| 246 | + os.path.splitext(args.dst)[0] + ".json", | ||
| 247 | + os.O_TRUNC | os.O_WRONLY | os.O_CREAT, | ||
| 248 | + stat.S_IWUSR | stat.S_IRUSR, | ||
| 249 | + ), | ||
| 250 | + "w", | ||
| 251 | + ) as f: | ||
| 179 | json.dump(json_template, f, indent=4) | 252 | json.dump(json_template, f, indent=4) |
| 180 | 253 | ||
| 181 | 254 | ||
| 182 | def get_common_options(args): | 255 | def get_common_options(args): |
| 183 | tikcpp_path = os.path.join(args.code_root, "3rdparty", "compiler", "tikcpp") | 256 | tikcpp_path = os.path.join(args.code_root, "3rdparty", "compiler", "tikcpp") |
| 184 | - options = ['-x', 'cce'] | 257 | + options = ["-x", "cce"] |
| 185 | options.append("-I.") | 258 | options.append("-I.") |
| 186 | options.append("-I" + tikcpp_path) | 259 | options.append("-I" + tikcpp_path) |
| 187 | options.append("-I" + os.path.join(tikcpp_path, "tikcfw")) | 260 | options.append("-I" + os.path.join(tikcpp_path, "tikcfw")) |
| @@ -212,9 +285,9 @@ def get_arch(soc, channel): | |||
| 212 | arch_dict = { | 285 | arch_dict = { |
| 213 | "ascend310b": {"vector": "dav-m300", "cube": "dav-m300"}, | 286 | "ascend310b": {"vector": "dav-m300", "cube": "dav-m300"}, |
| 214 | "ascend310p": {"vector": "dav-m200", "cube": "dav-m200"}, | 287 | "ascend310p": {"vector": "dav-m200", "cube": "dav-m200"}, |
| 215 | - "ascend910": {"vector": "dav-c100", "cube": "dav-c100"}, | 288 | + "ascend910": {"vector": "dav-c100", "cube": "dav-c100"}, |
| 216 | "ascend910b": {"vector": "dav-c220-vec", "cube": "dav-c220-cube", "mix": "mix"}, | 289 | "ascend910b": {"vector": "dav-c220-vec", "cube": "dav-c220-cube", "mix": "mix"}, |
| 217 | - "ascend950": {"vector": "dav-c310", "cube": "dav-c310", "mix": "mix"} | 290 | + "ascend950": {"vector": "dav-c310", "cube": "dav-c310", "mix": "mix"}, |
| 218 | } | 291 | } |
| 219 | try: | 292 | try: |
| 220 | return arch_dict[soc][channel] | 293 | return arch_dict[soc][channel] |
| @@ -248,86 +321,136 @@ def compile_ascendc_operation(args): | |||
| 248 | for key in tiling_key_ids: | 321 | for key in tiling_key_ids: |
| 249 | if args.soc == "ascend310p" or args.soc == "ascend910": | 322 | if args.soc == "ascend310p" or args.soc == "ascend910": |
| 250 | dst = os.path.splitext(args.dst)[0] + f"_{key}.o" | 323 | dst = os.path.splitext(args.dst)[0] + f"_{key}.o" |
| 251 | - opt = options + [f'-D{args.kernel}={args.kernel}_{key}', f'-DTILING_KEY_VAR={key}'] | 324 | + opt = options + [ |
| 252 | - compile_cmd = ' '.join(gen_compile_cmd(args, dst, arch, opt)) | 325 | + f"-D{args.kernel}={args.kernel}_{key}", |
| 253 | - if(exe_cmd(compile_cmd)) != 0: | 326 | + f"-DTILING_KEY_VAR={key}", |
| 327 | + ] | ||
| 328 | + compile_cmd = " ".join(gen_compile_cmd(args, dst, arch, opt)) | ||
| 329 | + if (exe_cmd(compile_cmd)) != 0: | ||
| 254 | return -1 | 330 | return -1 |
| 255 | dsts.append(dst) | 331 | dsts.append(dst) |
| 256 | if args.use_mssanitizer == "ON" and args.soc == "ascend310p": | 332 | if args.use_mssanitizer == "ON" and args.soc == "ascend310p": |
| 257 | dsts.append("--dependent-libraries") | 333 | dsts.append("--dependent-libraries") |
| 258 | - dsts.append(os.path.join(mssanitizer_path, "libsanitizer_stub_dav-m200.a")) | 334 | + dsts.append( |
| 335 | + os.path.join(mssanitizer_path, "libsanitizer_stub_dav-m200.a") | ||
| 336 | + ) | ||
| 259 | elif args.soc == "ascend910b": | 337 | elif args.soc == "ascend910b": |
| 260 | if args.channel != "mix": | 338 | if args.channel != "mix": |
| 261 | dst = os.path.splitext(args.dst)[0] + f"_{key}.o" | 339 | dst = os.path.splitext(args.dst)[0] + f"_{key}.o" |
| 262 | - opt = options + [f'-D{args.kernel}={args.kernel}_{key}', f'-DTILING_KEY_VAR={key}'] | 340 | + opt = options + [ |
| 263 | - compile_cmd = ' '.join(gen_compile_cmd_v220(args, dst, arch, opt)) | 341 | + f"-D{args.kernel}={args.kernel}_{key}", |
| 264 | - if(exe_cmd(compile_cmd)) != 0: | 342 | + f"-DTILING_KEY_VAR={key}", |
| 343 | + ] | ||
| 344 | + compile_cmd = " ".join(gen_compile_cmd_v220(args, dst, arch, opt)) | ||
| 345 | + if (exe_cmd(compile_cmd)) != 0: | ||
| 265 | return -1 | 346 | return -1 |
| 266 | dsts.append(dst) | 347 | dsts.append(dst) |
| 267 | if args.use_mssanitizer == "ON": | 348 | if args.use_mssanitizer == "ON": |
| 268 | dsts.append("--dependent-libraries") | 349 | dsts.append("--dependent-libraries") |
| 269 | - dsts.append(os.path.join(mssanitizer_path, "libsanitizer_stub_dav-c220-cube.a")) | 350 | + dsts.append( |
| 270 | - dsts.append(os.path.join(mssanitizer_path, "libsanitizer_stub_dav-c220-vec.a")) | 351 | + os.path.join( |
| 352 | + mssanitizer_path, "libsanitizer_stub_dav-c220-cube.a" | ||
| 353 | + ) | ||
| 354 | + ) | ||
| 355 | + dsts.append( | ||
| 356 | + os.path.join( | ||
| 357 | + mssanitizer_path, "libsanitizer_stub_dav-c220-vec.a" | ||
| 358 | + ) | ||
| 359 | + ) | ||
| 271 | else: | 360 | else: |
| 272 | dst = os.path.splitext(args.dst)[0] + f"_mix_aic_{key}.o" | 361 | dst = os.path.splitext(args.dst)[0] + f"_mix_aic_{key}.o" |
| 273 | - aic_opt = options + [f'-D{args.kernel}={args.kernel}_{key}_mix_aic', f'-DTILING_KEY_VAR={key}'] | 362 | + aic_opt = options + [ |
| 274 | - compile_cmd = ' '.join(gen_compile_cmd_v220(args, dst, "dav-c220-cube", aic_opt)) | 363 | + f"-D{args.kernel}={args.kernel}_{key}_mix_aic", |
| 275 | - if(exe_cmd(compile_cmd)) != 0: | 364 | + f"-DTILING_KEY_VAR={key}", |
| 365 | + ] | ||
| 366 | + compile_cmd = " ".join( | ||
| 367 | + gen_compile_cmd_v220(args, dst, "dav-c220-cube", aic_opt) | ||
| 368 | + ) | ||
| 369 | + if (exe_cmd(compile_cmd)) != 0: | ||
| 276 | return -1 | 370 | return -1 |
| 277 | dsts.append(dst) | 371 | dsts.append(dst) |
| 278 | if args.use_mssanitizer == "ON": | 372 | if args.use_mssanitizer == "ON": |
| 279 | dsts.append("--dependent-libraries") | 373 | dsts.append("--dependent-libraries") |
| 280 | - dsts.append(os.path.join(mssanitizer_path, "libsanitizer_stub_dav-c220-cube.a")) | 374 | + dsts.append( |
| 375 | + os.path.join( | ||
| 376 | + mssanitizer_path, "libsanitizer_stub_dav-c220-cube.a" | ||
| 377 | + ) | ||
| 378 | + ) | ||
| 281 | dst = os.path.splitext(args.dst)[0] + f"_mix_aiv_{key}.o" | 379 | dst = os.path.splitext(args.dst)[0] + f"_mix_aiv_{key}.o" |
| 282 | - aiv_opt = options + [f'-D{args.kernel}={args.kernel}_{key}_mix_aiv', f'-DTILING_KEY_VAR={key}'] | 380 | + aiv_opt = options + [ |
| 283 | - compile_cmd = ' '.join(gen_compile_cmd_v220(args, dst, "dav-c220-vec", aiv_opt)) | 381 | + f"-D{args.kernel}={args.kernel}_{key}_mix_aiv", |
| 284 | - if(exe_cmd(compile_cmd)) != 0: | 382 | + f"-DTILING_KEY_VAR={key}", |
| 383 | + ] | ||
| 384 | + compile_cmd = " ".join( | ||
| 385 | + gen_compile_cmd_v220(args, dst, "dav-c220-vec", aiv_opt) | ||
| 386 | + ) | ||
| 387 | + if (exe_cmd(compile_cmd)) != 0: | ||
| 285 | return -1 | 388 | return -1 |
| 286 | dsts.append(dst) | 389 | dsts.append(dst) |
| 287 | if args.use_mssanitizer == "ON": | 390 | if args.use_mssanitizer == "ON": |
| 288 | dsts.append("--dependent-libraries") | 391 | dsts.append("--dependent-libraries") |
| 289 | - dsts.append(os.path.join(mssanitizer_path, "libsanitizer_stub_dav-c220-vec.a")) | 392 | + dsts.append( |
| 393 | + os.path.join( | ||
| 394 | + mssanitizer_path, "libsanitizer_stub_dav-c220-vec.a" | ||
| 395 | + ) | ||
| 396 | + ) | ||
| 290 | elif args.soc == "ascend310b": | 397 | elif args.soc == "ascend310b": |
| 291 | dst = os.path.splitext(args.dst)[0] + f"_{key}.o" | 398 | dst = os.path.splitext(args.dst)[0] + f"_{key}.o" |
| 292 | - opt = options + [f'-D{args.kernel}={args.kernel}_{key}', f'-DTILING_KEY_VAR={key}'] | 399 | + opt = options + [ |
| 293 | - compile_cmd = ' '.join(gen_compile_cmd_v300(args, dst, arch, opt)) | 400 | + f"-D{args.kernel}={args.kernel}_{key}", |
| 294 | - if(exe_cmd(compile_cmd)) != 0: | 401 | + f"-DTILING_KEY_VAR={key}", |
| 402 | + ] | ||
| 403 | + compile_cmd = " ".join(gen_compile_cmd_v300(args, dst, arch, opt)) | ||
| 404 | + if (exe_cmd(compile_cmd)) != 0: | ||
| 295 | return -1 | 405 | return -1 |
| 296 | dsts.append(dst) | 406 | dsts.append(dst) |
| 297 | elif args.soc == "ascend950": | 407 | elif args.soc == "ascend950": |
| 298 | if args.channel != "mix": | 408 | if args.channel != "mix": |
| 299 | dst = os.path.splitext(args.dst)[0] + f"_{key}.o" | 409 | dst = os.path.splitext(args.dst)[0] + f"_{key}.o" |
| 300 | - opt = options + [f'-D{args.kernel}={args.kernel}_{key}', f'-DTILING_KEY_VAR={key}'] | 410 | + opt = options + [ |
| 301 | - compile_cmd = ' '.join(gen_compile_cmd_c310(args, dst, arch, opt)) | 411 | + f"-D{args.kernel}={args.kernel}_{key}", |
| 302 | - if(exe_cmd(compile_cmd)) != 0: | 412 | + f"-DTILING_KEY_VAR={key}", |
| 413 | + ] | ||
| 414 | + compile_cmd = " ".join(gen_compile_cmd_c310(args, dst, arch, opt)) | ||
| 415 | + if (exe_cmd(compile_cmd)) != 0: | ||
| 303 | return -1 | 416 | return -1 |
| 304 | dsts.append(dst) | 417 | dsts.append(dst) |
| 305 | else: | 418 | else: |
| 306 | dst = os.path.splitext(args.dst)[0] + f"_mix_aic_{key}.o" | 419 | dst = os.path.splitext(args.dst)[0] + f"_mix_aic_{key}.o" |
| 307 | - aic_opt = options + [f'-D{args.kernel}={args.kernel}_{key}_mix_aic', f'-DTILING_KEY_VAR={key}'] | 420 | + aic_opt = options + [ |
| 308 | - compile_cmd = ' '.join(gen_compile_cmd_c310(args, dst, "dav-c310", aic_opt)) | 421 | + f"-D{args.kernel}={args.kernel}_{key}_mix_aic", |
| 309 | - if(exe_cmd(compile_cmd)) != 0: | 422 | + f"-DTILING_KEY_VAR={key}", |
| 423 | + ] | ||
| 424 | + compile_cmd = " ".join( | ||
| 425 | + gen_compile_cmd_c310(args, dst, "dav-c310", aic_opt) | ||
| 426 | + ) | ||
| 427 | + if (exe_cmd(compile_cmd)) != 0: | ||
| 310 | return -1 | 428 | return -1 |
| 311 | dsts.append(dst) | 429 | dsts.append(dst) |
| 312 | dst = os.path.splitext(args.dst)[0] + f"_mix_aiv_{key}.o" | 430 | dst = os.path.splitext(args.dst)[0] + f"_mix_aiv_{key}.o" |
| 313 | - aiv_opt = options + [f'-D{args.kernel}={args.kernel}_{key}_mix_aiv', f'-DTILING_KEY_VAR={key}'] | 431 | + aiv_opt = options + [ |
| 314 | - compile_cmd = ' '.join(gen_compile_cmd_c310(args, dst, "dav-c310", aiv_opt)) | 432 | + f"-D{args.kernel}={args.kernel}_{key}_mix_aiv", |
| 315 | - if(exe_cmd(compile_cmd)) != 0: | 433 | + f"-DTILING_KEY_VAR={key}", |
| 434 | + ] | ||
| 435 | + compile_cmd = " ".join( | ||
| 436 | + gen_compile_cmd_c310(args, dst, "dav-c310", aiv_opt) | ||
| 437 | + ) | ||
| 438 | + if (exe_cmd(compile_cmd)) != 0: | ||
| 316 | return -1 | 439 | return -1 |
| 317 | dsts.append(dst) | 440 | dsts.append(dst) |
| 318 | else: | 441 | else: |
| 319 | logging.error("soc version %s is not supported", args.soc) | 442 | logging.error("soc version %s is not supported", args.soc) |
| 320 | - exit(1) | 443 | + sys.exit(1) |
| 321 | - kernels.append(f'{args.kernel}_{key}') | 444 | + kernels.append(f"{args.kernel}_{key}") |
| 322 | 445 | ||
| 323 | - link_cmd = ' '.join(gen_fatbin_cmd(args, dsts, args.dst)) | 446 | + link_cmd = " ".join(gen_fatbin_cmd(args, dsts, args.dst)) |
| 324 | - if(exe_cmd(link_cmd)) != 0: | 447 | + if (exe_cmd(link_cmd)) != 0: |
| 325 | return -1 | 448 | return -1 |
| 326 | gen_json(args, kernels) | 449 | gen_json(args, kernels) |
| 327 | return 0 | 450 | return 0 |
| 328 | 451 | ||
| 329 | 452 | ||
| 330 | -if __name__ == '__main__': | 453 | +if __name__ == "__main__": |
| 331 | input_args = parse_args() | 454 | input_args = parse_args() |
| 332 | output_dir = os.path.dirname(input_args.dst) | 455 | output_dir = os.path.dirname(input_args.dst) |
| 333 | if not os.path.exists(output_dir): | 456 | if not os.path.exists(output_dir): |
| @@ -335,4 +458,4 @@ if __name__ == '__main__': | |||
| 335 | res = compile_ascendc_operation(input_args) | 458 | res = compile_ascendc_operation(input_args) |
| 336 | if res != 0: | 459 | if res != 0: |
| 337 | logging.error("compile ascend C failed!") | 460 | logging.error("compile ascend C failed!") |
| 338 | - exit(1) | 461 | + sys.exit(1) |
| @@ -61,7 +61,7 @@ function log() { | |||
| 61 | if [ x"$log_file" = x ]; then | 61 | if [ x"$log_file" = x ]; then |
| 62 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] $2" | 62 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] $2" |
| 63 | else | 63 | else |
| 64 | - if [ $(stat -c %s $log_file) -gt $MAX_LOG_SIZE ];then | 64 | + if [ $(stat -c %s $log_file) -gt $MAX_LOG_SIZE ];then |
| 65 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] log file is bigger than $MAX_LOG_SIZE, stop write log to file" | 65 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] log file is bigger than $MAX_LOG_SIZE, stop write log to file" |
| 66 | else | 66 | else |
| 67 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] $2" >>$log_file | 67 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] $2" >>$log_file |
| @@ -80,7 +80,7 @@ function print() { | |||
| 80 | if [ x"$log_file" = x ]; then | 80 | if [ x"$log_file" = x ]; then |
| 81 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] $2" | 81 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] $2" |
| 82 | else | 82 | else |
| 83 | - if [ $(stat -c %s $log_file) -gt $MAX_LOG_SIZE ];then | 83 | + if [ $(stat -c %s $log_file) -gt $MAX_LOG_SIZE ];then |
| 84 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] log file is bigger than $MAX_LOG_SIZE, stop write log to file" | 84 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] log file is bigger than $MAX_LOG_SIZE, stop write log to file" |
| 85 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] $2" | 85 | echo -e "[cann-asdsip] [$(date +%Y%m%d-%H:%M:%S)] [$1] $2" |
| 86 | else | 86 | else |
| @@ -141,7 +141,7 @@ function chmod_authority() { | |||
| 141 | # 修改文件和目录权限 | 141 | # 修改文件和目录权限 |
| 142 | chmod_file ${default_install_path} | 142 | chmod_file ${default_install_path} |
| 143 | chmod_file ${install_dir} | 143 | chmod_file ${install_dir} |
| 144 | - if [ "${install_for_all_flag}" == "y" ]; then | 144 | + if [ "${install_for_all_flag}" == "y" ]; then |
| 145 | chmod 444 ${install_dir}/scripts/filelist.csv | 145 | chmod 444 ${install_dir}/scripts/filelist.csv |
| 146 | else | 146 | else |
| 147 | chmod 440 ${install_dir}/scripts/filelist.csv | 147 | chmod 440 ${install_dir}/scripts/filelist.csv |
| @@ -159,7 +159,7 @@ function chmod_authority() { | |||
| 159 | chmod ${path_rights} "${install_dir}" | 159 | chmod ${path_rights} "${install_dir}" |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | -function chmod_file() { | 162 | +function chmod_file() { |
| 163 | chmod_recursion ${1} "550" "file" "*.sh" | 163 | chmod_recursion ${1} "550" "file" "*.sh" |
| 164 | chmod_recursion ${1} "440" "file" "*.bin" | 164 | chmod_recursion ${1} "440" "file" "*.bin" |
| 165 | chmod_recursion ${1} "440" "file" "*.h" | 165 | chmod_recursion ${1} "440" "file" "*.h" |
| @@ -171,7 +171,7 @@ function chmod_file() { | |||
| 171 | 171 | ||
| 172 | function chmod_dir() { | 172 | function chmod_dir() { |
| 173 | chmod_recursion ${1} ${2} "dir" | 173 | chmod_recursion ${1} ${2} "dir" |
| 174 | -} | 174 | +} |
| 175 | 175 | ||
| 176 | function chmod_recursion() { | 176 | function chmod_recursion() { |
| 177 | # install-for-all 实际上是给other组用户赋予了和同组用户相同的权限 | 177 | # install-for-all 实际上是给other组用户赋予了和同组用户相同的权限 |
| @@ -424,7 +424,7 @@ function install_process() { | |||
| 424 | fi | 424 | fi |
| 425 | if [ -n "${ARCH}" ]; then | 425 | if [ -n "${ARCH}" ]; then |
| 426 | if [ "${arch_pkg}" != "${ARCH}" ]; then | 426 | if [ "${arch_pkg}" != "${ARCH}" ]; then |
| 427 | - print "ERROR" "Install failed, pkg arch ${arch_pkg} is not consistent with the current enviroment architecture ${ARCH}." | 427 | + print "ERROR" "Install failed, pkg arch ${arch_pkg} is not consistent with the current environment architecture ${ARCH}." |
| 428 | exit 1 | 428 | exit 1 |
| 429 | fi | 429 | fi |
| 430 | fi | 430 | fi |
| @@ -474,9 +474,20 @@ function check_owner() { | |||
| 474 | function uninstall() { | 474 | function uninstall() { |
| 475 | # 使用awk读取version.info文件中的version键对应的值 | 475 | # 使用awk读取version.info文件中的version键对应的值 |
| 476 | VERSION_INFO_PATH=${default_install_path}/latest/version.info | 476 | VERSION_INFO_PATH=${default_install_path}/latest/version.info |
| 477 | + # 容错: version.info 缺失(latest软链损坏/版本目录被删)时给出明确报错, 避免 grep 报错中断 | ||
| 478 | + if [ ! -f "$VERSION_INFO_PATH" ]; then | ||
| 479 | + print "ERROR" "Uninstall failed, can not find ${VERSION_INFO_PATH}, the installation may be broken. Please reinstall or remove ${default_install_path} manually." | ||
| 480 | + exit 1 | ||
| 481 | + fi | ||
| 477 | old_version=$(grep -E 'Ascend-cann-asdsip :' $VERSION_INFO_PATH | cut -d ':' -f2) | 482 | old_version=$(grep -E 'Ascend-cann-asdsip :' $VERSION_INFO_PATH | cut -d ':' -f2) |
| 478 | old_version=$(echo "$old_version" | sed 's/^[ ]*//') | 483 | old_version=$(echo "$old_version" | sed 's/^[ ]*//') |
| 479 | 484 | ||
| 485 | + # 容错: 提取到的版本号为空时直接报错, 避免拼接出带尾斜杠的无效路径 | ||
| 486 | + if [ -z "$old_version" ]; then | ||
| 487 | + print "ERROR" "Uninstall failed, can not parse version from ${VERSION_INFO_PATH}. Please remove ${default_install_path} manually." | ||
| 488 | + exit 1 | ||
| 489 | + fi | ||
| 490 | + | ||
| 480 | # 输出version值 | 491 | # 输出version值 |
| 481 | echo "Version is: $old_version" | 492 | echo "Version is: $old_version" |
| 482 | 493 | ||
| @@ -494,7 +505,7 @@ function check_uninstall_path() { | |||
| 494 | default_install_path="${HOME}/Ascend/asdsip" | 505 | default_install_path="${HOME}/Ascend/asdsip" |
| 495 | fi | 506 | fi |
| 496 | fi | 507 | fi |
| 497 | - | 508 | + |
| 498 | if [ ! -d "${default_install_path}" ]; then | 509 | if [ ! -d "${default_install_path}" ]; then |
| 499 | print "ERROR" "Uninstall failed, can not find the path of Ascend-cann-asdsip." | 510 | print "ERROR" "Uninstall failed, can not find the path of Ascend-cann-asdsip." |
| 500 | exit 1 | 511 | exit 1 |
| @@ -583,7 +594,7 @@ function upgrade() { | |||
| 583 | remove_back_up_version | 594 | remove_back_up_version |
| 584 | print "INFO" "Ascend-cann-asdsip upgrade success!" | 595 | print "INFO" "Ascend-cann-asdsip upgrade success!" |
| 585 | } | 596 | } |
| 586 | - | 597 | + |
| 587 | function main() { | 598 | function main() { |
| 588 | parse_script_args $* | 599 | parse_script_args $* |
| 589 | if [ "${uninstall_flag}" == "y" ]; then | 600 | if [ "${uninstall_flag}" == "y" ]; then |
| @@ -1,5 +1,5 @@ | |||
| 1 | # -*- coding: UTF-8 -*- | 1 | # -*- coding: UTF-8 -*- |
| 2 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 3 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 4 | # CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | # CANN Open Software License Agreement Version 2.0 (the "License"). |
| 5 | # Please refer to the License for details. You may not use this file except in compliance with the License. | 5 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -7,25 +7,40 @@ | |||
| 7 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 7 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 8 | # See LICENSE in the root of the software repository for the full text of the License. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 9 | 9 | ||
| 10 | -import os | ||
| 11 | import configparser | 10 | import configparser |
| 12 | import json | 11 | import json |
| 13 | import logging | 12 | import logging |
| 13 | +import os | ||
| 14 | import stat | 14 | import stat |
| 15 | import sys | 15 | import sys |
| 16 | from collections import namedtuple | 16 | from collections import namedtuple |
| 17 | + | ||
| 17 | from build_util import get_build_target_list | 18 | from build_util import get_build_target_list |
| 18 | 19 | ||
| 19 | - | 20 | +logging.basicConfig( |
| 20 | -logging.basicConfig(level=logging.INFO, | 21 | + level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" |
| 21 | - format='%(asctime)s - %(levelname)s - %(message)s') | 22 | +) |
| 22 | 23 | ||
| 23 | JsonSpecification = namedtuple( | 24 | JsonSpecification = namedtuple( |
| 24 | - "JsonSpecification", ["mode", "inputs", "outputs", "attrs", "dir", "deterministic"]) | 25 | + "JsonSpecification", ["mode", "inputs", "outputs", "attrs", "dir", "deterministic"] |
| 26 | +) | ||
| 25 | 27 | ||
| 26 | -TacticDef = namedtuple("TacticDef", [ | 28 | +TacticDef = namedtuple( |
| 27 | - "ops_name", "operation", "input_num", "output_num", "dtypes_in", "dtypes_out", "formats_in", | 29 | + "TacticDef", |
| 28 | - "formats_out", "mode", "attrs", "soc_support"]) | 30 | + [ |
| 31 | + "ops_name", | ||
| 32 | + "operation", | ||
| 33 | + "input_num", | ||
| 34 | + "output_num", | ||
| 35 | + "dtypes_in", | ||
| 36 | + "dtypes_out", | ||
| 37 | + "formats_in", | ||
| 38 | + "formats_out", | ||
| 39 | + "mode", | ||
| 40 | + "attrs", | ||
| 41 | + "soc_support", | ||
| 42 | + ], | ||
| 43 | +) | ||
| 29 | 44 | ||
| 30 | 45 | ||
| 31 | TARGET_INI = "configs/tbe_tactic_json.ini" | 46 | TARGET_INI = "configs/tbe_tactic_json.ini" |
| @@ -81,9 +96,17 @@ def read_tbe_json_file(json_file_path): | |||
| 81 | outputs = item["outputs"] | 96 | outputs = item["outputs"] |
| 82 | mode = item["implMode"] if "implMode" in item else None | 97 | mode = item["implMode"] if "implMode" in item else None |
| 83 | attrs = item["attrs"] if "attrs" in item else None | 98 | attrs = item["attrs"] if "attrs" in item else None |
| 84 | - deterministic = item["deterministic"] if "deterministic" in item else None | 99 | + deterministic = ( |
| 100 | + item["deterministic"] if "deterministic" in item else None | ||
| 101 | + ) | ||
| 85 | json_info = JsonSpecification( | 102 | json_info = JsonSpecification( |
| 86 | - mode=mode, inputs=inputs, outputs=outputs, attrs=attrs, dir=file_name, deterministic=deterministic) | 103 | + mode=mode, |
| 104 | + inputs=inputs, | ||
| 105 | + outputs=outputs, | ||
| 106 | + attrs=attrs, | ||
| 107 | + dir=file_name, | ||
| 108 | + deterministic=deterministic, | ||
| 109 | + ) | ||
| 87 | ops_specification_list.append(json_info) | 110 | ops_specification_list.append(json_info) |
| 88 | except FileNotFoundError: | 111 | except FileNotFoundError: |
| 89 | logging.error("file %s is not found!", json_file) | 112 | logging.error("file %s is not found!", json_file) |
| @@ -170,13 +193,23 @@ def get_match_json(json_info_dir, tactic_info): | |||
| 170 | return match_json_dir, result | 193 | return match_json_dir, result |
| 171 | count_check = 0 | 194 | count_check = 0 |
| 172 | for json_info in ops_specification_list: | 195 | for json_info in ops_specification_list: |
| 173 | - matched = impl_mode_matched_or_not(json_info.mode, tactic_info.mode) \ | 196 | + matched = ( |
| 197 | + impl_mode_matched_or_not(json_info.mode, tactic_info.mode) | ||
| 174 | and inputs_outputs_matched_or_not( | 198 | and inputs_outputs_matched_or_not( |
| 175 | - json_info.inputs, tactic_info.input_num, tactic_info.dtypes_in, tactic_info.formats_in) \ | 199 | + json_info.inputs, |
| 200 | + tactic_info.input_num, | ||
| 201 | + tactic_info.dtypes_in, | ||
| 202 | + tactic_info.formats_in, | ||
| 203 | + ) | ||
| 176 | and inputs_outputs_matched_or_not( | 204 | and inputs_outputs_matched_or_not( |
| 177 | - json_info.outputs, tactic_info.output_num, tactic_info.dtypes_out, tactic_info.formats_out) \ | 205 | + json_info.outputs, |
| 178 | - and attrs_matched_or_not(json_info.attrs, tactic_info.attrs) \ | 206 | + tactic_info.output_num, |
| 207 | + tactic_info.dtypes_out, | ||
| 208 | + tactic_info.formats_out, | ||
| 209 | + ) | ||
| 210 | + and attrs_matched_or_not(json_info.attrs, tactic_info.attrs) | ||
| 179 | and deterministic_matched_or_not(json_info.deterministic) | 211 | and deterministic_matched_or_not(json_info.deterministic) |
| 212 | + ) | ||
| 180 | 213 | ||
| 181 | if matched: | 214 | if matched: |
| 182 | match_json_dir, result = json_info.dir, True | 215 | match_json_dir, result = json_info.dir, True |
| @@ -184,7 +217,8 @@ def get_match_json(json_info_dir, tactic_info): | |||
| 184 | 217 | ||
| 185 | if count_check != 1: | 218 | if count_check != 1: |
| 186 | logging.error( | 219 | logging.error( |
| 187 | - f"{json_info_dir}: matched json file number is {count_check}, which should be 1") | 220 | + f"{json_info_dir}: matched json file number is {count_check}, which should be 1" |
| 221 | + ) | ||
| 188 | result = False | 222 | result = False |
| 189 | return match_json_dir, result | 223 | return match_json_dir, result |
| 190 | 224 | ||
| @@ -211,30 +245,28 @@ def get_tbe_tactic_json(tbe_config_ini): | |||
| 211 | target_version_list = get_build_target_list() | 245 | target_version_list = get_build_target_list() |
| 212 | logging.info("target version list: %s", target_version_list) | 246 | logging.info("target version list: %s", target_version_list) |
| 213 | for target_version in target_version_list: | 247 | for target_version in target_version_list: |
| 214 | - if target_version == 'ascend310b': | 248 | + if target_version == "ascend310b": |
| 215 | logging.warning("ascend310b opp kernel is not ready") | 249 | logging.warning("ascend310b opp kernel is not ready") |
| 216 | try: | 250 | try: |
| 217 | for tactic_name in tbe_config_ini.sections(): | 251 | for tactic_name in tbe_config_ini.sections(): |
| 218 | try: | 252 | try: |
| 219 | ops = tbe_config_ini.get(tactic_name, "ops") | 253 | ops = tbe_config_ini.get(tactic_name, "ops") |
| 220 | - operation_name = tbe_config_ini.get( | 254 | + operation_name = tbe_config_ini.get(tactic_name, "operationName") |
| 221 | - tactic_name, "operationName") | 255 | + input_num = int(tbe_config_ini.get(tactic_name, "inputCount")) |
| 222 | - input_num = int(tbe_config_ini.get( | 256 | + output_num = int(tbe_config_ini.get(tactic_name, "outputCount")) |
| 223 | - tactic_name, "inputCount")) | ||
| 224 | - output_num = int(tbe_config_ini.get( | ||
| 225 | - tactic_name, "outputCount")) | ||
| 226 | input_dtypes = tbe_config_ini.get(tactic_name, "dtypeIn") | 257 | input_dtypes = tbe_config_ini.get(tactic_name, "dtypeIn") |
| 227 | output_dtypes = tbe_config_ini.get(tactic_name, "dtypeOut") | 258 | output_dtypes = tbe_config_ini.get(tactic_name, "dtypeOut") |
| 228 | input_formats = tbe_config_ini.get( | 259 | input_formats = tbe_config_ini.get( |
| 229 | - tactic_name, "formatIn", fallback=None) | 260 | + tactic_name, "formatIn", fallback=None |
| 261 | + ) | ||
| 230 | output_formats = tbe_config_ini.get( | 262 | output_formats = tbe_config_ini.get( |
| 231 | - tactic_name, "formatOut", fallback=None) | 263 | + tactic_name, "formatOut", fallback=None |
| 232 | - mode = tbe_config_ini.get( | 264 | + ) |
| 233 | - tactic_name, "mode", fallback=None) | 265 | + mode = tbe_config_ini.get(tactic_name, "mode", fallback=None) |
| 234 | - attrs = tbe_config_ini.get( | 266 | + attrs = tbe_config_ini.get(tactic_name, "attrs", fallback=None) |
| 235 | - tactic_name, "attrs", fallback=None) | ||
| 236 | soc_support = tbe_config_ini.get( | 267 | soc_support = tbe_config_ini.get( |
| 237 | - tactic_name, "socSupport", fallback=None) | 268 | + tactic_name, "socSupport", fallback=None |
| 269 | + ) | ||
| 238 | except configparser.NoOptionError: | 270 | except configparser.NoOptionError: |
| 239 | logging.error("configparser option is not found: %s", tactic_name) | 271 | logging.error("configparser option is not found: %s", tactic_name) |
| 240 | continue | 272 | continue |
| @@ -252,32 +284,44 @@ def get_tbe_tactic_json(tbe_config_ini): | |||
| 252 | 284 | ||
| 253 | input_dtype_arr = input_dtypes.split(",") | 285 | input_dtype_arr = input_dtypes.split(",") |
| 254 | output_dtype_arr = output_dtypes.split(",") | 286 | output_dtype_arr = output_dtypes.split(",") |
| 255 | - input_format_arr = input_formats.split( | 287 | + input_format_arr = input_formats.split(",") if input_formats else None |
| 256 | - ",") if input_formats else None | 288 | + output_format_arr = ( |
| 257 | - output_format_arr = output_formats.split( | 289 | + output_formats.split(",") if output_formats else None |
| 258 | - ",") if output_formats else None | 290 | + ) |
| 259 | - attr_arr = attrs.split(',') if attrs else None | 291 | + attr_arr = attrs.split(",") if attrs else None |
| 260 | 292 | ||
| 261 | - tactic_info = TacticDef(ops_name=ops, operation=operation_name, | 293 | + tactic_info = TacticDef( |
| 262 | - input_num=input_num, output_num=output_num, | 294 | + ops_name=ops, |
| 263 | - dtypes_in=input_dtype_arr, dtypes_out=output_dtype_arr, | 295 | + operation=operation_name, |
| 264 | - formats_in=input_format_arr, formats_out=output_format_arr, | 296 | + input_num=input_num, |
| 265 | - mode=mode, attrs=attr_arr, soc_support=soc_support) | 297 | + output_num=output_num, |
| 266 | - if tactic_info.soc_support and target_version not in tactic_info.soc_support: | 298 | + dtypes_in=input_dtype_arr, |
| 299 | + dtypes_out=output_dtype_arr, | ||
| 300 | + formats_in=input_format_arr, | ||
| 301 | + formats_out=output_format_arr, | ||
| 302 | + mode=mode, | ||
| 303 | + attrs=attr_arr, | ||
| 304 | + soc_support=soc_support, | ||
| 305 | + ) | ||
| 306 | + if ( | ||
| 307 | + tactic_info.soc_support | ||
| 308 | + and target_version not in tactic_info.soc_support | ||
| 309 | + ): | ||
| 267 | continue | 310 | continue |
| 268 | - json_info_dir = os.path.join( | 311 | + json_info_dir = os.path.join(tbe_kernel_path, target_version, ops) |
| 269 | - tbe_kernel_path, target_version, ops) | 312 | + match_json_dir, ret = get_match_json(json_info_dir, tactic_info) |
| 270 | - match_json_dir, ret = get_match_json( | ||
| 271 | - json_info_dir, tactic_info) | ||
| 272 | if not ret: | 313 | if not ret: |
| 273 | logging.error( | 314 | logging.error( |
| 274 | - f"[{target_version}] get tactic failed: {tactic_name}") | 315 | + f"[{target_version}] get tactic failed: {tactic_name}" |
| 275 | - exit(1) | 316 | + ) |
| 317 | + sys.exit(1) | ||
| 276 | if not json_paths_info.has_section(operation_name): | 318 | if not json_paths_info.has_section(operation_name): |
| 277 | json_paths_info.add_section(operation_name) | 319 | json_paths_info.add_section(operation_name) |
| 278 | json_paths_info.set( | 320 | json_paths_info.set( |
| 279 | - operation_name, tactic_name + "." + target_version, | 321 | + operation_name, |
| 280 | - os.path.join(ops, match_json_dir)) | 322 | + tactic_name + "." + target_version, |
| 323 | + os.path.join(ops, match_json_dir), | ||
| 324 | + ) | ||
| 281 | 325 | ||
| 282 | except configparser.NoSectionError: | 326 | except configparser.NoSectionError: |
| 283 | result = False | 327 | result = False |
| @@ -290,11 +334,13 @@ def get_tbe_tactic_json(tbe_config_ini): | |||
| 290 | 334 | ||
| 291 | def write_tbe_tactic_json(json_paths_info): | 335 | def write_tbe_tactic_json(json_paths_info): |
| 292 | code_root_dir = get_code_root() | 336 | code_root_dir = get_code_root() |
| 293 | - tbe_tactic_json_path = os.path.join( | 337 | + tbe_tactic_json_path = os.path.join(code_root_dir, "configs/tbe_tactic_json.ini") |
| 294 | - code_root_dir, "configs/tbe_tactic_json.ini") | 338 | + fd = os.open( |
| 295 | - fd = os.open(tbe_tactic_json_path, os.O_WRONLY | os.O_CREAT | | 339 | + tbe_tactic_json_path, |
| 296 | - os.O_TRUNC, stat.S_IWUSR | stat.S_IRUSR) | 340 | + os.O_WRONLY | os.O_CREAT | os.O_TRUNC, |
| 297 | - with os.fdopen(fd, 'w+') as f: | 341 | + stat.S_IWUSR | stat.S_IRUSR, |
| 342 | + ) | ||
| 343 | + with os.fdopen(fd, "w+") as f: | ||
| 298 | try: | 344 | try: |
| 299 | json_paths_info.write(f, space_around_delimiters=False) | 345 | json_paths_info.write(f, space_around_delimiters=False) |
| 300 | except configparser.Error as e: | 346 | except configparser.Error as e: |
| @@ -307,11 +353,11 @@ def main(): | |||
| 307 | tbe_config_ini, ret = read_tbe_config_file() | 353 | tbe_config_ini, ret = read_tbe_config_file() |
| 308 | if not ret: | 354 | if not ret: |
| 309 | logging.error("get tbe tactic info failed!") | 355 | logging.error("get tbe tactic info failed!") |
| 310 | - exit(1) | 356 | + sys.exit(1) |
| 311 | json_paths_info, ret = get_tbe_tactic_json(tbe_config_ini) | 357 | json_paths_info, ret = get_tbe_tactic_json(tbe_config_ini) |
| 312 | if not ret: | 358 | if not ret: |
| 313 | logging.error("get tbe tactic json failed!") | 359 | logging.error("get tbe tactic json failed!") |
| 314 | - exit(1) | 360 | + sys.exit(1) |
| 315 | write_tbe_tactic_json(json_paths_info) | 361 | write_tbe_tactic_json(json_paths_info) |
| 316 | 362 | ||
| 317 | 363 | ||