Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
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").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
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.
9 : */
10 :
11 : #include "aicpu_task_cache_manager.h"
12 :
13 : #include "log.h"
14 :
15 : namespace hcomm {
16 :
17 : // 全局变量定义
18 : AicpuTaskCache AicpuTaskCacheManager::aicpuTaskCache;
19 :
20 : // 全局线程变量定义
21 : thread_local std::string AicpuTaskCacheManager::cacheTag = "";
22 : thread_local bool AicpuTaskCacheManager::isHit = false;
23 : thread_local AicpuTaskCacheEntry* AicpuTaskCacheManager::cacheEntryPtr = nullptr;
24 :
25 14 : bool AicpuTaskCacheManager::NeedCacheTask()
26 : {
27 : // cache miss且cache容量未满
28 14 : return !isHit && cacheEntryPtr != nullptr;
29 : }
30 :
31 4 : HcclResult AicpuTaskCacheManager::AddWqeArray(
32 : UbConnLite* ubConnLitePtr, UbTransportLiteImpl* ubTransportLiteImplPtr, const std::vector<WqeTask>& wqeTasks,
33 : const uint32_t streamId, const uint32_t dbSqeIdx, const bool isReportTask, const DbSqeProfInfo& dbSqeProfInfo)
34 : {
35 : // 注意: 只有需要cache task时, UbTransportLiteImpl才会调用本函数
36 4 : CHK_PRT_RET(
37 : NeedCacheTask() == false,
38 : HCCL_ERROR(
39 : "[AicpuTaskCacheManager][AddWqeArray] should not invoke if isHit[%d] cacheEntryPtr[0x%016llx]", isHit,
40 : cacheEntryPtr),
41 : HCCL_E_INTERNAL);
42 :
43 2 : CHK_PTR_NULL(ubConnLitePtr);
44 :
45 1 : CHK_RET(cacheEntryPtr->AddWqeArray(
46 : ubConnLitePtr, ubTransportLiteImplPtr, wqeTasks, streamId, dbSqeIdx, isReportTask, dbSqeProfInfo));
47 :
48 1 : return HCCL_SUCCESS;
49 : }
50 :
51 6 : HcclResult AicpuTaskCacheManager::AddSqeArray(
52 : RtsqA5* rtsqPtr, AicpuTsThread* aicpuTsThreadPtr, const uint64_t sqeCount, const uint8_t* sqeArray,
53 : const uint32_t streamId)
54 : {
55 : // 注意: 只有需要cache task时, RtsqA5才会调用本函数
56 6 : CHK_PRT_RET(
57 : NeedCacheTask() == false,
58 : HCCL_ERROR(
59 : "[AicpuTaskCacheManager][AddSqeArray] should not invoke if isHit[%d] cacheEntryPtr[0x%016llx]", isHit,
60 : cacheEntryPtr),
61 : HCCL_E_INTERNAL);
62 :
63 4 : CHK_PTR_NULL(rtsqPtr);
64 3 : CHK_PTR_NULL(aicpuTsThreadPtr);
65 :
66 2 : CHK_RET(cacheEntryPtr->AddSqeArray(rtsqPtr, aicpuTsThreadPtr, sqeCount, sqeArray, streamId));
67 :
68 2 : return HCCL_SUCCESS;
69 : }
70 :
71 : } // namespace hcomm
|