Skip to content

Commit

Permalink
WIP: Updarting RabbitMQ stage
Browse files Browse the repository at this point in the history
  • Loading branch information
dagardner-nv committed Jan 3, 2024
1 parent 276922a commit c9a7257
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/rabbitmq_cpp_stage/_version.py export-subst
122 changes: 83 additions & 39 deletions examples/developer_guide/4_rabbitmq_cpp_stage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,103 @@
# See the License for the specific language governing permissions and
# limitations under the License.

list(APPEND CMAKE_MESSAGE_CONTEXT "morpheus_rabbit")
list(APPEND CMAKE_MESSAGE_CONTEXT "4_rabbitmq_cpp_stage")

cmake_minimum_required(VERSION 3.24 FATAL_ERROR)

# Set the cache to be the same to allow for CCache to be used effectively
set(MORPHEUS_CACHE_DIR "${CMAKE_SOURCE_DIR}/.cache" CACHE PATH "Directory to contain all CPM and CCache data")
mark_as_advanced(MORPHEUS_CACHE_DIR)

# Add the Conda environment to the prefix path and add the CMake files
list(PREPEND CMAKE_PREFIX_PATH "$ENV{CONDA_PREFIX}")
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../external/utilities/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(Python3_FIND_VIRTUALENV "FIRST")
set(Python3_FIND_STRATEGY "LOCATION")
find_package(Python3 REQUIRED COMPONENTS Development Interpreter NumPy)
include(morpheus_utils/load)

include(cmake/dependencies.cmake)
project(4_rabbitmq_cpp_stage
VERSION 24.03.00
LANGUAGES C CXX
)

pybind11_add_module(morpheus_rabbit MODULE "${CMAKE_CURRENT_SOURCE_DIR}/_lib/rabbitmq_source.cpp")
set(CMAKE_CXX_STANDARD 20)

add_library(${PROJECT_NAME}::morpheus_rabbit ALIAS morpheus_rabbit)
morpheus_utils_initialize_cpm(MORPHEUS_CACHE_DIR)

target_link_libraries(morpheus_rabbit
PUBLIC
morpheus
rabbitmq
SimpleAmqpClient
mrc::pymrc
)
# Ensure CPM is initialized
rapids_cpm_init()

# Set the option prefix to match the outer project before including. Must be before find_package(morpheus)
set(OPTION_PREFIX "MORPHEUS")

morpheus_utils_python_configure()
include(cmake/dependencies.cmake)

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

