Skip to content

Commit 46b95c7

Browse files
committed
Octopus merge
This is an Octopus Merge commit of the following branches: wip/add-issue-template wip/avoid-criticality-issue wip/avoid_unordered_set wip/connection_box_serdes_merge_squashed wip/disable-check-route-option wip/optimize_ndmatrix wip/refactor_heap2 wip/rr-graph-binary-read-write wip/symbiflow-badger
1 parent 0fe92d4 commit 46b95c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2389
-112
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: Bug report
33
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
47

58
---
69

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: Feature request
33
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
47

58
---
69

.github/ISSUE_TEMPLATE/vtr-change.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: VTR change
3+
about: Describe purpose and lifecycle of a local change we made to VTR
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
### Why did we need this? (what does this change enable us to do)
11+
<!--- i.e. what does this change enable us to do? -->
12+
13+
### What did it change?
14+
<!--- i.e. technical description what the change does -->
15+
16+
### Should it be merged upstream - if not, when can we delete it?
17+
18+
### What is needed to get this merged / deleted?
19+
20+
* [ ] is the implementation work to make suitable for merging / deletion completed?
21+
* [ ] Is there an associated test? <!--- i.e. how will we prevent it from regressing? -->
22+
* [ ] is this currently part of the Conda package?
23+
* [ ] is this properly cleaned up in our local repositories? <!--- add subtasks here if needed) -->
24+
25+
### Tracker / branch / PR & other useful links

CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ option(VTR_ENABLE_SANITIZE "Enable address/leak/undefined-behaviour sanitizers (
3434
option(VTR_ENABLE_PROFILING "Enable performance profiler (gprof)" OFF)
3535
option(VTR_ENABLE_COVERAGE "Enable code coverage tracking (gcov)" OFF)
3636
option(VTR_ENABLE_DEBUG_LOGGING "Enable debug logging" OFF)
37+
option(VTR_ENABLE_CAPNPROTO "Enable capnproto binary serialization support in VPR." ON)
3738

3839
#Allow the user to decide weather to compile the graphics library
3940
set(VPR_USE_EZGL "auto" CACHE STRING "Specify whether vpr uses the graphics library")
@@ -276,8 +277,13 @@ endif()
276277
#
277278
# Set final flags
278279
#
279-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS} ${SANITIZE_FLAGS} ${PROFILING_FLAGS} ${COVERAGE_FLAGS} ${LOGGING_FLAGS} ${COLORED_COMPILE}")
280-
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
280+
separate_arguments(
281+
ADDITIONAL_FLAGS UNIX_COMMAND "${SANITIZE_FLAGS} ${PROFILING_FLAGS} ${COVERAGE_FLAGS} ${LOGGING_FLAGS} ${COLORED_COMPILE}"
282+
)
283+
add_compile_options(${ADDITIONAL_FLAGS})
284+
separate_arguments(
285+
WARN_FLAGS UNIX_COMMAND "${WARN_FLAGS}"
286+
)
281287

282288

283289
#
@@ -329,6 +335,9 @@ endif()
329335

330336
#Add the various sub-projects
331337
add_subdirectory(libs)
338+
339+
# Only add warn flags for VPR internal libraries.
340+
add_compile_options(${WARN_FLAGS})
332341
add_subdirectory(vpr)
333342
add_subdirectory(abc)
334343
add_subdirectory(ODIN_II)

libs/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
#VTR developed libraries
1+
#Externally developed libraries
2+
add_subdirectory(EXTERNAL)
3+
4+
# VTR developed libraries
5+
# Only add warn flags for VPR internal libraries.
6+
add_compile_options(${WARN_FLAGS})
27
add_subdirectory(libarchfpga)
38
add_subdirectory(libvtrutil)
49
add_subdirectory(liblog)
510
add_subdirectory(libpugiutil)
611
add_subdirectory(librtlnumber)
7-
8-
#Externally developed libraries
9-
add_subdirectory(EXTERNAL)
12+
if(${VTR_ENABLE_CAPNPROTO})
13+
add_subdirectory(libvtrcapnproto)
14+
endif()

libs/EXTERNAL/CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,25 @@ add_subdirectory(libsdcparse)
88
add_subdirectory(libblifparse)
99
add_subdirectory(libtatum)
1010

11-
#VPR_USE_EZGL is initialized in the root CMakeLists.
11+
# Override default policy for capnproto and libezgl (CMake policy version 3.1)
12+
# Enable new IPO variables
13+
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
14+
15+
#VPR_USE_EZGL is initialized in the root CMakeLists.
1216
#compile libezgl only if the user asks for or has its dependencies installed.
1317
if(VPR_USE_EZGL STREQUAL "on")
1418
add_subdirectory(libezgl)
1519
endif()
20+
21+
if(${VTR_ENABLE_CAPNPROTO})
22+
# Enable option overrides via variables
23+
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
24+
25+
# Re-enable CXX extensions for capnproto.
26+
set(CMAKE_CXX_EXTENSIONS ON)
27+
28+
# Disable capnproto tests
29+
set(BUILD_TESTING OFF)
30+
31+
add_subdirectory(capnproto EXCLUDE_FROM_ALL)
32+
endif()

