Skip to content

Commit b0baba5

Browse files
jgmelberfifieldgithub-actions[bot]
authored
Use TXN bin rather than text format (#2128)
Co-authored-by: Jeff Fifield <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 059ab3a commit b0baba5

199 files changed

Lines changed: 608 additions & 739 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/aie/Targets/AIETargets.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,10 @@ mlir::LogicalResult AIETranslateShimSolution(mlir::ModuleOp module,
3434
llvm::raw_ostream &);
3535
mlir::LogicalResult AIETranslateGraphXPE(mlir::ModuleOp module,
3636
llvm::raw_ostream &);
37-
mlir::LogicalResult AIETranslateNpuToBinary(mlir::ModuleOp module,
38-
llvm::raw_ostream &output,
39-
llvm::StringRef sequenceName = "");
4037
mlir::LogicalResult AIETranslateNpuToBinary(mlir::ModuleOp,
4138
std::vector<uint32_t> &,
4239
llvm::StringRef sequenceName = "");
4340
mlir::LogicalResult
44-
AIETranslateControlPacketsToUI32Vec(mlir::ModuleOp module,
45-
llvm::raw_ostream &output,
46-
llvm::StringRef sequenceName = "");
47-
mlir::LogicalResult
4841
AIETranslateControlPacketsToUI32Vec(mlir::ModuleOp, std::vector<uint32_t> &,
4942
llvm::StringRef sequenceName = "");
5043
mlir::LogicalResult AIETranslateToLdScript(mlir::ModuleOp module,

lib/CAPI/Translation.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,26 @@ MlirOperation aieTranslateBinaryToTxn(MlirContext ctx, MlirStringRef binary) {
9494

9595
MlirStringRef aieTranslateNpuToBinary(MlirOperation moduleOp,
9696
MlirStringRef sequenceName) {
97-
std::string npu;
98-
llvm::raw_string_ostream os(npu);
97+
std::vector<uint32_t> insts;
9998
ModuleOp mod = llvm::cast<ModuleOp>(unwrap(moduleOp));
10099
llvm::StringRef name(sequenceName.data, sequenceName.length);
101-
if (failed(AIETranslateNpuToBinary(mod, os, name)))
100+
if (failed(AIETranslateNpuToBinary(mod, insts, name)))
102101
return mlirStringRefCreate(nullptr, 0);
103-
char *cStr = static_cast<char *>(malloc(npu.size()));
104-
npu.copy(cStr, npu.size());
105-
return mlirStringRefCreate(cStr, npu.size());
102+
size_t insts_size = insts.size() * sizeof(uint32_t);
103+
char *cStr = static_cast<char *>(malloc(insts_size));
104+
memcpy(cStr, insts.data(), insts_size);
105+
return mlirStringRefCreate(cStr, insts_size);
106106
}
107107

108108
MlirStringRef aieTranslateControlPacketsToUI32Vec(MlirOperation moduleOp) {
109-
std::string npu;
110-
llvm::raw_string_ostream os(npu);
109+
std::vector<uint32_t> insts;
111110
ModuleOp mod = llvm::cast<ModuleOp>(unwrap(moduleOp));
112-
if (failed(AIETranslateControlPacketsToUI32Vec(mod, os)))
111+
if (failed(AIETranslateControlPacketsToUI32Vec(mod, insts)))
113112
return mlirStringRefCreate(nullptr, 0);
114-
char *cStr = static_cast<char *>(malloc(npu.size()));
115-
npu.copy(cStr, npu.size());
116-
return mlirStringRefCreate(cStr, npu.size());
113+
size_t insts_size = insts.size() * sizeof(uint32_t);
114+
char *cStr = static_cast<char *>(malloc(insts_size));
115+
memcpy(cStr, insts.data(), insts_size);
116+
return mlirStringRefCreate(cStr, insts_size);
117117
}
118118

119119
MlirStringRef aieTranslateToXAIEV2(MlirOperation moduleOp) {

lib/Targets/AIETargetNPU.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,6 @@ xilinx::AIE::AIETranslateNpuToBinary(ModuleOp module,
242242
return success();
243243
}
244244

245-
LogicalResult xilinx::AIE::AIETranslateNpuToBinary(ModuleOp module,
246-
raw_ostream &output,
247-
StringRef sequenceName) {
248-
std::vector<uint32_t> instructions;
249-
auto r = AIETranslateNpuToBinary(module, instructions, sequenceName);
250-
if (failed(r))
251-
return r;
252-
for (auto w : instructions)
253-
output << llvm::format("%08X\n", w);
254-
return success();
255-
}
256-
257245
LogicalResult xilinx::AIE::AIETranslateControlPacketsToUI32Vec(
258246
ModuleOp module, std::vector<uint32_t> &instructions,
259247
StringRef sequenceName) {
@@ -295,15 +283,3 @@ LogicalResult xilinx::AIE::AIETranslateControlPacketsToUI32Vec(
295283
}
296284
return success();
297285
}
298-
299-
LogicalResult xilinx::AIE::AIETranslateControlPacketsToUI32Vec(
300-
ModuleOp module, raw_ostream &output, StringRef sequenceName) {
301-
std::vector<uint32_t> instructions;
302-
auto r =
303-
AIETranslateControlPacketsToUI32Vec(module, instructions, sequenceName);
304-
if (failed(r))
305-
return r;
306-
for (auto w : instructions)
307-
output << llvm::format("%08X\n", w);
308-
return success();
309-
}

lib/Targets/AIETargets.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -346,33 +346,36 @@ void registerAIETranslations() {
346346
TranslateFromMLIRRegistration registrationNPU(
347347
"aie-npu-to-binary", "Translate npu instructions to binary",
348348
[](ModuleOp module, raw_ostream &output) {
349-
if (outputBinary == true) {
350-
std::vector<uint32_t> instructions;
351-
auto r = AIETranslateNpuToBinary(module, instructions, sequenceName);
352-
if (failed(r))
353-
return r;
349+
std::vector<uint32_t> instructions;
350+
auto r = AIETranslateNpuToBinary(module, instructions, sequenceName);
351+
if (failed(r))
352+
return r;
353+
if (outputBinary) {
354354
output.write(reinterpret_cast<const char *>(instructions.data()),
355355
instructions.size() * sizeof(uint32_t));
356-
return success();
356+
} else {
357+
for (auto w : instructions)
358+
output << llvm::format("%08X\n", w);
357359
}
358-
return AIETranslateNpuToBinary(module, output, sequenceName);
360+
return success();
359361
},
360362
registerDialects);
361363
TranslateFromMLIRRegistration registrationCtrlPkt(
362364
"aie-ctrlpkt-to-bin", "Translate aiex.control_packet ops to binary",
363365
[](ModuleOp module, raw_ostream &output) {
364-
if (outputBinary == true) {
365-
std::vector<uint32_t> instructions;
366-
auto r = AIETranslateControlPacketsToUI32Vec(module, instructions,
367-
sequenceName);
368-
if (failed(r))
369-
return r;
366+
std::vector<uint32_t> instructions;
367+
auto r = AIETranslateControlPacketsToUI32Vec(module, instructions,
368+
sequenceName);
369+
if (failed(r))
370+
return r;
371+
if (outputBinary) {
370372
output.write(reinterpret_cast<const char *>(instructions.data()),
371373
instructions.size() * sizeof(uint32_t));
372-
return success();
374+
} else {
375+
for (auto w : instructions)
376+
output << llvm::format("%08X\n", w);
373377
}
374-
return AIETranslateControlPacketsToUI32Vec(module, output,
375-
sequenceName);
378+
return success();
376379
},
377380
registerDialects);
378381
}

programming_examples/basic/dma_transpose/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SHELL := /bin/bash
1616

1717
devicename ?= $(if $(filter 1,$(NPU2)),npu2,npu)
1818
VPATH := ${srcdir}/../../../aie_kernels/generic
19-
all: build/final.xclbin build/insts.txt
19+
all: build/final.xclbin build/insts.bin
2020

2121
targetname = dma_transpose
2222
M ?= 64
@@ -45,7 +45,7 @@ build/final.xclbin: build/aie.mlir
4545
mkdir -p ${@D}
4646
cd ${@D} && aiecc.py --aie-generate-xclbin --no-compile-host --xclbin-name=${@F} \
4747
--no-xchesscc --no-xbridge \
48-
--aie-generate-npu-insts --npu-insts-name=insts.txt $(<:%=../%)
48+
--aie-generate-npu-insts --npu-insts-name=insts.bin $(<:%=../%)
4949

5050
${targetname}.exe: ${srcdir}/test.cpp
5151
rm -rf _build
@@ -59,7 +59,7 @@ else
5959
endif
6060

6161
run: ${targetname}.exe build/final.xclbin
62-
${powershell} ./$< -x build/final.xclbin -i build/insts.txt -k MLIR_AIE --M ${M} --K ${K}
62+
${powershell} ./$< -x build/final.xclbin -i build/insts.bin -k MLIR_AIE --M ${M} --K ${K}
6363

6464
generate_access_map: ${srcdir}/${aie_py_src}
6565
mkdir -p ${@D}

programming_examples/basic/dma_transpose/test.cpp

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,9 @@
2121
#include "xrt/xrt_device.h"
2222
#include "xrt/xrt_kernel.h"
2323

24-
namespace po = boost::program_options;
25-
26-
void check_arg_file_exists(po::variables_map &vm_in, std::string name) {
27-
if (!vm_in.count(name)) {
28-
throw std::runtime_error("Error: no " + name + " file was provided\n");
29-
} else {
30-
std::ifstream test(vm_in[name].as<std::string>());
31-
if (!test) {
32-
throw std::runtime_error("The " + name + " file " +
33-
vm_in[name].as<std::string>() +
34-
" does not exist.\n");
35-
}
36-
}
37-
}
24+
#include "test_utils.h"
3825

39-
std::vector<uint32_t> load_instr_sequence(std::string instr_path) {
40-
std::ifstream instr_file(instr_path);
41-
std::string line;
42-
std::vector<uint32_t> instr_v;
43-
while (std::getline(instr_file, line)) {
44-
std::istringstream iss(line);
45-
uint32_t a;
46-
if (!(iss >> std::hex >> a)) {
47-
throw std::runtime_error("Unable to parse instruction file\n");
48-
}
49-
instr_v.push_back(a);
50-
}
51-
return instr_v;
52-
}
26+
namespace po = boost::program_options;
5327

5428
int main(int argc, const char *argv[]) {
5529
// Program arguments parsing
@@ -85,11 +59,11 @@ int main(int argc, const char *argv[]) {
8559
return 1;
8660
}
8761

88-
check_arg_file_exists(vm, "xclbin");
89-
check_arg_file_exists(vm, "instr");
62+
test_utils::check_arg_file_exists(vm, "xclbin");
63+
test_utils::check_arg_file_exists(vm, "instr");
9064

9165
std::vector<uint32_t> instr_v =
92-
load_instr_sequence(vm["instr"].as<std::string>());
66+
test_utils::load_instr_binary(vm["instr"].as<std::string>());
9367

9468
int verbosity = vm["verbosity"].as<int>();
9569
if (verbosity >= 1)

programming_examples/basic/matrix_multiplication/common.h

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <ostream>
2424
#include <stdfloat>
2525

26+
#include "test_utils.h"
27+
2628
namespace matmul_common {
2729

2830
namespace po = boost::program_options;
@@ -31,19 +33,6 @@ namespace po = boost::program_options;
3133
// Command Line Argument Handling
3234
// --------------------------------------------------------------------------
3335

34-
void check_arg_file_exists(po::variables_map &vm_in, std::string name) {
35-
if (!vm_in.count(name)) {
36-
throw std::runtime_error("Error: no " + name + " file was provided\n");
37-
} else {
38-
std::ifstream test(vm_in[name].as<std::string>());
39-
if (!test) {
40-
throw std::runtime_error("The " + name + " file " +
41-
vm_in[name].as<std::string>() +
42-
" does not exist.\n");
43-
}
44-
}
45-
}
46-
4736
void add_default_options(po::options_description &desc) {
4837
desc.add_options()("help,h", "produce help message")(
4938
"xclbin,x", po::value<std::string>()->required(),
@@ -84,27 +73,8 @@ void parse_options(int argc, const char *argv[], po::options_description &desc,
8473
std::exit(1);
8574
}
8675

87-
check_arg_file_exists(vm, "xclbin");
88-
check_arg_file_exists(vm, "instr");
89-
}
90-
91-
// --------------------------------------------------------------------------
92-
// AIE Specifics
93-
// --------------------------------------------------------------------------
94-
95-
std::vector<uint32_t> load_instr_sequence(std::string instr_path) {
96-
std::ifstream instr_file(instr_path);
97-
std::string line;
98-
std::vector<uint32_t> instr_v;
99-
while (std::getline(instr_file, line)) {
100-
std::istringstream iss(line);
101-
uint32_t a;
102-
if (!(iss >> std::hex >> a)) {
103-
throw std::runtime_error("Unable to parse instruction file\n");
104-
}
105-
instr_v.push_back(a);
106-
}
107-
return instr_v;
76+
test_utils::check_arg_file_exists(vm, "xclbin");
77+
test_utils::check_arg_file_exists(vm, "instr");
10878
}
10979

11080
// --------------------------------------------------------------------------
@@ -474,4 +444,4 @@ void write_out_trace(char *traceOutPtr, size_t trace_size, std::string path) {
474444

475445
} // namespace matmul_common
476446

477-
#endif
447+
#endif

programming_examples/basic/matrix_multiplication/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int main(int argc, const char *argv[]) {
9595
size_t OUT_SIZE = C_SIZE + trace_size;
9696

9797
std::vector<uint32_t> instr_v =
98-
matmul_common::load_instr_sequence(vm["instr"].as<std::string>());
98+
test_utils::load_instr_binary(vm["instr"].as<std::string>());
9999

100100
if (verbosity >= 1)
101101
std::cout << "Sequence instr count: " << instr_v.size() << "\n";

programming_examples/basic/matrix_scalar_add/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ build/final.xclbin: build/aie.mlir
3131
mkdir -p ${@D}
3232
cd ${@D} && aiecc.py --aie-generate-xclbin --aie-generate-npu-insts --no-compile-host \
3333
--no-xchesscc --no-xbridge \
34-
--xclbin-name=${@F} --npu-insts-name=insts.txt ${<F}
34+
--xclbin-name=${@F} --npu-insts-name=insts.bin ${<F}
3535

3636
${targetname}.exe: ${srcdir}/test.cpp
3737
rm -rf _build
@@ -64,7 +64,7 @@ vck5000: build/aie.mlir
6464
-Wl,--whole-archive -Wl,--no-whole-archive -lstdc++ -ldl -lelf -o test.elf
6565

6666
run: ${targetname}.exe build/final.xclbin
67-
${powershell} ./$< -x build/final.xclbin -i build/insts.txt -k MLIR_AIE
67+
${powershell} ./$< -x build/final.xclbin -i build/insts.bin -k MLIR_AIE
6868

6969
clean:
7070
rm -rf build _build inst aie.mlir.prj core_* test.elf ${targetname}.exe

programming_examples/basic/matrix_scalar_add/test.cpp

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "xrt/xrt_device.h"
2121
#include "xrt/xrt_kernel.h"
2222

23+
#include "test_utils.h"
24+
2325
constexpr int IMAGE_WIDTH = 128;
2426
constexpr int IMAGE_HEIGHT = 16;
2527
constexpr int IMAGE_SIZE = (IMAGE_WIDTH * IMAGE_HEIGHT);
@@ -30,34 +32,6 @@ constexpr int TILE_SIZE = (TILE_WIDTH * TILE_HEIGHT);
3032

3133
namespace po = boost::program_options;
3234

33-
void check_arg_file_exists(po::variables_map &vm_in, std::string name) {
34-
if (!vm_in.count(name)) {
35-
throw std::runtime_error("Error: no " + name + " file was provided\n");
36-
} else {
37-
std::ifstream test(vm_in[name].as<std::string>());
38-
if (!test) {
39-
throw std::runtime_error("The " + name + " file " +
40-
vm_in[name].as<std::string>() +
41-
" does not exist.\n");
42-
}
43-
}
44-
}
45-
46-
std::vector<uint32_t> load_instr_sequence(std::string instr_path) {
47-
std::ifstream instr_file(instr_path);
48-
std::string line;
49-
std::vector<uint32_t> instr_v;
50-
while (std::getline(instr_file, line)) {
51-
std::istringstream iss(line);
52-
uint32_t a;
53-
if (!(iss >> std::hex >> a)) {
54-
throw std::runtime_error("Unable to parse instruction file\n");
55-
}
56-
instr_v.push_back(a);
57-
}
58-
return instr_v;
59-
}
60-
6135
int main(int argc, const char *argv[]) {
6236

6337
// Program arguments parsing
@@ -87,11 +61,11 @@ int main(int argc, const char *argv[]) {
8761
return 1;
8862
}
8963

90-
check_arg_file_exists(vm, "xclbin");
91-
check_arg_file_exists(vm, "instr");
64+
test_utils::check_arg_file_exists(vm, "xclbin");
65+
test_utils::check_arg_file_exists(vm, "instr");
9266

9367
std::vector<uint32_t> instr_v =
94-
load_instr_sequence(vm["instr"].as<std::string>());
68+
test_utils::load_instr_binary(vm["instr"].as<std::string>());
9569

9670
int verbosity = vm["verbosity"].as<int>();
9771
if (verbosity >= 1)

0 commit comments

Comments
 (0)