11// SPDX-License-Identifier: MIT
2- // Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.
2+ // Copyright (C) 2024-2025 , Advanced Micro Devices, Inc. All rights reserved.
33
44#ifndef _AIEBU_COMMON_ASSEMBLER_STATE_H_
55#define _AIEBU_COMMON_ASSEMBLER_STATE_H_
@@ -103,9 +103,11 @@ class label
103103 }
104104};
105105
106- class assembler_state
106+ class assembler_state : public std ::enable_shared_from_this<assembler_state>
107107{
108+ protected:
108109 offset_type m_pos = 0 ;
110+
109111 inline std::string gen_label_name (bool makeunique, const std::shared_ptr<asm_data> data)
110112 {
111113 return makeunique ? data->get_file () + " :" + data->get_operation ()->get_name () : data->get_operation ()->get_name ();
@@ -126,22 +128,22 @@ class assembler_state
126128 uint32_t base_actor_offset; // base channel
127129 };
128130
129- const std::unordered_map<std::string, ActionId> actor_id = {
130- {" mm2s" , {5 , 6 }},
131- {" s2mm" , {5 , 0 }},
132- {" tile_mm2s" , {10 , 6 }},
133- {" tile_s2mm" , {10 , 0 }},
134- {" shim_mm2s" , {10 , 6 }},
135- {" shim_s2mm" , {10 , 0 }},
136- {" mem_mm2s" , {9 , 6 }},
137- {" mem_s2mm" , {9 , 0 }}
138- };
131+ // std::unordered_map<std::string, ActionId> actor_id;
139132
140- uint32_t get_actor (const std::string& prefix, const std::string& s) const
133+ virtual std::unordered_map<std::string, uint32_t >& get_actor_id_map () const = 0;
134+ uint32_t get_actor (const std::string& s) const
141135 {
142- uint32_t actor = std::stoi (s. substr (actor_id. at (prefix). actor_start ) );
143- return actor_id.at (prefix). base_actor_offset + actor ;
136+ std::unordered_map<std::string, uint32_t >& actor_id = get_actor_id_map ( );
137+ return actor_id.at (s) ;
144138 }
139+
140+ assembler_state (std::shared_ptr<std::map<std::string, std::shared_ptr<isa_op>>> isa,
141+ std::vector<std::shared_ptr<asm_data>>& data,
142+ std::map<std::string, std::shared_ptr<scratchpad_info>>& scratchpad,
143+ std::map<std::string, uint32_t >& labelpageindex, uint32_t control_packet_index, bool makeunique);
144+ assembler_state (const assembler_state& rhs) = default ;
145+ assembler_state& operator =(const assembler_state& rhs) = default ;
146+ assembler_state (assembler_state &&s) = default ;
145147public:
146148 std::shared_ptr<std::map<std::string, std::shared_ptr<isa_op>>> m_isa;
147149 std::vector<std::shared_ptr<asm_data>>& m_data;
@@ -156,11 +158,6 @@ class assembler_state
156158 uint32_t m_control_packet_index;
157159 std::string m_controlpacket_padname;
158160
159- assembler_state (std::shared_ptr<std::map<std::string, std::shared_ptr<isa_op>>> isa,
160- std::vector<std::shared_ptr<asm_data>>& data,
161- std::map<std::string, std::shared_ptr<scratchpad_info>>& scratchpad,
162- std::map<std::string, uint32_t >& labelpageindex, uint32_t control_packet_index, bool makeunique);
163-
164161 HEADER_ACCESS_GET_SET (offset_type, pos);
165162
166163 void printstate () const ;
@@ -200,7 +197,130 @@ class assembler_state
200197 [](const std::map<std::string, std::shared_ptr<label>>::value_type &pair){return pair.first ;});
201198 return keys;
202199 }
200+
201+ virtual symbol::patch_schema get_shim_dma_patching () const = 0;
202+ virtual symbol::patch_schema get_control_packet_patching () const = 0;
203+ virtual ~assembler_state () = default ;
204+ };
205+
206+
207+ class assembler_state_aie2ps : public assembler_state
208+ {
209+ std::unordered_map<std::string, uint32_t >&
210+ get_actor_id_map () const override
211+ {
212+ static std::unordered_map<std::string, uint32_t > actor_id = {
213+ // {"s2mm_0", 0}, //NOLINT
214+ // {"s2mm_1", 1}, //NOLINT
215+
216+ // {"mm2s_0", 6}, //NOLINT
217+ // {"mm2s_1", 7}, //NOLINT
218+
219+ {" shim_s2mm_0" , 0 }, // NOLINT
220+ {" shim_s2mm_1" , 1 }, // NOLINT
221+
222+ {" shim_mm2s_0" , 6 }, // NOLINT
223+ {" shim_mm2s_1" , 7 }, // NOLINT
224+
225+ {" mem_s2mm_0" , 0 }, // NOLINT
226+ {" mem_s2mm_1" , 1 }, // NOLINT
227+ {" mem_s2mm_2" , 2 }, // NOLINT
228+ {" mem_s2mm_3" , 3 }, // NOLINT
229+ {" mem_s2mm_4" , 4 }, // NOLINT
230+ {" mem_s2mm_5" , 5 }, // NOLINT
231+
232+ {" mem_mm2s_0" , 6 }, // NOLINT
233+ {" mem_mm2s_1" , 7 }, // NOLINT
234+ {" mem_mm2s_2" , 8 }, // NOLINT
235+ {" mem_mm2s_3" , 9 }, // NOLINT
236+ {" mem_mm2s_4" , 10 }, // NOLINT
237+ {" mem_mm2s_5" , 11 }, // NOLINT
238+
239+ {" tile_s2mm_0" , 0 }, // NOLINT
240+ {" tile_s2mm_1" , 1 }, // NOLINT
241+ {" tile_mm2s_0" , 6 }, // NOLINT
242+ {" tile_mm2s_1" , 7 }, // NOLINT
243+ {" tile_core" , 15 }, // NOLINT
244+ };
245+ return actor_id;
246+ }
247+
248+ public:
249+ assembler_state_aie2ps (std::shared_ptr<std::map<std::string, std::shared_ptr<isa_op>>> isa,
250+ std::vector<std::shared_ptr<asm_data>>& data,
251+ std::map<std::string, std::shared_ptr<scratchpad_info>>& scratchpad,
252+ std::map<std::string, uint32_t >& labelpageindex, uint32_t control_packet_index, bool makeunique)
253+ : assembler_state(isa, data, scratchpad, labelpageindex, control_packet_index, makeunique)
254+ {
255+ // shim_dma_patching = symbol::patch_schema::shim_dma_57;
256+ // control_packet_patching = symbol::patch_schema::control_packet_57;
257+ }
258+
259+ symbol::patch_schema get_shim_dma_patching () const override { return symbol::patch_schema::shim_dma_57; }
260+ symbol::patch_schema get_control_packet_patching () const override { return symbol::patch_schema::control_packet_57; }
203261};
204262
263+ class assembler_state_aie4 : public assembler_state
264+ {
265+ std::unordered_map<std::string, uint32_t >&
266+ get_actor_id_map () const override
267+ {
268+ static std::unordered_map<std::string, uint32_t > actor_id = {
269+ {" shim_s2mm_0" , 0 }, // NOLINT
270+ {" shim_trace_s2mm" , 1 }, // NOLINT
271+ {" shim_s2mm_1" , 2 }, // NOLINT
272+
273+ {" shim_mm2s_0" , 6 }, // NOLINT
274+ {" shim_mm2s_1" , 7 }, // NOLINT
275+ {" shim_mm2s_2" , 8 }, // NOLINT
276+ {" shim_mm2s_3" , 9 }, // NOLINT
277+
278+ {" shim_ctrl_mm2s_0" , 16 }, // NOLINT
279+ {" shim_ctrl_mm2s_1" , 17 }, // NOLINT
280+
281+ {" mem_s2mm_0" , 0 }, // NOLINT
282+ {" mem_s2mm_1" , 1 }, // NOLINT
283+ {" mem_s2mm_2" , 2 }, // NOLINT
284+ {" mem_s2mm_3" , 3 }, // NOLINT
285+ {" mem_s2mm_4" , 4 }, // NOLINT
286+ {" mem_s2mm_5" , 5 }, // NOLINT
287+ {" mem_s2mm_6" , 6 }, // NOLINT
288+ {" mem_s2mm_7" , 7 }, // NOLINT
289+
290+ {" mem_mm2s_0" , 16 }, // NOLINT
291+ {" mem_mm2s_1" , 17 }, // NOLINT
292+ {" mem_mm2s_2" , 18 }, // NOLINT
293+ {" mem_mm2s_3" , 19 }, // NOLINT
294+ {" mem_mm2s_4" , 20 }, // NOLINT
295+ {" mem_mm2s_5" , 22 }, // NOLINT
296+ {" mem_mm2s_6" , 23 }, // NOLINT
297+ {" mem_mm2s_7" , 24 }, // NOLINT
298+ {" mem_mm2s_8" , 25 }, // NOLINT
299+ {" mem_mm2s_9" , 26 }, // NOLINT
300+
301+ {" tile_s2mm_0" , 0 }, // NOLINT
302+ {" tile_s2mm_1" , 1 }, // NOLINT
303+
304+ {" tile_mm2s_0" , 6 }, // NOLINT
305+
306+ {" tile_core" , 15 }, // NOLINT
307+ };
308+ return actor_id;
309+ }
310+
311+ public:
312+ assembler_state_aie4 (std::shared_ptr<std::map<std::string, std::shared_ptr<isa_op>>> isa,
313+ std::vector<std::shared_ptr<asm_data>>& data,
314+ std::map<std::string, std::shared_ptr<scratchpad_info>>& scratchpad,
315+ std::map<std::string, uint32_t >& labelpageindex, uint32_t control_packet_index, bool makeunique)
316+ : assembler_state(isa, data, scratchpad, labelpageindex, control_packet_index, makeunique)
317+ {
318+ // shim_dma_patching = symbol::patch_schema::shim_dma_57_aie4;
319+ // control_packet_patching = symbol::patch_schema::control_packet_57_aie4;
320+ }
321+
322+ symbol::patch_schema get_shim_dma_patching () const override { return symbol::patch_schema::shim_dma_57_aie4; }
323+ symbol::patch_schema get_control_packet_patching () const override { return symbol::patch_schema::control_packet_57_aie4; }
324+ };
205325}
206326#endif // _AIEBU_COMMON_ASSEMBLER_STATE_H_
0 commit comments