Skip to content

Commit 62efe4f

Browse files
authored
[Backend][SystemC] Stratus HLS Codegen Backend Support (Re-opened) (cornell-zhang#451)
* [Backend][SystemC] Add StratusHLS backend implementation * [Backend][SystemC] Add Python API and harness files * [Backend][SystemC] Ruling out illegal loop label string * [Backend][SystemC] Rename and move PortDirection and Hierarchy to ir_utils.h
1 parent a68823d commit 62efe4f

25 files changed

+5351
-29
lines changed

python/heterocl/api.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ def build(schedule, target=None, name="default_function", stmt=None):
323323
new_inputs.append(i.var)
324324

325325
# auto data moving to dev
326-
if len(schedule.placement) == 0 and (target is not None):
326+
if hasattr(target, "name") and target.name == "cadence_stratus":
327+
# Cadence stratus does not support auto data moving
328+
pass
329+
elif len(schedule.placement) == 0 and (target is not None):
327330
if not isinstance(target, str):
328331
# TODO: print clean info for auto placement
329332
# import builtins as __builtin__
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
###############################################################################
2+
#
3+
# Copyright (c) 2017 Cadence Design Systems, Inc. All rights reserved worldwide.
4+
#
5+
# The code contained herein is the proprietary and confidential information
6+
# of Cadence or its licensors, and is supplied subject to a previously
7+
# executed license and maintenance agreement between Cadence and customer.
8+
# This code is intended for use with Cadence high-level synthesis tools and
9+
# may not be used with other high-level synthesis tools. Permission is only
10+
# granted to distribute the code as indicated. Cadence grants permission for
11+
# customer to distribute a copy of this code to any partner to aid in designing
12+
# or verifying the customer's intellectual property, as long as such
13+
# distribution includes a restriction of no additional distributions from the
14+
# partner, unless the partner receives permission directly from Cadence.
15+
#
16+
# ALL CODE FURNISHED BY CADENCE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
17+
# KIND, AND CADENCE SPECIFICALLY DISCLAIMS ANY WARRANTY OF NONINFRINGEMENT,
18+
# FITNESS FOR A PARTICULAR PURPOSE OR MERCHANTABILITY. CADENCE SHALL NOT BE
19+
# LIABLE FOR ANY COSTS OF PROCUREMENT OF SUBSTITUTES, LOSS OF PROFITS,
20+
# INTERRUPTION OF BUSINESS, OR FOR ANY OTHER SPECIAL, CONSEQUENTIAL OR
21+
# INCIDENTAL DAMAGES, HOWEVER CAUSED, WHETHER FOR BREACH OF WARRANTY,
22+
# CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE.
23+
#
24+
################################################################################
25+
26+
# Include the Makefile.prj file extracted from project.tcl
27+
-include Makefile.prj
28+
29+
# Rule to update Makefile.prj anytime project.tcl changes
30+
Makefile.prj : project.tcl
31+
@bdw_makegen
32+
33+
# List subdirectories that contain memory libraries
34+
MEMLIBS =
35+
36+
# List subdirectories that contain interface libraries
37+
IFLIBS =
38+
39+
# Uncomment this line to use the Insight debugger
40+
BDW_DEBUG = 1
41+
42+
# The cmp_result target compares the golden results file (golden.dat) with
43+
# the simulation results file (data.out) written by the testbench into the
44+
# BDW_SIM_CONFIG simulation configuration directory. This is run automatically
45+
# at the end of each simulation (endOfSimCommand in project.tcl).
46+
GOLD_FILE = DRAM/golden.bin
47+
RESULTS_FILE = DRAM/result.bin
48+
49+
# cmp_result:
50+
# @if [ -f $(RESULTS_FILE) ] ; then \
51+
# echo "****************************************" ; \
52+
# echo `date` ; \
53+
# echo "Performing Simulation Results Comparison" ; \
54+
# echo "for $(BDW_SIM_CONFIG) Simulation..." ; \
55+
# if diff $(RESULTS_FILE) $(GOLD_FILE) ; then \
56+
# echo " $(BDW_SIM_CONFIG): SIMULATION PASSED" ; \
57+
# bdw_sim_pass ; \
58+
# else \
59+
# echo " $(BDW_SIM_CONFIG): SIMULATION FAILED" ; \
60+
# bdw_sim_fail ; \
61+
# fi ; \
62+
# echo "****************************************" ; \
63+
# else \
64+
# echo "****************************************" ; \
65+
# echo `date` ; \
66+
# echo "ERROR: Simulation output doesn't exist" ; \
67+
# echo "for $(BDW_SIM_CONFIG) Simulation..." ; \
68+
# echo " $(BDW_SIM_CONFIG): SIMULATION FAILED" ; \
69+
# bdw_sim_fail ; \
70+
# echo "****************************************" ; \
71+
# fi
72+
cmp_result:
73+
@if [ -f $(RESULTS_FILE) ] ; then \
74+
echo "****************************************" ; \
75+
echo `date` ; \
76+
echo "for $(BDW_SIM_CONFIG) Simulation..." ; \
77+
echo " $(BDW_SIM_CONFIG): SIMULATION PASSED" ; \
78+
bdw_sim_pass ; \
79+
echo "****************************************" ; \
80+
else \
81+
echo "****************************************" ; \
82+
echo `date` ; \
83+
echo "ERROR: Simulation output doesn't exist" ; \
84+
echo "for $(BDW_SIM_CONFIG) Simulation..." ; \
85+
echo " $(BDW_SIM_CONFIG): SIMULATION FAILED" ; \
86+
bdw_sim_fail ; \
87+
echo "****************************************" ; \
88+
fi
89+
90+
# Clean out undesirable junk files from the project directory
91+
# Uses the automatically created clean_all target from Makefile.prj
92+
clean: clean_all
93+
@rm -rf bdw_work vsim* *.wlf data.out *~ *.bak *.BAK Makefile.prj
94+
@rm -rf core *.pro *.user *.log .*.qws .*.check .stack* .parts*
95+
@rm -rf rc.* fv .stratus*
96+
97+
CLEAN: clean
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2017 Cadence Design Systems, Inc. All rights reserved worldwide.
4+
//
5+
// The code contained herein is the proprietary and confidential information
6+
// of Cadence or its licensors, and is supplied subject to a previously
7+
// executed license and maintenance agreement between Cadence and customer.
8+
// This code is intended for use with Cadence high-level synthesis tools and
9+
// may not be used with other high-level synthesis tools. Permission is only
10+
// granted to distribute the code as indicated. Cadence grants permission for
11+
// customer to distribute a copy of this code to any partner to aid in designing
12+
// or verifying the customer's intellectual property, as long as such
13+
// distribution includes a restriction of no additional distributions from the
14+
// partner, unless the partner receives permission directly from Cadence.
15+
//
16+
// ALL CODE FURNISHED BY CADENCE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
17+
// KIND, AND CADENCE SPECIFICALLY DISCLAIMS ANY WARRANTY OF NONINFRINGEMENT,
18+
// FITNESS FOR A PARTICULAR PURPOSE OR MERCHANTABILITY. CADENCE SHALL NOT BE
19+
// LIABLE FOR ANY COSTS OF PROCUREMENT OF SUBSTITUTES, LOSS OF PROFITS,
20+
// INTERRUPTION OF BUSINESS, OR FOR ANY OTHER SPECIAL, CONSEQUENTIAL OR
21+
// INCIDENTAL DAMAGES, HOWEVER CAUSED, WHETHER FOR BREACH OF WARRANTY,
22+
// CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE.
23+
//
24+
////////////////////////////////////////////////////////////////////////////////
25+
26+
#include <systemc.h> // SystemC definitions
27+
#include "system.h" // Top-level System module header file
28+
29+
static System * m_system = NULL; // The pointer that holds the top-level System module instance.
30+
31+
void esc_elaborate() // This function is required by Stratus to support SystemC-Verilog
32+
{ // cosimulation. It instances the top-level module.
33+
m_system = new System( "system" );
34+
}
35+
36+
void esc_cleanup() // This function is called at the end of simulation by the
37+
{ // Stratus co-simulation hub. It should delete the top-level
38+
delete m_system; // module instance.
39+
}
40+
41+
int sc_main( int argc, char ** argv ) // This function is called by the SystemC kernel for pure SystemC simulations
42+
{
43+
esc_initialize( argc, argv ); // esc_initialize() passes in the cmd-line args. This initializes the Stratus simulation
44+
// environment (such as opening report files for later logging and analysis).
45+
46+
esc_elaborate(); // esc_elaborate() (defined above) creates the top-level module instance. In a SystemC-Verilog
47+
// co-simulation, this is called during cosim initialization rather than from sc_main.
48+
49+
sc_start(); // Starts the simulation. Returns when a module calls esc_stop(), which finishes the simulation.
50+
// esc_cleanup() (defined above) is automatically called before sc_start() returns.
51+
52+
return 0; // Returns the status of the simulation. Required by most C compilers.
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
2+
///////////////////////////////////////////////////////////////////////////////
3+
//
4+
// Copyright (c) 2021 Cadence Design Systems, Inc. All rights reserved worldwide.
5+
//
6+
// The code contained herein is the proprietary and confidential information
7+
// of Cadence or its licensors, and is supplied subject to a previously
8+
// executed license and maintenance agreement between Cadence and customer.
9+
// This code is intended for use with Cadence high-level synthesis tools and
10+
// may not be used with other high-level synthesis tools. Permission is only
11+
// granted to distribute the code as indicated. Cadence grants permission for
12+
// customer to distribute a copy of this code to any partner to aid in designing
13+
// or verifying the customer's intellectual property, as long as such
14+
// distribution includes a restriction of no additional distributions from the
15+
// partner, unless the partner receives permission directly from Cadence.
16+
//
17+
// ALL CODE FURNISHED BY CADENCE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
18+
// KIND, AND CADENCE SPECIFICALLY DISCLAIMS ANY WARRANTY OF NONINFRINGEMENT,
19+
// FITNESS FOR A PARTICULAR PURPOSE OR MERCHANTABILITY. CADENCE SHALL NOT BE
20+
// LIABLE FOR ANY COSTS OF PROCUREMENT OF SUBSTITUTES, LOSS OF PROFITS,
21+
// INTERRUPTION OF BUSINESS, OR FOR ANY OTHER SPECIAL, CONSEQUENTIAL OR
22+
// INCIDENTAL DAMAGES, HOWEVER CAUSED, WHETHER FOR BREACH OF WARRANTY,
23+
// CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE.
24+
//
25+
////////////////////////////////////////////////////////////////////////////////
26+
27+
28+
// Generated by bdw_memgen 20.23-s100
29+
// Thu Jun 24 09:00:48 CST 2021
30+
31+
#if ! defined dram_CC
32+
#define dram_CC 1
33+
#if defined STRATUS && ! defined CYN_DONT_SUPPRESS_MSGS
34+
#pragma cyn_suppress_msgs NOTE
35+
#endif // STRATUS && CYN_DONT_SUPPRESS_MSGS
36+
#include "dram.h"
37+
38+
#ifdef STRATUS_HLS
39+
sc_uint<8> dram::read0(sc_uint<28> A0, bool WE0) {
40+
sc_uint<8> DOUT0;
41+
CYN_BIND(WE0,this->WE0);
42+
CYN_BIND(A0,this->A0);
43+
CYN_BIND(DOUT0,this->DOUT0);
44+
HLS_CONFIG_INSTRUCTION( "access_port", 1 );
45+
DOUT0 = mem[A0];
46+
return DOUT0;
47+
}
48+
49+
#endif // STRATUS_HLS
50+
#ifdef STRATUS_HLS
51+
sc_uint<8> dram::write0(sc_uint<28> A0, sc_uint<8> DIN0, bool WE0) {
52+
53+
CYN_BIND(WE0,this->WE0);
54+
CYN_BIND(A0,this->A0);
55+
CYN_BIND(DIN0,this->DIN0);
56+
HLS_CONFIG_INSTRUCTION( "access_port", 1 );
57+
mem[A0] = DIN0;
58+
return DIN0;
59+
}
60+
61+
#endif // STRATUS_HLS
62+
#ifdef STRATUS_HLS
63+
void dram::nop0(bool WE0) {
64+
CYN_BIND(WE0,this->WE0);
65+
HLS_CONFIG_INSTRUCTION( "access_port", 1 );
66+
}
67+
68+
#endif // STRATUS_HLS
69+
void dram::thread0() {
70+
#if defined(__GNUC__) && BDW_USE_SCV
71+
if ( m_p1_tx_0.is_active() ) {
72+
m_p1_tx_stream->end_tx( m_p1_tx_0, DOUT0.read() );
73+
}
74+
#endif
75+
#if defined(__GNUC__)
76+
// Perform an address range check to prevent crashes on out of bounds
77+
// accesses in SystemC behavioral simulations.
78+
if((int)(A0.read()) <= WORDCOUNT) {
79+
#endif
80+
if(WE0.read() == 0) {
81+
82+
#if defined(__GNUC__) && BDW_USE_SCV
83+
m_p1_tx_0 = m_p1_tx_stream->begin_write_tx( A0.read(), DIN0.read() );
84+
#endif
85+
86+
#if defined(__GNUC__) && defined(BDW_TRACE_MEMS)
87+
fprintf(stderr,"TRACE: %s%s: %s: write 0x%s to 0x%x\n", name(), "", sc_time_stamp().to_string().c_str(), DIN0.read().to_string(SC_HEX).c_str(), (int)A0.read().to_uint());
88+
#endif
89+
mem[A0.read().to_uint()] = DIN0.read();
90+
#if defined(__GNUC__)
91+
sync_put(A0.read().to_uint());
92+
#endif
93+
} else {
94+
95+
#if defined(__GNUC__)
96+
#if BDW_USE_SCV
97+
m_p1_tx_0 = m_p1_tx_stream->begin_read_tx( A0.read() );
98+
#endif
99+
sync_get(A0.read().to_uint());
100+
#endif
101+
102+
#if defined(__GNUC__) && defined(BDW_TRACE_MEMS)
103+
fprintf(stderr,"TRACE: %s: %s: read 0x%s from 0x%x\n", name(), sc_time_stamp().to_string().c_str(), mem[A0.read().to_uint()].to_string(SC_HEX).c_str(), (int)A0.read().to_uint());
104+
#endif
105+
DOUT0 = mem[A0.read().to_uint()];
106+
}
107+
108+
#if defined(__GNUC__)
109+
}
110+
#endif
111+
}
112+
#if defined(STRATUS_VLG)
113+
dram::dram(const sc_module_name name)
114+
: sc_module( name ) ,CLK("CLK"),WE0("WE0"),DIN0("DIN0"),DOUT0("DOUT0"),A0("A0"), mem()
115+
#else
116+
dram::dram( sc_module_name name)
117+
: sc_module( name ) ,CLK("CLK"),WE0("WE0"),DIN0("DIN0"),DOUT0("DOUT0"),A0("A0"), mem()
118+
#if defined(__GNUC__)
119+
, m_iface(0)
120+
#endif
121+
#endif
122+
{
123+
#ifdef STRATUS_HLS
124+
SC_CTHREAD( thread0, (CLK).pos() );
125+
#else
126+
SC_METHOD( thread0 );
127+
sensitive << (CLK).pos();
128+
129+
#endif
130+
#ifndef STRATUS_HLS
131+
dont_initialize();
132+
#endif
133+
#if defined(__GNUC__) && BDW_USE_SCV
134+
esc_enable_scv_logging();
135+
m_p1_tx_stream = new cynw_scv_memory_tx_stream< sc_uint<28>, sc_uint<8> >( (std::string("sc_main.") + std::string(this->name())).c_str(), esc_get_scv_tr_db() );
136+
#endif
137+
138+
}
139+
140+
const unsigned long dram::implemented = 1;
141+
const unsigned long dram::pipelined = 1;
142+
const float dram::area = 0;
143+
const float dram::delay = 1;
144+
const float dram::setup_time = 1;
145+
const unsigned long dram::latency_WE0 = 1;
146+
const unsigned long dram::latency_DIN0 = 1;
147+
const unsigned long dram::latency_A0 = 1;
148+
const unsigned long dram::bits_per_maskbit_WM0 = 0;
149+
const unsigned long dram::reg_mem_inputs = 0;
150+
const unsigned long dram::reg_mem_outputs = 0;
151+
const unsigned long dram::regs_at_mem_inputs = 0;
152+
const unsigned long dram::regs_at_mem_outputs = 0;
153+
const unsigned long dram::no_spec_reads = 1;
154+
const unsigned long dram::is_mem = 1;
155+
const unsigned long dram::clock_multiplier = 0;
156+
const bool dram::has_extra_ports = false;
157+
const bool dram::is_prototype = false;
158+
const char* dram::naming_convention = 0;
159+
160+
#endif // dram_CC
161+

0 commit comments

Comments
 (0)