Skip to content

Commit

Permalink
[ESI][Runtime] Python wheel now provides cpp support (#7001)
Browse files Browse the repository at this point in the history
Wheel install now contains C++ headers, cmake file, and python func for
cmake location.
  • Loading branch information
teqdruid authored May 13, 2024
1 parent 4a240b9 commit 474fc3f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
65 changes: 50 additions & 15 deletions lib/Dialect/ESI/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,31 @@ FetchContent_Declare(json
)
FetchContent_MakeAvailable(json)

include_directories(cpp/include)

set(ESIRuntimeSources
cpp/lib/Accelerator.cpp
cpp/lib/Context.cpp
cpp/lib/Common.cpp
cpp/lib/Design.cpp
cpp/lib/Manifest.cpp
cpp/lib/Services.cpp
cpp/lib/Ports.cpp
cpp/lib/Utils.cpp

cpp/lib/backends/Trace.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/Accelerator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/Context.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/Common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/Design.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/Manifest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/Services.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/Ports.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/Utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/backends/Trace.cpp
)
set(ESIRuntimeHeaders
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/Utils.h
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/Accelerator.h
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/Common.h
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/Context.h
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/Design.h
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/Manifest.h
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/Types.h
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/Ports.h
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/Services.h
)
set(ESIRuntimeBackendHeaders
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/backends/Trace.h
)
set(ESIRuntimeLinkLibraries
ZLIB::ZLIB
Expand Down Expand Up @@ -104,7 +116,11 @@ if(ESI_COSIM)

set(ESIRuntimeSources
${ESIRuntimeSources}
cpp/lib/backends/Cosim.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/backends/Cosim.cpp
)
set(ESIRuntimeBackendHeaders
${ESIRuntimeBackendHeaders}
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/backends/Cosim.h
)
set(ESIRuntimeLinkLibraries
${ESIRuntimeLinkLibraries}
Expand All @@ -124,7 +140,11 @@ if (XRT_PATH)

set(ESIRuntimeSources
${ESIRuntimeSources}
cpp/lib/backends/Xrt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/backends/Xrt.cpp
)
set(ESIRuntimeBackendHeaders
${ESIRuntimeBackendHeaders}
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/backends/Xrt.h
)
set(ESIRuntimeIncludeDirs
${ESIRuntimeIncludeDirs}
Expand Down Expand Up @@ -155,6 +175,8 @@ endif()
add_library(ESIRuntime SHARED
${ESIRuntimeSources}
)
target_include_directories(ESIRuntime PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include)
target_link_libraries(ESIRuntime PRIVATE ${ESIRuntimeLinkLibraries})
target_include_directories(ESIRuntime PRIVATE ${ESIRuntimeIncludeDirs})
target_compile_options(ESIRuntime PRIVATE ${ESIRuntimeCxxFlags})
Expand All @@ -175,14 +197,26 @@ install(RUNTIME_DEPENDENCY_SET ESIRuntime_RUNTIME_DEPS
PRE_INCLUDE_REGEXES capnp kj
COMPONENT ESIRuntime
)
install(FILES ${ESIRuntimeHeaders}
DESTINATION include/esi
COMPONENT ESIRuntime
)
install(FILES ${ESIRuntimeBackendHeaders}
DESTINATION include/esi/backends
COMPONENT ESIRuntime
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/cmake/esiaccel.cmake
DESTINATION cmake
COMPONENT ESIRuntime
)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(ESIRuntime PRIVATE -Wno-covered-switch-default)
endif()

# The esiquery tool is a simple wrapper around the SysInfo API.
add_executable(esiquery
cpp/tools/esiquery.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/tools/esiquery.cpp
)
target_link_libraries(esiquery PRIVATE ESIRuntime)
install(TARGETS esiquery
Expand Down Expand Up @@ -235,7 +269,8 @@ if(Python3_FOUND)
endif()
else()
# Compile Pybind11 module and copy to the correct python directory.
pybind11_add_module(esiCppAccel python/esiaccel/esiCppAccel.cpp)
pybind11_add_module(esiCppAccel
${CMAKE_CURRENT_SOURCE_DIR}/python/esiaccel/esiCppAccel.cpp)
target_link_libraries(esiCppAccel PRIVATE ESIRuntime)

if (WHEEL_BUILD)
Expand Down
7 changes: 7 additions & 0 deletions lib/Dialect/ESI/runtime/cosim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ install(FILES
COMPONENT ESIRuntime
)

# Cap'nProto MUST be built with exceptions enabled.
if (MSVC)
target_compile_options(EsiCosimCapnp PRIVATE /EHsc)
else()
target_compile_options(EsiCosimCapnp PRIVATE -fexceptions)
endif()

include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
add_subdirectory(cosim_dpi_server)
add_subdirectory(MtiPliStub)
12 changes: 12 additions & 0 deletions lib/Dialect/ESI/runtime/cpp/cmake/esiaccel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function(add_esiaccel_flags TARGET)
message("-- Adding ESI runtime flags to target ${TARGET}")
target_include_directories(${TARGET}
PUBLIC
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../include"
)
file(GLOB ESI_LIBS ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../lib/*)
target_link_libraries(${TARGET}
PUBLIC
${ESI_LIBS}
)
endfunction()
5 changes: 5 additions & 0 deletions lib/Dialect/ESI/runtime/python/esiaccel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ def run_esi_cosim():
cosim_import = importlib.util.module_from_spec(spec)
spec.loader.exec_module(cosim_import)
return cosim_import.__main__(sys.argv)


def get_cpp_cmake() -> str:
"""Return the path to the cmake file."""
return str(_thisdir / "cmake" / "esiaccel.cmake")

0 comments on commit 474fc3f

Please sign in to comment.