Skip to content

Commit

Permalink
[ESI Runtime] Incorporate RPC server into ESICppRuntime
Browse files Browse the repository at this point in the history
Since the gRPC server is now going to be used in multiple places AND the
RPC server now uses ports 'n' stuff from ESICppRuntime, it is
appropriate to move RpcServer into ESICppRuntime proper. This also
significantly simplifies the build.
  • Loading branch information
teqdruid committed Jun 26, 2024
1 parent bf7c4e7 commit 2dc0746
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 124 deletions.
2 changes: 0 additions & 2 deletions integration_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ llvm_canonicalize_cmake_booleans(ESI_RUNTIME)
if (ESI_RUNTIME)
list(APPEND CIRCT_INTEGRATION_TEST_DEPENDS
ESIRuntime
ESIPythonRuntime
esiquery
esitester
)

Expand Down
2 changes: 1 addition & 1 deletion integration_test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ config.iverilog_path = "@IVERILOG_PATH@"
config.clang_tidy_path = "@CLANG_TIDY_PATH@"
config.have_systemc = "@HAVE_SYSTEMC@"
config.esi_runtime = "@ESI_RUNTIME@"
config.esi_runtime_path = "@ESIRuntimePath@"
config.esi_runtime_path = "@ESICppRuntimePath@"
config.bindings_python_enabled = @CIRCT_BINDINGS_PYTHON_ENABLED@
config.bindings_tcl_enabled = @CIRCT_BINDINGS_TCL_ENABLED@
config.lec_enabled = "@CIRCT_LEC_ENABLED@"
Expand Down
28 changes: 19 additions & 9 deletions lib/Dialect/ESI/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,21 @@ if(ESI_COSIM)
find_package(gRPC REQUIRED CONFIG)
endif()

add_subdirectory(cosim)
add_subdirectory(cosim_dpi_server)
# Inform the runtime code that Cosimulation is enabled. Kinda hacky since all
# backends should only need to be linked in.
# TODO: Once the hack in the python bindings is remidied, remove this.
add_compile_definitions(ESI_COSIM)
set(ESICppRuntimeSources
${ESICppRuntimeSources}
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/backends/Cosim.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/backends/RpcServer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cosim.proto
)
set(ESICppRuntimeBackendHeaders
${ESICppRuntimeBackendHeaders}
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/backends/Cosim.h
)
set(ESICppRuntimeLinkLibraries
${ESICppRuntimeLinkLibraries}
EsiCosimGRPC
)
set(ESICppRuntimeIncludeDirs
${ESICppRuntimeIncludeDirs}
${CMAKE_CURRENT_SOURCE_DIR}/cosim/include
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/backends/RpcServer.h
)
else()
message("-- ESI cosim disabled")
Expand Down Expand Up @@ -198,6 +193,21 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(ESICppRuntime PRIVATE -Wno-covered-switch-default)
endif()

if(ESI_COSIM)
target_link_libraries(ESICppRuntime PUBLIC protobuf::libprotobuf gRPC::grpc++)
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
target_include_directories(ESICppRuntime PUBLIC "$<BUILD_INTERFACE:${PROTO_BINARY_DIR}>")
protobuf_generate(
TARGET ESICppRuntime
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
protobuf_generate(
TARGET ESICppRuntime
LANGUAGE grpc
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
PLUGIN "protoc-gen-grpc=\$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
endif()

# The esiquery tool is a simple wrapper around the SysInfo API.
add_executable(esiquery
${CMAKE_CURRENT_SOURCE_DIR}/cpp/tools/esiquery.cpp
Expand Down
File renamed without changes.
70 changes: 0 additions & 70 deletions lib/Dialect/ESI/runtime/cosim/CMakeLists.txt

This file was deleted.

8 changes: 0 additions & 8 deletions lib/Dialect/ESI/runtime/cosim/MtiPliStub/CMakeLists.txt

This file was deleted.

30 changes: 0 additions & 30 deletions lib/Dialect/ESI/runtime/cosim/cosim_dpi_server/CMakeLists.txt

This file was deleted.

75 changes: 75 additions & 0 deletions lib/Dialect/ESI/runtime/cosim_dpi_server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
##===- CMakeLists.txt - Core cosim DPI library ----------------*- cmake -*-===//
##
## Define the cosim DPI library if it's enabled.
##
##===----------------------------------------------------------------------===//

# Dummy library for a library which should be included by the RTL simulator.
# Dummy is necessary for linking purposes. NOT to be distributed.
add_library(MtiPli SHARED
DummySvDpi.cpp
)
set_target_properties(MtiPli PROPERTIES CXX_VISIBILITY_PRESET "default")

# DPI calls.
add_library(EsiCosimDpiServer SHARED
DpiEntryPoints.cpp
)
set_target_properties(EsiCosimDpiServer
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
CXX_VISIBILITY_PRESET "default"
)
add_dependencies(EsiCosimDpiServer ESICppRuntime MtiPli)
target_link_libraries(EsiCosimDpiServer
PUBLIC
ESICppRuntime
MtiPli
)

install(TARGETS EsiCosimDpiServer
DESTINATION lib
COMPONENT ESIRuntime
)

# RTL cosimulation collateral.
set(cosim_collateral
Cosim_DpiPkg.sv
Cosim_Endpoint.sv
Cosim_Manifest.sv
Cosim_MMIO.sv

driver.sv
driver.cpp
)

install(FILES
${cosim_collateral}
DESTINATION cosim
COMPONENT ESIRuntime
)

add_custom_target(esi-cosim
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/esi-cosim.py
${CIRCT_TOOLS_DIR}/esi-cosim.py)
foreach (cf ${cosim_collateral})
add_custom_command(TARGET esi-cosim POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/${cf}
${CIRCT_TOOLS_DIR}/../cosim/${cf}
)
endforeach()

# ESI simple cosim runner.
install(FILES
esi-cosim.py
DESTINATION bin
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
WORLD_EXECUTE WORLD_READ
COMPONENT ESIRuntime
)
set(ESI_COSIM_PATH $<TARGET_FILE:EsiCosimDpiServer>
CACHE PATH "Path to Cosim DPI shared library")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "dpi.h"
#include "esi/Ports.h"
#include "esi/cosim/RpcServer.h"
#include "esi/backends/RpcServer.h"

#include <algorithm>
#include <cassert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#undef EETERN
#define EETERN DPI_EXTERN DPI_DLLESPEC

#include "dpi/svdpi.h"
#include "svdpi.h"
#undef NDEBUG
#include <cassert>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef CIRCT_DIALECT_ESI_COSIM_DPI_H
#define CIRCT_DIALECT_ESI_COSIM_DPI_H

#include "dpi/svdpi.h"
#include "svdpi.h"

#ifdef WIN32
#define DPI extern "C" __declspec(dllexport)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace esi {
namespace cosim {

/// TODO: make this a proper backend (as much as possible).
class RpcServer {
public:
~RpcServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "esi/cosim/RpcServer.h"
#include "esi/backends/RpcServer.h"
#include "esi/Utils.h"

#include "cosim.grpc.pb.h"
Expand Down

0 comments on commit 2dc0746

Please sign in to comment.