Coverage for  / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / core / multicore / modules / common / runtime_structs.py: 0%

52 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-05-20 07:18 +0800

1# Copyright 2026 Huawei Technologies Co., Ltd 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14# ============================================================================ 

15""" 

16C++ runtime header structs mapped to ctypes.Structure. 

17Matches runtime_head.hpp exactly. 

18""" 

19import ctypes 

20from enum import IntEnum 

21 

22# ── Constants (match runtime_head.hpp exactly) ──────────────────────────────── 

23MAX_TENSOR_DIMS = 4 

24MAX_INPUTS_PER_TASK = 4 

25MAX_OUTPUTS_PER_TASK = 4 

26 

27MAX_TASK_NUM = 256 * 100 

28MAX_EVENT_NUM = 1024 

29NUM_WORKERS_VECTOR = 48 

30NUM_WORKERS_CUBE = 24 

31QUEUE_CAPACITY = 100 

32TASK_TYPE_INDEX_NUM = 256 * 100 

33MAX_GROUP_LIST = 512 

34ATOMIC_ADD_VALUE_LEN = 8 

35 

36# ── Enums ───────────────────────────────────────────────────────────────────── 

37class TaskAiCoreType(IntEnum): 

38 TASK_AICORE_INVALID = 0 

39 TASK_AICORE_CUBE = 1 

40 TASK_AICORE_VECTOR = 2 

41 TASK_AICORE_MIX = 3 

42 

43 

44class TaskType(IntEnum): 

45 TASK_TERMINATE = 0 

46 TASK_BEGIN_TASK_GRAPH = 10 

47 TASK_ADD_CUSTOM = 101 

48 TASK_SWI_GLU = 102 

49 TASK_MATMUL = 103 

50 TASK_GROUPED_MATMUL = 104 

51 TASK_SHMEM_PUT_MEM_SIGNAL = 105 

52 TASK_SWI_GLU_GRAD = 106 

53 

54 

55class EventType(IntEnum): 

56 EVENT_EMPTY = 900 

57 EVENT_LAUNCH_TASKS = 901 

58 EVENT_LAUNCH_MASSIVE_TASKS = 902 

59 EVENT_LAUNCH_DEPENDENT_TASKS = 903 

60 EVENT_END_OF_TASK_GRAPH = 910 

61 EVENT_TERMINATION = 911 

62 EVENT_INVALID = 999 

63 

64 

65class DynamicType(IntEnum): 

66 DYNAMIC_EMPTY = 0 

67 DYNAMIC_DSV3_MOE_FFN = 101 

68 

69 

70# ── ctypes Structures ───────────────────────────────────────────────────────── 

71 

72class TensorDescC(ctypes.Structure): 

73 _fields_ = [ 

74 ("tensor_type", ctypes.c_uint32), 

75 ("num_dims", ctypes.c_uint32), 

76 ("dim", ctypes.c_uint32 * MAX_TENSOR_DIMS), 

77 ("stride", ctypes.c_uint32 * MAX_TENSOR_DIMS), 

78 ("data_type", ctypes.c_uint32), 

79 ("input_position", ctypes.c_uint32), 

80 ("base_ptr_offset", ctypes.c_uint32), 

81 ("transpose_flag", ctypes.c_uint32), 

82 ("dynamic_shape", ctypes.c_uint32), 

83 ("dynamic_dim", ctypes.c_uint32), 

84 ] 

85 

86 

87class TaskDescC(ctypes.Structure): 

88 _fields_ = [ 

89 ("task_type", ctypes.c_uint32), 

90 ("task_aicore_type", ctypes.c_uint32), 

91 ("num_inputs", ctypes.c_uint32), 

92 ("num_outputs", ctypes.c_uint32), 

93 ("trigger_event", ctypes.c_uint32), 

94 ("dependent_event", ctypes.c_uint32), 

95 ("inputs", TensorDescC * MAX_INPUTS_PER_TASK), 

96 ("outputs", TensorDescC * MAX_OUTPUTS_PER_TASK), 

97 ("tiling_data_position", ctypes.c_uint32), 

98 ("tiling_data_offset", ctypes.c_uint32), 

99 ("task_index", ctypes.c_uint32), 

100 ("task_split_num", ctypes.c_uint32), 

101 ("task_split_value", ctypes.c_uint32), 

102 ("extra_value_0", ctypes.c_uint32), 

103 ("extra_value_1", ctypes.c_uint32), 

104 ("extra_value_2", ctypes.c_uint32), 

105 ("extra_value_3", ctypes.c_uint32), 

106 ("extra_value_4", ctypes.c_uint32), 

107 ] 

