Skip to content

Commit

Permalink
Avoid copy of source data in AddClassificationsStage and FilterDetect…
Browse files Browse the repository at this point in the history
…ionsStage (nv-morpheus#730)

* Adds two new overloads of `MatxUtil::threshold`
* Reduces the amount of code in both stages.
* `MemoryDescriptor` is no longer an empty struct, and now contains the cuda stream and memory resource.
* `DevMemInfo` now holds a `MemoryDescriptor` and a `void*` no longer requiring access to the `rmm::device_buffer`
* `MatxUtil::create_seg_ids` now receives a `MemoryDescriptor`

Previously we would take a copy of the source tensor and source cudf column because `MatxUtil::threshold` wanted an `rmm::device_buffer`.

fixes nv-morpheus#728

Authors:
  - David Gardner (https://github.com/dagardner-nv)
  - Michael Demoret (https://github.com/mdemoret-nv)

Approvers:
  - Christopher Harris (https://github.com/cwharris)
  - Michael Demoret (https://github.com/mdemoret-nv)

URL: nv-morpheus#730
  • Loading branch information
dagardner-nv authored Mar 22, 2023
1 parent 24bce9f commit 043919a
Show file tree
Hide file tree
Showing 30 changed files with 762 additions and 240 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ if(MORPHEUS_ENABLE_DEBUG_INFO)

morpheus_utils_print_target_properties(
TARGETS
cuda_utils
common
messages
morpheus
morpheus_utils
stages
messages
common
WRITE_TO_FILE
)

Expand Down
4 changes: 2 additions & 2 deletions morpheus/_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ list(APPEND CMAKE_MESSAGE_CONTEXT "_lib")
########### morpheus ###########
set(MORPHEUS_LIB_ROOT ${CMAKE_CURRENT_SOURCE_DIR})

#----------cuda_utils---------
include(cmake/libraries/cuda_utils.cmake)
#----------morpheus_utils---------
include(cmake/libraries/morpheus_utils.cmake)

#----------cudf_helpers---------
include(cmake/libraries/cudf_helpers.cmake)
Expand Down
95 changes: 0 additions & 95 deletions morpheus/_lib/cmake/libraries/cuda_utils.cmake

This file was deleted.

4 changes: 3 additions & 1 deletion morpheus/_lib/cmake/libraries/cudf_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ morpheus_add_cython_library(
PYX_FILE
"${MORPHEUS_LIB_ROOT}/cudf_helpers.pyx"
LINK_TARGETS
cuda_utils
morpheus_utils
Python::Module
Python::NumPy
OUTPUT_TARGET
cudf_helpers_target
)
Expand Down
82 changes: 68 additions & 14 deletions morpheus/_lib/cmake/libraries/morpheus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,38 @@

message(STATUS "Adding library: morpheus")

include(GenerateExportHeader)

# Place the two cuda sources in their own target and disable IWYU for that target.
add_library(cuda_objs
OBJECT
${MORPHEUS_LIB_ROOT}/src/utilities/matx_util.cu
)

set_target_properties(
cuda_objs
PROPERTIES
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
C_INCLUDE_WHAT_YOU_USE ""
CXX_INCLUDE_WHAT_YOU_USE ""
EXPORT_COMPILE_COMMANDS OFF
)

target_include_directories(cuda_objs
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)

target_link_libraries(cuda_objs
PUBLIC
cudf::cudf
matx::matx
)


add_library(morpheus
# Keep these sorted!
${MORPHEUS_LIB_ROOT}/src/io/deserializers.cpp
Expand All @@ -32,11 +64,17 @@ add_library(morpheus
${MORPHEUS_LIB_ROOT}/src/messages/multi_response.cpp
${MORPHEUS_LIB_ROOT}/src/messages/multi_tensor.cpp
${MORPHEUS_LIB_ROOT}/src/messages/multi.cpp
${MORPHEUS_LIB_ROOT}/src/objects/data_table.cpp
${MORPHEUS_LIB_ROOT}/src/objects/dev_mem_info.cpp
${MORPHEUS_LIB_ROOT}/src/objects/dtype.cpp
${MORPHEUS_LIB_ROOT}/src/objects/fiber_queue.cpp
${MORPHEUS_LIB_ROOT}/src/objects/file_types.cpp
${MORPHEUS_LIB_ROOT}/src/objects/memory_descriptor.cpp
${MORPHEUS_LIB_ROOT}/src/objects/mutable_table_ctx_mgr.cpp
${MORPHEUS_LIB_ROOT}/src/objects/python_data_table.cpp
${MORPHEUS_LIB_ROOT}/src/objects/rmm_tensor.cpp
${MORPHEUS_LIB_ROOT}/src/objects/table_info.cpp
${MORPHEUS_LIB_ROOT}/src/objects/tensor_object.cpp
${MORPHEUS_LIB_ROOT}/src/objects/tensor.cpp
${MORPHEUS_LIB_ROOT}/src/objects/wrapped_tensor.cpp
${MORPHEUS_LIB_ROOT}/src/stages/add_classification.cpp
Expand All @@ -57,32 +95,48 @@ add_library(morpheus
${MORPHEUS_LIB_ROOT}/src/utilities/python_util.cpp
${MORPHEUS_LIB_ROOT}/src/utilities/string_util.cpp
${MORPHEUS_LIB_ROOT}/src/utilities/table_util.cpp
${MORPHEUS_LIB_ROOT}/src/utilities/tensor_util.cpp
$<TARGET_OBJECTS:cuda_objs>
)

add_library(${PROJECT_NAME}::morpheus ALIAS morpheus)

target_link_libraries(morpheus
PUBLIC
cuda_utils
${cudf_helpers_target}
TritonClient::httpclient_static
RDKAFKA::RDKAFKA
PUBLIC
${cudf_helpers_target}
CUDA::nvToolsExt
morpheus_utils
mrc::pymrc
RDKAFKA::RDKAFKA
TritonClient::httpclient_static
)

target_include_directories(morpheus
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)

set_target_properties(morpheus PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(morpheus
PROPERTIES
CXX_VISIBILITY_PRESET hidden
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
)

# Generates an include file for specifying external linkage since everything is hidden by default
generate_export_header(morpheus
NO_EXPORT_MACRO_NAME MORPHEUS_LOCAL
)

install(
TARGETS
morpheus
EXPORT
${PROJECT_NAME}-exports
COMPONENT Wheel
TARGETS
morpheus
EXPORT
${PROJECT_NAME}-exports
COMPONENT
Wheel
)

if (MORPHEUS_PYTHON_INPLACE_BUILD)
Expand Down
56 changes: 56 additions & 0 deletions morpheus/_lib/cmake/libraries/morpheus_utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# =============================================================================
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
#
# 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 "morpheus_utils")

# find_package(pybind11 REQUIRED)


add_library(morpheus_utils
SHARED
${MORPHEUS_LIB_ROOT}/src/objects/table_info_data.cpp
)

target_include_directories(morpheus_utils
PUBLIC
"${MORPHEUS_LIB_ROOT}/include"
)

target_link_libraries(morpheus_utils
PUBLIC
cudf::cudf
PRIVATE
glog::glog
)

# set_target_properties(
# morpheus_utils
# PROPERTIES
# CUDA_STANDARD 17
# CUDA_STANDARD_REQUIRED ON
# )

install(
TARGETS
morpheus_utils
EXPORT
${PROJECT_NAME}-exports
COMPONENT Wheel
)

if (MORPHEUS_PYTHON_INPLACE_BUILD)
morpheus_utils_inplace_build_copy(morpheus_utils ${MORPHEUS_LIB_ROOT})
endif()

list(POP_BACK CMAKE_MESSAGE_CONTEXT)
Loading

0 comments on commit 043919a

Please sign in to comment.