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 : #ifndef LAUNCH_CONTEXT_H
12 : #define LAUNCH_CONTEXT_H
13 :
14 : #include <unordered_map>
15 : #include <unordered_set>
16 : #include <vector>
17 : #include <string>
18 : #include <mutex>
19 : #include <algorithm>
20 : #include "hccl_api_data.h"
21 : #include "log.h"
22 : #include "rtsq_base.h"
23 :
24 : constexpr uint32_t NOTIFY_WAIT_TIMEOUT_DEFAULT = 1836;
25 :
26 : class LaunchContext {
27 : public:
28 : LaunchContext();
29 :
30 : HcclResult SetLaunchMode(const char* launchTag, HcommLaunchMode mode);
31 11 : inline void AddThreadWithTag(ThreadHandle thread) // ffts场景使用,支持储存存多个子图对应的thread信息
32 : {
33 11 : if (mode_ != HCOMM_LAUNCH_MODE_BATCH) {
34 9 : return;
35 : }
36 2 : auto& threadSet = launchModeMap_[launchTag_];
37 2 : threadSet.insert(thread);
38 : }
39 :
40 63 : inline void AddThread(ThreadHandle thread) // 储存当前线程使用的thread
41 : {
42 63 : if (UNLIKELY(mode_ != HCOMM_LAUNCH_MODE_BATCH)) {
43 61 : return;
44 : }
45 2 : if (std::find(threadVec_.begin(), threadVec_.end(), thread) == threadVec_.end()) {
46 2 : threadVec_.push_back(thread);
47 : }
48 : }
49 :
50 : HcclResult SetNotifyWaitTimeOut(uint32_t timeout);
51 : HcclResult GetNotifyWaitTimeOut(uint32_t& timeout);
52 : HcclResult SetSqFullTimeOut(uint32_t timeout);
53 : uint32_t GetSqFullTimeOut();
54 0 : inline bool IsBatchLaunchMode() const { return mode_ == HCOMM_LAUNCH_MODE_BATCH; }
55 : HcclResult HandleDispatchAllStreams();
56 :
57 : private:
58 : HcclResult HandleBatchMode();
59 : HcclResult HandleEagerMode();
60 : HcclResult HandleClear();
61 :
62 : std::string launchTag_; // 当前tag
63 : std::unordered_map<std::string, std::unordered_set<ThreadHandle>>
64 : launchModeMap_; // 按tag粒度记录当前线程使用的thread
65 : std::vector<ThreadHandle> threadVec_; // 不区分tag,记录当前线程使用的thread
66 :
67 : struct NotifyWaitTimeoutConfig {
68 : uint32_t notifyWaitTimeout = NOTIFY_WAIT_TIMEOUT_DEFAULT;
69 : bool isSet = false;
70 : } notifyWaitTimeoutConfig_;
71 :
72 : struct SqFullTimeoutConfig {
73 : uint32_t sqFullTimeout = Hccl::RTSQ_FULL_TIMEOUT_DEFAULT;
74 : bool isSet = false;
75 : } sqFullTimeoutConfig_;
76 :
77 : HcommLaunchMode mode_ = HCOMM_LAUNCH_MODE_EAGER;
78 : };
79 :
80 : #endif
|