Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang format for stratus accelerators #229

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions accelerators/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
BasedOnStyle: LLVM
TabWidth: 4
IndentWidth: 4
UseTab: Never
ColumnLimit: 120

AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: Consecutive
AlignEscapedNewlines: Left
AlignTrailingComments: true

DerivePointerAlignment: false
PointerAlignment: Right

SpaceBeforeParens: ControlStatements
SpacesBeforeTrailingComments: 1
SpacesInAngles: false

IndentCaseBlocks: true
IndentCaseLabels: true
IndentGotoLabels: false
IndentPPDirectives: BeforeHash
IndentWrappedFunctionNames: true

SortIncludes: false

BreakBeforeBraces: Linux
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeColon

AllowShortFunctionsOnASingleLine: None
...
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;
}
Loading