Skip to content

Commit

Permalink
Clang-format for stratus_hls accelerators
Browse files Browse the repository at this point in the history
  • Loading branch information
klchiu committed Oct 22, 2024
1 parent d269239 commit 1b05135
Show file tree
Hide file tree
Showing 104 changed files with 50,594 additions and 66,367 deletions.
1,024 changes: 512 additions & 512 deletions accelerators/stratus_hls/cholesky_stratus/hw/datagen/data.h

Large diffs are not rendered by default.

394 changes: 197 additions & 197 deletions accelerators/stratus_hls/cholesky_stratus/hw/src/cholesky.cpp

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions accelerators/stratus_hls/cholesky_stratus/hw/tb/sc_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@

#define RESET_PERIOD (30 * CLOCK_PERIOD)

system_t * testbench = NULL;
system_t *testbench = NULL;

extern void esc_elaborate()
{
// Creating the whole system
testbench = new system_t("testbench");
// Creating the whole system
testbench = new system_t("testbench");
}

extern void esc_cleanup()
{
// Deleting the system
delete testbench;
// Deleting the system
delete testbench;
}

int sc_main(int argc, char *argv[])
{
// Kills a Warning when using SC_CTHREADS
//sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING);
sc_report_handler::set_actions (SC_WARNING, SC_DO_NOTHING);
// Kills a Warning when using SC_CTHREADS
// sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING);
sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING);

esc_initialize(argc, argv);
esc_elaborate();
esc_initialize(argc, argv);
esc_elaborate();

sc_clock clk("clk", CLOCK_PERIOD, SC_PS);
sc_signal<bool> rst("rst");
sc_clock clk("clk", CLOCK_PERIOD, SC_PS);
sc_signal<bool> rst("rst");

testbench->clk(clk);
testbench->rst(rst);
rst.write(false);
testbench->clk(clk);
testbench->rst(rst);
rst.write(false);

sc_start(RESET_PERIOD, SC_PS);
sc_start(RESET_PERIOD, SC_PS);

rst.write(true);
rst.write(true);

sc_start();
sc_start();

esc_log_pass();
esc_cleanup();
esc_log_pass();
esc_cleanup();

return 0;
return 0;
}
97 changes: 51 additions & 46 deletions accelerators/stratus_hls/cholesky_stratus/hw/tb/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ void system_t::config_proc()
/* <<--params-->> */
config.rows = rows;

wait(); conf_info.write(config);
wait();
conf_info.write(config);
conf_done.write(true);
}

Expand All @@ -38,26 +39,27 @@ void system_t::config_proc()
ESP_REPORT_TIME(begin_time, "BEGIN - cholesky");

// Wait the termination of the accelerator
do { wait(); } while (!acc_done.read());
do {
wait();
} while (!acc_done.read());
debug_info_t debug_code = debug.read();

// Print information about end time
sc_time end_time = sc_time_stamp();
ESP_REPORT_TIME(end_time, "END - cholesky");

esc_log_latency(sc_object::basename(), clock_cycle(end_time - begin_time));
wait(); conf_done.write(false);
wait();
conf_done.write(false);
}

