已合并
CleanCode #933
leihuan1创建于 3月17日
CleanCode #933
已合并
共 13 个文件变更+16-15
| @@ -1,4 +1,5 @@ | |||
| 1 | #!/usr/bin/env python3 | 1 | #!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- | ||
| 2 | # ----------------------------------------------------------------------------------------------------------- | 3 | # ----------------------------------------------------------------------------------------------------------- |
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 4 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 5 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| @@ -194,7 +194,7 @@ public: | |||
| 194 | rtError_t BindSqPerStream(Stream * const streamIn, const uint32_t flag); | 194 | rtError_t BindSqPerStream(Stream * const streamIn, const uint32_t flag); |
| 195 | rtError_t UnBindSqPerStream(Stream * const streamIn); | 195 | rtError_t UnBindSqPerStream(Stream * const streamIn); |
| 196 | rtError_t ModelGetStreams(Stream **streams, uint32_t *numStreams) const; | 196 | rtError_t ModelGetStreams(Stream **streams, uint32_t *numStreams) const; |
| 197 | - rtError_t ModelDestroyRegisterCallback(const rtCallback_t fn, void *ptr); | 197 | + rtError_t ModelDestroyRegisterCallback(const rtCallback_t fn, const void *ptr); |
| 198 | rtError_t ModelDestroyUnregisterCallback(const rtCallback_t fn); | 198 | rtError_t ModelDestroyUnregisterCallback(const rtCallback_t fn); |
| 199 | 199 | ||
| 200 | void SetModelExecutorType(uint32_t executorFlag) | 200 | void SetModelExecutorType(uint32_t executorFlag) |
| @@ -25,7 +25,7 @@ void RecycleThreadDoForStarsV2(Device *deviceInfo); | |||
| 25 | 25 | ||
| 26 | TaskInfo* GetTaskInfo(const Device * const dev, uint32_t streamId, uint32_t id); | 26 | TaskInfo* GetTaskInfo(const Device * const dev, uint32_t streamId, uint32_t id); |
| 27 | 27 | ||
| 28 | -rtError_t TaskReclaimByStream(Stream * const stm, const bool limited, const bool needLog = true); | 28 | +rtError_t TaskReclaimByStream(const Stream * const stm, const bool limited, const bool needLog = true); |
| 29 | 29 | ||
| 30 | rtError_t StreamLaunchCpuKernel(const rtKernelLaunchNames_t * const launchNames, const uint32_t coreDim, | 30 | rtError_t StreamLaunchCpuKernel(const rtKernelLaunchNames_t * const launchNames, const uint32_t coreDim, |
| 31 | const rtArgsEx_t * const argsInfo, Stream * const stm, const uint32_t flag); | 31 | const rtArgsEx_t * const argsInfo, Stream * const stm, const uint32_t flag); |
| @@ -42,7 +42,7 @@ void RecycleModelBindStreamAllTask(Stream * const stm, const bool cleanFlag); | |||
| 42 | // 上层使用时,一定要加流同步锁StreamSyncLock | 42 | // 上层使用时,一定要加流同步锁StreamSyncLock |
| 43 | rtError_t SyncTask(Stream * const stm, const uint32_t taskResPos, int32_t timeout); | 43 | rtError_t SyncTask(Stream * const stm, const uint32_t taskResPos, int32_t timeout); |
| 44 | rtError_t SyncTaskForSeparateSendAndRecycle(Stream * const stm, const uint32_t taskResPos, int32_t timeout); | 44 | rtError_t SyncTaskForSeparateSendAndRecycle(Stream * const stm, const uint32_t taskResPos, int32_t timeout); |
| 45 | -rtError_t TaskReclaimByStream(Stream * const stm, const bool limited, const bool needLog = true); | 45 | +rtError_t TaskReclaimByStream(const Stream * const stm, const bool limited, const bool needLog = true); |
| 46 | 46 | ||
| 47 | // device stop时,全量回收。异常析构流程可能进,因此跟老形态保持一致,不能加锁,加锁可能会出现递归锁 | 47 | // device stop时,全量回收。异常析构流程可能进,因此跟老形态保持一致,不能加锁,加锁可能会出现递归锁 |
| 48 | rtError_t TaskReclaimAllStream(const Device * const dev); | 48 | rtError_t TaskReclaimAllStream(const Device * const dev); |
| @@ -3224,7 +3224,7 @@ RTS_API rtError_t rtSetDeviceSatMode(rtFloatOverflowMode_t floatOverflowMode) | |||
| 3224 | 3224 | ||
| 3225 | if ((floatOverflowMode >= RT_OVERFLOW_MODE_SATURATION) && | 3225 | if ((floatOverflowMode >= RT_OVERFLOW_MODE_SATURATION) && |
| 3226 | (floatOverflowMode < RT_OVERFLOW_MODE_UNDEF)) { | 3226 | (floatOverflowMode < RT_OVERFLOW_MODE_UNDEF)) { |
| 3227 | - uint32_t mode = 1 << floatOverflowMode; | 3227 | + const uint32_t mode = 1U << floatOverflowMode; |
| 3228 | const char* errorMsg = (floatOverflowMode == RT_OVERFLOW_MODE_INFNAN) ? | 3228 | const char* errorMsg = (floatOverflowMode == RT_OVERFLOW_MODE_INFNAN) ? |
| 3229 | "the Inf/NaN mode; only the saturation mode can be set" : | 3229 | "the Inf/NaN mode; only the saturation mode can be set" : |
| 3230 | "the saturation mode; only the Inf/NaN mode can be set"; | 3230 | "the saturation mode; only the Inf/NaN mode can be set"; |
| @@ -1923,7 +1923,7 @@ rtError_t ApiErrorDecorator::MemcpyAsyncCheckParam(const rtMemcpyKind_t kind, co | |||
| 1923 | { | 1923 | { |
| 1924 | if ((kind == RT_MEMCPY_HOST_TO_DEVICE_EX) || (kind == RT_MEMCPY_DEVICE_TO_HOST_EX)) { | 1924 | if ((kind == RT_MEMCPY_HOST_TO_DEVICE_EX) || (kind == RT_MEMCPY_DEVICE_TO_HOST_EX)) { |
| 1925 | if (stm != nullptr) { | 1925 | if (stm != nullptr) { |
| 1926 | - COND_RETURN_OUT_ERROR_MSG_CALL(stm->GetModelNum() != 0, RT_ERROR_INVALID_VALUE, | 1926 | + COND_RETURN_OUT_ERROR_MSG_CALL(stm->GetModelNum() != 0U, RT_ERROR_INVALID_VALUE, |
| 1927 | "If stm is a model stream, parameter kind cannot be equal to %d for function MemcpyAsyncCheckParam.", kind); | 1927 | "If stm is a model stream, parameter kind cannot be equal to %d for function MemcpyAsyncCheckParam.", kind); |
| 1928 | } | 1928 | } |
| 1929 | } | 1929 | } |
| @@ -3838,7 +3838,8 @@ rtError_t ApiImpl::NewContext(const uint32_t deviceId, const uint32_t tsId, Cont | |||
| 3838 | "Failed to new context, device_id=%u.", deviceId); | 3838 | "Failed to new context, device_id=%u.", deviceId); |
| 3839 | RT_LOG(RT_LOG_INFO, "curCtx=%p, device_id=%d, ts_id=%u, Runtime_alloc_size %zu", curCtx, deviceId, tsId, sizeof(Context)); | 3839 | RT_LOG(RT_LOG_INFO, "curCtx=%p, device_id=%d, ts_id=%u, Runtime_alloc_size %zu", curCtx, deviceId, tsId, sizeof(Context)); |
| 3840 | rtError_t error = curCtx->Setup(); | 3840 | rtError_t error = curCtx->Setup(); |
| 3841 | - ERROR_PROC_RETURN_MSG_INNER(error, DELETE_O(curCtx);, "Failed to setup context, retCode=%#x", static_cast<uint32_t>(error)); | 3841 | + ERROR_PROC_RETURN_MSG_INNER(error, curCtx->TearDown(); DELETE_O(curCtx);, "Failed to setup context, retCode=%#x", |
| 3842 | + static_cast<uint32_t>(error)); | ||
| 3842 | 3843 | ||
| 3843 | *ctx = curCtx; | 3844 | *ctx = curCtx; |
| 3844 | return error; | 3845 | return error; |
| @@ -477,8 +477,7 @@ rtError_t Context::Setup() | |||
| 477 | const bool syncFlag = ((defaultStream_->Flags() & RT_STREAM_PRIMARY_FIRST_DEFAULT) != 0U) && (!(device_->IsStarsPlatform())); | 477 | const bool syncFlag = ((defaultStream_->Flags() & RT_STREAM_PRIMARY_FIRST_DEFAULT) != 0U) && (!(device_->IsStarsPlatform())); |
| 478 | if (syncFlag) { | 478 | if (syncFlag) { |
| 479 | error = defaultStream_->Synchronize(true); | 479 | error = defaultStream_->Synchronize(true); |
| 480 | - COND_RETURN_ERROR_MSG_INNER(error != RT_ERROR_NONE, error, | 480 | + COND_RETURN_ERROR_MSG_INNER(error != RT_ERROR_NONE, error, "Set up failed, failed to synchronize primaryStream."); |
| 481 | - "Set up failed, failed to synchronize primaryStream."); | ||
| 482 | } | 481 | } |
| 483 | 482 | ||
| 484 | return OnlineStreamInit(chipType); | 483 | return OnlineStreamInit(chipType); |
| @@ -137,8 +137,8 @@ static rtError_t ConvertAsyncDmaForSoftWareSq(MemcpyAsyncTaskInfo * const cpyAsy | |||
| 137 | } | 137 | } |
| 138 | cpyAsyncTask->dmaAddr.offsetAddr.devid = static_cast<uint32_t>(updateStm->Device_()->Id_()); | 138 | cpyAsyncTask->dmaAddr.offsetAddr.devid = static_cast<uint32_t>(updateStm->Device_()->Id_()); |
| 139 | void *sqeDeviceAddr = RtValueToPtr<void *>(updateStm->GetSqBaseAddr() + (updateTask->pos) * sizeof(rtDavidSqe_t)); | 139 | void *sqeDeviceAddr = RtValueToPtr<void *>(updateStm->GetSqBaseAddr() + (updateTask->pos) * sizeof(rtDavidSqe_t)); |
| 140 | - error = curDrv->MemConvertAddr(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(cpyAsyncTask->src)), | 140 | + error = curDrv->MemConvertAddr(RtPtrToValue(cpyAsyncTask->src), RtPtrToValue(sqeDeviceAddr), |
| 141 | - static_cast<uint64_t>(reinterpret_cast<uintptr_t>(sqeDeviceAddr)), cpyAsyncTask->size, &(cpyAsyncTask->dmaAddr)); | 141 | + cpyAsyncTask->size, &(cpyAsyncTask->dmaAddr)); |
| 142 | COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "MemConvertAddr failed, device_id=%d, stream_id=%d, retCode=%#x.", | 142 | COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "MemConvertAddr failed, device_id=%d, stream_id=%d, retCode=%#x.", |
| 143 | updateStm->Device_()->Id_(), updateStm->Id_(), static_cast<uint32_t>(error)); | 143 | updateStm->Device_()->Id_(), updateStm->Id_(), static_cast<uint32_t>(error)); |
| 144 | cpyAsyncTask->destPtr = sqeDeviceAddr; | 144 | cpyAsyncTask->destPtr = sqeDeviceAddr; |
| @@ -2006,10 +2006,10 @@ rtError_t Model::ModelGetStreams(Stream **streams, uint32_t *numStreams) const | |||
| 2006 | return RT_ERROR_NONE; | 2006 | return RT_ERROR_NONE; |
| 2007 | } | 2007 | } |
| 2008 | 2008 | ||
| 2009 | -rtError_t Model::ModelDestroyRegisterCallback(const rtCallback_t fn, void *ptr) | 2009 | +rtError_t Model::ModelDestroyRegisterCallback(const rtCallback_t fn, const void *ptr) |
| 2010 | { | 2010 | { |
| 2011 | const std::unique_lock<std::mutex> mdlDestroyCallbackLock(mdlDestroyCallbackMutex_); | 2011 | const std::unique_lock<std::mutex> mdlDestroyCallbackLock(mdlDestroyCallbackMutex_); |
| 2012 | - MdlDestroyCallbackInfo info{fn, ptr}; | 2012 | + MdlDestroyCallbackInfo info{fn, RtPtrToUnConstPtr<void *>(ptr)}; |
| 2013 | const auto callBackIter = mdlDestroyCallbackSet_.find(info); | 2013 | const auto callBackIter = mdlDestroyCallbackSet_.find(info); |
| 2014 | if (callBackIter != mdlDestroyCallbackSet_.end()) { | 2014 | if (callBackIter != mdlDestroyCallbackSet_.end()) { |
| 2015 | RT_LOG(RT_LOG_ERROR, | 2015 | RT_LOG(RT_LOG_ERROR, |
| @@ -133,7 +133,7 @@ void SetTprtResultForDavinciTask(TaskInfo* taskInfo, const TprtLogicCqReport_t & | |||
| 133 | if (taskInfo->type == TS_TASK_TYPE_KERNEL_AICPU) { | 133 | if (taskInfo->type == TS_TASK_TYPE_KERNEL_AICPU) { |
| 134 | taskInfo->errorCode = aicpuErrMap[errorIndex]; | 134 | taskInfo->errorCode = aicpuErrMap[errorIndex]; |
| 135 | STREAM_REPORT_ERR_MSG(taskInfo->stream, ERR_MODULE_HCCL, | 135 | STREAM_REPORT_ERR_MSG(taskInfo->stream, ERR_MODULE_HCCL, |
| 136 | - "AICPU Kernel task happen error, retCode=%#x, streamId=%u, taskId=%u.", taskInfo->errorCode, taskInfo->stream->Id_(), taskInfo->id); | 136 | + "AICPU Kernel task happen error, retCode=%#x, streamId=%d, taskId=%u.", taskInfo->errorCode, taskInfo->stream->Id_(), taskInfo->id); |
| 137 | } else { | 137 | } else { |
| 138 | RT_LOG(RT_LOG_ERROR, "only support aicpu, streamId=%u, taskId=%u.", taskInfo->stream->Id_(), taskInfo->id); | 138 | RT_LOG(RT_LOG_ERROR, "only support aicpu, streamId=%u, taskId=%u.", taskInfo->stream->Id_(), taskInfo->id); |
| 139 | } | 139 | } |
| @@ -157,7 +157,7 @@ rtError_t TryRecycleTask(Stream * const stm) | |||
| 157 | return RT_ERROR_NONE; | 157 | return RT_ERROR_NONE; |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | -rtError_t TaskReclaimByStream(Stream *const stm, const bool limited, const bool needLog) | 160 | +rtError_t TaskReclaimByStream(const Stream *const stm, const bool limited, const bool needLog) |
| 161 | { | 161 | { |
| 162 | if ((stm->Flags() & RT_STREAM_PERSISTENT) != 0U) { | 162 | if ((stm->Flags() & RT_STREAM_PERSISTENT) != 0U) { |
| 163 | RT_LOG(RT_LOG_ERROR, "persistent stream can not call this func!"); | 163 | RT_LOG(RT_LOG_ERROR, "persistent stream can not call this func!"); |
| @@ -22,7 +22,7 @@ TaskInfo* GetTaskInfo(const Device * const dev, uint32_t streamId, uint32_t id) | |||
| 22 | return dev->GetTaskFactory()->GetTask(static_cast<int32_t>(streamId), static_cast<uint16_t>(id)); | 22 | return dev->GetTaskFactory()->GetTask(static_cast<int32_t>(streamId), static_cast<uint16_t>(id)); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | -rtError_t TaskReclaimByStream(Stream *const stm, const bool limited, const bool needLog) | 25 | +rtError_t TaskReclaimByStream(const Stream *const stm, const bool limited, const bool needLog) |
| 26 | { | 26 | { |
| 27 | UNUSED(stm); | 27 | UNUSED(stm); |
| 28 | UNUSED(limited); | 28 | UNUSED(limited); |