1313#include " xrt/xrt_device.h"
1414#include " xrt/xrt_kernel.h"
1515
16+ #include " test_utils.h"
17+
1618#ifndef XCLBIN
1719#define XCLBIN " build/final.xclbin"
1820#endif
2527#define KERNEL_NAME " MLIR_AIE"
2628#endif
2729
28- #define IN_SIZE (M * N * sizeof (float )) // in bytes
29- #define BIAS_SIZE (N * sizeof (float )) // in bytes
30- #define OUT_SIZE (M * N * sizeof (float )) // in bytes
30+ #define IN_SIZE (SIZE_M * SIZE_N * sizeof (float )) // in bytes
31+ #define BIAS_SIZE (SIZE_N * sizeof (float )) // in bytes
32+ #define OUT_SIZE (SIZE_M * SIZE_N * sizeof (float )) // in bytes
3133
3234void print_matrix (float *buf, int n_rows, int n_cols) {
3335 for (int row = 0 ; row < n_rows; row++) {
@@ -38,34 +40,9 @@ void print_matrix(float *buf, int n_rows, int n_cols) {
3840 }
3941}
4042
41- std::vector<uint32_t > load_instr_binary (std::string instr_path) {
42- // Open file in binary mode
43- std::ifstream instr_file (instr_path, std::ios::binary);
44- if (!instr_file.is_open ()) {
45- throw std::runtime_error (" Unable to open instruction file\n " );
46- }
47-
48- // Get the size of the file
49- instr_file.seekg (0 , std::ios::end);
50- std::streamsize size = instr_file.tellg ();
51- instr_file.seekg (0 , std::ios::beg);
52-
53- // Check that the file size is a multiple of 4 bytes (size of uint32_t)
54- if (size % 4 != 0 ) {
55- throw std::runtime_error (" File size is not a multiple of 4 bytes\n " );
56- }
57-
58- // Allocate vector and read the binary data
59- std::vector<uint32_t > instr_v (size / 4 );
60- if (!instr_file.read (reinterpret_cast <char *>(instr_v.data ()), size)) {
61- throw std::runtime_error (" Failed to read instruction file\n " );
62- }
63- return instr_v;
64- }
65-
6643int main (int argc, const char *argv[]) {
6744
68- std::vector<uint32_t > instr_v = load_instr_binary (INSTS_BIN );
45+ std::vector<uint32_t > instr_v = test_utils:: load_instr_binary (INSTS_BIN );
6946 assert (instr_v.size () > 0 );
7047
7148 // Get a device handle
@@ -131,22 +108,22 @@ int main(int argc, const char *argv[]) {
131108
132109 bo_out.sync (XCL_BO_SYNC_BO_FROM_DEVICE );
133110
134- float ref[M * N ] = {};
135- for (int i = 0 ; i < M ; i++) {
136- for (int j = 0 ; j < N ; j++) {
137- ref[i * N + j] = buf_in[i * N + j] + buf_bias[j];
111+ float ref[SIZE_M * SIZE_N ] = {};
112+ for (int i = 0 ; i < SIZE_M ; i++) {
113+ for (int j = 0 ; j < SIZE_N ; j++) {
114+ ref[i * SIZE_N + j] = buf_in[i * SIZE_N + j] + buf_bias[j];
138115 }
139116 }
140117
141- if (M <= 64 && N <= 64 ) {
118+ if (SIZE_M <= 64 && SIZE_N <= 64 ) {
142119 std::cout << " Input:" << std::endl;
143- print_matrix (buf_in, M, N );
120+ print_matrix (buf_in, SIZE_M , SIZE_N );
144121 std::cout << " Bias:" << std::endl;
145- print_matrix (buf_bias, 1 , N );
122+ print_matrix (buf_bias, 1 , SIZE_N );
146123 std::cout << " Expected:" << std::endl;
147- print_matrix (ref, M, N );
124+ print_matrix (ref, SIZE_M , SIZE_N );
148125 std::cout << " Output:" << std::endl;
149- print_matrix (buf_out, M, N );
126+ print_matrix (buf_out, SIZE_M , SIZE_N );
150127 }
151128
152129 if (memcmp (ref, buf_out, sizeof (ref)) == 0 ) {
0 commit comments