Skip to content

Commit 17a768b

Browse files
committed
[Infra]: - add Yosys synthesizer to the VTR flow
- add yosys stage to run_vtr_flow script. - add yosyslib and vtr primitive verilog files to vtr_flow/misc - add slightly modified VTR compatible yosys_models adapted from @eddiehung version - add vtr_reg_yosys running VTR benchmarks using Yosys as the VTR front-end - modify CMakeList to add the libyosys to the VTR build tree Signed-off-by: Seyed Alireza Damghani <[email protected]>
1 parent 8861b11 commit 17a768b

File tree

17 files changed

+1037
-31
lines changed

17 files changed

+1037
-31
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ option(ODIN_TIDY "Enable building odin with clang tidy" OFF)
5252
option(ODIN_SANITIZE "Enable building odin with sanitize flags" OFF)
5353

5454
# Allow the user to enable building Yosys
55+
option(WITH_YOSYS "Enable building Yosys" OFF)
5556
option(ODIN_USE_YOSYS "Enable building Yosys" OFF)
5657

5758
set(VTR_VERSION_MAJOR 8)
@@ -381,14 +382,18 @@ if(${WITH_ABC})
381382
add_subdirectory(ace2)
382383
endif()
383384
add_subdirectory(utils)
384-
if(${WITH_ODIN})
385+
# define cmake params to compile Yosys
386+
if(${WITH_YOSYS})
387+
add_definitions("-D_YOSYS_")
388+
elseif(${WITH_ODIN})
385389
add_subdirectory(ODIN_II)
386390
# blifexplorer depends on odin
387391
if(${WITH_BLIFEXPLORER})
388392
add_subdirectory(blifexplorer)
389393
endif()
390394
endif()
391395

396+
392397
#Add extra compilation flags to suppress warnings from some libraries/tools
393398
# Note that target_compile_options() *appends* to the current compilation options of
394399
# the specified target

libs/EXTERNAL/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ if(VPR_USE_EZGL STREQUAL "on")
1414
add_subdirectory(libezgl)
1515
endif()
1616

17-
# The VTR root CMakeFile initializes the ODIN_USE_YOSYS
17+
# The VTR root CMakeFile initializes the ODIN_USE_YOSYS or WITH_YOSYS
1818
# Yosys is compiled only if the user ask for it
19-
if(${ODIN_USE_YOSYS})
19+
if(${ODIN_USE_YOSYS} OR ${WITH_YOSYS})
2020
add_subdirectory(libyosys)
2121
endif()
2222

libs/EXTERNAL/libyosys/CMakeLists.txt

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
cmake_minimum_required(VERSION 3.9)
22

3-
# [KNOWN_ISSUE]: if ODIN_USE_YOSYS is active, abc will be compiled
4-
# for the second time inside Yosys, since Yosys uses a different
5-
# version of abc
63
project("libyosys")
74