// Validate
{
dump_memory(); // store the output in more suitable data structure if needed
// check the results with the golden model
if (validate())
{
if (validate()) {
ESP_REPORT_ERROR("validation failed!");
} else
{
} else {
ESP_REPORT_INFO("validation passed!");
}
}
Expand All @@ -73,23 +75,22 @@ void system_t::load_memory()
{
// Optional usage check
#ifdef CADENCE
if (esc_argc() != 1)
{
if (esc_argc() != 1) {
ESP_REPORT_INFO("usage: %s\n", esc_argv()[0]);
sc_stop();
}
#endif

// Input data and golden output (aligned to DMA_WIDTH makes your life easier)
#if (DMA_WORD_PER_BEAT == 0)
in_words_adj = rows * rows;
in_words_adj = rows * rows;
out_words_adj = rows * rows;
#else
in_words_adj = round_up(rows * rows, DMA_WORD_PER_BEAT);
in_words_adj = round_up(rows * rows, DMA_WORD_PER_BEAT);
out_words_adj = round_up(rows * rows, DMA_WORD_PER_BEAT);
#endif

in_size = in_words_adj * (1);
in_size = in_words_adj * (1);
out_size = out_words_adj * (1);

ifstream f("../datagen/input.txt");
Expand All @@ -107,38 +108,38 @@ void system_t::load_memory()
in = new float[in_size];
for (int i = 0; i < 1; i++)
for (int j = 0; j < rows * rows; j++)
f>> in[i * in_words_adj + j] ;
f >> in[i * in_words_adj + j];

// Compute golden output
gold = new float[out_size];
for (int i = 0; i < 1; i++)
for (int j = 0; j < rows * rows; j++)
fo>> gold[i * out_words_adj + j] ;
for (int i = 0; i < 1; i++)
for (int j = 0; j < rows * rows; j++)
fo >> gold[i * out_words_adj + j];

for (int i = 0; i < out_size; i++) {
sc_dt::sc_bv<DMA_WIDTH> gold_bv;
gold_bv.range( DATA_WIDTH - 1, 0) = fp2bv<FPDATA, WORD_SIZE>(FPDATA(gold[i ]));
gold_bv.range(DATA_WIDTH - 1, 0) = fp2bv<FPDATA, WORD_SIZE>(FPDATA(gold[i]));
// cout << "gold [" << i <<" ]" << "=" << gold_bv.to_int64() << "; \n" ;
}

// Memory initialization:
#if (DMA_WORD_PER_BEAT == 0)
for (int i = 0; i < in_size; i++) {
for (int i = 0; i < in_size; i++) {
sc_dt::sc_bv<DATA_WIDTH> data_bv(in[i]);
for (int j = 0; j < DMA_BEAT_PER_WORD; j++)
mem[DMA_BEAT_PER_WORD * i + j] = data_bv.range((j + 1) * DMA_WIDTH - 1, j * DMA_WIDTH);
}
#else
for (int i = 0; i < in_size / DMA_WORD_PER_BEAT; i++) {
for (int i = 0; i < in_size / DMA_WORD_PER_BEAT; i++) {
sc_dt::sc_bv<DMA_WIDTH> data_bv;
for (int j = 0; j < DMA_WORD_PER_BEAT; j++)
{
data_bv.range((j+1) * DATA_WIDTH - 1, j * DATA_WIDTH) = fp2bv<FPDATA, WORD_SIZE> (FPDATA( in[i * DMA_WORD_PER_BEAT + j]));
//cout << "INPUT DATA FPDATA" << (FPDATA( in[i * DMA_WORD_PER_BEAT + j])) << "\n";
//cout << "INPUT DATA I" << in[i * DMA_WORD_PER_BEAT + j] << "\n";
}
for (int j = 0; j < DMA_WORD_PER_BEAT; j++) {
data_bv.range((j + 1) * DATA_WIDTH - 1, j * DATA_WIDTH) =
fp2bv<FPDATA, WORD_SIZE>(FPDATA(in[i * DMA_WORD_PER_BEAT + j]));
// cout << "INPUT DATA FPDATA" << (FPDATA( in[i * DMA_WORD_PER_BEAT + j])) << "\n";
// cout << "INPUT DATA I" << in[i * DMA_WORD_PER_BEAT + j] << "\n";
}
mem[i] = data_bv;
//cout << " mem[" << i << "] = " << data_bv.to_int64() << ";" << " \n";
// cout << " mem[" << i << "] = " << data_bv.to_int64() << ";" << " \n";
}
#endif

Expand All @@ -149,12 +150,12 @@ void system_t::dump_memory()
{

// Get results from memory
out = new float [out_size];
out = new float[out_size];
uint32_t offset = in_size;

#if (DMA_WORD_PER_BEAT == 0)
offset = offset * DMA_BEAT_PER_WORD;
for (int i = 0; i < out_size; i++) {
for (int i = 0; i < out_size; i++) {
sc_dt::sc_bv<DATA_WIDTH> data_bv;

for (int j = 0; j < DMA_BEAT_PER_WORD; j++)
Expand All @@ -163,13 +164,14 @@ void system_t::dump_memory()
out[i] = data_bv.to_int64();
}
#else
offset = offset / DMA_WORD_PER_BEAT;
offset = offset / DMA_WORD_PER_BEAT;
for (int i = 0; i < out_size / DMA_WORD_PER_BEAT; i++)
for (int j = 0; j < DMA_WORD_PER_BEAT; j++) {
FPDATA out_fx = bv2fp<FPDATA, WORD_SIZE>(mem[offset + i].range((j + 1) * DATA_WIDTH - 1, j * DATA_WIDTH).to_int64());
out[i * DMA_WORD_PER_BEAT + j] = (float) out_fx;
// cout << " FIXED VALUE " << out_fx << " FLOAT VALUE " << (float) out_fx << "\n";
}
FPDATA out_fx =
bv2fp<FPDATA, WORD_SIZE>(mem[offset + i].range((j + 1) * DATA_WIDTH - 1, j * DATA_WIDTH).to_int64());
out[i * DMA_WORD_PER_BEAT + j] = (float)out_fx;
// cout << " FIXED VALUE " << out_fx << " FLOAT VALUE " << (float) out_fx << "\n";
}

#endif

Expand All @@ -179,26 +181,29 @@ void system_t::dump_memory()
int system_t::validate()
{
// Check for mismatches
uint32_t errors = 0;
int n=0;
const float ERR_TH = 0.25f; //20% error
uint32_t errors = 0;
int n = 0;
const float ERR_TH = 0.25f; // 20% error
for (int i = 0; i < 1; i++) {
for (int j = 0; j < rows * rows; j++) {
if (j==(rows *n)) {
cout << "# ######################################## ROW " << (n+1) << " ############################################# \n";
if (j == (rows * n)) {
cout << "# ######################################## ROW " << (n + 1)
<< " ############################################# \n";
n++;
}
if ((fabs(gold[i* out_words_adj + j] - out[i* out_words_adj +j]) / fabs(gold[i * out_words_adj +j])) > ERR_TH) {
}
if ((fabs(gold[i * out_words_adj + j] - out[i * out_words_adj + j]) / fabs(gold[i * out_words_adj + j])) >
ERR_TH) {
errors++;
printf("(%d, %d): Out: %.5f, Gold: %.5f\n" , n, j % rows, out[i * out_words_adj + j], gold[i*out_words_adj + j]);
printf("(%d, %d): Out: %.5f, Gold: %.5f\n", n, j % rows, out[i * out_words_adj + j],
gold[i * out_words_adj + j]);
}
}
}
cout << "\n";
cout << " ERROR COUNT = " << errors ;
delete [] in;
delete [] out;
delete [] gold;
cout << "\n";
cout << " ERROR COUNT = " << errors;
delete[] in;
delete[] out;
delete[] gold;

return errors;
}
35 changes: 16 additions & 19 deletions accelerators/stratus_hls/cholesky_stratus/sw/linux/app/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@ int32_t rows = ROWS;
#define NACC 1

struct cholesky_stratus_access cholesky_cfg_000[] = {
/* <<--descriptor-->> */
/* <<--descriptor-->> */
{
.rows = ROWS,
.src_offset = 0,
.dst_offset = 0,
.esp.coherence = ACC_COH_FULL,
.esp.p2p_store = 0,
.esp.p2p_nsrcs = 0,
.esp.p2p_srcs = {"", "", "", ""},
}
};

esp_thread_info_t cfg_000[] = {
{
.run = true,
.devname = "cholesky_stratus.0",
.ioctl_req = CHOLESKY_STRATUS_IOC_ACCESS,
.esp_desc = &(cholesky_cfg_000[0].esp),
}
};
.rows = ROWS,
.src_offset = 0,
.dst_offset = 0,
.esp.coherence = ACC_COH_FULL,
.esp.p2p_store = 0,
.esp.p2p_nsrcs = 0,
.esp.p2p_srcs = {"", "", "", ""},
}};

esp_thread_info_t cfg_000[] = {{
.run = true,
.devname = "cholesky_stratus.0",
.ioctl_req = CHOLESKY_STRATUS_IOC_ACCESS,
.esp_desc = &(cholesky_cfg_000[0].esp),
}};

#endif /* __ESP_CFG_000_H__ */
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
#define _CHOLESKY_STRATUS_H_

#ifdef __KERNEL__
#include <linux/ioctl.h>
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/types.h>
#else
#include <sys/ioctl.h>
#include <stdint.h>
#ifndef __user
#define __user
#endif
#include <sys/ioctl.h>
#include <stdint.h>
#ifndef __user
#define __user
#endif
#endif /* __KERNEL__ */

#include <esp.h>
#include <esp_accelerator.h>

struct cholesky_stratus_access {
struct esp_access esp;
/* <<--regs-->> */
unsigned rows;
unsigned src_offset;
unsigned dst_offset;
struct esp_access esp;
/* <<--regs-->> */
unsigned rows;
unsigned src_offset;
unsigned dst_offset;
};

#define CHOLESKY_STRATUS_IOC_ACCESS _IOW ('S', 0, struct cholesky_stratus_access)
#define CHOLESKY_STRATUS_IOC_ACCESS _IOW('S', 0, struct cholesky_stratus_access)

#endif /* _CHOLESKY_STRATUS_H_ */
Loading

0 comments on commit 1b05135

Please sign in to comment.