Skip to content

Commit ad258eb

Browse files
aie4 changes (#86)
* aie4 changes Signed-off-by: HimanshuChoudhary-Xilinx <Himanshu.Choudhary@amd.com> * fix actor id's Signed-off-by: HimanshuChoudhary-Xilinx <Himanshu.Choudhary@amd.com> --------- Signed-off-by: HimanshuChoudhary-Xilinx <Himanshu.Choudhary@amd.com>
1 parent 435c13c commit ad258eb

22 files changed

Lines changed: 473 additions & 93 deletions

src/cpp/assembler/aiebu_assembler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ aiebu_assembler(buffer_type type,
6161
aiebu::assembler a(assembler::elf_type::config);
6262
elf_data = a.process(buffer1, libs, libpaths, patch_json, buffer2);
6363
}
64+
else if (type == buffer_type::asm_aie4)
65+
{
66+
aiebu::assembler a(assembler::elf_type::aie4_asm);
67+
elf_data = a.process(buffer1, libs, libpaths, patch_json);
68+
}
6469
else {
6570
throw error(error::error_code::invalid_buffer_type, "Buffer_type not supported !!!");
6671
}

src/cpp/assembler/assembler.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "aie2ps_elfwriter.h"
1010
#include "aie2ps_encoder.h"
1111
#include "aie2ps_preprocessor.h"
12+
#include "encoder/aie4/aie4_encoder.h"
13+
#include "preprocessor/aie4/aie4_preprocessor.h"
14+
#include "preprocessor/aie4/aie4_preprocessor_input.h"
15+
#include "elf/aie4/aie4_elfwriter.h"
1216
#include "elfwriter.h"
1317
#include "encoder.h"
1418
#include "preprocessor.h"
@@ -56,6 +60,13 @@ assembler(const elf_type type)
5660
m_elfwriter = std::make_unique<config_elf_writer>();
5761
m_ppi = std::make_shared<config_preprocessor_input>();
5862
}
63+
else if (type == elf_type::aie4_asm)
64+
{
65+
m_preprocessor = std::make_unique<aie4_preprocessor>();
66+
m_enoder = std::make_unique<aie4_encoder>();
67+
m_elfwriter = std::make_unique<aie4_elf_writer>();
68+
m_ppi = std::make_shared<aie4_preprocessor_input>();
69+
}
5970
else {
6071
throw error(error::error_code::invalid_buffer_type ,"Invalid elf type!!!");
6172
}

src/cpp/assembler/assembler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class assembler
3030
aie2_dpu_blob,
3131
aie2ps_asm,
3232
aie2_asm,
33-
config
33+
config,
34+
aie4_asm
3435
};
3536

3637
explicit assembler(const elf_type type);

