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 "callback_thread_manager.h"
12 : #include "log.h"
13 :
14 : namespace hccl {
15 :
16 3 : bool ThreadStreamManager::StreamHasBeenReged(void* stream) { return streamTidMap_.find(stream) != streamTidMap_.end(); }
17 :
18 1 : HcclResult ThreadStreamManager::RegTidAndStream(u64 tid, rtStream_t stream)
19 : {
20 1 : CHK_PTR_NULL(stream);
21 :
22 1 : std::unique_lock<std::mutex> lock(mapMutex_);
23 1 : streamTidMap_[stream] = tid;
24 :
25 1 : return HCCL_SUCCESS;
26 1 : }
27 :
28 2 : HcclResult ThreadStreamManager::GetStreamByTid(u64 tid, rtStream_t& stream)
29 : {
30 2 : std::unique_lock<std::mutex> lock(mapMutex_);
31 2 : std::map<rtStream_t, u64>::iterator it;
32 2 : for (it = streamTidMap_.begin(); it != streamTidMap_.end(); it++) {
33 1 : if (it->second == tid) {
34 1 : stream = it->first;
35 1 : return HCCL_SUCCESS;
36 : }
37 : }
38 1 : return HCCL_E_NOT_FOUND;
39 2 : }
40 :
41 1 : void ThreadStreamManager::ReleaseTidAndStream(rtStream_t stream)
42 : {
43 1 : std::unique_lock<std::mutex> lock(mapMutex_);
44 1 : if (StreamHasBeenReged(stream)) {
45 1 : streamTidMap_.erase(stream);
46 : }
47 1 : }
48 :
49 : } // namespace hccl
|