From 37f809c5e9cd276e904dde7f5d070a370b65dd8f Mon Sep 17 00:00:00 2001 From: John Demme Date: Mon, 9 Nov 2020 11:15:02 -0800 Subject: [PATCH] [ESI] [Cosim DPI] Cap'nProto install and schema generation (#216) * [ESI] [Cosim DPI] Capn'Proto install and schema generation This is the second in a series to merge #213. This is the capnp schema generation component. * Added header comment. --- CMakeLists.txt | 3 ++ include/circt/Dialect/ESI/CMakeLists.txt | 2 + .../circt/Dialect/ESI/cosim/CMakeLists.txt | 9 ++++ .../circt/Dialect/ESI/cosim/CosimDpi.capnp | 44 +++++++++++++++++++ utils/get-capnp.sh | 18 ++++++++ 5 files changed, 76 insertions(+) create mode 100644 include/circt/Dialect/ESI/cosim/CMakeLists.txt create mode 100644 include/circt/Dialect/ESI/cosim/CosimDpi.capnp create mode 100755 utils/get-capnp.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 34328573a3..a8eccd1430 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,9 @@ add_custom_target(circt-headers) set_target_properties(circt-headers PROPERTIES FOLDER "Misc") add_custom_target(circt-doc) +set(ENV{PKG_CONFIG_PATH} + "${CMAKE_CURRENT_SOURCE_DIR}/ext/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") + list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") diff --git a/include/circt/Dialect/ESI/CMakeLists.txt b/include/circt/Dialect/ESI/CMakeLists.txt index 695ab4fa0e..174d629bf5 100644 --- a/include/circt/Dialect/ESI/CMakeLists.txt +++ b/include/circt/Dialect/ESI/CMakeLists.txt @@ -6,3 +6,5 @@ mlir_tablegen(ESIAttrs.h.inc -gen-struct-attr-decls) mlir_tablegen(ESIAttrs.cpp.inc -gen-struct-attr-defs) add_public_tablegen_target(MLIRESIEnumsIncGen) + +add_subdirectory(cosim) diff --git a/include/circt/Dialect/ESI/cosim/CMakeLists.txt b/include/circt/Dialect/ESI/cosim/CMakeLists.txt new file mode 100644 index 0000000000..a16f3b4b7b --- /dev/null +++ b/include/circt/Dialect/ESI/cosim/CMakeLists.txt @@ -0,0 +1,9 @@ +find_package(CapnProto CONFIG PATHS "${CMAKE_SOURCE_DIR}/ext") +if(CapnProto_FOUND) + option(ESI_COSIM "Enable ESI Cosimulation" ON) + message("-- Enabling ESI cosim") + add_definitions(${CAPNP_DEFINITIONS}) + capnp_generate_cpp(COSIM_CAPNP_SRCS COSIM_CANPN_HDRS CosimDpi.capnp) + add_library(EsiCosimCapnp ${COSIM_CAPNP_HDRS} ${COSIM_CAPNP_SRCS}) + target_link_libraries(EsiCosimCapnp PRIVATE CapnProto::capnp) +endif() diff --git a/include/circt/Dialect/ESI/cosim/CosimDpi.capnp b/include/circt/Dialect/ESI/cosim/CosimDpi.capnp new file mode 100644 index 0000000000..9a1d6c943b --- /dev/null +++ b/include/circt/Dialect/ESI/cosim/CosimDpi.capnp @@ -0,0 +1,44 @@ +##===- CosimDpi.capnp - ESI cosim RPC schema ------------------*- CAPNP -*-===// +## +## The ESI cosimulation RPC Cap'nProto schema. Documentation is in +## docs/ESI/cosim.md. TL;DR: Run the simulation, then connect to its RPC server +## with a client generated by the Cap'nProto implementation for your language of +## choice! (https://capnproto.org/otherlang.html) +## +##===----------------------------------------------------------------------===// + +@0xe642127a31681ef6; + +# The primary interface exposed by an ESI cosim simulation. +interface CosimDpiServer { + # List all the registered endpoints. + list @0 () -> (ifaces :List(EsiDpiInterfaceDesc)); + # Open one of them. Specify both the send and recv data types if want type + # safety and your language supports it. + open @1 [S, T] (iface :EsiDpiInterfaceDesc) -> (iface :EsiDpiEndpoint(S, T)); +} + +# Description of a registered endpoint. +struct EsiDpiInterfaceDesc { + # Capn'Proto ID of the struct type being sent _to_ the simulator. + sendTypeID @0 :UInt64; + # Capn'Proto ID of the struct type being sent _from_ the simulator. + recvTypeID @1 :UInt64; + # Numerical identifier of the endpoint. Defined in the design. + endpointID @2 :Int32; +} + +# Interactions with an open endpoint. Optionally typed. +interface EsiDpiEndpoint(SendMsgType, RecvMsgType) { + # Send a message to the endpoint. + send @0 (msg :SendMsgType); + # Recieve a message from the endpoint. Non-blocking. + recv @1 (block :Bool = true) -> (hasData :Bool, resp :RecvMsgType); + # Close the connect to this endpoint. + close @2 (); +} + +# A struct for untyped access to an endpoint. +struct UntypedData @0xac6e64291027d47a { + data @0 :Data; +} diff --git a/utils/get-capnp.sh b/utils/get-capnp.sh new file mode 100755 index 0000000000..3858d46877 --- /dev/null +++ b/utils/get-capnp.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Downloads, compiles, and installs CapnProto into $/ext + +EXT_DIR=$(cd "$(dirname "$BASH_SOURCE[0]")/../ext" && pwd) +CAPNP_VER=0f1bf4fce79923fb4974aa55a53e26450f83f286 + +echo $EXT_DIR +cd $EXT_DIR + +git clone https://github.com/capnproto/capnproto.git +cd capnproto +git checkout $CAPNP_VER +cd c++ +autoreconf -i +./configure --prefix=$EXT_DIR +make -j$(nprocs) +make install +cd ../../