src/cpp/common/assembler_state.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ process(bool makeunique)
140140
* 4. If string is numeric string: it will convert to decimal
141141
*/
142142
uint32_t assembler_state::parse_num_arg(const std::string& str) {
143-
static const std::unordered_map<std::string, std::function<uint32_t(const std::string&)>> handlers = {
143+
const std::unordered_map<std::string, std::function<uint32_t(const std::string&)>> handlers = {
144144
{"@", [this](const std::string& s) -> uint32_t {
145145
//If string start with '@': it can be either pad name or label name
146146
auto key = s.substr(1);
@@ -150,14 +150,15 @@ uint32_t assembler_state::parse_num_arg(const std::string& str) {
150150
return it->second->get_pos();
151151
throw error(error::error_code::invalid_asm, "Label " + key + " not present in label map\n");
152152
}},
153-
{"s2mm_", [this](const std::string& s) -> uint32_t { return get_actor("s2mm", s); }},
154-
{"mm2s_", [this](const std::string& s) -> uint32_t { return get_actor("mm2s", s); }},
155-
{"mem_s2mm_", [this](const std::string& s) -> uint32_t { return get_actor("mem_s2mm", s); }},
156-
{"mem_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor("mem_mm2s", s); }},
157-
{"shim_s2mm_", [this](const std::string& s) -> uint32_t { return get_actor("shim_s2mm", s); }},
158-
{"shim_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor("shim_mm2s", s); }},
159-
{"tile_s2mm_", [this](const std::string& s) -> uint32_t { return get_actor("tile_s2mm", s); }},
160-
{"tile_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor("tile_mm2s", s); }}
153+
{"s2mm_", [this](const std::string& s) -> uint32_t { return get_actor(s); }},
154+
{"mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }},
155+
{"mem_s2mm_", [this](const std::string& s) -> uint32_t { return get_actor(s); }},
156+
{"mem_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }},
157+
{"shim_s2mm_", [this](const std::string& s) -> uint32_t { return get_actor(s); }},
158+
{"shim_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }},
159+
{"tile_s2mm_", [this](const std::string& s) -> uint32_t { return get_actor(s); }},
160+
{"tile_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }},
161+
{"shim_ctrl_mm2s_", [this](const std::string& s) -> uint32_t { return get_actor(s); }}
161162
};
162163

163164
// check if its pad/label/actor

src/cpp/common/assembler_state.h

Lines changed: 140 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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;
145147
public:
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_

src/cpp/common/symbol.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class symbol
2323
shim_dma_57_aie4 = 6,
2424
control_packet_57 = 7,
2525
address_64 = 8,
26-
unknown = 9,
26+
control_packet_57_aie4 = 9,
27+
unknown = 10,
2728
};
2829

2930
private:

src/cpp/elf/aie4/aie4_elfwriter.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (C) 2025, Advanced Micro Devices, Inc. All rights reserved.
3+
4+
#ifndef AIEBU_ELF_AIE4_ELF_WRITER_H_
5+
#define AIEBU_ELF_AIE4_ELF_WRITER_H_
6+
7+
#include <aie2ps_elfwriter.h>
8+
9+
namespace aiebu {
10+
11+
class aie4_elf_writer: public aie2ps_elf_writer
12+
{
13+
public:
14+
aie4_elf_writer(): aie2ps_elf_writer()
15+
{ }
16+
};
17+
18+
}
19+
#endif //AIEBU_ELF_AIE4_ELF_WRITER_H_

src/cpp/encoder/aie2ps/aie2ps_encoder.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ page_writer(page& lpage, std::map<std::string, std::shared_ptr<scratchpad_info>>
128128
std::vector<std::shared_ptr<asm_data>> all;
129129
all.insert(all.end(), lpage.m_text.begin(), lpage.m_text.end());
130130
all.insert(all.end(), lpage.m_data.begin(), lpage.m_data.end());
131-
assembler_state page_state = assembler_state(m_isa, all, scratchpad, labelpageindex, control_packet_index, false);
131+
std::shared_ptr<assembler_state> page_state = create_assembler_state(m_isa, all, scratchpad, labelpageindex, control_packet_index, false);
132132

133133
writer textwriter(get_TextSectionName(colnum, pagenum), code_section::text);
134134
writer datawriter(get_DataSectionName(colnum, pagenum), code_section::data);
@@ -145,7 +145,7 @@ page_writer(page& lpage, std::map<std::string, std::shared_ptr<scratchpad_info>>
145145
std::string name = text->get_operation()->get_name();
146146
if (text->isOpcode())
147147
{
148-
page_state.set_pos(textwriter.tell() - offset);
148+
page_state->set_pos(textwriter.tell() - offset);
149149
std::vector<uint8_t> ret = (*m_isa)[name]->serializer(text->get_operation()->get_args())
150150
->serialize(page_state, tsym, colnum, pagenum);
151151
for (uint8_t byte : ret) {
@@ -159,7 +159,7 @@ page_writer(page& lpage, std::map<std::string, std::shared_ptr<scratchpad_info>>
159159
// encode data section
160160
for (auto data : lpage.m_data)
161161
{
162-
page_state.set_pos(datawriter.tell() + textwriter.tell() - offset);
162+
page_state->set_pos(datawriter.tell() + textwriter.tell() - offset);
163163
std::string name = data->get_operation()->get_name();
164164
if (!name.compare("eof"))
165165
continue;
@@ -178,13 +178,13 @@ page_writer(page& lpage, std::map<std::string, std::shared_ptr<scratchpad_info>>
178178
throw error(error::error_code::internal_error, "Invalid operation: " + name + " in DATA section !!!");
179179
}
180180

181-
for (auto &spad : page_state.m_patch)
181+
for (auto &spad : page_state->m_patch)
182182
{
183183
for (auto& arg : spad.second)
184184
{
185-
offset = page_state.parse_num_arg(arg);
185+
offset = page_state->parse_num_arg(arg);
186186
patch57(textwriter, datawriter, offset + page_header.size(),
187-
page_state.m_scratchpad[spad.first.substr(1)]->get_base() + page_state.m_scratchpad[spad.first.substr(1)]->get_offset());
187+
page_state->m_scratchpad[spad.first.substr(1)]->get_base() + page_state->m_scratchpad[spad.first.substr(1)]->get_offset());
188188
}
189189
}
190190

@@ -195,7 +195,7 @@ page_writer(page& lpage, std::map<std::string, std::shared_ptr<scratchpad_info>>
195195
twriter.push_back(textwriter);
196196
twriter.push_back(datawriter);
197197

198-
return page_state.m_controlpacket_padname;
198+
return page_state->m_controlpacket_padname;
199199
// TODO add size and generate report
200200
}
201201

src/cpp/encoder/aie2ps/aie2ps_encoder.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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_ENCODER_AIE2PS_ENCODER_H_
55
#define _AIEBU_ENCODER_AIE2PS_ENCODER_H_
@@ -30,10 +30,20 @@ class aie2ps_encoder : public encoder
3030
std::string get_DataSectionName(uint32_t colnum, pageid_type pagenum) {return ".ctrldata." + std::to_string(colnum) + "." + std::to_string(pagenum); }
3131
std::string get_PadSectionName(uint32_t colnum) {return ".pad." + std::to_string(colnum); }
3232
std::string page_writer(page& lpage, std::map<std::string, std::shared_ptr<scratchpad_info>>& scratchpad, std::map<std::string, uint32_t>& labelpageindex, uint32_t control_packet_index);
33-
void patch57(const writer& textwriter, writer& datawriter, offset_type offset, uint64_t patch);
33+
virtual void patch57(const writer& textwriter, writer& datawriter, offset_type offset, uint64_t patch);
3434
void fill_scratchpad(writer& padwriter,const std::map<std::string, std::shared_ptr<scratchpad_info>>& scratchpads);
3535
void fill_control_packet_symbols(writer& padwriter,const uint32_t col, const std::string& controlpacket_padname, std::vector<symbol>& syms, const std::map<std::string, std::shared_ptr<scratchpad_info>>& scratchpads);
3636
std::string findKey(const std::map<std::string, std::vector<std::string>>& myMap, const std::string& value);
37+
38+
virtual std::shared_ptr<assembler_state>
39+
create_assembler_state(std::shared_ptr<std::map<std::string, std::shared_ptr<isa_op>>> isa,
40+
std::vector<std::shared_ptr<asm_data>>& data,
41+
std::map<std::string, std::shared_ptr<scratchpad_info>>& scratchpad,
42+
std::map<std::string, uint32_t>& labelpageindex,
43+
uint32_t control_packet_index, bool makeunique)
44+
{
45+
return std::make_shared<assembler_state_aie2ps>(isa, data, scratchpad, labelpageindex, control_packet_index, makeunique);
46+
}
3747
};
3848

3949
}

0 commit comments

Comments
 (0)