LCOV - code coverage report
Current view: top level - base_comm/primitives - launch_context.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 83.3 % 12 10
Test Date: 2026-07-28 12:11:00 Functions: 66.7 % 3 2

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

Generated by: LCOV version 2.0-1