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 AICPUSD_THREADS_PROCESS_H
11 : #define AICPUSD_THREADS_PROCESS_H
12 :
13 : #include <cstdint>
14 : #include <sys/types.h>
15 : #include <pthread.h>
16 : #include "aicpu_sharder.h"
17 : #include "aicpusd_task_queue.h"
18 : #include "aicpu_context.h"
19 : #include "aicpusd_interface.h"
20 :
21 : namespace AicpuSchedule {
22 : /**
23 : * compute process class.
24 : */
25 : class ComputeProcess {
26 : public:
27 : /**
28 : * Get instance.
29 : * @return instance.
30 : */
31 : static ComputeProcess &GetInstance();
32 :
33 : /**
34 : * start compute process.
35 : * @param deviceId device id
36 : * @param hostPid host pid
37 : * @param profilingMode profiling Mode
38 : * @param pidSign pid signature
39 : * @param vfId vfId
40 : * @param runMode aicpu run mode
41 : * @return 0:success, other:fail
42 : */
43 : int32_t Start(const std::vector<uint32_t> &deviceVec,
44 : const pid_t hostPid, const std::string &pidSign,
45 : const uint32_t profilMode, const uint32_t vfId, const aicpu::AicpuRunMode runMode);
46 : /**
47 : * stop compute process.
48 : */
49 : void Stop();
50 :
51 : /**
52 : * update profiling Mode.
53 : */
54 : void UpdateProfilingMode(const ProfilingMode mode) const;
55 :
56 : /**
57 : * update profiling Model Mode.
58 : */
59 : void UpdateProfilingModelMode(const bool mode) const;
60 :
61 : std::string DebugString();
62 : bool DoSplitKernelTask(const AICPUSharderTaskInfo &taskInfo);
63 : bool DoRandomKernelTask();
64 :
65 : private:
66 : ComputeProcess();
67 22 : ~ComputeProcess() = default;
68 :
69 : // not allow copy constructor and assignment operators
70 : ComputeProcess(ComputeProcess &) = delete;
71 : ComputeProcess &operator = (ComputeProcess &) = delete;
72 :
73 : /**
74 : * start tdt server.
75 : */
76 : int32_t StartTdtServer();
77 :
78 : /**
79 : * stop tdt server.
80 : */
81 : void StopTdtServer() const;
82 :
83 : /**
84 : * register sharder task
85 : * @return 0:success, other:fail
86 : */
87 : int32_t RegisterScheduleTask();
88 :
89 : uint32_t SubmitRandomKernelTask(const aicpu::Closure &task);
90 : uint32_t SubmitSplitKernelTask(const AICPUSharderTaskInfo &taskInfo,
91 : const std::queue<aicpu::Closure> &taskQueue);
92 : uint32_t SubmitBatchSplitKernelEventOneByOne(const AICPUSharderTaskInfo &taskInfo) const;
93 : uint32_t SubmitBatchSplitKernelEventDc(const AICPUSharderTaskInfo &taskInfo);
94 : uint32_t SubmitOneSplitKernelEvent(const AICPUSharderTaskInfo &taskInfo) const;
95 : bool GetAndDoSplitKernelTask();
96 :
97 : int32_t MemorySvmDevice();
98 : void LoadKernelSo();
99 :
100 : void LoadExtendKernelSo();
101 :
102 : private:
103 : // the device id
104 : std::vector<uint32_t> deviceVec_;
105 :
106 : // host device id
107 : uint32_t hostDeviceId_;
108 :
109 : // the pid of host process
110 : pid_t hostPid_;
111 :
112 : // the pid sign of host process
113 : std::string pidSign_;
114 :
115 : // aicpu num of all device
116 : uint32_t aicpuNum_;
117 :
118 : // the Mode decide if profiling open
119 : ProfilingMode profilingMode_;
120 :
121 : // sharder task for split kernel
122 : TaskMap splitKernelTask_;
123 :
124 : // sharder task for random kernel
125 : TaskQueue randomKernelTask_;
126 :
127 : // vf id
128 : uint32_t vfId_;
129 :
130 : // it is used to mark whether the tdt server is opened.
131 : bool isStartTdtFlag_;
132 :
133 : // aicpu run mode
134 : aicpu::AicpuRunMode runMode_;
135 : };
136 : }
137 :
138 : #endif
|