create snp result checker to enable parallel spn calculation and result comparison

This commit is contained in:
Stanislaw Kaushanski 2021-03-25 09:36:16 +01:00
parent 8c0211f945
commit b03f1bff4f
3 changed files with 97 additions and 29 deletions

Binary file not shown.

View File

@ -1,19 +1,15 @@
#include "raven_spn.h" #include "raven_spn.h"
#include "spn_regs.h" #include "spn_regs.h"
#include "init.h" #include "init.h"
#include <math.h> #include "spn_checker_regs.h"
using spn = spn_regs<0x90000000>; using spn = spn_regs<0x90000000>;
using spn_checker = spn_checker_regs<0x10040000>;
// huge arrays of XSPN input and referance data // huge arrays of XSPN input and referance data
extern std::array<uint8_t, 50000> input_data; extern std::array<uint8_t, 50000> input_data;
extern std::array<double, 10000> ref_data; extern std::array<double, 10000> ref_data;
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, int num_samples, int in_beats, int out_beats) { void run_xspn(int in_addr, int out_addr, int num_samples, int in_beats, int out_beats) {
spn::mode_reg() = 0; spn::mode_reg() = 0;
spn::input_length_reg() = num_samples; // each sample consists of 5 uint8 values spn::input_length_reg() = num_samples; // each sample consists of 5 uint8 values
@ -25,22 +21,6 @@ void run_xspn(int in_addr, int out_addr, int num_samples, int in_beats, int out_
spn::start_reg() = 1; spn::start_reg() = 1;
} }
void check_results(int addr, int k, int step) {
int k0 = 0;
bool result = 0;
double *res_base = (double*) (addr);
int * error_exit = (int *)0xF0000000;
for (int i = 0; i < step; i++) {
if (!double_equals(res_base[i], ref_data.at(k0 + i))) {
printf("XSPN ref %d comparison FAILED\n", k0 + i);
result = 1;
}
}
if (result == 1) *error_exit = 0x1;
printf("Compared samples %d - %d with the reference\n", k, k+step);
}
/*! \brief main function /*! \brief main function
* *
@ -73,12 +53,8 @@ int main() {
printf("Result Bytes: %d\n", result_bytes); printf("Result Bytes: %d\n", result_bytes);
uint32_t step = 500; uint32_t step = 2000;
<<<<<<< Updated upstream
uint32_t iterations = 20;
=======
uint32_t iterations = 5; uint32_t iterations = 5;
>>>>>>> Stashed changes
uint32_t in_beats = (step * sample_bytes) / axi_bytes; uint32_t in_beats = (step * sample_bytes) / axi_bytes;
if (in_beats * axi_bytes < step * sample_bytes) in_beats++; if (in_beats * axi_bytes < step * sample_bytes) in_beats++;
@ -88,13 +64,17 @@ int main() {
int in_addr = (int)input_data.data(); int in_addr = (int)input_data.data();
int out_addr = 0x800B0000; int out_addr = 0x800B0000;
spn_checker::ref_addr_reg() = (int)ref_data.data();
spn_checker::addr_reg() = out_addr;
for (int k = 0; k < iterations*step; k+=step) { 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); run_xspn(in_addr, out_addr, step, in_beats, out_beats);
wait_for_interrupt(); wait_for_interrupt();
printf("XSPN finished\n"); printf("XSPN finished\n");
spn_checker::offset_reg() = k;
spn_checker::length_reg() = step;
spn_checker::start_reg() = 1;
spn::interrupt_reg() = 1; spn::interrupt_reg() = 1;
check_results(out_addr, k, step);
in_addr += step * sample_bytes; // 5 bytes in each sample in_addr += step * sample_bytes; // 5 bytes in each sample
} }

View File

@ -0,0 +1,88 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017, MINRES Technologies GmbH
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Created on: Thu Oct 01 15:45:55 CEST 2020
// * spn_regs.h Author: <RDL Generator>
//
////////////////////////////////////////////////////////////////////////////////
#ifndef _SPN_CNTL_REGS_H_
#define _SPN_CNTL_REGS_H_
#include <util/bit_field.h>
#include <cstdint>
#define SPN_CNTL_REG_START 0x00
#define SPN_CNTL_REG_OFFSET 0x10
#define SPN_CNTL_REG_LENGTH 0x20
#define SPN_CNTL_REG_ADDR 0x30
#define SPN_CNTL_REG_REF_ADDR 0x40
template<uint32_t BASE_ADDR>
class spn_checker_regs {
public:
// storage declarations
// BEGIN_BF_DECL(start_t, uint32_t);
// BF_FIELD(start, 0, 1);
// END_BF_DECL() r_start;
uint32_t r_start;
uint32_t r_offset;
uint32_t r_length;
uint32_t r_addr;
uint32_t r_ref_addr;
static inline uint32_t& start_reg(){
return *reinterpret_cast<uint32_t*>(BASE_ADDR+SPN_CNTL_REG_START);
}
static inline uint32_t & offset_reg(){
return *reinterpret_cast<uint32_t*>(BASE_ADDR+SPN_CNTL_REG_OFFSET);
}
static inline uint32_t & length_reg(){
return *reinterpret_cast<uint32_t*>(BASE_ADDR+SPN_CNTL_REG_LENGTH);
}
static inline uint32_t & addr_reg(){
return *reinterpret_cast<uint32_t*>(BASE_ADDR+SPN_CNTL_REG_ADDR);
}
static inline uint32_t & ref_addr_reg(){
return *reinterpret_cast<uint32_t*>(BASE_ADDR+SPN_CNTL_REG_REF_ADDR);
}
};
#endif // _SPN_CNTL_REGS_H_