Skip to content

Commit 08e754b

Browse files
committed
implement server functionality as a module which could be disabled during the build. new cpp macro NO_SERVER, move server init logic to separate call vpr_init_server
1 parent f2f47b1 commit 08e754b

17 files changed

+103
-50
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ set(VPR_USE_EZGL "auto" CACHE STRING "Specify whether vpr uses the graphics libr
3939
set_property(CACHE VPR_USE_EZGL PROPERTY STRINGS auto off on)
4040
option(VTR_ENABLE_CAPNPROTO "Enable capnproto binary serialization support in VPR." ON)
4141

42+
#Allow the user to decide whether to compile the server module
43+
option(VPR_USE_SERVER "Specify whether vpr enables the server mode" ON)
44+
4245
#Allow the user to enable/disable VPR analytic placement
4346
#VPR option --enable_analytic_placer is also required for Analytic Placement
4447
option(VPR_ANALYTIC_PLACE "Enable analytic placement in VPR." ON)

libs/EXTERNAL/CMakeLists.txt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ add_subdirectory(libtatum)
1111
add_subdirectory(libcatch2)
1212
#add_subdirectory(parmys)
1313

14-
#sockpp
15-
set(SOCKPP_BUILD_SHARED OFF CACHE BOOL "Override default value" FORCE)
16-
set(SOCKPP_BUILD_STATIC ON CACHE BOOL "Override default value" FORCE)
17-
add_subdirectory(sockpp)
14+
#VPR_USE_SERVER is initialized in the root CMakeLists
15+
#compile sockpp only if server mode is enabled
16+
if (VPR_USE_SERVER)
17+
set(SOCKPP_BUILD_SHARED OFF CACHE BOOL "Override default value" FORCE)
18+
set(SOCKPP_BUILD_STATIC ON CACHE BOOL "Override default value" FORCE)
19+
add_subdirectory(sockpp)
20+
endif()
1821

1922
#VPR_USE_EZGL is initialized in the root CMakeLists.
2023
#compile libezgl only if the user asks for or has its dependencies installed.
@@ -138,9 +141,11 @@ target_include_directories(Catch2
138141
)
139142

140143
# Some sockpp headers generate warnings, so treat them as system headers to suppress warnings
141-
target_include_directories(sockpp-static
142-
SYSTEM
143-
PUBLIC
144-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sockpp/include>
145-
$<INSTALL_INTERFACE:include>
146-
)
144+
if (VPR_USE_SERVER)
145+
target_include_directories(sockpp-static
146+
SYSTEM
147+
PUBLIC
148+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sockpp/include>
149+
$<INSTALL_INTERFACE:include>
150+
)
151+
endif()

vpr/CMakeLists.txt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ else()
3232
message(STATUS "EZGL: graphics disabled")
3333
endif()
3434

35+
36+
#Handle server setup
37+
set(SERVER_DEFINES "")
38+
39+
set(SERVER_DISABILED_REASON "")
40+
if (VPR_USE_SERVER)
41+
if (VPR_USE_EZGL STREQUAL "off")
42+
set(SERVER_DISABILED_REASON ", due to EZGL beign disabled")
43+
set(VPR_USE_SERVER OFF)
44+
endif()
45+
endif()
46+
47+
if (VPR_USE_SERVER)
48+
message(STATUS "Server mode is enabled")
49+
else()
50+
list(APPEND SERVER_DEFINES "-DNO_SERVER")
51+
message(STATUS "Server mode is disabled${SERVER_DISABILED_REASON}")
52+
endif()
53+
3554
#
3655
# Build Configuration
3756
#
@@ -85,10 +104,15 @@ target_link_libraries(libvpr
85104
libargparse
86105
libpugixml
87106
librrgraph
88-
sockpp-static
89-
-lz
90107
)
91108

109+
if(VPR_USE_SERVER)
110+
target_link_libraries(libvpr
111+
sockpp-static
112+
-lz
113+
)
114+
endif()
115+
92116
#link graphics library only when graphics set to on
93117
if (VPR_USE_EZGL STREQUAL "on")
94118
target_link_libraries(libvpr
@@ -125,7 +149,7 @@ if (VPR_USE_EZGL STREQUAL "on")
125149

126150
endif()
127151

128-
target_compile_definitions(libvpr PUBLIC ${GRAPHICS_DEFINES})
152+
target_compile_definitions(libvpr PUBLIC ${GRAPHICS_DEFINES} ${SERVER_DEFINES})
129153

130154
if(${VTR_ENABLE_CAPNPROTO})
131155
target_link_libraries(libvpr libvtrcapnproto)

vpr/src/base/read_options.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,7 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
28802880
.default_value("vpr_noc_placement_output.txt")
28812881
.show_in(argparse::ShowIn::HELP_ONLY);
28822882

2883+
#ifndef NO_SERVER
28832884
auto& server_grp = parser.add_argument_group("server options");
28842885

28852886
server_grp.add_argument<bool, ParseOnOff>(args.is_server_mode_enabled, "--server")
@@ -2892,6 +2893,7 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
28922893
.help("Server port number.")
28932894
.default_value("60555")
28942895
.show_in(argparse::ShowIn::HELP_ONLY);
2896+
#endif /* NO_SERVER */
28952897

28962898
return parser;
28972899
}

vpr/src/base/vpr_api.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
# include <tbb/global_control.h>
103103
#endif
104104

105+
#ifndef NO_SERVER
106+
#include "gateio.h"
107+
#include "serverupdate.h"
108+
#endif /* NO_SERVER */
109+
105110
/* Local subroutines */
106111
static void free_complex_block_types();
107112

@@ -388,6 +393,7 @@ bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) {
388393

389394
// TODO: Placer still assumes that cluster net list is used - graphics can not work with flat routing yet
390395
vpr_init_graphics(vpr_setup, arch, false);
396+
vpr_init_server(vpr_setup);
391397
{ //Place
392398
const auto& placement_net_list = (const Netlist<>&)g_vpr_ctx.clustering().clb_nlist;
393399
bool place_success = vpr_place_flow(placement_net_list, vpr_setup, arch);
@@ -1046,11 +1052,25 @@ void vpr_init_graphics(const t_vpr_setup& vpr_setup, const t_arch& arch, bool is
10461052
/* Startup X graphics */
10471053
init_graphics_state(vpr_setup.ShowGraphics, vpr_setup.GraphPause,
10481054
vpr_setup.RouterOpts.route_type, vpr_setup.SaveGraphics,
1049-
vpr_setup.GraphicsCommands, is_flat, vpr_setup.ServerOpts.is_server_mode_enabled, vpr_setup.ServerOpts.port_num);
1055+
vpr_setup.GraphicsCommands, is_flat);
10501056
if (vpr_setup.ShowGraphics || vpr_setup.SaveGraphics || !vpr_setup.GraphicsCommands.empty())
10511057
alloc_draw_structs(&arch);
10521058
}
10531059

1060+
void vpr_init_server(const t_vpr_setup& vpr_setup)
1061+
{
1062+
#ifndef NO_SERVER
1063+
if (vpr_setup.ServerOpts.is_server_mode_enabled) {
1064+
/* Set up a server and its callback to be triggered at 100ms intervals by the timer's timeout event. */
1065+
server::GateIO& gate_io = g_vpr_ctx.mutable_server().mutable_gateIO();
1066+
if (!gate_io.isRunning()) {
1067+
gate_io.start(vpr_setup.ServerOpts.port_num);
1068+
g_timeout_add(/*interval_ms*/ 100, server::update, &application);
1069+
}
1070+
}
1071+
#endif /* NO_SERVER */
1072+
}
1073+
10541074
void vpr_close_graphics(const t_vpr_setup& /*vpr_setup*/) {
10551075
/* Close down X Display */
10561076
free_draw_structs();

vpr/src/base/vpr_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ void vpr_create_device_grid(const t_vpr_setup& vpr_setup, const t_arch& Arch);
139139
void vpr_create_rr_graph(t_vpr_setup& vpr_setup, const t_arch& arch, int chan_width, bool is_flat);
140140

141141
void vpr_init_graphics(const t_vpr_setup& vpr_setup, const t_arch& arch, bool is_flat);
142+
void vpr_init_server(const t_vpr_setup& vpr_setup);
143+
142144
void vpr_close_graphics(const t_vpr_setup& vpr_setup);
143145

144146
void vpr_setup_clock_networks(t_vpr_setup& vpr_setup, const t_arch& Arch);

vpr/src/base/vpr_context.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ struct NocContext : public Context {
553553
std::unique_ptr<NocRouting> noc_flows_router;
554554
};
555555

556-
#ifndef NO_GRAPHICS
556+
#ifndef NO_SERVER
557557
/**
558558
* @brief State relating to server mode
559559
*
@@ -623,7 +623,7 @@ class ServerContext : public Context {
623623

624624
bool draw_crit_path_contour_ = false;
625625
};
626-
#endif /* NO_GRAPHICS */
626+
#endif /* NO_SERVER */
627627

628628
/**
629629
* @brief This object encapsulates VPR's state.
@@ -708,10 +708,10 @@ class VprContext : public Context {
708708
const PackingMultithreadingContext& packing_multithreading() const { return packing_multithreading_; }
709709
PackingMultithreadingContext& mutable_packing_multithreading() { return packing_multithreading_; }
710710

711-
#ifndef NO_GRAPHICS
711+
#ifndef NO_SERVER
712712
const ServerContext& server() const { return server_; }
713713
ServerContext& mutable_server() { return server_; }
714-
#endif /* NO_GRAPHICS */
714+
#endif /* NO_SERVER */
715715

716716
private:
717717
DeviceContext device_;
@@ -729,9 +729,9 @@ class VprContext : public Context {
729729
FloorplanningContext constraints_;
730730
NocContext noc_;
731731

732-
#ifndef NO_GRAPHICS
732+
#ifndef NO_SERVER
733733
ServerContext server_;
734-
#endif /* NO_GRAPHICS */
734+
#endif /* NO_SERVER */
735735

736736
PackingMultithreadingContext packing_multithreading_;
737737
};

vpr/src/draw/draw.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@
7979

8080
#ifndef NO_GRAPHICS
8181

82-
#include "gateio.h"
83-
#include "serverupdate.h"
84-
8582
//To process key presses we need the X11 keysym definitions,
8683
//which are unavailable when building with MINGW
8784
# if defined(X11) && !defined(__MINGW32__)
@@ -184,9 +181,7 @@ void init_graphics_state(bool show_graphics_val,
184181
enum e_route_type route_type,
185182
bool save_graphics,
186183
std::string graphics_commands,
187-
bool is_flat,
188-
bool enable_server,
189-
int port_num) {
184+
bool is_flat) {
190185
#ifndef NO_GRAPHICS
191186
/* Call accessor functions to retrieve global variables. */
192187
t_draw_state* draw_state = get_draw_state_vars();
@@ -201,15 +196,6 @@ void init_graphics_state(bool show_graphics_val,
201196
draw_state->save_graphics = save_graphics;
202197
draw_state->graphics_commands = graphics_commands;
203198
draw_state->is_flat = is_flat;
204-
205-
if (enable_server) {
206-
/* Set up a server and its callback to be triggered at 100ms intervals by the timer's timeout event. */
207-
server::GateIO& gate_io = g_vpr_ctx.mutable_server().mutable_gateIO();
208-
if (!gate_io.isRunning()) {
209-
gate_io.start(port_num);
210-
g_timeout_add(/*interval_ms*/ 100, server::update, &application);
211-
}
212-
}
213199
#else
214200
//Suppress unused parameter warnings
215201
(void)show_graphics_val;
@@ -218,8 +204,6 @@ void init_graphics_state(bool show_graphics_val,
218204
(void)save_graphics;
219205
(void)graphics_commands;
220206
(void)is_flat;
221-
(void)enable_server;
222-
(void)port_num;
223207
#endif // NO_GRAPHICS
224208
}
225209

@@ -269,12 +253,16 @@ static void draw_main_canvas(ezgl::renderer* g) {
269253

270254
draw_placement_macros(g);
271255

256+
#ifndef NO_SERVER
272257
if (g_vpr_ctx.server().gateIO().isRunning()) {
273258
const ServerContext& server_ctx = g_vpr_ctx.server(); // shortcut
274259
draw_crit_path_elements(server_ctx.crit_paths(), server_ctx.crit_path_element_indexes(), g);
275260
} else {
276261
draw_crit_path(g);
277262
}
263+
#else
264+
draw_crit_path(g);
265+
#endif /* NO_SERVER */
278266

279267
draw_logical_connections(g);
280268

vpr/src/draw/draw.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ void init_graphics_state(bool show_graphics_val,
5656
enum e_route_type route_type,
5757
bool save_graphics,
5858
std::string graphics_commands,
59-
bool is_flat,
60-
bool server,
61-
int port_num);
59+
bool is_flat);
6260

6361
/* Allocates the structures needed to draw the placement and routing.*/
6462
void alloc_draw_structs(const t_arch* arch);

vpr/src/draw/draw_basic.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,7 @@ void draw_crit_path(ezgl::renderer* g) {
11111111
*/
11121112
void draw_crit_path_elements(const std::vector<tatum::TimingPath>& paths, const std::map<std::size_t, std::set<std::size_t>>& indexes, ezgl::renderer* g)
11131113
{
1114+
#ifndef NO_SERVER
11141115
t_draw_state* draw_state = get_draw_state_vars();
11151116
static ezgl::color contour_color{0,0,0,40};
11161117
const bool draw_crit_path_contour = g_vpr_ctx.server().draw_crit_path_contour();
@@ -1182,6 +1183,7 @@ void draw_crit_path_elements(const std::vector<tatum::TimingPath>& paths, const
11821183
}
11831184
}
11841185
}
1186+
#endif /* NO_SERVER */
11851187
}
11861188

11871189
int get_timing_path_node_layer_num(tatum::NodeId node) {

vpr/src/server/gateio.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "gateio.h"
2+
3+
#ifndef NO_SERVER
4+
25
#include "telegramparser.h"
36
#include "telegrambuffer.h"
47
#include "commconstants.h"
@@ -259,3 +262,5 @@ void GateIO::printLogs()
259262
}
260263

261264
} // namespace server
265+
266+
#endif /* NO_SERVER */

vpr/src/server/gateio.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef GATEIO_H
22
#define GATEIO_H
33

4+
#ifndef NO_SERVER
5+
46
#include "task.h"
57

68
#include <chrono>
@@ -197,5 +199,7 @@ class GateIO
197199

198200
} // namespace server
199201

202+
#endif /* NO_SERVER */
203+
200204
#endif /* GATEIO_H */
201205

vpr/src/server/serverupdate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef NO_GRAPHICS
1+
#ifndef NO_SERVER
22

33
#include "serverupdate.h"
44
#include "gateio.h"
@@ -41,4 +41,4 @@ gboolean update(gpointer data) {
4141

4242
} // namespace server
4343

44-
#endif // NO_GRAPHICS
44+
#endif // NO_SERVER

vpr/src/server/serverupdate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SERVERUPDATE_H
22
#define SERVERUPDATE_H
33

4-
#ifndef NO_GRAPHICS
4+
#ifndef NO_SERVER
55

66
#include <glib.h>
77

@@ -18,6 +18,6 @@ gboolean update(gpointer);
1818

1919
} // namespace server
2020

21-
#endif /* NO_GRAPHICS */
21+
#endif /* NO_SERVER */
2222

2323
#endif /* SERVERUPDATE_H */

vpr/src/server/taskresolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef NO_GRAPHICS
1+
#ifndef NO_SERVER
22

33
#include "taskresolver.h"
44

@@ -166,4 +166,4 @@ void TaskResolver::processDrawCriticalPathTask(ezgl::application* app, const Tas
166166

167167
} // namespace server
168168

169-
#endif /* NO_GRAPHICS */
169+
#endif /* NO_SERVER */

vpr/src/server/taskresolver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef NO_GRAPHICS
1+
#ifndef NO_SERVER
22

33
#ifndef TASKRESOLVER_H
44
#define TASKRESOLVER_H
@@ -52,4 +52,4 @@ class TaskResolver {
5252

5353
#endif /* TASKRESOLVER_H */
5454

55-
#endif /* NO_GRAPHICS */
55+
#endif /* NO_SERVER */

0 commit comments

Comments
 (0)