Create separate xspn-fpga FW

Add xspn data for different accelerators
This commit is contained in:
2021-03-04 11:19:35 +01:00
parent 7f8ddf3201
commit 6bfe684e73
110 changed files with 52472 additions and 35 deletions

Binary file not shown.

View File

@ -83,7 +83,7 @@ void platform_init(){
// Enable the Machine-External bit in MIE
set_csr(mie, MIP_MEIP);
hw_interrupt = false;
//hw_interrupt = false;
}
#endif /* SRC_INIT_H_ */

View File

@ -1,8 +1,9 @@
#include "raven_spn.h"
#include "spn_regs.h"
#include "init.h"
#include <math.h>
using spn =spn_regs<0x90000000>;
using spn = spn_regs<0x90000000>;
// huge arrays of XSPN input and referance data
extern std::array<uint8_t, 50000> input_data;
@ -13,30 +14,33 @@ bool double_equals(double a, double b, double epsilon = 0.001)
return std::abs(a - b) < epsilon;
}
void run_xspn(int in_addr, int out_addr) {
spn::mode_reg() = 0;
spn::input_length_reg() = 500; // each sample consists of 5 uint8 values
spn::input_addr_reg() = in_addr;
spn::output_addr_reg() = out_addr;
spn::num_of_in_beats_reg() = 40; // Number of AXI4 burst beats needed to load all input data
spn::num_of_out_beats_reg() = 64; // Number of AXI4 burst beats needed to store all result data
spn::start_reg() = 1;
void run_xspn(int in_addr, int out_addr, int num_samples, int in_beats, int out_beats) {
spn::mode_reg() = 0;
spn::input_length_reg() = num_samples; // each sample consists of 5 uint8 values
spn::input_addr_reg() = in_addr;
spn::output_addr_reg() = out_addr;
spn::num_of_in_beats_reg() = in_beats; // Number of AXI4 burst beats needed to load all input data
spn::num_of_out_beats_reg() = out_beats; // Number of AXI4 burst beats needed to store all result data
printf("Starting XSPN\n");
spn::start_reg() = 1;
}
void check_results(int addr, int k) {
bool result = 0;
int step = 500;
double *res_base = (double*) (addr);
int * error_exit = (int *)0xF0000000;
void check_results(int addr, int k, int step) {
bool result = 0;
double *res_base = (double*) (addr);
int * error_exit = (int *)0xF0000000;
printf("Start result comparison %d - %d\n", k, k+step);
for (int i = 0; i < step; i++) {
if (!double_equals(res_base[i], ref_data.at(k + i))) {
printf("XSPN ref %d comparison FAILED\n", k + i);
*error_exit = 0x1;
result = 1;
}
}
for (int i = 0; i < step; i++) {
if (!double_equals(res_base[i], ref_data.at(k + i))) {
printf("%x%x vs %x%x\n", ((uint32_t*)res_base)[2*i], ((uint32_t*)res_base)[1+2*i], ((uint32_t*)ref_data.data())[2*i+k*20], ((uint32_t*)ref_data.data())[1+2*i+k*20]);
printf("XSPN ref %d comparison FAILED\n", k + i);
result = 1;
}
}
if (result == 1) *error_exit = 0x1;
printf("Compared samples %d - %d with the reference\n", k, k+step);
}
@ -44,30 +48,55 @@ void check_results(int addr, int k) {
*
*/
int main() {
platform_init();
spn::mode_reg() = 1;
spn::start_reg() = 1;
wait_for_interrupt();
spn::interrupt_reg() = 1;
printf("READOUT HW:0x%x\n", spn::readout_reg());
uint32_t readout = spn::readout_reg();
printf("READOUT HW:0x%x\n", readout);
int in_addr = (int)input_data.data();
int out_addr = 0x800B0000;
uint32_t axi_bytes = readout;
axi_bytes = axi_bytes & 0xff;
axi_bytes = 1 << axi_bytes;
run_xspn(in_addr, out_addr);
printf("AXI Bytes: %d\n", axi_bytes);
int step = 500; // number of samples to be process at once
for (int k = 0; k < 10000; k+=step) {
uint32_t sample_bytes = readout;
sample_bytes = sample_bytes >> 16;
sample_bytes = sample_bytes / 8;
printf("Sample Bytes: %d\n", sample_bytes);
uint32_t result_bytes = 8;
printf("Result Bytes: %d\n", result_bytes);
uint32_t step = 500;
uint32_t iterations = 10;
uint32_t in_beats = (step * sample_bytes) / axi_bytes;
if (in_beats * axi_bytes < step * sample_bytes) in_beats++;
uint32_t out_beats = (step * result_bytes) / axi_bytes;
if (out_beats * axi_bytes < step * result_bytes) out_beats++;
int in_addr = (int)input_data.data();
int out_addr = 0x800B0000;
//run_xspn(in_addr, out_addr);
for (int k = 0; k < iterations*step; k+=step) {
printf("XSPN processes samples %d - %d\n", k, k+step);
run_xspn(in_addr, out_addr, step, in_beats, out_beats);
wait_for_interrupt();
spn::interrupt_reg() = 1;
check_results(out_addr, k);
printf("XSPN finished\n");
spn::interrupt_reg() = 1;
//check_results(out_addr, 0, step);
in_addr += step * 5; // 5 bytes in each sample
run_xspn(in_addr, out_addr);
}
//in_addr += step * sample_bytes; // 5 bytes in each sample
}
return 0;
return 0;
}

View File

@ -0,0 +1,45 @@
#!/usr/bin/python3
import re
import sys
if (len(sys.argv) < 2):
print('No argument given')
exit()
nips = sys.argv[1]
input_file = open(nips + '_inputdata.txt', 'r')
in_data = input_file.read();
# convert double to uint8_t
in_data = re.sub(r'(\d)\.0+e\+00', r'\1,', in_data)
in_data = re.sub(r'(\d)\.(\d)0+e\+01', r'\1\2,', in_data)
in_data = re.sub(r'(\d)\.(\d)(\d)0+e\+02', r'\1\2\3,', in_data)
in_data = in_data.replace(";", "")
# remove last comma
in_data = in_data[:-2]
# count samples
input_sample_cnt = len(in_data.split(","))
#####################################################################
ref_file = open(nips + '_outputdata.txt', 'r')
ref_data = ref_file.read()
ref_data = re.sub(r'\n', r' / ln2,\n', ref_data)
ref_data = ref_data[:-2]
ref_sample_cnt = len(ref_data.split(","))
# create cpp file
f = open("../xspn_data.cpp", "w")
cpp_file = "#include <array>\n"
cpp_file += "#include <cmath>\n\n"
# The results in the outputdata.txt file are not directly what comes out of the PE but the natural logarithm of it.
cpp_file += "constexpr auto ln2 = std::log(2);\n"
cpp_file += "std::array<uint8_t, " + str(input_sample_cnt) + "> input_data = {\n" + str(in_data) + "}; \n\n"
cpp_file += "std::array<double, " + str(ref_sample_cnt) + "> ref_data = {\n" + str(ref_data)+ "}; \n"
f.write(cpp_file)
f.close()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff