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 CTX_H
12 : #define CTX_H
13 :
14 : #include "hccl_common.h"
15 : #include "hccl/base.h"
16 : #include "notify_pool.h"
17 :
18 : namespace hccl {
19 : using FftsCounterCallBack = HcclResult (*)(const HcclDispatcher&, Stream&);
20 : HcclResult FftsHeadCounter(const HcclDispatcher& dispatcher, Stream& stream);
21 : HcclResult FftsTailCounter(const HcclDispatcher& dispatcher, Stream& stream);
22 :
23 : enum class CtxDispatcherType {
24 : DISPATCHER_NORMAL = 0,
25 : DISPATCHER_VIRTURAL,
26 : DISPATCHER_AICPU,
27 : DISPATCHER_FFTS,
28 : };
29 :
30 : class DispatcherCtx {
31 : public:
32 422 : explicit DispatcherCtx(u32 devicePhyId, u32 timeOut = INVALID_UINT)
33 422 : : devicePhyId_(devicePhyId),
34 422 : waitTimeOut_(timeOut) {};
35 422 : ~DispatcherCtx() { Destroy(); };
36 : HcclResult Init();
37 : HcclResult Destroy();
38 : HcclDispatcher GetDispatcher() const;
39 : u32 GetWaitTimeOut() const;
40 : HcclResult SetWaitTimeOut(u32 waitTimeOut);
41 : FftsCounterCallBack GetInitTaskCallback() const;
42 : FftsCounterCallBack GetLaunchTaskCallback() const;
43 : HcclResult SetDispatcherHcclQos(u32 hcclQos);
44 :
45 : private:
46 : CtxDispatcherType dispatcherType_;
47 : HcclDispatcher dispatcher_{nullptr};
48 :
49 : u32 devicePhyId_ = INVALID_UINT;
50 : u32 deviceLogicId_ = INVALID_UINT;
51 : DevType deviceType_ = DevType::DEV_TYPE_COUNT;
52 : u32 waitTimeOut_ = INVALID_UINT;
53 : HcclResult DispatcherInit(CtxDispatcherType type, const s32 devicePhyId, HcclDispatcher* dispatcher);
54 :
55 : FftsCounterCallBack g_InitTaskCallback = nullptr;
56 : FftsCounterCallBack g_LaunchTaskCallback = nullptr;
57 :
58 : std::mutex destroyMutex_;
59 : };
60 : } // namespace hccl
61 :
62 : #endif
|