85
# Create a target out of the library compilation result
96
SET(LIB_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libyosys.so)
107
SET(BINARY_LIB_FILE ${CMAKE_CURRENT_BINARY_DIR}/lib/yosys/libyosys.so)
8+
SET(YOSYS_EXEC ${CMAKE_CURRENT_SOURCE_DIR}/yosys)
9+
SET(BINARY_EXEC_FILE ${CMAKE_CURRENT_BINARY_DIR}/bin/yosys)
1110
SET(YOSYS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
1211

1312
# handle make program with both ninja and unix style
1413
set(MAKE_PROGRAM "$(MAKE)")
1514
# handle cppflags to suppress yosys warning with both ninja and unix style
1615
set(CURRENT_CPPFLAGS "$(CPPFLAGS)-w")
1716
if(${CMAKE_GENERATOR} STREQUAL "Ninja")
18-
set(MAKE_PROGRAM "make")
19-
set(CURRENT_CPPFLAGS "-w")
17+
set(MAKE_PROGRAM "make")
18+
set(CURRENT_CPPFLAGS "-w")
2019
endif()
2120

2221
# how to build the result of the library
23-
add_custom_command(OUTPUT ${LIB_FILE} ${BINARY_LIB_FILE}
24-
COMMAND ${MAKE_PROGRAM} -k "ENABLE_LIBYOSYS=1"
25-
CPPFLAGS=${CURRENT_CPPFLAGS}
26-
-j${CMAKE_BUILD_PARALLEL_LEVEL}
27-
PREFIX=${CMAKE_CURRENT_BINARY_DIR}
28-
> /dev/null
29-
COMMAND ${MAKE_PROGRAM} install
30-
PREFIX=${CMAKE_CURRENT_BINARY_DIR}
31-
> /dev/null
32-
COMMAND ${CMAKE_COMMAND} -E
33-
make_directory ${CMAKE_CURRENT_BINARY_DIR}/lib/yosys/
34-
COMMAND ${CMAKE_COMMAND} -E
35-
copy ${LIB_FILE} ${CMAKE_CURRENT_BINARY_DIR}/lib/yosys/
36-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
22+
add_custom_command(OUTPUT ${LIB_FILE} ${BINARY_LIB_FILE} ${YOSYS_EXEC} ${BINARY_EXEC_FILE}
23+
COMMAND ${MAKE_PROGRAM} -k "ENABLE_LIBYOSYS=1" "ENABLE_ABC=0"
24+
CPPFLAGS=${CURRENT_CPPFLAGS}
25+
-j${CMAKE_BUILD_PARALLEL_LEVEL}
26+
PREFIX=${CMAKE_CURRENT_BINARY_DIR}
27+
> /dev/null
28+
COMMAND ${MAKE_PROGRAM} install
29+
PREFIX=${CMAKE_CURRENT_BINARY_DIR}
30+
> /dev/null
31+
COMMAND ${CMAKE_COMMAND} -E
32+
make_directory ${CMAKE_CURRENT_BINARY_DIR}/lib/yosys/
33+
COMMAND ${CMAKE_COMMAND} -E
34+
copy ${LIB_FILE} ${CMAKE_CURRENT_BINARY_DIR}/lib/yosys/
35+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
3736

3837
# create a target out of the library compilation result
39-
add_custom_target(yosys DEPENDS ${LIB_FILE} ${BINARY_LIB_FILE})
38+
add_custom_target(yosys ALL DEPENDS ${LIB_FILE} ${BINARY_LIB_FILE})
4039

4140
# create an library target out of the library compilation result
4241
add_library(libyosys SHARED IMPORTED GLOBAL)
@@ -47,3 +46,6 @@ set_target_properties(libyosys
4746
PROPERTIES PREFIX "" #Avoid extra 'lib' prefix
4847
IMPORTED_LOCATION ${LIB_FILE}
4948
INTERFACE_INCLUDE_DIRECTORIES ${YOSYS_INCLUDE_DIRS})
49+
50+
51+
install(FILES ${YOSYS_EXEC} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

vtr_flow/misc/synthesis.ys

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# XXX is replaced with filename by run_vtr_flow.pl
2+
read_verilog -nolatches XXX
3+
4+
# These commands follow the generic `synth'
5+
# command script inside Yosys
6+
# The -libdir argument allows Yosys to search the current
7+
# directory for any definitions to modules it doesn't know
8+
# about, such as hand-instantiated (not inferred) memories
9+
hierarchy -check -auto-top -libdir . -libdir TTT
10+
proc
11+
12+
# Check that there are no combinational loops
13+
scc -select
14+
select -assert-none %
15+
select -clear
16+
17+
opt
18+
wreduce
19+
# Do not transform $add/$mul ops to $alu and $macc cells
20+
#alumacc
21+
share
22+
opt
23+
fsm
24+
opt -fast
25+
memory -nomap
26+
opt_clean
27+
# But instead of using the `memory_map' command,
28+
# we map any memories, multipliers, and adders into
29+
# VTR primitives (e.g. single_port_ram)
30+
opt -full
31+
32+
# Transform all async FFs into synchronous ones
33+
techmap -map +/adff2dff.v
34+
# Map multipliers, DSPs, and add/subtracts according to yosys_models.v
35+
techmap -map YYY */t:$mul */t:$mem */t:$sub */t:$add
36+
memory_map
37+
# Taking care to remove any undefined muxes that
38+
# are introduced to promote resource sharing
39+
opt -full
40+
# Then techmap all other `complex' blocks into basic
41+
# (lookup table) logic
42+
techmap
43+
opt -fast
44+
45+
flatten
46+
# Perform technology-mapping using ABC
47+
techmap -map YYY */t:$lut
48+
opt -fast
49+
50+
# Turn all DFFs into simple latches
51+
dffunmap
52+
53+
# We read the definitions for all the VTR primitives
54+
# as blackboxes
55+
read_verilog -lib TTT/adder.v
56+
read_verilog -lib TTT/multiply.v
57+
read_verilog -lib -ignore_redef TTT/single_port_ram.v
58+
read_verilog -lib -ignore_redef TTT/dual_port_ram.v
59+
60+
# Lastly, check the hierarchy for any unknown modules,
61+
# and purge all modules (including blackboxes) that
62+
# aren't used
63+
hierarchy -check -purge_lib
64+
tee -o /dev/stdout stat
65+
66+
# Then write it out as a blif file, remembering to call
67+
# the internal `$true'/`$false' signals vcc/gnd, but
68+
# switch `-impltf' doesn't output them
69+
# ZZZ will be replaced by run_vtr_flow.pl
70+
write_blif -true - vcc -false - gnd -undef - unconn -blackbox ZZZ

vtr_flow/misc/yosyslib/adder.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(* blackbox *)
2+
module adder(a, b, cin, cout, sumout);
3+
input a, b, cin;
4+
output cout, sumout;
5+
6+
//assign {cout,sumout} = a + b + cin;
7+
endmodule
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
`timescale 1ps/1ps
2+
3+
module dual_port_ram(clk, we1, we2, addr1, addr2, data1, data2, out1, out2);
4+
parameter ADDR_WIDTH = 15;
5+
parameter DATA_WIDTH = 1;
6+
7+
input clk;
8+
input we1, we2;
9+
input [ADDR_WIDTH-1:0] addr1, addr2;
10+
input [DATA_WIDTH-1:0] data1, data2;
11+
12+
output reg [DATA_WIDTH-1:0] out1, out2;
13+
reg [DATA_WIDTH-1:0] RAM [(1<<ADDR_WIDTH)-1:0];
14+
15+
always @(posedge clk)
16+
begin
17+
if (we1)
18+
RAM[addr1] <= data1;
19+
if (we2)
20+
RAM[addr2] <= data2;
21+
22+
out1 <= RAM[addr1];
23+
out2 <= RAM[addr2];
24+
end
25+
endmodule

vtr_flow/misc/yosyslib/multiply.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(* blackbox *)
2+
module multiply(a, b, out);
3+
parameter A_WIDTH = 36;
4+
parameter B_WIDTH = 36;
5+
parameter Y_WIDTH = A_WIDTH+B_WIDTH;
6+
7+
input [A_WIDTH-1:0] a;
8+
input [B_WIDTH-1:0] b;
9+
output [Y_WIDTH-1:0] out;
10+
11+
//assign out = a * b;
12+
13+
endmodule
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
`timescale 1ps/1ps
2+
3+
module single_port_ram(clk, we, addr, data, out);
4+
5+
parameter ADDR_WIDTH = 15;
6+
parameter DATA_WIDTH = 1;
7+
8+
input clk;
9+
input we;
10+
input [ADDR_WIDTH-1:0] addr;
11+
input [DATA_WIDTH-1:0] data;
12+
13+
output reg [DATA_WIDTH-1:0] out;
14+
reg [DATA_WIDTH-1:0] RAM [(1<<ADDR_WIDTH)-1:0];
15+
16+
always @(posedge clk)
17+
begin
18+
if (we)
19+
RAM[addr] <= data;
20+
21+
out <= RAM[addr];
22+
end
23+
endmodule

0 commit comments

Comments
 (0)