libs/libarchfpga/src/physical_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,10 @@ struct t_segment_inf {
12761276
//float Cmetal_per_m; /* Wire capacitance (per meter) */
12771277
};
12781278

1279+
inline bool operator==(const t_segment_inf& a, const t_segment_inf& b) {
1280+
return a.name == b.name && a.frequency == b.frequency && a.length == b.length && a.arch_wire_switch == b.arch_wire_switch && a.arch_opin_switch == b.arch_opin_switch && a.frac_cb == b.frac_cb && a.frac_sb == b.frac_sb && a.longline == b.longline && a.Rmetal == b.Rmetal && a.Cmetal == b.Cmetal && a.directionality == b.directionality && a.cb == b.cb && a.sb == b.sb;
1281+
}
1282+
12791283
enum class SwitchType {
12801284
MUX = 0, //A configurable (buffered) mux (single-driver)
12811285
TRISTATE, //A configurable tristate-able buffer (multi-driver)

libs/libvtrcapnproto/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
if(NOT MSCV)
2+
# These flags generate noisy but non-bug warnings when using lib kj,
3+
# supress them.
4+
set(WARN_FLAGS_TO_DISABLE
5+
-Wno-undef
6+
-Wno-non-virtual-dtor
7+
)
8+
foreach(flag ${WARN_FLAGS_TO_DISABLE})
9+
CHECK_CXX_COMPILER_FLAG(${flag} CXX_COMPILER_SUPPORTS_${flag})
10+
if(CXX_COMPILER_SUPPORTS_${flag})
11+
#Flag supported, so enable it
12+
add_compile_options(${flag})
13+
endif()
14+
endforeach()
15+
endif()
16+
17+
# Create generated headers from capnp schema files
18+
#
19+
# Each schema used should appear here.
20+
capnp_generate_cpp(CAPNP_SRCS CAPNP_HDRS
21+
place_delay_model.capnp
22+
connection_map.capnp
23+
matrix.capnp
24+
)
25+
26+
add_library(libvtrcapnproto STATIC
27+
${CAPNP_SRCS}
28+
mmap_file.h
29+
mmap_file.cpp
30+
serdes_utils.h
31+
serdes_utils.cpp
32+
)
33+
target_include_directories(libvtrcapnproto PUBLIC
34+
${CMAKE_CURRENT_SOURCE_DIR}
35+
${CMAKE_CURRENT_BINARY_DIR}
36+
)
37+
target_link_libraries(libvtrcapnproto
38+
libvtrutil
39+
CapnProto::capnp
40+
)

libs/libvtrcapnproto/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Capnproto usage in VTR
2+
======================
3+
4+
Capnproto is a data serialization framework designed for portabliity and speed.
5+
In VPR, capnproto is used to provide binary formats for internal data
6+
structures that can be computed once, and used many times. Specific examples:
7+
- rrgraph
8+
- Router lookahead data
9+
- Place matrix delay estimates
10+
11+
What is capnproto?
12+
==================
13+
14+
capnproto can be broken down into 3 parts:
15+
- A schema language
16+
- A code generator
17+
- A library
18+
19+
The schema language is used to define messages. Each message must have an
20+
explcit capnproto schema, which are stored in files suffixed with ".capnp".
21+
The capnproto documentation for how to write these schema files can be found
22+
here: https://capnproto.org/language.html
23+
24+
The schema by itself is not especially useful. In order to read and write
25+
messages defined by the schema in a target language (e.g. C++), a code
26+
generation step is required. Capnproto provides a cmake function for this
27+
purpose, `capnp_generate_cpp`. This generates C++ source and header files.
28+
These source and header files combined with the capnproto C++ library, enables
29+
C++ code to read and write the messages matching a particular schema. The C++
30+
library API can be found here: https://capnproto.org/cxx.html
31+
32+
Contents of libvtrcapnproto
33+
===========================
34+
35+
libvtrcapnproto should contain two elements:
36+
- Utilities for working capnproto messages in VTR
37+
- Generate source and header files of all capnproto messages used in VTR
38+
39+
I/O Utilities
40+
-------------
41+
42+
Capnproto does not provide IO support, instead it works from arrays (or file
43+
descriptors). To avoid re-writing this code, libvtrcapnproto provides two
44+
utilities that should be used whenever reading or writing capnproto message to
45+
disk:
46+
- `serdes_utils.h` provides the writeMessageToFile function - Writes a
47+
capnproto message to disk.
48+
- `mmap_file.h` provides MmapFile object - Maps a capnproto message from the
49+
disk as a flat array.
50+
51+
NdMatrix Utilities
52+
------------------
53+
54+
A common datatype which appears in many data structures that VPR might want to
55+
serialize is the generic type `vtr::NdMatrix`. `ndmatrix_serdes.h` provides
56+
generic functions ToNdMatrix and FromNdMatrix, which can be used to generically
57+
convert between the provideid capnproto message `Matrix` and `vtr::NdMatrix`.
58+
59+
Capnproto schemas
60+
-----------------
61+
62+
libvtrcapnproto should contain all capnproto schema definitions used within
63+
VTR. To add a new schema:
64+
1. Add the schema to git in `libs/libvtrcapnproto/`
65+
2. Add the schema file name to `capnp_generate_cpp` invocation in
66+
`libs/libvtrcapnproto/CMakeLists.txt`.
67+
68+
The schema will be available in the header file `schema filename>.h`. The
69+
actual header file will appear in the CMake build directory
70+
`libs/libvtrcapnproto` after `libvtrcapnproto` has been rebuilt.
71+
72+
Writing capnproto binary files to text
73+
======================================
74+
75+
The `capnp` tool (found in the CMake build directiory
76+
`libs/EXTERNAL/capnproto/c++/src/capnp`) can be used to convert from a binary
77+
capnp message to a textual form.
78+
79+
Example converting VprOverrideDelayModel from binary to text:
80+
81+
```
82+
capnp convert binary:text place_delay_model.capnp VprOverrideDelayModel \
83+
< place_delay.bin > place_delay.txt
84+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@0x876ec83c2fea5a18;
2+
3+
using Matrix = import "matrix.capnp";
4+
5+
struct VprCostEntry {
6+
delay @0 :Float32;
7+
congestion @1 :Float32;
8+
}
9+
10+
struct VprVector2D {
11+
x @0 :Int64;
12+
y @1 :Int64;
13+
}
14+
15+
struct VprCostMap {
16+
costMap @0 :Matrix.Matrix((Matrix.Matrix(VprCostEntry)));
17+
offset @1 :Matrix.Matrix(VprVector2D);
18+
segmentMap @2 :List(Int64);
19+
}

libs/libvtrcapnproto/matrix.capnp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@0xafffc9c1f309bc00;
2+
3+
struct Matrix(Value) {
4+
struct Entry {
5+
value @0 :Value;
6+
}
7+
dims @0 :List(Int64);
8+
data @1 :List(Entry);
9+
}

libs/libvtrcapnproto/mmap_file.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "mmap_file.h"
2+
#include "vtr_error.h"
3+
#include "vtr_util.h"
4+
5+
#include <fcntl.h>
6+
#include <sys/stat.h>
7+
#include <sys/mman.h>
8+
#include <unistd.h>
9+
10+
#include "kj/filesystem.h"
11+
12+
MmapFile::MmapFile(const std::string& file)
13+
: size_(0) {
14+
try {
15+
auto fs = kj::newDiskFilesystem();
16+
auto path = fs->getCurrentPath().evalNative(file);
17+
18+
const auto& dir = fs->getRoot();
19+
auto stat = dir.lstat(path);
20+
auto f = dir.openFile(path);
21+
size_ = stat.size;
22+
data_ = f->mmap(0, stat.size);
23+
} catch (kj::Exception& e) {
24+
throw vtr::VtrError(e.getDescription().cStr(), e.getFile(), e.getLine());
25+
}
26+
}
27+
28+
const kj::ArrayPtr<const ::capnp::word> MmapFile::getData() const {
29+
if ((size_ % sizeof(::capnp::word)) != 0) {
30+
throw vtr::VtrError(
31+
vtr::string_fmt("size_ %d is not a multiple of capnp::word", size_),
32+
__FILE__, __LINE__);
33+
}
34+
35+
return kj::arrayPtr(reinterpret_cast<const ::capnp::word*>(data_.begin()),
36+
size_ / sizeof(::capnp::word));
37+
}

libs/libvtrcapnproto/mmap_file.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef MMAP_FILE_H_
2+
#define MMAP_FILE_H_
3+
4+
#include <string>
5+
#include "capnp/message.h"
6+
#include "kj/array.h"
7+
8+
// Platform independent mmap, useful for reading large capnp's.
9+
class MmapFile {
10+
public:
11+
explicit MmapFile(const std::string& file);
12+
const kj::ArrayPtr<const ::capnp::word> getData() const;
13+
14+
private:
15+
size_t size_;
16+
kj::Array<const kj::byte> data_;
17+
};
18+
19+
#endif /* MMAP_FILE_H_ */

0 commit comments

Comments
 (0)