Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions specification/aie4/preemption_asm/generate_aie4_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,46 @@ def generate_header(asm_dir, output_file):
#include <map>
#include <vector>
#include <cstdint>
#include <string>

// C++17 inline variable - single instance across all translation units
inline std::map<uint32_t, std::pair<std::vector<uint8_t>, std::vector<uint8_t>>> aie4_save_restore_map = {
inline const std::map<uint32_t, std::pair<std::vector<std::string>, std::vector<std::string>>> aie4_save_restore_shimbd_map = {
{1, {{"DMAWRITE_data_125", "DMAWRITE_data_126"},
{"DMAWRITE_data_0", "DMAWRITE_data_1", "DMAWRITE_data_2", "DMAWRITE_data_3"}}},
{2, {{"DMAWRITE_data_250", "DMAWRITE_data_251", "DMAWRITE_data_252", "DMAWRITE_data_253"},
{"DMAWRITE_data_0", "DMAWRITE_data_1", "DMAWRITE_data_2", "DMAWRITE_data_3", "DMAWRITE_data_4", "DMAWRITE_data_5", "DMAWRITE_data_6", "DMAWRITE_data_7"}}},
{3, {{"DMAWRITE_data_375", "DMAWRITE_data_376", "DMAWRITE_data_377", "DMAWRITE_data_378", "DMAWRITE_data_379", "DMAWRITE_data_380"},
{"DMAWRITE_data_0", "DMAWRITE_data_1", "DMAWRITE_data_2", "DMAWRITE_data_3", "DMAWRITE_data_4", "DMAWRITE_data_5", "DMAWRITE_data_6", "DMAWRITE_data_7", "DMAWRITE_data_8", "DMAWRITE_data_9", "DMAWRITE_data_10", "DMAWRITE_data_11"}}},
{10, {{"DMAWRITE_data_125", "DMAWRITE_data_126"}, {"DMAWRITE_data_0", "DMAWRITE_data_1", "DMAWRITE_data_2", "DMAWRITE_data_3"}}},
{12, {{"DMAWRITE_data_125", "DMAWRITE_data_126"}, {"DMAWRITE_data_0", "DMAWRITE_data_1", "DMAWRITE_data_2", "DMAWRITE_data_3"}}},
{14, {{"DMAWRITE_data_125", "DMAWRITE_data_126"}, {"DMAWRITE_data_0", "DMAWRITE_data_1", "DMAWRITE_data_2", "DMAWRITE_data_3"}}}
};

inline const std::map<uint32_t, std::pair<std::vector<std::string>, std::vector<std::string>>>&
get_aie4_save_restore_shimbd()
{
return aie4_save_restore_shimbd_map;
}

inline const std::map<uint32_t, std::pair<std::vector<std::string>, std::vector<std::string>>> aie4_save_restore_membd_map = {
{1, {{"DMAWRITE_data_127", "DMAWRITE_data_128"},
{"DMAWRITE_data_4", "DMAWRITE_data_5", "DMAWRITE_data_6", "DMAWRITE_data_7"}}},
{2, {{"DMAWRITE_data_254", "DMAWRITE_data_255", "DMAWRITE_data_256", "DMAWRITE_data_257"},
{"DMAWRITE_data_8", "DMAWRITE_data_9", "DMAWRITE_data_10", "DMAWRITE_data_11", "DMAWRITE_data_12", "DMAWRITE_data_13", "DMAWRITE_data_14", "DMAWRITE_data_15"}}},
{3, {{"DMAWRITE_data_381", "DMAWRITE_data_382", "DMAWRITE_data_383", "DMAWRITE_data_384", "DMAWRITE_data_385", "DMAWRITE_data_386"},
{"DMAWRITE_data_12", "DMAWRITE_data_13", "DMAWRITE_data_14", "DMAWRITE_data_15", "DMAWRITE_data_16", "DMAWRITE_data_17", "DMAWRITE_data_18", "DMAWRITE_data_19", "DMAWRITE_data_20", "DMAWRITE_data_21", "DMAWRITE_data_22", "DMAWRITE_data_23"}}},
{10, {{"DMAWRITE_data_127", "DMAWRITE_data_128"}, {"DMAWRITE_data_4", "DMAWRITE_data_5", "DMAWRITE_data_6", "DMAWRITE_data_7"}}},
{12, {{"DMAWRITE_data_127", "DMAWRITE_data_128"}, {"DMAWRITE_data_4", "DMAWRITE_data_5", "DMAWRITE_data_6", "DMAWRITE_data_7"}}},
{14, {{"DMAWRITE_data_127", "DMAWRITE_data_128"}, {"DMAWRITE_data_4", "DMAWRITE_data_5", "DMAWRITE_data_6", "DMAWRITE_data_7"}}}
};

inline const std::map<uint32_t, std::pair<std::vector<std::string>, std::vector<std::string>>>&
get_aie4_save_restore_membd()
{
return aie4_save_restore_membd_map;
}

inline const std::map<uint32_t, std::pair<std::vector<uint8_t>, std::vector<uint8_t>>> aie4_save_restore_map = {
"""

# Add entries
Expand All @@ -123,7 +160,7 @@ def generate_header(asm_dir, output_file):
header += """
};

inline std::map<uint32_t, std::pair<std::vector<uint8_t>, std::vector<uint8_t>>>&
inline const std::map<uint32_t, std::pair<std::vector<uint8_t>, std::vector<uint8_t>>>&
get_aie4_save_restore()
{
return aie4_save_restore_map;
Expand Down
13 changes: 7 additions & 6 deletions src/cpp/preprocessor/aie4/aie4_save_restore_map_prebuilt.h

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions src/cpp/preprocessor/asm/asm_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,50 @@ asm_parser::inject_hintmap_save_restore(int col,
for (const auto& hm : grp.hintmaps)
m_hintmap_labels[col_prefix + hm] = grp.labels;

// When hint_bitmap is all-zero the scratchpad size is 0: no state needs to
// be saved or restored. Inject minimal dummy jobs so the PREEMPT opcode
// still has valid save/restore label targets, but skip all BD configuration
// and stream-switch routing that the full templates would generate.
if (grp.size == 0) {
const std::string& slabel = grp.labels.first;
const std::string& rlabel = grp.labels.second;
log_info() << "hint_bitmap is 0 for col " << col
<< ": injecting dummy save/restore jobs (labels @"
<< slabel << " / @" << rlabel << ")" << std::endl;

const std::string save_asm =
slabel + ":\n"
"START_JOB 0\n"
"NOP\n"
"END_JOB\n"
"EOF\n"
"\n.endl " + slabel + "\n";

const std::string restore_asm =
rlabel + ":\n"
"START_JOB 0\n"
"LOAD_LAST_PDI\n"
"END_JOB\n"
"EOF\n"
"\n.endl " + rlabel + "\n";

m_current_col = col;
std::string dummy_save_file = "0_0_" + save_file;
std::string dummy_restore_file = "0_0_" + restore_file;
log_info() << "Adding dummy save_file: " << dummy_save_file << " [size: " << save_asm.size()
<< "], restore_file: " << dummy_restore_file << " [size: " << restore_asm.size() << "]" << std::endl;
set_data_state(false);
parse_lines(std::vector<char>(save_asm.begin(), save_asm.end()),
dummy_save_file);
pop_data_state();

set_data_state(false);
parse_lines(std::vector<char>(restore_asm.begin(), restore_asm.end()),
dummy_restore_file);
pop_data_state();
return;
}

// Modify save_file like {scratchaddress}_{size}_aie4_save_3c.asm / {scratchaddress}_{size}_aie4_restore_3c.asm
std::string save_file_mod = std::to_string(grp.scratchbase / CHUNK_SIZE) + "_" + std::to_string(grp.size / CHUNK_SIZE) + "_" + save_file;
std::string restore_file_mod = std::to_string(grp.scratchbase / CHUNK_SIZE) + "_" + std::to_string(grp.size / CHUNK_SIZE) + "_" + restore_file;
Expand Down
18 changes: 18 additions & 0 deletions test/aie4-ctrlcode/1col_preempt_0hint/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2026 Advanced Micro Devices, Inc.

# Assemble control code ASM with zero-hint_bitmap (hintmap_0 = 0x0) alongside a
# non-zero hintmap (hintmap_1 = 0xf). The zero-hintmap PREEMPT points must
# produce minimal dummy save/restore jobs (NOP / LOAD_LAST_PDI) with no BD
# configuration or stream-switch routing.
add_test(NAME "aie4_1col_preempt_0hint_asm"
COMMAND aiebu-asm -t aie4_config -j "${CMAKE_CURRENT_SOURCE_DIR}/config.json" -o 1col-preempt-0hint.elf -f disabledump
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# Compare the md5sum of the generated ELF against the golden file
add_test(NAME "aie4_1col_preempt_0hint_asm_md5sum"
COMMAND cmake -P "${AIEBU_SOURCE_DIR}/cmake/md5sum-compare.cmake" "${CMAKE_CURRENT_BINARY_DIR}/1col-preempt-0hint.elf" "${CMAKE_CURRENT_SOURCE_DIR}/gold.md5"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set_tests_properties("aie4_1col_preempt_0hint_asm_md5sum" PROPERTIES DEPENDS "aie4_1col_preempt_0hint_asm")
set_tests_properties("aie4_1col_preempt_0hint_asm" PROPERTIES LABELS memcheck)
15 changes: 15 additions & 0 deletions test/aie4-ctrlcode/1col_preempt_0hint/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"xrt-kernels": [
{
"name": "DPU",
"arguments": [
],
"instance": [
{
"id": "dpu",
"ctrl_code_file": "./test.asm"
}
]
}
]
}
1 change: 1 addition & 0 deletions test/aie4-ctrlcode/1col_preempt_0hint/gold.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
691dbc2343144d54c5ad1a8876b4d196
6 changes: 6 additions & 0 deletions test/aie4-ctrlcode/1col_preempt_0hint/pdi.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pdi:
START_JOB 0
NOP
END_JOB
EOF
.endl pdi
32 changes: 32 additions & 0 deletions test/aie4-ctrlcode/1col_preempt_0hint/test.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.target aie4
.partition 1column
.attach_to_group 0
START_JOB 0
LOAD_PDI 0, @pdi
END_JOB
START_JOB 1
PREEMPT 0, @save, @restore , @hintmap_0
END_JOB
START_JOB 2
NOP
END_JOB
START_JOB 3
PREEMPT 1, @save, @restore , @hintmap_1
END_JOB
START_JOB 4
NOP
END_JOB
START_JOB 5
PREEMPT 2, @save, @restore , @hintmap_0
END_JOB
START_JOB 6
NOP
END_JOB

.include pdi.asm
EOF
.align 4
hintmap_0:
.long 0x00000000
hintmap_1:
.long 0x0000000f
18 changes: 18 additions & 0 deletions test/aie4-ctrlcode/3col_preempt_0hint/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2026 Advanced Micro Devices, Inc.

# Assemble control code ASM with zero-hint_bitmap (hintmap_0 = 0x0) alongside a
# non-zero hintmap (hintmap_1 = 0xf) for a 3-column partition. The zero-hintmap
# PREEMPT points must produce minimal dummy save/restore jobs (NOP / LOAD_LAST_PDI)
# with no BD configuration or stream-switch routing.
add_test(NAME "aie4_3col_preempt_0hint_asm"
COMMAND aiebu-asm -t aie4_config -j "${CMAKE_CURRENT_SOURCE_DIR}/config.json" -o 3col-preempt-0hint.elf -f disabledump
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# Compare the md5sum of the generated ELF against the golden file
add_test(NAME "aie4_3col_preempt_0hint_asm_md5sum"
COMMAND cmake -P "${AIEBU_SOURCE_DIR}/cmake/md5sum-compare.cmake" "${CMAKE_CURRENT_BINARY_DIR}/3col-preempt-0hint.elf" "${CMAKE_CURRENT_SOURCE_DIR}/gold.md5"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set_tests_properties("aie4_3col_preempt_0hint_asm_md5sum" PROPERTIES DEPENDS "aie4_3col_preempt_0hint_asm")
set_tests_properties("aie4_3col_preempt_0hint_asm" PROPERTIES LABELS memcheck)
15 changes: 15 additions & 0 deletions test/aie4-ctrlcode/3col_preempt_0hint/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"xrt-kernels": [
{
"name": "DPU",
"arguments": [
],
"instance": [
{
"id": "dpu",
"ctrl_code_file": "./test.asm"
}
]
}
]
}
1 change: 1 addition & 0 deletions test/aie4-ctrlcode/3col_preempt_0hint/gold.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b27d37dceddc6f93b93ebd1bdcbc5f19
6 changes: 6 additions & 0 deletions test/aie4-ctrlcode/3col_preempt_0hint/pdi.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pdi:
START_JOB 0
NOP
END_JOB
EOF
.endl pdi
5 changes: 5 additions & 0 deletions test/aie4-ctrlcode/3col_preempt_0hint/test.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.include uc0.asm
.eop
.include uc2.asm
.eop
.include uc4.asm
35 changes: 35 additions & 0 deletions test/aie4-ctrlcode/3col_preempt_0hint/uc0.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.target aie4
.aie_row_topology 1-1-4-0
.partition 3column

.attach_to_group 0

START_JOB 0
LOAD_PDI 0, @pdi
END_JOB
START_JOB 1
PREEMPT 0, @save, @restore , @hintmap_0
END_JOB
START_JOB 2
NOP
END_JOB
START_JOB 3
PREEMPT 1, @save, @restore , @hintmap_1
END_JOB
START_JOB 4
NOP
END_JOB
START_JOB 5
PREEMPT 2, @save, @restore , @hintmap_0
END_JOB
START_JOB 6
NOP
END_JOB

.include pdi.asm
EOF
.align 4
hintmap_0:
.long 0x00000000
hintmap_1:
.long 0x0000000f
35 changes: 35 additions & 0 deletions test/aie4-ctrlcode/3col_preempt_0hint/uc2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.target aie4
.aie_row_topology 1-1-4-0
.partition 3column

.attach_to_group 2

START_JOB 0
LOAD_PDI 0, @pdi
END_JOB
START_JOB 1
PREEMPT 0, @save, @restore , @hintmap_0
END_JOB
START_JOB 2
NOP
END_JOB
START_JOB 3
PREEMPT 1, @save, @restore , @hintmap_0
END_JOB
START_JOB 4
NOP
END_JOB
START_JOB 5
PREEMPT 2, @save, @restore , @hintmap_1
END_JOB
START_JOB 6
NOP
END_JOB

.include pdi.asm
EOF
.align 4
hintmap_0:
.long 0x00000000
hintmap_1:
.long 0x0000000f
35 changes: 35 additions & 0 deletions test/aie4-ctrlcode/3col_preempt_0hint/uc4.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.target aie4
.aie_row_topology 1-1-4-0
.partition 3column

.attach_to_group 4

START_JOB 0
LOAD_PDI 0, @pdi
END_JOB
START_JOB 1
PREEMPT 0, @save, @restore , @hintmap_0
END_JOB
START_JOB 2
NOP
END_JOB
START_JOB 3
PREEMPT 1, @save, @restore , @hintmap_1
END_JOB
START_JOB 4
NOP
END_JOB
START_JOB 5
PREEMPT 2, @save, @restore , @hintmap_0
END_JOB
START_JOB 6
NOP
END_JOB

.include pdi.asm
EOF
.align 4
hintmap_0:
.long 0x00000000
hintmap_1:
.long 0x0000000f
2 changes: 2 additions & 0 deletions test/aie4-ctrlcode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ if (${Boost_VERSION} VERSION_GREATER_EQUAL "1.71.0")
add_subdirectory(basic)
add_subdirectory(move_ddr_to_memtile_ctrlpkt)
add_subdirectory(1col_preempt)
add_subdirectory(1col_preempt_0hint)
add_subdirectory(3col_preempt_0hint)
add_subdirectory(multi_layer)
add_subdirectory(compile_time/fused_hw_package_subgraph_0)
add_subdirectory(multi_graph)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a91699474561b1d112d7885add3dd3d8
75c70239ed04fc3d48399f0afffa0fe7
Loading