Skip to content

Commit c17fdd0

Browse files
AIESW-27905: special handling for hint_bitmap 0 preemption point
Signed-off-by: Himanshu Choudhary <Himanshu.Choudhary@amd.com>
1 parent e811334 commit c17fdd0

18 files changed

Lines changed: 277 additions & 9 deletions

File tree

specification/aie4/preemption_asm/generate_aie4_header.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def generate_header(asm_dir, output_file):
102102
#include <cstdint>
103103
104104
// C++17 inline variable - single instance across all translation units
105-
inline std::map<uint32_t, std::pair<std::vector<uint8_t>, std::vector<uint8_t>>> aie4_save_restore_map = {
105+
inline const std::map<uint32_t, std::pair<std::vector<uint8_t>, std::vector<uint8_t>>> aie4_save_restore_map = {
106106
"""
107107

108108
# Add entries
@@ -123,7 +123,7 @@ def generate_header(asm_dir, output_file):
123123
header += """
124124
};
125125
126-
inline std::map<uint32_t, std::pair<std::vector<uint8_t>, std::vector<uint8_t>>>&
126+
inline const std::map<uint32_t, std::pair<std::vector<uint8_t>, std::vector<uint8_t>>>&
127127
get_aie4_save_restore()
128128
{
129129
return aie4_save_restore_map;

src/cpp/preprocessor/aie4/aie4_save_restore_map_prebuilt.h

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

src/cpp/preprocessor/asm/asm_parser.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,50 @@ asm_parser::inject_hintmap_save_restore(int col,
10231023
for (const auto& hm : grp.hintmaps)
10241024
m_hintmap_labels[col_prefix + hm] = grp.labels;
10251025

1026+
// When hint_bitmap is all-zero the scratchpad size is 0: no state needs to
1027+
// be saved or restored. Inject minimal dummy jobs so the PREEMPT opcode
1028+
// still has valid save/restore label targets, but skip all BD configuration
1029+
// and stream-switch routing that the full templates would generate.
1030+
if (grp.size == 0) {
1031+
const std::string& slabel = grp.labels.first;
1032+
const std::string& rlabel = grp.labels.second;
1033+
log_info() << "hint_bitmap is 0 for col " << col
1034+
<< ": injecting dummy save/restore jobs (labels @"
1035+
<< slabel << " / @" << rlabel << ")" << std::endl;
1036+
1037+
const std::string save_asm =
1038+
slabel + ":\n"
1039+
"START_JOB 0\n"
1040+
"NOP\n"
1041+
"END_JOB\n"
1042+
"EOF\n"
1043+
"\n.endl " + slabel + "\n";
1044+
1045+
const std::string restore_asm =
1046+
rlabel + ":\n"
1047+
"START_JOB 0\n"
1048+
"LOAD_LAST_PDI\n"
1049+
"END_JOB\n"
1050+
"EOF\n"
1051+
"\n.endl " + rlabel + "\n";
1052+
1053+
m_current_col = col;
1054+
std::string dummy_save_file = "0_0_" + save_file;
1055+
std::string dummy_restore_file = "0_0_" + restore_file;
1056+
log_info() << "Adding dummy save_file: " << dummy_save_file << " [size: " << save_asm.size()
1057+
<< "], restore_file: " << dummy_restore_file << " [size: " << restore_asm.size() << "]" << std::endl;
1058+
set_data_state(false);
1059+
parse_lines(std::vector<char>(save_asm.begin(), save_asm.end()),
1060+
dummy_save_file);
1061+
pop_data_state();
1062+
1063+
set_data_state(false);
1064+
parse_lines(std::vector<char>(restore_asm.begin(), restore_asm.end()),
1065+
dummy_restore_file);
1066+
pop_data_state();
1067+
return;
1068+
}
1069+
10261070
// Modify save_file like {scratchaddress}_{size}_aie4_save_3c.asm / {scratchaddress}_{size}_aie4_restore_3c.asm
10271071
std::string save_file_mod = std::to_string(grp.scratchbase / CHUNK_SIZE) + "_" + std::to_string(grp.size / CHUNK_SIZE) + "_" + save_file;
10281072
std::string restore_file_mod = std::to_string(grp.scratchbase / CHUNK_SIZE) + "_" + std::to_string(grp.size / CHUNK_SIZE) + "_" + restore_file;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (C) 2026 Advanced Micro Devices, Inc.
3+
4+
# Assemble control code ASM with zero-hint_bitmap (hintmap_0 = 0x0) alongside a
5+
# non-zero hintmap (hintmap_1 = 0xf). The zero-hintmap PREEMPT points must
6+
# produce minimal dummy save/restore jobs (NOP / LOAD_LAST_PDI) with no BD
7+
# configuration or stream-switch routing.
8+
add_test(NAME "aie4_1col_preempt_0hint_asm"
9+
COMMAND aiebu-asm -t aie4_config -j "${CMAKE_CURRENT_SOURCE_DIR}/config.json" -o 1col-preempt-0hint.elf -f disabledump
10+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
11+
12+
# Compare the md5sum of the generated ELF against the golden file
13+
add_test(NAME "aie4_1col_preempt_0hint_asm_md5sum"
14+
COMMAND cmake -P "${AIEBU_SOURCE_DIR}/cmake/md5sum-compare.cmake" "${CMAKE_CURRENT_BINARY_DIR}/1col-preempt-0hint.elf" "${CMAKE_CURRENT_SOURCE_DIR}/gold.md5"
15+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
16+
17+
set_tests_properties("aie4_1col_preempt_0hint_asm_md5sum" PROPERTIES DEPENDS "aie4_1col_preempt_0hint_asm")
18+
set_tests_properties("aie4_1col_preempt_0hint_asm" PROPERTIES LABELS memcheck)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"xrt-kernels": [
3+
{
4+
"name": "DPU",
5+
"arguments": [
6+
],
7+
"instance": [
8+
{
9+
"id": "dpu",
10+
"ctrl_code_file": "./test.asm"
11+
}
12+
]
13+
}
14+
]
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
691dbc2343144d54c5ad1a8876b4d196
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pdi:
2+
START_JOB 0
3+
NOP
4+
END_JOB
5+
EOF
6+
.endl pdi
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.target aie4
2+
.partition 1column
3+
.attach_to_group 0
4+
START_JOB 0
5+
LOAD_PDI 0, @pdi
6+
END_JOB
7+
START_JOB 1
8+
PREEMPT 0, @save, @restore , @hintmap_0
9+
END_JOB
10+
START_JOB 2
11+
NOP
12+
END_JOB
13+
START_JOB 3
14+
PREEMPT 1, @save, @restore , @hintmap_1
15+
END_JOB
16+
START_JOB 4
17+
NOP
18+
END_JOB
19+
START_JOB 5
20+
PREEMPT 2, @save, @restore , @hintmap_0
21+
END_JOB
22+
START_JOB 6
23+
NOP
24+
END_JOB
25+
26+
.include pdi.asm
27+
EOF
28+
.align 4
29+
hintmap_0:
30+
.long 0x00000000
31+
hintmap_1:
32+
.long 0x0000000f
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (C) 2026 Advanced Micro Devices, Inc.
3+
4+
# Assemble control code ASM with zero-hint_bitmap (hintmap_0 = 0x0) alongside a
5+
# non-zero hintmap (hintmap_1 = 0xf) for a 3-column partition. The zero-hintmap
6+
# PREEMPT points must produce minimal dummy save/restore jobs (NOP / LOAD_LAST_PDI)
7+
# with no BD configuration or stream-switch routing.
8+
add_test(NAME "aie4_3col_preempt_0hint_asm"
9+
COMMAND aiebu-asm -t aie4_config -j "${CMAKE_CURRENT_SOURCE_DIR}/config.json" -o 3col-preempt-0hint.elf -f disabledump
10+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
11+
12+
# Compare the md5sum of the generated ELF against the golden file
13+
add_test(NAME "aie4_3col_preempt_0hint_asm_md5sum"
14+
COMMAND cmake -P "${AIEBU_SOURCE_DIR}/cmake/md5sum-compare.cmake" "${CMAKE_CURRENT_BINARY_DIR}/3col-preempt-0hint.elf" "${CMAKE_CURRENT_SOURCE_DIR}/gold.md5"
15+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
16+
17+
set_tests_properties("aie4_3col_preempt_0hint_asm_md5sum" PROPERTIES DEPENDS "aie4_3col_preempt_0hint_asm")
18+
set_tests_properties("aie4_3col_preempt_0hint_asm" PROPERTIES LABELS memcheck)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"xrt-kernels": [
3+
{
4+
"name": "DPU",
5+
"arguments": [
6+
],
7+
"instance": [
8+
{
9+
"id": "dpu",
10+
"ctrl_code_file": "./test.asm"
11+
}
12+
]
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)