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 CUST_AICPUSD_THREADS_PROCESS_H
12 : #define CUST_AICPUSD_THREADS_PROCESS_H
13 :
14 : #include <string>
15 : #include <cstdint>
16 : #include <sys/types.h>
17 : #include "aicpusd_task_queue.h"
18 : #include "aicpu_context.h"
19 :
20 : namespace AicpuSchedule {
21 : /**
22 : * compute process result code.
23 : */
24 : enum class ComputProcessRetCode {
25 : CP_RET_SUCCESS = 0, // success
26 : CP_RET_COMMON_ERROR, // common error
27 : };
28 :
29 : /**
30 : * compute process class.
31 : */
32 : class ComputeProcess {
33 : public:
34 : /**
35 : * Get instance.
36 : * @return instance.
37 : */
38 : static ComputeProcess& GetInstance();
39 :
40 : /**
41 : * start compute process.
42 : * @param deviceId device id
43 : * @param hostPid host pid
44 : * @param pidSign pid signature
45 : * @param profilingMode profiling Mode
46 : * @param aicpuPid aicpu-sd pid
47 : * @param vfId vf id
48 : * @param runMode pcie socket or thread run mode
49 : * @return 0:success, other:fail
50 : */
51 : int32_t Start(
52 : const uint32_t deviceId, const pid_t hostPid, const uint32_t profilingMode, const pid_t aicpuPid,
53 : const uint32_t vfId, const aicpu::AicpuRunMode runMode);
54 :
55 : void UpdateProfilingSetting(uint32_t flag);
56 :
57 : bool DoSplitKernelTask(const AICPUSharderTaskInfo& taskInfo);
58 : bool DoRandomKernelTask();
59 :
60 : /**
61 : * stop compute process.
62 : */
63 : void Stop();
64 :
65 : private:
66 : ComputeProcess();
67 18 : ~ComputeProcess() = default;
68 :
69 : // not allow copy constructor and assignment operators
70 : ComputeProcess(const ComputeProcess&) = delete;
71 : ComputeProcess& operator=(const ComputeProcess&) = delete;
72 :
73 : uint32_t RegisterScheduleTask();
74 : uint32_t SubmitRandomKernelTask(const aicpu::Closure& task);
75 : uint32_t SubmitSplitKernelTask(const AICPUSharderTaskInfo& taskInfo, const std::queue<aicpu::Closure>& taskQueue);
76 : uint32_t SubmitBatchSplitKernelEventOneByOne(const AICPUSharderTaskInfo& taskInfo) const;
77 : uint32_t SubmitBatchSplitKernelEventDc(const AICPUSharderTaskInfo& taskInfo);
78 : uint32_t SubmitOneSplitKernelEvent(const AICPUSharderTaskInfo& taskInfo) const;
79 : bool GetAndDoSplitKernelTask();
80 :
81 : // the device id
82 : uint32_t deviceId_;
83 :
84 : // the pid of host process
85 : pid_t hostPid_;
86 :
87 : // number of aicpu
88 : uint32_t aicpuNum_;
89 :
90 : // the Mode decide if profiling open
91 : ProfilingMode profilingMode_;
92 :
93 : // the pid of aicpu-sd process
94 : pid_t aicpuPid_;
95 :
96 : // vf id
97 : uint32_t vfId_;
98 :
99 : // sharder task for split kernel
100 : TaskMap splitKernelTask_;
101 :
102 : // sharder task for random kernel
103 : TaskQueue randomKernelTask_;
104 :
105 : // cust aicpusd run mode : thread pice socket
106 : aicpu::AicpuRunMode runMode_;
107 : };
108 : } // namespace AicpuSchedule
109 : #endif
|