108 

109 

110class EventDescC(ctypes.Structure): 

111 _fields_ = [ 

112 ("event_type", ctypes.c_uint32), 

113 ("num_triggers", ctypes.c_uint32), 

114 ("first_task_id", ctypes.c_uint32), 

115 ("last_task_id", ctypes.c_uint32), 

116 ] 

117 

118 

119class DynamicDataC(ctypes.Structure): 

120 _fields_ = [ 

121 ("dynamic_type", ctypes.c_uint32), 

122 ("dynamic_input_position", ctypes.c_uint32), 

123 ("dynamic_group_size", ctypes.c_uint32), 

124 ("dynamic_max_seq_len", ctypes.c_int32), 

125 ] 

126 

127 

128class RuntimeConfigC(ctypes.Structure): 

129 _fields_ = [ 

130 ("task_num", ctypes.c_uint32), 

131 ("num_workers", ctypes.c_uint32), 

132 ("queue_capacity", ctypes.c_uint32), 

133 ("config_extra_value", ctypes.c_uint32), 

134 ("all_event_num_triggers", ctypes.c_int32 * MAX_EVENT_NUM), 

135 ("all_tasks", TaskDescC * MAX_TASK_NUM), 

136 ("all_events", EventDescC * MAX_EVENT_NUM), 

137 ("task_index_num", ctypes.c_int32 * 4), 

138 ("cube_task_indices", ctypes.c_int32 * TASK_TYPE_INDEX_NUM), 

139 ("vector_task_indices", ctypes.c_int32 * TASK_TYPE_INDEX_NUM), 

140 ("mix_task_indices", ctypes.c_int32 * TASK_TYPE_INDEX_NUM), 

141 ("dynamic_data", DynamicDataC), 

142 ("grouped_matmul_group_list", ctypes.c_int64 * MAX_GROUP_LIST), 

143 ("atomic_add_values", ctypes.c_int32 * ATOMIC_ADD_VALUE_LEN), 

144 ] 

145 

146 

147# TilingData (used by add_custom, not GMM) 

148class TilingDataC(ctypes.Structure): 

149 _fields_ = [ 

150 ("smallCoreDataNum", ctypes.c_uint64), 

151 ("bigCoreDataNum", ctypes.c_uint64), 

152 ("ubPartDataNum", ctypes.c_uint64), 

153 ("smallCoreTailDataNum", ctypes.c_uint64), 

154 ("bigCoreTailDataNum", ctypes.c_uint64), 

155 ("smallCoreLoopNum", ctypes.c_uint64), 

156 ("bigCoreLoopNum", ctypes.c_uint64), 

157 ("tailBlockNum", ctypes.c_uint64), 

158 ] 

159 

160 

161class SwiGluTilingDataC(ctypes.Structure): 

162 _fields_ = [ 

163 ("is32BAligned", ctypes.c_uint32), 

164 ("isDoubleBuffer", ctypes.c_uint32), 

165 ("rowLen", ctypes.c_uint64), 

166 ("colLen", ctypes.c_uint64), 

167 ("baseRowLen", ctypes.c_uint32), 

168 ("baseColLen", ctypes.c_uint32), 

169 ("activateLeft", ctypes.c_uint32), 

170 ("biasIsEmpty", ctypes.c_uint32), 

171 ("quantScaleIsEmpty", ctypes.c_uint32), 

172 ("activateScaleIsEmpty", ctypes.c_uint32), 

173 ("swiColLen", ctypes.c_uint64), 

174 ("perRowLen", ctypes.c_uint64), 

175 ("modRowLen", ctypes.c_uint64), 

176 ("usedCoreNum", ctypes.c_uint32), 

177 ]