From a390f10b61926df0da891a56567e01bd0f9e6033 Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Fri, 22 Nov 2024 18:18:34 -0800 Subject: [PATCH] Enable packaging Signed-off-by: Victor Chang --- .../grpc_endoscopy_tool_tracking/README.md | 6 ++ .../cpp/CMakeLists.txt | 16 ++++++ .../cpp/cloud/app_cloud_main.cpp | 16 ++++-- .../cpp/cloud/app_cloud_pipeline.hpp | 6 +- .../cpp/cloud/grpc_service.hpp | 4 +- .../cpp/endoscopy_tool_tracking.yaml | 7 +++ .../cpp/package-app.sh | 56 +++++++++++++++++++ cmake/grpc_generate_cpp.cmake | 5 +- operators/grpc_operators/CMakeLists.txt | 4 ++ 9 files changed, 110 insertions(+), 10 deletions(-) create mode 100755 applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/package-app.sh diff --git a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/README.md b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/README.md index 3093c860c..1aa7c44e6 100644 --- a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/README.md +++ b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/README.md @@ -145,3 +145,9 @@ The following launch profiles are available: [error] [program.cpp:614] Event notification 2 for entity [video_in__outgoing_requests] with id [33] received in an unexpected state [Origin] ``` + +## Containerize the application + +To containerize the application using [Holoscan CLI](https://docs.nvidia.com/holoscan/sdk-user-guide/cli/cli.html), first build the application using `./dev_container build_and_install grpc_endoscopy_tool_tracking`, run the `package-app.sh` script in the [cpp](./cpp/package-app.sh) directory and then follow the generated output to package and run the application. + +Refer to the [Packaging Holoscan Applications](https://docs.nvidia.com/holoscan/sdk-user-guide/holoscan_packager.html) section of the [Holoscan User Guide](https://docs.nvidia.com/holoscan/sdk-user-guide/) to learn more about installing the Holoscan CLI or packaging your application using Holoscan CLI. diff --git a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/CMakeLists.txt b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/CMakeLists.txt index d60975c50..36894b9a0 100644 --- a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/CMakeLists.txt +++ b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/CMakeLists.txt @@ -80,3 +80,19 @@ if(HOLOHUB_DOWNLOAD_DATASETS) ) add_dependencies(grpc_endoscopy_tool_tracking_edge endoscopy_data) endif() + +# Install application and dependencies into the install/ directory for packaging +install( + TARGETS grpc_endoscopy_tool_tracking_edge + DESTINATION bin/grpc_endoscopy_tool_tracking/cpp +) + +install( + TARGETS grpc_endoscopy_tool_tracking_cloud + DESTINATION bin/grpc_endoscopy_tool_tracking/cpp +) + +install( + FILES endoscopy_tool_tracking.yaml + DESTINATION bin/grpc_endoscopy_tool_tracking/cpp +) diff --git a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/app_cloud_main.cpp b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/app_cloud_main.cpp index f9cb51959..aebeb6672 100644 --- a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/app_cloud_main.cpp +++ b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/app_cloud_main.cpp @@ -71,13 +71,19 @@ void signal_handler(int signum) { } /** Helper function to parse benchmarking setting from the configuration file */ -void parse_config(const std::string& config_path, bool& benchmarking) { +void parse_config(const std::string& config_path, bool& benchmarking, + bool& enable_health_check_service) { auto config = holoscan::Config(config_path); auto& yaml_nodes = config.yaml_nodes(); for (const auto& yaml_node : yaml_nodes) { try { auto application = yaml_node["application"]; - if (application.IsMap()) { benchmarking = application["benchmarking"].as(); } + if (application.IsMap()) { + benchmarking = application["benchmarking"].as(); + enable_health_check_service = application["grpc_health_check"].as(); + } else { + HOLOSCAN_LOG_ERROR("Error parsing configuration file, 'application' is not a map"); + } } catch (std::exception& e) { HOLOSCAN_LOG_ERROR("Error parsing configuration file: {}", e.what()); benchmarking = false; @@ -143,10 +149,12 @@ int main(int argc, char** argv) { } bool benchmarking = false; - parse_config(config_path, benchmarking); + bool enable_health_check_service = false; + parse_config(config_path, benchmarking, enable_health_check_service); // Register each gRPC service with a Holoscan application: - // - the callback function (create_application_instance_func) is used to create a new instance of + // - the callback function (create_application_instance_func) is used to create a new instance + // of // the application when a new RPC call is received. ApplicationFactory::get_instance()->register_application( "EntityStream", diff --git a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/app_cloud_pipeline.hpp b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/app_cloud_pipeline.hpp index c08026bba..6041cc94a 100644 --- a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/app_cloud_pipeline.hpp +++ b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/app_cloud_pipeline.hpp @@ -15,8 +15,8 @@ * limitations under the License. */ -#ifndef GRPC_H264_ENDOSCOPY_TOOL_TRACKING_CPP_CLOUD_APP_CLOUD_PIPELINE_HPP -#define GRPC_H264_ENDOSCOPY_TOOL_TRACKING_CPP_CLOUD_APP_CLOUD_PIPELINE_HPP +#ifndef GRPC_GRPC_ENDOSCOPY_TOOL_TRACKING_CPP_CLOUD_APP_CLOUD_PIPELINE_HPP +#define GRPC_GRPC_ENDOSCOPY_TOOL_TRACKING_CPP_CLOUD_APP_CLOUD_PIPELINE_HPP #include #include @@ -108,4 +108,4 @@ class AppCloudPipeline : public HoloscanGrpcApplication { } }; } // namespace holohub::grpc_h264_endoscopy_tool_tracking -#endif /* GRPC_H264_ENDOSCOPY_TOOL_TRACKING_CPP_CLOUD_APP_CLOUD_PIPELINE_HPP */ +#endif /* GRPC_GRPC_ENDOSCOPY_TOOL_TRACKING_CPP_CLOUD_APP_CLOUD_PIPELINE_HPP */ diff --git a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/grpc_service.hpp b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/grpc_service.hpp index 552797527..9edb1bbc0 100644 --- a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/grpc_service.hpp +++ b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/cloud/grpc_service.hpp @@ -57,8 +57,8 @@ class GrpcService { return instance; } - void start() { - grpc::EnableDefaultHealthCheckService(true); + void start(bool enable_health_check_service = true) { + grpc::EnableDefaultHealthCheckService(enable_health_check_service); grpc::reflection::InitProtoReflectionServerBuilderPlugin(); service_ = std::make_unique( diff --git a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/endoscopy_tool_tracking.yaml b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/endoscopy_tool_tracking.yaml index 2909fd6c3..5d09898ab 100644 --- a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/endoscopy_tool_tracking.yaml +++ b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/endoscopy_tool_tracking.yaml @@ -24,7 +24,14 @@ application: outputFormats: ["screen"] multifragment: false # default: false, true to run in multi-fragment mode, false otherwise benchmarking: false # default: false, true to enable Data Flow Benchmarking, false otherwise + grpc_health_check: false # default: false, true to enable gRPC health check, false otherwise +resources: + cpu: 1 + gpu: 1 + memory: 1Gi + gpuMemory: 1Gi + replayer: basename: "surgical_video" frame_rate: 0 # as specified in timestamps diff --git a/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/package-app.sh b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/package-app.sh new file mode 100755 index 000000000..f42c8c9cf --- /dev/null +++ b/applications/distributed/grpc/grpc_endoscopy_tool_tracking/cpp/package-app.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -e + +GIT_ROOT=$(readlink -f ./$(git rev-parse --show-cdup)) +APP_PATH="$GIT_ROOT/install/bin/grpc_endoscopy_tool_tracking/cpp" + +. $GIT_ROOT/utilities/bash_utils.sh + +if [ ! -d $APP_PATH ]; then + print_error "Please build the gRPC Endoscopy Tool Tracking application first with the following command:" + print_error "./dev_container build_and_install grpc_endoscopy_tool_tracking" + exit -1 +fi + +PLATFORM=x64-workstation +GPU=$(get_host_gpu) +if [ $(get_host_arch) == "aarch64" ]; then + PLATFORM=igx-orin-devkit +fi + +echo -e "Copying the required files to the application directory..." +# cp -rf "$GIT_ROOT/install/lib/." "$APP_PATH" +# cp -rf "$GIT_ROOT/install/lib/gxf_extensions/." "$APP_PATH" +sed -i 's|../../../../../lib/gxf_extensions/||' "$APP_PATH/endoscopy_tool_tracking.yaml" +echo -e "done\n" + +echo -e Install Holoscan CLI and then use the following commands to package and run the Endoscopy Tool Tracking application: +echo -e "==========Package the application==========" +echo -e "Cloud:" +echo -e "${YELLOW}holoscan package -c $APP_PATH/endoscopy_tool_tracking.yaml --platform [igx-orin-devkit | jetson-agx-orin-devkit | sbsa, x64-workstation] --platform-config [igpu | dgpu] -t holohub-grpc-endoscopy-tool-tracking-cloud $APP_PATH/grpc_endoscopy_tool_tracking_cloud --include onnx holoviz$ --add $GIT_ROOT/install/lib${NOCOLOR}" +echo -e "\nFor example:" +echo -e "${YELLOW}holoscan package -c $APP_PATH/endoscopy_tool_tracking.yaml --platform ${PLATFORM} --platform-config ${GPU} -t holohub-grpc-endoscopy-tool-tracking-cloud $APP_PATH/grpc_endoscopy_tool_tracking_cloud --include onnx holoviz --add $GIT_ROOT/install/lib${NOCOLOR}" +echo -e "\nEdge:" +echo -e "${YELLOW}holoscan package -c $APP_PATH/endoscopy_tool_tracking.yaml --platform [igx-orin-devkit | jetson-agx-orin-devkit | sbsa, x64-workstation] --platform-config [igpu | dgpu] -t holohub-grpc-endoscopy-tool-tracking-edge $APP_PATH/grpc_endoscopy_tool_tracking_edge --include onnx holoviz --add $GIT_ROOT/install/lib${NOCOLOR}" +echo -e "\nFor example:" +echo -e "${YELLOW}holoscan package -c $APP_PATH/endoscopy_tool_tracking.yaml --platform ${PLATFORM} --platform-config ${GPU} -t holohub-grpc-endoscopy-tool-tracking-edge $APP_PATH/grpc_endoscopy_tool_tracking_edge --include onnx holoviz --add $GIT_ROOT/install/lib${NOCOLOR}" +echo -e "\n\n==========Run the application==========" +echo -e "Cloud:" +echo -e "${YELLOW}holoscan run -r \$(docker images | grep "holohub-grpc-endoscopy-tool-tracking-cloud" | awk '{print \$1\":\"\$2}') -i $GIT_ROOT/data/endoscopy${NOCOLOR}" +echo -e "\nEdge:" +echo -e "${YELLOW}holoscan run -r \$(docker images | grep "holohub-grpc-endoscopy-tool-tracking-edge" | awk '{print \$1\":\"\$2}') -i $GIT_ROOT/data/endoscopy${NOCOLOR}" +echo -e "\n\nRefer to Packaging Holoscan Applications (https://docs.nvidia.com/holoscan/sdk-user-guide/holoscan_packager.html) in the User Guide for more information." diff --git a/cmake/grpc_generate_cpp.cmake b/cmake/grpc_generate_cpp.cmake index e090c8230..061ba512d 100644 --- a/cmake/grpc_generate_cpp.cmake +++ b/cmake/grpc_generate_cpp.cmake @@ -78,7 +78,10 @@ function(grpc_generate_cpp SRCS HDRS INCLUDE_DIRS) endfunction() include(FetchContent) -set(ABSL_ENABLE_INSTALL ON) +# set(ABSL_ENABLE_INSTALL OFF) +# set(gRPC_INSTALL OFF) +# set(protobuf_INSTALL OFF) +# set(CARES_INSTALL OFF) FetchContent_Declare( grpc GIT_REPOSITORY https://github.com/grpc/grpc.git diff --git a/operators/grpc_operators/CMakeLists.txt b/operators/grpc_operators/CMakeLists.txt index 2c79405f0..3bc00dc3f 100644 --- a/operators/grpc_operators/CMakeLists.txt +++ b/operators/grpc_operators/CMakeLists.txt @@ -56,3 +56,7 @@ target_include_directories(grpc_operators ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) + +# Installation +install(TARGETS grpc_operators) +