target_include_directories(morpheus_rabbit
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${MORPHEUS_ROOT}/morpheus/_lib/include>
rabbitmq
${SimpleAmqpClient_SOURCE_DIR}/src
morpheus_utils_create_python_package(morpheus_rabbit
PROJECT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src"
)

set_target_properties(morpheus_rabbit PROPERTIES CXX_VISIBILITY_PRESET hidden)
add_subdirectory(src/rabbitmq_cpp_stage/_lib)

# Complete the python package
if(MORPHEUS_PYTHON_INPLACE_BUILD)
set_target_properties(morpheus_rabbit
PROPERTIES
INSTALL_RPATH "${PROJECT_SOURCE_DIR}/morpheus/_lib"
)
else()
# TODO: https://github.com/nv-morpheus/Morpheus/issues/331
set_target_properties(morpheus_rabbit
PROPERTIES
INSTALL_RPATH "${Python3_SITELIB}/morpheus/_lib"
)
list(APPEND extra_args "IS_INPLACE")
endif()

morpheus_utils_inplace_build_copy(morpheus_rabbit "${CMAKE_CURRENT_SOURCE_DIR}/_lib")
if(TARGET morpheus-package-install)
list(APPEND extra_args "PYTHON_DEPENDENCIES" "morpheus-package-install")
endif()

message(STATUS " Install dest: (morpheus_rabbit) ${CMAKE_CURRENT_BINARY_DIR}/_lib")
install(
TARGETS
morpheus_rabbit
LIBRARY DESTINATION
"${CMAKE_CURRENT_BINARY_DIR}/_lib"
)
morpheus_utils_build_python_package(morpheus_rabbit ${extra_args})

# -----------
# pybind11_add_module(morpheus_rabbit MODULE "${CMAKE_CURRENT_SOURCE_DIR}/_lib/rabbitmq_source.cpp")

# add_library(${PROJECT_NAME}::morpheus_rabbit ALIAS morpheus_rabbit)

# target_link_libraries(morpheus_rabbit
# PUBLIC
# morpheus
# rabbitmq
# SimpleAmqpClient
# mrc::pymrc
# )

# target_include_directories(morpheus_rabbit
# PUBLIC
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
# $<BUILD_INTERFACE:${MORPHEUS_ROOT}/morpheus/_lib/include>
# rabbitmq
# ${SimpleAmqpClient_SOURCE_DIR}/src
# )

# set_target_properties(morpheus_rabbit PROPERTIES CXX_VISIBILITY_PRESET hidden)

# if(MORPHEUS_PYTHON_INPLACE_BUILD)
# set_target_properties(morpheus_rabbit
# PROPERTIES
# INSTALL_RPATH "${PROJECT_SOURCE_DIR}/morpheus/_lib"
# )
# else()
# # TODO: https://github.com/nv-morpheus/Morpheus/issues/331
# set_target_properties(morpheus_rabbit
# PROPERTIES
# INSTALL_RPATH "${Python3_SITELIB}/morpheus/_lib"
# )
# endif()

# morpheus_utils_inplace_build_copy(morpheus_rabbit "${CMAKE_CURRENT_SOURCE_DIR}/_lib")

# message(STATUS " Install dest: (morpheus_rabbit) ${CMAKE_CURRENT_BINARY_DIR}/_lib")
# install(
# TARGETS
# morpheus_rabbit
# LIBRARY DESTINATION
# "${CMAKE_CURRENT_BINARY_DIR}/_lib"
# )
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
2 changes: 2 additions & 0 deletions examples/developer_guide/4_rabbitmq_cpp_stage/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include src/rabbitmq_cpp_stage/_version.py
recursive-include src *.so *.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

list(APPEND CMAKE_MESSAGE_CONTEXT "dep")

rapids_find_package(morpheus REQUIRED)
rapids_find_package(CUDAToolkit REQUIRED)

set(RABBITMQ_VERSION "0.12.0" CACHE STRING "Version of RabbitMQ-C to use")
include(Configure_rabbitmq)

Expand Down
31 changes: 31 additions & 0 deletions examples/developer_guide/4_rabbitmq_cpp_stage/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2021-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 -x
set -e

# Optionally can set INSTALL_PREFIX to build and install to a specific directory. Also causes cmake install to run
BUILD_DIR=${BUILD_DIR:-"build"}

echo "Runing CMake configure..."
cmake -B ${BUILD_DIR} -GNinja \
-DCMAKE_MESSAGE_CONTEXT_SHOW=ON \
-DMORPHEUS_PYTHON_INPLACE_BUILD:BOOL=ON \
-DMORPHEUS_PYTHON_PERFORM_INSTALL:BOOL=ON `# Ensure all of the libraries are installed` \
${CMAKE_CONFIGURE_EXTRA_ARGS:+CMAKE_CONFIGURE_EXTRA_ARGS} .

echo "Running CMake build..."
cmake --build ${BUILD_DIR} -j "$@"
33 changes: 33 additions & 0 deletions examples/developer_guide/4_rabbitmq_cpp_stage/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.

[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools", "wheel", "versioneer[toml]==0.29"]

[tool.versioneer]
# See the docstring in versioneer.py for instructions. Note that you must
# re-run 'versioneer.py setup' after changing this section, and commit the
# resulting files.
VCS = "git"
style = "pep440"
tag_prefix = "v"
versionfile_build = "src/rabbitmq_cpp_stage/_version.py"
versionfile_source = "src/rabbitmq_cpp_stage/_version.py"

[tool.yapfignore]
ignore_patterns = [
"**/_version.py",
]
35 changes: 35 additions & 0 deletions examples/developer_guide/4_rabbitmq_cpp_stage/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SPDX-FileCopyrightText: Copyright (c) 2023-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.

[metadata]
name = rabbitmq_cpp_stage
version = attr: versioneer.get_version
description = Morpheus Example - RabbitMQ C++ Stage
author = NVIDIA Corporation
license = Apache
classifiers =
Intended Audience :: Developers
Programming Language :: Python
Programming Language :: Python :: 3.10

[options]
zip_safe = False
include_package_data = True
packages = find:
package_dir =
=src

[options.packages.find]
where = src
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SPDX-FileCopyrightText: Copyright (c) 2022-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.

list(APPEND CMAKE_MESSAGE_CONTEXT "rabbitmq_cpp_stage")

morpheus_add_pybind11_module(rabbitmq_cpp_stage
SOURCE_FILES
"rabbitmq_source.cpp"
INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
${SimpleAmqpClient_SOURCE_DIR}/src
LINK_TARGETS
morpheus
mrc::pymrc
rabbitmq
SimpleAmqpClient
)

list(POP_BACK CMAKE_MESSAGE_CONTEXT)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import annotations
import src.rabbitmq_cpp_stage._lib.rabbitmq_cpp_stage
import typing
import datetime
import morpheus._lib.messages
import mrc.core.segment

__all__ = [
"RabbitMQSourceStage"
]


class RabbitMQSourceStage(mrc.core.segment.SegmentObject):
def __init__(self, builder: mrc.core.segment.Builder, name: str, host: str, exchange: str, exchange_type: str = 'fanout', queue_name: str = '', poll_interval: datetime.timedelta = datetime.timedelta(microseconds=100000)) -> None: ...
pass
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ std::shared_ptr<mrc::segment::Object<RabbitMQSourceStage>> RabbitMQSourceStageIn
namespace py = pybind11;

// Define the pybind11 module m.
PYBIND11_MODULE(morpheus_rabbit, m)
PYBIND11_MODULE(rabbitmq_cpp_stage, m)
{
mrc::pymrc::import(m, "morpheus._lib.messages");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ def compute_schema(self, schema: StageSchema):
def _build_source(self, builder: mrc.Builder) -> mrc.SegmentObject:
if self._build_cpp_node():
# pylint: disable=c-extension-no-member,no-name-in-module
from _lib import morpheus_rabbit as morpheus_rabbit_cpp

node = morpheus_rabbit_cpp.RabbitMQSourceStage(builder,
self.unique_name,
self._host,
self._exchange,
self._exchange_type,
self._queue_name,
self._poll_interval.to_pytimedelta())
from ._lib import rabbitmq_cpp_stage

node = rabbitmq_cpp_stage.RabbitMQSourceStage(builder,
self.unique_name,
self._host,
self._exchange,
self._exchange_type,
self._queue_name,
self._poll_interval.to_pytimedelta())
else:
self.connect()
node = builder.make_source(self.unique_name, self.source_generator)
Expand Down

0 comments on commit c9a7257

Please sign in to comment.