From dbacfc2d6a9487db79a88e1edb7faa76d82d4875 Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Wed, 4 Nov 2020 11:29:19 -0500 Subject: [PATCH] Add a CMake option to build RDC library only When RDC are only used as the libraries, the user can choose not to build the rdci and rdcd, which will remove the dependencies to the gRPC and protoc. The -DBUILD_STANDALONE=off should be pass to the cmake. * Change README.md for the instructions. * Move the python_binding installation from client/CMakeLists.txt to CMakeLists.txt so that the RDC library only build will also install the folder. * Change CMakeLists.txt and rdc_libs/CMakeLists.txt to build with gRPC only if the BUILD_STANDALONE is enabled. Change-Id: If9cfe9fc298a83636d85fe352a311fe2fe041661 [ROCm/rdc commit: 105675aeeb1a1ab22f4d90c2e6e3857e5891412a] --- projects/rdc/CMakeLists.txt | 100 ++++++++++++++++----------- projects/rdc/README.md | 6 ++ projects/rdc/client/CMakeLists.txt | 3 - projects/rdc/rdc_libs/CMakeLists.txt | 72 ++++++++++--------- 4 files changed, 107 insertions(+), 74 deletions(-) diff --git a/projects/rdc/CMakeLists.txt b/projects/rdc/CMakeLists.txt index eff71d1207..31beca4dd1 100755 --- a/projects/rdc/CMakeLists.txt +++ b/projects/rdc/CMakeLists.txt @@ -26,6 +26,11 @@ cmake_minimum_required(VERSION 3.5.0) # ROCM_DIR should be passed in via command line; these will be used # in sub-projects set(RSMI_INC_DIR ${ROCM_DIR}/rocm_smi/include) + +# When cmake -DBUILD_STANDALONE=off, it will not build rdcd and rdci +# which requires the gRPC +option(BUILD_STANDALONE "Build targets for rdci and rdcd" ON) + set(RSMI_LIB_DIR ${ROCM_DIR}/rocm_smi/lib) if (NOT DEFINED GRPC_ROOT) @@ -83,7 +88,9 @@ project(${RDC}) set(RDC_SRC_ROOT "${PROJECT_SOURCE_DIR}") message("Build Configuration:") -message("-----------GRPC ROOT: " ${GRPC_ROOT}) +if(BUILD_STANDALONE) + message("-----------GRPC ROOT: " ${GRPC_ROOT}) +endif() message("-----------ROCM_DIR : " ${ROCM_DIR}) # Create a configure file to get version info from within library @@ -110,42 +117,43 @@ endif() ## Verbose output. set(CMAKE_VERBOSE_MAKEFILE on) +if(BUILD_STANDALONE) + # Compile .proto files + file(GLOB PROTOB_DEF_SRC_FILES "protos/*.proto") + set(PROTOB_SRC_DIR "${PROJECT_SOURCE_DIR}/protos") + set(PROTOB_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}") + set(PROTOB_CMD "${GRPC_ROOT}/bin/protoc") + set(GRPC_PLUGIN "${GRPC_ROOT}/bin/grpc_cpp_plugin") + set(GRPC_LIB_DIR "${GRPC_ROOT}/lib") -# Compile .proto files -file(GLOB PROTOB_DEF_SRC_FILES "protos/*.proto") -set(PROTOB_SRC_DIR "${PROJECT_SOURCE_DIR}/protos") -set(PROTOB_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}") -set(PROTOB_CMD "${GRPC_ROOT}/bin/protoc") -set(GRPC_PLUGIN "${GRPC_ROOT}/bin/grpc_cpp_plugin") -set(GRPC_LIB_DIR "${GRPC_ROOT}/lib") + set(ENV{LD_LIBRARY_PATH} ${GRPC_LIB_DIR}:${GRPC_LIB_DIR}64) + foreach(file ${PROTOB_DEF_SRC_FILES}) + execute_process(COMMAND + ${PROTOB_CMD} --proto_path=${PROTOB_SRC_DIR} + --cpp_out=${PROTOB_OUT_DIR} ${file} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + RESULT_VARIABLE PROTOB_RESULT + OUTPUT_VARIABLE PROTOB_OUT_VAR) + message("protoc command returned: ${PROTOB_RESULT}") -set(ENV{LD_LIBRARY_PATH} ${GRPC_LIB_DIR}:${GRPC_LIB_DIR}64) -foreach(file ${PROTOB_DEF_SRC_FILES}) - execute_process(COMMAND - ${PROTOB_CMD} --proto_path=${PROTOB_SRC_DIR} - --cpp_out=${PROTOB_OUT_DIR} ${file} - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - RESULT_VARIABLE PROTOB_RESULT - OUTPUT_VARIABLE PROTOB_OUT_VAR) - message("protoc command returned: ${PROTOB_RESULT}") + # find_program (GRPC_PLUGIN NAMES grpc_cpp_plugin) + message("GRPC_PLUGIN=${GRPC_PLUGIN})") + message("protoc cmd:") + message(" $ ${PROTOB_CMD} --proto_path=${PROTOB_SRC_DIR}") + message(" --grpc_out=${PROTOB_OUT_DIR}") + message("....--plugin=\"${GRPC_PLUGIN}\" ${file}") -# find_program (GRPC_PLUGIN NAMES grpc_cpp_plugin) - message("GRPC_PLUGIN=${GRPC_PLUGIN})") - message("protoc cmd:") - message(" $ ${PROTOB_CMD} --proto_path=${PROTOB_SRC_DIR}") - message(" --grpc_out=${PROTOB_OUT_DIR}") - message("....--plugin=\"${GRPC_PLUGIN}\" ${file}") + execute_process(COMMAND + ${PROTOB_CMD} --proto_path=${PROTOB_SRC_DIR} + --grpc_out=${PROTOB_OUT_DIR} + --plugin=protoc-gen-grpc=${GRPC_PLUGIN} ${file} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + RESULT_VARIABLE PROTOB_RESULT + OUTPUT_VARIABLE PROTOB_OUT_VAR) + message("protoc command returned: ${PROTOB_RESULT}") - execute_process(COMMAND - ${PROTOB_CMD} --proto_path=${PROTOB_SRC_DIR} - --grpc_out=${PROTOB_OUT_DIR} - --plugin=protoc-gen-grpc=${GRPC_PLUGIN} ${file} - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - RESULT_VARIABLE PROTOB_RESULT - OUTPUT_VARIABLE PROTOB_OUT_VAR) - message("protoc command returned: ${PROTOB_RESULT}") - -endforeach() + endforeach() +endif() set(CMAKE_INSTALL_PREFIX ${RDC_SERVER_ROOT_PATH} CACHE STRING "Default installation directory.") @@ -157,16 +165,28 @@ set(CPACK_PACKAGING_INSTALL_PREFIX ${RDC_SERVER_ROOT_PATH} set(SERVER_COMPONENT "server") set(CLIENT_COMPONENT "client") -install(DIRECTORY ${GRPC_ROOT} - USE_SOURCE_PERMISSIONS - DESTINATION ${RDC_CLIENT_INSTALL_PREFIX} - COMPONENT ${SERVER_COMPONENT}) +# Standalone only folders +if(BUILD_STANDALONE) + install(DIRECTORY ${GRPC_ROOT}/lib + USE_SOURCE_PERMISSIONS + DESTINATION usr + FILES_MATCHING PATTERN "libgrpc*") -add_subdirectory("server") -add_subdirectory("client") + add_subdirectory("server") + add_subdirectory("client") + add_subdirectory("rdci") +endif() + +# Folders for both standalone and embedded add_subdirectory("rdc_libs") add_subdirectory("example") -add_subdirectory("rdci") +install(DIRECTORY ${PROJECT_SOURCE_DIR}/python_binding + DESTINATION ${RDC_CLIENT_INSTALL_PREFIX}/${RDC} + COMPONENT ${CLIENT_COMPONENT}) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/example + DESTINATION ${RDC_CLIENT_INSTALL_PREFIX}/${RDC} + COMPONENT ${CLIENT_COMPONENT}) + set(CPACK_PACKAGE_NAME ${RDC_PACKAGE}) set(CPACK_PACKAGE_VERSION ${VERSION_STRING}) diff --git a/projects/rdc/README.md b/projects/rdc/README.md index c88f3b4961..a314584a03 100644 --- a/projects/rdc/README.md +++ b/projects/rdc/README.md @@ -69,6 +69,12 @@ Clone the RDC source code from GitHub and use CMake to build and install $ make $ make install ## default installation location is /opt/rocm +## Building RDC library only without gRPC (optional) + +If only the RDC libraries are needed (i.e. only "embedded mode" is required), the user can choose to not build rdci and rdcd. This will eliminate the need for gRPC and protoc. To build in this way, -DBUILD_STANDALONE=off should be passed on the the cmake command line: + + $ cmake -DROCM_DIR=/opt/rocm -DBUILD_STANDALONE=off <-DCMAKE_INSTALL_PREFIX=> .. + ## Update System Library Path The following commands need to be executed as root (sudo). It may be easiest to put them into a script and then run that script as root: diff --git a/projects/rdc/client/CMakeLists.txt b/projects/rdc/client/CMakeLists.txt index b3f4db2d2d..66cec04f06 100755 --- a/projects/rdc/client/CMakeLists.txt +++ b/projects/rdc/client/CMakeLists.txt @@ -164,9 +164,6 @@ install(TARGETS ${CLIENT_LIB} install(DIRECTORY ${SOURCE_DIR}/authentication DESTINATION ${RDC_CLIENT_INSTALL_PREFIX}/${RDC} COMPONENT ${CLIENT_COMPONENT}) -install(DIRECTORY ${SOURCE_DIR}/python_binding - DESTINATION ${RDC_CLIENT_INSTALL_PREFIX}/${RDC} - COMPONENT ${CLIENT_COMPONENT}) # Generate Doxygen documentation for client api manual find_package(Doxygen) diff --git a/projects/rdc/rdc_libs/CMakeLists.txt b/projects/rdc/rdc_libs/CMakeLists.txt index b2a3852238..f4f7f82d80 100755 --- a/projects/rdc/rdc_libs/CMakeLists.txt +++ b/projects/rdc/rdc_libs/CMakeLists.txt @@ -189,39 +189,40 @@ set_property(TARGET ${RDC_LIB} PROPERTY set_property(TARGET ${RDC_LIB} PROPERTY VERSION "${SO_VERSION_STRING}") -# librdc_client.so set up -file(GLOB PROTOBUF_GENERATED_INCLUDES "${PROTOB_OUT_DIR}/*.h") -file(GLOB PROTOBUF_GENERATED_SRCS "${PROTOB_OUT_DIR}/*.cc") +if(BUILD_STANDALONE) + # librdc_client.so set up + file(GLOB PROTOBUF_GENERATED_INCLUDES "${PROTOB_OUT_DIR}/*.h") + file(GLOB PROTOBUF_GENERATED_SRCS "${PROTOB_OUT_DIR}/*.cc") -set(RDCCLIENT_LIB "rdc_client") -set(RDCCLIENT_LIB_COMPONENT "lib${RDCCLIENT_LIB}") -set(RDCCLIENT_LIB_SRC_LIST "${SRC_DIR}/rdc_client/src/RdcStandaloneHandler.cc") -set(RDCCLIENT_LIB_SRC_LIST ${RDCCLIENT_LIB_SRC_LIST} "${PROTOBUF_GENERATED_SRCS}") + set(RDCCLIENT_LIB "rdc_client") + set(RDCCLIENT_LIB_COMPONENT "lib${RDCCLIENT_LIB}") + set(RDCCLIENT_LIB_SRC_LIST "${SRC_DIR}/rdc_client/src/RdcStandaloneHandler.cc") + set(RDCCLIENT_LIB_SRC_LIST ${RDCCLIENT_LIB_SRC_LIST} "${PROTOBUF_GENERATED_SRCS}") -set(RDCCLIENT_LIB_INC_LIST "${RDC_LIB_INC_DIR}/rdc/rdc.h") -set(BRDCCLIENT_LIB_INC_LIST ${RDCCLIENT_LIB_INC_LIST} "${RDC_LIB_INC_DIR}/rdc_lib/rdc_common.h") -set(RDCCLIENT_LIB_INC_LIST ${RDCCLIENT_LIB_INC_LIST} "${RDC_LIB_INC_DIR}/rdc_lib/RdcHandler.h") -set(RDCCLIENT_LIB_INC_LIST ${RDCCLIENT_LIB_INC_LIST} "${RDC_LIB_INC_DIR}/rdc_lib/impl/RdcStandaloneHandler.h") + set(RDCCLIENT_LIB_INC_LIST "${RDC_LIB_INC_DIR}/rdc/rdc.h") + set(BRDCCLIENT_LIB_INC_LIST ${RDCCLIENT_LIB_INC_LIST} "${RDC_LIB_INC_DIR}/rdc_lib/rdc_common.h") + set(RDCCLIENT_LIB_INC_LIST ${RDCCLIENT_LIB_INC_LIST} "${RDC_LIB_INC_DIR}/rdc_lib/RdcHandler.h") + set(RDCCLIENT_LIB_INC_LIST ${RDCCLIENT_LIB_INC_LIST} "${RDC_LIB_INC_DIR}/rdc_lib/impl/RdcStandaloneHandler.h") -message("RDCCLIENT_LIB_INC_LIST=${RDCCLIENT_LIB_INC_LIST}") + message("RDCCLIENT_LIB_INC_LIST=${RDCCLIENT_LIB_INC_LIST}") -add_library(${RDCCLIENT_LIB} SHARED ${RDCCLIENT_LIB_SRC_LIST} ${RDCCLIENT_LIB_INC_LIST}) -target_link_libraries(${RDCCLIENT_LIB} ${BOOTSTRAP_LIB} pthread rt grpc grpc++ grpc++_reflection + add_library(${RDCCLIENT_LIB} SHARED ${RDCCLIENT_LIB_SRC_LIST} ${RDCCLIENT_LIB_INC_LIST}) + target_link_libraries(${RDCCLIENT_LIB} ${BOOTSTRAP_LIB} pthread rt grpc grpc++ grpc++_reflection dl protobuf) -target_include_directories(${RDCCLIENT_LIB} PRIVATE - "${GRPC_ROOT}/include" - "${PROJECT_SOURCE_DIR}" - "${PROJECT_SOURCE_DIR}/include" - "${PROTOB_OUT_DIR}" - "${CMAKE_CURRENT_SOURCE_DIR}/include") - -# TODO: set the properties for the library once we have one -## Set the VERSION and SOVERSION values -set_property(TARGET ${RDCCLIENT_LIB} PROPERTY - SOVERSION "${VERSION_MAJOR}") -set_property(TARGET ${RDCCLIENT_LIB} PROPERTY - VERSION "${SO_VERSION_STRING}") + target_include_directories(${RDCCLIENT_LIB} PRIVATE + "${GRPC_ROOT}/include" + "${PROJECT_SOURCE_DIR}" + "${PROJECT_SOURCE_DIR}/include" + "${PROTOB_OUT_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/include") + # TODO: set the properties for the library once we have one + ## Set the VERSION and SOVERSION values + set_property(TARGET ${RDCCLIENT_LIB} PROPERTY + SOVERSION "${VERSION_MAJOR}") + set_property(TARGET ${RDCCLIENT_LIB} PROPERTY + VERSION "${SO_VERSION_STRING}") +endif() ## If the library is a release, strip the target library if ("${CMAKE_BUILD_TYPE}" STREQUAL Release) @@ -231,15 +232,24 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL Release) add_custom_command( TARGET ${RDC_LIB} POST_BUILD COMMAND ${CMAKE_STRIP} lib${RDC_LIB}.so) - add_custom_command( - TARGET ${RDCCLIENT_LIB} - POST_BUILD COMMAND ${CMAKE_STRIP} lib${RDCCLIENT_LIB}.so) + if(BUILD_STANDALONE) + add_custom_command( + TARGET ${RDCCLIENT_LIB} + POST_BUILD COMMAND ${CMAKE_STRIP} lib${RDCCLIENT_LIB}.so) + endif() endif () ## Add the install directives for the runtime library. -install(TARGETS ${BOOTSTRAP_LIB} ${RDC_LIB} ${RDCCLIENT_LIB} +if(BUILD_STANDALONE) + install(TARGETS ${BOOTSTRAP_LIB} ${RDC_LIB} ${RDCCLIENT_LIB} LIBRARY DESTINATION ${RDC_CLIENT_INSTALL_PREFIX}/${RDC}/lib COMPONENT ${CLIENT_COMPONENT}) +else() + install(TARGETS ${BOOTSTRAP_LIB} ${RDC_LIB} + LIBRARY DESTINATION ${RDC_CLIENT_INSTALL_PREFIX}/${RDC}/lib + COMPONENT ${CLIENT_COMPONENT}) +endif() + install(FILES ${SOURCE_DIR}/include/rdc/rdc.h DESTINATION ${RDC_CLIENT_INSTALL_PREFIX}/${RDC}/include/rdc COMPONENT ${CLIENT_COMPONENT})