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 CTX_H
11 : #define CTX_H
12 :
13 : #include "hccl_common.h"
14 : #include "hccl/base.h"
15 : #include "notify_pool.h"
16 :
17 : namespace hccl {
18 : using FftsCounterCallBack = HcclResult (*)(const HcclDispatcher&, Stream &);
19 : HcclResult FftsHeadCounter(const HcclDispatcher &dispatcher, Stream &stream);
20 : HcclResult FftsTailCounter(const HcclDispatcher &dispatcher, Stream &stream);
21 :
22 : enum class CtxDispatcherType {
23 : DISPATCHER_NORMAL = 0,
24 : DISPATCHER_VIRTURAL,
25 : DISPATCHER_AICPU,
26 : DISPATCHER_FFTS,
27 : };
28 :
29 : class DispatcherCtx {
30 : public:
31 419 : explicit DispatcherCtx(u32 devicePhyId, u32 timeOut = INVALID_UINT) : devicePhyId_(devicePhyId), waitTimeOut_(timeOut) {};
32 419 : ~DispatcherCtx()
33 : {
34 419 : Destroy();
35 419 : };
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 : }
61 :
62 : #endif
|