diff --git a/CMakeLists.txt b/CMakeLists.txt index 45a080fe7..4f0f92c91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ option(MRC_USE_CONDA "Enables finding dependencies via conda. All dependencies m environment" ON) option(MRC_USE_IWYU "Enable running include-what-you-use as part of the build process" OFF) -set(MRC_RAPIDS_VERSION "23.02" CACHE STRING "Which version of RAPIDS to build for. Sets default versions for RAPIDS CMake and RMM.") +set(MRC_RAPIDS_VERSION "23.06" CACHE STRING "Which version of RAPIDS to build for. Sets default versions for RAPIDS CMake and RMM.") set(MRC_CACHE_DIR "${CMAKE_SOURCE_DIR}/.cache" CACHE PATH "Directory to contain all CPM and CCache data") mark_as_advanced(MRC_CACHE_DIR) diff --git a/ci/conda/environments/dev_env.yml b/ci/conda/environments/dev_env.yml index 4d3e066f9..f7ded3713 100644 --- a/ci/conda/environments/dev_env.yml +++ b/ci/conda/environments/dev_env.yml @@ -38,17 +38,17 @@ dependencies: - gflags=2.2 - git>=2.35.3 # Needed for wildcards on safe.directory - glog=0.6 - - gmock=1.10 + - gmock=1.13 - graphviz=3.0 - - grpc-cpp=1.48 - - gtest=1.10 + - grpc-cpp=1.51 + - gtest=1.13 - gxx=11.2 # Specifies which versions of GXX and GCC to use - isort - jinja2=3.0 - lcov=1.15 - libhwloc=2.5 - libprotobuf=3.21 - - librmm=23.02 + - librmm=23.06 - libtool - ninja=1.10 - nlohmann_json=3.9 @@ -61,9 +61,8 @@ dependencies: - pytest-timeout - python=3.10 - scikit-build>=0.17 - - spdlog=1.8.5 - sysroot_linux-64=2.17 - - ucx=1.13 + - ucx=1.14 - yapf # Remove once `mamba repoquery whoneeds cudatoolkit` is empty. For now, we need to specify a version diff --git a/ci/conda/recipes/libmrc/build.sh b/ci/conda/recipes/libmrc/build.sh index cad5dfb64..3bdbf295f 100644 --- a/ci/conda/recipes/libmrc/build.sh +++ b/ci/conda/recipes/libmrc/build.sh @@ -53,7 +53,7 @@ export CXX=${GXX} # Common CMake args CMAKE_ARGS="-DBUILD_SHARED_LIBS=ON ${CMAKE_ARGS}" CMAKE_ARGS="-DCMAKE_BUILD_TYPE=${MRC_BUILD_TYPE} ${CMAKE_ARGS}" -CMAKE_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES=-"ALL"} ${CMAKE_ARGS}" +CMAKE_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES=-"RAPIDS"} ${CMAKE_ARGS}" CMAKE_ARGS="-DCMAKE_INSTALL_LIBDIR=lib ${CMAKE_ARGS}" CMAKE_ARGS="-DCMAKE_INSTALL_PREFIX=$PREFIX ${CMAKE_ARGS}" CMAKE_ARGS="-DCMAKE_MESSAGE_CONTEXT_SHOW=ON ${CMAKE_ARGS}" diff --git a/ci/conda/recipes/libmrc/conda_build_config.yaml b/ci/conda/recipes/libmrc/conda_build_config.yaml index 5ba3ff7f5..04cd535d0 100644 --- a/ci/conda/recipes/libmrc/conda_build_config.yaml +++ b/ci/conda/recipes/libmrc/conda_build_config.yaml @@ -28,30 +28,36 @@ cuda_compiler_version: python: - 3.8 - 3.10 + - 3.10 # Setup the dependencies to build with multiple versions of RAPIDS -rapids_version: # Keep around compatibility with current version -1 - - 22.12 +rapids_version: # Keep around compatibility with current version -2 - 23.02 + - 23.04 + - 23.06 # Multiple versions of abseil are required to satisfy the solver for some # environments. RAPIDS 22.06 only works with gRPC 1.45 and 22.08 only works with # 1.46. For each version of gRPC, support 2 abseil versions. Zip all of the keys # together to avoid impossible combinations libabseil: - - 20220623.0 + - 20230125.0 + - 20230125.0 - 20230125.0 grpc_cpp: - - 1.46 + - 1.51 + - 1.51 - 1.51 ucx: - 1.13 - - 1.13 + - 1.14 + - 1.14 libprotobuf: - - 3.20 + - 3.21 + - 3.21 - 3.21 zip_keys: diff --git a/ci/conda/recipes/libmrc/meta.yaml b/ci/conda/recipes/libmrc/meta.yaml index e8771cb10..b4be6cd94 100644 --- a/ci/conda/recipes/libmrc/meta.yaml +++ b/ci/conda/recipes/libmrc/meta.yaml @@ -29,7 +29,7 @@ source: build: number: {{ GIT_DESCRIBE_NUMBER }} script_env: - - CMAKE_CUDA_ARCHITECTURES=ALL + - CMAKE_CUDA_ARCHITECTURES=RAPIDS - MRC_CACHE_DIR - PARALLEL_LEVEL include_recipe: False @@ -58,9 +58,9 @@ requirements: - flatbuffers 2.0.* - gflags - glog - - gmock 1.10.* + - gmock 1.13.* - grpc-cpp - - gtest 1.10.* + - gtest 1.13.* - libabseil - libhwloc 2.5.* - libprotobuf @@ -70,7 +70,6 @@ requirements: - pybind11-stubgen 0.10.5 - python {{ python }} - scikit-build >=0.17 - - spdlog 1.8.5 - ucx # Need to specify cudatoolkit to get correct version. Remove once all libraries migrate to cuda-toolkit - cudatoolkit {{ cuda_version }}.* diff --git a/ci/conda/recipes/run_conda_build.sh b/ci/conda/recipes/run_conda_build.sh index 203f4aa62..bbdc3ed2e 100755 --- a/ci/conda/recipes/run_conda_build.sh +++ b/ci/conda/recipes/run_conda_build.sh @@ -53,6 +53,9 @@ export CMAKE_C_COMPILER_LAUNCHER="ccache" export CMAKE_CXX_COMPILER_LAUNCHER="ccache" export CMAKE_CUDA_COMPILER_LAUNCHER="ccache" +# Avoid confirmation messages during the conda build +export CONDA_ALWAYS_YES=true + # Holds the arguments in an array to allow for complex json objects CONDA_ARGS_ARRAY=() @@ -92,7 +95,7 @@ fi # Choose default variants if hasArg quick; then # For quick build, just do most recent version of rapids - CONDA_ARGS_ARRAY+=("--variants" "{rapids_version: 23.02}") + CONDA_ARGS_ARRAY+=("--variants" "{rapids_version: 23.06}") fi # And default channels diff --git a/ci/iwyu/mappings.imp b/ci/iwyu/mappings.imp index 0cc1aed73..7e9f70083 100644 --- a/ci/iwyu/mappings.imp +++ b/ci/iwyu/mappings.imp @@ -27,7 +27,10 @@ # gprc { "include": ["@", "private", "", "public"] }, +{ "include": ["@", "private", "", "public"] }, { "include": ["@", "private", "", "public"] }, +{ "include": ["@", "private", "", "public"] }, +{ "symbol": ["@grpc::.*", "private", "", "public"] }, # nlohmann json { "include": ["", "private", "", "public"] }, diff --git a/ci/scripts/github/common.sh b/ci/scripts/github/common.sh index eab8ac4d5..02684da2f 100644 --- a/ci/scripts/github/common.sh +++ b/ci/scripts/github/common.sh @@ -80,7 +80,7 @@ function update_conda_env() { # Make sure we have the conda-merge package installed if [[ -z "$(conda list | grep conda-merge)" ]]; then - rapids-mamba-retry install -n mrc -c conda-forge "conda-merge>=0.2" + rapids-mamba-retry install -q -n mrc -c conda-forge "conda-merge>=0.2" fi # Create a temp directory which we store the combined environment file in @@ -91,7 +91,7 @@ function update_conda_env() { conda run -n mrc --live-stream conda-merge ${CONDA_ENV_YML} ${CONDA_CLANG_ENV_YML} ${CONDA_CI_ENV_YML} > ${condatmpdir}/merged_env.yml # Update the conda env with prune remove excess packages (in case one was removed from the env) - rapids-mamba-retry env update -n mrc -q --prune --file ${condatmpdir}/merged_env.yml + rapids-mamba-retry env update -n mrc --prune --file ${condatmpdir}/merged_env.yml # Delete the temp directory rm -rf ${condatmpdir} diff --git a/cpp/mrc/CMakeLists.txt b/cpp/mrc/CMakeLists.txt index 7190eac9d..a0af3cbcd 100644 --- a/cpp/mrc/CMakeLists.txt +++ b/cpp/mrc/CMakeLists.txt @@ -21,36 +21,34 @@ add_library(libmrc src/internal/codable/codable_storage.cpp src/internal/codable/decodable_storage_view.cpp src/internal/codable/storage_view.cpp - src/internal/control_plane/client/connections_manager.cpp src/internal/control_plane/client.cpp + src/internal/control_plane/client/connections_manager.cpp src/internal/control_plane/client/instance.cpp src/internal/control_plane/client/state_manager.cpp src/internal/control_plane/client/subscription_service.cpp - src/internal/control_plane/resources.cpp - src/internal/control_plane/server/connection_manager.cpp + src/internal/control_plane/control_plane_resources.cpp src/internal/control_plane/server.cpp + src/internal/control_plane/server/connection_manager.cpp src/internal/control_plane/server/subscription_manager.cpp src/internal/control_plane/server/tagged_issuer.cpp src/internal/data_plane/callbacks.cpp src/internal/data_plane/client.cpp + src/internal/data_plane/data_plane_resources.cpp src/internal/data_plane/request.cpp - src/internal/data_plane/resources.cpp src/internal/data_plane/server.cpp - src/internal/executor/executor.cpp - src/internal/executor/iexecutor.cpp + src/internal/executor/executor_definition.cpp src/internal/grpc/progress_engine.cpp src/internal/grpc/server.cpp src/internal/memory/device_resources.cpp src/internal/memory/host_resources.cpp src/internal/memory/transient_pool.cpp - src/internal/network/resources.cpp + src/internal/network/network_resources.cpp src/internal/pipeline/controller.cpp - src/internal/pipeline/instance.cpp - src/internal/pipeline/ipipeline.cpp src/internal/pipeline/manager.cpp - src/internal/pipeline/pipeline.cpp + src/internal/pipeline/pipeline_definition.cpp + src/internal/pipeline/pipeline_instance.cpp + src/internal/pipeline/pipeline_resources.cpp src/internal/pipeline/port_graph.cpp - src/internal/pipeline/resources.cpp src/internal/pubsub/publisher_round_robin.cpp src/internal/pubsub/publisher_service.cpp src/internal/pubsub/subscriber_service.cpp @@ -61,21 +59,19 @@ add_library(libmrc src/internal/resources/manager.cpp src/internal/resources/partition_resources_base.cpp src/internal/resources/partition_resources.cpp - src/internal/runnable/engine.cpp src/internal/runnable/engine_factory.cpp + src/internal/runnable/engine.cpp src/internal/runnable/engines.cpp src/internal/runnable/fiber_engine.cpp src/internal/runnable/fiber_engines.cpp - src/internal/runnable/resources.cpp + src/internal/runnable/runnable_resources.cpp src/internal/runnable/thread_engine.cpp src/internal/runnable/thread_engines.cpp src/internal/runtime/partition.cpp src/internal/runtime/runtime.cpp - src/internal/segment/builder.cpp - src/internal/segment/definition.cpp - src/internal/segment/ibuilder.cpp - src/internal/segment/idefinition.cpp - src/internal/segment/instance.cpp + src/internal/segment/builder_definition.cpp + src/internal/segment/segment_definition.cpp + src/internal/segment/segment_instance.cpp src/internal/service.cpp src/internal/system/device_info.cpp src/internal/system/device_partition.cpp @@ -84,39 +80,36 @@ add_library(libmrc src/internal/system/fiber_pool.cpp src/internal/system/fiber_task_queue.cpp src/internal/system/gpu_info.cpp - src/internal/system/host_partition.cpp src/internal/system/host_partition_provider.cpp - src/internal/system/iresources.cpp - src/internal/system/isystem.cpp - src/internal/system/partition.cpp + src/internal/system/host_partition.cpp src/internal/system/partition_provider.cpp + src/internal/system/partition.cpp src/internal/system/partitions.cpp - src/internal/system/resources.cpp - src/internal/system/system.cpp src/internal/system/system_provider.cpp - src/internal/system/thread.cpp + src/internal/system/system.cpp src/internal/system/thread_pool.cpp + src/internal/system/thread.cpp + src/internal/system/threading_resources.cpp src/internal/system/topology.cpp src/internal/ucx/context.cpp src/internal/ucx/endpoint.cpp src/internal/ucx/memory_block.cpp src/internal/ucx/receive_manager.cpp - src/internal/ucx/resources.cpp + src/internal/ucx/ucx_resources.cpp src/internal/ucx/worker.cpp src/internal/utils/collision_detector.cpp src/internal/utils/exception_guard.cpp src/internal/utils/parse_config.cpp src/internal/utils/parse_ints.cpp src/internal/utils/shared_resource_bit_map.cpp - src/public/benchmarking/tracer.cpp src/public/benchmarking/trace_statistics.cpp + src/public/benchmarking/tracer.cpp src/public/benchmarking/util.cpp src/public/channel/channel.cpp src/public/codable/encoded_object.cpp src/public/codable/memory.cpp src/public/core/addresses.cpp src/public/core/bitmap.cpp - src/public/core/executor.cpp src/public/core/fiber_pool.cpp src/public/core/logging.cpp src/public/core/thread.cpp @@ -145,15 +138,16 @@ add_library(libmrc src/public/options/resources.cpp src/public/options/services.cpp src/public/options/topology.cpp + src/public/pipeline/executor.cpp src/public/pipeline/pipeline.cpp + src/public/pipeline/segment.cpp + src/public/pipeline/system.cpp src/public/runnable/context.cpp src/public/runnable/launcher.cpp src/public/runnable/runnable.cpp src/public/runnable/runner.cpp src/public/runnable/types.cpp src/public/runtime/remote_descriptor.cpp - src/public/segment/builder.cpp - src/public/segment/definition.cpp src/public/utils/bytes_to_string.cpp src/public/utils/thread_utils.cpp src/public/utils/type_utils.cpp diff --git a/cpp/mrc/benchmarks/bench_segment.cpp b/cpp/mrc/benchmarks/bench_segment.cpp index 5c5054b20..2ddeed4e2 100644 --- a/cpp/mrc/benchmarks/bench_segment.cpp +++ b/cpp/mrc/benchmarks/bench_segment.cpp @@ -18,11 +18,10 @@ #include "mrc/benchmarking/segment_watcher.hpp" #include "mrc/benchmarking/tracer.hpp" #include "mrc/benchmarking/util.hpp" -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/node/rx_node.hpp" #include "mrc/node/rx_sink.hpp" #include "mrc/node/rx_source.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/segment/builder.hpp" // IWYU pragma: keep #include "mrc/segment/object.hpp" // IWYU pragma: keep @@ -190,7 +189,7 @@ class SimpleEmitReceiveFixture : public benchmark::Fixture void SetUp(const ::benchmark::State& state) override { TimeUtil::estimate_steady_clock_delay(); - auto init = [this](segment::Builder& segment) { + auto init = [this](segment::IBuilder& segment) { std::string src_name = "nsrc"; std::string int_name = "n1"; std::string sink_name = "nsink"; @@ -215,7 +214,7 @@ class SimpleEmitReceiveFixture : public benchmark::Fixture segment.make_edge(internal, sink); }; - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); auto segment = pipeline->make_segment("bench_segment", init); std::shared_ptr executor = std::make_shared(); @@ -250,7 +249,7 @@ class LongEmitReceiveFixture : public benchmark::Fixture void SetUp(const ::benchmark::State& state) override { TimeUtil::estimate_steady_clock_delay(); - auto init = [this](segment::Builder& segment) { + auto init = [this](segment::IBuilder& segment) { std::string src_name = "nsrc"; std::string sink_name = "nsink"; @@ -284,7 +283,7 @@ class LongEmitReceiveFixture : public benchmark::Fixture segment.make_edge(last_node, sink); }; - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); auto segment = pipeline->make_segment("bench_segment", init); std::shared_ptr executor = std::make_shared(); diff --git a/cpp/mrc/include/mrc/benchmarking/segment_watcher.hpp b/cpp/mrc/include/mrc/benchmarking/segment_watcher.hpp index 364f27406..f22889e36 100644 --- a/cpp/mrc/include/mrc/benchmarking/segment_watcher.hpp +++ b/cpp/mrc/include/mrc/benchmarking/segment_watcher.hpp @@ -19,7 +19,7 @@ #include "mrc/benchmarking/trace_statistics.hpp" #include "mrc/benchmarking/tracer.hpp" -#include "mrc/core/executor.hpp" +#include "mrc/pipeline/executor.hpp" #include #include @@ -48,8 +48,8 @@ class SegmentWatcher using time_pt_t = std::chrono::time_point; ~SegmentWatcher() = default; - SegmentWatcher(std::shared_ptr executor); - SegmentWatcher(std::shared_ptr executor, std::function payload_init); + SegmentWatcher(std::shared_ptr executor); + SegmentWatcher(std::shared_ptr executor, std::function payload_init); [[nodiscard]] bool tracing() const; @@ -142,7 +142,7 @@ class SegmentWatcher std::atomic m_segment_started{false}; std::atomic m_latency_cycle_ready{true}; - std::shared_ptr m_executor; + std::shared_ptr m_executor; std::mutex m_mutex; boost::fibers::condition_variable_any m_cond_wake; @@ -290,11 +290,12 @@ decltype(auto) SegmentWatcher::create_rx_tracer_source(const std::s } template -SegmentWatcher::SegmentWatcher(std::shared_ptr executor) : m_executor(std::move(executor)) +SegmentWatcher::SegmentWatcher(std::shared_ptr executor) : + m_executor(std::move(executor)) {} template -SegmentWatcher::SegmentWatcher(std::shared_ptr executor, +SegmentWatcher::SegmentWatcher(std::shared_ptr executor, std::function payload_init) : m_executor(std::move(executor)), m_payload_init(payload_init) diff --git a/cpp/mrc/include/mrc/core/executor.hpp b/cpp/mrc/include/mrc/core/executor.hpp deleted file mode 100644 index 03de4ce64..000000000 --- a/cpp/mrc/include/mrc/core/executor.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include "mrc/engine/executor/iexecutor.hpp" - -#include - -namespace mrc::internal::system { -class IResources; -} // namespace mrc::internal::system - -namespace mrc { -class Options; - -class Executor final : public internal::executor::IExecutor -{ - public: - Executor(); - Executor(std::shared_ptr options); - Executor(std::unique_ptr resources); - ~Executor() final = default; -}; - -} // namespace mrc diff --git a/cpp/mrc/include/mrc/core/task_queue.hpp b/cpp/mrc/include/mrc/core/task_queue.hpp index 773936bec..492f0a165 100644 --- a/cpp/mrc/include/mrc/core/task_queue.hpp +++ b/cpp/mrc/include/mrc/core/task_queue.hpp @@ -18,6 +18,7 @@ #pragma once #include "mrc/core/fiber_meta_data.hpp" +#include "mrc/core/utils.hpp" #include "mrc/types.hpp" #include @@ -70,8 +71,14 @@ class FiberTaskQueue // track detached fibers - main fiber will wait on all detached fibers to finish packaged_task wrapped_task([this, t = std::move(task)]() mutable { + auto decrement_detached = Unwinder::create([this]() { + --m_detached; + }); + + // Call the task t(); - --m_detached; + + // Detached will get automatically decremented even if there is an exception }); ++m_detached; diff --git a/cpp/mrc/include/mrc/core/utils.hpp b/cpp/mrc/include/mrc/core/utils.hpp index 12e763ee2..84e2f8e06 100644 --- a/cpp/mrc/include/mrc/core/utils.hpp +++ b/cpp/mrc/include/mrc/core/utils.hpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace mrc { diff --git a/cpp/mrc/include/mrc/coroutines/ring_buffer.hpp b/cpp/mrc/include/mrc/coroutines/ring_buffer.hpp index 88605b41b..d266d91c6 100644 --- a/cpp/mrc/include/mrc/coroutines/ring_buffer.hpp +++ b/cpp/mrc/include/mrc/coroutines/ring_buffer.hpp @@ -158,25 +158,44 @@ class RingBuffer return (!m_stopped ? RingBufferOpStatus::Success : RingBufferOpStatus::Stopped); } - WriteOperation& use_scheduling_policy(SchedulePolicy policy) + WriteOperation& use_scheduling_policy(SchedulePolicy policy) & { m_policy = policy; return *this; } - WriteOperation& resume_immediately() + WriteOperation use_scheduling_policy(SchedulePolicy policy) && + { + m_policy = policy; + return std::move(*this); + } + + WriteOperation& resume_immediately() & { m_policy = SchedulePolicy::Immediate; return *this; } - WriteOperation& resume_on(ThreadPool* thread_pool) + WriteOperation resume_immediately() && + { + m_policy = SchedulePolicy::Immediate; + return std::move(*this); + } + + WriteOperation& resume_on(ThreadPool* thread_pool) & { m_policy = SchedulePolicy::Reschedule; set_resume_on_thread_pool(thread_pool); return *this; } + WriteOperation resume_on(ThreadPool* thread_pool) && + { + m_policy = SchedulePolicy::Reschedule; + set_resume_on_thread_pool(thread_pool); + return std::move(*this); + } + private: friend RingBuffer; diff --git a/cpp/mrc/include/mrc/engine/executor/iexecutor.hpp b/cpp/mrc/include/mrc/engine/executor/iexecutor.hpp deleted file mode 100644 index ac67a7546..000000000 --- a/cpp/mrc/include/mrc/engine/executor/iexecutor.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include - -namespace mrc { -class Options; -} // namespace mrc -namespace mrc::internal::pipeline { -class IPipeline; -} // namespace mrc::internal::pipeline - -namespace mrc::internal::system { -class IResources; -} - -namespace mrc::internal::executor { - -class Executor; - -/** - * @brief The I-classes in mrc/internal enable the building and customization of an Executor. - * - * The build order should be: - * - ISystem - * - ISystemResources - * - IExecutor - * - * Over time, new customization points will be added between ISystemResources and IExecutor. - */ -class IExecutor -{ - public: - IExecutor(); - IExecutor(std::shared_ptr); - IExecutor(std::unique_ptr); - virtual ~IExecutor() = 0; - - void register_pipeline(std::unique_ptr pipeline); - - void start(); - void stop(); - void join(); - - protected: - // this method will be applied - - private: - std::shared_ptr m_impl; - friend Executor; -}; - -} // namespace mrc::internal::executor diff --git a/cpp/mrc/include/mrc/engine/pipeline/ipipeline.hpp b/cpp/mrc/include/mrc/engine/pipeline/ipipeline.hpp deleted file mode 100644 index c29620dca..000000000 --- a/cpp/mrc/include/mrc/engine/pipeline/ipipeline.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include - -namespace mrc::internal::segment { -class IDefinition; -class Definition; -} // namespace mrc::internal::segment - -namespace mrc::internal::pipeline { - -class Pipeline; - -class IPipeline -{ - public: - IPipeline(); - virtual ~IPipeline() = 0; - - protected: - void register_segment(std::shared_ptr segment); - - private: - void add_segment(std::shared_ptr segment); - - std::shared_ptr m_impl; - friend Pipeline; -}; - -} // namespace mrc::internal::pipeline diff --git a/cpp/mrc/include/mrc/engine/segment/forward.hpp b/cpp/mrc/include/mrc/engine/segment/forward.hpp deleted file mode 100644 index 6b50d0b05..000000000 --- a/cpp/mrc/include/mrc/engine/segment/forward.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include "mrc/engine/segment/idefinition.hpp" - -namespace mrc::internal::segment { - -class Definition; -class IDefinition; -class IBuilder; - -} // namespace mrc::internal::segment diff --git a/cpp/mrc/include/mrc/engine/segment/ibuilder.hpp b/cpp/mrc/include/mrc/engine/segment/ibuilder.hpp deleted file mode 100644 index d4af7df78..000000000 --- a/cpp/mrc/include/mrc/engine/segment/ibuilder.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2022, 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. - */ - -#pragma once - -#include "mrc/utils/macros.hpp" - -#include -#include -#include -#include - -namespace mrc::runnable { -class Launchable; -} // namespace mrc::runnable - -// todo(ryan) - most base classes that will be owned by the engine will need to be moved to engine api/lib -namespace mrc::modules { -class SegmentModule; -} -namespace mrc::segment { -class ObjectProperties; -class EgressPortBase; -class IngressPortBase; -} // namespace mrc::segment - -namespace mrc::internal::segment { - -class Builder; - -class IBuilder final -{ - public: - IBuilder(Builder* impl); - ~IBuilder(); - - DELETE_COPYABILITY(IBuilder); - DELETE_MOVEABILITY(IBuilder); - - const std::string& name() const; - bool has_object(const std::string& name) const; - ::mrc::segment::ObjectProperties& find_object(const std::string& name); - void add_object(const std::string& name, std::shared_ptr<::mrc::segment::ObjectProperties> object); - void add_module(const std::string& name, std::shared_ptr module); - void add_runnable(const std::string& name, std::shared_ptr runnable); - std::shared_ptr<::mrc::segment::IngressPortBase> get_ingress_base(const std::string& name); - std::shared_ptr<::mrc::segment::EgressPortBase> get_egress_base(const std::string& name); - std::function make_throughput_counter(const std::string& name); - - private: - Builder* m_impl; -}; - -} // namespace mrc::internal::segment diff --git a/cpp/mrc/include/mrc/engine/segment/idefinition.hpp b/cpp/mrc/include/mrc/engine/segment/idefinition.hpp deleted file mode 100644 index 9f64b73d3..000000000 --- a/cpp/mrc/include/mrc/engine/segment/idefinition.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include "mrc/segment/initializers.hpp" - -#include -#include -#include - -namespace mrc::internal::pipeline { -class IPipeline; -} - -namespace mrc::internal::segment { - -class Definition; - -struct IDefinition -{ - IDefinition(std::string name, - std::map ingress_initializers, - std::map egress_initializers, - ::mrc::segment::backend_initializer_fn_t backend_initializer); - virtual ~IDefinition() = 0; - - const std::string& name() const; - - private: - std::shared_ptr m_impl; - friend pipeline::IPipeline; -}; - -} // namespace mrc::internal::segment diff --git a/cpp/mrc/include/mrc/engine/system/iresources.hpp b/cpp/mrc/include/mrc/engine/system/iresources.hpp deleted file mode 100644 index 1a9012ead..000000000 --- a/cpp/mrc/include/mrc/engine/system/iresources.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include -#include - -namespace mrc::internal::system { - -class ISystem; -class Resources; - -class IResources -{ - public: - IResources(std::shared_ptr system); - virtual ~IResources() = 0; - - protected: - void add_thread_initializer(std::function initializer_fn); - void add_thread_finalizer(std::function finalizer_fn); - - private: - std::unique_ptr m_impl; - friend Resources; -}; - -} // namespace mrc::internal::system diff --git a/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap.hpp b/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap.hpp index 8a1613c6d..8b0d12099 100644 --- a/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap.hpp +++ b/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap.hpp @@ -43,7 +43,7 @@ class MirrorTapModule : public SegmentModule, public PersistentModule std::string tap_egress_port_name() const; protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; @@ -80,7 +80,7 @@ std::string MirrorTapModule::tap_egress_port_name() const } template -void MirrorTapModule::initialize(segment::Builder& builder) +void MirrorTapModule::initialize(segment::IBuilder& builder) { // ********** Implementation ************ // auto bcast = builder.construct_object>("broadcast"); diff --git a/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap_orchestrator.hpp b/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap_orchestrator.hpp index 4a923d9b9..29971b1f6 100644 --- a/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap_orchestrator.hpp +++ b/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap_orchestrator.hpp @@ -37,7 +37,7 @@ namespace mrc::modules { template class MirrorTapOrchestrator { - using initializer_t = std::function; + using initializer_t = std::function; using type_t = MirrorTapOrchestrator; public: @@ -48,7 +48,7 @@ class MirrorTapOrchestrator initializer_t tap(initializer_t initializer, const std::string tap_from, const std::string tap_to) { using namespace modules; - return [this, initializer, tap_from, tap_to](segment::Builder& builder) { + return [this, initializer, tap_from, tap_to](segment::IBuilder& builder) { initializer(builder); builder.init_module(m_tap); @@ -59,7 +59,7 @@ class MirrorTapOrchestrator initializer_t stream_to(initializer_t initializer, const std::string entry_point) { using namespace modules; - return [this, initializer, entry_point](segment::Builder& builder) { + return [this, initializer, entry_point](segment::IBuilder& builder) { initializer(builder); builder.init_module(m_stream); diff --git a/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap_stream.hpp b/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap_stream.hpp index 066e86d34..b053a4098 100644 --- a/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap_stream.hpp +++ b/cpp/mrc/include/mrc/experimental/modules/mirror_tap/mirror_tap_stream.hpp @@ -45,7 +45,7 @@ class MirrorTapStreamModule : public SegmentModule, public PersistentModule void tap_ingress_port_name(std::string name); protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; @@ -82,7 +82,7 @@ void MirrorTapStreamModule::tap_ingress_port_name(std::string ingress } template -void MirrorTapStreamModule::initialize(segment::Builder& builder) +void MirrorTapStreamModule::initialize(segment::IBuilder& builder) { auto mirror_ingress = builder.get_ingress(m_ingress_name); m_stream_buffer = builder.make_module>("test", config()); diff --git a/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_module.hpp b/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_module.hpp index 3efd2ce75..d7eeece45 100644 --- a/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_module.hpp +++ b/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_module.hpp @@ -57,7 +57,7 @@ class StreamBufferModule : public SegmentModule, public PersistentModule StreamBufferModule(std::string module_name, nlohmann::json config); protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; @@ -86,7 +86,7 @@ StreamBufferModule::StreamBufferModule(std::string } template class StreamBufferTypeT> -void StreamBufferModule::initialize(segment::Builder& builder) +void StreamBufferModule::initialize(segment::IBuilder& builder) { auto buffer_sink = builder.template make_sink("buffer_sink_new", m_subject.get_subscriber()); diff --git a/cpp/mrc/include/mrc/forward.hpp b/cpp/mrc/include/mrc/forward.hpp index 1f70ce105..e2ecd105f 100644 --- a/cpp/mrc/include/mrc/forward.hpp +++ b/cpp/mrc/include/mrc/forward.hpp @@ -24,7 +24,7 @@ class Executor; struct PlacementGroup; namespace pipeline { -class Pipeline; +class PipelineDefinition; } // namespace pipeline struct CpuSet; diff --git a/cpp/mrc/include/mrc/manifold/composite_manifold.hpp b/cpp/mrc/include/mrc/manifold/composite_manifold.hpp index dc5d8af9d..974729468 100644 --- a/cpp/mrc/include/mrc/manifold/composite_manifold.hpp +++ b/cpp/mrc/include/mrc/manifold/composite_manifold.hpp @@ -32,7 +32,8 @@ class CompositeManifold : public Manifold static_assert(std::is_base_of_v, "ingress must be derived from EgressDelegate"); public: - CompositeManifold(PortName port_name, pipeline::Resources& resources) : Manifold(std::move(port_name), resources) + CompositeManifold(PortName port_name, runnable::IRunnableResources& resources) : + Manifold(std::move(port_name), resources) { // construct IngressT and EgressT on the NUMA node / memory domain in which the object will run this->resources() @@ -47,7 +48,7 @@ class CompositeManifold : public Manifold .get(); } CompositeManifold(PortName port_name, - pipeline::Resources& resources, + runnable::IRunnableResources& resources, std::unique_ptr ingress, std::unique_ptr egress) : Manifold(std::move(port_name), resources), diff --git a/cpp/mrc/include/mrc/manifold/connectable.hpp b/cpp/mrc/include/mrc/manifold/connectable.hpp index 695775011..81e9ac94d 100644 --- a/cpp/mrc/include/mrc/manifold/connectable.hpp +++ b/cpp/mrc/include/mrc/manifold/connectable.hpp @@ -18,7 +18,7 @@ #pragma once #include "mrc/manifold/interface.hpp" -#include "mrc/pipeline/resources.hpp" +#include "mrc/runnable/runnable_resources.hpp" namespace mrc::manifold { @@ -30,7 +30,7 @@ struct Connectable * @brief Create a Manifold in the typed environment of the Connectable object, e.g. IngressPort, EgressPort * @return std::shared_ptr */ - virtual std::shared_ptr make_manifold(pipeline::Resources&) = 0; + virtual std::shared_ptr make_manifold(runnable::IRunnableResources&) = 0; /** * @brief Connect a Connectable to a Manifold diff --git a/cpp/mrc/include/mrc/manifold/factory.hpp b/cpp/mrc/include/mrc/manifold/factory.hpp index 6c19ea0d7..e51fd2457 100644 --- a/cpp/mrc/include/mrc/manifold/factory.hpp +++ b/cpp/mrc/include/mrc/manifold/factory.hpp @@ -27,7 +27,7 @@ namespace mrc::manifold { template struct Factory final { - static std::shared_ptr make_manifold(PortName port_name, pipeline::Resources& resources) + static std::shared_ptr make_manifold(PortName port_name, runnable::IRunnableResources& resources) { return std::make_shared>(std::move(port_name), resources); } diff --git a/cpp/mrc/include/mrc/manifold/interface.hpp b/cpp/mrc/include/mrc/manifold/interface.hpp index d457e7b16..5c3d28fa4 100644 --- a/cpp/mrc/include/mrc/manifold/interface.hpp +++ b/cpp/mrc/include/mrc/manifold/interface.hpp @@ -24,10 +24,13 @@ namespace mrc::manifold { struct Interface { - virtual ~Interface() = default; - virtual const PortName& port_name() const = 0; - virtual void start() = 0; - virtual void join() = 0; + virtual ~Interface() = default; + + virtual const PortName& port_name() const = 0; + + virtual void start() = 0; + virtual void join() = 0; + virtual void add_input(const SegmentAddress& address, edge::IWritableAcceptorBase* input_source) = 0; virtual void add_output(const SegmentAddress& address, edge::IWritableProviderBase* output_sink) = 0; diff --git a/cpp/mrc/include/mrc/manifold/load_balancer.hpp b/cpp/mrc/include/mrc/manifold/load_balancer.hpp index 7d28089e0..d88168dd7 100644 --- a/cpp/mrc/include/mrc/manifold/load_balancer.hpp +++ b/cpp/mrc/include/mrc/manifold/load_balancer.hpp @@ -25,9 +25,9 @@ #include "mrc/node/operators/muxer.hpp" #include "mrc/node/rx_sink.hpp" #include "mrc/node/source_channel_owner.hpp" -#include "mrc/pipeline/resources.hpp" #include "mrc/runnable/launch_options.hpp" #include "mrc/runnable/launchable.hpp" +#include "mrc/runnable/runnable_resources.hpp" #include "mrc/runnable/types.hpp" #include "mrc/types.hpp" @@ -68,7 +68,7 @@ class LoadBalancer : public CompositeManifold, RoundRobinEgress< using base_t = CompositeManifold, RoundRobinEgress>; public: - LoadBalancer(PortName port_name, pipeline::Resources& resources) : base_t(std::move(port_name), resources) + LoadBalancer(PortName port_name, runnable::IRunnableResources& resources) : base_t(std::move(port_name), resources) { m_launch_options.engine_factory_name = "main"; m_launch_options.pe_count = 1; diff --git a/cpp/mrc/include/mrc/manifold/manifold.hpp b/cpp/mrc/include/mrc/manifold/manifold.hpp index 28740a519..4cb567341 100644 --- a/cpp/mrc/include/mrc/manifold/manifold.hpp +++ b/cpp/mrc/include/mrc/manifold/manifold.hpp @@ -26,21 +26,22 @@ namespace mrc::edge { class IWritableAcceptorBase; class IWritableProviderBase; } // namespace mrc::edge -namespace mrc::pipeline { -struct Resources; -} // namespace mrc::pipeline +namespace mrc::runnable { +struct IRunnableResources; +} // namespace mrc::runnable namespace mrc::manifold { class Manifold : public Interface { public: - Manifold(PortName port_name, pipeline::Resources& resources); + Manifold(PortName port_name, runnable::IRunnableResources& resources); + ~Manifold() override; const PortName& port_name() const final; protected: - pipeline::Resources& resources(); + runnable::IRunnableResources& resources(); const std::string& info() const; @@ -52,7 +53,7 @@ class Manifold : public Interface virtual void do_add_output(const SegmentAddress& address, edge::IWritableProviderBase* output_sink) = 0; PortName m_port_name; - pipeline::Resources& m_resources; + runnable::IRunnableResources& m_resources; std::string m_info; }; diff --git a/cpp/mrc/include/mrc/memory/resources/arena_resource.hpp b/cpp/mrc/include/mrc/memory/resources/arena_resource.hpp index fbdf74c12..2f0dd39fc 100644 --- a/cpp/mrc/include/mrc/memory/resources/arena_resource.hpp +++ b/cpp/mrc/include/mrc/memory/resources/arena_resource.hpp @@ -24,8 +24,6 @@ #include #include #include -#include -#include #include #include @@ -108,12 +106,7 @@ class arena_resource final : public adaptor adaptor(std::move(upstream_mr)), global_arena_(std::make_shared(&this->resource(), initial_size, maximum_size)), dump_log_on_failure_(dump_log_on_failure) - { - if (dump_log_on_failure_) - { - logger_ = spdlog::basic_logger_mt("arena_memory_dump", "rmm_arena_memory_dump.log"); - } - } + {} ~arena_resource() override = default; @@ -248,7 +241,7 @@ class arena_resource final : public adaptor * @return arena& The arena associated with the given stream. arena& get_stream_arena(cuda_stream_view stream) { - RMM_LOGGING_ASSERT(!use_per_thread_arena(stream)); + DCHECK(!use_per_thread_arena(stream)); { read_lock lock(mtx_); auto const iter = stream_arenas_.find(stream.value()); @@ -317,8 +310,6 @@ class arena_resource final : public adaptor // std::map stream_arenas_; /// If true, dump memory information to log on allocation failure. bool dump_log_on_failure_; // NOLINT - /// The logger for memory dump. - std::shared_ptr logger_{}; // NOLINT /// Mutex for read and write locks. mutable std::shared_timed_mutex mtx_; // NOLINT }; diff --git a/cpp/mrc/include/mrc/memory/resources/detail/arena.hpp b/cpp/mrc/include/mrc/memory/resources/detail/arena.hpp index 4b3098b15..e25631606 100644 --- a/cpp/mrc/include/mrc/memory/resources/detail/arena.hpp +++ b/cpp/mrc/include/mrc/memory/resources/detail/arena.hpp @@ -18,12 +18,11 @@ #pragma once #include +#include #include #include #include #include -#include -#include #include #include @@ -123,7 +122,7 @@ class block */ [[nodiscard]] std::pair split(std::size_t size) const { - RMM_LOGGING_ASSERT(size_ >= size); + DCHECK(size_ >= size); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (size_ > size) { @@ -142,7 +141,7 @@ class block */ [[nodiscard]] block merge(block const& blk) const { - RMM_LOGGING_ASSERT(is_contiguous_before(blk)); + DCHECK(is_contiguous_before(blk)); return {pointer_, size_ + blk.size_}; } @@ -401,29 +400,30 @@ class global_arena final } } - /** - * @brief Dump memory to log. - * - * @param logger the spdlog logger to use - */ - void dump_memory_log(std::shared_ptr const& logger) const - { - lock_guard lock(mtx_); + // /** + // * @brief Dump memory to log. + // * + // * @param logger the spdlog logger to use + // */ + // void dump_memory_log(std::shared_ptr const& logger) const + // { + // lock_guard lock(mtx_); - logger->info(" Maximum size: {}", rmm::detail::bytes{maximum_size_}); - logger->info(" Current size: {}", rmm::detail::bytes{current_size_}); + // logger->info(" Maximum size: {}", rmm::detail::bytes{maximum_size_}); + // logger->info(" Current size: {}", rmm::detail::bytes{current_size_}); - logger->info(" # free blocks: {}", free_blocks_.size()); - if (!free_blocks_.empty()) - { - logger->info(" Total size of free blocks: {}", rmm::detail::bytes{total_block_size(free_blocks_)}); - auto const largest_free = *std::max_element(free_blocks_.begin(), free_blocks_.end(), block_size_compare); - logger->info(" Size of largest free block: {}", rmm::detail::bytes{largest_free.size()}); - } + // logger->info(" # free blocks: {}", free_blocks_.size()); + // if (!free_blocks_.empty()) + // { + // logger->info(" Total size of free blocks: {}", rmm::detail::bytes{total_block_size(free_blocks_)}); + // auto const largest_free = *std::max_element(free_blocks_.begin(), free_blocks_.end(), + // block_size_compare); logger->info(" Size of largest free block: {}", + // rmm::detail::bytes{largest_free.size()}); + // } - logger->info(" # upstream blocks={}", upstream_blocks_.size()); - logger->info(" Total size of upstream blocks: {}", rmm::detail::bytes{total_block_size(upstream_blocks_)}); - } + // logger->info(" # upstream blocks={}", upstream_blocks_.size()); + // logger->info(" Total size of upstream blocks: {}", rmm::detail::bytes{total_block_size(upstream_blocks_)}); + // } private: using lock_guard = std::lock_guard; @@ -566,22 +566,23 @@ class arena free_blocks_.clear(); } - /** - * Dump memory to log. - * - * @param logger the spdlog logger to use - */ - void dump_memory_log(std::shared_ptr const& logger) const - { - lock_guard lock(mtx_); - logger->info(" # free blocks: {}", free_blocks_.size()); - if (!free_blocks_.empty()) - { - logger->info(" Total size of free blocks: {}", rmm::detail::bytes{total_block_size(free_blocks_)}); - auto const largest_free = *std::max_element(free_blocks_.begin(), free_blocks_.end(), block_size_compare); - logger->info(" Size of largest free block: {}", rmm::detail::bytes{largest_free.size()}); - } - } + // /** + // * Dump memory to log. + // * + // * @param logger the spdlog logger to use + // */ + // void dump_memory_log(std::shared_ptr const& logger) const + // { + // lock_guard lock(mtx_); + // logger->info(" # free blocks: {}", free_blocks_.size()); + // if (!free_blocks_.empty()) + // { + // logger->info(" Total size of free blocks: {}", rmm::detail::bytes{total_block_size(free_blocks_)}); + // auto const largest_free = *std::max_element(free_blocks_.begin(), free_blocks_.end(), + // block_size_compare); logger->info(" Size of largest free block: {}", + // rmm::detail::bytes{largest_free.size()}); + // } + // } private: using lock_guard = std::lock_guard; diff --git a/cpp/mrc/include/mrc/modules/sample_modules.hpp b/cpp/mrc/include/mrc/modules/sample_modules.hpp index 647f211af..23db4db57 100644 --- a/cpp/mrc/include/mrc/modules/sample_modules.hpp +++ b/cpp/mrc/include/mrc/modules/sample_modules.hpp @@ -45,7 +45,7 @@ class SimpleModule : public SegmentModule bool m_was_configured{false}; protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; private: @@ -68,7 +68,7 @@ class ConfigurableModule : public SegmentModule bool m_was_configured{false}; protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; private: @@ -89,7 +89,7 @@ class SourceModule : public SegmentModule SourceModule(std::string module_name, nlohmann::json config); protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; }; @@ -108,7 +108,7 @@ class SinkModule : public SegmentModule unsigned int m_packet_count{0}; protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; }; @@ -129,7 +129,7 @@ class NestedModule : public SegmentModule NestedModule(std::string module_name, nlohmann::json config); protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; }; @@ -147,7 +147,7 @@ class TemplateModule : public SegmentModule TemplateModule(std::string module_name); TemplateModule(std::string module_name, nlohmann::json config); - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; }; @@ -161,7 +161,7 @@ TemplateModule::TemplateModule(std::string module_name, nlohmann::j {} template -void TemplateModule::initialize(segment::Builder& builder) +void TemplateModule::initialize(segment::IBuilder& builder) { unsigned int count{1}; @@ -208,7 +208,7 @@ class TemplateWithInitModule : public SegmentModule TemplateWithInitModule(std::string module_name); TemplateWithInitModule(std::string module_name, nlohmann::json config); - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; }; @@ -224,7 +224,7 @@ TemplateWithInitModule::TemplateWithInitModule(std::st {} template -void TemplateWithInitModule::initialize(segment::Builder& builder) +void TemplateWithInitModule::initialize(segment::IBuilder& builder) { unsigned int count{1}; diff --git a/cpp/mrc/include/mrc/modules/segment_modules.hpp b/cpp/mrc/include/mrc/modules/segment_modules.hpp index 49be6f012..3cabb0d03 100644 --- a/cpp/mrc/include/mrc/modules/segment_modules.hpp +++ b/cpp/mrc/include/mrc/modules/segment_modules.hpp @@ -26,7 +26,8 @@ #include namespace mrc::segment { -class Builder; +class IBuilder; +class BuilderDefinition; } // namespace mrc::segment namespace mrc::segment { @@ -37,8 +38,6 @@ namespace mrc::modules { class SegmentModule { - friend mrc::segment::Builder; - public: using segment_module_port_map_t = std::map>; using segment_module_port_t = std::shared_ptr; @@ -122,7 +121,7 @@ class SegmentModule * Functional entrypoint for module constructor during build -- this lets us act like a std::function * @param builder */ - void operator()(segment::Builder& builder); + void operator()(segment::IBuilder& builder); /** * Retrieve the class name for the module, defaults to 'segment_module' @@ -137,7 +136,7 @@ class SegmentModule * Entrypoint for module constructor during build * @param builder */ - virtual void initialize(segment::Builder& builder) = 0; + virtual void initialize(segment::IBuilder& builder) = 0; /* Interface Functions */ /** @@ -190,6 +189,8 @@ class SegmentModule segment_module_port_map_t m_output_ports{}; const nlohmann::json m_config; + + friend class segment::BuilderDefinition; }; } // namespace mrc::modules diff --git a/cpp/mrc/include/mrc/mrc.hpp b/cpp/mrc/include/mrc/mrc.hpp index 34abe3f11..b86340fe6 100644 --- a/cpp/mrc/include/mrc/mrc.hpp +++ b/cpp/mrc/include/mrc/mrc.hpp @@ -22,10 +22,11 @@ // Then the rest of the includes #include "mrc/core/context.hpp" -#include "mrc/core/executor.hpp" #include "mrc/options/options.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" +#include "mrc/pipeline/segment.hpp" +#include "mrc/pipeline/system.hpp" #include "mrc/segment/builder.hpp" -#include "mrc/segment/definition.hpp" #include "mrc/segment/egress_ports.hpp" #include "mrc/segment/ingress_ports.hpp" diff --git a/cpp/mrc/include/mrc/options/options.hpp b/cpp/mrc/include/mrc/options/options.hpp index da5f34c86..5455c75c7 100644 --- a/cpp/mrc/include/mrc/options/options.hpp +++ b/cpp/mrc/include/mrc/options/options.hpp @@ -35,6 +35,9 @@ class Options public: Options(); + Options(const Options&); + Options& operator=(const Options&); + EngineGroups& engine_factories(); FiberPoolOptions& fiber_pool(); PlacementOptions& placement(); diff --git a/cpp/mrc/include/mrc/pipeline/executor.hpp b/cpp/mrc/include/mrc/pipeline/executor.hpp new file mode 100644 index 000000000..1c575e1b0 --- /dev/null +++ b/cpp/mrc/include/mrc/pipeline/executor.hpp @@ -0,0 +1,75 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. + */ + +#pragma once + +#include "mrc/utils/macros.hpp" + +#include + +namespace mrc { +class Options; +} // namespace mrc +namespace mrc::pipeline { +class IPipeline; +} // namespace mrc::pipeline + +namespace mrc::pipeline { +class ISystem; + +class IExecutor +{ + public: + virtual ~IExecutor() = default; + + DELETE_COPYABILITY(IExecutor); + + virtual void register_pipeline(std::shared_ptr pipeline) = 0; + virtual void start() = 0; + virtual void stop() = 0; + virtual void join() = 0; + + protected: + IExecutor() = default; +}; + +} // namespace mrc::pipeline + +namespace mrc { + +// For backwards compatibility, make utility implementation which holds onto a unique_ptr +class Executor : public pipeline::IExecutor +{ + public: + Executor(); + Executor(std::shared_ptr options); + ~Executor() override; + + void register_pipeline(std::shared_ptr pipeline) override; + void start() override; + void stop() override; + void join() override; + + private: + std::unique_ptr m_impl; +}; + +std::unique_ptr make_executor(std::shared_ptr options); + +std::unique_ptr make_executor(std::unique_ptr system); + +} // namespace mrc diff --git a/cpp/mrc/include/mrc/pipeline/pipeline.hpp b/cpp/mrc/include/mrc/pipeline/pipeline.hpp index 6237a8a44..9167db16e 100644 --- a/cpp/mrc/include/mrc/pipeline/pipeline.hpp +++ b/cpp/mrc/include/mrc/pipeline/pipeline.hpp @@ -17,18 +17,18 @@ #pragma once -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/segment/initializers.hpp" #include "mrc/utils/macros.hpp" #include #include #include +#include namespace mrc::segment { struct EgressPortsBase; struct IngressPortsBase; -class Definition; + } // namespace mrc::segment // work-around for known iwyu issue @@ -37,25 +37,21 @@ class Definition; namespace mrc::pipeline { -class Pipeline final : public internal::pipeline::IPipeline -{ - Pipeline() = default; - using base_t = internal::pipeline::IPipeline; +class ISegment; +class IPipeline +{ public: - static std::unique_ptr create(); - - ~Pipeline() final = default; + virtual ~IPipeline() = default; - DELETE_COPYABILITY(Pipeline); - DELETE_MOVEABILITY(Pipeline); + DELETE_COPYABILITY(IPipeline); /** * @brief register a segment * @param [in] segment * @throws **/ - void register_segment(std::shared_ptr segment); + virtual std::shared_ptr register_segment(std::shared_ptr segment) = 0; /** * @brief register multiple segments @@ -63,10 +59,13 @@ class Pipeline final : public internal::pipeline::IPipeline * @tparam SegmentDefs * @param segment_defs */ - template // NOLINT - void register_segments(SegmentDefs&&... segment_defs) + template + std::vector> register_segments(SegmentDefsT&&... segment_defs) { - (register_segment(std::forward(segment_defs)), ...); + auto segments = std::vector>{ + {this->register_segment(std::forward(segment_defs))...}}; + + return segments; } /** @@ -77,10 +76,10 @@ class Pipeline final : public internal::pipeline::IPipeline * @param segment_name Unique name to assign to segments built from this definition * @param segment_initializer User defined lambda function which will be used to initialize * new segments. - * @return A shared pointer to a new segment::Definition + * @return A shared pointer to a new segment::ISegment */ - std::shared_ptr make_segment(const std::string& segment_name, - segment::segment_initializer_fn_t segment_initializer); + virtual std::shared_ptr make_segment(const std::string& segment_name, + segment::segment_initializer_fn_t segment_initializer) = 0; /** * Create a segment definition, which describes how to create new Segment instances. @@ -92,12 +91,12 @@ class Pipeline final : public internal::pipeline::IPipeline * @param segment_name Unique name to assign to segments built from this definition * @param segment_initializer User defined lambda function which will be used to initialize * new segments. - * @return A shared pointer to a new segment::Definition + * @return A shared pointer to a new segment::ISegment */ - std::shared_ptr make_segment(const std::string& segment_name, - segment::IngressPortsBase ingress_ports, - segment::EgressPortsBase egress_ports, - segment::segment_initializer_fn_t segment_initializer); + virtual std::shared_ptr make_segment(const std::string& segment_name, + segment::IngressPortsBase ingress_ports, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t segment_initializer) = 0; /** * Create a segment definition, which describes how to create new Segment instances. @@ -109,11 +108,11 @@ class Pipeline final : public internal::pipeline::IPipeline * @param segment_name Unique name to assign to segments built from this definition * @param segment_initializer User defined lambda function which will be used to initialize * new segments. - * @return A shared pointer to a new segment::Definition + * @return A shared pointer to a new segment::ISegment */ - std::shared_ptr make_segment(const std::string& segment_name, - segment::IngressPortsBase ingress_ports, - segment::segment_initializer_fn_t segment_initializer); + virtual std::shared_ptr make_segment(const std::string& segment_name, + segment::IngressPortsBase ingress_ports, + segment::segment_initializer_fn_t segment_initializer) = 0; /** * Create a segment definition, which describes how to create new Segment instances. @@ -125,13 +124,18 @@ class Pipeline final : public internal::pipeline::IPipeline * @param segment_name Unique name to assign to segments built from this definition * @param segment_initializer User defined lambda function which will be used to initialize * new segments. - * @return A shared pointer to a new segment::Definition + * @return A shared pointer to a new segment::ISegment */ - std::shared_ptr make_segment(const std::string& segment_name, - segment::EgressPortsBase egress_ports, - segment::segment_initializer_fn_t segment_initializer); -}; + virtual std::shared_ptr make_segment(const std::string& segment_name, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t segment_initializer) = 0; -std::unique_ptr make_pipeline(); + protected: + IPipeline() = default; +}; } // namespace mrc::pipeline + +namespace mrc { +std::unique_ptr make_pipeline(); +} diff --git a/cpp/mrc/include/mrc/pipeline/segment.hpp b/cpp/mrc/include/mrc/pipeline/segment.hpp new file mode 100644 index 000000000..23dff2505 --- /dev/null +++ b/cpp/mrc/include/mrc/pipeline/segment.hpp @@ -0,0 +1,90 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. + */ + +#pragma once + +#include "mrc/segment/initializers.hpp" +#include "mrc/types.hpp" +#include "mrc/utils/macros.hpp" + +#include +#include +#include + +namespace mrc::segment { +struct EgressPortsBase; +struct IngressPortsBase; +} // namespace mrc::segment + +namespace mrc::pipeline { + +class ISegment +{ + public: + virtual ~ISegment() = default; + + DELETE_COPYABILITY(ISegment); + + virtual SegmentID id() const = 0; + virtual const std::string& name() const = 0; + virtual std::vector ingress_port_names() const = 0; + virtual std::vector egress_port_names() const = 0; + + protected: + ISegment() = default; +}; +} // namespace mrc::pipeline + +namespace mrc { + +// This helper class if for backwards compatibility only +class Segment final +{ + public: + static std::unique_ptr create(std::string name, + segment::IngressPortsBase ingress_ports, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t initializer); + + static std::unique_ptr create(std::string name, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t initializer); + + static std::unique_ptr create(std::string name, + segment::IngressPortsBase ingress_ports, + segment::segment_initializer_fn_t initializer); + + static std::unique_ptr create(std::string name, + segment::segment_initializer_fn_t initializer); +}; + +std::unique_ptr make_segment(std::string name, + segment::IngressPortsBase ingress_ports, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t initializer); + +std::unique_ptr make_segment(std::string name, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t initializer); + +std::unique_ptr make_segment(std::string name, + segment::IngressPortsBase ingress_ports, + segment::segment_initializer_fn_t initializer); + +std::unique_ptr make_segment(std::string name, segment::segment_initializer_fn_t initializer); + +} // namespace mrc diff --git a/cpp/mrc/include/mrc/engine/system/isystem.hpp b/cpp/mrc/include/mrc/pipeline/system.hpp similarity index 65% rename from cpp/mrc/include/mrc/engine/system/isystem.hpp rename to cpp/mrc/include/mrc/pipeline/system.hpp index bbe411899..b4a50697e 100644 --- a/cpp/mrc/include/mrc/engine/system/isystem.hpp +++ b/cpp/mrc/include/mrc/pipeline/system.hpp @@ -17,15 +17,16 @@ #pragma once +#include "mrc/utils/macros.hpp" + +#include #include namespace mrc { class Options; } // namespace mrc -namespace mrc::internal::system { - -class System; +namespace mrc::pipeline { /** * @brief System object @@ -37,12 +38,20 @@ class System; class ISystem { public: - ISystem(std::shared_ptr options); - virtual ~ISystem() = 0; + virtual ~ISystem() = default; + DELETE_COPYABILITY(ISystem); + + virtual const Options& options() const = 0; - private: - std::shared_ptr m_impl; - friend System; + virtual void add_thread_initializer(std::function initializer_fn) = 0; + virtual void add_thread_finalizer(std::function finalizer_fn) = 0; + + protected: + ISystem() = default; }; -} // namespace mrc::internal::system +} // namespace mrc::pipeline + +namespace mrc { +std::unique_ptr make_system(std::shared_ptr options = nullptr); +} diff --git a/cpp/mrc/include/mrc/runnable/engine.hpp b/cpp/mrc/include/mrc/runnable/engine.hpp index 3228cf084..1c8f95212 100644 --- a/cpp/mrc/include/mrc/runnable/engine.hpp +++ b/cpp/mrc/include/mrc/runnable/engine.hpp @@ -43,10 +43,10 @@ class Runner; /** * @brief Provides a one-time use method to execute a task on a supplied execution context */ -class Engine +class IEngine { public: - virtual ~Engine() = default; + virtual ~IEngine() = default; virtual EngineType engine_type() const = 0; @@ -60,15 +60,15 @@ class Engine * @brief Provides a set of Engines that * */ -class Engines +class IEngines { public: - virtual ~Engines() = default; + virtual ~IEngines() = default; - virtual const std::vector>& launchers() const = 0; - virtual const LaunchOptions& launch_options() const = 0; - virtual EngineType engine_type() const = 0; - virtual std::size_t size() const = 0; + virtual const std::vector>& launchers() const = 0; + virtual const LaunchOptions& launch_options() const = 0; + virtual EngineType engine_type() const = 0; + virtual std::size_t size() const = 0; }; } // namespace mrc::runnable diff --git a/cpp/mrc/include/mrc/runnable/engine_factory.hpp b/cpp/mrc/include/mrc/runnable/engine_factory.hpp index e3fc7dcbd..efb2995e9 100644 --- a/cpp/mrc/include/mrc/runnable/engine_factory.hpp +++ b/cpp/mrc/include/mrc/runnable/engine_factory.hpp @@ -38,7 +38,7 @@ struct EngineFactory { virtual ~EngineFactory() = default; virtual EngineType backend() const = 0; // todo(cpp20) constexpr virtual for the specific types - virtual std::shared_ptr build_engines(const LaunchOptions& launch_options) = 0; + virtual std::shared_ptr build_engines(const LaunchOptions& launch_options) = 0; }; } // namespace mrc::runnable diff --git a/cpp/mrc/include/mrc/runnable/forward.hpp b/cpp/mrc/include/mrc/runnable/forward.hpp index b3d282e35..1f999d19f 100644 --- a/cpp/mrc/include/mrc/runnable/forward.hpp +++ b/cpp/mrc/include/mrc/runnable/forward.hpp @@ -30,7 +30,7 @@ class FiberContext; template class ThreadContext; -class Engine; +class IEngine; class FiberEngine; class ThreadEngine; diff --git a/cpp/mrc/include/mrc/runnable/launch_control.hpp b/cpp/mrc/include/mrc/runnable/launch_control.hpp index 330267bf6..67371a218 100644 --- a/cpp/mrc/include/mrc/runnable/launch_control.hpp +++ b/cpp/mrc/include/mrc/runnable/launch_control.hpp @@ -101,7 +101,7 @@ class LaunchControl final // our launcher needs engines specific to the backend // engines are out way of running some task on the specified backend - std::shared_ptr engines = build_engines(options); + std::shared_ptr engines = build_engines(options); // make contexts std::vector> contexts; @@ -202,7 +202,7 @@ class LaunchControl final // our launcher needs engines specific to the backend // engines are out way of running some task on the specified backend - std::shared_ptr engines = build_engines(options); + std::shared_ptr engines = build_engines(options); // make contexts std::vector> contexts; @@ -281,7 +281,7 @@ class LaunchControl final // return config().default_options; // } - std::shared_ptr build_engines(const LaunchOptions& launch_options) const + std::shared_ptr build_engines(const LaunchOptions& launch_options) const { return get_engine_factory(launch_options.engine_factory_name).build_engines(launch_options); } @@ -325,7 +325,7 @@ class LaunchControl final * @return auto */ template - auto make_contexts(const Engines& engines, ArgsT&&... args) + auto make_contexts(const IEngines& engines, ArgsT&&... args) { const auto size = engines.size(); std::vector> contexts; diff --git a/cpp/mrc/include/mrc/runnable/launcher.hpp b/cpp/mrc/include/mrc/runnable/launcher.hpp index 4b799e30e..b7a40b1d1 100644 --- a/cpp/mrc/include/mrc/runnable/launcher.hpp +++ b/cpp/mrc/include/mrc/runnable/launcher.hpp @@ -26,7 +26,7 @@ namespace mrc::runnable { class Context; -class Engines; +class IEngines; class Runner; /** @@ -37,7 +37,7 @@ class Launcher final public: Launcher(std::unique_ptr runner, std::vector>&& contexts, - std::shared_ptr engines); + std::shared_ptr engines); ~Launcher(); @@ -61,7 +61,7 @@ class Launcher final private: std::unique_ptr m_runner; std::vector> m_contexts; - std::shared_ptr m_engines; + std::shared_ptr m_engines; std::mutex m_mutex; }; diff --git a/cpp/mrc/include/mrc/pipeline/resources.hpp b/cpp/mrc/include/mrc/runnable/runnable_resources.hpp similarity index 89% rename from cpp/mrc/include/mrc/pipeline/resources.hpp rename to cpp/mrc/include/mrc/runnable/runnable_resources.hpp index 25dfdfbd4..33df5459c 100644 --- a/cpp/mrc/include/mrc/pipeline/resources.hpp +++ b/cpp/mrc/include/mrc/runnable/runnable_resources.hpp @@ -22,15 +22,15 @@ #include "mrc/metrics/registry.hpp" #include "mrc/runnable/launch_control.hpp" -namespace mrc::pipeline { +namespace mrc::runnable { -struct Resources +struct IRunnableResources { - virtual ~Resources() = default; + virtual ~IRunnableResources() = default; virtual core::FiberTaskQueue& main() = 0; virtual runnable::LaunchControl& launch_control() = 0; // virtual std::shared_ptr metrics_registry() = 0; }; -} // namespace mrc::pipeline +} // namespace mrc::runnable diff --git a/cpp/mrc/include/mrc/runnable/runner.hpp b/cpp/mrc/include/mrc/runnable/runner.hpp index 3308f7256..c2539b601 100644 --- a/cpp/mrc/include/mrc/runnable/runner.hpp +++ b/cpp/mrc/include/mrc/runnable/runner.hpp @@ -157,7 +157,7 @@ class Runner Promise m_live_promise; SharedFuture m_live_future; SharedFuture m_join_future; - std::shared_ptr m_engine; + std::shared_ptr m_engine; std::shared_ptr m_context; friend class Runner; @@ -170,7 +170,7 @@ class Runner const std::vector& instances() const; protected: - void enqueue(std::shared_ptr, std::vector>&&); + void enqueue(std::shared_ptr, std::vector>&&); /** * @brief Access the const version of the Runnable @@ -221,7 +221,7 @@ class SpecializedRunner : public Runner ~SpecializedRunner() override = default; template - void enqueue(std::shared_ptr launcher, ArgsT&&... args) + void enqueue(std::shared_ptr launcher, ArgsT&&... args) { DCHECK(launcher && launcher->size()); @@ -241,7 +241,7 @@ class SpecializedRunner : public Runner protected: template - auto make_contexts(const Engines& launcher, ArgsT&&... args) + auto make_contexts(const IEngines& launcher, ArgsT&&... args) { const auto size = launcher.size(); std::vector> contexts; diff --git a/cpp/mrc/include/mrc/runtime/remote_descriptor.hpp b/cpp/mrc/include/mrc/runtime/remote_descriptor.hpp index 9fca56ce8..d84ff903a 100644 --- a/cpp/mrc/include/mrc/runtime/remote_descriptor.hpp +++ b/cpp/mrc/include/mrc/runtime/remote_descriptor.hpp @@ -26,9 +26,9 @@ #include #include -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { class Manager; -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor namespace mrc::runtime { @@ -118,7 +118,7 @@ class RemoteDescriptor final std::shared_ptr m_manager; std::unique_ptr m_handle; - friend internal::remote_descriptor::Manager; + friend remote_descriptor::Manager; }; } // namespace mrc::runtime diff --git a/cpp/mrc/include/mrc/segment/builder.hpp b/cpp/mrc/include/mrc/segment/builder.hpp index 7daf94af0..a35f571c9 100644 --- a/cpp/mrc/include/mrc/segment/builder.hpp +++ b/cpp/mrc/include/mrc/segment/builder.hpp @@ -19,7 +19,6 @@ #include "mrc/benchmarking/trace_statistics.hpp" #include "mrc/edge/edge_builder.hpp" -#include "mrc/engine/segment/ibuilder.hpp" #include "mrc/exceptions/runtime_error.hpp" #include "mrc/node/rx_node.hpp" #include "mrc/node/rx_sink.hpp" @@ -80,14 +79,14 @@ namespace { namespace hana = boost::hana; template -auto has_source_add_watcher = - hana::is_valid([](auto&& thing) -> decltype(std::forward(thing).source_add_watcher( - std::declval>())) {}); +auto has_source_add_watcher = hana::is_valid( + [](auto&& thing) -> decltype(std::forward(thing).source_add_watcher( + std::declval>())) {}); template -auto has_sink_add_watcher = - hana::is_valid([](auto&& thing) -> decltype(std::forward(thing).sink_add_watcher( - std::declval>())) {}); +auto has_sink_add_watcher = hana::is_valid( + [](auto&& thing) -> decltype(std::forward(thing).sink_add_watcher( + std::declval>())) {}); template void add_stats_watcher_if_rx_source(T& thing, std::string name) @@ -116,30 +115,87 @@ void add_stats_watcher_if_rx_sink(T& thing, std::string name) namespace mrc::segment { -class Builder final +class IBuilder { - Builder(internal::segment::IBuilder& backend) : m_backend(backend) {} - public: - DELETE_COPYABILITY(Builder); - DELETE_MOVEABILITY(Builder); + IBuilder() = default; + virtual ~IBuilder() = default; - std::shared_ptr get_ingress(std::string name, std::type_index type_index); + DELETE_COPYABILITY(IBuilder); - std::shared_ptr get_egress(std::string name, std::type_index type_index); + virtual const std::string& name() const = 0; - template - std::shared_ptr>> get_egress(std::string name); + /** + * @brief Takes either a local or global object name and returns the global name and local name separately. Global + * names contain '///' (leading '/') where local names are + * '/' (no leading '/') + * + * @param name Name to normalize + * @param ignore_namespace Whether or not to ignore the '' portion. Useful for ports. + * @return std::tuple Global name, Local name + */ + virtual std::tuple normalize_name(const std::string& name, + bool ignore_namespace = false) const = 0; - template - std::shared_ptr>> get_ingress(std::string name); + virtual std::shared_ptr get_ingress(std::string name, std::type_index type_index) = 0; - template - std::shared_ptr> make_object(std::string name, std::unique_ptr node); + virtual std::shared_ptr get_egress(std::string name, std::type_index type_index) = 0; + + /** + * Initialize a SegmentModule that was instantiated outside of the builder. + * @param module Module to initialize + */ + virtual void init_module(std::shared_ptr smodule) = 0; + + /** + * Register an input port on the given module -- note: this in generally only necessary for dynamically + * created modules that use an alternate initializer function independent of the derived class. + * See: PythonSegmentModule + * @param input_name Unique name of the input port + * @param object shared pointer to type erased Object associated with 'input_name' on this module instance. + */ + virtual void register_module_input(std::string input_name, std::shared_ptr object) = 0; + + /** + * Get the json configuration for the current module under configuration. + * @return nlohmann::json object. + */ + virtual nlohmann::json get_current_module_config() = 0; + + /** + * Register an output port on the given module -- note: this in generally only necessary for dynamically + * created modules that use an alternate initializer function independent of the derived class. + * See: PythonSegmentModule + * @param output_name Unique name of the output port + * @param object shared pointer to type erased Object associated with 'output_name' on this module instance. + */ + virtual void register_module_output(std::string output_name, std::shared_ptr object) = 0; + + /** + * Load an existing, registered module, initialize it, and return it to the caller + * @param module_id Unique ID of the module to load + * @param registry_namespace Namespace where the module id is registered + * @param module_name Unique name of this instance of the module + * @param config Configuration to pass to the module + * @return Return a shared pointer to the new module, which is a derived class of SegmentModule + */ + virtual std::shared_ptr load_module_from_registry(const std::string& module_id, + const std::string& registry_namespace, + std::string module_name, + nlohmann::json config = {}) = 0; template std::shared_ptr> construct_object(std::string name, ArgsT&&... args); + template + std::shared_ptr> make_object(std::string name, std::unique_ptr node); + + template + std::shared_ptr>> get_egress(std::string name); + + template + std::shared_ptr>> get_ingress(std::string name); + /** * Create a source node using the provided name and function, the function is lifted to an observable * @tparam SourceTypeT the type of data produced by the source @@ -248,49 +304,6 @@ class Builder final template std::shared_ptr make_module(std::string module_name, nlohmann::json config = {}); - /** - * Initialize a SegmentModule that was instantiated outside of the builder. - * @param module Module to initialize - */ - void init_module(std::shared_ptr smodule); - - /** - * Register an input port on the given module -- note: this in generally only necessary for dynamically - * created modules that use an alternate initializer function independent of the derived class. - * See: PythonSegmentModule - * @param input_name Unique name of the input port - * @param object shared pointer to type erased Object associated with 'input_name' on this module instance. - */ - void register_module_input(std::string input_name, std::shared_ptr object); - - /** - * Get the json configuration for the current module under configuration. - * @return nlohmann::json object. - */ - nlohmann::json get_current_module_config(); - - /** - * Register an output port on the given module -- note: this in generally only necessary for dynamically - * created modules that use an alternate initializer function independent of the derived class. - * See: PythonSegmentModule - * @param output_name Unique name of the output port - * @param object shared pointer to type erased Object associated with 'output_name' on this module instance. - */ - void register_module_output(std::string output_name, std::shared_ptr object); - - /** - * Load an existing, registered module, initialize it, and return it to the caller - * @param module_id Unique ID of the module to load - * @param registry_namespace Namespace where the module id is registered - * @param module_name Unique name of this instance of the module - * @param config Configuration to pass to the module - * @return Return a shared pointer to the new module, which is a derived class of SegmentModule - */ - std::shared_ptr load_module_from_registry(const std::string& module_id, - const std::string& registry_namespace, - std::string module_name, - nlohmann::json config = {}); - /** * Create an edge between two things that are convertible to ObjectProperties * @tparam SourceNodeTypeT Type hint for the source node -- optional -- this will be used if the type of the source @@ -332,44 +345,57 @@ class Builder final SpliceOutputObjectT splice_output); template - void add_throughput_counter(std::shared_ptr> segment_object); + void add_throughput_counter(std::shared_ptr> segment_object); template - void add_throughput_counter(std::shared_ptr> segment_object, CallableT&& callable); + void add_throughput_counter(std::shared_ptr> segment_object, CallableT&& callable); private: - using sp_segment_module_t = std::shared_ptr; - - std::string m_namespace_prefix; - std::vector m_namespace_stack{}; - std::vector m_module_stack{}; - - internal::segment::IBuilder& m_backend; - - void ns_push(sp_segment_module_t smodule); - - void ns_pop(); + virtual ObjectProperties& find_object(const std::string& name) = 0; + virtual void add_object(const std::string& name, std::shared_ptr object) = 0; + virtual std::shared_ptr get_ingress_base(const std::string& name) = 0; + virtual std::shared_ptr get_egress_base(const std::string& name) = 0; + virtual std::function make_throughput_counter(const std::string& name) = 0; template ObjectProperties& to_object_properties(ObjectReprT& repr); - - friend Definition; }; template -std::shared_ptr> Builder::construct_object(std::string name, ArgsT&&... args) +std::shared_ptr> IBuilder::construct_object(std::string name, ArgsT&&... args) { - auto ns_name = m_namespace_prefix.empty() ? name : m_namespace_prefix + "/" + name; - auto uptr = std::make_unique(std::forward(args)...); + auto uptr = std::make_unique(std::forward(args)...); - ::add_stats_watcher_if_rx_source(*uptr, ns_name); - ::add_stats_watcher_if_rx_sink(*uptr, ns_name); + return make_object(std::move(name), std::move(uptr)); +} - return make_object(std::move(ns_name), std::move(uptr)); +template +std::shared_ptr> IBuilder::make_object(std::string name, std::unique_ptr node) +{ + std::shared_ptr> segment_object{nullptr}; + + if constexpr (std::is_base_of_v) + { + segment_object = std::make_shared>(std::move(node)); + this->add_object(name, segment_object); + } + else + { + segment_object = std::make_shared>(std::move(node)); + this->add_object(name, segment_object); + } + + CHECK(segment_object); + + // Now that we have been added, set the stats watchers using the object name + ::add_stats_watcher_if_rx_source(segment_object->object(), segment_object->name()); + ::add_stats_watcher_if_rx_sink(segment_object->object(), segment_object->name()); + + return segment_object; } template class NodeTypeT, typename CreateFnT> -auto Builder::make_source(std::string name, CreateFnT&& create_fn) +auto IBuilder::make_source(std::string name, CreateFnT&& create_fn) { return construct_object>( name, @@ -377,25 +403,25 @@ auto Builder::make_source(std::string name, CreateFnT&& create_fn) } template class NodeTypeT> -auto Builder::make_source(std::string name, rxcpp::observable obs) +auto IBuilder::make_source(std::string name, rxcpp::observable obs) { return construct_object>(name, obs); } template class NodeTypeT, typename... ArgsT> -auto Builder::make_sink(std::string name, ArgsT&&... ops) +auto IBuilder::make_sink(std::string name, ArgsT&&... ops) { return construct_object>(name, rxcpp::make_observer(std::forward(ops)...)); } template class NodeTypeT, typename... ArgsT> -auto Builder::make_sink_component(std::string name, ArgsT&&... ops) +auto IBuilder::make_sink_component(std::string name, ArgsT&&... ops) { return construct_object>(name, rxcpp::make_observer(std::forward(ops)...)); } template class NodeTypeT, typename... ArgsT> -auto Builder::make_node(std::string name, ArgsT&&... ops) +auto IBuilder::make_node(std::string name, ArgsT&&... ops) { return construct_object>(name, std::forward(ops)...); } @@ -405,19 +431,19 @@ template class NodeTypeT, typename... ArgsT> -auto Builder::make_node(std::string name, ArgsT&&... ops) +auto IBuilder::make_node(std::string name, ArgsT&&... ops) { return construct_object>(name, std::forward(ops)...); } template class NodeTypeT, typename... ArgsT> -auto Builder::make_node_component(std::string name, ArgsT&&... ops) +auto IBuilder::make_node_component(std::string name, ArgsT&&... ops) { return construct_object>(name, std::forward(ops)...); } template -std::shared_ptr Builder::make_module(std::string module_name, nlohmann::json config) +std::shared_ptr IBuilder::make_module(std::string module_name, nlohmann::json config) { static_assert(std::is_base_of_v); @@ -428,7 +454,7 @@ std::shared_ptr Builder::make_module(std::string module_name, nlohm } template -void Builder::make_edge(SourceObjectT source, SinkObjectT sink) +void IBuilder::make_edge(SourceObjectT source, SinkObjectT sink) { DVLOG(10) << "forming edge between two segment objects"; @@ -473,10 +499,10 @@ template -void Builder::splice_edge(SourceObjectT source, - SinkObjectT sink, - SpliceInputObjectT splice_input, - SpliceOutputObjectT splice_output) +void IBuilder::splice_edge(SourceObjectT source, + SinkObjectT sink, + SpliceInputObjectT splice_input, + SpliceOutputObjectT splice_output) { auto& source_object = to_object_properties(source); @@ -539,42 +565,10 @@ void Builder::splice_edge(SourceObjectT source, throw std::runtime_error("Attempt to splice unsupported edge types"); } -template -std::shared_ptr> Builder::make_object(std::string name, std::unique_ptr node) -{ - // Note: name should have any prefix modifications done prior to getting here. - if (m_backend.has_object(name)) - { - LOG(ERROR) << "A Object named " << name << " is already registered"; - throw exceptions::MrcRuntimeError("duplicate name detected - name owned by a node"); - } - - std::shared_ptr> segment_object{nullptr}; - - if constexpr (std::is_base_of_v) - { - auto segment_name = m_backend.name() + "/" + name; - auto segment_node = std::make_shared>(segment_name, std::move(node)); - - m_backend.add_runnable(name, segment_node); - m_backend.add_object(name, segment_node); - segment_object = segment_node; - } - else - { - auto segment_node = std::make_shared>(std::move(node)); - m_backend.add_object(name, segment_node); - segment_object = segment_node; - } - - CHECK(segment_object); - return segment_object; -} - template -std::shared_ptr>> Builder::get_egress(std::string name) +std::shared_ptr>> IBuilder::get_egress(std::string name) { - auto base = m_backend.get_egress_base(name); + auto base = this->get_egress_base(name); if (!base) { throw exceptions::MrcRuntimeError("Egress port name not found: " + name); @@ -590,9 +584,9 @@ std::shared_ptr>> Builder::get_egress(std::string nam } template -std::shared_ptr>> Builder::get_ingress(std::string name) +std::shared_ptr>> IBuilder::get_ingress(std::string name) { - auto base = m_backend.get_ingress_base(name); + auto base = this->get_ingress_base(name); if (!base) { throw exceptions::MrcRuntimeError("Ingress port name not found: " + name); @@ -608,20 +602,20 @@ std::shared_ptr>> Builder::get_ingress(std::string } template -void Builder::add_throughput_counter(std::shared_ptr> segment_object) +void IBuilder::add_throughput_counter(std::shared_ptr> segment_object) { auto runnable = std::dynamic_pointer_cast>(segment_object); CHECK(runnable); CHECK(segment_object->is_source()); using source_type_t = typename ObjectT::source_type_t; - auto counter = m_backend.make_throughput_counter(runnable->name()); + auto counter = this->make_throughput_counter(runnable->name()); runnable->object().add_epilogue_tap([counter](const source_type_t& data) { counter(1); }); } template -void Builder::add_throughput_counter(std::shared_ptr> segment_object, CallableT&& callable) +void IBuilder::add_throughput_counter(std::shared_ptr> segment_object, CallableT&& callable) { auto runnable = std::dynamic_pointer_cast>(segment_object); CHECK(runnable); @@ -629,7 +623,7 @@ void Builder::add_throughput_counter(std::shared_ptr> s using source_type_t = typename ObjectT::source_type_t; using tick_fn_t = std::function; tick_fn_t tick_fn = callable; - auto counter = m_backend.make_throughput_counter(runnable->name()); + auto counter = this->make_throughput_counter(runnable->name()); runnable->object().add_epilogue_tap([counter, tick_fn](const source_type_t& data) { counter(tick_fn(data)); }); @@ -637,7 +631,7 @@ void Builder::add_throughput_counter(std::shared_ptr> s /* Private Member Functions */ template -ObjectProperties& Builder::to_object_properties(ObjectReprT& repr) +ObjectProperties& IBuilder::to_object_properties(ObjectReprT& repr) { ObjectProperties* object_properties_ptr{nullptr}; if constexpr (is_shared_ptr_v) @@ -670,7 +664,7 @@ ObjectProperties& Builder::to_object_properties(ObjectReprT& repr) // String-like lookup else { - object_properties_ptr = std::addressof(m_backend.find_object(repr)); + object_properties_ptr = std::addressof(this->find_object(repr)); } CHECK(object_properties_ptr != nullptr) << "If this fails, something is wrong with the concept definition"; @@ -678,4 +672,7 @@ ObjectProperties& Builder::to_object_properties(ObjectReprT& repr) return *object_properties_ptr; } +// For backwards compatibility, make a type alias to `Builder` +using Builder = IBuilder; // NOLINT(readability-identifier-naming) + } // namespace mrc::segment diff --git a/cpp/mrc/include/mrc/segment/definition.hpp b/cpp/mrc/include/mrc/segment/definition.hpp deleted file mode 100644 index e7affa9e4..000000000 --- a/cpp/mrc/include/mrc/segment/definition.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include "mrc/engine/segment/idefinition.hpp" -#include "mrc/segment/initializers.hpp" -#include "mrc/utils/macros.hpp" - -#include -#include -#include - -namespace mrc::segment { -struct EgressPortsBase; -struct IngressPortsBase; - -class Definition final : public internal::segment::IDefinition -{ - private: - Definition(std::string name, - std::map ingress_ports, - std::map egress_ports, - backend_initializer_fn_t backend_initializer); - - static std::shared_ptr create(std::string name, - std::map ingress_initializers, - std::map egress_initializers, - segment_initializer_fn_t initializer); - - public: - ~Definition() final = default; - - DELETE_COPYABILITY(Definition); - DELETE_MOVEABILITY(Definition); - - static std::shared_ptr create(std::string name, - IngressPortsBase ingress_ports, - EgressPortsBase egress_ports, - segment_initializer_fn_t initializer); - - static std::shared_ptr create(std::string name, - EgressPortsBase egress_ports, - segment_initializer_fn_t initializer); - - static std::shared_ptr create(std::string name, - IngressPortsBase ingress_ports, - segment_initializer_fn_t initializer); - - static std::shared_ptr create(std::string name, segment_initializer_fn_t initializer); -}; - -} // namespace mrc::segment diff --git a/cpp/mrc/include/mrc/segment/egress_port.hpp b/cpp/mrc/include/mrc/segment/egress_port.hpp index 32bb51ba8..7fe52a5ce 100644 --- a/cpp/mrc/include/mrc/segment/egress_port.hpp +++ b/cpp/mrc/include/mrc/segment/egress_port.hpp @@ -40,11 +40,11 @@ namespace mrc::segment { -class Instance; +class SegmentInstance; class EgressPortBase : public runnable::Launchable, public manifold::Connectable, public virtual ObjectProperties { - friend Instance; + friend SegmentInstance; }; template @@ -62,9 +62,7 @@ class EgressPort final : public Object>, m_segment_address(address), m_port_name(std::move(name)), m_sink(std::make_unique>()) - { - this->set_name(m_port_name); - } + {} private: node::RxSinkBase* get_object() const final @@ -81,7 +79,7 @@ class EgressPort final : public Object>, return launch_control.prepare_launcher(std::move(m_sink)); } - std::shared_ptr make_manifold(pipeline::Resources& resources) final + std::shared_ptr make_manifold(runnable::IRunnableResources& resources) final { return manifold::Factory::make_manifold(m_port_name, resources); } diff --git a/cpp/mrc/include/mrc/segment/forward.hpp b/cpp/mrc/include/mrc/segment/forward.hpp index 3d4ce39c6..7ce590512 100644 --- a/cpp/mrc/include/mrc/segment/forward.hpp +++ b/cpp/mrc/include/mrc/segment/forward.hpp @@ -20,7 +20,7 @@ namespace mrc::segment { class Definition; -class Builder; +class IBuilder; class ObjectProperties; diff --git a/cpp/mrc/include/mrc/segment/ingress_port.hpp b/cpp/mrc/include/mrc/segment/ingress_port.hpp index 589fad28a..fec6d469e 100644 --- a/cpp/mrc/include/mrc/segment/ingress_port.hpp +++ b/cpp/mrc/include/mrc/segment/ingress_port.hpp @@ -36,11 +36,11 @@ namespace mrc::segment { -class Instance; +class SegmentInstance; struct IngressPortBase : public runnable::Launchable, public manifold::Connectable, public virtual ObjectProperties { - friend Instance; + friend SegmentInstance; }; template @@ -56,9 +56,7 @@ class IngressPort : public Object>, public IngressPortBase m_segment_address(address), m_port_name(std::move(name)), m_source(std::make_unique>()) - { - this->set_name(m_port_name); - } + {} private: node::RxSourceBase* get_object() const final @@ -74,7 +72,7 @@ class IngressPort : public Object>, public IngressPortBase return launch_control.prepare_launcher(std::move(m_source)); } - std::shared_ptr make_manifold(pipeline::Resources& resources) final + std::shared_ptr make_manifold(runnable::IRunnableResources& resources) final { return manifold::Factory::make_manifold(m_port_name, resources); } @@ -92,7 +90,7 @@ class IngressPort : public Object>, public IngressPortBase std::unique_ptr> m_source; std::mutex m_mutex; - friend Instance; + friend SegmentInstance; }; } // namespace mrc::segment diff --git a/cpp/mrc/include/mrc/segment/initializers.hpp b/cpp/mrc/include/mrc/segment/initializers.hpp index d7cf8c7c0..14a124552 100644 --- a/cpp/mrc/include/mrc/segment/initializers.hpp +++ b/cpp/mrc/include/mrc/segment/initializers.hpp @@ -17,22 +17,20 @@ #pragma once -#include "mrc/engine/segment/ibuilder.hpp" #include "mrc/segment/forward.hpp" // IWYU pragma: export #include "mrc/types.hpp" #include #include -namespace mrc::internal::segment { +namespace mrc::segment { class IBuilder; } namespace mrc::segment { -using segment_initializer_fn_t = std::function; +using segment_initializer_fn_t = std::function; using egress_initializer_t = std::function(const SegmentAddress&)>; using ingress_initializer_t = std::function(const SegmentAddress&)>; -using backend_initializer_fn_t = std::function; } // namespace mrc::segment diff --git a/cpp/mrc/include/mrc/segment/object.hpp b/cpp/mrc/include/mrc/segment/object.hpp index 1cfba010e..2ccc80094 100644 --- a/cpp/mrc/include/mrc/segment/object.hpp +++ b/cpp/mrc/include/mrc/segment/object.hpp @@ -38,8 +38,9 @@ struct ObjectProperties { virtual ~ObjectProperties() = 0; - virtual std::string name() const = 0; - virtual std::string type_name() const = 0; + virtual void set_name(const std::string& name) = 0; + virtual std::string name() const = 0; + virtual std::string type_name() const = 0; virtual bool is_sink() const = 0; virtual bool is_source() const = 0; @@ -198,7 +199,8 @@ class Object : public virtual ObjectProperties } protected: - void set_name(const std::string& name); + // Move to protected to allow only the IBuilder to set the name + void set_name(const std::string& name) override; private: std::string m_name{}; diff --git a/cpp/mrc/include/mrc/segment/ports.hpp b/cpp/mrc/include/mrc/segment/ports.hpp index a723558aa..4f4807e75 100644 --- a/cpp/mrc/include/mrc/segment/ports.hpp +++ b/cpp/mrc/include/mrc/segment/ports.hpp @@ -36,6 +36,8 @@ class Ports public: using port_builder_fn_t = std::function(const SegmentAddress&, const PortName&)>; + Ports() = default; + Ports(std::vector names, std::vector builder_fns) { if (names.size() != builder_fns.size()) @@ -71,9 +73,16 @@ class Ports } private: + const std::map(const SegmentAddress&)>>& get_initializers() const + { + return m_initializers; + } + std::vector m_names; std::map(const SegmentAddress&)>> m_initializers; + friend Definition; + friend class SegmentDefinition; }; } // namespace mrc::segment diff --git a/cpp/mrc/include/mrc/segment/runnable.hpp b/cpp/mrc/include/mrc/segment/runnable.hpp index aac15359b..ab5b590ca 100644 --- a/cpp/mrc/include/mrc/segment/runnable.hpp +++ b/cpp/mrc/include/mrc/segment/runnable.hpp @@ -38,18 +38,12 @@ class Runnable : public Object, public runnable::Launchable { public: template - Runnable(std::string name, ArgsT&&... args) : m_node(std::make_unique(std::forward(args)...)) - { - // Set the name in the Object class - this->set_name(std::move(name)); - } + Runnable(ArgsT&&... args) : m_node(std::make_unique(std::forward(args)...)) + {} - Runnable(std::string name, std::unique_ptr node) : m_node(std::move(node)) + Runnable(std::unique_ptr node) : m_node(std::move(node)) { CHECK(m_node); - - // Set the name in the Object class - this->set_name(std::move(name)); } private: diff --git a/cpp/mrc/include/mrc/segment/segment.hpp b/cpp/mrc/include/mrc/segment/segment.hpp deleted file mode 100644 index f6941b8e1..000000000 --- a/cpp/mrc/include/mrc/segment/segment.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include "mrc/core/addresses.hpp" -#include "mrc/segment/builder.hpp" -#include "mrc/segment/definition.hpp" -#include "mrc/segment/egress_ports.hpp" -#include "mrc/segment/forward.hpp" -#include "mrc/segment/ingress_ports.hpp" - -namespace mrc { - -class Segment final -{ - public: - template - static std::shared_ptr create(std::string name, ArgsT&&... args) - { - return segment::Definition::create(std::move(name), std::forward(args)...); - } -}; - -} // namespace mrc diff --git a/cpp/mrc/src/internal/codable/codable_storage.cpp b/cpp/mrc/src/internal/codable/codable_storage.cpp index 41e7292f7..c59a274a0 100644 --- a/cpp/mrc/src/internal/codable/codable_storage.cpp +++ b/cpp/mrc/src/internal/codable/codable_storage.cpp @@ -17,13 +17,13 @@ #include "internal/codable/codable_storage.hpp" -#include "internal/data_plane/resources.hpp" +#include "internal/data_plane/data_plane_resources.hpp" #include "internal/memory/host_resources.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/resources/partition_resources.hpp" #include "internal/ucx/memory_block.hpp" #include "internal/ucx/registration_cache.hpp" -#include "internal/ucx/resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "mrc/codable/memory.hpp" #include "mrc/cuda/common.hpp" @@ -43,7 +43,7 @@ using namespace mrc::memory::literals; -namespace mrc::internal::codable { +namespace mrc::codable { CodableStorage::CodableStorage(resources::PartitionResources& resources) : m_resources(resources) {} CodableStorage::CodableStorage(mrc::codable::protos::EncodedObject proto, resources::PartitionResources& resources) : @@ -221,4 +221,4 @@ CodableStorage::idx_t CodableStorage::add_meta_data(const google::protobuf::Mess return index; } -} // namespace mrc::internal::codable +} // namespace mrc::codable diff --git a/cpp/mrc/src/internal/codable/codable_storage.hpp b/cpp/mrc/src/internal/codable/codable_storage.hpp index 627e7981e..14931ea24 100644 --- a/cpp/mrc/src/internal/codable/codable_storage.hpp +++ b/cpp/mrc/src/internal/codable/codable_storage.hpp @@ -36,16 +36,16 @@ namespace google::protobuf { class Message; } // namespace google::protobuf -namespace mrc::internal::resources { +namespace mrc::resources { class PartitionResources; // IWYU pragma: keep -} // namespace mrc::internal::resources -namespace mrc::internal::ucx { +} // namespace mrc::resources +namespace mrc::ucx { struct MemoryBlock; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx // IWYU pragma: no_include "internal/resources/partition_resources.hpp" -namespace mrc::internal::codable { +namespace mrc::codable { /** * @brief CodableStorage implements both the IEncodableStorage and the IDecodableStorage interfaces @@ -118,4 +118,4 @@ class CodableStorage final : public mrc::codable::ICodableStorage, public Storag mutable std::mutex m_mutex; }; -} // namespace mrc::internal::codable +} // namespace mrc::codable diff --git a/cpp/mrc/src/internal/codable/decodable_storage_view.cpp b/cpp/mrc/src/internal/codable/decodable_storage_view.cpp index aae42e1ad..a4db24dac 100644 --- a/cpp/mrc/src/internal/codable/decodable_storage_view.cpp +++ b/cpp/mrc/src/internal/codable/decodable_storage_view.cpp @@ -18,11 +18,11 @@ #include "internal/codable/decodable_storage_view.hpp" #include "internal/data_plane/client.hpp" +#include "internal/data_plane/data_plane_resources.hpp" #include "internal/data_plane/request.hpp" -#include "internal/data_plane/resources.hpp" #include "internal/memory/device_resources.hpp" #include "internal/memory/host_resources.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/resources/partition_resources.hpp" #include "internal/ucx/endpoint.hpp" #include "internal/ucx/remote_registration_cache.hpp" @@ -39,7 +39,7 @@ #include #include -namespace mrc::internal::codable { +namespace mrc::codable { std::size_t DecodableStorageView::buffer_size(const idx_t& idx) const { @@ -163,4 +163,4 @@ std::shared_ptr DecodableStorageView::device_memor return nullptr; } -} // namespace mrc::internal::codable +} // namespace mrc::codable diff --git a/cpp/mrc/src/internal/codable/decodable_storage_view.hpp b/cpp/mrc/src/internal/codable/decodable_storage_view.hpp index f6951ac84..8e07cd797 100644 --- a/cpp/mrc/src/internal/codable/decodable_storage_view.hpp +++ b/cpp/mrc/src/internal/codable/decodable_storage_view.hpp @@ -29,7 +29,7 @@ class buffer_view; struct memory_resource; } // namespace mrc::memory -namespace mrc::internal::codable { +namespace mrc::codable { /** * @brief Storage implements the IDecodableStorage interface for an EncodedObject/Storage @@ -53,4 +53,4 @@ class DecodableStorageView : public virtual mrc::codable::IDecodableStorage, pub std::shared_ptr device_memory_resource() const final; }; -} // namespace mrc::internal::codable +} // namespace mrc::codable diff --git a/cpp/mrc/src/internal/codable/storage_resources.hpp b/cpp/mrc/src/internal/codable/storage_resources.hpp index 8733ba498..62ed0c651 100644 --- a/cpp/mrc/src/internal/codable/storage_resources.hpp +++ b/cpp/mrc/src/internal/codable/storage_resources.hpp @@ -19,7 +19,7 @@ #include "internal/resources/forward.hpp" -namespace mrc::internal::codable { +namespace mrc::codable { struct IStorageResources { @@ -27,4 +27,4 @@ struct IStorageResources virtual resources::PartitionResources& resources() const = 0; }; -} // namespace mrc::internal::codable +} // namespace mrc::codable diff --git a/cpp/mrc/src/internal/codable/storage_view.cpp b/cpp/mrc/src/internal/codable/storage_view.cpp index 353cfea98..3ae474ad7 100644 --- a/cpp/mrc/src/internal/codable/storage_view.cpp +++ b/cpp/mrc/src/internal/codable/storage_view.cpp @@ -22,7 +22,7 @@ #include #include -namespace mrc::internal::codable { +namespace mrc::codable { const mrc::codable::protos::EncodedObject& StorageView::proto() const { @@ -62,4 +62,4 @@ std::optional StorageView::parent_obj_idx_for_object(con return parent_object_idx; } -} // namespace mrc::internal::codable +} // namespace mrc::codable diff --git a/cpp/mrc/src/internal/codable/storage_view.hpp b/cpp/mrc/src/internal/codable/storage_view.hpp index aff6b7954..a39259266 100644 --- a/cpp/mrc/src/internal/codable/storage_view.hpp +++ b/cpp/mrc/src/internal/codable/storage_view.hpp @@ -23,7 +23,7 @@ #include #include -namespace mrc::internal::codable { +namespace mrc::codable { /** * @brief StorageView implements the methods on IEncodedObject with a reference to a protos::EncodedObject as the @@ -56,4 +56,4 @@ class StorageView : public virtual mrc::codable::IStorage virtual const mrc::codable::protos::EncodedObject& get_proto() const = 0; }; -} // namespace mrc::internal::codable +} // namespace mrc::codable diff --git a/cpp/mrc/src/internal/control_plane/client.cpp b/cpp/mrc/src/internal/control_plane/client.cpp index 716b39dcd..7a85adc2e 100644 --- a/cpp/mrc/src/internal/control_plane/client.cpp +++ b/cpp/mrc/src/internal/control_plane/client.cpp @@ -20,7 +20,7 @@ #include "internal/control_plane/client/connections_manager.hpp" #include "internal/grpc/progress_engine.hpp" #include "internal/grpc/promise_handler.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/system/system.hpp" #include "mrc/channel/status.hpp" @@ -35,14 +35,12 @@ #include "mrc/runnable/runner.hpp" #include -#include #include -#include #include #include -namespace mrc::internal::control_plane { +namespace mrc::control_plane { Client::Client(resources::PartitionResourceBase& base, std::shared_ptr cq) : resources::PartitionResourceBase(base), @@ -193,7 +191,7 @@ void Client::do_handle_event(event_t&& event) } std::map> Client::register_ucx_addresses( - std::vector>& ucx_resources) + std::vector>& ucx_resources) { forward_state(State::RegisteringWorkers); auto instances = m_connections_manager->register_ucx_addresses(ucx_resources); @@ -262,4 +260,4 @@ void Client::request_update() // } } -} // namespace mrc::internal::control_plane +} // namespace mrc::control_plane diff --git a/cpp/mrc/src/internal/control_plane/client.hpp b/cpp/mrc/src/internal/control_plane/client.hpp index 677730909..0a07991a6 100644 --- a/cpp/mrc/src/internal/control_plane/client.hpp +++ b/cpp/mrc/src/internal/control_plane/client.hpp @@ -51,21 +51,21 @@ namespace grpc { class Channel; class CompletionQueue; } // namespace grpc -namespace mrc::internal::control_plane::client { +namespace mrc::control_plane::client { class ConnectionsManager; class SubscriptionService; -} // namespace mrc::internal::control_plane::client -namespace mrc::internal::network { -class Resources; -} // namespace mrc::internal::network -namespace mrc::internal::ucx { -class Resources; -} // namespace mrc::internal::ucx +} // namespace mrc::control_plane::client +namespace mrc::network { +class NetworkResources; +} // namespace mrc::network +namespace mrc::ucx { +class UcxResources; +} // namespace mrc::ucx namespace mrc::runnable { class Runner; } // namespace mrc::runnable -namespace mrc::internal::control_plane { +namespace mrc::control_plane { template class AsyncStatus; @@ -119,7 +119,7 @@ class Client final : public resources::PartitionResourceBase, public Service // const std::vector& instance_ids() const; std::map> register_ucx_addresses( - std::vector>& ucx_resources); + std::vector>& ucx_resources); // void register_port_publisher(InstanceID instance_id, const std::string& port_name); // void register_port_subscriber(InstanceID instance_id, const std::string& port_name); @@ -201,7 +201,7 @@ class Client final : public resources::PartitionResourceBase, public Service std::mutex m_mutex; - friend network::Resources; + friend network::NetworkResources; }; // todo: create this object from the client which will own the stop_source @@ -267,4 +267,4 @@ void Client::issue_event(const protos::EventType& event_type, MessageT&& message m_writer->await_write(std::move(event)); } -} // namespace mrc::internal::control_plane +} // namespace mrc::control_plane diff --git a/cpp/mrc/src/internal/control_plane/client/connections_manager.cpp b/cpp/mrc/src/internal/control_plane/client/connections_manager.cpp index 23192e7ed..76cc2477e 100644 --- a/cpp/mrc/src/internal/control_plane/client/connections_manager.cpp +++ b/cpp/mrc/src/internal/control_plane/client/connections_manager.cpp @@ -19,8 +19,8 @@ #include "internal/control_plane/client.hpp" #include "internal/control_plane/client/instance.hpp" -#include "internal/runnable/resources.hpp" -#include "internal/ucx/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "internal/ucx/worker.hpp" #include "internal/utils/contains.hpp" @@ -38,7 +38,7 @@ #include #include -namespace mrc::internal::control_plane::client { +namespace mrc::control_plane::client { ConnectionsManager::ConnectionsManager(Client& client, update_channel_t& update_channel) : StateManager(client) { @@ -57,7 +57,7 @@ const std::vector& ConnectionsManager::instance_ids() const } std::map> ConnectionsManager::register_ucx_addresses( - std::vector>& ucx_resources) + std::vector>& ucx_resources) { CHECK(client().state() == Client::State::RegisteringWorkers); @@ -187,4 +187,4 @@ const std::map return m_update_channels; } -} // namespace mrc::internal::control_plane::client +} // namespace mrc::control_plane::client diff --git a/cpp/mrc/src/internal/control_plane/client/connections_manager.hpp b/cpp/mrc/src/internal/control_plane/client/connections_manager.hpp index 7d096b3bf..8c1015c92 100644 --- a/cpp/mrc/src/internal/control_plane/client/connections_manager.hpp +++ b/cpp/mrc/src/internal/control_plane/client/connections_manager.hpp @@ -29,14 +29,14 @@ #include #include -namespace mrc::internal::control_plane { +namespace mrc::control_plane { class Client; -} // namespace mrc::internal::control_plane -namespace mrc::internal::ucx { -class Resources; -} // namespace mrc::internal::ucx +} // namespace mrc::control_plane +namespace mrc::ucx { +class UcxResources; +} // namespace mrc::ucx -namespace mrc::internal::control_plane::client { +namespace mrc::control_plane::client { class Instance; class ConnectionsManager : public StateManager @@ -48,7 +48,7 @@ class ConnectionsManager : public StateManager ~ConnectionsManager() override; std::map> register_ucx_addresses( - std::vector>& ucx_resources); + std::vector>& ucx_resources); const MachineID& machine_id() const; const std::vector& instance_ids() const; @@ -69,4 +69,4 @@ class ConnectionsManager : public StateManager std::map> m_update_channels; }; -} // namespace mrc::internal::control_plane::client +} // namespace mrc::control_plane::client diff --git a/cpp/mrc/src/internal/control_plane/client/instance.cpp b/cpp/mrc/src/internal/control_plane/client/instance.cpp index fab9a09d6..65c0040ad 100644 --- a/cpp/mrc/src/internal/control_plane/client/instance.cpp +++ b/cpp/mrc/src/internal/control_plane/client/instance.cpp @@ -20,7 +20,7 @@ #include "internal/control_plane/client.hpp" #include "internal/control_plane/client/subscription_service.hpp" #include "internal/resources/partition_resources_base.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/utils/contains.hpp" #include "mrc/edge/edge_builder.hpp" @@ -42,7 +42,7 @@ #include #include -namespace mrc::internal::control_plane::client { +namespace mrc::control_plane::client { Instance::Instance(Client& client, InstanceID instance_id, @@ -220,4 +220,4 @@ Client& Instance::client() // } // } -} // namespace mrc::internal::control_plane::client +} // namespace mrc::control_plane::client diff --git a/cpp/mrc/src/internal/control_plane/client/instance.hpp b/cpp/mrc/src/internal/control_plane/client/instance.hpp index 166493c33..9ab69161c 100644 --- a/cpp/mrc/src/internal/control_plane/client/instance.hpp +++ b/cpp/mrc/src/internal/control_plane/client/instance.hpp @@ -31,12 +31,12 @@ namespace mrc::edge { template class IWritableAcceptor; } // namespace mrc::edge -namespace mrc::internal::control_plane { +namespace mrc::control_plane { class Client; -} // namespace mrc::internal::control_plane -namespace mrc::internal::network { -class Resources; -} // namespace mrc::internal::network +} // namespace mrc::control_plane +namespace mrc::network { +class NetworkResources; +} // namespace mrc::network namespace mrc::protos { class DropSubscriptionServiceState; class StateUpdate; @@ -46,7 +46,7 @@ namespace mrc::runnable { class Runner; } // namespace mrc::runnable -namespace mrc::internal::control_plane::client { +namespace mrc::control_plane::client { class ISubscriptionServiceUpdater; @@ -86,7 +86,7 @@ class Instance final : private resources::PartitionResourceBase, private Service std::multimap> m_subscription_services; std::unique_ptr m_update_handler; - friend network::Resources; + friend network::NetworkResources; }; -} // namespace mrc::internal::control_plane::client +} // namespace mrc::control_plane::client diff --git a/cpp/mrc/src/internal/control_plane/client/state_manager.cpp b/cpp/mrc/src/internal/control_plane/client/state_manager.cpp index db874b542..1970e3574 100644 --- a/cpp/mrc/src/internal/control_plane/client/state_manager.cpp +++ b/cpp/mrc/src/internal/control_plane/client/state_manager.cpp @@ -18,7 +18,7 @@ #include "internal/control_plane/client/state_manager.hpp" #include "internal/control_plane/client.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "mrc/core/error.hpp" #include "mrc/edge/edge_builder.hpp" @@ -35,7 +35,7 @@ #include #include -namespace mrc::internal::control_plane::client { +namespace mrc::control_plane::client { StateManager::StateManager(Client& client) : m_client(client) {} @@ -100,4 +100,4 @@ void StateManager::await_join() CHECK(m_runner); m_runner->await_join(); } -} // namespace mrc::internal::control_plane::client +} // namespace mrc::control_plane::client diff --git a/cpp/mrc/src/internal/control_plane/client/state_manager.hpp b/cpp/mrc/src/internal/control_plane/client/state_manager.hpp index 03d027aad..9a600688c 100644 --- a/cpp/mrc/src/internal/control_plane/client/state_manager.hpp +++ b/cpp/mrc/src/internal/control_plane/client/state_manager.hpp @@ -36,7 +36,7 @@ namespace mrc::runnable { class Runner; } // namespace mrc::runnable -namespace mrc::internal::control_plane { +namespace mrc::control_plane { class Client; @@ -96,4 +96,4 @@ class StateManager }; } // namespace client -} // namespace mrc::internal::control_plane +} // namespace mrc::control_plane diff --git a/cpp/mrc/src/internal/control_plane/client/subscription_service.cpp b/cpp/mrc/src/internal/control_plane/client/subscription_service.cpp index b6a465e51..50e6e2351 100644 --- a/cpp/mrc/src/internal/control_plane/client/subscription_service.cpp +++ b/cpp/mrc/src/internal/control_plane/client/subscription_service.cpp @@ -31,7 +31,7 @@ #include #include -namespace mrc::internal::control_plane::client { +namespace mrc::control_plane::client { SubscriptionService::SubscriptionService(const std::string& service_name, Instance& instance) : m_service_name(std::move(service_name)), @@ -239,4 +239,4 @@ void RoleUpdater::update_tagged_instances(const std::unordered_map -namespace mrc::internal::control_plane { +namespace mrc::control_plane { -Resources::Resources(resources::PartitionResourceBase& base) : +ControlPlaneResources::ControlPlaneResources(resources::PartitionResourceBase& base) : resources::PartitionResourceBase(base), - m_client(std::make_unique(base)) + m_client(std::make_unique(base)) { if (system().options().enable_server()) { @@ -45,7 +45,7 @@ Resources::Resources(resources::PartitionResourceBase& base) : m_client->service_await_live(); } -Resources::~Resources() +ControlPlaneResources::~ControlPlaneResources() { if (m_client) { @@ -60,4 +60,4 @@ Resources::~Resources() } } -} // namespace mrc::internal::control_plane +} // namespace mrc::control_plane diff --git a/cpp/mrc/src/internal/control_plane/resources.hpp b/cpp/mrc/src/internal/control_plane/control_plane_resources.hpp similarity index 73% rename from cpp/mrc/src/internal/control_plane/resources.hpp rename to cpp/mrc/src/internal/control_plane/control_plane_resources.hpp index 6a6e7392e..7561c1d89 100644 --- a/cpp/mrc/src/internal/control_plane/resources.hpp +++ b/cpp/mrc/src/internal/control_plane/control_plane_resources.hpp @@ -21,20 +21,20 @@ #include -namespace mrc::internal::network { -class Resources; -} // namespace mrc::internal::network +namespace mrc::network { +class NetworkResources; +} // namespace mrc::network -namespace mrc::internal::control_plane { +namespace mrc::control_plane { class Client; class Server; -class Resources final : private resources::PartitionResourceBase +class ControlPlaneResources final : private resources::PartitionResourceBase { public: - Resources(resources::PartitionResourceBase& base); - ~Resources() final; + ControlPlaneResources(resources::PartitionResourceBase& base); + ~ControlPlaneResources() final; Client& client() { @@ -45,7 +45,7 @@ class Resources final : private resources::PartitionResourceBase std::unique_ptr m_server; const std::unique_ptr m_client; - friend network::Resources; + friend network::NetworkResources; }; -} // namespace mrc::internal::control_plane +} // namespace mrc::control_plane diff --git a/cpp/mrc/src/internal/control_plane/proto_helpers.hpp b/cpp/mrc/src/internal/control_plane/proto_helpers.hpp index 9fb6de36e..332677441 100644 --- a/cpp/mrc/src/internal/control_plane/proto_helpers.hpp +++ b/cpp/mrc/src/internal/control_plane/proto_helpers.hpp @@ -23,7 +23,7 @@ #include -namespace mrc::internal::control_plane { +namespace mrc::control_plane { // protobuf convenience methods template @@ -48,4 +48,4 @@ Expected unpack(const google::protobuf::Any& message) return Error::create("unable to unpack message to the requested type"); } -} // namespace mrc::internal::control_plane +} // namespace mrc::control_plane diff --git a/cpp/mrc/src/internal/control_plane/server.cpp b/cpp/mrc/src/internal/control_plane/server.cpp index 97e2c6c5c..aa980aba8 100644 --- a/cpp/mrc/src/internal/control_plane/server.cpp +++ b/cpp/mrc/src/internal/control_plane/server.cpp @@ -20,7 +20,7 @@ #include "internal/control_plane/proto_helpers.hpp" #include "internal/control_plane/server/subscription_manager.hpp" #include "internal/grpc/stream_writer.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "mrc/channel/status.hpp" #include "mrc/edge/edge_builder.hpp" @@ -49,7 +49,7 @@ #include #include -namespace mrc::internal::control_plane { +namespace mrc::control_plane { template static Expected unpack_request(Server::event_t& event) @@ -86,7 +86,7 @@ static Expected<> unary_response(Server::event_t& event, Expected&& me return {}; } -Server::Server(runnable::Resources& runnable) : m_runnable(runnable), m_server(m_runnable) {} +Server::Server(runnable::RunnableResources& runnable) : m_runnable(runnable), m_server(m_runnable) {} Server::~Server() = default; @@ -681,4 +681,4 @@ Expected Server::get_ return search; } -} // namespace mrc::internal::control_plane +} // namespace mrc::control_plane diff --git a/cpp/mrc/src/internal/control_plane/server.hpp b/cpp/mrc/src/internal/control_plane/server.hpp index ede02d13c..d3d319502 100644 --- a/cpp/mrc/src/internal/control_plane/server.hpp +++ b/cpp/mrc/src/internal/control_plane/server.hpp @@ -43,17 +43,17 @@ template class Queue; } // namespace mrc::node -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { class ClientInstance; class SubscriptionService; -} // namespace mrc::internal::control_plane::server -namespace mrc::internal::rpc { +} // namespace mrc::control_plane::server +namespace mrc::rpc { template struct StreamWriter; -} // namespace mrc::internal::rpc -namespace mrc::internal::runnable { -class Resources; -} // namespace mrc::internal::runnable +} // namespace mrc::rpc +namespace mrc::runnable { +class RunnableResources; +} // namespace mrc::runnable namespace mrc::protos { class Ack; class Event; @@ -63,7 +63,7 @@ namespace mrc::runnable { class Runner; } // namespace mrc::runnable -namespace mrc::internal::control_plane { +namespace mrc::control_plane { /** * @brief Control Plane Server @@ -73,7 +73,7 @@ namespace mrc::internal::control_plane { * to exchange connection information like UCX worker addresses. * * The server must be resilient to termination, meaning we can not use glog's CHECK statement to validate assumptions. - * We will use C++ exceptions that throw a mrc::internal::Error to replace the std::abort of a failed CHECK/ASSERT. + * We will use C++ exceptions that throw a mrc::Error to replace the std::abort of a failed CHECK/ASSERT. * To indicate "softer" errors, perhaps configuration errors by the client or mismatched state between client and server * as failed Expected. All top-level event handlers should return an Expected where message is the type of * message which will be returned to the client. The write methods will check the state of the Expected and @@ -89,7 +89,7 @@ class Server : public Service using stream_id_t = std::size_t; using instance_id_t = std::size_t; - Server(runnable::Resources& runnable); + Server(runnable::RunnableResources& runnable); ~Server() override; private: @@ -104,7 +104,7 @@ class Server : public Service void do_issue_update(rxcpp::subscriber& s); // mrc resources - runnable::Resources& m_runnable; + runnable::RunnableResources& m_runnable; // grpc rpc::Server m_server; @@ -152,4 +152,4 @@ class Server : public Service Expected get_subscription_service(const std::string& name) const; }; -} // namespace mrc::internal::control_plane +} // namespace mrc::control_plane diff --git a/cpp/mrc/src/internal/control_plane/server/client_instance.hpp b/cpp/mrc/src/internal/control_plane/server/client_instance.hpp index 995fd9325..ce94790f1 100644 --- a/cpp/mrc/src/internal/control_plane/server/client_instance.hpp +++ b/cpp/mrc/src/internal/control_plane/server/client_instance.hpp @@ -24,7 +24,7 @@ #include -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { class ClientInstance { @@ -62,4 +62,4 @@ class ClientInstance const std::string m_worker_address; }; -} // namespace mrc::internal::control_plane::server +} // namespace mrc::control_plane::server diff --git a/cpp/mrc/src/internal/control_plane/server/connection_manager.cpp b/cpp/mrc/src/internal/control_plane/server/connection_manager.cpp index 9d49c1544..617c3b4c6 100644 --- a/cpp/mrc/src/internal/control_plane/server/connection_manager.cpp +++ b/cpp/mrc/src/internal/control_plane/server/connection_manager.cpp @@ -31,7 +31,7 @@ #include #include -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { ConnectionManager::~ConnectionManager() = default; @@ -259,4 +259,4 @@ const std::map& Con return m_streams; } -} // namespace mrc::internal::control_plane::server +} // namespace mrc::control_plane::server diff --git a/cpp/mrc/src/internal/control_plane/server/connection_manager.hpp b/cpp/mrc/src/internal/control_plane/server/connection_manager.hpp index aa93afe3d..34d328df1 100644 --- a/cpp/mrc/src/internal/control_plane/server/connection_manager.hpp +++ b/cpp/mrc/src/internal/control_plane/server/connection_manager.hpp @@ -30,10 +30,10 @@ #include #include -namespace mrc::internal::rpc { +namespace mrc::rpc { template struct StreamWriter; -} // namespace mrc::internal::rpc +} // namespace mrc::rpc namespace mrc::protos { class Ack; class Event; @@ -45,13 +45,13 @@ class StateUpdate; class TaggedInstance; } // namespace mrc::protos -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { class ClientInstance; /** * @brief Control Plane Connection Manager * - * Manages each gRPC bidirectional stream via the mrc::internal::rpc::ServerStream connection. + * Manages each gRPC bidirectional stream via the mrc::rpc::ServerStream connection. * * Each stream/connection is allowed a one-time registration of client instances (client-side partitions) to be * associated with the stream. @@ -120,4 +120,4 @@ class ConnectionManager : public VersionedState std::multimap m_instances_by_stream; }; -} // namespace mrc::internal::control_plane::server +} // namespace mrc::control_plane::server diff --git a/cpp/mrc/src/internal/control_plane/server/subscription_manager.cpp b/cpp/mrc/src/internal/control_plane/server/subscription_manager.cpp index 06a270389..c406e9ef9 100644 --- a/cpp/mrc/src/internal/control_plane/server/subscription_manager.cpp +++ b/cpp/mrc/src/internal/control_plane/server/subscription_manager.cpp @@ -30,7 +30,7 @@ #include #include -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { Role::Role(std::string service_name, std::string role_name) : m_service_name(std::move(service_name)), @@ -292,4 +292,4 @@ Expected<> SubscriptionService::update_role(const protos::UpdateSubscriptionServ } return {}; } -} // namespace mrc::internal::control_plane::server +} // namespace mrc::control_plane::server diff --git a/cpp/mrc/src/internal/control_plane/server/subscription_manager.hpp b/cpp/mrc/src/internal/control_plane/server/subscription_manager.hpp index dcb57ef8b..9081922a0 100644 --- a/cpp/mrc/src/internal/control_plane/server/subscription_manager.hpp +++ b/cpp/mrc/src/internal/control_plane/server/subscription_manager.hpp @@ -35,7 +35,7 @@ class StateUpdate; class UpdateSubscriptionServiceRequest; } // namespace mrc::protos -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { class Role; class ClientInstance; @@ -158,4 +158,4 @@ class Role final : public VersionedState std::map>> m_latched_members; }; -} // namespace mrc::internal::control_plane::server +} // namespace mrc::control_plane::server diff --git a/cpp/mrc/src/internal/control_plane/server/tagged_issuer.cpp b/cpp/mrc/src/internal/control_plane/server/tagged_issuer.cpp index 1cf649cda..0f9fcfadc 100644 --- a/cpp/mrc/src/internal/control_plane/server/tagged_issuer.cpp +++ b/cpp/mrc/src/internal/control_plane/server/tagged_issuer.cpp @@ -25,7 +25,7 @@ #include #include -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { Tagged::~Tagged() = default; @@ -138,4 +138,4 @@ void TaggedIssuer::issue_update() do_issue_update(); } -} // namespace mrc::internal::control_plane::server +} // namespace mrc::control_plane::server diff --git a/cpp/mrc/src/internal/control_plane/server/tagged_issuer.hpp b/cpp/mrc/src/internal/control_plane/server/tagged_issuer.hpp index f85958520..db0e12b20 100644 --- a/cpp/mrc/src/internal/control_plane/server/tagged_issuer.hpp +++ b/cpp/mrc/src/internal/control_plane/server/tagged_issuer.hpp @@ -28,7 +28,7 @@ #include #include -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { /** * @brief Creates masked tags. @@ -103,4 +103,4 @@ class TaggedIssuer : public Tagged, public UpdateIssuer decltype(m_instance_tags)::iterator drop_tag(decltype(m_instance_tags)::iterator it); }; -} // namespace mrc::internal::control_plane::server +} // namespace mrc::control_plane::server diff --git a/cpp/mrc/src/internal/control_plane/server/update_issuer.hpp b/cpp/mrc/src/internal/control_plane/server/update_issuer.hpp index 2bd093898..7ecf1df33 100644 --- a/cpp/mrc/src/internal/control_plane/server/update_issuer.hpp +++ b/cpp/mrc/src/internal/control_plane/server/update_issuer.hpp @@ -19,7 +19,7 @@ #include -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { struct UpdateIssuer { @@ -28,4 +28,4 @@ struct UpdateIssuer virtual const std::string& service_name() const = 0; }; -} // namespace mrc::internal::control_plane::server +} // namespace mrc::control_plane::server diff --git a/cpp/mrc/src/internal/control_plane/server/versioned_issuer.hpp b/cpp/mrc/src/internal/control_plane/server/versioned_issuer.hpp index 578221fe5..a1425eb25 100644 --- a/cpp/mrc/src/internal/control_plane/server/versioned_issuer.hpp +++ b/cpp/mrc/src/internal/control_plane/server/versioned_issuer.hpp @@ -24,7 +24,7 @@ #include -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { class VersionedState : public UpdateIssuer { @@ -76,4 +76,4 @@ class VersionedState : public UpdateIssuer std::size_t m_issued_nonce{1}; }; -} // namespace mrc::internal::control_plane::server +} // namespace mrc::control_plane::server diff --git a/cpp/mrc/src/internal/data_plane/callbacks.cpp b/cpp/mrc/src/internal/data_plane/callbacks.cpp index c0ced8aba..58ab6dc7f 100644 --- a/cpp/mrc/src/internal/data_plane/callbacks.cpp +++ b/cpp/mrc/src/internal/data_plane/callbacks.cpp @@ -25,7 +25,7 @@ #include #include -namespace mrc::internal::data_plane { +namespace mrc::data_plane { void Callbacks::send(void* request, ucs_status_t status, void* user_data) { @@ -87,4 +87,4 @@ void Callbacks::recv(void* request, ucs_status_t status, const ucp_tag_recv_info } } -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/data_plane/callbacks.hpp b/cpp/mrc/src/internal/data_plane/callbacks.hpp index 500e827ed..b86244f4b 100644 --- a/cpp/mrc/src/internal/data_plane/callbacks.hpp +++ b/cpp/mrc/src/internal/data_plane/callbacks.hpp @@ -20,7 +20,7 @@ #include #include -namespace mrc::internal::data_plane { +namespace mrc::data_plane { struct Callbacks final { @@ -29,4 +29,4 @@ struct Callbacks final static void recv(void* request, ucs_status_t status, const ucp_tag_recv_info_t* msg_info, void* user_data); }; -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/data_plane/client.cpp b/cpp/mrc/src/internal/data_plane/client.cpp index f8c9d9e33..0f0a5ee4c 100644 --- a/cpp/mrc/src/internal/data_plane/client.cpp +++ b/cpp/mrc/src/internal/data_plane/client.cpp @@ -19,15 +19,15 @@ #include "internal/control_plane/client/connections_manager.hpp" #include "internal/data_plane/callbacks.hpp" +#include "internal/data_plane/data_plane_resources.hpp" #include "internal/data_plane/request.hpp" -#include "internal/data_plane/resources.hpp" #include "internal/data_plane/tags.hpp" #include "internal/memory/transient_pool.hpp" #include "internal/remote_descriptor/manager.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/ucx/common.hpp" #include "internal/ucx/endpoint.hpp" -#include "internal/ucx/resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "internal/ucx/worker.hpp" #include "mrc/channel/buffered_channel.hpp" @@ -55,12 +55,12 @@ #include #include -namespace mrc::internal::data_plane { +namespace mrc::data_plane { using namespace mrc::memory::literals; Client::Client(resources::PartitionResourceBase& base, - ucx::Resources& ucx, + ucx::UcxResources& ucx, control_plane::client::ConnectionsManager& connections_manager, memory::TransientPool& transient_pool) : resources::PartitionResourceBase(base), @@ -302,7 +302,7 @@ void Client::do_service_start() mrc::make_edge(*m_rd_channel, *rd_writer); // todo(ryan) - parameterize mrc::data_plane::client::max_inflight_remote_descriptor_sends - auto launch_options = Resources::launch_options(16); + auto launch_options = DataPlaneResources::launch_options(16); // launch rd_writer m_rd_writer = runnable().launch_control().prepare_launcher(launch_options, std::move(rd_writer))->ignition(); @@ -329,4 +329,4 @@ void Client::do_service_await_join() m_rd_writer->await_join(); } -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/data_plane/client.hpp b/cpp/mrc/src/internal/data_plane/client.hpp index 9fbe2cf0e..7b02b1451 100644 --- a/cpp/mrc/src/internal/data_plane/client.hpp +++ b/cpp/mrc/src/internal/data_plane/client.hpp @@ -37,23 +37,23 @@ namespace mrc::node { template class WritableProvider; } // namespace mrc::node -namespace mrc::internal::control_plane::client { +namespace mrc::control_plane::client { class ConnectionsManager; -} // namespace mrc::internal::control_plane::client -namespace mrc::internal::memory { +} // namespace mrc::control_plane::client +namespace mrc::memory { class TransientPool; -} // namespace mrc::internal::memory -namespace mrc::internal::ucx { +} // namespace mrc::memory +namespace mrc::ucx { class Endpoint; -class Resources; -} // namespace mrc::internal::ucx +class UcxResources; +} // namespace mrc::ucx namespace mrc::runnable { class Runner; } // namespace mrc::runnable -namespace mrc::internal::data_plane { +namespace mrc::data_plane { class Request; -class Resources; +class DataPlaneResources; struct RemoteDescriptorMessage { @@ -66,7 +66,7 @@ class Client final : public resources::PartitionResourceBase, private Service { public: Client(resources::PartitionResourceBase& base, - ucx::Resources& ucx, + ucx::UcxResources& ucx, control_plane::client::ConnectionsManager& connections_manager, memory::TransientPool& transient_pool); ~Client() final; @@ -133,7 +133,7 @@ class Client final : public resources::PartitionResourceBase, private Service void do_service_kill() final; void do_service_await_join() final; - ucx::Resources& m_ucx; + ucx::UcxResources& m_ucx; control_plane::client::ConnectionsManager& m_connnection_manager; memory::TransientPool& m_transient_pool; mutable std::map> m_endpoints; @@ -141,7 +141,7 @@ class Client final : public resources::PartitionResourceBase, private Service std::unique_ptr m_rd_writer; std::unique_ptr> m_rd_channel; - friend Resources; + friend DataPlaneResources; }; -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/data_plane/resources.cpp b/cpp/mrc/src/internal/data_plane/data_plane_resources.cpp similarity index 63% rename from cpp/mrc/src/internal/data_plane/resources.cpp rename to cpp/mrc/src/internal/data_plane/data_plane_resources.cpp index bc0c48de0..3ecf2d3f6 100644 --- a/cpp/mrc/src/internal/data_plane/resources.cpp +++ b/cpp/mrc/src/internal/data_plane/data_plane_resources.cpp @@ -15,28 +15,28 @@ * limitations under the License. */ -#include "internal/data_plane/resources.hpp" +#include "internal/data_plane/data_plane_resources.hpp" #include "internal/control_plane/client.hpp" #include "internal/data_plane/client.hpp" #include "internal/data_plane/server.hpp" #include "internal/memory/host_resources.hpp" -#include "internal/ucx/resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "internal/ucx/worker.hpp" #include "mrc/memory/literals.hpp" #include -namespace mrc::internal::data_plane { +namespace mrc::data_plane { using namespace mrc::memory::literals; -Resources::Resources(resources::PartitionResourceBase& base, - ucx::Resources& ucx, - memory::HostResources& host, - const InstanceID& instance_id, - control_plane::Client& control_plane_client) : +DataPlaneResources::DataPlaneResources(resources::PartitionResourceBase& base, + ucx::UcxResources& ucx, + memory::HostResources& host, + const InstanceID& instance_id, + control_plane::Client& control_plane_client) : resources::PartitionResourceBase(base), m_ucx(ucx), m_host(host), @@ -51,75 +51,70 @@ Resources::Resources(resources::PartitionResourceBase& base, service_await_live(); } -Resources::~Resources() +DataPlaneResources::~DataPlaneResources() { Service::call_in_destructor(); } -Client& Resources::client() +Client& DataPlaneResources::client() { return *m_client; } -// Server& Resources::server() -// { -// return m_server; -// } - -std::string Resources::ucx_address() const +std::string DataPlaneResources::ucx_address() const { return m_ucx.worker().address(); } -const ucx::RegistrationCache& Resources::registration_cache() const +const ucx::RegistrationCache& DataPlaneResources::registration_cache() const { return m_ucx.registration_cache(); } -void Resources::do_service_start() +void DataPlaneResources::do_service_start() { m_server->service_start(); m_client->service_start(); } -void Resources::do_service_await_live() +void DataPlaneResources::do_service_await_live() { m_server->service_await_live(); m_client->service_await_live(); } -void Resources::do_service_stop() +void DataPlaneResources::do_service_stop() { // we only issue m_client->service_stop(); } -void Resources::do_service_kill() +void DataPlaneResources::do_service_kill() { m_server->service_kill(); m_client->service_kill(); } -void Resources::do_service_await_join() +void DataPlaneResources::do_service_await_join() { m_client->service_await_join(); m_server->service_stop(); m_server->service_await_join(); } -Server& Resources::server() +Server& DataPlaneResources::server() { return *m_server; } -mrc::runnable::LaunchOptions Resources::launch_options(std::size_t concurrency) +mrc::runnable::LaunchOptions DataPlaneResources::launch_options(std::size_t concurrency) { - return ucx::Resources::launch_options(concurrency); + return ucx::UcxResources::launch_options(concurrency); } -const InstanceID& Resources::instance_id() const +const InstanceID& DataPlaneResources::instance_id() const { return m_instance_id; } -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/data_plane/resources.hpp b/cpp/mrc/src/internal/data_plane/data_plane_resources.hpp similarity index 70% rename from cpp/mrc/src/internal/data_plane/resources.hpp rename to cpp/mrc/src/internal/data_plane/data_plane_resources.hpp index 5e493daf0..62f85f75f 100644 --- a/cpp/mrc/src/internal/data_plane/resources.hpp +++ b/cpp/mrc/src/internal/data_plane/data_plane_resources.hpp @@ -28,21 +28,21 @@ #include #include -namespace mrc::internal::control_plane { +namespace mrc::control_plane { class Client; -} // namespace mrc::internal::control_plane -namespace mrc::internal::memory { +} // namespace mrc::control_plane +namespace mrc::memory { class HostResources; -} // namespace mrc::internal::memory -namespace mrc::internal::network { -class Resources; -} // namespace mrc::internal::network -namespace mrc::internal::ucx { +} // namespace mrc::memory +namespace mrc::network { +class NetworkResources; +} // namespace mrc::network +namespace mrc::ucx { class RegistrationCache; -class Resources; -} // namespace mrc::internal::ucx +class UcxResources; +} // namespace mrc::ucx -namespace mrc::internal::data_plane { +namespace mrc::data_plane { class Client; class Server; @@ -50,15 +50,15 @@ class Server; * @brief ArchitectResources hold and is responsible for constructing any object that depending the UCX data plane * */ -class Resources final : private Service, private resources::PartitionResourceBase +class DataPlaneResources final : private Service, private resources::PartitionResourceBase { public: - Resources(resources::PartitionResourceBase& base, - ucx::Resources& ucx, - memory::HostResources& host, - const InstanceID& instance_id, - control_plane::Client& control_plane_client); - ~Resources() final; + DataPlaneResources(resources::PartitionResourceBase& base, + ucx::UcxResources& ucx, + memory::HostResources& host, + const InstanceID& instance_id, + control_plane::Client& control_plane_client); + ~DataPlaneResources() final; Client& client(); Server& server(); @@ -76,7 +76,7 @@ class Resources final : private Service, private resources::PartitionResourceBas void do_service_kill() final; void do_service_await_join() final; - ucx::Resources& m_ucx; + ucx::UcxResources& m_ucx; memory::HostResources& m_host; control_plane::Client& m_control_plane_client; InstanceID m_instance_id; @@ -85,7 +85,7 @@ class Resources final : private Service, private resources::PartitionResourceBas std::unique_ptr m_server; std::unique_ptr m_client; - friend network::Resources; + friend network::NetworkResources; }; -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/data_plane/request.cpp b/cpp/mrc/src/internal/data_plane/request.cpp index 30aff7cfc..32b2ad69e 100644 --- a/cpp/mrc/src/internal/data_plane/request.cpp +++ b/cpp/mrc/src/internal/data_plane/request.cpp @@ -22,7 +22,7 @@ #include -namespace mrc::internal::data_plane { +namespace mrc::data_plane { Request::Request() = default; @@ -60,4 +60,4 @@ bool Request::await_complete() LOG(FATAL) << "error in ucx callback"; } -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/data_plane/request.hpp b/cpp/mrc/src/internal/data_plane/request.hpp index c4157f75d..ee64ebc45 100644 --- a/cpp/mrc/src/internal/data_plane/request.hpp +++ b/cpp/mrc/src/internal/data_plane/request.hpp @@ -21,7 +21,7 @@ #include -namespace mrc::internal::data_plane { +namespace mrc::data_plane { class Callbacks; class Client; @@ -61,4 +61,4 @@ class Request final friend Callbacks; }; -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/data_plane/server.cpp b/cpp/mrc/src/internal/data_plane/server.cpp index 358189690..a230ad934 100644 --- a/cpp/mrc/src/internal/data_plane/server.cpp +++ b/cpp/mrc/src/internal/data_plane/server.cpp @@ -18,9 +18,9 @@ #include "internal/data_plane/server.hpp" #include "internal/data_plane/tags.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/ucx/common.hpp" -#include "internal/ucx/resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "internal/ucx/worker.hpp" #include "mrc/core/task_queue.hpp" @@ -51,7 +51,7 @@ #include #include -namespace mrc::internal::data_plane { +namespace mrc::data_plane { namespace { @@ -143,7 +143,7 @@ class DataPlaneServerWorker final : public node::GenericSource }; Server::Server(resources::PartitionResourceBase& provider, - ucx::Resources& ucx, + ucx::UcxResources& ucx, memory::HostResources& host, memory::TransientPool& transient_pool, InstanceID instance_id) : @@ -348,4 +348,4 @@ void DataPlaneServerWorker::on_tagged_msg(rxcpp::subscriber& su } } -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/data_plane/server.hpp b/cpp/mrc/src/internal/data_plane/server.hpp index 0c31754e1..fa56146bd 100644 --- a/cpp/mrc/src/internal/data_plane/server.hpp +++ b/cpp/mrc/src/internal/data_plane/server.hpp @@ -39,12 +39,12 @@ namespace mrc::node { template class TaggedRouter; } // namespace mrc::node -namespace mrc::internal::memory { +namespace mrc::memory { class HostResources; -} // namespace mrc::internal::memory -namespace mrc::internal::ucx { -class Resources; -} // namespace mrc::internal::ucx +} // namespace mrc::memory +namespace mrc::ucx { +class UcxResources; +} // namespace mrc::ucx namespace mrc::runnable { class Runner; } // namespace mrc::runnable @@ -70,7 +70,7 @@ class Runner; // channel decoder, which should issue the recv in the same context as was // called and return immediately. -namespace mrc::internal::data_plane { +namespace mrc::data_plane { using network_event_t = std::pair; @@ -89,7 +89,7 @@ class Server final : public Service, public resources::PartitionResourceBase { public: Server(resources::PartitionResourceBase& provider, - ucx::Resources& ucx, + ucx::UcxResources& ucx, memory::HostResources& host, memory::TransientPool& transient_pool, InstanceID instance_id); @@ -109,7 +109,7 @@ class Server final : public Service, public resources::PartitionResourceBase const std::size_t m_pre_posted_recv_count{16}; // ucx resources - ucx::Resources& m_ucx; + ucx::UcxResources& m_ucx; memory::HostResources& m_host; InstanceID m_instance_id; @@ -131,4 +131,4 @@ class Server final : public Service, public resources::PartitionResourceBase std::unique_ptr m_progress_engine; }; -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane diff --git a/cpp/mrc/src/internal/executor/executor.cpp b/cpp/mrc/src/internal/executor/executor_definition.cpp similarity index 69% rename from cpp/mrc/src/internal/executor/executor.cpp rename to cpp/mrc/src/internal/executor/executor_definition.cpp index 867269aab..de630115d 100644 --- a/cpp/mrc/src/internal/executor/executor.cpp +++ b/cpp/mrc/src/internal/executor/executor_definition.cpp @@ -15,14 +15,13 @@ * limitations under the License. */ -#include "internal/executor/executor.hpp" +#include "internal/executor/executor_definition.hpp" #include "internal/pipeline/manager.hpp" -#include "internal/pipeline/pipeline.hpp" +#include "internal/pipeline/pipeline_definition.hpp" #include "internal/pipeline/port_graph.hpp" #include "internal/pipeline/types.hpp" #include "internal/resources/manager.hpp" -#include "internal/system/resources.hpp" #include "internal/system/system.hpp" #include "mrc/core/addresses.hpp" @@ -31,46 +30,102 @@ #include #include +#include #include #include #include #include -namespace mrc::internal::executor { +namespace mrc::executor { -static bool valid_pipeline(const pipeline::Pipeline& pipeline); +static bool valid_pipeline(const pipeline::PipelineDefinition& pipeline) +{ + bool valid = true; + pipeline::PortGraph pg(pipeline); -Executor::Executor(std::shared_ptr options) : - SystemProvider(system::make_system(std::move(options))), - m_resources_manager(std::make_unique(*this)) -{} + for (const auto& [name, connections] : pg.port_map()) + { + // first validate all port names have at least one: + // - segment using that port as an ingress, and + // - segment using that port as an egress + if (connections.egress_segments.empty() or connections.ingress_segments.empty()) + { + valid = false; + // todo - print list of segments names for ingress/egres connections to this port + LOG(WARNING) << "port: " << name << " has incomplete connections - used as ingress on " + << connections.ingress_segments.size() << " segments; used as egress on " + << connections.egress_segments.size() << " segments"; + } + + // we currently only have an load-balancer manifold + // it doesn't make sense to connect segments of different types to a load-balancer, they should probably be + // broadcast + // in general, if there are more than one type of segments writing to or reading from a manifold, then that port + // should have an explicit manifold type specified + if (connections.egress_segments.size() > 1 or connections.ingress_segments.size() > 1) + { + valid = false; + LOG(WARNING) << "port: " << name + << " has more than 1 segment type connected to an ingress or egress port; this is currently " + "an invalid configuration as there are no manifold available to handle this condition"; + } + } + + return valid; +} -Executor::Executor(std::unique_ptr resources) : - SystemProvider(*resources), - m_resources_manager(std::make_unique(std::move(resources))) +ExecutorDefinition::ExecutorDefinition(std::unique_ptr system) : + SystemProvider(std::move(system)), + m_resources_manager(std::make_unique(*this)) {} -Executor::~Executor() +ExecutorDefinition::~ExecutorDefinition() { Service::call_in_destructor(); } -void Executor::register_pipeline(std::unique_ptr ipipeline) +std::shared_ptr ExecutorDefinition::unwrap(std::shared_ptr object) +{ + // Convert to the full implementation + auto full_object = std::dynamic_pointer_cast(object); + + CHECK(full_object) << "Invalid cast for ExecutorDefinition. Please report to the developers"; + + return full_object; +} + +void ExecutorDefinition::register_pipeline(std::shared_ptr pipeline) { - CHECK(ipipeline); + CHECK(pipeline) << "Must pass a non-null pipeline pointer to register_pipeline"; CHECK(m_pipeline_manager == nullptr); - auto pipeline = pipeline::Pipeline::unwrap(*ipipeline); + // Convert it to the full implementation + auto full_pipeline = pipeline::PipelineDefinition::unwrap(pipeline); - if (!valid_pipeline(*pipeline)) + if (!valid_pipeline(*full_pipeline)) { throw exceptions::MrcRuntimeError("pipeline validation failed"); } - m_pipeline_manager = std::make_unique(pipeline, *m_resources_manager); + m_pipeline_manager = std::make_unique(full_pipeline, *m_resources_manager); } -void Executor::do_service_start() +void ExecutorDefinition::start() +{ + this->service_start(); +} + +void ExecutorDefinition::stop() +{ + this->service_stop(); +} + +void ExecutorDefinition::join() +{ + this->service_await_join(); +} + +void ExecutorDefinition::do_service_start() { CHECK(m_pipeline_manager); m_pipeline_manager->service_start(); @@ -84,72 +139,25 @@ void Executor::do_service_start() m_pipeline_manager->push_updates(std::move(initial_segments)); } -void Executor::do_service_stop() +void ExecutorDefinition::do_service_stop() { CHECK(m_pipeline_manager); m_pipeline_manager->service_stop(); } -void Executor::do_service_kill() +void ExecutorDefinition::do_service_kill() { CHECK(m_pipeline_manager); return m_pipeline_manager->service_kill(); } -void Executor::do_service_await_live() +void ExecutorDefinition::do_service_await_live() { CHECK(m_pipeline_manager); m_pipeline_manager->service_await_live(); } -void Executor::do_service_await_join() +void ExecutorDefinition::do_service_await_join() { CHECK(m_pipeline_manager); m_pipeline_manager->service_await_join(); } -// convert to std::expect -bool valid_pipeline(const pipeline::Pipeline& pipeline) -{ - bool valid = true; - pipeline::PortGraph pg(pipeline); - - for (const auto& [name, connections] : pg.port_map()) - { - // first validate all port names have at least one: - // - segment using that port as an ingress, and - // - segment using that port as an egress - if (connections.egress_segments.empty() or connections.ingress_segments.empty()) - { - valid = false; - // todo - print list of segments names for ingress/egres connections to this port - LOG(WARNING) << "port: " << name << " has incomplete connections - used as ingress on " - << connections.ingress_segments.size() << " segments; used as egress on " - << connections.egress_segments.size() << " segments"; - } - - // we currently only have an load-balancer manifold - // it doesn't make sense to connect segments of different types to a load-balancer, they should probably be - // broadcast - // in general, if there are more than one type of segments writing to or reading from a manifold, then that port - // should have an explicit manifold type specified - if (connections.egress_segments.size() > 1 or connections.ingress_segments.size() > 1) - { - valid = false; - LOG(WARNING) << "port: " << name - << " has more than 1 segment type connected to an ingress or egress port; this is currently " - "an invalid configuration as there are no manifold available to handle this condition"; - } - } - - return valid; -} - -std::unique_ptr make_executor(std::shared_ptr options) -{ - return std::make_unique(std::move(options)); -} - -std::unique_ptr make_executor(std::unique_ptr resources) -{ - return std::make_unique(std::move(resources)); -} - -} // namespace mrc::internal::executor +} // namespace mrc::executor diff --git a/cpp/mrc/src/internal/executor/executor.hpp b/cpp/mrc/src/internal/executor/executor_definition.hpp similarity index 63% rename from cpp/mrc/src/internal/executor/executor.hpp rename to cpp/mrc/src/internal/executor/executor_definition.hpp index 45603ef42..653db9d53 100644 --- a/cpp/mrc/src/internal/executor/executor.hpp +++ b/cpp/mrc/src/internal/executor/executor_definition.hpp @@ -20,37 +20,41 @@ #include "internal/service.hpp" #include "internal/system/system_provider.hpp" +#include "mrc/pipeline/executor.hpp" + #include -namespace mrc { -class Options; -} // namespace mrc -namespace mrc::internal::pipeline { +namespace mrc::system { +class SystemDefinition; +} // namespace mrc::system + +namespace mrc::pipeline { class IPipeline; class Manager; -} // namespace mrc::internal::pipeline -namespace mrc::internal::resources { +} // namespace mrc::pipeline +namespace mrc::resources { class Manager; -} // namespace mrc::internal::resources -namespace mrc::internal::system { -class Resources; -} // namespace mrc::internal::system +} // namespace mrc::resources -namespace mrc::internal::executor { +namespace mrc::executor { /** * @brief Common Executor code used by both the Standalone and Architect Executors * * Issues #149 will begin to separate some of the functionality of ExeuctorBase into individual components. */ -class Executor : public Service, public system::SystemProvider +class ExecutorDefinition : public pipeline::IExecutor, public Service, public system::SystemProvider { public: - Executor(std::shared_ptr options); - Executor(std::unique_ptr resources); - ~Executor() override; + ExecutorDefinition(std::unique_ptr system); + ~ExecutorDefinition() override; + + static std::shared_ptr unwrap(std::shared_ptr object); - void register_pipeline(std::unique_ptr ipipeline); + void register_pipeline(std::shared_ptr pipeline) override; + void start() override; + void stop() override; + void join() override; private: void do_service_start() final; @@ -63,8 +67,4 @@ class Executor : public Service, public system::SystemProvider std::unique_ptr m_pipeline_manager; }; -std::unique_ptr make_executor(std::shared_ptr options); - -std::unique_ptr make_executor(std::unique_ptr resources); - -} // namespace mrc::internal::executor +} // namespace mrc::executor diff --git a/cpp/mrc/src/internal/executor/iexecutor.cpp b/cpp/mrc/src/internal/executor/iexecutor.cpp deleted file mode 100644 index a705fbb5a..000000000 --- a/cpp/mrc/src/internal/executor/iexecutor.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#include "mrc/engine/executor/iexecutor.hpp" - -#include "internal/executor/executor.hpp" -#include "internal/system/resources.hpp" - -#include "mrc/engine/pipeline/ipipeline.hpp" - -#include - -#include -#include - -namespace mrc::internal::executor { - -IExecutor::IExecutor(std::shared_ptr options) : m_impl(make_executor(std::move(options))) {} -IExecutor::IExecutor(std::unique_ptr resources) : - m_impl(make_executor(system::Resources::unwrap(*resources))) -{ - CHECK(m_impl); -} - -IExecutor::~IExecutor() = default; - -void IExecutor::register_pipeline(std::unique_ptr pipeline) -{ - CHECK(m_impl); - m_impl->register_pipeline(std::move(pipeline)); -} - -void IExecutor::start() -{ - CHECK(m_impl); - m_impl->service_start(); -} - -void IExecutor::stop() -{ - CHECK(m_impl); - m_impl->service_stop(); -} - -void IExecutor::join() -{ - CHECK(m_impl); - m_impl->service_await_join(); -} - -} // namespace mrc::internal::executor diff --git a/cpp/mrc/src/internal/grpc/client_streaming.hpp b/cpp/mrc/src/internal/grpc/client_streaming.hpp index d63427b45..8ee6bd82e 100644 --- a/cpp/mrc/src/internal/grpc/client_streaming.hpp +++ b/cpp/mrc/src/internal/grpc/client_streaming.hpp @@ -19,7 +19,7 @@ #include "internal/grpc/progress_engine.hpp" #include "internal/grpc/stream_writer.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/service.hpp" #include "mrc/channel/channel.hpp" @@ -49,7 +49,7 @@ #include #include -namespace mrc::internal::rpc { +namespace mrc::rpc { /** * @brief Implementation of a gRPC bidirectional streaming client using MRC primitives @@ -151,7 +151,7 @@ class ClientStream : private Service, public std::enable_shared_from_this>(grpc::ClientContext* context)>; - ClientStream(prepare_fn_t prepare_fn, runnable::Resources& runnable) : + ClientStream(prepare_fn_t prepare_fn, runnable::RunnableResources& runnable) : m_prepare_fn(prepare_fn), m_runnable(runnable), m_reader_source(std::make_unique>( @@ -335,7 +335,7 @@ class ClientStream : private Service, public std::enable_shared_from_this #include -#include #include #include @@ -28,7 +27,7 @@ #include #include -namespace mrc::internal::rpc { +namespace mrc::rpc { ProgressEngine::ProgressEngine(std::shared_ptr cq) : m_cq(std::move(cq)) {} @@ -68,4 +67,4 @@ void ProgressEngine::data_source(rxcpp::subscriber& s) void ProgressEngine::on_stop(const rxcpp::subscription& subscription) {} -} // namespace mrc::internal::rpc +} // namespace mrc::rpc diff --git a/cpp/mrc/src/internal/grpc/progress_engine.hpp b/cpp/mrc/src/internal/grpc/progress_engine.hpp index 6846b10ed..7bea6239e 100644 --- a/cpp/mrc/src/internal/grpc/progress_engine.hpp +++ b/cpp/mrc/src/internal/grpc/progress_engine.hpp @@ -29,7 +29,7 @@ namespace grpc { class CompletionQueue; } // namespace grpc -namespace mrc::internal::rpc { +namespace mrc::rpc { /** * @brief gRPC event data pulled from a CQ @@ -67,4 +67,4 @@ class ProgressEngine final : public mrc::node::GenericSource std::shared_ptr m_cq; }; -} // namespace mrc::internal::rpc +} // namespace mrc::rpc diff --git a/cpp/mrc/src/internal/grpc/promise_handler.hpp b/cpp/mrc/src/internal/grpc/promise_handler.hpp index 6a86c8e5a..437a22e69 100644 --- a/cpp/mrc/src/internal/grpc/promise_handler.hpp +++ b/cpp/mrc/src/internal/grpc/promise_handler.hpp @@ -23,7 +23,7 @@ #include -namespace mrc::internal::rpc { +namespace mrc::rpc { /** * @brief MRC Sink to handle ProgressEvents which correspond to Promise tags @@ -37,4 +37,4 @@ class PromiseHandler final : public mrc::node::GenericSink } }; -} // namespace mrc::internal::rpc +} // namespace mrc::rpc diff --git a/cpp/mrc/src/internal/grpc/server.cpp b/cpp/mrc/src/internal/grpc/server.cpp index 9f0e885ab..9e0c0ecb4 100644 --- a/cpp/mrc/src/internal/grpc/server.cpp +++ b/cpp/mrc/src/internal/grpc/server.cpp @@ -19,21 +19,19 @@ #include "internal/grpc/progress_engine.hpp" #include "internal/grpc/promise_handler.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "mrc/edge/edge_builder.hpp" #include "mrc/runnable/launch_control.hpp" #include "mrc/runnable/launcher.hpp" #include "mrc/runnable/runner.hpp" -#include - #include #include -namespace mrc::internal::rpc { +namespace mrc::rpc { -Server::Server(runnable::Resources& runnable) : m_runnable(runnable) +Server::Server(runnable::RunnableResources& runnable) : m_runnable(runnable) { m_cq = m_builder.AddCompletionQueue(); m_builder.AddListeningPort("0.0.0.0:13337", grpc::InsecureServerCredentials()); @@ -88,7 +86,7 @@ void Server::do_service_await_join() } } -runnable::Resources& Server::runnable() +runnable::RunnableResources& Server::runnable() { return m_runnable; } @@ -101,4 +99,4 @@ void Server::register_service(std::shared_ptr service) m_builder.RegisterService(service.get()); m_services.push_back(service); } -} // namespace mrc::internal::rpc +} // namespace mrc::rpc diff --git a/cpp/mrc/src/internal/grpc/server.hpp b/cpp/mrc/src/internal/grpc/server.hpp index cc21542a4..cacd4602d 100644 --- a/cpp/mrc/src/internal/grpc/server.hpp +++ b/cpp/mrc/src/internal/grpc/server.hpp @@ -27,26 +27,26 @@ namespace grpc { class Service; } // namespace grpc -namespace mrc::internal::runnable { -class Resources; -} // namespace mrc::internal::runnable +namespace mrc::runnable { +class RunnableResources; +} // namespace mrc::runnable namespace mrc::runnable { class Runner; } // namespace mrc::runnable -namespace mrc::internal::rpc { +namespace mrc::rpc { class Server : public Service { public: - Server(runnable::Resources& runnable); + Server(runnable::RunnableResources& runnable); ~Server() override; void register_service(std::shared_ptr service); std::shared_ptr get_cq() const; - runnable::Resources& runnable(); + runnable::RunnableResources& runnable(); private: void do_service_start() final; @@ -56,7 +56,7 @@ class Server : public Service void do_service_await_join() final; grpc::ServerBuilder m_builder; - runnable::Resources& m_runnable; + runnable::RunnableResources& m_runnable; std::vector> m_services; std::shared_ptr m_cq; std::unique_ptr m_server; @@ -64,4 +64,4 @@ class Server : public Service std::unique_ptr m_event_hander; }; -} // namespace mrc::internal::rpc +} // namespace mrc::rpc diff --git a/cpp/mrc/src/internal/grpc/server_streaming.hpp b/cpp/mrc/src/internal/grpc/server_streaming.hpp index a44369a9c..0d4da8b44 100644 --- a/cpp/mrc/src/internal/grpc/server_streaming.hpp +++ b/cpp/mrc/src/internal/grpc/server_streaming.hpp @@ -19,7 +19,7 @@ #include "internal/grpc/progress_engine.hpp" #include "internal/grpc/stream_writer.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/service.hpp" #include "mrc/channel/channel.hpp" @@ -54,7 +54,7 @@ #include #include -namespace mrc::internal::rpc { +namespace mrc::rpc { /** * @brief Implementation of a gRPC bidirectional streaming server using MRC primitives @@ -163,7 +163,7 @@ class ServerStream : private Service, public std::enable_shared_from_this* stream, void* tag)>; - ServerStream(request_fn_t request_fn, runnable::Resources& runnable) : + ServerStream(request_fn_t request_fn, runnable::RunnableResources& runnable) : m_runnable(runnable), m_stream(std::make_unique>(&m_context)), m_reader_source(std::make_unique>( @@ -356,7 +356,7 @@ class ServerStream : private Service, public std::enable_shared_from_this struct StreamWriter : public mrc::channel::Ingress @@ -30,4 +30,4 @@ struct StreamWriter : public mrc::channel::Ingress virtual std::size_t get_id() const = 0; }; -} // namespace mrc::internal::rpc +} // namespace mrc::rpc diff --git a/cpp/mrc/src/internal/memory/block_manager.hpp b/cpp/mrc/src/internal/memory/block_manager.hpp index 99d3c5616..063a8bfad 100644 --- a/cpp/mrc/src/internal/memory/block_manager.hpp +++ b/cpp/mrc/src/internal/memory/block_manager.hpp @@ -27,7 +27,7 @@ #include #include -namespace mrc::internal::memory { +namespace mrc::memory { template class BlockManager final @@ -133,4 +133,4 @@ class BlockManager final std::map m_block_map; }; -} // namespace mrc::internal::memory +} // namespace mrc::memory diff --git a/cpp/mrc/src/internal/memory/callback_adaptor.hpp b/cpp/mrc/src/internal/memory/callback_adaptor.hpp index 712d1ff6b..96f00b539 100644 --- a/cpp/mrc/src/internal/memory/callback_adaptor.hpp +++ b/cpp/mrc/src/internal/memory/callback_adaptor.hpp @@ -20,8 +20,9 @@ #include "mrc/memory/adaptors.hpp" #include +#include -namespace mrc::internal::memory { +namespace mrc::memory { template class CallbackAdaptor; @@ -108,4 +109,4 @@ class CallbackAdaptor final : public mrc::memory::adaptor std::vector m_deallocate_callbacks; }; -} // namespace mrc::internal::memory +} // namespace mrc::memory diff --git a/cpp/mrc/src/internal/memory/device_resources.cpp b/cpp/mrc/src/internal/memory/device_resources.cpp index 53504e6ff..907eb1a4a 100644 --- a/cpp/mrc/src/internal/memory/device_resources.cpp +++ b/cpp/mrc/src/internal/memory/device_resources.cpp @@ -17,11 +17,11 @@ #include "internal/memory/device_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/system/device_partition.hpp" #include "internal/system/partition.hpp" #include "internal/system/system.hpp" -#include "internal/ucx/resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "mrc/core/task_queue.hpp" #include "mrc/cuda/device_guard.hpp" @@ -37,7 +37,6 @@ #include #include -#include #include #include @@ -47,9 +46,9 @@ #include #include -namespace mrc::internal::memory { +namespace mrc::memory { -DeviceResources::DeviceResources(resources::PartitionResourceBase& base, std::optional& ucx) : +DeviceResources::DeviceResources(resources::PartitionResourceBase& base, std::optional& ucx) : resources::PartitionResourceBase(base) { CHECK(partition().has_device()); @@ -116,4 +115,4 @@ std::shared_ptr DeviceResources::arena_memory_reso { return m_arena; } -} // namespace mrc::internal::memory +} // namespace mrc::memory diff --git a/cpp/mrc/src/internal/memory/device_resources.hpp b/cpp/mrc/src/internal/memory/device_resources.hpp index 9d01f4ebb..a769c9ae3 100644 --- a/cpp/mrc/src/internal/memory/device_resources.hpp +++ b/cpp/mrc/src/internal/memory/device_resources.hpp @@ -29,11 +29,11 @@ namespace mrc::memory { struct memory_resource; } // namespace mrc::memory -namespace mrc::internal::ucx { -class Resources; +namespace mrc::ucx { +class UcxResources; } -namespace mrc::internal::memory { +namespace mrc::memory { /** * @brief Object that provides access to device memory_resource objects for a "flattened" partition @@ -41,7 +41,7 @@ namespace mrc::internal::memory { class DeviceResources : private resources::PartitionResourceBase { public: - DeviceResources(resources::PartitionResourceBase& base, std::optional& ucx); + DeviceResources(resources::PartitionResourceBase& base, std::optional& ucx); int cuda_device_id() const; @@ -57,4 +57,4 @@ class DeviceResources : private resources::PartitionResourceBase std::shared_ptr m_arena; }; -} // namespace mrc::internal::memory +} // namespace mrc::memory diff --git a/cpp/mrc/src/internal/memory/forward.hpp b/cpp/mrc/src/internal/memory/forward.hpp index 204e045df..e3272d1a0 100644 --- a/cpp/mrc/src/internal/memory/forward.hpp +++ b/cpp/mrc/src/internal/memory/forward.hpp @@ -17,7 +17,7 @@ #pragma once -namespace mrc::internal::memory { +namespace mrc::memory { class TransientBuffer; diff --git a/cpp/mrc/src/internal/memory/host_resources.cpp b/cpp/mrc/src/internal/memory/host_resources.cpp index a23071c76..c98c78618 100644 --- a/cpp/mrc/src/internal/memory/host_resources.cpp +++ b/cpp/mrc/src/internal/memory/host_resources.cpp @@ -18,7 +18,7 @@ #include "internal/memory/host_resources.hpp" #include "internal/memory/callback_adaptor.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/system/host_partition.hpp" #include "internal/system/system.hpp" #include "internal/ucx/registation_callback_builder.hpp" @@ -37,7 +37,6 @@ #include #include -#include #include #include @@ -48,9 +47,9 @@ #include #include -namespace mrc::internal::memory { +namespace mrc::memory { -HostResources::HostResources(runnable::Resources& runnable, ucx::RegistrationCallbackBuilder&& callbacks) : +HostResources::HostResources(runnable::RunnableResources& runnable, ucx::RegistrationCallbackBuilder&& callbacks) : system::HostPartitionProvider(runnable) { runnable.main() @@ -122,4 +121,4 @@ std::shared_ptr HostResources::arena_memory_resour { return m_arena; } -} // namespace mrc::internal::memory +} // namespace mrc::memory diff --git a/cpp/mrc/src/internal/memory/host_resources.hpp b/cpp/mrc/src/internal/memory/host_resources.hpp index ab10fbfb1..0759daeef 100644 --- a/cpp/mrc/src/internal/memory/host_resources.hpp +++ b/cpp/mrc/src/internal/memory/host_resources.hpp @@ -24,17 +24,17 @@ #include #include -namespace mrc::internal::runnable { -class Resources; -} // namespace mrc::internal::runnable -namespace mrc::internal::ucx { +namespace mrc::runnable { +class RunnableResources; +} // namespace mrc::runnable +namespace mrc::ucx { class RegistrationCallbackBuilder; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx namespace mrc::memory { struct memory_resource; } // namespace mrc::memory -namespace mrc::internal::memory { +namespace mrc::memory { /** * @brief Object that provides access to host memory_resource objects for a given host partition @@ -42,7 +42,7 @@ namespace mrc::internal::memory { class HostResources final : private system::HostPartitionProvider { public: - HostResources(runnable::Resources& runnable, ucx::RegistrationCallbackBuilder&& callbacks); + HostResources(runnable::RunnableResources& runnable, ucx::RegistrationCallbackBuilder&& callbacks); mrc::memory::buffer make_buffer(std::size_t bytes); @@ -56,4 +56,4 @@ class HostResources final : private system::HostPartitionProvider std::shared_ptr m_arena; }; -} // namespace mrc::internal::memory +} // namespace mrc::memory diff --git a/cpp/mrc/src/internal/memory/memory_block.hpp b/cpp/mrc/src/internal/memory/memory_block.hpp index 5e050e560..4874b1475 100644 --- a/cpp/mrc/src/internal/memory/memory_block.hpp +++ b/cpp/mrc/src/internal/memory/memory_block.hpp @@ -19,7 +19,7 @@ #include -namespace mrc::internal::memory { +namespace mrc::memory { struct MemoryBlock { @@ -132,4 +132,4 @@ struct MemoryBlockCompareAddr } }; -} // namespace mrc::internal::memory +} // namespace mrc::memory diff --git a/cpp/mrc/src/internal/memory/transient_pool.cpp b/cpp/mrc/src/internal/memory/transient_pool.cpp index 977c2c755..f16931458 100644 --- a/cpp/mrc/src/internal/memory/transient_pool.cpp +++ b/cpp/mrc/src/internal/memory/transient_pool.cpp @@ -21,7 +21,7 @@ #define MRC_DEBUG 1 -namespace mrc::internal::memory { +namespace mrc::memory { TransientBuffer::TransientBuffer(void* addr, std::size_t bytes, mrc::data::SharedReusable buffer) : m_addr(addr), @@ -125,4 +125,4 @@ TransientBuffer TransientPool::await_buffer(std::size_t bytes) return {addr, bytes, m_buffer}; } -} // namespace mrc::internal::memory +} // namespace mrc::memory diff --git a/cpp/mrc/src/internal/memory/transient_pool.hpp b/cpp/mrc/src/internal/memory/transient_pool.hpp index 904ba577e..066b00dad 100644 --- a/cpp/mrc/src/internal/memory/transient_pool.hpp +++ b/cpp/mrc/src/internal/memory/transient_pool.hpp @@ -32,7 +32,7 @@ namespace mrc::memory { struct memory_resource; } // namespace mrc::memory -namespace mrc::internal::memory { +namespace mrc::memory { /** * @brief A short-lived buffer based on a portion of a data::SharedResable @@ -205,4 +205,4 @@ class TransientPool mrc::data::SharedReusable m_buffer; }; -} // namespace mrc::internal::memory +} // namespace mrc::memory diff --git a/cpp/mrc/src/internal/modules/segment_modules.cpp b/cpp/mrc/src/internal/modules/segment_modules.cpp new file mode 100644 index 000000000..3c77ac9b5 --- /dev/null +++ b/cpp/mrc/src/internal/modules/segment_modules.cpp @@ -0,0 +1,253 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. + */ + +#include "internal/modules/segment_modules.hpp" + +#include "mrc/edge/edge.hpp" +#include "mrc/edge/edge_readable.hpp" +#include "mrc/edge/edge_writable.hpp" +#include "mrc/segment/object.hpp" + +#include + +#include +#include +#include + +namespace mrc::modules { + +SegmentModule::SegmentModule(std::string module_name) : m_module_instance_name(std::move(module_name)) +{ + if (m_module_instance_name.find_first_of("/") != std::string::npos) + { + throw std::invalid_argument("Module name cannot contain '/' characters"); + } +} + +SegmentModule::SegmentModule(std::string module_name, nlohmann::json config) : + m_module_instance_name(std::move(module_name)), + m_config(std::move(config)) +{ + if (m_module_instance_name.find_first_of("/") != std::string::npos) + { + throw std::invalid_argument("Module name cannot contain '/' characters"); + } +} + +std::string SegmentModule::component_prefix() const +{ + return module_type_name() + "::" + name(); +} + +const nlohmann::json& SegmentModule::config() const +{ + return m_config; +} + +const std::vector& SegmentModule::input_ids() const +{ + return m_input_port_ids; +} + +const SegmentModule::segment_module_port_map_t& SegmentModule::input_ports() const +{ + return m_input_ports; +} + +SegmentModule::segment_module_port_t SegmentModule::input_port(const std::string& input_name) +{ + if (m_input_ports.find(input_name) != m_input_ports.end()) + { + return m_input_ports[input_name]; + } + + std::stringstream sstream; + + sstream << "Invalid input port: " << input_name; + throw std::invalid_argument(sstream.str()); +} + +const SegmentModule::segment_module_typeindex_map_t& SegmentModule::input_port_type_ids() const +{ + return m_input_port_type_indices; +} + +std::type_index SegmentModule::input_port_type_id(const std::string& input_name) +{ + auto ipt_iter = m_input_port_type_indices.find(input_name); + if (ipt_iter != m_input_port_type_indices.end()) + { + return ipt_iter->second; + } + + std::stringstream sstream; + + sstream << "Invalid input port: " << input_name; + throw std::invalid_argument(sstream.str()); +} + +const SegmentModule::segment_module_port_map_t& SegmentModule::output_ports() const +{ + return m_output_ports; +} + +SegmentModule::segment_module_port_t SegmentModule::output_port(const std::string& output_name) +{ + if (m_output_ports.find(output_name) != m_output_ports.end()) + { + return m_output_ports[output_name]; + } + + std::stringstream sstream; + + sstream << "Invalid output port: " << output_name; + throw std::invalid_argument(sstream.str()); +} + +const SegmentModule::segment_module_typeindex_map_t& SegmentModule::output_port_type_ids() const +{ + return m_output_port_type_indices; +} + +std::type_index SegmentModule::output_port_type_id(const std::string& output_name) +{ + auto opt_iter = m_output_port_type_indices.find(output_name); + if (opt_iter != m_output_port_type_indices.end()) + { + return opt_iter->second; + } + + std::stringstream sstream; + + sstream << "Invalid output port: " << output_name; + throw std::invalid_argument(sstream.str()); +} + +const std::vector& SegmentModule::output_ids() const +{ + return m_output_port_ids; +} + +const std::string& SegmentModule::name() const +{ + return m_module_instance_name; +} + +void SegmentModule::operator()(segment::IBuilder& builder) +{ + this->initialize(builder); +} + +void SegmentModule::register_input_port(std::string input_name, std::shared_ptr object) +{ + // Seems to be required for ingress ports + if (object->is_sink()) + { + register_typed_input_port(std::move(input_name), object, object->sink_type()); + return; + } + + if (object->is_writable_provider()) + { + auto& writable_provider = object->writable_provider_base(); + register_typed_output_port(std::move(input_name), + object, + writable_provider.writable_provider_type().unwrapped_type()); + return; + } + + if (object->is_readable_acceptor()) + { + auto& readable_acceptor = object->readable_acceptor_base(); + register_typed_input_port(std::move(input_name), + object, + readable_acceptor.readable_acceptor_type().unwrapped_type()); + return; + } + + throw std::invalid_argument("Input port object must be a writable provider or readable acceptor"); +} + +void SegmentModule::register_typed_input_port(std::string input_name, + std::shared_ptr object, + std::type_index tidx) +{ + if (m_input_ports.find(input_name) != m_input_ports.end()) + { + std::stringstream sstream; + + sstream << "Attempt to register duplicate module input port: " + std::move(input_name); + throw std::invalid_argument(sstream.str()); + } + + VLOG(5) << "Registering input port: " << input_name << " with type: " << tidx.name() << " for module: " << name(); + + m_input_port_ids.push_back(input_name); + m_input_ports[input_name] = object; + m_input_port_type_indices.try_emplace(input_name, tidx); +} + +void SegmentModule::register_output_port(std::string output_name, std::shared_ptr object) +{ + // Seems to be necessary for egress ports. + if (object->is_source()) + { + register_typed_output_port(std::move(output_name), object, object->source_type()); + return; + } + + if (object->is_writable_acceptor()) + { + auto& writable_acceptor = object->writable_acceptor_base(); + register_typed_output_port(std::move(output_name), + object, + writable_acceptor.writable_acceptor_type().unwrapped_type()); + return; + } + + if (object->is_readable_provider()) + { + auto& readable_provider = object->readable_provider_base(); + register_typed_output_port(std::move(output_name), + object, + readable_provider.readable_provider_type().unwrapped_type()); + return; + } + + throw std::invalid_argument("Output port object must be a writable acceptor or readable provider"); +} + +void SegmentModule::register_typed_output_port(std::string output_name, + std::shared_ptr object, + std::type_index tidx) +{ + if (m_output_ports.find(output_name) != m_output_ports.end()) + { + std::stringstream sstream; + + sstream << "Attempt to register duplicate module output port: " + std::move(output_name); + throw std::invalid_argument(sstream.str()); + } + + VLOG(5) << "Registering output port: " << output_name << " with type: " << tidx.name() << " for module: " << name(); + + m_output_port_ids.push_back(output_name); + m_output_ports[output_name] = object; + m_output_port_type_indices.try_emplace(output_name, tidx); +} + +} // namespace mrc::modules diff --git a/cpp/mrc/src/internal/modules/segment_modules.hpp b/cpp/mrc/src/internal/modules/segment_modules.hpp new file mode 100644 index 000000000..4789e752a --- /dev/null +++ b/cpp/mrc/src/internal/modules/segment_modules.hpp @@ -0,0 +1,195 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. + */ + +#pragma once + +#include + +#include +#include +#include +#include +#include + +namespace mrc::segment { +class IBuilder; +} // namespace mrc::segment + +namespace mrc::segment { +struct ObjectProperties; +} // namespace mrc::segment + +namespace mrc::modules { + +class SegmentModule +{ + friend mrc::segment::IBuilder; + + public: + using segment_module_port_map_t = std::map>; + using segment_module_port_t = std::shared_ptr; + using segment_module_typeindex_map_t = std::map; + + virtual ~SegmentModule() = default; + + SegmentModule() = delete; + + SegmentModule(std::string module_name); + SegmentModule(std::string module_name, nlohmann::json config); + + std::string component_prefix() const; + const nlohmann::json& config() const; + const std::string& name() const; + + /** + * Return vector of input ids -- these are only understood by the SegmentModule + * @return std::vector + */ + const std::vector& input_ids() const; + + /** + * Return a vector of output ids -- these are only understood by the SegmentModule class + * @return std::vector + */ + const std::vector& output_ids() const; + + /** + * Return a set of ObjectProperties for module input_ids + * @return ObjectProperties + */ + const segment_module_port_map_t& input_ports() const; + + /** + * Return the ObjectProperties object corresponding to input_name + * @param input_name Name of the module port + * @return ObjectProperties + */ + segment_module_port_t input_port(const std::string& input_name); + + /** + * Return a map of module port id : type indices + * @return std::map + */ + const segment_module_typeindex_map_t& input_port_type_ids() const; + + /** + * Return the type index of a given input name + * @return Type index + */ + std::type_index input_port_type_id(const std::string& input_name); + + /** + * Return a set of ObjectProperties for module input_ids + * @return ObjectProperties + */ + const segment_module_port_map_t& output_ports() const; + + /** + * Return an ObjectProperties for the module port corresponding to output name + * @param output_name Name of the module port to return + * @return ObjectProperties + */ + segment_module_port_t output_port(const std::string& output_name); + + /** + * Return a map of module port id : type indices + * @return std::map + */ + const segment_module_typeindex_map_t& output_port_type_ids() const; + + /** + * Return the type index of a given input name + * @param input_name Name of the module port to return a type index for + * @return Type index + */ + std::type_index output_port_type_id(const std::string& output_name); + + /** + * Functional entrypoint for module constructor during build -- this lets us act like a std::function + * @param builder + */ + void operator()(segment::IBuilder& builder); + + /** + * Retrieve the class name for the module, defaults to 'segment_module' + * @return + */ + virtual std::string module_type_name() const = 0; + + protected: + // Derived class interface functions + /* Virtual Functions */ + /** + * Entrypoint for module constructor during build + * @param builder + */ + virtual void initialize(segment::IBuilder& builder) = 0; + + /* Interface Functions */ + /** + * Register an input port that should be exposed for the module + * @param input_name Port name + * @param object ObjectProperties object associated with the port + */ + void register_input_port(std::string input_name, std::shared_ptr object); + + /** + * Register an output port that should be exposed for the module + * @param input_name Port name + * @param object ObjectProperties object associated with the port + */ + void register_output_port(std::string output_name, std::shared_ptr object); + + private: + /** + * Register an input port that should be exposed for the module, with explicit type index. This is + * necessary for Objects that aren't explicit Source or Sink types (e.g. a custom object type) + * @param input_name Port name + * @param object ObjectProperties object associated with the port + * @param tidx Type index of the object's payload data type + */ + void register_typed_input_port(std::string input_name, + std::shared_ptr object, + std::type_index tidx); + /** + * Register an output port that should be exposed for the module, with explicit type index. This is + * necessary for Objects that aren't explicit Source or Sink types (e.g. a custom object type) + * @param output_name Port name + * @param object ObjectProperties object associated with the port + * @param tidx Type index of the object's payload data type + */ + void register_typed_output_port(std::string output_name, + std::shared_ptr object, + std::type_index tidx); + + const std::string m_module_instance_name; + + std::string m_module_instance_registered_namespace{}; + + std::vector m_input_port_ids{}; + std::vector m_output_port_ids{}; + + segment_module_typeindex_map_t m_input_port_type_indices{}; + segment_module_typeindex_map_t m_output_port_type_indices{}; + + segment_module_port_map_t m_input_ports{}; + segment_module_port_map_t m_output_ports{}; + + const nlohmann::json m_config; +}; + +} // namespace mrc::modules diff --git a/cpp/mrc/src/internal/network/resources.cpp b/cpp/mrc/src/internal/network/network_resources.cpp similarity index 64% rename from cpp/mrc/src/internal/network/resources.cpp rename to cpp/mrc/src/internal/network/network_resources.cpp index e6bb4ab54..b28a0d14f 100644 --- a/cpp/mrc/src/internal/network/resources.cpp +++ b/cpp/mrc/src/internal/network/network_resources.cpp @@ -15,14 +15,14 @@ * limitations under the License. */ -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/control_plane/client.hpp" #include "internal/control_plane/client/connections_manager.hpp" #include "internal/control_plane/client/instance.hpp" -#include "internal/data_plane/resources.hpp" +#include "internal/data_plane/data_plane_resources.hpp" #include "internal/resources/partition_resources_base.hpp" -#include "internal/ucx/resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "mrc/core/task_queue.hpp" #include "mrc/types.hpp" @@ -33,12 +33,12 @@ #include #include -namespace mrc::internal::network { +namespace mrc::network { -Resources::Resources(resources::PartitionResourceBase& base, - ucx::Resources& ucx, - memory::HostResources& host, - std::unique_ptr control_plane) : +NetworkResources::NetworkResources(resources::PartitionResourceBase& base, + ucx::UcxResources& ucx, + memory::HostResources& host, + std::unique_ptr control_plane) : resources::PartitionResourceBase(base), m_instance_id(control_plane->instance_id()), m_ucx(ucx), @@ -53,13 +53,16 @@ Resources::Resources(resources::PartitionResourceBase& base, // construct resources on the mrc_network task queue thread ucx.network_task_queue() .enqueue([this, &base, &ucx, &host] { - m_data_plane = - std::make_unique(base, ucx, host, m_instance_id, m_control_plane_client); + m_data_plane = std::make_unique(base, + ucx, + host, + m_instance_id, + m_control_plane_client); }) .get(); } -Resources::~Resources() +NetworkResources::~NetworkResources() { // this will sync with the control plane server to drop the instance // when this completes, we can disable the data plane @@ -72,31 +75,31 @@ Resources::~Resources() } } -data_plane::Resources& Resources::data_plane() +data_plane::DataPlaneResources& NetworkResources::data_plane() { CHECK(m_data_plane); return *m_data_plane; } -control_plane::client::Instance& Resources::control_plane() +control_plane::client::Instance& NetworkResources::control_plane() { CHECK(m_control_plane); return *m_control_plane; } -const InstanceID& Resources::instance_id() const +const InstanceID& NetworkResources::instance_id() const { return m_instance_id; } -ucx::Resources& Resources::ucx() +ucx::UcxResources& NetworkResources::ucx() { return m_ucx; } -Future Resources::shutdown() +Future NetworkResources::shutdown() { return m_control_plane->shutdown(); } -} // namespace mrc::internal::network +} // namespace mrc::network diff --git a/cpp/mrc/src/internal/network/resources.hpp b/cpp/mrc/src/internal/network/network_resources.hpp similarity index 53% rename from cpp/mrc/src/internal/network/resources.hpp rename to cpp/mrc/src/internal/network/network_resources.hpp index d62d75aca..b542299fc 100644 --- a/cpp/mrc/src/internal/network/resources.hpp +++ b/cpp/mrc/src/internal/network/network_resources.hpp @@ -24,57 +24,57 @@ #include -namespace mrc::internal::control_plane { +namespace mrc::control_plane { class Client; -} // namespace mrc::internal::control_plane -namespace mrc::internal::control_plane::client { +} // namespace mrc::control_plane +namespace mrc::control_plane::client { class Instance; -} // namespace mrc::internal::control_plane::client -namespace mrc::internal::data_plane { -class Resources; -} // namespace mrc::internal::data_plane -namespace mrc::internal::memory { +} // namespace mrc::control_plane::client +namespace mrc::data_plane { +class DataPlaneResources; +} // namespace mrc::data_plane +namespace mrc::memory { class HostResources; -} // namespace mrc::internal::memory -namespace mrc::internal::resources { +} // namespace mrc::memory +namespace mrc::resources { class Manager; -} // namespace mrc::internal::resources -namespace mrc::internal::ucx { -class Resources; -} // namespace mrc::internal::ucx +} // namespace mrc::resources +namespace mrc::ucx { +class UcxResources; +} // namespace mrc::ucx -namespace mrc::internal::network { +namespace mrc::network { -class Resources final : private resources::PartitionResourceBase +class NetworkResources final : private resources::PartitionResourceBase { public: - Resources(resources::PartitionResourceBase& base, - ucx::Resources& ucx, - memory::HostResources& host, - std::unique_ptr control_plane); - ~Resources() final; + NetworkResources(resources::PartitionResourceBase& base, + ucx::UcxResources& ucx, + memory::HostResources& host, + std::unique_ptr control_plane); + ~NetworkResources() final; - DELETE_COPYABILITY(Resources); + DELETE_COPYABILITY(NetworkResources); // todo(clang-format-15) // clang-format off - Resources(Resources&&) noexcept = default; - Resources& operator=(Resources&&) noexcept = delete; + NetworkResources(NetworkResources&&) noexcept = default; + NetworkResources& operator=(NetworkResources&&) noexcept = delete; // clang-format on const InstanceID& instance_id() const; - ucx::Resources& ucx(); + ucx::UcxResources& ucx(); control_plane::client::Instance& control_plane(); - data_plane::Resources& data_plane(); + data_plane::DataPlaneResources& data_plane(); private: Future shutdown(); InstanceID m_instance_id; - ucx::Resources& m_ucx; + ucx::UcxResources& m_ucx; control_plane::Client& m_control_plane_client; - std::unique_ptr m_data_plane; + std::unique_ptr m_data_plane; // this must be the first variable destroyed std::unique_ptr m_control_plane; @@ -82,4 +82,4 @@ class Resources final : private resources::PartitionResourceBase friend resources::Manager; }; -} // namespace mrc::internal::network +} // namespace mrc::network diff --git a/cpp/mrc/src/internal/pipeline/controller.cpp b/cpp/mrc/src/internal/pipeline/controller.cpp index 706e1b757..93946abbe 100644 --- a/cpp/mrc/src/internal/pipeline/controller.cpp +++ b/cpp/mrc/src/internal/pipeline/controller.cpp @@ -17,7 +17,7 @@ #include "internal/pipeline/controller.hpp" -#include "internal/pipeline/instance.hpp" +#include "internal/pipeline/pipeline_instance.hpp" #include "internal/pipeline/types.hpp" #include "mrc/core/utils.hpp" @@ -38,9 +38,9 @@ #include #include -namespace mrc::internal::pipeline { +namespace mrc::pipeline { -Controller::Controller(std::unique_ptr pipeline) : m_pipeline(std::move(pipeline)) +Controller::Controller(std::unique_ptr pipeline) : m_pipeline(std::move(pipeline)) { CHECK(m_pipeline); m_pipeline->service_start(); @@ -166,4 +166,4 @@ const std::string& Controller::info() return str; } -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/controller.hpp b/cpp/mrc/src/internal/pipeline/controller.hpp index 037185914..14c9e528b 100644 --- a/cpp/mrc/src/internal/pipeline/controller.hpp +++ b/cpp/mrc/src/internal/pipeline/controller.hpp @@ -24,13 +24,13 @@ #include #include -namespace mrc::internal::pipeline { -class Instance; +namespace mrc::pipeline { +class PipelineInstance; class Controller final : public node::GenericSink { public: - Controller(std::unique_ptr pipeline); + Controller(std::unique_ptr pipeline); ~Controller() override; void await_on_pipeline() const; @@ -45,8 +45,8 @@ class Controller final : public node::GenericSink static const std::string& info(); - std::unique_ptr m_pipeline; + std::unique_ptr m_pipeline; SegmentAddresses m_current_segments; }; -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/forward.hpp b/cpp/mrc/src/internal/pipeline/forward.hpp index c8c7eb781..b191d42e9 100644 --- a/cpp/mrc/src/internal/pipeline/forward.hpp +++ b/cpp/mrc/src/internal/pipeline/forward.hpp @@ -17,7 +17,7 @@ #pragma once -namespace mrc::internal::pipeline { +namespace mrc::pipeline { class Pipeline; class Manager; -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/ipipeline.cpp b/cpp/mrc/src/internal/pipeline/ipipeline.cpp deleted file mode 100644 index 41d86dd82..000000000 --- a/cpp/mrc/src/internal/pipeline/ipipeline.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#include "mrc/engine/pipeline/ipipeline.hpp" - -#include "internal/pipeline/pipeline.hpp" - -#include "mrc/engine/segment/idefinition.hpp" - -#include - -#include - -namespace mrc::internal::pipeline { - -IPipeline::IPipeline() : m_impl(std::make_shared()) {} -IPipeline::~IPipeline() = default; - -void IPipeline::register_segment(std::shared_ptr segment) -{ - CHECK(segment); - add_segment(segment->m_impl); -} - -void IPipeline::add_segment(std::shared_ptr segment) -{ - CHECK(segment); - CHECK(m_impl); - m_impl->add_segment(std::move(segment)); -} - -} // namespace mrc::internal::pipeline diff --git a/cpp/mrc/src/internal/pipeline/manager.cpp b/cpp/mrc/src/internal/pipeline/manager.cpp index 837dc7132..0487fdfb9 100644 --- a/cpp/mrc/src/internal/pipeline/manager.cpp +++ b/cpp/mrc/src/internal/pipeline/manager.cpp @@ -18,11 +18,11 @@ #include "internal/pipeline/manager.hpp" #include "internal/pipeline/controller.hpp" -#include "internal/pipeline/instance.hpp" +#include "internal/pipeline/pipeline_instance.hpp" #include "internal/pipeline/types.hpp" #include "internal/resources/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "mrc/edge/edge_builder.hpp" #include "mrc/node/writable_entrypoint.hpp" @@ -41,9 +41,9 @@ #include #include -namespace mrc::internal::pipeline { +namespace mrc::pipeline { -Manager::Manager(std::shared_ptr pipeline, resources::Manager& resources) : +Manager::Manager(std::shared_ptr pipeline, resources::Manager& resources) : m_pipeline(std::move(pipeline)), m_resources(resources) { @@ -71,7 +71,7 @@ void Manager::do_service_start() main.pe_count = 1; main.engines_per_pe = 1; - auto instance = std::make_unique(m_pipeline, m_resources); + auto instance = std::make_unique(m_pipeline, m_resources); auto controller = std::make_unique(std::move(instance)); m_update_channel = std::make_unique>(); @@ -133,9 +133,9 @@ resources::Manager& Manager::resources() return m_resources; } -const Pipeline& Manager::pipeline() const +const PipelineDefinition& Manager::pipeline() const { CHECK(m_pipeline); return *m_pipeline; } -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/manager.hpp b/cpp/mrc/src/internal/pipeline/manager.hpp index e3641e458..cce46c347 100644 --- a/cpp/mrc/src/internal/pipeline/manager.hpp +++ b/cpp/mrc/src/internal/pipeline/manager.hpp @@ -26,15 +26,15 @@ // IWYU pragma: no_forward_declare mrc::node::WritableEntrypoint -namespace mrc::internal::resources { +namespace mrc::resources { class Manager; -} // namespace mrc::internal::resources +} // namespace mrc::resources namespace mrc::runnable { class Runner; } // namespace mrc::runnable -namespace mrc::internal::pipeline { -class Pipeline; +namespace mrc::pipeline { +class PipelineDefinition; /** * @brief Responsible for coordinating and controlling a Pipeline running on a set of resources/partitions. @@ -46,10 +46,10 @@ class Pipeline; class Manager : public Service { public: - Manager(std::shared_ptr pipeline, resources::Manager& resources); + Manager(std::shared_ptr pipeline, resources::Manager& resources); ~Manager() override; - const Pipeline& pipeline() const; + const PipelineDefinition& pipeline() const; void push_updates(SegmentAddresses&& segment_addresses); @@ -64,9 +64,9 @@ class Manager : public Service void do_service_await_join() final; resources::Manager& m_resources; - std::shared_ptr m_pipeline; + std::shared_ptr m_pipeline; std::unique_ptr> m_update_channel; std::unique_ptr m_controller; }; -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/pipeline.cpp b/cpp/mrc/src/internal/pipeline/pipeline.cpp deleted file mode 100644 index 0113c6683..000000000 --- a/cpp/mrc/src/internal/pipeline/pipeline.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#include "internal/pipeline/pipeline.hpp" - -#include "internal/segment/definition.hpp" - -#include "mrc/engine/pipeline/ipipeline.hpp" -#include "mrc/exceptions/runtime_error.hpp" -#include "mrc/types.hpp" - -#include - -#include -#include -#include -#include - -namespace mrc::internal::pipeline { - -void Pipeline::add_segment(std::shared_ptr segment) -{ - auto id = m_segment_hasher.register_name(segment->name()); - - // check to ensure segment is not already registered - auto search = m_segments.find(id); - if (search != m_segments.end()) - { - LOG(ERROR) << "segment: " << segment->name() << " is already registered"; - throw exceptions::MrcRuntimeError("duplicate segment registration"); - } - - // check for name collisions - for (auto& name : segment->ingress_port_names()) - { - auto pid = m_port_hasher.register_name(name); - DVLOG(10) << "segment: " << segment->name() << " [" << id << "] - ingress port " << name << " [" << pid << "]"; - } - for (auto& name : segment->egress_port_names()) - { - auto pid = m_port_hasher.register_name(name); - DVLOG(10) << "segment: " << segment->name() << " [" << id << "] - egress port " << name << " [" << pid << "]"; - } - - m_segments[id] = segment; -} - -std::shared_ptr Pipeline::find_segment(SegmentID segment_id) const -{ - auto search = m_segments.find(segment_id); - CHECK(search != m_segments.end()); - return search->second; -} - -const std::map>& Pipeline::segments() const -{ - return m_segments; -} -std::shared_ptr Pipeline::unwrap(IPipeline& pipeline) -{ - return pipeline.m_impl; -} -} // namespace mrc::internal::pipeline diff --git a/cpp/mrc/src/internal/pipeline/pipeline.hpp b/cpp/mrc/src/internal/pipeline/pipeline.hpp deleted file mode 100644 index 1f994384f..000000000 --- a/cpp/mrc/src/internal/pipeline/pipeline.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include "internal/utils/collision_detector.hpp" - -#include "mrc/types.hpp" - -#include -#include - -namespace mrc::internal::segment { -class Definition; -} // namespace mrc::internal::segment - -namespace mrc::internal::pipeline { -class IPipeline; - -class Pipeline -{ - public: - static std::shared_ptr unwrap(IPipeline& pipeline); - - void add_segment(std::shared_ptr segment); - - const std::map>& segments() const; - - std::shared_ptr find_segment(SegmentID segment_id) const; - - private: - utils::CollisionDetector m_segment_hasher; - utils::CollisionDetector m_port_hasher; - - std::map> m_segments; -}; - -} // namespace mrc::internal::pipeline diff --git a/cpp/mrc/src/internal/pipeline/pipeline_definition.cpp b/cpp/mrc/src/internal/pipeline/pipeline_definition.cpp new file mode 100644 index 000000000..0e035159a --- /dev/null +++ b/cpp/mrc/src/internal/pipeline/pipeline_definition.cpp @@ -0,0 +1,126 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. + */ + +#include "internal/pipeline/pipeline_definition.hpp" + +#include "internal/segment/segment_definition.hpp" + +#include "mrc/exceptions/runtime_error.hpp" +#include "mrc/pipeline/segment.hpp" +#include "mrc/segment/egress_ports.hpp" +#include "mrc/segment/ingress_ports.hpp" +#include "mrc/types.hpp" + +#include + +#include +#include +#include +#include + +namespace mrc::pipeline { + +PipelineDefinition::~PipelineDefinition() = default; + +std::shared_ptr PipelineDefinition::unwrap(std::shared_ptr object) +{ + // Convert to the full implementation + auto full_object = std::dynamic_pointer_cast(object); + + CHECK(full_object) << "Invalid cast for PipelineDefinition. Please report to the developers"; + + return full_object; +} + +std::shared_ptr PipelineDefinition::register_segment(std::shared_ptr segment) +{ + auto id = m_segment_hasher.register_name(segment->name()); + + // check to ensure segment is not already registered + auto search = m_segments.find(id); + if (search != m_segments.end()) + { + LOG(ERROR) << "segment: " << segment->name() << " is already registered"; + throw exceptions::MrcRuntimeError("duplicate segment registration"); + } + + auto full_segment = segment::SegmentDefinition::unwrap(std::move(segment)); + + // check for name collisions + for (auto& name : full_segment->ingress_port_names()) + { + auto pid = m_port_hasher.register_name(name); + DVLOG(10) << "segment: " << full_segment->name() << " [" << id << "] - ingress port " << name << " [" << pid + << "]"; + } + for (auto& name : full_segment->egress_port_names()) + { + auto pid = m_port_hasher.register_name(name); + DVLOG(10) << "segment: " << full_segment->name() << " [" << id << "] - egress port " << name << " [" << pid + << "]"; + } + + const auto& [inserted_iterator, was_inserted] = m_segments.emplace(id, std::move(full_segment)); + + return inserted_iterator->second; +} + +std::shared_ptr PipelineDefinition::make_segment(const std::string& segment_name, + segment::segment_initializer_fn_t segment_initializer) +{ + auto segdef = Segment::create(segment_name, segment_initializer); + return this->register_segment(std::move(segdef)); +} + +std::shared_ptr PipelineDefinition::make_segment(const std::string& segment_name, + segment::IngressPortsBase ingress_ports, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t segment_initializer) +{ + auto segdef = Segment::create(segment_name, ingress_ports, egress_ports, segment_initializer); + return this->register_segment(std::move(segdef)); +} + +std::shared_ptr PipelineDefinition::make_segment(const std::string& segment_name, + segment::IngressPortsBase ingress_ports, + segment::segment_initializer_fn_t segment_initializer) +{ + auto segdef = Segment::create(segment_name, ingress_ports, segment_initializer); + return this->register_segment(std::move(segdef)); +} + +std::shared_ptr PipelineDefinition::make_segment(const std::string& segment_name, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t segment_initializer) +{ + auto segdef = Segment::create(segment_name, egress_ports, segment_initializer); + return this->register_segment(std::move(segdef)); +} + +std::shared_ptr PipelineDefinition::find_segment(SegmentID segment_id) const +{ + auto search = m_segments.find(segment_id); + CHECK(search != m_segments.end()); + return search->second; +} + +const std::map>& PipelineDefinition::segments() const +{ + return m_segments; +} + +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/pipeline_definition.hpp b/cpp/mrc/src/internal/pipeline/pipeline_definition.hpp new file mode 100644 index 000000000..d6227e1eb --- /dev/null +++ b/cpp/mrc/src/internal/pipeline/pipeline_definition.hpp @@ -0,0 +1,77 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. + */ + +#pragma once + +#include "internal/utils/collision_detector.hpp" + +#include "mrc/pipeline/pipeline.hpp" +#include "mrc/segment/initializers.hpp" +#include "mrc/types.hpp" + +#include +#include +#include + +namespace mrc::segment { +class SegmentDefinition; +struct EgressPortsBase; +struct IngressPortsBase; +} // namespace mrc::segment + +namespace mrc::pipeline { +class ISegment; + +class PipelineDefinition : public IPipeline +{ + public: + ~PipelineDefinition() override; + + static std::shared_ptr unwrap(std::shared_ptr object); + + std::shared_ptr register_segment(std::shared_ptr segment) override; + + std::shared_ptr make_segment(const std::string& segment_name, + segment::segment_initializer_fn_t segment_initializer) override; + + std::shared_ptr make_segment(const std::string& segment_name, + segment::IngressPortsBase ingress_ports, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t segment_initializer) override; + + std::shared_ptr make_segment(const std::string& segment_name, + segment::IngressPortsBase ingress_ports, + segment::segment_initializer_fn_t segment_initializer) override; + + std::shared_ptr make_segment(const std::string& segment_name, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t segment_initializer) override; + + // static std::shared_ptr unwrap(IPipeline& pipeline); + + const std::map>& segments() const; + + std::shared_ptr find_segment(SegmentID segment_id) const; + + private: + utils::CollisionDetector m_segment_hasher; + utils::CollisionDetector m_port_hasher; + + std::map> m_segments; +}; + +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/instance.cpp b/cpp/mrc/src/internal/pipeline/pipeline_instance.cpp similarity index 76% rename from cpp/mrc/src/internal/pipeline/instance.cpp rename to cpp/mrc/src/internal/pipeline/pipeline_instance.cpp index 952d922bd..50e3abca1 100644 --- a/cpp/mrc/src/internal/pipeline/instance.cpp +++ b/cpp/mrc/src/internal/pipeline/pipeline_instance.cpp @@ -15,15 +15,15 @@ * limitations under the License. */ -#include "internal/pipeline/instance.hpp" +#include "internal/pipeline/pipeline_instance.hpp" -#include "internal/pipeline/pipeline.hpp" -#include "internal/pipeline/resources.hpp" +#include "internal/pipeline/pipeline_definition.hpp" +#include "internal/pipeline/pipeline_resources.hpp" #include "internal/resources/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" -#include "internal/segment/definition.hpp" -#include "internal/segment/instance.hpp" +#include "internal/runnable/runnable_resources.hpp" +#include "internal/segment/segment_definition.hpp" +#include "internal/segment/segment_instance.hpp" #include "mrc/core/addresses.hpp" #include "mrc/core/task_queue.hpp" @@ -35,24 +35,26 @@ #include #include +#include #include #include #include #include -namespace mrc::internal::pipeline { +namespace mrc::pipeline { -Instance::Instance(std::shared_ptr definition, resources::Manager& resources) : - Resources(resources), +PipelineInstance::PipelineInstance(std::shared_ptr definition, + resources::Manager& resources) : + PipelineResources(resources), m_definition(std::move(definition)) { CHECK(m_definition); m_joinable_future = m_joinable_promise.get_future().share(); } -Instance::~Instance() = default; +PipelineInstance::~PipelineInstance() = default; -void Instance::update() +void PipelineInstance::update() { for (const auto& [name, manifold] : m_manifolds) { @@ -68,21 +70,21 @@ void Instance::update() mark_joinable(); } -void Instance::remove_segment(const SegmentAddress& address) +void PipelineInstance::remove_segment(const SegmentAddress& address) { auto search = m_segments.find(address); CHECK(search != m_segments.end()); m_segments.erase(search); } -void Instance::join_segment(const SegmentAddress& address) +void PipelineInstance::join_segment(const SegmentAddress& address) { auto search = m_segments.find(address); CHECK(search != m_segments.end()); search->second->service_await_join(); } -void Instance::stop_segment(const SegmentAddress& address) +void PipelineInstance::stop_segment(const SegmentAddress& address) { auto search = m_segments.find(address); CHECK(search != m_segments.end()); @@ -99,7 +101,7 @@ void Instance::stop_segment(const SegmentAddress& address) search->second->service_stop(); } -void Instance::create_segment(const SegmentAddress& address, std::uint32_t partition_id) +void PipelineInstance::create_segment(const SegmentAddress& address, std::uint32_t partition_id) { // perform our allocations on the numa domain of the intended target // CHECK_LT(partition_id, m_resources->host_resources().size()); @@ -114,7 +116,7 @@ void Instance::create_segment(const SegmentAddress& address, std::uint32_t parti auto [id, rank] = segment_address_decode(address); auto definition = m_definition->find_segment(id); - auto segment = std::make_unique(definition, rank, *this, partition_id); + auto segment = std::make_unique(definition, rank, *this, partition_id); for (const auto& name : definition->egress_port_names()) { @@ -147,14 +149,14 @@ void Instance::create_segment(const SegmentAddress& address, std::uint32_t parti .get(); } -manifold::Interface& Instance::manifold(const PortName& port_name) +manifold::Interface& PipelineInstance::manifold(const PortName& port_name) { auto manifold = get_manifold(port_name); CHECK(manifold); return *manifold; } -std::shared_ptr Instance::get_manifold(const PortName& port_name) +std::shared_ptr PipelineInstance::get_manifold(const PortName& port_name) { auto search = m_manifolds.find(port_name); if (search == m_manifolds.end()) @@ -165,7 +167,7 @@ std::shared_ptr Instance::get_manifold(const PortName& port return m_manifolds.at(port_name); } -void Instance::mark_joinable() +void PipelineInstance::mark_joinable() { if (!m_joinable) { @@ -174,14 +176,14 @@ void Instance::mark_joinable() } } -void Instance::do_service_start() {} +void PipelineInstance::do_service_start() {} -void Instance::do_service_await_live() +void PipelineInstance::do_service_await_live() { m_joinable_future.get(); } -void Instance::do_service_stop() +void PipelineInstance::do_service_stop() { mark_joinable(); @@ -191,7 +193,7 @@ void Instance::do_service_stop() } } -void Instance::do_service_kill() +void PipelineInstance::do_service_kill() { mark_joinable(); for (auto& [id, segment] : m_segments) @@ -201,7 +203,7 @@ void Instance::do_service_kill() } } -void Instance::do_service_await_join() +void PipelineInstance::do_service_await_join() { std::exception_ptr first_exception = nullptr; m_joinable_future.get(); @@ -220,9 +222,9 @@ void Instance::do_service_await_join() } if (first_exception) { - LOG(ERROR) << "pipeline::Instance - an exception was caught while awaiting on segments - rethrowing"; + LOG(ERROR) << "pipeline::PipelineInstance - an exception was caught while awaiting on segments - rethrowing"; std::rethrow_exception(std::move(first_exception)); } } -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/instance.hpp b/cpp/mrc/src/internal/pipeline/pipeline_instance.hpp similarity index 78% rename from cpp/mrc/src/internal/pipeline/instance.hpp rename to cpp/mrc/src/internal/pipeline/pipeline_instance.hpp index ceb68abba..d9f2489b8 100644 --- a/cpp/mrc/src/internal/pipeline/instance.hpp +++ b/cpp/mrc/src/internal/pipeline/pipeline_instance.hpp @@ -17,7 +17,7 @@ #pragma once -#include "internal/pipeline/resources.hpp" +#include "internal/pipeline/pipeline_resources.hpp" #include "internal/service.hpp" #include "mrc/types.hpp" @@ -26,24 +26,24 @@ #include #include -namespace mrc::internal::resources { +namespace mrc::resources { class Manager; -} // namespace mrc::internal::resources -namespace mrc::internal::segment { -class Instance; -} // namespace mrc::internal::segment +} // namespace mrc::resources +namespace mrc::segment { +class SegmentInstance; +} // namespace mrc::segment namespace mrc::manifold { struct Interface; } // namespace mrc::manifold -namespace mrc::internal::pipeline { -class Pipeline; +namespace mrc::pipeline { +class PipelineDefinition; -class Instance final : public Service, public Resources +class PipelineInstance final : public Service, public PipelineResources { public: - Instance(std::shared_ptr definition, resources::Manager& resources); - ~Instance() override; + PipelineInstance(std::shared_ptr definition, resources::Manager& resources); + ~PipelineInstance() override; // currently we are passing the instance back to the executor // we should own the instance here in the pipeline instance @@ -76,9 +76,9 @@ class Instance final : public Service, public Resources manifold::Interface& manifold(const PortName& port_name); std::shared_ptr get_manifold(const PortName& port_name); - std::shared_ptr m_definition; // convert to pipeline::Pipeline + std::shared_ptr m_definition; // convert to pipeline::Pipeline - std::map> m_segments; + std::map> m_segments; std::map> m_manifolds; bool m_joinable{false}; @@ -86,4 +86,4 @@ class Instance final : public Service, public Resources SharedFuture m_joinable_future; }; -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/resources.cpp b/cpp/mrc/src/internal/pipeline/pipeline_resources.cpp similarity index 73% rename from cpp/mrc/src/internal/pipeline/resources.cpp rename to cpp/mrc/src/internal/pipeline/pipeline_resources.cpp index 555050c4f..2a336fe94 100644 --- a/cpp/mrc/src/internal/pipeline/resources.cpp +++ b/cpp/mrc/src/internal/pipeline/pipeline_resources.cpp @@ -15,30 +15,30 @@ * limitations under the License. */ -#include "internal/pipeline/resources.hpp" +#include "internal/pipeline/pipeline_resources.hpp" #include "mrc/metrics/registry.hpp" #include -namespace mrc::internal::pipeline { +namespace mrc::pipeline { -Resources::Resources(resources::Manager& resources) : +PipelineResources::PipelineResources(resources::Manager& resources) : m_resources(resources), m_metrics_registry(std::make_unique()) {} -Resources::~Resources() = default; +PipelineResources::~PipelineResources() = default; -resources::Manager& Resources::resources() const +resources::Manager& PipelineResources::resources() const { return m_resources; } -metrics::Registry& Resources::metrics_registry() const +metrics::Registry& PipelineResources::metrics_registry() const { DCHECK(m_metrics_registry); return *m_metrics_registry; } -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/resources.hpp b/cpp/mrc/src/internal/pipeline/pipeline_resources.hpp similarity index 81% rename from cpp/mrc/src/internal/pipeline/resources.hpp rename to cpp/mrc/src/internal/pipeline/pipeline_resources.hpp index fc8c1fef1..898516be2 100644 --- a/cpp/mrc/src/internal/pipeline/resources.hpp +++ b/cpp/mrc/src/internal/pipeline/pipeline_resources.hpp @@ -23,17 +23,17 @@ namespace mrc::metrics { class Registry; } // namespace mrc::metrics -namespace mrc::internal::resources { +namespace mrc::resources { class Manager; -} // namespace mrc::internal::resources +} // namespace mrc::resources -namespace mrc::internal::pipeline { +namespace mrc::pipeline { -class Resources +class PipelineResources { public: - Resources(resources::Manager& resources); - ~Resources(); + PipelineResources(resources::Manager& resources); + ~PipelineResources(); resources::Manager& resources() const; metrics::Registry& metrics_registry() const; @@ -43,4 +43,4 @@ class Resources std::unique_ptr m_metrics_registry; }; -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/port_graph.cpp b/cpp/mrc/src/internal/pipeline/port_graph.cpp index d40f2c74e..6a1cead0f 100644 --- a/cpp/mrc/src/internal/pipeline/port_graph.cpp +++ b/cpp/mrc/src/internal/pipeline/port_graph.cpp @@ -17,15 +17,15 @@ #include "internal/pipeline/port_graph.hpp" -#include "internal/pipeline/pipeline.hpp" -#include "internal/segment/definition.hpp" +#include "internal/pipeline/pipeline_definition.hpp" +#include "internal/segment/segment_definition.hpp" #include #include -namespace mrc::internal::pipeline { +namespace mrc::pipeline { -PortGraph::PortGraph(const Pipeline& pipeline) +PortGraph::PortGraph(const PipelineDefinition& pipeline) { for (const auto& [seg_id, seg_definition] : pipeline.segments()) { @@ -72,4 +72,4 @@ const std::set& PortGraph::segments_with_only_egress_ports() const { return m_sinks; } -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/port_graph.hpp b/cpp/mrc/src/internal/pipeline/port_graph.hpp index ac22ba1d0..c889c9df3 100644 --- a/cpp/mrc/src/internal/pipeline/port_graph.hpp +++ b/cpp/mrc/src/internal/pipeline/port_graph.hpp @@ -25,9 +25,9 @@ * @brief Graph of Pipeline Ports */ -namespace mrc::internal::pipeline { +namespace mrc::pipeline { -class Pipeline; +class PipelineDefinition; struct PortConnections { @@ -41,7 +41,7 @@ using PortMap = std::map; // NOLINT class PortGraph { public: - PortGraph(const Pipeline& pipeline); + PortGraph(const PipelineDefinition& pipeline); const PortMap& port_map() const; @@ -62,4 +62,4 @@ class PortGraph std::set m_sources; }; -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pipeline/types.hpp b/cpp/mrc/src/internal/pipeline/types.hpp index f8e3a012c..68699b57e 100644 --- a/cpp/mrc/src/internal/pipeline/types.hpp +++ b/cpp/mrc/src/internal/pipeline/types.hpp @@ -21,7 +21,7 @@ #include -namespace mrc::internal::pipeline { +namespace mrc::pipeline { using PartitionID = std::uint32_t; // NOLINT using SegmentAddresses = std::map; // NOLINT @@ -39,4 +39,4 @@ struct ControlMessage SegmentAddresses addresses; }; -} // namespace mrc::internal::pipeline +} // namespace mrc::pipeline diff --git a/cpp/mrc/src/internal/pubsub/base.hpp b/cpp/mrc/src/internal/pubsub/base.hpp index f4b54f5ed..14b040333 100644 --- a/cpp/mrc/src/internal/pubsub/base.hpp +++ b/cpp/mrc/src/internal/pubsub/base.hpp @@ -18,13 +18,13 @@ #pragma once #include "internal/control_plane/client/subscription_service.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/resources/partition_resources.hpp" #include "internal/runtime/runtime.hpp" #include -namespace mrc::internal::pubsub { +namespace mrc::pubsub { /** * @brief PubSub is a specialization of the generic SubscriptionService @@ -73,4 +73,4 @@ class Base : public control_plane::client::SubscriptionService runtime::Partition& m_runtime; }; -} // namespace mrc::internal::pubsub +} // namespace mrc::pubsub diff --git a/cpp/mrc/src/internal/pubsub/forward.hpp b/cpp/mrc/src/internal/pubsub/forward.hpp index f005b5d2b..6399fa332 100644 --- a/cpp/mrc/src/internal/pubsub/forward.hpp +++ b/cpp/mrc/src/internal/pubsub/forward.hpp @@ -17,7 +17,7 @@ #pragma once -namespace mrc::internal::pubsub { +namespace mrc::pubsub { class PublisherService; class SubscriberService; @@ -25,4 +25,4 @@ class SubscriberService; // Specific types of Publishers class PublisherRoundRobin; -} // namespace mrc::internal::pubsub +} // namespace mrc::pubsub diff --git a/cpp/mrc/src/internal/pubsub/publisher_round_robin.cpp b/cpp/mrc/src/internal/pubsub/publisher_round_robin.cpp index 134979298..dcaf27272 100644 --- a/cpp/mrc/src/internal/pubsub/publisher_round_robin.cpp +++ b/cpp/mrc/src/internal/pubsub/publisher_round_robin.cpp @@ -19,7 +19,7 @@ #include "internal/data_plane/client.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "mrc/core/task_queue.hpp" #include "mrc/runtime/remote_descriptor.hpp" @@ -30,7 +30,7 @@ #include #include -namespace mrc::internal::pubsub { +namespace mrc::pubsub { void PublisherRoundRobin::on_update() { @@ -65,4 +65,4 @@ void PublisherRoundRobin::apply_policy(rxcpp::subscriber #include -namespace mrc::internal::data_plane { +namespace mrc::data_plane { struct RemoteDescriptorMessage; -} // namespace mrc::internal::data_plane -namespace mrc::internal::runtime { +} // namespace mrc::data_plane +namespace mrc::runtime { class Partition; -} // namespace mrc::internal::runtime -namespace mrc::internal::ucx { +} // namespace mrc::runtime +namespace mrc::ucx { class Endpoint; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx namespace mrc::runtime { class RemoteDescriptor; } // namespace mrc::runtime -namespace mrc::internal::pubsub { +namespace mrc::pubsub { class PublisherRoundRobin final : public PublisherService { @@ -60,4 +60,4 @@ class PublisherRoundRobin final : public PublisherService friend runtime::Partition; }; -} // namespace mrc::internal::pubsub +} // namespace mrc::pubsub diff --git a/cpp/mrc/src/internal/pubsub/publisher_service.cpp b/cpp/mrc/src/internal/pubsub/publisher_service.cpp index b46df5078..2ea517e44 100644 --- a/cpp/mrc/src/internal/pubsub/publisher_service.cpp +++ b/cpp/mrc/src/internal/pubsub/publisher_service.cpp @@ -19,11 +19,11 @@ #include "internal/codable/codable_storage.hpp" #include "internal/data_plane/client.hpp" -#include "internal/data_plane/resources.hpp" -#include "internal/network/resources.hpp" +#include "internal/data_plane/data_plane_resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/remote_descriptor/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/runtime/partition.hpp" #include "mrc/channel/status.hpp" @@ -44,7 +44,7 @@ #include #include -namespace mrc::internal::pubsub { +namespace mrc::pubsub { PublisherService::PublisherService(std::string service_name, runtime::Partition& runtime) : Base(std::move(service_name), runtime), @@ -152,4 +152,4 @@ const std::unordered_map>& Publish { return m_tagged_endpoints; } -} // namespace mrc::internal::pubsub +} // namespace mrc::pubsub diff --git a/cpp/mrc/src/internal/pubsub/publisher_service.hpp b/cpp/mrc/src/internal/pubsub/publisher_service.hpp index 8f1ba9bd4..c5531230d 100644 --- a/cpp/mrc/src/internal/pubsub/publisher_service.hpp +++ b/cpp/mrc/src/internal/pubsub/publisher_service.hpp @@ -32,23 +32,23 @@ #include #include -namespace mrc::internal::data_plane { +namespace mrc::data_plane { struct RemoteDescriptorMessage; -} // namespace mrc::internal::data_plane +} // namespace mrc::data_plane namespace mrc::runtime { class RemoteDescriptor; } // namespace mrc::runtime namespace mrc::codable { struct ICodableStorage; } // namespace mrc::codable -namespace mrc::internal::runtime { +namespace mrc::runtime { class Partition; -} // namespace mrc::internal::runtime -namespace mrc::internal::ucx { +} // namespace mrc::runtime +namespace mrc::ucx { class Endpoint; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx -namespace mrc::internal::pubsub { +namespace mrc::pubsub { class PublisherService : public Base, public mrc::pubsub::IPublisherService { @@ -90,19 +90,19 @@ class PublisherService : public Base, public mrc::pubsub::IPublisherService // [IPublisherService] provides a runtime dependent codable storage object std::unique_ptr create_storage() final; - // [internal::control_plane::client::SubscriptionService] + // [control_plane::client::SubscriptionService] // setup up the runnables needed to driver the publisher void do_subscription_service_setup() final; - // [internal::control_plane::client::SubscriptionService] + // [control_plane::client::SubscriptionService] // teardown up the runnables needed to driver the publisher void do_subscription_service_teardown() final; - // [internal::control_plane::client::SubscriptionService] + // [control_plane::client::SubscriptionService] // await on the completion of all internal runnables void do_subscription_service_join() final; - // [internal::control_plane::client::SubscriptionService] + // [control_plane::client::SubscriptionService] // called by the update engine when updates for a given subscribed_to role is received void update_tagged_instances(const std::string& role, const std::unordered_map& tagged_instances) final; @@ -127,4 +127,4 @@ class PublisherService : public Base, public mrc::pubsub::IPublisherService std::unordered_map> m_tagged_endpoints; }; -} // namespace mrc::internal::pubsub +} // namespace mrc::pubsub diff --git a/cpp/mrc/src/internal/pubsub/subscriber_service.cpp b/cpp/mrc/src/internal/pubsub/subscriber_service.cpp index b4eaabcff..c53dac546 100644 --- a/cpp/mrc/src/internal/pubsub/subscriber_service.cpp +++ b/cpp/mrc/src/internal/pubsub/subscriber_service.cpp @@ -17,13 +17,13 @@ #include "internal/pubsub/subscriber_service.hpp" -#include "internal/data_plane/resources.hpp" +#include "internal/data_plane/data_plane_resources.hpp" #include "internal/data_plane/server.hpp" #include "internal/memory/transient_pool.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/remote_descriptor/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/runtime/partition.hpp" #include "mrc/edge/edge_builder.hpp" @@ -43,7 +43,7 @@ #include #include -namespace mrc::internal::pubsub { +namespace mrc::pubsub { SubscriberService::SubscriberService(std::string service_name, runtime::Partition& runtime) : Base(std::move(service_name), runtime) @@ -111,4 +111,4 @@ void SubscriberService::update_tagged_instances(const std::string& role, { LOG(FATAL) << "subscribers should not receive updates"; } -} // namespace mrc::internal::pubsub +} // namespace mrc::pubsub diff --git a/cpp/mrc/src/internal/pubsub/subscriber_service.hpp b/cpp/mrc/src/internal/pubsub/subscriber_service.hpp index 1083d65bc..6bfa33b32 100644 --- a/cpp/mrc/src/internal/pubsub/subscriber_service.hpp +++ b/cpp/mrc/src/internal/pubsub/subscriber_service.hpp @@ -33,14 +33,14 @@ namespace mrc::runnable { class Runner; } // namespace mrc::runnable -namespace mrc::internal::memory { +namespace mrc::memory { class TransientBuffer; -} // namespace mrc::internal::memory -namespace mrc::internal::runtime { +} // namespace mrc::memory +namespace mrc::runtime { class Partition; -} // namespace mrc::internal::runtime +} // namespace mrc::runtime -namespace mrc::internal::pubsub { +namespace mrc::pubsub { /** * @brief The internal type-erased SubscriberService @@ -63,19 +63,19 @@ class SubscriberService final : public Base, public mrc::pubsub::ISubscriberServ const std::set& subscribe_to_roles() const final; private: - // [internal::control_plane::client::SubscriptionService] + // [control_plane::client::SubscriptionService] // setup up the runnables needed to driver the publisher void do_subscription_service_setup() final; - // [internal::control_plane::client::SubscriptionService] + // [control_plane::client::SubscriptionService] // teardown up the runnables needed to driver the publisher void do_subscription_service_teardown() final; - // [internal::control_plane::client::SubscriptionService] + // [control_plane::client::SubscriptionService] // await on the completion of all internal runnables void do_subscription_service_join() final; - // [internal::control_plane::client::SubscriptionService] + // [control_plane::client::SubscriptionService] // called by the update engine when updates for a given subscribed_to role is received void update_tagged_instances(const std::string& role, const std::unordered_map& tagged_instances) final; @@ -90,4 +90,4 @@ class SubscriberService final : public Base, public mrc::pubsub::ISubscriberServ friend runtime::Partition; }; -} // namespace mrc::internal::pubsub +} // namespace mrc::pubsub diff --git a/cpp/mrc/src/internal/remote_descriptor/decodable_storage.cpp b/cpp/mrc/src/internal/remote_descriptor/decodable_storage.cpp index a8391a3c7..406a91e7b 100644 --- a/cpp/mrc/src/internal/remote_descriptor/decodable_storage.cpp +++ b/cpp/mrc/src/internal/remote_descriptor/decodable_storage.cpp @@ -19,7 +19,7 @@ #include -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { DecodableStorage::DecodableStorage(mrc::codable::protos::RemoteDescriptor&& proto, resources::PartitionResources& resources) : @@ -43,4 +43,4 @@ const mrc::codable::protos::RemoteDescriptor& DecodableStorage::remote_descripto { return m_proto; } -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/remote_descriptor/decodable_storage.hpp b/cpp/mrc/src/internal/remote_descriptor/decodable_storage.hpp index d2860f5d6..c618f7ccd 100644 --- a/cpp/mrc/src/internal/remote_descriptor/decodable_storage.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/decodable_storage.hpp @@ -25,11 +25,11 @@ #include "mrc/runtime/remote_descriptor_handle.hpp" #include "mrc/utils/macros.hpp" -namespace mrc::internal::resources { +namespace mrc::resources { class PartitionResources; -} // namespace mrc::internal::resources +} // namespace mrc::resources -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { class DecodableStorage final : public codable::DecodableStorageView, public codable::StorageView, @@ -54,4 +54,4 @@ class DecodableStorage final : public codable::DecodableStorageView, resources::PartitionResources& m_resources; }; -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/remote_descriptor/forward.hpp b/cpp/mrc/src/internal/remote_descriptor/forward.hpp index 01b7e9a05..266a8f3d3 100644 --- a/cpp/mrc/src/internal/remote_descriptor/forward.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/forward.hpp @@ -17,8 +17,8 @@ #pragma once -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { class Manager; -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/remote_descriptor/manager.cpp b/cpp/mrc/src/internal/remote_descriptor/manager.cpp index 7aaf0532f..fe73a61bc 100644 --- a/cpp/mrc/src/internal/remote_descriptor/manager.cpp +++ b/cpp/mrc/src/internal/remote_descriptor/manager.cpp @@ -19,15 +19,15 @@ #include "internal/codable/codable_storage.hpp" #include "internal/data_plane/client.hpp" +#include "internal/data_plane/data_plane_resources.hpp" #include "internal/data_plane/request.hpp" -#include "internal/data_plane/resources.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/remote_descriptor/decodable_storage.hpp" #include "internal/remote_descriptor/messages.hpp" #include "internal/remote_descriptor/storage.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" -#include "internal/ucx/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "internal/ucx/worker.hpp" #include "mrc/channel/buffered_channel.hpp" @@ -59,7 +59,7 @@ #include #include -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { namespace { @@ -283,4 +283,4 @@ mrc::runtime::RemoteDescriptor Manager::make_remote_descriptor( return {shared_from_this(), std::move(handle)}; } -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/remote_descriptor/manager.hpp b/cpp/mrc/src/internal/remote_descriptor/manager.hpp index 42107b097..43a1a99fe 100644 --- a/cpp/mrc/src/internal/remote_descriptor/manager.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/manager.hpp @@ -41,12 +41,12 @@ struct ICodableStorage; namespace mrc::codable::protos { class RemoteDescriptor; } // namespace mrc::codable::protos -namespace mrc::internal::resources { +namespace mrc::resources { class PartitionResources; -} // namespace mrc::internal::resources -namespace mrc::internal::runtime { +} // namespace mrc::resources +namespace mrc::runtime { class Partition; -} // namespace mrc::internal::runtime +} // namespace mrc::runtime namespace mrc::runnable { class Runner; } // namespace mrc::runnable @@ -54,7 +54,7 @@ namespace mrc::runtime { struct IRemoteDescriptorHandle; } // namespace mrc::runtime -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { struct RemoteDescriptorDecrementMessage; /** @@ -124,7 +124,7 @@ class Manager final : private Service, mutable std::mutex m_mutex; - friend internal::runtime::Partition; + friend runtime::Partition; }; -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/remote_descriptor/messages.hpp b/cpp/mrc/src/internal/remote_descriptor/messages.hpp index 1ef0324b1..02a87cc4b 100644 --- a/cpp/mrc/src/internal/remote_descriptor/messages.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/messages.hpp @@ -19,7 +19,7 @@ #include -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { struct RemoteDescriptorDecrementMessage { @@ -27,4 +27,4 @@ struct RemoteDescriptorDecrementMessage std::uint64_t tokens; }; -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.cpp b/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.cpp index bc9f905ca..6759f37cd 100644 --- a/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.cpp +++ b/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.cpp @@ -23,7 +23,7 @@ // #include "mrc/codable/api.hpp" // #include "mrc/protos/codable.pb.h" -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { // RemoteDescriptor::~RemoteDescriptor() // { @@ -62,4 +62,4 @@ namespace mrc::internal::remote_descriptor { // return std::move(rd.m_impl); // } -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.hpp b/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.hpp index ef0b20879..381b03874 100644 --- a/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.hpp @@ -30,7 +30,7 @@ // #include // #include -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { // class Manager; @@ -82,4 +82,4 @@ namespace mrc::internal::remote_descriptor { // friend Manager; // }; -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/remote_descriptor/storage.cpp b/cpp/mrc/src/internal/remote_descriptor/storage.cpp index 467abb41b..a593da476 100644 --- a/cpp/mrc/src/internal/remote_descriptor/storage.cpp +++ b/cpp/mrc/src/internal/remote_descriptor/storage.cpp @@ -23,7 +23,7 @@ #include -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { Storage::Storage(std::unique_ptr storage) : m_storage(std::move(storage)) { @@ -50,4 +50,4 @@ std::size_t Storage::decrement_tokens(std::size_t decrement_count) return m_tokens; } -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/remote_descriptor/storage.hpp b/cpp/mrc/src/internal/remote_descriptor/storage.hpp index 4299a6e2f..79fef4443 100644 --- a/cpp/mrc/src/internal/remote_descriptor/storage.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/storage.hpp @@ -28,7 +28,7 @@ class IDecodableStorage; class EncodedStorage; } // namespace mrc::codable -namespace mrc::internal::remote_descriptor { +namespace mrc::remote_descriptor { class Storage final { @@ -52,4 +52,4 @@ class Storage final std::int32_t m_tokens{INT32_MAX}; }; -} // namespace mrc::internal::remote_descriptor +} // namespace mrc::remote_descriptor diff --git a/cpp/mrc/src/internal/resources/forward.hpp b/cpp/mrc/src/internal/resources/forward.hpp index f8c1a0816..f2d47b675 100644 --- a/cpp/mrc/src/internal/resources/forward.hpp +++ b/cpp/mrc/src/internal/resources/forward.hpp @@ -17,7 +17,7 @@ #pragma once -namespace mrc::internal { +namespace mrc { namespace runtime { class Partition; @@ -30,7 +30,7 @@ class PartitionResources; } // namespace resources namespace runnable { -class Resources; +class RunnableResources; } // namespace runnable namespace memory { @@ -40,22 +40,22 @@ class DeviceResources; // control plane and data plane namespace network { -class Resources; +class NetworkResources; } // namespace network namespace ucx { -class Resources; +class UcxResources; } // namespace ucx namespace control_plane { -class Resources; +class ControlPlaneResources; namespace client { class Instance; } } // namespace control_plane namespace data_plane { -class Resources; +class DataPlaneResources; } // namespace data_plane -} // namespace mrc::internal +} // namespace mrc diff --git a/cpp/mrc/src/internal/resources/manager.cpp b/cpp/mrc/src/internal/resources/manager.cpp index 5f4d5e4dc..b47334c04 100644 --- a/cpp/mrc/src/internal/resources/manager.cpp +++ b/cpp/mrc/src/internal/resources/manager.cpp @@ -20,20 +20,20 @@ #include "internal/control_plane/client.hpp" #include "internal/control_plane/client/connections_manager.hpp" #include "internal/control_plane/client/instance.hpp" -#include "internal/control_plane/resources.hpp" -#include "internal/data_plane/resources.hpp" // IWYU pragma: keep +#include "internal/control_plane/control_plane_resources.hpp" +#include "internal/data_plane/data_plane_resources.hpp" // IWYU pragma: keep #include "internal/memory/device_resources.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/resources/partition_resources_base.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/system/engine_factory_cpu_sets.hpp" #include "internal/system/host_partition.hpp" #include "internal/system/partition.hpp" #include "internal/system/partitions.hpp" -#include "internal/system/resources.hpp" #include "internal/system/system.hpp" +#include "internal/system/threading_resources.hpp" #include "internal/ucx/registation_callback_builder.hpp" -#include "internal/ucx/resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "internal/utils/contains.hpp" #include "mrc/core/bitmap.hpp" @@ -52,26 +52,24 @@ #include #include -namespace mrc::internal::resources { +namespace mrc::resources { thread_local Manager* Manager::m_thread_resources{nullptr}; thread_local PartitionResources* Manager::m_thread_partition{nullptr}; -Manager::Manager(const system::SystemProvider& system) : Manager(std::make_unique(system)) {} - -Manager::Manager(std::unique_ptr resources) : - SystemProvider(*resources), - m_system(std::move(resources)) +Manager::Manager(const system::SystemProvider& system) : + SystemProvider(system), + m_threading(std::make_unique(system)) { - const auto& partitions = system().partitions().flattened(); - const auto& host_partitions = system().partitions().host_partitions(); - const bool network_enabled = !system().options().architect_url().empty(); + const auto& partitions = this->system().partitions().flattened(); + const auto& host_partitions = this->system().partitions().host_partitions(); + const bool network_enabled = !this->system().options().architect_url().empty(); // construct the runnable resources on each host_partition - launch control and main for (std::size_t i = 0; i < host_partitions.size(); ++i) { VLOG(1) << "building runnable/launch_control resources on host_partition: " << i; - m_runnable.emplace_back(*m_system, i); + m_runnable.emplace_back(*m_threading, i); } std::vector base_partition_resources; @@ -90,8 +88,8 @@ Manager::Manager(std::unique_ptr resources) : VLOG(1) << "building ucx resources for partition " << base.partition_id(); auto network_task_queue_cpuset = base.partition().host().engine_factory_cpu_sets().fiber_cpu_sets.at( "mrc_network"); - auto& network_fiber_queue = m_system->get_task_queue(network_task_queue_cpuset.first()); - std::optional ucx; + auto& network_fiber_queue = m_threading->get_task_queue(network_task_queue_cpuset.first()); + std::optional ucx; ucx.emplace(base, network_fiber_queue); m_ucx.push_back(std::move(ucx)); } @@ -105,7 +103,7 @@ Manager::Manager(std::unique_ptr resources) : std::map> control_instances; if (network_enabled) { - m_control_plane = std::make_shared(base_partition_resources.at(0)); + m_control_plane = std::make_shared(base_partition_resources.at(0)); control_instances = m_control_plane->client().register_ucx_addresses(m_ucx); CHECK_EQ(m_control_plane->client().connections().instance_ids().size(), m_ucx.size()); } @@ -155,10 +153,10 @@ Manager::Manager(std::unique_ptr resources) : auto instance_id = m_control_plane->client().connections().instance_ids().at(base.partition_id()); DCHECK(contains(control_instances, instance_id)); // todo(cpp20) contains auto instance = std::move(control_instances.at(instance_id)); - network::Resources network(base, - *m_ucx.at(base.partition_id()), - m_host.at(base.partition().host_partition_id()), - std::move(instance)); + network::NetworkResources network(base, + *m_ucx.at(base.partition_id()), + m_host.at(base.partition().host_partition_id()), + std::move(instance)); m_network.emplace_back(std::move(network)); } else @@ -182,9 +180,9 @@ Manager::Manager(std::unique_ptr resources) : // set thread local access to resources on all fiber task queues and any future thread created by the runtime for (auto& partition : m_partitions) { - m_system->register_thread_local_initializer(partition.partition().host().cpu_set(), [this, &partition] { + m_threading->register_thread_local_initializer(partition.partition().host().cpu_set(), [this, &partition] { m_thread_resources = this; - if (system().partitions().device_to_host_strategy() == PlacementResources::Dedicated) + if (this->system().partitions().device_to_host_strategy() == PlacementResources::Dedicated) { m_thread_partition = &partition; } @@ -267,4 +265,4 @@ Future Manager::shutdown() } }); } -} // namespace mrc::internal::resources +} // namespace mrc::resources diff --git a/cpp/mrc/src/internal/resources/manager.hpp b/cpp/mrc/src/internal/resources/manager.hpp index c03d9bcc9..a823bbe27 100644 --- a/cpp/mrc/src/internal/resources/manager.hpp +++ b/cpp/mrc/src/internal/resources/manager.hpp @@ -19,7 +19,7 @@ #include "internal/memory/host_resources.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/system/system_provider.hpp" #include "mrc/types.hpp" @@ -29,32 +29,32 @@ #include #include -namespace mrc::internal::network { -class Resources; -} // namespace mrc::internal::network -namespace mrc::internal::control_plane { -class Resources; -} // namespace mrc::internal::control_plane -namespace mrc::internal::memory { +namespace mrc::network { +class NetworkResources; +} // namespace mrc::network +namespace mrc::control_plane { +class ControlPlaneResources; +} // namespace mrc::control_plane +namespace mrc::memory { class DeviceResources; -} // namespace mrc::internal::memory -namespace mrc::internal::system { -class Resources; -} // namespace mrc::internal::system -namespace mrc::internal::ucx { -class Resources; -} // namespace mrc::internal::ucx -namespace mrc::internal::runtime { +} // namespace mrc::memory +namespace mrc::system { +class ThreadingResources; +} // namespace mrc::system +namespace mrc::ucx { +class UcxResources; +} // namespace mrc::ucx +namespace mrc::runtime { class Runtime; -} // namespace mrc::internal::runtime +} // namespace mrc::runtime -namespace mrc::internal::resources { +namespace mrc::resources { class Manager final : public system::SystemProvider { public: Manager(const system::SystemProvider& system); - Manager(std::unique_ptr resources); + // Manager(std::unique_ptr resources); ~Manager() override; static Manager& get_resources(); @@ -68,11 +68,11 @@ class Manager final : public system::SystemProvider private: Future shutdown(); - const std::unique_ptr m_system; - std::vector m_runnable; // one per host partition - std::vector> m_ucx; // one per flattened partition if network is enabled - std::shared_ptr m_control_plane; // one per instance of resources::Manager - std::vector m_host; // one per host partition + const std::unique_ptr m_threading; + std::vector m_runnable; // one per host partition + std::vector> m_ucx; // one per flattened partition if network is enabled + std::shared_ptr m_control_plane; // one per instance of resources::Manager + std::vector m_host; // one per host partition std::vector> m_device; // one per flattened partition upto device_count std::vector m_partitions; // one per flattened partition @@ -80,7 +80,7 @@ class Manager final : public system::SystemProvider // so it can be the first variable destroyed // this is the owner of the control_plane::Client::Instance // which must be destroyed before all other - std::vector> m_network; // one per flattened partition + std::vector> m_network; // one per flattened partition static thread_local PartitionResources* m_thread_partition; static thread_local Manager* m_thread_resources; @@ -88,4 +88,4 @@ class Manager final : public system::SystemProvider friend runtime::Runtime; }; -} // namespace mrc::internal::resources +} // namespace mrc::resources diff --git a/cpp/mrc/src/internal/resources/partition_resources.cpp b/cpp/mrc/src/internal/resources/partition_resources.cpp index 4dae30f92..c6bbb4b9e 100644 --- a/cpp/mrc/src/internal/resources/partition_resources.cpp +++ b/cpp/mrc/src/internal/resources/partition_resources.cpp @@ -17,13 +17,13 @@ #include "internal/resources/partition_resources.hpp" -namespace mrc::internal::resources { +namespace mrc::resources { -PartitionResources::PartitionResources(runnable::Resources& runnable_resources, +PartitionResources::PartitionResources(runnable::RunnableResources& runnable_resources, std::size_t partition_id, memory::HostResources& host, std::optional& device, - std::optional& network) : + std::optional& network) : PartitionResourceBase(runnable_resources, partition_id), m_host(host), m_device(device), @@ -40,8 +40,8 @@ std::optional& PartitionResources::device() return m_device; } -std::optional& PartitionResources::network() +std::optional& PartitionResources::network() { return m_network; } -} // namespace mrc::internal::resources +} // namespace mrc::resources diff --git a/cpp/mrc/src/internal/resources/partition_resources.hpp b/cpp/mrc/src/internal/resources/partition_resources.hpp index 9483c744e..d1e832471 100644 --- a/cpp/mrc/src/internal/resources/partition_resources.hpp +++ b/cpp/mrc/src/internal/resources/partition_resources.hpp @@ -22,18 +22,18 @@ #include #include -namespace mrc::internal::memory { +namespace mrc::memory { class DeviceResources; class HostResources; -} // namespace mrc::internal::memory -namespace mrc::internal::network { -class Resources; -} // namespace mrc::internal::network -namespace mrc::internal::runnable { -class Resources; -} // namespace mrc::internal::runnable +} // namespace mrc::memory +namespace mrc::network { +class NetworkResources; +} // namespace mrc::network +namespace mrc::runnable { +class RunnableResources; +} // namespace mrc::runnable -namespace mrc::internal::resources { +namespace mrc::resources { /** * @brief Partition Resources define the set of Resources available to a given Partition @@ -44,20 +44,20 @@ namespace mrc::internal::resources { class PartitionResources final : public PartitionResourceBase { public: - PartitionResources(runnable::Resources& runnable_resources, + PartitionResources(runnable::RunnableResources& runnable_resources, std::size_t partition_id, memory::HostResources& host, std::optional& device, - std::optional& network); + std::optional& network); memory::HostResources& host(); std::optional& device(); - std::optional& network(); + std::optional& network(); private: memory::HostResources& m_host; std::optional& m_device; - std::optional& m_network; + std::optional& m_network; }; -} // namespace mrc::internal::resources +} // namespace mrc::resources diff --git a/cpp/mrc/src/internal/resources/partition_resources_base.cpp b/cpp/mrc/src/internal/resources/partition_resources_base.cpp index 314d358d6..1983a23d6 100644 --- a/cpp/mrc/src/internal/resources/partition_resources_base.cpp +++ b/cpp/mrc/src/internal/resources/partition_resources_base.cpp @@ -17,26 +17,26 @@ #include "internal/resources/partition_resources_base.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/system/partition.hpp" #include -namespace mrc::internal::resources { +namespace mrc::resources { -PartitionResourceBase::PartitionResourceBase(runnable::Resources& runnable, std::size_t partition_id) : +PartitionResourceBase::PartitionResourceBase(runnable::RunnableResources& runnable, std::size_t partition_id) : system::PartitionProvider(runnable, partition_id), m_runnable(runnable) { CHECK_EQ(runnable.host_partition_id(), partition().host_partition_id()); } -runnable::Resources& PartitionResourceBase::runnable() +runnable::RunnableResources& PartitionResourceBase::runnable() { return m_runnable; } -const runnable::Resources& PartitionResourceBase::runnable() const +const runnable::RunnableResources& PartitionResourceBase::runnable() const { return m_runnable; } -} // namespace mrc::internal::resources +} // namespace mrc::resources diff --git a/cpp/mrc/src/internal/resources/partition_resources_base.hpp b/cpp/mrc/src/internal/resources/partition_resources_base.hpp index a6276d92c..75d774556 100644 --- a/cpp/mrc/src/internal/resources/partition_resources_base.hpp +++ b/cpp/mrc/src/internal/resources/partition_resources_base.hpp @@ -22,11 +22,11 @@ #include #include -namespace mrc::internal::runnable { -class Resources; -} // namespace mrc::internal::runnable +namespace mrc::runnable { +class RunnableResources; +} // namespace mrc::runnable -namespace mrc::internal::resources { +namespace mrc::resources { /** * @brief Provider of both a system::PartitionProvider and a runnable::Resource assigned to the particular partition @@ -37,13 +37,13 @@ namespace mrc::internal::resources { class PartitionResourceBase : public system::PartitionProvider { public: - PartitionResourceBase(runnable::Resources& runnable, std::size_t partition_id); + PartitionResourceBase(runnable::RunnableResources& runnable, std::size_t partition_id); - runnable::Resources& runnable(); - const runnable::Resources& runnable() const; + runnable::RunnableResources& runnable(); + const runnable::RunnableResources& runnable() const; private: - std::reference_wrapper m_runnable; + std::reference_wrapper m_runnable; }; -} // namespace mrc::internal::resources +} // namespace mrc::resources diff --git a/cpp/mrc/src/internal/runnable/engine.cpp b/cpp/mrc/src/internal/runnable/engine.cpp index 67ce561cc..4ebe57491 100644 --- a/cpp/mrc/src/internal/runnable/engine.cpp +++ b/cpp/mrc/src/internal/runnable/engine.cpp @@ -25,7 +25,7 @@ #include #include -namespace mrc::internal::runnable { +namespace mrc::runnable { Future Engine::launch_task(std::function task) { @@ -38,4 +38,4 @@ Future Engine::launch_task(std::function task) return do_launch_task(std::move(task)); } -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/engine.hpp b/cpp/mrc/src/internal/runnable/engine.hpp index 1be173c54..afed43e3c 100644 --- a/cpp/mrc/src/internal/runnable/engine.hpp +++ b/cpp/mrc/src/internal/runnable/engine.hpp @@ -27,11 +27,11 @@ namespace mrc::runnable { enum class EngineType; } // namespace mrc::runnable -namespace mrc::internal::runnable { +namespace mrc::runnable { using ::mrc::runnable::EngineType; -class Engine : public ::mrc::runnable::Engine +class Engine : public IEngine { Future launch_task(std::function task) final; @@ -41,4 +41,4 @@ class Engine : public ::mrc::runnable::Engine std::mutex m_mutex; }; -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/engine_factory.cpp b/cpp/mrc/src/internal/runnable/engine_factory.cpp index df0bf3fb9..db3857bfa 100644 --- a/cpp/mrc/src/internal/runnable/engine_factory.cpp +++ b/cpp/mrc/src/internal/runnable/engine_factory.cpp @@ -17,11 +17,10 @@ #include "internal/runnable/engine_factory.hpp" -#include "internal/runnable/engine.hpp" #include "internal/runnable/fiber_engines.hpp" #include "internal/runnable/thread_engines.hpp" #include "internal/system/fiber_pool.hpp" -#include "internal/system/resources.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/constants.hpp" #include "mrc/core/bitmap.hpp" @@ -39,7 +38,8 @@ #include #include -namespace mrc::internal::runnable { +namespace mrc::runnable { +class IEngines; class FiberEngineFactory : public ::mrc::runnable::EngineFactory { @@ -52,7 +52,7 @@ class FiberEngineFactory : public ::mrc::runnable::EngineFactory * * @return std::shared_ptr */ - std::shared_ptr<::mrc::runnable::Engines> build_engines(const LaunchOptions& launch_options) final + std::shared_ptr<::mrc::runnable::IEngines> build_engines(const LaunchOptions& launch_options) final { std::lock_guard lock(m_mutex); return std::make_shared(launch_options, @@ -76,7 +76,7 @@ class FiberEngineFactory : public ::mrc::runnable::EngineFactory class ReusableFiberEngineFactory final : public FiberEngineFactory { public: - ReusableFiberEngineFactory(const system::Resources& system_resources, const CpuSet& cpu_set) : + ReusableFiberEngineFactory(const system::ThreadingResources& system_resources, const CpuSet& cpu_set) : m_pool(system_resources.make_fiber_pool(cpu_set)) {} ~ReusableFiberEngineFactory() final = default; @@ -115,7 +115,7 @@ class ReusableFiberEngineFactory final : public FiberEngineFactory class SingleUseFiberEngineFactory final : public FiberEngineFactory { public: - SingleUseFiberEngineFactory(const system::Resources& system_resources, const CpuSet& cpu_set) : + SingleUseFiberEngineFactory(const system::ThreadingResources& system_resources, const CpuSet& cpu_set) : m_pool(system_resources.make_fiber_pool(cpu_set)) {} ~SingleUseFiberEngineFactory() final = default; @@ -147,14 +147,14 @@ class SingleUseFiberEngineFactory final : public FiberEngineFactory class ThreadEngineFactory : public ::mrc::runnable::EngineFactory { public: - ThreadEngineFactory(const system::Resources& system_resources, CpuSet cpu_set) : + ThreadEngineFactory(const system::ThreadingResources& system_resources, CpuSet cpu_set) : m_system_resources(system_resources), m_cpu_set(std::move(cpu_set)) { CHECK(!m_cpu_set.empty()); } - std::shared_ptr<::mrc::runnable::Engines> build_engines(const LaunchOptions& launch_options) final + std::shared_ptr<::mrc::runnable::IEngines> build_engines(const LaunchOptions& launch_options) final { std::lock_guard lock(m_mutex); auto cpu_set = get_next_n_cpus(launch_options.pe_count); @@ -176,7 +176,7 @@ class ThreadEngineFactory : public ::mrc::runnable::EngineFactory virtual CpuSet get_next_n_cpus(std::size_t count) = 0; CpuSet m_cpu_set; - const system::Resources& m_system_resources; + const system::ThreadingResources& m_system_resources; std::mutex m_mutex; }; @@ -186,7 +186,7 @@ class ThreadEngineFactory : public ::mrc::runnable::EngineFactory class ReusableThreadEngineFactory final : public ThreadEngineFactory { public: - ReusableThreadEngineFactory(const system::Resources& system_resources, const CpuSet& cpu_set) : + ReusableThreadEngineFactory(const system::ThreadingResources& system_resources, const CpuSet& cpu_set) : ThreadEngineFactory(system_resources, cpu_set) {} @@ -213,7 +213,7 @@ class ReusableThreadEngineFactory final : public ThreadEngineFactory class SingleUseThreadEngineFactory final : public ThreadEngineFactory { public: - SingleUseThreadEngineFactory(const system::Resources& system_resources, const CpuSet& cpu_set) : + SingleUseThreadEngineFactory(const system::ThreadingResources& system_resources, const CpuSet& cpu_set) : ThreadEngineFactory(system_resources, cpu_set) {} @@ -238,7 +238,7 @@ class SingleUseThreadEngineFactory final : public ThreadEngineFactory int m_prev_cpu_idx = -1; }; -std::shared_ptr<::mrc::runnable::EngineFactory> make_engine_factory(const system::Resources& system_resources, +std::shared_ptr<::mrc::runnable::EngineFactory> make_engine_factory(const system::ThreadingResources& system_resources, EngineType engine_type, const CpuSet& cpu_set, bool reusable) @@ -264,4 +264,4 @@ std::shared_ptr<::mrc::runnable::EngineFactory> make_engine_factory(const system LOG(FATAL) << "unsupported engine type"; } -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/engine_factory.hpp b/cpp/mrc/src/internal/runnable/engine_factory.hpp index 12a62a6b3..e8df4b4bd 100644 --- a/cpp/mrc/src/internal/runnable/engine_factory.hpp +++ b/cpp/mrc/src/internal/runnable/engine_factory.hpp @@ -17,8 +17,7 @@ #pragma once -#include "internal/runnable/engines.hpp" -#include "internal/system/resources.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/core/bitmap.hpp" @@ -29,11 +28,11 @@ enum class EngineType; struct EngineFactory; } // namespace mrc::runnable -namespace mrc::internal::runnable { +namespace mrc::runnable { -std::shared_ptr<::mrc::runnable::EngineFactory> make_engine_factory(const system::Resources& system, +std::shared_ptr<::mrc::runnable::EngineFactory> make_engine_factory(const system::ThreadingResources& system, EngineType engine_type, const CpuSet& cpu_set, bool reusable); -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/engines.cpp b/cpp/mrc/src/internal/runnable/engines.cpp index f78fcef33..aadd29f1d 100644 --- a/cpp/mrc/src/internal/runnable/engines.cpp +++ b/cpp/mrc/src/internal/runnable/engines.cpp @@ -21,13 +21,13 @@ #include -namespace mrc::internal::runnable { +namespace mrc::runnable { Engines::Engines(LaunchOptions launch_options) : m_launch_options(std::move(launch_options)) {} Engines::~Engines() = default; -const std::vector>& Engines::launchers() const +const std::vector>& Engines::launchers() const { return m_launchers; } @@ -42,7 +42,7 @@ const LaunchOptions& Engines::launch_options() const return m_launch_options; } -void Engines::add_launcher(std::shared_ptr<::mrc::runnable::Engine> launcher) +void Engines::add_launcher(std::shared_ptr<::mrc::runnable::IEngine> launcher) { m_launchers.push_back(std::move(launcher)); } @@ -52,4 +52,4 @@ void Engines::clear_launchers() m_launchers.clear(); } -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/engines.hpp b/cpp/mrc/src/internal/runnable/engines.hpp index 99a6ac7ef..4c4100a79 100644 --- a/cpp/mrc/src/internal/runnable/engines.hpp +++ b/cpp/mrc/src/internal/runnable/engines.hpp @@ -28,28 +28,28 @@ namespace mrc::runnable { enum class EngineType; } // namespace mrc::runnable -namespace mrc::internal::runnable { +namespace mrc::runnable { using ::mrc::runnable::EngineType; using ::mrc::runnable::LaunchOptions; -class Engines : public ::mrc::runnable::Engines +class Engines : public IEngines { public: Engines(LaunchOptions launch_options); ~Engines() override; - const std::vector>& launchers() const final; + const std::vector>& launchers() const final; const LaunchOptions& launch_options() const final; std::size_t size() const final; protected: - void add_launcher(std::shared_ptr<::mrc::runnable::Engine> launcher); + void add_launcher(std::shared_ptr launcher); void clear_launchers(); private: LaunchOptions m_launch_options; - std::vector> m_launchers; + std::vector> m_launchers; }; -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/fiber_engine.cpp b/cpp/mrc/src/internal/runnable/fiber_engine.cpp index 1443c7e6a..10dc1eb51 100644 --- a/cpp/mrc/src/internal/runnable/fiber_engine.cpp +++ b/cpp/mrc/src/internal/runnable/fiber_engine.cpp @@ -25,7 +25,7 @@ #include -namespace mrc::internal::runnable { +namespace mrc::runnable { FiberEngine::FiberEngine(core::FiberTaskQueue& task_queue, int priority) : m_task_queue(task_queue), m_meta{priority} {} @@ -43,4 +43,4 @@ runnable::EngineType FiberEngine::engine_type() const { return EngineType::Fiber; } -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/fiber_engine.hpp b/cpp/mrc/src/internal/runnable/fiber_engine.hpp index 5b237f187..4d6986398 100644 --- a/cpp/mrc/src/internal/runnable/fiber_engine.hpp +++ b/cpp/mrc/src/internal/runnable/fiber_engine.hpp @@ -32,7 +32,7 @@ namespace mrc::runnable { enum class EngineType; } // namespace mrc::runnable -namespace mrc::internal::runnable { +namespace mrc::runnable { class FiberEngine final : public Engine { @@ -51,4 +51,4 @@ class FiberEngine final : public Engine FiberMetaData m_meta; }; -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/fiber_engines.cpp b/cpp/mrc/src/internal/runnable/fiber_engines.cpp index 2a944d528..87dfa5556 100644 --- a/cpp/mrc/src/internal/runnable/fiber_engines.cpp +++ b/cpp/mrc/src/internal/runnable/fiber_engines.cpp @@ -17,7 +17,6 @@ #include "internal/runnable/fiber_engines.hpp" -#include "internal/runnable/engine.hpp" #include "internal/runnable/fiber_engine.hpp" #include "internal/system/fiber_pool.hpp" @@ -31,7 +30,7 @@ #include #include -namespace mrc::internal::runnable { +namespace mrc::runnable { FiberEngines::FiberEngines(system::FiberPool& pool, int priority) : FiberEngines(::mrc::runnable::LaunchOptions("custom_options", pool.thread_count()), pool, priority) @@ -88,4 +87,4 @@ runnable::EngineType FiberEngines::engine_type() const { return EngineType::Fiber; } -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/fiber_engines.hpp b/cpp/mrc/src/internal/runnable/fiber_engines.hpp index e7f8c1aea..72590324a 100644 --- a/cpp/mrc/src/internal/runnable/fiber_engines.hpp +++ b/cpp/mrc/src/internal/runnable/fiber_engines.hpp @@ -28,15 +28,15 @@ namespace mrc::core { class FiberTaskQueue; } // namespace mrc::core -namespace mrc::internal::system { +namespace mrc::system { class FiberPool; -} // namespace mrc::internal::system +} // namespace mrc::system namespace mrc::runnable { enum class EngineType; struct LaunchOptions; } // namespace mrc::runnable -namespace mrc::internal::runnable { +namespace mrc::runnable { class FiberEngines final : public Engines { @@ -64,4 +64,4 @@ class FiberEngines final : public Engines FiberMetaData m_meta; }; -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/resources.cpp b/cpp/mrc/src/internal/runnable/runnable_resources.cpp similarity index 85% rename from cpp/mrc/src/internal/runnable/resources.cpp rename to cpp/mrc/src/internal/runnable/runnable_resources.cpp index 9ee8d3bb9..4fa98f1ce 100644 --- a/cpp/mrc/src/internal/runnable/resources.cpp +++ b/cpp/mrc/src/internal/runnable/runnable_resources.cpp @@ -15,10 +15,9 @@ * limitations under the License. */ -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/runnable/engine_factory.hpp" -#include "internal/runnable/engines.hpp" #include "internal/system/engine_factory_cpu_sets.hpp" #include "internal/system/fiber_task_queue.hpp" #include "internal/system/host_partition.hpp" @@ -36,9 +35,10 @@ #include #include -namespace mrc::internal::runnable { +namespace mrc::runnable { -Resources::Resources(const system::Resources& system_resources, std::size_t _host_partition_id) : +RunnableResources::RunnableResources(const system::ThreadingResources& system_resources, + std::size_t _host_partition_id) : HostPartitionProvider(system_resources, _host_partition_id), m_main(system_resources.get_task_queue(host_partition().engine_factory_cpu_sets().main_cpu_id())) { @@ -78,23 +78,23 @@ Resources::Resources(const system::Resources& system_resources, std::size_t _hos .get(); } -Resources::Resources(Resources&& other) = default; +RunnableResources::RunnableResources(RunnableResources&& other) = default; -Resources::~Resources() = default; +RunnableResources::~RunnableResources() = default; -core::FiberTaskQueue& Resources::main() +core::FiberTaskQueue& RunnableResources::main() { return m_main; } -mrc::runnable::LaunchControl& Resources::launch_control() +mrc::runnable::LaunchControl& RunnableResources::launch_control() { CHECK(m_launch_control); return *m_launch_control; } -const mrc::core::FiberTaskQueue& Resources::main() const +const mrc::core::FiberTaskQueue& RunnableResources::main() const { return m_main; } -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/resources.hpp b/cpp/mrc/src/internal/runnable/runnable_resources.hpp similarity index 70% rename from cpp/mrc/src/internal/runnable/resources.hpp rename to cpp/mrc/src/internal/runnable/runnable_resources.hpp index 35bf88879..fbce3895e 100644 --- a/cpp/mrc/src/internal/runnable/resources.hpp +++ b/cpp/mrc/src/internal/runnable/runnable_resources.hpp @@ -18,27 +18,27 @@ #pragma once #include "internal/system/host_partition_provider.hpp" -#include "internal/system/resources.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/core/task_queue.hpp" -#include "mrc/pipeline/resources.hpp" #include "mrc/runnable/launch_control.hpp" +#include "mrc/runnable/runnable_resources.hpp" #include #include -namespace mrc::internal::system { +namespace mrc::system { class FiberTaskQueue; -} // namespace mrc::internal::system +} // namespace mrc::system -namespace mrc::internal::runnable { +namespace mrc::runnable { -class Resources final : public system::HostPartitionProvider, public mrc::pipeline::Resources +class RunnableResources final : public system::HostPartitionProvider, public IRunnableResources { public: - Resources(const system::Resources& system_resources, std::size_t _host_partition_id); - Resources(Resources&& other); - ~Resources() override; + RunnableResources(const system::ThreadingResources& system_resources, std::size_t _host_partition_id); + RunnableResources(RunnableResources&& other); + ~RunnableResources() override; mrc::core::FiberTaskQueue& main() final; const mrc::core::FiberTaskQueue& main() const; @@ -49,4 +49,4 @@ class Resources final : public system::HostPartitionProvider, public mrc::pipeli std::unique_ptr m_launch_control; }; -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/thread_engine.cpp b/cpp/mrc/src/internal/runnable/thread_engine.cpp index 6990a00f1..fb18c3b60 100644 --- a/cpp/mrc/src/internal/runnable/thread_engine.cpp +++ b/cpp/mrc/src/internal/runnable/thread_engine.cpp @@ -17,8 +17,8 @@ #include "internal/runnable/thread_engine.hpp" -#include "internal/system/resources.hpp" #include "internal/system/thread.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/core/bitmap.hpp" #include "mrc/runnable/types.hpp" @@ -30,9 +30,9 @@ #include #include -namespace mrc::internal::runnable { +namespace mrc::runnable { -ThreadEngine::ThreadEngine(CpuSet cpu_set, const system::Resources& system) : +ThreadEngine::ThreadEngine(CpuSet cpu_set, const system::ThreadingResources& system) : m_cpu_set(std::move(cpu_set)), m_system(system) {} @@ -61,4 +61,4 @@ runnable::EngineType ThreadEngine::engine_type() const return EngineType::Thread; } -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/thread_engine.hpp b/cpp/mrc/src/internal/runnable/thread_engine.hpp index 6ae40876f..b94ca677c 100644 --- a/cpp/mrc/src/internal/runnable/thread_engine.hpp +++ b/cpp/mrc/src/internal/runnable/thread_engine.hpp @@ -18,7 +18,7 @@ #pragma once #include "internal/runnable/engine.hpp" -#include "internal/system/resources.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/core/bitmap.hpp" #include "mrc/types.hpp" @@ -28,19 +28,19 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { class Thread; -} // namespace mrc::internal::system +} // namespace mrc::system namespace mrc::runnable { enum class EngineType; } // namespace mrc::runnable -namespace mrc::internal::runnable { +namespace mrc::runnable { class ThreadEngine final : public Engine { public: - explicit ThreadEngine(CpuSet cpu_set, const system::Resources& system); + explicit ThreadEngine(CpuSet cpu_set, const system::ThreadingResources& system); ~ThreadEngine() final; EngineType engine_type() const final; @@ -52,8 +52,8 @@ class ThreadEngine final : public Engine Future do_launch_task(std::function task) final; CpuSet m_cpu_set; - const system::Resources& m_system; + const system::ThreadingResources& m_system; std::unique_ptr m_thread; }; -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/thread_engines.cpp b/cpp/mrc/src/internal/runnable/thread_engines.cpp index b2f022175..23f9c430a 100644 --- a/cpp/mrc/src/internal/runnable/thread_engines.cpp +++ b/cpp/mrc/src/internal/runnable/thread_engines.cpp @@ -17,7 +17,6 @@ #include "internal/runnable/thread_engines.hpp" -#include "internal/runnable/engine.hpp" #include "internal/runnable/thread_engine.hpp" #include "mrc/core/bitmap.hpp" @@ -32,7 +31,7 @@ #include #include -namespace mrc::internal::runnable { +namespace mrc::runnable { void ThreadEngines::initialize_launchers() { @@ -50,11 +49,11 @@ void ThreadEngines::initialize_launchers() }); } -ThreadEngines::ThreadEngines(CpuSet cpu_set, const system::Resources& system) : +ThreadEngines::ThreadEngines(CpuSet cpu_set, const system::ThreadingResources& system) : ThreadEngines(LaunchOptions("custom_options", cpu_set.weight()), cpu_set, std::move(system)) {} -ThreadEngines::ThreadEngines(LaunchOptions launch_options, CpuSet cpu_set, const system::Resources& system) : +ThreadEngines::ThreadEngines(LaunchOptions launch_options, CpuSet cpu_set, const system::ThreadingResources& system) : Engines(std::move(launch_options)), m_cpu_set(std::move(cpu_set)), m_system(std::move(system)) @@ -66,4 +65,4 @@ runnable::EngineType ThreadEngines::engine_type() const { return EngineType::Thread; } -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runnable/thread_engines.hpp b/cpp/mrc/src/internal/runnable/thread_engines.hpp index 1878a5731..a89149756 100644 --- a/cpp/mrc/src/internal/runnable/thread_engines.hpp +++ b/cpp/mrc/src/internal/runnable/thread_engines.hpp @@ -18,7 +18,7 @@ #pragma once #include "internal/runnable/engines.hpp" -#include "internal/system/resources.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/core/bitmap.hpp" @@ -27,13 +27,13 @@ enum class EngineType; struct LaunchOptions; } // namespace mrc::runnable -namespace mrc::internal::runnable { +namespace mrc::runnable { class ThreadEngines final : public Engines { public: - ThreadEngines(CpuSet cpu_set, const system::Resources& system); - ThreadEngines(LaunchOptions launch_options, CpuSet cpu_set, const system::Resources& system); + ThreadEngines(CpuSet cpu_set, const system::ThreadingResources& system); + ThreadEngines(LaunchOptions launch_options, CpuSet cpu_set, const system::ThreadingResources& system); ~ThreadEngines() final = default; EngineType engine_type() const final; @@ -42,7 +42,7 @@ class ThreadEngines final : public Engines void initialize_launchers(); CpuSet m_cpu_set; - const system::Resources& m_system; + const system::ThreadingResources& m_system; }; -} // namespace mrc::internal::runnable +} // namespace mrc::runnable diff --git a/cpp/mrc/src/internal/runtime/partition.cpp b/cpp/mrc/src/internal/runtime/partition.cpp index b233eba31..7289936b8 100644 --- a/cpp/mrc/src/internal/runtime/partition.cpp +++ b/cpp/mrc/src/internal/runtime/partition.cpp @@ -18,7 +18,7 @@ #include "internal/runtime/partition.hpp" #include "internal/codable/codable_storage.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/pubsub/publisher_round_robin.hpp" #include "internal/pubsub/subscriber_service.hpp" #include "internal/remote_descriptor/manager.hpp" @@ -31,7 +31,7 @@ #include #include -namespace mrc::internal::runtime { +namespace mrc::runtime { Partition::Partition(resources::PartitionResources& resources) : m_resources(resources) { @@ -84,4 +84,4 @@ std::unique_ptr Partition::make_codable_storage() return std::make_unique(m_resources); } -} // namespace mrc::internal::runtime +} // namespace mrc::runtime diff --git a/cpp/mrc/src/internal/runtime/partition.hpp b/cpp/mrc/src/internal/runtime/partition.hpp index 613654369..4bda20727 100644 --- a/cpp/mrc/src/internal/runtime/partition.hpp +++ b/cpp/mrc/src/internal/runtime/partition.hpp @@ -28,16 +28,16 @@ namespace mrc::codable { struct ICodableStorage; } // namespace mrc::codable -namespace mrc::internal::resources { +namespace mrc::resources { class PartitionResources; -} // namespace mrc::internal::resources +} // namespace mrc::resources namespace mrc::pubsub { class IPublisherService; class ISubscriberService; enum class PublisherPolicy; } // namespace mrc::pubsub -namespace mrc::internal::runtime { +namespace mrc::runtime { class Partition final : public mrc::runtime::IPartition { @@ -66,4 +66,4 @@ class Partition final : public mrc::runtime::IPartition std::shared_ptr m_remote_descriptor_manager; }; -} // namespace mrc::internal::runtime +} // namespace mrc::runtime diff --git a/cpp/mrc/src/internal/runtime/runtime.cpp b/cpp/mrc/src/internal/runtime/runtime.cpp index cb16f0c8c..7b2ea0576 100644 --- a/cpp/mrc/src/internal/runtime/runtime.cpp +++ b/cpp/mrc/src/internal/runtime/runtime.cpp @@ -26,7 +26,7 @@ #include -namespace mrc::internal::runtime { +namespace mrc::runtime { Runtime::Runtime(std::unique_ptr resources) : m_resources(std::move(resources)) { @@ -67,4 +67,4 @@ Partition& Runtime::partition(std::size_t partition_id) return *m_partitions.at(partition_id); } -} // namespace mrc::internal::runtime +} // namespace mrc::runtime diff --git a/cpp/mrc/src/internal/runtime/runtime.hpp b/cpp/mrc/src/internal/runtime/runtime.hpp index e6b759b6c..3edbb69e0 100644 --- a/cpp/mrc/src/internal/runtime/runtime.hpp +++ b/cpp/mrc/src/internal/runtime/runtime.hpp @@ -25,11 +25,11 @@ #include #include -namespace mrc::internal::resources { +namespace mrc::resources { class Manager; -} // namespace mrc::internal::resources +} // namespace mrc::resources -namespace mrc::internal::runtime { +namespace mrc::runtime { /** * @brief Implements the public Runtime interface and owns any high-level runtime resources, e.g. the remote descriptor @@ -59,4 +59,4 @@ class Runtime final : public mrc::runtime::IRuntime std::vector> m_partitions; }; -} // namespace mrc::internal::runtime +} // namespace mrc::runtime diff --git a/cpp/mrc/src/internal/segment/builder.cpp b/cpp/mrc/src/internal/segment/builder.cpp deleted file mode 100644 index 810fbe29a..000000000 --- a/cpp/mrc/src/internal/segment/builder.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2022, 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. - */ - -#include "internal/segment/builder.hpp" - -#include "internal/pipeline/resources.hpp" -#include "internal/segment/definition.hpp" - -#include "mrc/core/addresses.hpp" -#include "mrc/engine/segment/ibuilder.hpp" -#include "mrc/exceptions/runtime_error.hpp" -#include "mrc/metrics/counter.hpp" -#include "mrc/metrics/registry.hpp" -#include "mrc/segment/egress_port.hpp" // IWYU pragma: keep -#include "mrc/segment/ingress_port.hpp" // IWYU pragma: keep -#include "mrc/segment/initializers.hpp" -#include "mrc/types.hpp" - -#include - -#include -#include -#include - -namespace mrc::internal::segment { - -Builder::Builder(std::shared_ptr segdef, - SegmentRank rank, - pipeline::Resources& resources, - std::size_t default_partition_id) : - m_definition(std::move(segdef)), - m_resources(resources), - m_default_partition_id(default_partition_id) -{ - auto address = segment_address_encode(definition().id(), rank); - - // construct ingress ports - for (const auto& [name, initializer] : definition().ingress_initializers()) - { - DVLOG(10) << "constructing ingress_port: " << name; - m_ingress_ports[name] = initializer(address); - m_objects[name] = m_ingress_ports[name]; - } - - // construct egress ports - for (const auto& [name, initializer] : definition().egress_initializers()) - { - DVLOG(10) << "constructing egress_port: " << name; - m_egress_ports[name] = initializer(address); - m_objects[name] = m_egress_ports[name]; - } - - IBuilder builder(this); - - // Call the segment initializer - try - { - definition().initializer_fn()(builder); - } catch (const std::exception& e) - { - LOG(ERROR) << "Exception during segment initializer. Segment name: " << m_definition->name() - << ", Segment Rank: " << rank << ". Exception message:\n" - << e.what(); - - // Rethrow after logging - std::rethrow_exception(std::current_exception()); - } -} - -const std::string& Builder::name() const -{ - CHECK(m_definition); - return m_definition->name(); -} - -bool Builder::has_object(const std::string& name) const -{ - auto search = m_objects.find(name); - return bool(search != m_objects.end()); -} - -mrc::segment::ObjectProperties& Builder::find_object(const std::string& name) -{ - auto search = m_objects.find(name); - if (search == m_objects.end()) - { - LOG(ERROR) << "Unable to find segment object with name: " << name; - throw exceptions::MrcRuntimeError("unable to find segment object with name " + name); - } - return *(search->second); -} - -std::shared_ptr<::mrc::segment::IngressPortBase> Builder::get_ingress_base(const std::string& name) -{ - auto search = m_ingress_ports.find(name); - if (search != m_ingress_ports.end()) - { - return search->second; - } - return nullptr; -} - -std::shared_ptr<::mrc::segment::EgressPortBase> Builder::get_egress_base(const std::string& name) -{ - auto search = m_egress_ports.find(name); - if (search != m_egress_ports.end()) - { - return search->second; - } - return nullptr; -} - -void Builder::add_object(const std::string& name, std::shared_ptr<::mrc::segment::ObjectProperties> object) -{ - if (has_object(name)) - { - LOG(ERROR) << "A Object named " << name << " is already registered"; - throw exceptions::MrcRuntimeError("duplicate name detected - name owned by a node"); - } - m_objects[name] = std::move(object); -} - -void Builder::add_module(const std::string& name, std::shared_ptr smodule) -{ - if (has_object(name)) - { - LOG(ERROR) << "A Module named " << name << " is already registered"; - throw exceptions::MrcRuntimeError("duplicate name detected - name owned by a module"); - } - m_modules[name] = std::move(smodule); -} - -void Builder::add_runnable(const std::string& name, std::shared_ptr runnable) -{ - if (has_object(name)) - { - LOG(ERROR) << "A Object named " << name << " is already registered"; - throw exceptions::MrcRuntimeError("duplicate name detected - name owned by a node"); - } - m_nodes[name] = std::move(runnable); -} - -const std::map>& Builder::egress_ports() const -{ - return m_egress_ports; -} - -const std::map>& Builder::ingress_ports() const -{ - return m_ingress_ports; -} - -const Definition& Builder::definition() const -{ - CHECK(m_definition); - return *m_definition; -} -const std::map>& Builder::nodes() const -{ - return m_nodes; -} -std::function Builder::make_throughput_counter(const std::string& name) -{ - auto counter = m_resources.metrics_registry().make_throughput_counter(name); - return [counter](std::int64_t ticks) mutable { - counter.increment(ticks); - }; -} -} // namespace mrc::internal::segment diff --git a/cpp/mrc/src/internal/segment/builder.hpp b/cpp/mrc/src/internal/segment/builder.hpp deleted file mode 100644 index dbcb42e26..000000000 --- a/cpp/mrc/src/internal/segment/builder.hpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2022, 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. - */ - -#pragma once - -#include "mrc/types.hpp" - -#include -#include -#include -#include -#include -#include - -namespace mrc::internal::pipeline { -class Resources; -} // namespace mrc::internal::pipeline - -namespace mrc::modules { -class SegmentModule; -} - -namespace mrc::runnable { -struct Launchable; -} // namespace mrc::runnable - -namespace mrc::segment { -class EgressPortBase; -struct IngressPortBase; -struct ObjectProperties; -} // namespace mrc::segment - -namespace mrc::internal::segment { -class Definition; -class IBuilder; - -class Builder final -{ - public: - Builder(std::shared_ptr segdef, - SegmentRank rank, - pipeline::Resources& resources, - std::size_t default_partition_id); - - const Definition& definition() const; - - const std::map>& nodes() const; - const std::map>& egress_ports() const; - const std::map>& ingress_ports() const; - - private: - const std::string& name() const; - - bool has_object(const std::string& name) const; - bool has_module(const std::string& name) const; - ::mrc::segment::ObjectProperties& find_object(const std::string& name); - - void add_object(const std::string& name, std::shared_ptr<::mrc::segment::ObjectProperties> object); - void add_module(const std::string& name, std::shared_ptr module); - void add_runnable(const std::string& name, std::shared_ptr runnable); - - std::shared_ptr<::mrc::segment::IngressPortBase> get_ingress_base(const std::string& name); - std::shared_ptr<::mrc::segment::EgressPortBase> get_egress_base(const std::string& name); - - // temporary metrics interface - std::function make_throughput_counter(const std::string& name); - - // definition - std::shared_ptr m_definition; - - // all objects - ports, runnables, etc. - std::map> m_objects; - - // only modules - std::map> m_modules; - - // only runnables - std::map> m_nodes; - - // ingress/egress - these are also nodes/objects - std::map> m_ingress_ports; - std::map> m_egress_ports; - - pipeline::Resources& m_resources; - const std::size_t m_default_partition_id; - - friend IBuilder; -}; - -} // namespace mrc::internal::segment diff --git a/cpp/mrc/src/internal/segment/builder_definition.cpp b/cpp/mrc/src/internal/segment/builder_definition.cpp new file mode 100644 index 000000000..e631c3f1e --- /dev/null +++ b/cpp/mrc/src/internal/segment/builder_definition.cpp @@ -0,0 +1,421 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2022, 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. + */ + +#include "internal/segment/builder_definition.hpp" + +#include "internal/pipeline/pipeline_resources.hpp" +#include "internal/segment/segment_definition.hpp" + +#include "mrc/core/addresses.hpp" +#include "mrc/exceptions/runtime_error.hpp" +#include "mrc/metrics/counter.hpp" +#include "mrc/metrics/registry.hpp" +#include "mrc/modules/module_registry.hpp" +#include "mrc/modules/properties/persistent.hpp" // IWYU pragma: keep +#include "mrc/modules/segment_modules.hpp" +#include "mrc/node/port_registry.hpp" +#include "mrc/segment/egress_port.hpp" // IWYU pragma: keep +#include "mrc/segment/ingress_port.hpp" // IWYU pragma: keep +#include "mrc/segment/initializers.hpp" +#include "mrc/segment/object.hpp" +#include "mrc/types.hpp" + +#include + +#include +#include +#include +#include +#include +#include + +namespace { + +std::string accum_merge(std::string lhs, std::string rhs) +{ + if (lhs.empty()) + { + return std::move(rhs); + } + + return std::move(lhs) + "/" + std::move(rhs); +} + +/** + * @brief Checks for invalid characters in a name. Throws an exception if invalid characters are found. + * + * @param name The name to check + */ +void validate_name(const std::string& name) +{ + auto found_bad_characters = name.find_first_of("/"); + + if (found_bad_characters != std::string::npos) + { + throw mrc::exceptions::MrcRuntimeError("Invalid name `" + name + + "'. Cannot contain any of these characters: '/'"); + } +} + +} // namespace + +namespace mrc::segment { + +BuilderDefinition::BuilderDefinition(std::shared_ptr definition, + SegmentRank rank, + pipeline::PipelineResources& resources, + std::size_t default_partition_id) : + m_definition(std::move(definition)), + m_rank(rank), + m_resources(resources), + m_default_partition_id(default_partition_id) +{} + +std::shared_ptr BuilderDefinition::unwrap(std::shared_ptr object) +{ + // Convert to the full implementation + auto full_object = std::dynamic_pointer_cast(object); + + CHECK(full_object) << "Invalid cast for BuilderDefinition. Please report to the developers"; + + return full_object; +} + +const std::string& BuilderDefinition::name() const +{ + return m_definition->name(); +} + +std::tuple BuilderDefinition::normalize_name(const std::string& name, + bool ignore_namespace) const +{ + // Prefix all nodes with `//` + auto global_prefix = "/" + this->name() + "/"; + + // Check and see if the name starts with "/" which means its global + bool is_global = name.starts_with(global_prefix); + + if (is_global) + { + // Local is everything after the global prefix + auto local_name = name.substr(global_prefix.length()); + + return std::make_tuple(name, local_name); + } + + // Otherwise build up the local name from any module prefix + auto local_name = (ignore_namespace || m_namespace_prefix.empty()) ? name : m_namespace_prefix + "/" + name; + + auto global_name = global_prefix + local_name; + + return std::make_tuple(global_name, local_name); +} + +std::shared_ptr BuilderDefinition::get_ingress(std::string name, std::type_index type_index) +{ + auto base = this->get_ingress_base(name); + if (!base) + { + throw exceptions::MrcRuntimeError("Egress port name not found: " + name); + } + + auto port_util = node::PortRegistry::find_port_util(type_index); + auto port = port_util->try_cast_ingress_base_to_object(base); + if (port == nullptr) + { + throw exceptions::MrcRuntimeError("Egress port type mismatch: " + name); + } + + return port; +} + +std::shared_ptr BuilderDefinition::get_egress(std::string name, std::type_index type_index) +{ + auto base = this->get_egress_base(name); + if (!base) + { + throw exceptions::MrcRuntimeError("Egress port name not found: " + name); + } + + auto port_util = node::PortRegistry::find_port_util(type_index); + + auto port = port_util->try_cast_egress_base_to_object(base); + if (port == nullptr) + { + throw exceptions::MrcRuntimeError("Egress port type mismatch: " + name); + } + + return port; +} + +void BuilderDefinition::init_module(std::shared_ptr smodule) +{ + this->ns_push(smodule); + VLOG(2) << "Initializing module: " << m_namespace_prefix; + smodule->m_module_instance_registered_namespace = m_namespace_prefix; + smodule->initialize(*this); + + // TODO(Devin): Maybe a better way to do this with compile time type ledger. + if (auto persist = std::dynamic_pointer_cast(smodule)) + { + VLOG(2) << "Registering persistent module -> '" << m_namespace_prefix << "'"; + + // Just save to a vector to keep it alive + m_modules.push_back(persist); + } + this->ns_pop(); +} + +void BuilderDefinition::register_module_input(std::string input_name, std::shared_ptr object) +{ + validate_name(input_name); + + if (m_module_stack.empty()) + { + std::stringstream sstream; + + sstream << "Failed to register module input '" << input_name << "' -> no module context exists"; + VLOG(2) << sstream.str(); + + throw std::invalid_argument(sstream.str()); + } + + auto current_module = m_module_stack.back(); + current_module->register_input_port(std::move(input_name), object); +} + +[[maybe_unused]] nlohmann::json BuilderDefinition::get_current_module_config() +{ + if (m_module_stack.empty()) + { + std::stringstream sstream; + + sstream << "Failed to acquire module configuration -> no module context exists"; + VLOG(2) << sstream.str(); + + throw std::invalid_argument(sstream.str()); + } + + auto current_module = m_module_stack.back(); + + return current_module->config(); +} + +[[maybe_unused]] void BuilderDefinition::register_module_output(std::string output_name, + std::shared_ptr object) +{ + validate_name(output_name); + + if (m_module_stack.empty()) + { + std::stringstream sstream; + + sstream << "Failed to register module output'" << output_name << "' -> no module context exists"; + VLOG(2) << sstream.str(); + + throw std::invalid_argument(sstream.str()); + } + + auto current_module = m_module_stack.back(); + + current_module->register_output_port(std::move(output_name), object); +} + +std::shared_ptr BuilderDefinition::load_module_from_registry( + const std::string& module_id, + const std::string& registry_namespace, + std::string module_name, + nlohmann::json config) +{ + auto fn_module_constructor = mrc::modules::ModuleRegistry::get_module_constructor(module_id, registry_namespace); + auto smodule = fn_module_constructor(std::move(module_name), std::move(config)); + + init_module(smodule); + + return smodule; +} + +const SegmentDefinition& BuilderDefinition::definition() const +{ + return *m_definition; +} + +void BuilderDefinition::initialize() +{ + auto address = segment_address_encode(this->definition().id(), m_rank); + + // construct ingress ports + for (const auto& [name, initializer] : this->definition().ingress_initializers()) + { + DVLOG(10) << "constructing ingress_port: " << name; + auto port = initializer(address); + this->add_object(name, port); + } + + // construct egress ports + for (const auto& [name, initializer] : this->definition().egress_initializers()) + { + DVLOG(10) << "constructing egress_port: " << name; + auto port = initializer(address); + this->add_object(name, port); + } + + // Call the segment initializer + try + { + m_definition->initializer_fn()(*this); + } catch (const std::exception& e) + { + LOG(ERROR) << "Exception during segment initializer. Segment name: " << m_definition->name() + << ", Segment Rank: " << m_rank << ". Exception message:\n" + << e.what(); + + // Rethrow after logging + std::rethrow_exception(std::current_exception()); + } +} + +const std::map>& BuilderDefinition::nodes() const +{ + return m_nodes; +} + +const std::map>& BuilderDefinition::egress_ports() const +{ + return m_egress_ports; +} + +const std::map>& BuilderDefinition::ingress_ports() const +{ + return m_ingress_ports; +} + +bool BuilderDefinition::has_object(const std::string& name) const +{ + auto [global_name, local_name] = this->normalize_name(name); + + auto search = m_objects.find(local_name); + return bool(search != m_objects.end()); +} + +mrc::segment::ObjectProperties& BuilderDefinition::find_object(const std::string& name) +{ + auto [global_name, local_name] = this->normalize_name(name); + + auto search = m_objects.find(local_name); + if (search == m_objects.end()) + { + LOG(ERROR) << "Unable to find segment object with name: " << name; + throw exceptions::MrcRuntimeError("unable to find segment object with name " + name); + } + return *(search->second); +} + +void BuilderDefinition::add_object(const std::string& name, std::shared_ptr<::mrc::segment::ObjectProperties> object) +{ + // First, ensure that the name is properly formatted + validate_name(name); + + if (has_object(name)) + { + LOG(ERROR) << "A Object named " << name << " is already registered"; + throw exceptions::MrcRuntimeError("duplicate name detected - name owned by a node"); + } + + auto [global_name, local_name] = this->normalize_name(name); + + m_objects[local_name] = object; + + // Now set the name on the object + object->set_name(global_name); + + if (object->is_runnable()) + { + auto launchable = std::dynamic_pointer_cast(object); + + CHECK(launchable) << "Invalid conversion. Object returned is_runnable() == true, but was not of type " + "Launchable"; + + m_nodes[local_name] = launchable; + } + + // Add to ingress ports list if it is the right type + if (auto ingress_port = std::dynamic_pointer_cast(object)) + { + // Save by the original name + m_ingress_ports[local_name] = ingress_port; + } + + // Add to egress ports list if it is the right type + if (auto egress_port = std::dynamic_pointer_cast(object)) + { + // Save by the original name + m_egress_ports[local_name] = egress_port; + } +} + +std::shared_ptr<::mrc::segment::IngressPortBase> BuilderDefinition::get_ingress_base(const std::string& name) +{ + auto [global_name, local_name] = this->normalize_name(name, true); + + auto search = m_ingress_ports.find(local_name); + if (search != m_ingress_ports.end()) + { + return search->second; + } + return nullptr; +} + +std::shared_ptr<::mrc::segment::EgressPortBase> BuilderDefinition::get_egress_base(const std::string& name) +{ + auto [global_name, local_name] = this->normalize_name(name, true); + + auto search = m_egress_ports.find(local_name); + if (search != m_egress_ports.end()) + { + return search->second; + } + return nullptr; +} + +std::function BuilderDefinition::make_throughput_counter(const std::string& name) +{ + auto [global_name, local_name] = this->normalize_name(name); + + auto counter = m_resources.metrics_registry().make_throughput_counter(global_name); + return [counter](std::int64_t ticks) mutable { + counter.increment(ticks); + }; +} + +void BuilderDefinition::ns_push(std::shared_ptr smodule) +{ + m_module_stack.push_back(smodule); + m_namespace_stack.push_back(smodule->component_prefix()); + m_namespace_prefix = + std::accumulate(m_namespace_stack.begin(), m_namespace_stack.end(), std::string(""), ::accum_merge); +} + +void BuilderDefinition::ns_pop() +{ + m_module_stack.pop_back(); + m_namespace_stack.pop_back(); + m_namespace_prefix = + std::accumulate(m_namespace_stack.begin(), m_namespace_stack.end(), std::string(""), ::accum_merge); +} + +} // namespace mrc::segment diff --git a/cpp/mrc/src/internal/segment/builder_definition.hpp b/cpp/mrc/src/internal/segment/builder_definition.hpp new file mode 100644 index 000000000..aa0c96140 --- /dev/null +++ b/cpp/mrc/src/internal/segment/builder_definition.hpp @@ -0,0 +1,168 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2022, 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. + */ + +#pragma once + +#include "mrc/segment/builder.hpp" +#include "mrc/types.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace mrc::pipeline { +class PipelineResources; +} // namespace mrc::pipeline + +namespace mrc::modules { +class SegmentModule; +class PersistentModule; +} // namespace mrc::modules + +namespace mrc::runnable { +struct Launchable; +} // namespace mrc::runnable + +namespace mrc::segment { +class EgressPortBase; +struct IngressPortBase; +struct ObjectProperties; +} // namespace mrc::segment + +namespace mrc::segment { +class SegmentDefinition; + +class BuilderDefinition : public IBuilder +{ + public: + BuilderDefinition(std::shared_ptr definition, + SegmentRank rank, + pipeline::PipelineResources& resources, + std::size_t default_partition_id); + + static std::shared_ptr unwrap(std::shared_ptr object); + + const std::string& name() const override; + + std::tuple normalize_name(const std::string& name, + bool ignore_namespace = false) const override; + + std::shared_ptr get_ingress(std::string name, std::type_index type_index) override; + + std::shared_ptr get_egress(std::string name, std::type_index type_index) override; + + /** + * Initialize a SegmentModule that was instantiated outside of the builder. + * @param module Module to initialize + */ + void init_module(std::shared_ptr smodule) override; + + /** + * Register an input port on the given module -- note: this in generally only necessary for dynamically + * created modules that use an alternate initializer function independent of the derived class. + * See: PythonSegmentModule + * @param input_name Unique name of the input port + * @param object shared pointer to type erased Object associated with 'input_name' on this module instance. + */ + void register_module_input(std::string input_name, std::shared_ptr object) override; + + /** + * Get the json configuration for the current module under configuration. + * @return nlohmann::json object. + */ + nlohmann::json get_current_module_config() override; + + /** + * Register an output port on the given module -- note: this in generally only necessary for dynamically + * created modules that use an alternate initializer function independent of the derived class. + * See: PythonSegmentModule + * @param output_name Unique name of the output port + * @param object shared pointer to type erased Object associated with 'output_name' on this module instance. + */ + void register_module_output(std::string output_name, std::shared_ptr object) override; + + /** + * Load an existing, registered module, initialize it, and return it to the caller + * @param module_id Unique ID of the module to load + * @param registry_namespace Namespace where the module id is registered + * @param module_name Unique name of this instance of the module + * @param config Configuration to pass to the module + * @return Return a shared pointer to the new module, which is a derived class of SegmentModule + */ + std::shared_ptr load_module_from_registry(const std::string& module_id, + const std::string& registry_namespace, + std::string module_name, + nlohmann::json config = {}) override; + + const SegmentDefinition& definition() const; + + void initialize(); + + const std::map>& nodes() const; + const std::map>& egress_ports() const; + const std::map>& ingress_ports() const; + + private: + // Overriding methods + ObjectProperties& find_object(const std::string& name) override; + void add_object(const std::string& name, std::shared_ptr object) override; + std::shared_ptr get_ingress_base(const std::string& name) override; + std::shared_ptr get_egress_base(const std::string& name) override; + std::function make_throughput_counter(const std::string& name) override; + + // Local methods + bool has_object(const std::string& name) const; + + void ns_push(std::shared_ptr smodule); + void ns_pop(); + + // definition + std::shared_ptr m_definition; + SegmentRank m_rank; + + // Resource info + pipeline::PipelineResources& m_resources; + const std::size_t m_default_partition_id; + + // Module info + std::string m_namespace_prefix; + std::vector m_namespace_stack{}; + std::vector> m_module_stack{}; + + // all objects - ports, runnables, etc. + std::map> m_objects; + + // Saved modules to guarantee lifetime + std::vector> m_modules; + + // only runnables + std::map> m_nodes; + + // ingress/egress - these are also nodes/objects + std::map> m_ingress_ports; + std::map> m_egress_ports; +}; + +} // namespace mrc::segment diff --git a/cpp/mrc/src/internal/segment/definition.hpp b/cpp/mrc/src/internal/segment/definition.hpp deleted file mode 100644 index 16e17e868..000000000 --- a/cpp/mrc/src/internal/segment/definition.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#pragma once - -#include "mrc/segment/initializers.hpp" -#include "mrc/types.hpp" - -#include -#include -#include - -namespace mrc::internal::segment { - -class Definition final -{ - public: - Definition(std::string name, - std::map ingress_initializers, - std::map egress_initializers, - ::mrc::segment::backend_initializer_fn_t backend_initializer); - - const std::string& name() const; - SegmentID id() const; - std::vector ingress_port_names() const; - std::vector egress_port_names() const; - - const ::mrc::segment::backend_initializer_fn_t& initializer_fn() const; - const std::map& egress_initializers() const; - const std::map& ingress_initializers() const; - - private: - void validate_ports() const; - - std::string m_name; - SegmentID m_id; - ::mrc::segment::backend_initializer_fn_t m_backend_initializer; - std::map m_egress_initializers; - std::map m_ingress_initializers; -}; - -} // namespace mrc::internal::segment diff --git a/cpp/mrc/src/internal/segment/ibuilder.cpp b/cpp/mrc/src/internal/segment/ibuilder.cpp deleted file mode 100644 index 0a89c5e08..000000000 --- a/cpp/mrc/src/internal/segment/ibuilder.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2022, 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. - */ - -#include "mrc/engine/segment/ibuilder.hpp" - -#include "internal/segment/builder.hpp" - -#include - -#include - -namespace mrc::internal::segment { - -IBuilder::IBuilder(Builder* impl) : m_impl(impl) -{ - CHECK(m_impl != nullptr); -} - -IBuilder::~IBuilder() = default; - -const std::string& IBuilder::name() const -{ - CHECK(m_impl); - return m_impl->name(); -} - -bool IBuilder::has_object(const std::string& name) const -{ - CHECK(m_impl); - return m_impl->has_object(name); -} - -mrc::segment::ObjectProperties& IBuilder::find_object(const std::string& name) -{ - CHECK(m_impl); - return m_impl->find_object(name); -} - -void IBuilder::add_object(const std::string& name, std::shared_ptr<::mrc::segment::ObjectProperties> object) -{ - CHECK(m_impl); - return m_impl->add_object(name, std::move(object)); -} - -void IBuilder::add_module(const std::string& name, std::shared_ptr smodule) -{ - CHECK(m_impl); - return m_impl->add_module(name, std::move(smodule)); -} - -void IBuilder::add_runnable(const std::string& name, std::shared_ptr runnable) -{ - CHECK(m_impl); - return m_impl->add_runnable(name, std::move(runnable)); -} - -std::shared_ptr IBuilder::get_ingress_base(const std::string& name) -{ - CHECK(m_impl); - return m_impl->get_ingress_base(name); -} - -std::shared_ptr IBuilder::get_egress_base(const std::string& name) -{ - CHECK(m_impl); - return m_impl->get_egress_base(name); -} - -std::function IBuilder::make_throughput_counter(const std::string& name) -{ - CHECK(m_impl); - return m_impl->make_throughput_counter(name); -} - -} // namespace mrc::internal::segment diff --git a/cpp/mrc/src/internal/segment/idefinition.cpp b/cpp/mrc/src/internal/segment/idefinition.cpp deleted file mode 100644 index 2771eea72..000000000 --- a/cpp/mrc/src/internal/segment/idefinition.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#include "mrc/engine/segment/idefinition.hpp" - -#include "internal/segment/definition.hpp" - -#include - -namespace mrc::internal::segment { - -IDefinition::IDefinition(std::string name, - std::map ingress_initializers, - std::map egress_initializers, - ::mrc::segment::backend_initializer_fn_t backend_initializer) : - m_impl(std::make_shared(std::move(name), - std::move(ingress_initializers), - std::move(egress_initializers), - std::move(backend_initializer))) -{} - -IDefinition::~IDefinition() = default; - -const std::string& IDefinition::name() const -{ - return m_impl->name(); -} - -} // namespace mrc::internal::segment diff --git a/cpp/mrc/src/internal/segment/definition.cpp b/cpp/mrc/src/internal/segment/segment_definition.cpp similarity index 62% rename from cpp/mrc/src/internal/segment/definition.cpp rename to cpp/mrc/src/internal/segment/segment_definition.cpp index 811e923e7..1f04f50f6 100644 --- a/cpp/mrc/src/internal/segment/definition.cpp +++ b/cpp/mrc/src/internal/segment/segment_definition.cpp @@ -15,42 +15,57 @@ * limitations under the License. */ -#include "internal/segment/definition.hpp" +#include "internal/segment/segment_definition.hpp" #include "mrc/core/addresses.hpp" #include "mrc/exceptions/runtime_error.hpp" +#include "mrc/segment/egress_ports.hpp" +#include "mrc/segment/ingress_ports.hpp" #include "mrc/types.hpp" +#include + #include +#include #include #include -namespace mrc::internal::segment { +namespace mrc::segment { -Definition::Definition(std::string name, - std::map ingress_initializers, - std::map egress_initializers, - ::mrc::segment::backend_initializer_fn_t backend_initializer) : - m_name(name), +SegmentDefinition::SegmentDefinition(std::string name, + IngressPortsBase ingress_ports, + EgressPortsBase egress_ports, + segment_initializer_fn_t initializer) : m_id(segment_name_hash(name)), - m_backend_initializer(std::move(backend_initializer)), - m_ingress_initializers(std::move(ingress_initializers)), - m_egress_initializers(std::move(egress_initializers)) + m_name(std::move(name)), + m_ingress_initializers(ingress_ports.get_initializers()), + m_egress_initializers(egress_ports.get_initializers()), + m_initializer_fn(std::move(initializer)) { validate_ports(); } -const std::string& Definition::name() const +std::shared_ptr SegmentDefinition::unwrap(std::shared_ptr object) { - return m_name; + // Convert to the full implementation + auto full_object = std::dynamic_pointer_cast(object); + + CHECK(full_object) << "Invalid cast for SegmentDefinition. Please report to the developers"; + + return full_object; } -SegmentID Definition::id() const +SegmentID SegmentDefinition::id() const { return m_id; } -std::vector Definition::ingress_port_names() const +const std::string& SegmentDefinition::name() const +{ + return m_name; +} + +std::vector SegmentDefinition::ingress_port_names() const { std::vector names; for (const auto& [name, init] : m_ingress_initializers) @@ -59,7 +74,7 @@ std::vector Definition::ingress_port_names() const } return names; } -std::vector Definition::egress_port_names() const +std::vector SegmentDefinition::egress_port_names() const { std::vector names; for (const auto& [name, init] : m_egress_initializers) @@ -69,22 +84,22 @@ std::vector Definition::egress_port_names() const return names; } -const ::mrc::segment::backend_initializer_fn_t& Definition::initializer_fn() const +const segment_initializer_fn_t& SegmentDefinition::initializer_fn() const { - return m_backend_initializer; + return m_initializer_fn; } -const std::map& Definition::egress_initializers() const +const std::map& SegmentDefinition::egress_initializers() const { return m_egress_initializers; } -const std::map& Definition::ingress_initializers() const +const std::map& SegmentDefinition::ingress_initializers() const { return m_ingress_initializers; } -void Definition::validate_ports() const +void SegmentDefinition::validate_ports() const { std::vector names; @@ -119,4 +134,4 @@ void Definition::validate_ports() const } } -} // namespace mrc::internal::segment +} // namespace mrc::segment diff --git a/cpp/mrc/src/internal/segment/segment_definition.hpp b/cpp/mrc/src/internal/segment/segment_definition.hpp new file mode 100644 index 000000000..8f1d62827 --- /dev/null +++ b/cpp/mrc/src/internal/segment/segment_definition.hpp @@ -0,0 +1,63 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. + */ + +#pragma once + +#include "mrc/pipeline/segment.hpp" +#include "mrc/segment/initializers.hpp" +#include "mrc/types.hpp" + +#include +#include +#include +#include + +namespace mrc::segment { +struct EgressPortsBase; +struct IngressPortsBase; + +class SegmentDefinition final : public pipeline::ISegment +{ + public: + SegmentDefinition(std::string name, + IngressPortsBase ingress_ports, + EgressPortsBase egress_ports, + segment_initializer_fn_t initializer); + + static std::shared_ptr unwrap(std::shared_ptr object); + + SegmentID id() const override; + const std::string& name() const override; + std::vector ingress_port_names() const override; + std::vector egress_port_names() const override; + + const segment_initializer_fn_t& initializer_fn() const; + + const std::map& egress_initializers() const; + const std::map& ingress_initializers() const; + + private: + void validate_ports() const; + + SegmentID m_id; + std::string m_name; + std::map m_egress_initializers; + std::map m_ingress_initializers; + segment_initializer_fn_t m_initializer_fn; +}; + +} // namespace mrc::segment diff --git a/cpp/mrc/src/internal/segment/instance.cpp b/cpp/mrc/src/internal/segment/segment_instance.cpp similarity index 84% rename from cpp/mrc/src/internal/segment/instance.cpp rename to cpp/mrc/src/internal/segment/segment_instance.cpp index 9aafbc4af..871b7a2ca 100644 --- a/cpp/mrc/src/internal/segment/instance.cpp +++ b/cpp/mrc/src/internal/segment/segment_instance.cpp @@ -15,14 +15,14 @@ * limitations under the License. */ -#include "internal/segment/instance.hpp" +#include "internal/segment/segment_instance.hpp" -#include "internal/pipeline/resources.hpp" +#include "internal/pipeline/pipeline_resources.hpp" #include "internal/resources/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" -#include "internal/segment/builder.hpp" -#include "internal/segment/definition.hpp" +#include "internal/runnable/runnable_resources.hpp" +#include "internal/segment/builder_definition.hpp" +#include "internal/segment/segment_definition.hpp" #include "mrc/core/addresses.hpp" #include "mrc/core/task_queue.hpp" @@ -48,12 +48,12 @@ #include #include -namespace mrc::internal::segment { +namespace mrc::segment { -Instance::Instance(std::shared_ptr definition, - SegmentRank rank, - pipeline::Resources& resources, - std::size_t partition_id) : +SegmentInstance::SegmentInstance(std::shared_ptr definition, + SegmentRank rank, + pipeline::PipelineResources& resources, + std::size_t partition_id) : m_name(definition->name()), m_id(definition->id()), m_rank(rank), @@ -68,34 +68,39 @@ Instance::Instance(std::shared_ptr definition, .runnable() .main() .enqueue([&]() mutable { - return std::make_unique(definition, rank, m_resources, m_default_partition_id); + auto builder = + std::make_unique(definition, rank, m_resources, m_default_partition_id); + + builder->initialize(); + + return builder; }) .get(); } -Instance::~Instance() = default; +SegmentInstance::~SegmentInstance() = default; -const std::string& Instance::name() const +const std::string& SegmentInstance::name() const { return m_name; } -const SegmentID& Instance::id() const +const SegmentID& SegmentInstance::id() const { return m_id; } -const SegmentRank& Instance::rank() const +const SegmentRank& SegmentInstance::rank() const { return m_rank; } -const SegmentAddress& Instance::address() const +const SegmentAddress& SegmentInstance::address() const { return m_address; } -void Instance::do_service_start() +void SegmentInstance::do_service_start() { // prepare launchers from m_builder std::map> m_launchers; @@ -165,7 +170,7 @@ void Instance::do_service_start() DVLOG(10) << info() << " start has been initiated; use the is_running future to await on startup"; } -void Instance::do_service_stop() +void SegmentInstance::do_service_stop() { DVLOG(10) << info() << " issuing stop request"; @@ -180,7 +185,7 @@ void Instance::do_service_stop() DVLOG(10) << info() << " stop has been initiated; use the is_completed future to await on shutdown"; } -void Instance::do_service_kill() +void SegmentInstance::do_service_kill() { DVLOG(10) << info() << " issuing kill request"; @@ -205,7 +210,7 @@ void Instance::do_service_kill() DVLOG(10) << info() << " kill has been initiated; use the is_completed future to await on shutdown"; } -void Instance::do_service_await_live() +void SegmentInstance::do_service_await_live() { DVLOG(10) << info() << " await_live started"; for (const auto& [name, runner] : m_ingress_runners) @@ -226,7 +231,7 @@ void Instance::do_service_await_live() DVLOG(10) << info() << " join complete"; } -void Instance::do_service_await_join() +void SegmentInstance::do_service_await_join() { DVLOG(10) << info() << " join started"; std::exception_ptr first_exception = nullptr; @@ -262,12 +267,13 @@ void Instance::do_service_await_join() DVLOG(10) << info() << " join complete"; if (first_exception) { - LOG(ERROR) << "segment::Instance - an exception was caught while awaiting on one or more nodes - rethrowing"; + LOG(ERROR) << "segment::SegmentInstance - an exception was caught while awaiting on one or more nodes - " + "rethrowing"; rethrow_exception(std::move(first_exception)); } } -void Instance::attach_manifold(std::shared_ptr manifold) +void SegmentInstance::attach_manifold(std::shared_ptr manifold) { auto port_name = manifold->port_name(); @@ -295,12 +301,12 @@ void Instance::attach_manifold(std::shared_ptr manifold) throw exceptions::MrcRuntimeError("invalid manifold for segment"); } -const std::string& Instance::info() const +const std::string& SegmentInstance::info() const { return m_info; } -std::shared_ptr Instance::create_manifold(const PortName& name) +std::shared_ptr SegmentInstance::create_manifold(const PortName& name) { std::lock_guard lock(m_mutex); DVLOG(10) << info() << " attempting to build manifold for port " << name; @@ -322,4 +328,4 @@ std::shared_ptr Instance::create_manifold(const PortName& n return nullptr; } -} // namespace mrc::internal::segment +} // namespace mrc::segment diff --git a/cpp/mrc/src/internal/segment/instance.hpp b/cpp/mrc/src/internal/segment/segment_instance.hpp similarity index 78% rename from cpp/mrc/src/internal/segment/instance.hpp rename to cpp/mrc/src/internal/segment/segment_instance.hpp index ba012b58b..addd38dd1 100644 --- a/cpp/mrc/src/internal/segment/instance.hpp +++ b/cpp/mrc/src/internal/segment/segment_instance.hpp @@ -28,26 +28,26 @@ #include #include -namespace mrc::internal::pipeline { -class Resources; -} // namespace mrc::internal::pipeline +namespace mrc::pipeline { +class PipelineResources; +} // namespace mrc::pipeline namespace mrc::manifold { struct Interface; } // namespace mrc::manifold -namespace mrc::internal::segment { -class Definition; -class Builder; +namespace mrc::segment { +class SegmentDefinition; +class BuilderDefinition; // todo(ryan) - inherit from service -class Instance final : public Service +class SegmentInstance final : public Service { public: - Instance(std::shared_ptr definition, - SegmentRank rank, - pipeline::Resources& resources, - std::size_t partition_id); - ~Instance() override; + SegmentInstance(std::shared_ptr definition, + SegmentRank rank, + pipeline::PipelineResources& resources, + std::size_t partition_id); + ~SegmentInstance() override; const std::string& name() const; const SegmentID& id() const; @@ -75,8 +75,8 @@ class Instance final : public Service SegmentAddress m_address; std::string m_info; - std::unique_ptr m_builder; - pipeline::Resources& m_resources; + std::unique_ptr m_builder; + pipeline::PipelineResources& m_resources; const std::size_t m_default_partition_id; std::map> m_runners; @@ -86,4 +86,4 @@ class Instance final : public Service mutable std::mutex m_mutex; }; -} // namespace mrc::internal::segment +} // namespace mrc::segment diff --git a/cpp/mrc/src/internal/service.cpp b/cpp/mrc/src/internal/service.cpp index 01c8e1edb..01c51b014 100644 --- a/cpp/mrc/src/internal/service.cpp +++ b/cpp/mrc/src/internal/service.cpp @@ -22,7 +22,7 @@ #include #include -namespace mrc::internal { +namespace mrc { Service::~Service() { @@ -144,4 +144,4 @@ void Service::service_set_description(std::string description) m_description = std::move(description); } -} // namespace mrc::internal +} // namespace mrc diff --git a/cpp/mrc/src/internal/service.hpp b/cpp/mrc/src/internal/service.hpp index d369d1f30..f707321e2 100644 --- a/cpp/mrc/src/internal/service.hpp +++ b/cpp/mrc/src/internal/service.hpp @@ -20,7 +20,7 @@ #include #include -namespace mrc::internal { +namespace mrc { enum class ServiceState { @@ -71,8 +71,8 @@ class Service // : public IService virtual void do_service_await_join() = 0; ServiceState m_state{ServiceState::Initialized}; - std::string m_description{"mrc::internal::service"}; + std::string m_description{"mrc::service"}; mutable std::mutex m_mutex; }; -} // namespace mrc::internal +} // namespace mrc diff --git a/cpp/mrc/src/internal/system/device_info.cpp b/cpp/mrc/src/internal/system/device_info.cpp index 66836078c..b9f3461f2 100644 --- a/cpp/mrc/src/internal/system/device_info.cpp +++ b/cpp/mrc/src/internal/system/device_info.cpp @@ -38,7 +38,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { struct NvmlHandle; struct NvmlState; @@ -396,4 +396,4 @@ std::string DeviceInfo::UUID(unsigned int device_id) return buffer.data(); } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/device_info.hpp b/cpp/mrc/src/internal/system/device_info.hpp index 441fc5175..ce73031bc 100644 --- a/cpp/mrc/src/internal/system/device_info.hpp +++ b/cpp/mrc/src/internal/system/device_info.hpp @@ -29,7 +29,7 @@ using hwloc_topology_t = struct hwloc_topology*; using nvmlDevice_t = struct nvmlDevice_st*; // NOLINTEND(readability-identifier-naming) -namespace mrc::internal::system { +namespace mrc::system { struct DeviceInfo { @@ -48,4 +48,4 @@ struct DeviceInfo // NOLINTEND(readability-identifier-naming) }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/device_partition.cpp b/cpp/mrc/src/internal/system/device_partition.cpp index ced9e7964..75860c784 100644 --- a/cpp/mrc/src/internal/system/device_partition.cpp +++ b/cpp/mrc/src/internal/system/device_partition.cpp @@ -21,7 +21,7 @@ #include -namespace mrc::internal::system { +namespace mrc::system { DevicePartition::DevicePartition(const GpuInfo& gpu_info, std::shared_ptr host_partition) : GpuInfo(gpu_info), @@ -55,4 +55,4 @@ const HostPartition& DevicePartition::host() const CHECK(m_host_partition); return *m_host_partition; } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/device_partition.hpp b/cpp/mrc/src/internal/system/device_partition.hpp index 35ce9131a..2cc7209fc 100644 --- a/cpp/mrc/src/internal/system/device_partition.hpp +++ b/cpp/mrc/src/internal/system/device_partition.hpp @@ -23,7 +23,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { class HostPartition; class DevicePartition final : private GpuInfo @@ -48,4 +48,4 @@ class DevicePartition final : private GpuInfo std::shared_ptr m_host_partition; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/engine_factory_cpu_sets.cpp b/cpp/mrc/src/internal/system/engine_factory_cpu_sets.cpp index 1e7865f67..11a3234c8 100644 --- a/cpp/mrc/src/internal/system/engine_factory_cpu_sets.cpp +++ b/cpp/mrc/src/internal/system/engine_factory_cpu_sets.cpp @@ -33,7 +33,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { bool EngineFactoryCpuSets::is_resuable(const std::string& name) const { @@ -258,4 +258,4 @@ std::size_t EngineFactoryCpuSets::main_cpu_id() const return search->second.first(); } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/engine_factory_cpu_sets.hpp b/cpp/mrc/src/internal/system/engine_factory_cpu_sets.hpp index 867f5a4c6..2dd300389 100644 --- a/cpp/mrc/src/internal/system/engine_factory_cpu_sets.hpp +++ b/cpp/mrc/src/internal/system/engine_factory_cpu_sets.hpp @@ -27,7 +27,7 @@ namespace mrc { class Options; } // namespace mrc -namespace mrc::internal::system { +namespace mrc::system { class Topology; @@ -58,4 +58,4 @@ extern EngineFactoryCpuSets generate_engine_factory_cpu_sets(const Topology& top const Options& options, const CpuSet& cpu_set); -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/fiber_manager.cpp b/cpp/mrc/src/internal/system/fiber_manager.cpp index b4543915e..2eec52f12 100644 --- a/cpp/mrc/src/internal/system/fiber_manager.cpp +++ b/cpp/mrc/src/internal/system/fiber_manager.cpp @@ -18,8 +18,8 @@ #include "internal/system/fiber_manager.hpp" #include "internal/system/fiber_pool.hpp" -#include "internal/system/resources.hpp" #include "internal/system/system.hpp" +#include "internal/system/threading_resources.hpp" #include "internal/system/topology.hpp" #include "mrc/core/bitmap.hpp" @@ -30,9 +30,9 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { -FiberManager::FiberManager(const Resources& resources) : m_cpu_set(resources.system().topology().cpu_set()) +FiberManager::FiberManager(const ThreadingResources& resources) : m_cpu_set(resources.system().topology().cpu_set()) { auto cpu_count = m_cpu_set.weight(); const auto& options = resources.system().options(); @@ -94,4 +94,4 @@ FiberTaskQueue& FiberManager::task_queue(std::uint32_t cpu_id) const return *search->second; } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/fiber_manager.hpp b/cpp/mrc/src/internal/system/fiber_manager.hpp index 4d0847900..09e055c56 100644 --- a/cpp/mrc/src/internal/system/fiber_manager.hpp +++ b/cpp/mrc/src/internal/system/fiber_manager.hpp @@ -34,14 +34,14 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { -class Resources; +class ThreadingResources; class FiberManager final { public: - FiberManager(const Resources& resources); + FiberManager(const ThreadingResources& resources); ~FiberManager(); DELETE_COPYABILITY(FiberManager); @@ -111,4 +111,4 @@ class FiberManager final std::map> m_queues; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/fiber_pool.cpp b/cpp/mrc/src/internal/system/fiber_pool.cpp index 2541fde56..256acb923 100644 --- a/cpp/mrc/src/internal/system/fiber_pool.cpp +++ b/cpp/mrc/src/internal/system/fiber_pool.cpp @@ -28,7 +28,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { FiberPool::FiberPool(CpuSet cpu_set, std::vector>&& queues) : m_cpu_set(std::move(cpu_set)), @@ -53,4 +53,4 @@ core::FiberTaskQueue& FiberPool::task_queue(const std::size_t& index) return m_queues.at(index); } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/fiber_pool.hpp b/cpp/mrc/src/internal/system/fiber_pool.hpp index 9155a92a1..857401bb7 100644 --- a/cpp/mrc/src/internal/system/fiber_pool.hpp +++ b/cpp/mrc/src/internal/system/fiber_pool.hpp @@ -29,7 +29,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { class FiberTaskQueue; class FiberPool final : public core::FiberPool @@ -70,4 +70,4 @@ class FiberPool final : public core::FiberPool std::vector> m_queues; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/fiber_priority_scheduler.hpp b/cpp/mrc/src/internal/system/fiber_priority_scheduler.hpp index 478bef253..8753acedf 100644 --- a/cpp/mrc/src/internal/system/fiber_priority_scheduler.hpp +++ b/cpp/mrc/src/internal/system/fiber_priority_scheduler.hpp @@ -20,7 +20,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { class FiberPriorityProps : public boost::fibers::fiber_properties { @@ -152,4 +152,4 @@ class FiberPriorityScheduler : public boost::fibers::algo::algorithm_with_proper } }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/fiber_task_queue.cpp b/cpp/mrc/src/internal/system/fiber_task_queue.cpp index e64b38288..709be264e 100644 --- a/cpp/mrc/src/internal/system/fiber_task_queue.cpp +++ b/cpp/mrc/src/internal/system/fiber_task_queue.cpp @@ -18,7 +18,7 @@ #include "internal/system/fiber_task_queue.hpp" #include "internal/system/fiber_priority_scheduler.hpp" -#include "internal/system/resources.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/core/bitmap.hpp" #include "mrc/core/fiber_meta_data.hpp" @@ -37,9 +37,9 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { -FiberTaskQueue::FiberTaskQueue(const Resources& resources, CpuSet cpu_affinity, std::size_t channel_size) : +FiberTaskQueue::FiberTaskQueue(const ThreadingResources& resources, CpuSet cpu_affinity, std::size_t channel_size) : m_queue(channel_size), m_cpu_affinity(std::move(cpu_affinity)), m_thread(resources.make_thread("fiberq", m_cpu_affinity, [this] { @@ -133,4 +133,4 @@ bool FiberTaskQueue::caller_on_same_thread() const { return std::this_thread::get_id() == m_thread.thread().get_id(); } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/fiber_task_queue.hpp b/cpp/mrc/src/internal/system/fiber_task_queue.hpp index 0c2a9176c..c58c8190b 100644 --- a/cpp/mrc/src/internal/system/fiber_task_queue.hpp +++ b/cpp/mrc/src/internal/system/fiber_task_queue.hpp @@ -29,14 +29,14 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { -class Resources; +class ThreadingResources; class FiberTaskQueue final : public core::FiberTaskQueue { public: - FiberTaskQueue(const Resources& resources, CpuSet cpu_affinity, std::size_t channel_size = 64); + FiberTaskQueue(const ThreadingResources& resources, CpuSet cpu_affinity, std::size_t channel_size = 64); ~FiberTaskQueue() final; DELETE_COPYABILITY(FiberTaskQueue); @@ -62,4 +62,4 @@ class FiberTaskQueue final : public core::FiberTaskQueue Thread m_thread; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/forward.hpp b/cpp/mrc/src/internal/system/forward.hpp index f1fa8b3bf..c3e938415 100644 --- a/cpp/mrc/src/internal/system/forward.hpp +++ b/cpp/mrc/src/internal/system/forward.hpp @@ -17,7 +17,7 @@ #pragma once -namespace mrc::internal::system { +namespace mrc::system { class System; class Topology; @@ -30,4 +30,4 @@ class FiberTaskQueue; class FiberPool; class FiberManager; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/gpu_info.cpp b/cpp/mrc/src/internal/system/gpu_info.cpp index 3257eee5f..0c8c15a23 100644 --- a/cpp/mrc/src/internal/system/gpu_info.cpp +++ b/cpp/mrc/src/internal/system/gpu_info.cpp @@ -19,7 +19,7 @@ #include "mrc/core/bitmap.hpp" -namespace mrc::internal::system { +namespace mrc::system { const CpuSet& GpuInfo::cpu_set() const { @@ -76,4 +76,4 @@ GpuInfo GpuInfo::deserialize(const protos::GpuInfo& msg) return info; } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/gpu_info.hpp b/cpp/mrc/src/internal/system/gpu_info.hpp index 9fc16ffb8..396912ca3 100644 --- a/cpp/mrc/src/internal/system/gpu_info.hpp +++ b/cpp/mrc/src/internal/system/gpu_info.hpp @@ -25,7 +25,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { /** * @brief GpuInfo describes an NVIDIA GPU within the hwloc topology @@ -75,4 +75,4 @@ class GpuInfo } }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/host_partition.cpp b/cpp/mrc/src/internal/system/host_partition.cpp index dd33e7ca6..b27f3f7d1 100644 --- a/cpp/mrc/src/internal/system/host_partition.cpp +++ b/cpp/mrc/src/internal/system/host_partition.cpp @@ -21,7 +21,7 @@ #include -namespace mrc::internal::system { +namespace mrc::system { HostPartition::HostPartition(CpuSet cpu_set, NumaSet numa_set, std::size_t total_memory) : m_cpu_set(std::move(cpu_set)), @@ -60,4 +60,4 @@ const EngineFactoryCpuSets& HostPartition::engine_factory_cpu_sets() const { return m_engine_factory_cpu_sets; } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/host_partition.hpp b/cpp/mrc/src/internal/system/host_partition.hpp index 3c6d815c5..222cb925f 100644 --- a/cpp/mrc/src/internal/system/host_partition.hpp +++ b/cpp/mrc/src/internal/system/host_partition.hpp @@ -28,7 +28,7 @@ namespace mrc { class Options; } -namespace mrc::internal::system { +namespace mrc::system { class Topology; class HostPartition @@ -55,4 +55,4 @@ class HostPartition EngineFactoryCpuSets m_engine_factory_cpu_sets; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/host_partition_provider.cpp b/cpp/mrc/src/internal/system/host_partition_provider.cpp index 64859bf11..953833435 100644 --- a/cpp/mrc/src/internal/system/host_partition_provider.cpp +++ b/cpp/mrc/src/internal/system/host_partition_provider.cpp @@ -24,7 +24,7 @@ #include -namespace mrc::internal::system { +namespace mrc::system { class HostPartition; HostPartitionProvider::HostPartitionProvider(const SystemProvider& _system, std::size_t _host_partition_id) : @@ -44,4 +44,4 @@ const HostPartition& HostPartitionProvider::host_partition() const CHECK_LT(m_host_partition_id, system().partitions().host_partitions().size()); return system().partitions().host_partitions().at(m_host_partition_id); } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/host_partition_provider.hpp b/cpp/mrc/src/internal/system/host_partition_provider.hpp index fc377e50e..c66eb1665 100644 --- a/cpp/mrc/src/internal/system/host_partition_provider.hpp +++ b/cpp/mrc/src/internal/system/host_partition_provider.hpp @@ -21,7 +21,7 @@ #include -namespace mrc::internal::system { +namespace mrc::system { class HostPartition; /** @@ -41,4 +41,4 @@ class HostPartitionProvider : public SystemProvider const std::size_t m_host_partition_id; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/iresources.cpp b/cpp/mrc/src/internal/system/iresources.cpp deleted file mode 100644 index 2cf567143..000000000 --- a/cpp/mrc/src/internal/system/iresources.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#include "mrc/engine/system/iresources.hpp" - -#include "internal/system/resources.hpp" -#include "internal/system/system.hpp" -#include "internal/system/system_provider.hpp" -#include "internal/system/topology.hpp" - -#include -#include - -namespace mrc::internal::system { - -IResources::IResources(std::shared_ptr system) : - m_impl(std::make_unique(SystemProvider(System::unwrap(*system)))) -{} -IResources::~IResources() = default; - -void IResources::add_thread_initializer(std::function initializer_fn) -{ - m_impl->register_thread_local_initializer(m_impl->system().topology().cpu_set(), std::move(initializer_fn)); -} - -void IResources::add_thread_finalizer(std::function finalizer_fn) -{ - m_impl->register_thread_local_finalizer(m_impl->system().topology().cpu_set(), std::move(finalizer_fn)); -} - -} // namespace mrc::internal::system diff --git a/cpp/mrc/src/internal/system/partition.cpp b/cpp/mrc/src/internal/system/partition.cpp index b1facf503..c78e07224 100644 --- a/cpp/mrc/src/internal/system/partition.cpp +++ b/cpp/mrc/src/internal/system/partition.cpp @@ -24,7 +24,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { const HostPartition& Partition::host() const { @@ -60,4 +60,4 @@ size_t Partition::host_partition_id() const return m_host_partition_id; } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/partition.hpp b/cpp/mrc/src/internal/system/partition.hpp index f57b9311d..b64358ecd 100644 --- a/cpp/mrc/src/internal/system/partition.hpp +++ b/cpp/mrc/src/internal/system/partition.hpp @@ -20,7 +20,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { class DevicePartition; class HostPartition; @@ -43,4 +43,4 @@ class Partition final std::shared_ptr m_device; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/partition_provider.cpp b/cpp/mrc/src/internal/system/partition_provider.cpp index 14b957b12..33feb2c77 100644 --- a/cpp/mrc/src/internal/system/partition_provider.cpp +++ b/cpp/mrc/src/internal/system/partition_provider.cpp @@ -24,7 +24,7 @@ #include -namespace mrc::internal::system { +namespace mrc::system { PartitionProvider::PartitionProvider(SystemProvider& system, std::size_t partition_id) : SystemProvider(system), @@ -41,4 +41,4 @@ const Partition& PartitionProvider::partition() const { return system().partitions().flattened().at(m_partition_id); } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/partition_provider.hpp b/cpp/mrc/src/internal/system/partition_provider.hpp index cb18a8a9f..88fef21ba 100644 --- a/cpp/mrc/src/internal/system/partition_provider.hpp +++ b/cpp/mrc/src/internal/system/partition_provider.hpp @@ -21,7 +21,7 @@ #include -namespace mrc::internal::system { +namespace mrc::system { class Partition; /** @@ -44,4 +44,4 @@ class PartitionProvider : public SystemProvider std::size_t m_partition_id; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/partitions.cpp b/cpp/mrc/src/internal/system/partitions.cpp index 6d35ea913..01fbeacca 100644 --- a/cpp/mrc/src/internal/system/partitions.cpp +++ b/cpp/mrc/src/internal/system/partitions.cpp @@ -56,9 +56,9 @@ static void div_even(std::int32_t n, std::int32_t np, std::int32_t me, std::int3 } } -namespace mrc::internal::system { +namespace mrc::system { -Partitions::Partitions(const System& system) : Partitions(system.topology(), system.options()) {} +Partitions::Partitions(const SystemDefinition& system) : Partitions(system.topology(), system.options()) {} Partitions::Partitions(const Topology& topology, const Options& options) { @@ -337,4 +337,4 @@ const std::vector& Partitions::device_partitions() const { return m_device_partitions; } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/partitions.hpp b/cpp/mrc/src/internal/system/partitions.hpp index 47f9a4c04..82dd80af7 100644 --- a/cpp/mrc/src/internal/system/partitions.hpp +++ b/cpp/mrc/src/internal/system/partitions.hpp @@ -29,16 +29,16 @@ enum class PlacementResources; enum class PlacementStrategy; } // namespace mrc -namespace mrc::internal::system { +namespace mrc::system { -class System; +class SystemDefinition; class Topology; class Partitions { public: Partitions(const Topology& topology, const Options& options); - Partitions(const System& system); + Partitions(const SystemDefinition& system); // The host and device partitions are hierarchical where there is a possibility, depending on options provided, // where more than one cuda device shares the same host partition, so those host resources are shared. @@ -68,4 +68,4 @@ class Partitions PlacementResources m_device_to_host_strategy; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/system.cpp b/cpp/mrc/src/internal/system/system.cpp index 403223564..175505126 100644 --- a/cpp/mrc/src/internal/system/system.cpp +++ b/cpp/mrc/src/internal/system/system.cpp @@ -21,60 +21,83 @@ #include "internal/system/topology.hpp" #include "mrc/core/bitmap.hpp" -#include "mrc/engine/system/isystem.hpp" #include "mrc/options/options.hpp" #include #include +#include +#include #include -namespace mrc::internal::system { +namespace mrc::system { -std::shared_ptr System::create(std::shared_ptr options) -{ - return std::shared_ptr(new System(std::move(options))); -} +SystemDefinition::SystemDefinition(const Options& options) : + m_options(std::make_unique(options)), // Run the copy constructor to make a copy + m_topology(Topology::Create(m_options->topology())), + m_partitions(std::make_shared(*this)) +{} -std::shared_ptr System::unwrap(const ISystem& system) +SystemDefinition::SystemDefinition(std::shared_ptr options) : SystemDefinition(*options) {} + +SystemDefinition::~SystemDefinition() = default; + +std::unique_ptr SystemDefinition::unwrap(std::unique_ptr object) { - return system.m_impl; -} + // Convert to the full implementation + auto* full_object_ptr = dynamic_cast(object.get()); -System::System(std::shared_ptr options) : - m_options(options), - m_topology(Topology::Create(options->topology())), - m_partitions(std::make_shared(*this)) -{} + CHECK(full_object_ptr) << "Invalid cast for SystemDefinition. Please report to the developers"; -const Options& System::options() const + // At this point, the object is a valid cast. Release the pointer so it doesnt get deallocated + object.release(); + + return std::unique_ptr(full_object_ptr); +} + +const Options& SystemDefinition::options() const { CHECK(m_options); return *m_options; } -const Topology& System::topology() const +const Topology& SystemDefinition::topology() const { CHECK(m_topology); return *m_topology; } -const Partitions& System::partitions() const +const Partitions& SystemDefinition::partitions() const { CHECK(m_partitions); return *m_partitions; } -CpuSet System::get_current_thread_affinity() const +void SystemDefinition::add_thread_initializer(std::function initializer_fn) { - CpuSet cpu_set; - hwloc_get_cpubind(topology().handle(), &cpu_set.bitmap(), HWLOC_CPUBIND_THREAD); - return cpu_set; + m_thread_initializers.emplace_back(std::move(initializer_fn)); +} + +void SystemDefinition::add_thread_finalizer(std::function finalizer_fn) +{ + m_thread_finalizers.emplace_back(std::move(finalizer_fn)); +} + +const std::vector>& SystemDefinition::thread_initializers() const +{ + return m_thread_initializers; } -std::shared_ptr make_system(std::shared_ptr options) +const std::vector>& SystemDefinition::thread_finalizers() const { - return System::create(std::move(options)); + return m_thread_finalizers; +} + +CpuSet SystemDefinition::get_current_thread_affinity() const +{ + CpuSet cpu_set; + hwloc_get_cpubind(topology().handle(), &cpu_set.bitmap(), HWLOC_CPUBIND_THREAD); + return cpu_set; } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/system.hpp b/cpp/mrc/src/internal/system/system.hpp index f28d704f3..649dbf63d 100644 --- a/cpp/mrc/src/internal/system/system.hpp +++ b/cpp/mrc/src/internal/system/system.hpp @@ -18,45 +18,53 @@ #pragma once #include "mrc/core/bitmap.hpp" +#include "mrc/pipeline/system.hpp" #include "mrc/utils/macros.hpp" +#include #include +#include namespace mrc { class Options; } // namespace mrc -namespace mrc::internal::system { +namespace mrc::system { -class ISystem; class Partitions; class Topology; -class System final +class SystemDefinition final : public pipeline::ISystem { - System(std::shared_ptr options); - public: - static std::shared_ptr create(std::shared_ptr options); - static std::shared_ptr unwrap(const ISystem& system); + SystemDefinition(const Options& options); + SystemDefinition(std::shared_ptr options); + ~SystemDefinition() override; - ~System() = default; + static std::unique_ptr unwrap(std::unique_ptr object); - DELETE_COPYABILITY(System); - DELETE_MOVEABILITY(System); + DELETE_COPYABILITY(SystemDefinition); + DELETE_MOVEABILITY(SystemDefinition); - const Options& options() const; + const Options& options() const override; const Topology& topology() const; const Partitions& partitions() const; + void add_thread_initializer(std::function initializer_fn) override; + void add_thread_finalizer(std::function finalizer_fn) override; + + const std::vector>& thread_initializers() const; + const std::vector>& thread_finalizers() const; + CpuSet get_current_thread_affinity() const; private: - std::shared_ptr m_options; + std::unique_ptr m_options; std::shared_ptr m_topology; std::shared_ptr m_partitions; -}; -std::shared_ptr make_system(std::shared_ptr options); + std::vector> m_thread_initializers; + std::vector> m_thread_finalizers; +}; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/system_provider.cpp b/cpp/mrc/src/internal/system/system_provider.cpp index d6e2554be..4416cf4e4 100644 --- a/cpp/mrc/src/internal/system/system_provider.cpp +++ b/cpp/mrc/src/internal/system/system_provider.cpp @@ -21,16 +21,16 @@ #include -namespace mrc::internal::system { +namespace mrc::system { -SystemProvider::SystemProvider(std::shared_ptr system) : m_system(std::move(system)) +SystemProvider::SystemProvider(std::shared_ptr system) : m_system(std::move(system)) { CHECK(m_system); } -const System& mrc::internal::system::SystemProvider::system() const +const SystemDefinition& mrc::system::SystemProvider::system() const { DCHECK(m_system); return *m_system; } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/system_provider.hpp b/cpp/mrc/src/internal/system/system_provider.hpp index 42d01bb69..d90d09e2c 100644 --- a/cpp/mrc/src/internal/system/system_provider.hpp +++ b/cpp/mrc/src/internal/system/system_provider.hpp @@ -19,9 +19,9 @@ #include -namespace mrc::internal::system { +namespace mrc::system { -class System; +class SystemDefinition; /** * @brief SystemProvider is a base class designed provide access to the System object. @@ -36,13 +36,13 @@ class System; class SystemProvider { public: - SystemProvider(std::shared_ptr system); + SystemProvider(std::shared_ptr system); virtual ~SystemProvider() = default; - const System& system() const; + const SystemDefinition& system() const; private: - std::shared_ptr m_system; + std::shared_ptr m_system; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/thread.cpp b/cpp/mrc/src/internal/system/thread.cpp index 3bb5680be..413e86f6c 100644 --- a/cpp/mrc/src/internal/system/thread.cpp +++ b/cpp/mrc/src/internal/system/thread.cpp @@ -32,7 +32,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { Thread::Thread(std::shared_ptr resources, std::thread&& thread) : m_resources(std::move(resources)), @@ -158,4 +158,4 @@ void ThreadResources::finalize_thread(const CpuSet& cpu_affinity) const } } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/thread.hpp b/cpp/mrc/src/internal/system/thread.hpp index 1f439e589..aa8669da0 100644 --- a/cpp/mrc/src/internal/system/thread.hpp +++ b/cpp/mrc/src/internal/system/thread.hpp @@ -34,7 +34,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { class ThreadResources; @@ -106,4 +106,4 @@ Thread ThreadResources::make_thread(std::string desc, CpuSet cpu_affinity, Calla return {shared_from_this(), std::move(thread)}; } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/thread_pool.cpp b/cpp/mrc/src/internal/system/thread_pool.cpp index 6c37fbdfb..f3ff7814f 100644 --- a/cpp/mrc/src/internal/system/thread_pool.cpp +++ b/cpp/mrc/src/internal/system/thread_pool.cpp @@ -17,16 +17,16 @@ #include "internal/system/thread_pool.hpp" -#include "internal/system/resources.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/core/bitmap.hpp" #include #include -namespace mrc::internal::system { +namespace mrc::system { -ThreadPool::ThreadPool(const system::Resources& resources, CpuSet cpuset, std::size_t channel_size) : +ThreadPool::ThreadPool(const system::ThreadingResources& resources, CpuSet cpuset, std::size_t channel_size) : m_cpuset(std::move(cpuset)), m_channel(channel_size) { @@ -65,4 +65,4 @@ void ThreadPool::shutdown() m_channel.close(); } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/thread_pool.hpp b/cpp/mrc/src/internal/system/thread_pool.hpp index 3280a4eef..9c0b45745 100644 --- a/cpp/mrc/src/internal/system/thread_pool.hpp +++ b/cpp/mrc/src/internal/system/thread_pool.hpp @@ -17,8 +17,8 @@ #pragma once -#include "internal/system/resources.hpp" #include "internal/system/thread.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/core/bitmap.hpp" #include "mrc/exceptions/runtime_error.hpp" @@ -37,7 +37,7 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { /** * @brief Fiber-friendly ThreadPool @@ -60,7 +60,7 @@ namespace mrc::internal::system { class ThreadPool final { public: - ThreadPool(const system::Resources&, CpuSet cpuset, std::size_t channel_size = 128); + ThreadPool(const system::ThreadingResources&, CpuSet cpuset, std::size_t channel_size = 128); ~ThreadPool(); template @@ -93,4 +93,4 @@ class ThreadPool final std::vector m_threads; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/resources.cpp b/cpp/mrc/src/internal/system/threading_resources.cpp similarity index 62% rename from cpp/mrc/src/internal/system/resources.cpp rename to cpp/mrc/src/internal/system/threading_resources.cpp index 1250572eb..27001092a 100644 --- a/cpp/mrc/src/internal/system/resources.cpp +++ b/cpp/mrc/src/internal/system/threading_resources.cpp @@ -15,36 +15,45 @@ * limitations under the License. */ -#include "internal/system/resources.hpp" +#include "internal/system/threading_resources.hpp" #include "internal/system/fiber_manager.hpp" -#include "mrc/engine/system/iresources.hpp" - #include #include #include -namespace mrc::internal::system { +namespace mrc::system { -Resources::Resources(SystemProvider system) : +ThreadingResources::ThreadingResources(SystemProvider system) : SystemProvider(system), m_thread_resources(std::make_shared(*this)), m_fiber_manager(*this) -{} +{ + // Register any initializers and finalizers set on the system object + for (const auto& f : this->system().thread_initializers()) + { + this->register_thread_local_initializer(this->system().topology().cpu_set(), f); + } + + for (const auto& f : this->system().thread_finalizers()) + { + this->register_thread_local_finalizer(this->system().topology().cpu_set(), f); + } +} -FiberTaskQueue& Resources::get_task_queue(std::uint32_t cpu_id) const +FiberTaskQueue& ThreadingResources::get_task_queue(std::uint32_t cpu_id) const { return m_fiber_manager.task_queue(cpu_id); } -FiberPool Resources::make_fiber_pool(const CpuSet& cpu_set) const +FiberPool ThreadingResources::make_fiber_pool(const CpuSet& cpu_set) const { return m_fiber_manager.make_pool(cpu_set); } -void Resources::register_thread_local_initializer(const CpuSet& cpu_set, std::function initializer) +void ThreadingResources::register_thread_local_initializer(const CpuSet& cpu_set, std::function initializer) { CHECK(initializer); CHECK_GE(cpu_set.weight(), 0); @@ -59,7 +68,7 @@ void Resources::register_thread_local_initializer(const CpuSet& cpu_set, std::fu } } -void Resources::register_thread_local_finalizer(const CpuSet& cpu_set, std::function finalizer) +void ThreadingResources::register_thread_local_finalizer(const CpuSet& cpu_set, std::function finalizer) { CHECK(finalizer); CHECK_GE(cpu_set.weight(), 0); @@ -67,8 +76,4 @@ void Resources::register_thread_local_finalizer(const CpuSet& cpu_set, std::func m_thread_resources->register_finalizer(cpu_set, finalizer); } -std::unique_ptr Resources::unwrap(IResources& resources) -{ - return std::move(resources.m_impl); -} -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/resources.hpp b/cpp/mrc/src/internal/system/threading_resources.hpp similarity index 79% rename from cpp/mrc/src/internal/system/resources.hpp rename to cpp/mrc/src/internal/system/threading_resources.hpp index 5605d08ea..d92788cd9 100644 --- a/cpp/mrc/src/internal/system/resources.hpp +++ b/cpp/mrc/src/internal/system/threading_resources.hpp @@ -35,18 +35,13 @@ #include #include -namespace mrc::internal::system { +namespace mrc::system { class FiberTaskQueue; -class IResources; -class Resources final : public SystemProvider +class ThreadingResources final : public SystemProvider { public: - static std::unique_ptr unwrap(IResources& resources); - static std::unique_ptr create(const SystemProvider& system); - static std::unique_ptr create(std::shared_ptr system); - - Resources(SystemProvider system); + ThreadingResources(SystemProvider system); template [[nodiscard]] Thread make_thread(CpuSet cpu_affinity, CallableT&& callable) const; @@ -69,7 +64,7 @@ class Resources final : public SystemProvider }; template -void Resources::register_thread_local_resource(const CpuSet& cpu_set, std::shared_ptr resource) +void ThreadingResources::register_thread_local_resource(const CpuSet& cpu_set, std::shared_ptr resource) { CHECK(resource); CHECK(system().topology().contains(cpu_set)); @@ -81,17 +76,17 @@ void Resources::register_thread_local_resource(const CpuSet& cpu_set, std::share } template -Thread Resources::make_thread(CpuSet cpu_affinity, CallableT&& callable) const +Thread ThreadingResources::make_thread(CpuSet cpu_affinity, CallableT&& callable) const { CHECK(m_thread_resources); return m_thread_resources->make_thread("thread", std::move(cpu_affinity), std::move(callable)); } template -Thread Resources::make_thread(std::string desc, CpuSet cpu_affinity, CallableT&& callable) const +Thread ThreadingResources::make_thread(std::string desc, CpuSet cpu_affinity, CallableT&& callable) const { CHECK(m_thread_resources); return m_thread_resources->make_thread(std::move(desc), std::move(cpu_affinity), std::move(callable)); } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/topology.cpp b/cpp/mrc/src/internal/system/topology.cpp index 757513dac..b43008bde 100644 --- a/cpp/mrc/src/internal/system/topology.cpp +++ b/cpp/mrc/src/internal/system/topology.cpp @@ -43,7 +43,7 @@ // Topology -namespace mrc::internal::system { +namespace mrc::system { std::shared_ptr Topology::Create() { @@ -384,4 +384,4 @@ bool Topology::contains(const CpuSet& cpu_set) const { return bool(hwloc_bitmap_isincluded(&cpu_set.bitmap(), &this->cpu_set().bitmap())); } -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/system/topology.hpp b/cpp/mrc/src/internal/system/topology.hpp index 0092b9ed7..11dfd1295 100644 --- a/cpp/mrc/src/internal/system/topology.hpp +++ b/cpp/mrc/src/internal/system/topology.hpp @@ -43,7 +43,7 @@ class TopologyOptions; CHECK_NE(rc, -1); \ } -namespace mrc::internal::system { +namespace mrc::system { class Topology final { @@ -207,4 +207,4 @@ class Topology final std::map m_gpu_info; }; -} // namespace mrc::internal::system +} // namespace mrc::system diff --git a/cpp/mrc/src/internal/ucx/common.hpp b/cpp/mrc/src/internal/ucx/common.hpp index 65ba08020..737e05ebf 100644 --- a/cpp/mrc/src/internal/ucx/common.hpp +++ b/cpp/mrc/src/internal/ucx/common.hpp @@ -25,7 +25,7 @@ #include #include -namespace mrc::internal::ucx { +namespace mrc::ucx { using WorkerAddress = std::string; // NOLINT @@ -39,4 +39,4 @@ class Endpoint; class SendManager; class ReceiveManager; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/context.cpp b/cpp/mrc/src/internal/ucx/context.cpp index 26d393b66..69c323280 100644 --- a/cpp/mrc/src/internal/ucx/context.cpp +++ b/cpp/mrc/src/internal/ucx/context.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include // for ucs_status_string, UCS_OK @@ -28,7 +29,7 @@ #include // for runtime_error #include // for make_tuple, tuple -namespace mrc::internal::ucx { +namespace mrc::ucx { Context::Context() { @@ -124,4 +125,4 @@ void Context::unregister_memory(ucp_mem_h handle, void* rbuffer) } } -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/context.hpp b/cpp/mrc/src/internal/ucx/context.hpp index 54e630e08..90fbc0e30 100644 --- a/cpp/mrc/src/internal/ucx/context.hpp +++ b/cpp/mrc/src/internal/ucx/context.hpp @@ -24,7 +24,7 @@ #include // for size_t #include -namespace mrc::internal::ucx { +namespace mrc::ucx { class Context final : public Primitive { @@ -39,4 +39,4 @@ class Context final : public Primitive void unregister_memory(ucp_mem_h, void* rbuffer = nullptr); }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/endpoint.cpp b/cpp/mrc/src/internal/ucx/endpoint.cpp index 058f2a37a..acda3afed 100644 --- a/cpp/mrc/src/internal/ucx/endpoint.cpp +++ b/cpp/mrc/src/internal/ucx/endpoint.cpp @@ -24,7 +24,8 @@ #include "mrc/types.hpp" #include -#include // for ucp_ep_close_nb, ucp_ep_create, UCP_EP_... +#include // for ucp_ep_close_nb, ucp_ep_create, UCP_EP_... +#include #include // for ucp_ep_params_t, ucp_address_t, ucp_ep #include // for ucs_status_string, UCS_OK, UCS_PTR_STATUS @@ -33,7 +34,7 @@ #include // for logging #include -namespace mrc::internal::ucx { +namespace mrc::ucx { Endpoint::Endpoint(Handle local_worker, WorkerAddress remote_worker) : m_worker(std::move(local_worker)) { @@ -91,4 +92,4 @@ const RemoteRegistrationCache& Endpoint::registration_cache() const return *m_registration_cache; } -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/endpoint.hpp b/cpp/mrc/src/internal/ucx/endpoint.hpp index 2d785b643..389387ba8 100644 --- a/cpp/mrc/src/internal/ucx/endpoint.hpp +++ b/cpp/mrc/src/internal/ucx/endpoint.hpp @@ -26,7 +26,7 @@ #include -namespace mrc::internal::ucx { +namespace mrc::ucx { class RemoteRegistrationCache; class Worker; @@ -45,4 +45,4 @@ class Endpoint : public Primitive std::unique_ptr m_registration_cache; }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/forward.hpp b/cpp/mrc/src/internal/ucx/forward.hpp index 605096f13..4fe9ccb46 100644 --- a/cpp/mrc/src/internal/ucx/forward.hpp +++ b/cpp/mrc/src/internal/ucx/forward.hpp @@ -17,7 +17,7 @@ #pragma once -namespace mrc::internal::ucx { +namespace mrc::ucx { class Context; class Worker; @@ -25,4 +25,4 @@ class Endpoint; class MemoryBlock; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/memory_block.cpp b/cpp/mrc/src/internal/ucx/memory_block.cpp index 10f1aa3fd..f6d44538c 100644 --- a/cpp/mrc/src/internal/ucx/memory_block.cpp +++ b/cpp/mrc/src/internal/ucx/memory_block.cpp @@ -21,7 +21,7 @@ #include -namespace mrc::internal::ucx { +namespace mrc::ucx { MemoryBlock::MemoryBlock(const void* data, std::size_t bytes) : memory::MemoryBlock(data, bytes) {} @@ -80,4 +80,4 @@ std::string MemoryBlock::packed_remote_keys() const return keys; } -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/memory_block.hpp b/cpp/mrc/src/internal/ucx/memory_block.hpp index f505539c7..0d0e8670e 100644 --- a/cpp/mrc/src/internal/ucx/memory_block.hpp +++ b/cpp/mrc/src/internal/ucx/memory_block.hpp @@ -24,7 +24,7 @@ #include #include -namespace mrc::internal::ucx { +namespace mrc::ucx { /** * @brief Extends memory::MemoryBlock to add UCX memory registration information @@ -68,4 +68,4 @@ struct MemoryBlock : public memory::MemoryBlock std::size_t m_remote_handle_size{0}; }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/primitive.hpp b/cpp/mrc/src/internal/ucx/primitive.hpp index d8e2cf4fc..529e62607 100644 --- a/cpp/mrc/src/internal/ucx/primitive.hpp +++ b/cpp/mrc/src/internal/ucx/primitive.hpp @@ -19,7 +19,7 @@ #include "internal/ucx/common.hpp" -namespace mrc::internal::ucx { +namespace mrc::ucx { template class Primitive : public std::enable_shared_from_this> @@ -43,4 +43,4 @@ class Primitive : public std::enable_shared_from_this> T m_handle; }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/receive_manager.cpp b/cpp/mrc/src/internal/ucx/receive_manager.cpp index 189b58286..2796bf84e 100644 --- a/cpp/mrc/src/internal/ucx/receive_manager.cpp +++ b/cpp/mrc/src/internal/ucx/receive_manager.cpp @@ -32,7 +32,7 @@ #include // for uint32_t #include -namespace mrc::internal::ucx { +namespace mrc::ucx { TaggedReceiveManager::TaggedReceiveManager(Handle worker, ucp_tag_t tag, ucp_tag_t task_mask) : m_worker(std::move(worker)), @@ -113,4 +113,4 @@ void TaggedReceiveManager::progress_engine() } } -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/receive_manager.hpp b/cpp/mrc/src/internal/ucx/receive_manager.hpp index f62ccb34a..0e81f766a 100644 --- a/cpp/mrc/src/internal/ucx/receive_manager.hpp +++ b/cpp/mrc/src/internal/ucx/receive_manager.hpp @@ -25,7 +25,7 @@ #include // for enable_shared_from_this -namespace mrc::internal::ucx { +namespace mrc::ucx { class Worker; class TaggedReceiveManager : public std::enable_shared_from_this @@ -63,4 +63,4 @@ class TaggedReceiveManager : public std::enable_shared_from_this #include -namespace mrc::internal::ucx { +namespace mrc::ucx { class RegistrationCallbackBuilder final : public memory::CallbackBuilder { @@ -45,4 +45,4 @@ class RegistrationCallbackBuilder final : public memory::CallbackBuilder using CallbackBuilder::register_callbacks; }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/registration_cache.hpp b/cpp/mrc/src/internal/ucx/registration_cache.hpp index 80ad5b079..29393cf40 100644 --- a/cpp/mrc/src/internal/ucx/registration_cache.hpp +++ b/cpp/mrc/src/internal/ucx/registration_cache.hpp @@ -27,7 +27,7 @@ #include #include -namespace mrc::internal::ucx { +namespace mrc::ucx { /** * @brief UCX Registration Cache @@ -106,4 +106,4 @@ class RegistrationCache final memory::BlockManager m_blocks; }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/registration_resource.hpp b/cpp/mrc/src/internal/ucx/registration_resource.hpp index 230a7a1b3..a0b04ead7 100644 --- a/cpp/mrc/src/internal/ucx/registration_resource.hpp +++ b/cpp/mrc/src/internal/ucx/registration_resource.hpp @@ -25,7 +25,7 @@ #include -namespace mrc::internal::ucx { +namespace mrc::ucx { /** * @brief Memory Resource adaptor to provide UCX registration to allocated blocks. @@ -72,4 +72,4 @@ class RegistrationResource : public mrc::memory::adaptor const int m_cuda_device_id; }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/remote_registration_cache.hpp b/cpp/mrc/src/internal/ucx/remote_registration_cache.hpp index 83857a0dd..771e3f065 100644 --- a/cpp/mrc/src/internal/ucx/remote_registration_cache.hpp +++ b/cpp/mrc/src/internal/ucx/remote_registration_cache.hpp @@ -29,7 +29,7 @@ #include #include -namespace mrc::internal::ucx { +namespace mrc::ucx { /** * @brief UCX Registration Cache @@ -143,4 +143,4 @@ class RemoteRegistrationCache final memory::BlockManager m_blocks; }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/ucx.hpp b/cpp/mrc/src/internal/ucx/ucx.hpp index 6b97b520a..88aa3e877 100644 --- a/cpp/mrc/src/internal/ucx/ucx.hpp +++ b/cpp/mrc/src/internal/ucx/ucx.hpp @@ -23,4 +23,4 @@ #include "internal/ucx/worker.hpp" // IWYU pragma: end_exports -namespace mrc::internal::ucx {} // namespace mrc::internal::ucx +namespace mrc::ucx {} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/ucx_fwd.hpp b/cpp/mrc/src/internal/ucx/ucx_fwd.hpp index 2b1533e5f..48c70f0fa 100644 --- a/cpp/mrc/src/internal/ucx/ucx_fwd.hpp +++ b/cpp/mrc/src/internal/ucx/ucx_fwd.hpp @@ -17,10 +17,10 @@ #pragma once -namespace mrc::internal::ucx { +namespace mrc::ucx { class Context; class Worker; class Endpoint; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/resources.cpp b/cpp/mrc/src/internal/ucx/ucx_resources.cpp similarity index 84% rename from cpp/mrc/src/internal/ucx/resources.cpp rename to cpp/mrc/src/internal/ucx/ucx_resources.cpp index 7dbc8dac3..458dd9814 100644 --- a/cpp/mrc/src/internal/ucx/resources.cpp +++ b/cpp/mrc/src/internal/ucx/ucx_resources.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "internal/ucx/resources.hpp" +#include "internal/ucx/ucx_resources.hpp" #include "internal/resources/partition_resources_base.hpp" #include "internal/system/device_partition.hpp" @@ -40,9 +40,9 @@ namespace mrc::core { class FiberTaskQueue; } // namespace mrc::core -namespace mrc::internal::ucx { +namespace mrc::ucx { -Resources::Resources(resources::PartitionResourceBase& base, system::FiberTaskQueue& network_task_queue) : +UcxResources::UcxResources(resources::PartitionResourceBase& base, system::FiberTaskQueue& network_task_queue) : resources::PartitionResourceBase(base), m_network_task_queue(network_task_queue) { @@ -76,34 +76,34 @@ Resources::Resources(resources::PartitionResourceBase& base, system::FiberTaskQu .get(); } -void Resources::add_registration_cache_to_builder(RegistrationCallbackBuilder& builder) +void UcxResources::add_registration_cache_to_builder(RegistrationCallbackBuilder& builder) { builder.add_registration_cache(m_registration_cache); } -mrc::core::FiberTaskQueue& Resources::network_task_queue() +mrc::core::FiberTaskQueue& UcxResources::network_task_queue() { return m_network_task_queue; } -RegistrationCache& Resources::registration_cache() +RegistrationCache& UcxResources::registration_cache() { CHECK(m_registration_cache); return *m_registration_cache; } -Worker& Resources::worker() +Worker& UcxResources::worker() { CHECK(m_worker); return *m_worker; } -std::shared_ptr Resources::make_ep(const std::string& worker_address) const +std::shared_ptr UcxResources::make_ep(const std::string& worker_address) const { return std::make_shared(m_worker, worker_address); } -mrc::runnable::LaunchOptions Resources::launch_options(std::uint64_t concurrency) +mrc::runnable::LaunchOptions UcxResources::launch_options(std::uint64_t concurrency) { mrc::runnable::LaunchOptions launch_options; launch_options.engine_factory_name = "mrc_network"; @@ -111,4 +111,4 @@ mrc::runnable::LaunchOptions Resources::launch_options(std::uint64_t concurrency launch_options.pe_count = 1; return launch_options; } -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/resources.hpp b/cpp/mrc/src/internal/ucx/ucx_resources.hpp similarity index 87% rename from cpp/mrc/src/internal/ucx/resources.hpp rename to cpp/mrc/src/internal/ucx/ucx_resources.hpp index 91f939111..122e690bd 100644 --- a/cpp/mrc/src/internal/ucx/resources.hpp +++ b/cpp/mrc/src/internal/ucx/ucx_resources.hpp @@ -30,15 +30,15 @@ namespace mrc::core { class FiberTaskQueue; } // namespace mrc::core -namespace mrc::internal::system { +namespace mrc::system { class FiberTaskQueue; -} // namespace mrc::internal::system +} // namespace mrc::system -namespace mrc::internal::network { -class Resources; +namespace mrc::network { +class NetworkResources; } -namespace mrc::internal::ucx { +namespace mrc::ucx { class Context; class Endpoint; class RegistrationCache; @@ -48,10 +48,10 @@ class Worker; /** * @brief UCX Resources - if networking is enabled, there should be 1 UCX Resource per "flattened" partition */ -class Resources final : public resources::PartitionResourceBase +class UcxResources final : public resources::PartitionResourceBase { public: - Resources(resources::PartitionResourceBase& base, system::FiberTaskQueue& network_task_queue); + UcxResources(resources::PartitionResourceBase& base, system::FiberTaskQueue& network_task_queue); using resources::PartitionResourceBase::partition; @@ -87,7 +87,7 @@ class Resources final : public resources::PartitionResourceBase std::shared_ptr m_registration_cache; // enable direct access to context and workers - friend network::Resources; + friend network::NetworkResources; }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/utils.hpp b/cpp/mrc/src/internal/ucx/utils.hpp index 411b0c243..af14540c1 100644 --- a/cpp/mrc/src/internal/ucx/utils.hpp +++ b/cpp/mrc/src/internal/ucx/utils.hpp @@ -19,4 +19,4 @@ #include "internal/ucx/common.hpp" -namespace mrc::internal::ucx {} // namespace mrc::internal::ucx +namespace mrc::ucx {} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/worker.cpp b/cpp/mrc/src/internal/ucx/worker.cpp index 824df8309..1bbef1c2f 100644 --- a/cpp/mrc/src/internal/ucx/worker.cpp +++ b/cpp/mrc/src/internal/ucx/worker.cpp @@ -24,7 +24,8 @@ #include "mrc/types.hpp" #include -#include // for ucp_* +#include // for ucp_* +#include #include // for ucp_worker_h #include // for ucs_status_string, UCS_OK #include // for UCS_THREAD_MODE_MULTI @@ -36,7 +37,7 @@ #include #include -namespace mrc::internal::ucx { +namespace mrc::ucx { Worker::Worker(Handle context) : m_context(std::move(context)), m_address_pointer(nullptr), m_address_length(0) { @@ -114,4 +115,4 @@ Context& Worker::context() return *m_context; } -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/ucx/worker.hpp b/cpp/mrc/src/internal/ucx/worker.hpp index dab1a66ff..4306807e1 100644 --- a/cpp/mrc/src/internal/ucx/worker.hpp +++ b/cpp/mrc/src/internal/ucx/worker.hpp @@ -27,7 +27,7 @@ #include // for size_t #include -namespace mrc::internal::ucx { +namespace mrc::ucx { class Context; class Endpoint; @@ -53,4 +53,4 @@ class Worker : public Primitive std::size_t m_address_length; }; -} // namespace mrc::internal::ucx +} // namespace mrc::ucx diff --git a/cpp/mrc/src/internal/utils/collision_detector.cpp b/cpp/mrc/src/internal/utils/collision_detector.cpp index 6fbb6fc96..6e6d46a4d 100644 --- a/cpp/mrc/src/internal/utils/collision_detector.cpp +++ b/cpp/mrc/src/internal/utils/collision_detector.cpp @@ -26,7 +26,7 @@ #include #include -namespace mrc::internal::utils { +namespace mrc::utils { std::uint16_t CollisionDetector::register_name(const std::string& name) { @@ -82,4 +82,4 @@ const std::string& CollisionDetector::name(const std::uint16_t& hash) const return search->second; } -} // namespace mrc::internal::utils +} // namespace mrc::utils diff --git a/cpp/mrc/src/internal/utils/collision_detector.hpp b/cpp/mrc/src/internal/utils/collision_detector.hpp index 992605bed..bf6c7a6ba 100644 --- a/cpp/mrc/src/internal/utils/collision_detector.hpp +++ b/cpp/mrc/src/internal/utils/collision_detector.hpp @@ -21,7 +21,7 @@ #include #include -namespace mrc::internal::utils { +namespace mrc::utils { /** * @brief Creates 16-bit hash for a given string. @@ -60,4 +60,4 @@ class CollisionDetector std::map m_hashes; }; -} // namespace mrc::internal::utils +} // namespace mrc::utils diff --git a/cpp/mrc/src/internal/utils/exception_guard.cpp b/cpp/mrc/src/internal/utils/exception_guard.cpp index 930f5d19a..4ab6b21d7 100644 --- a/cpp/mrc/src/internal/utils/exception_guard.cpp +++ b/cpp/mrc/src/internal/utils/exception_guard.cpp @@ -19,7 +19,7 @@ #include -namespace mrc::internal::utils { +namespace mrc::utils { ExceptionGuard::ExceptionGuard(std::function lambda) { @@ -41,4 +41,4 @@ ExceptionGuard::~ExceptionGuard() } } -} // namespace mrc::internal::utils +} // namespace mrc::utils diff --git a/cpp/mrc/src/internal/utils/exception_guard.hpp b/cpp/mrc/src/internal/utils/exception_guard.hpp index 6aa48d948..03d65315a 100644 --- a/cpp/mrc/src/internal/utils/exception_guard.hpp +++ b/cpp/mrc/src/internal/utils/exception_guard.hpp @@ -22,7 +22,7 @@ #include #include -namespace mrc::internal::utils { +namespace mrc::utils { class ExceptionGuard final { @@ -37,4 +37,4 @@ class ExceptionGuard final std::exception_ptr m_ptr{nullptr}; }; -} // namespace mrc::internal::utils +} // namespace mrc::utils diff --git a/cpp/mrc/src/public/core/executor.cpp b/cpp/mrc/src/public/core/executor.cpp deleted file mode 100644 index 5ebb55a5c..000000000 --- a/cpp/mrc/src/public/core/executor.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#include "mrc/core/executor.hpp" - -#include "mrc/engine/executor/iexecutor.hpp" -#include "mrc/engine/system/iresources.hpp" -#include "mrc/options/options.hpp" - -#include // for move - -namespace mrc { - -Executor::Executor() : internal::executor::IExecutor(std::make_shared()) {} -Executor::Executor(std::shared_ptr options) : internal::executor::IExecutor(std::move(options)) {} -Executor::Executor(std::unique_ptr resources) : - internal::executor::IExecutor(std::move(resources)) -{} - -} // namespace mrc diff --git a/cpp/mrc/src/public/manifold/manifold.cpp b/cpp/mrc/src/public/manifold/manifold.cpp index 35e59f940..a1a3cca25 100644 --- a/cpp/mrc/src/public/manifold/manifold.cpp +++ b/cpp/mrc/src/public/manifold/manifold.cpp @@ -28,17 +28,19 @@ namespace mrc::manifold { -Manifold::Manifold(PortName port_name, pipeline::Resources& resources) : +Manifold::Manifold(PortName port_name, runnable::IRunnableResources& resources) : m_port_name(std::move(port_name)), m_resources(resources) {} +Manifold::~Manifold() = default; + const PortName& Manifold::port_name() const { return m_port_name; } -pipeline::Resources& Manifold::resources() +runnable::IRunnableResources& Manifold::resources() { return m_resources; } diff --git a/cpp/mrc/src/public/modules/plugins.cpp b/cpp/mrc/src/public/modules/plugins.cpp index 4a7dcb8f9..0f93f435f 100644 --- a/cpp/mrc/src/public/modules/plugins.cpp +++ b/cpp/mrc/src/public/modules/plugins.cpp @@ -17,13 +17,12 @@ #include "mrc/modules/plugins.hpp" -#include -#include -#include #include #include +#include #include +#include #include #include #include @@ -31,7 +30,7 @@ #include #include -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace mrc::modules { diff --git a/cpp/mrc/src/public/modules/sample_modules.cpp b/cpp/mrc/src/public/modules/sample_modules.cpp index aef19879d..fe850615c 100644 --- a/cpp/mrc/src/public/modules/sample_modules.cpp +++ b/cpp/mrc/src/public/modules/sample_modules.cpp @@ -39,7 +39,7 @@ SimpleModule::SimpleModule(std::string module_name, nlohmann::json config) : SegmentModule(std::move(module_name), std::move(config)) {} -void SimpleModule::initialize(segment::Builder& builder) +void SimpleModule::initialize(segment::IBuilder& builder) { if (config().contains("simple_key_1")) { @@ -109,7 +109,7 @@ ConfigurableModule::ConfigurableModule(std::string module_name, nlohmann::json c SegmentModule(std::move(module_name), std::move(config)) {} -void ConfigurableModule::initialize(segment::Builder& builder) +void ConfigurableModule::initialize(segment::IBuilder& builder) { if (config().contains("config_key_1")) { @@ -154,7 +154,7 @@ SourceModule::SourceModule(std::string module_name, nlohmann::json config) : SegmentModule(std::move(module_name), std::move(config)) {} -void SourceModule::initialize(segment::Builder& builder) +void SourceModule::initialize(segment::IBuilder& builder) { unsigned int count{1}; @@ -189,7 +189,7 @@ SinkModule::SinkModule(std::string module_name, nlohmann::json config) : SegmentModule(std::move(module_name), std::move(config)) {} -void SinkModule::initialize(segment::Builder& builder) +void SinkModule::initialize(segment::IBuilder& builder) { auto sink = builder.make_sink("sink", [this](bool input) { m_packet_count++; @@ -210,7 +210,7 @@ NestedModule::NestedModule(std::string module_name, nlohmann::json config) : SegmentModule(std::move(module_name), std::move(config)) {} -void NestedModule::initialize(segment::Builder& builder) +void NestedModule::initialize(segment::IBuilder& builder) { auto configurable_mod = builder.make_module("NestedModule_submod2"); diff --git a/cpp/mrc/src/public/modules/segment_modules.cpp b/cpp/mrc/src/public/modules/segment_modules.cpp index b1d8ce19a..fb37d52eb 100644 --- a/cpp/mrc/src/public/modules/segment_modules.cpp +++ b/cpp/mrc/src/public/modules/segment_modules.cpp @@ -147,7 +147,7 @@ const std::string& SegmentModule::name() const return m_module_instance_name; } -void SegmentModule::operator()(segment::Builder& builder) +void SegmentModule::operator()(segment::IBuilder& builder) { this->initialize(builder); } diff --git a/cpp/mrc/src/public/options/options.cpp b/cpp/mrc/src/public/options/options.cpp index a1f25d234..6a74eca28 100644 --- a/cpp/mrc/src/public/options/options.cpp +++ b/cpp/mrc/src/public/options/options.cpp @@ -39,6 +39,42 @@ Options::Options() : m_topology(std::make_unique()) {} +Options::Options(const Options& other) : + m_engine_groups(std::make_unique(*other.m_engine_groups)), + m_fiber_pool(std::make_unique(*other.m_fiber_pool)), + m_placement(std::make_unique(*other.m_placement)), + m_resources(std::make_unique(*other.m_resources)), + m_services(std::make_unique(*other.m_services)), + m_topology(std::make_unique(*other.m_topology)), + m_architect_url(other.m_architect_url), + m_enable_server(other.m_enable_server), + m_server_port(other.m_server_port), + m_config_request(other.m_config_request) +{} + +Options& Options::operator=(const Options& other) +{ + // protect against invalid self-assignment + if (this != &other) + { + // Child objects + *m_engine_groups = *other.m_engine_groups; + *m_fiber_pool = *other.m_fiber_pool; + *m_placement = *other.m_placement; + *m_resources = *other.m_resources; + *m_services = *other.m_services; + *m_topology = *other.m_topology; + + // Values + m_architect_url = other.m_architect_url; + m_enable_server = other.m_enable_server; + m_server_port = other.m_server_port; + m_config_request = other.m_config_request; + } + + return *this; +} + TopologyOptions& Options::topology() { CHECK(m_topology); diff --git a/cpp/mrc/src/public/pipeline/executor.cpp b/cpp/mrc/src/public/pipeline/executor.cpp new file mode 100644 index 000000000..40ae80a26 --- /dev/null +++ b/cpp/mrc/src/public/pipeline/executor.cpp @@ -0,0 +1,74 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2023, 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. + */ + +#include "mrc/pipeline/executor.hpp" + +#include "internal/executor/executor_definition.hpp" +#include "internal/system/system.hpp" + +#include "mrc/options/options.hpp" +#include "mrc/pipeline/system.hpp" + +#include +#include + +namespace mrc { + +Executor::Executor() : m_impl(make_executor(std::make_shared())) {} + +Executor::Executor(std::shared_ptr options) : m_impl(make_executor(options)) {} + +Executor::~Executor() = default; + +void Executor::register_pipeline(std::shared_ptr pipeline) +{ + m_impl->register_pipeline(std::move(pipeline)); +} + +void Executor::start() +{ + m_impl->start(); +} + +void Executor::stop() +{ + m_impl->stop(); +} + +void Executor::join() +{ + m_impl->join(); +} + +std::unique_ptr make_executor(std::shared_ptr options) +{ + // Convert options to a system object first + auto system = mrc::make_system(std::move(options)); + + auto full_system = system::SystemDefinition::unwrap(std::move(system)); + + return std::make_unique(std::move(full_system)); +} + +std::unique_ptr make_executor(std::unique_ptr system) +{ + auto full_system = system::SystemDefinition::unwrap(std::move(system)); + + return std::make_unique(std::move(full_system)); +} + +} // namespace mrc diff --git a/cpp/mrc/src/public/pipeline/pipeline.cpp b/cpp/mrc/src/public/pipeline/pipeline.cpp index e49b05288..465871084 100644 --- a/cpp/mrc/src/public/pipeline/pipeline.cpp +++ b/cpp/mrc/src/public/pipeline/pipeline.cpp @@ -17,61 +17,15 @@ #include "mrc/pipeline/pipeline.hpp" -#include "mrc/segment/definition.hpp" -#include "mrc/segment/egress_ports.hpp" -#include "mrc/segment/ingress_ports.hpp" +#include "internal/pipeline/pipeline_definition.hpp" -namespace mrc::pipeline { +#include -std::unique_ptr Pipeline::create() -{ - return std::unique_ptr(new Pipeline()); -} - -void Pipeline::register_segment(std::shared_ptr segment) -{ - base_t::register_segment(std::move(segment)); -} - -std::shared_ptr Pipeline::make_segment(const std::string& segment_name, - segment::segment_initializer_fn_t segment_initializer) -{ - auto segdef = segment::Definition::create(segment_name, segment_initializer); - this->register_segment(segdef); - return segdef; -}; - -std::shared_ptr Pipeline::make_segment(const std::string& segment_name, - segment::IngressPortsBase ingress_ports, - segment::EgressPortsBase egress_ports, - segment::segment_initializer_fn_t segment_initializer) -{ - auto segdef = segment::Definition::create(segment_name, ingress_ports, egress_ports, segment_initializer); - this->register_segment(segdef); - return segdef; -}; - -std::shared_ptr Pipeline::make_segment(const std::string& segment_name, - segment::IngressPortsBase ingress_ports, - segment::segment_initializer_fn_t segment_initializer) -{ - auto segdef = segment::Definition::create(segment_name, ingress_ports, segment_initializer); - this->register_segment(segdef); - return segdef; -}; - -std::shared_ptr Pipeline::make_segment(const std::string& segment_name, - segment::EgressPortsBase egress_ports, - segment::segment_initializer_fn_t segment_initializer) -{ - auto segdef = segment::Definition::create(segment_name, egress_ports, segment_initializer); - this->register_segment(segdef); - return segdef; -}; +namespace mrc { -std::unique_ptr make_pipeline() +std::unique_ptr make_pipeline() { - return Pipeline::create(); + return std::make_unique(); } -} // namespace mrc::pipeline +} // namespace mrc diff --git a/cpp/mrc/src/public/pipeline/segment.cpp b/cpp/mrc/src/public/pipeline/segment.cpp new file mode 100644 index 000000000..18ecfe98a --- /dev/null +++ b/cpp/mrc/src/public/pipeline/segment.cpp @@ -0,0 +1,88 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. + */ + +#include "mrc/pipeline/segment.hpp" + +#include "internal/segment/segment_definition.hpp" + +#include "mrc/segment/egress_ports.hpp" +#include "mrc/segment/ingress_ports.hpp" + +#include +#include + +namespace mrc { + +std::unique_ptr Segment::create(std::string name, + segment::IngressPortsBase ingress_ports, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t initializer) +{ + return std::make_unique(std::move(name), + std::move(ingress_ports), + std::move(egress_ports), + std::move(initializer)); +} + +std::unique_ptr Segment::create(std::string name, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t initializer) +{ + return Segment::create(std::move(name), {}, std::move(egress_ports), std::move(initializer)); +} + +std::unique_ptr Segment::create(std::string name, + segment::IngressPortsBase ingress_ports, + segment::segment_initializer_fn_t initializer) +{ + return Segment::create(std::move(name), std::move(ingress_ports), {}, std::move(initializer)); +} + +std::unique_ptr Segment::create(std::string name, + segment::segment_initializer_fn_t initializer) +{ + return Segment::create(std::move(name), {}, {}, std::move(initializer)); +} + +std::unique_ptr make_segment(std::string name, + segment::IngressPortsBase ingress_ports, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t initializer) +{ + return Segment::create(std::move(name), std::move(ingress_ports), std::move(egress_ports), std::move(initializer)); +} + +std::unique_ptr make_segment(std::string name, + segment::EgressPortsBase egress_ports, + segment::segment_initializer_fn_t initializer) +{ + return Segment::create(std::move(name), {}, std::move(egress_ports), std::move(initializer)); +} + +std::unique_ptr make_segment(std::string name, + segment::IngressPortsBase ingress_ports, + segment::segment_initializer_fn_t initializer) +{ + return Segment::create(std::move(name), std::move(ingress_ports), {}, std::move(initializer)); +} + +std::unique_ptr make_segment(std::string name, segment::segment_initializer_fn_t initializer) +{ + return Segment::create(std::move(name), {}, {}, std::move(initializer)); +} + +} // namespace mrc diff --git a/cpp/mrc/src/internal/system/isystem.cpp b/cpp/mrc/src/public/pipeline/system.cpp similarity index 62% rename from cpp/mrc/src/internal/system/isystem.cpp rename to cpp/mrc/src/public/pipeline/system.cpp index e231d5a55..151f4e2a8 100644 --- a/cpp/mrc/src/internal/system/isystem.cpp +++ b/cpp/mrc/src/public/pipeline/system.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +15,25 @@ * limitations under the License. */ -#include "mrc/engine/system/isystem.hpp" +#include "mrc/pipeline/system.hpp" #include "internal/system/system.hpp" +#include "mrc/options/options.hpp" + +#include #include -namespace mrc::internal::system { +namespace mrc { + +std::unique_ptr make_system(std::shared_ptr options) +{ + if (!options) + { + options = std::make_shared(); + } -ISystem::ISystem(std::shared_ptr options) : m_impl(make_system(std::move(options))) {} -ISystem::~ISystem() = default; + return std::make_unique(std::move(options)); +} -} // namespace mrc::internal::system +} // namespace mrc diff --git a/cpp/mrc/src/public/runnable/launcher.cpp b/cpp/mrc/src/public/runnable/launcher.cpp index 6ab69c1e3..0f8ac43ba 100644 --- a/cpp/mrc/src/public/runnable/launcher.cpp +++ b/cpp/mrc/src/public/runnable/launcher.cpp @@ -27,7 +27,7 @@ namespace mrc::runnable { Launcher::Launcher(std::unique_ptr runner, std::vector>&& contexts, - std::shared_ptr engines) : + std::shared_ptr engines) : m_runner(std::move(runner)), m_contexts(std::move(contexts)), m_engines(std::move(engines)) diff --git a/cpp/mrc/src/public/runnable/runner.cpp b/cpp/mrc/src/public/runnable/runner.cpp index 3500b201f..5545fa628 100644 --- a/cpp/mrc/src/public/runnable/runner.cpp +++ b/cpp/mrc/src/public/runnable/runner.cpp @@ -86,7 +86,7 @@ Runner::~Runner() } } -void Runner::enqueue(std::shared_ptr launcher, std::vector>&& contexts) +void Runner::enqueue(std::shared_ptr launcher, std::vector>&& contexts) { DCHECK(launcher); DCHECK_EQ(launcher->size(), contexts.size()); diff --git a/cpp/mrc/src/public/segment/builder.cpp b/cpp/mrc/src/public/segment/builder.cpp deleted file mode 100644 index f8a063e20..000000000 --- a/cpp/mrc/src/public/segment/builder.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2022, 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. - */ - -#include "mrc/segment/builder.hpp" - -#include "mrc/modules/module_registry.hpp" -#include "mrc/modules/properties/persistent.hpp" // IWYU pragma: keep -#include "mrc/modules/segment_modules.hpp" -#include "mrc/node/port_registry.hpp" - -#include - -#include -#include - -namespace { - -std::string accum_merge(std::string lhs, std::string rhs) -{ - if (lhs.empty()) - { - return std::move(rhs); - } - - return std::move(lhs) + "/" + std::move(rhs); -} - -} // namespace - -namespace mrc::segment { - -void Builder::init_module(std::shared_ptr smodule) -{ - ns_push(smodule); - VLOG(2) << "Initializing module: " << m_namespace_prefix; - smodule->m_module_instance_registered_namespace = m_namespace_prefix; - smodule->initialize(*this); - - // TODO(Devin): Maybe a better way to do this with compile time type ledger. - if (std::dynamic_pointer_cast(smodule) != nullptr) - { - VLOG(2) << "Registering persistent module -> '" << m_namespace_prefix << "'"; - m_backend.add_module(m_namespace_prefix, smodule); - } - ns_pop(); -} - -std::shared_ptr Builder::get_ingress(std::string name, std::type_index type_index) -{ - auto base = m_backend.get_ingress_base(name); - if (!base) - { - throw exceptions::MrcRuntimeError("Egress port name not found: " + name); - } - - auto port_util = node::PortRegistry::find_port_util(type_index); - auto port = port_util->try_cast_ingress_base_to_object(base); - if (port == nullptr) - { - throw exceptions::MrcRuntimeError("Egress port type mismatch: " + name); - } - - return port; -} - -std::shared_ptr Builder::get_egress(std::string name, std::type_index type_index) -{ - auto base = m_backend.get_egress_base(name); - if (!base) - { - throw exceptions::MrcRuntimeError("Egress port name not found: " + name); - } - - auto port_util = node::PortRegistry::find_port_util(type_index); - - auto port = port_util->try_cast_egress_base_to_object(base); - if (port == nullptr) - { - throw exceptions::MrcRuntimeError("Egress port type mismatch: " + name); - } - - return port; -} - -std::shared_ptr Builder::load_module_from_registry(const std::string& module_id, - const std::string& registry_namespace, - std::string module_name, - nlohmann::json config) -{ - auto fn_module_constructor = mrc::modules::ModuleRegistry::get_module_constructor(module_id, registry_namespace); - auto smodule = fn_module_constructor(std::move(module_name), std::move(config)); - - init_module(smodule); - - return smodule; -} - -/** private implementations **/ - -void Builder::ns_push(sp_segment_module_t smodule) -{ - m_module_stack.push_back(smodule); - m_namespace_stack.push_back(smodule->component_prefix()); - m_namespace_prefix = - std::accumulate(m_namespace_stack.begin(), m_namespace_stack.end(), std::string(""), ::accum_merge); -} - -void Builder::ns_pop() -{ - m_module_stack.pop_back(); - m_namespace_stack.pop_back(); - m_namespace_prefix = - std::accumulate(m_namespace_stack.begin(), m_namespace_stack.end(), std::string(""), ::accum_merge); -} - -void Builder::register_module_input(std::string input_name, std::shared_ptr object) -{ - if (m_module_stack.empty()) - { - std::stringstream sstream; - - sstream << "Failed to register module input '" << input_name << "' -> no module context exists"; - VLOG(2) << sstream.str(); - - throw std::invalid_argument(sstream.str()); - } - - auto current_module = m_module_stack.back(); - current_module->register_input_port(std::move(input_name), object); -} - -[[maybe_unused]] void Builder::register_module_output(std::string output_name, - std::shared_ptr object) -{ - if (m_module_stack.empty()) - { - std::stringstream sstream; - - sstream << "Failed to register module output'" << output_name << "' -> no module context exists"; - VLOG(2) << sstream.str(); - - throw std::invalid_argument(sstream.str()); - } - - auto current_module = m_module_stack.back(); - - current_module->register_output_port(std::move(output_name), object); -} - -[[maybe_unused]] nlohmann::json Builder::get_current_module_config() -{ - if (m_module_stack.empty()) - { - std::stringstream sstream; - - sstream << "Failed to acquire module configuration -> no module context exists"; - VLOG(2) << sstream.str(); - - throw std::invalid_argument(sstream.str()); - } - - auto current_module = m_module_stack.back(); - - return current_module->config(); -} - -} // namespace mrc::segment diff --git a/cpp/mrc/src/public/segment/definition.cpp b/cpp/mrc/src/public/segment/definition.cpp deleted file mode 100644 index 127faf408..000000000 --- a/cpp/mrc/src/public/segment/definition.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#include "mrc/segment/definition.hpp" - -#include "mrc/engine/segment/idefinition.hpp" // for IDefinition -#include "mrc/segment/builder.hpp" // for Builder -#include "mrc/segment/egress_ports.hpp" // for EgressPortsBase -#include "mrc/segment/ingress_ports.hpp" // for IngressPortsBase - -#include // for move -namespace mrc::internal::segment { -class IBuilder; -} - -namespace mrc::segment { - -std::shared_ptr Definition::create(std::string name, - std::map ingress_initializers, - std::map egress_initializers, - segment_initializer_fn_t initializer) -{ - return std::shared_ptr(new Definition(std::move(name), - std::move(ingress_initializers), - std::move(egress_initializers), - [initializer](internal::segment::IBuilder& backend) { - Builder builder(backend); - initializer(builder); - })); -} - -Definition::Definition(std::string name, - std::map ingress_ports, - std::map egress_ports, - backend_initializer_fn_t backend_initializer) : - internal::segment::IDefinition(std::move(name), - std::move(ingress_ports), - std::move(egress_ports), - std::move(backend_initializer)) -{} - -std::shared_ptr Definition::create(std::string name, - IngressPortsBase ingress_ports, - EgressPortsBase egress_ports, - segment_initializer_fn_t initializer) -{ - return Definition::create(std::move(name), - ingress_ports.m_initializers, - egress_ports.m_initializers, - std::move(initializer)); -} - -std::shared_ptr Definition::create(std::string name, - EgressPortsBase egress_ports, - segment_initializer_fn_t initializer) -{ - return Definition::create(std::move(name), {}, egress_ports.m_initializers, std::move(initializer)); -} - -std::shared_ptr Definition::create(std::string name, - IngressPortsBase ingress_ports, - segment_initializer_fn_t initializer) -{ - return Definition::create(std::move(name), ingress_ports.m_initializers, {}, std::move(initializer)); -} - -std::shared_ptr Definition::create(std::string name, segment_initializer_fn_t initializer) -{ - return Definition::create(std::move(name), - std::map{}, - std::map{}, - std::move(initializer)); -} - -} // namespace mrc::segment diff --git a/cpp/mrc/src/tests/common.cpp b/cpp/mrc/src/tests/common.cpp index 5b06eaeac..6e4d915bb 100644 --- a/cpp/mrc/src/tests/common.cpp +++ b/cpp/mrc/src/tests/common.cpp @@ -18,18 +18,37 @@ #include "common.hpp" #include "internal/system/system.hpp" +#include "internal/system/system_provider.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/options/options.hpp" +#include #include -std::shared_ptr make_system(std::function updater) +namespace mrc::tests { + +std::unique_ptr make_system(std::function updater) { - auto options = std::make_shared(); + auto options = std::make_shared(); if (updater) { updater(*options); } - return mrc::internal::system::make_system(std::move(options)); + return std::make_unique(std::move(options)); +} + +std::unique_ptr make_threading_resources(std::function updater) +{ + auto system = make_system(updater); + + return make_threading_resources(std::move(system)); } + +std::unique_ptr make_threading_resources(std::unique_ptr system) +{ + return std::make_unique(system::SystemProvider(std::move(system))); +} + +} // namespace mrc::tests diff --git a/cpp/mrc/src/tests/common.hpp b/cpp/mrc/src/tests/common.hpp index 4ded50429..3c0825e6d 100644 --- a/cpp/mrc/src/tests/common.hpp +++ b/cpp/mrc/src/tests/common.hpp @@ -30,8 +30,16 @@ namespace mrc { class Options; } // namespace mrc -namespace mrc::internal::system { -class System; -} // namespace mrc::internal::system -std::shared_ptr make_system(std::function updater = nullptr); +namespace mrc::system { +class SystemDefinition; +class ThreadingResources; +} // namespace mrc::system + +namespace mrc::tests { +std::unique_ptr make_system(std::function updater = nullptr); + +std::unique_ptr make_threading_resources(std::function updater = nullptr); + +std::unique_ptr make_threading_resources(std::unique_ptr system); +} // namespace mrc::tests diff --git a/cpp/mrc/src/tests/pipelines/common_pipelines.hpp b/cpp/mrc/src/tests/pipelines/common_pipelines.hpp index acfb2c6ac..0ef8d88cd 100644 --- a/cpp/mrc/src/tests/pipelines/common_pipelines.hpp +++ b/cpp/mrc/src/tests/pipelines/common_pipelines.hpp @@ -21,8 +21,8 @@ namespace test::pipelines { -std::unique_ptr finite_single_segment(); -std::unique_ptr finite_single_segment_will_throw(); -std::unique_ptr finite_multisegment(); +std::unique_ptr finite_single_segment(); +std::unique_ptr finite_single_segment_will_throw(); +std::unique_ptr finite_multisegment(); } // namespace test::pipelines diff --git a/cpp/mrc/src/tests/pipelines/multi_segment.cpp b/cpp/mrc/src/tests/pipelines/multi_segment.cpp index 3b267bcdf..5157ef5d6 100644 --- a/cpp/mrc/src/tests/pipelines/multi_segment.cpp +++ b/cpp/mrc/src/tests/pipelines/multi_segment.cpp @@ -17,13 +17,12 @@ #include "common_pipelines.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/node/rx_sink.hpp" #include "mrc/node/rx_source.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/segment/builder.hpp" -#include "mrc/segment/definition.hpp" #include "mrc/segment/egress_ports.hpp" +#include "mrc/segment/forward.hpp" #include "mrc/segment/ingress_ports.hpp" #include "mrc/segment/object.hpp" @@ -40,14 +39,14 @@ using namespace mrc; namespace test::pipelines { -std::unique_ptr finite_multisegment() +std::unique_ptr finite_multisegment() { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); - auto segment_initializer = [](segment::Builder& seg) {}; + auto segment_initializer = [](segment::IBuilder& seg) {}; // ideally we make this a true source (seg_1) and true source (seg_4) - auto seg_1 = segment::Definition::create("seg_1", segment::EgressPorts({"my_int2"}), [](segment::Builder& s) { + pipeline->make_segment("seg_1", segment::EgressPorts({"my_int2"}), [](segment::IBuilder& s) { auto src = s.make_source("rx_source", [](rxcpp::subscriber s) { s.on_next(1); s.on_next(2); @@ -57,25 +56,25 @@ std::unique_ptr finite_multisegment() auto egress = s.get_egress("my_int2"); s.make_edge(src, egress); }); - auto seg_2 = segment::Definition::create("seg_2", - segment::IngressPorts({"my_int2"}), - segment::EgressPorts({"my_int3"}), - [](segment::Builder& s) { - // pure pass-thru - auto in = s.get_ingress("my_int2"); - auto out = s.get_egress("my_int3"); - s.make_edge(in, out); - }); - auto seg_3 = segment::Definition::create("seg_3", - segment::IngressPorts({"my_int3"}), - segment::EgressPorts({"my_int4"}), - [](segment::Builder& s) { - // pure pass-thru - auto in = s.get_ingress("my_int3"); - auto out = s.get_egress("my_int4"); - s.make_edge(in, out); - }); - auto seg_4 = segment::Definition::create("seg_4", segment::IngressPorts({"my_int4"}), [](segment::Builder& s) { + pipeline->make_segment("seg_2", + segment::IngressPorts({"my_int2"}), + segment::EgressPorts({"my_int3"}), + [](segment::IBuilder& s) { + // pure pass-thru + auto in = s.get_ingress("my_int2"); + auto out = s.get_egress("my_int3"); + s.make_edge(in, out); + }); + pipeline->make_segment("seg_3", + segment::IngressPorts({"my_int3"}), + segment::EgressPorts({"my_int4"}), + [](segment::IBuilder& s) { + // pure pass-thru + auto in = s.get_ingress("my_int3"); + auto out = s.get_egress("my_int4"); + s.make_edge(in, out); + }); + pipeline->make_segment("seg_4", segment::IngressPorts({"my_int4"}), [](segment::IBuilder& s) { // pure pass-thru auto in = s.get_ingress("my_int4"); auto sink = s.make_sink("rx_sink", rxcpp::make_observer_dynamic([&](int x) { @@ -84,11 +83,6 @@ std::unique_ptr finite_multisegment() s.make_edge(in, sink); }); - pipeline->register_segment(seg_1); - pipeline->register_segment(seg_2); - pipeline->register_segment(seg_3); - pipeline->register_segment(seg_4); - return pipeline; } diff --git a/cpp/mrc/src/tests/pipelines/single_segment.cpp b/cpp/mrc/src/tests/pipelines/single_segment.cpp index 1803f854a..2a986ecb1 100644 --- a/cpp/mrc/src/tests/pipelines/single_segment.cpp +++ b/cpp/mrc/src/tests/pipelines/single_segment.cpp @@ -18,8 +18,8 @@ #include "../segments/common_segments.hpp" #include "common_pipelines.hpp" -#include "mrc/engine/segment/ibuilder.hpp" #include "mrc/pipeline/pipeline.hpp" +#include "mrc/segment/forward.hpp" #include @@ -29,16 +29,16 @@ using namespace mrc; namespace test::pipelines { -std::unique_ptr finite_single_segment() +std::unique_ptr finite_single_segment() { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); pipeline->register_segment(test::segments::single_finite_no_ports("seg_1")); return pipeline; } -std::unique_ptr finite_single_segment_will_throw() +std::unique_ptr finite_single_segment_will_throw() { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); pipeline->register_segment(test::segments::single_finite_no_ports_will_throw("seg_1")); return pipeline; } diff --git a/cpp/mrc/src/tests/segments/common_segments.cpp b/cpp/mrc/src/tests/segments/common_segments.cpp index 7023b7270..9e0f6b61d 100644 --- a/cpp/mrc/src/tests/segments/common_segments.cpp +++ b/cpp/mrc/src/tests/segments/common_segments.cpp @@ -20,8 +20,8 @@ #include "mrc/channel/status.hpp" #include "mrc/node/rx_sink.hpp" #include "mrc/node/rx_source.hpp" +#include "mrc/pipeline/segment.hpp" #include "mrc/segment/builder.hpp" -#include "mrc/segment/definition.hpp" #include "mrc/segment/object.hpp" #include @@ -34,18 +34,18 @@ using namespace mrc; namespace test::segments { -std::shared_ptr single_finite_no_ports(std::string segment_name) +std::shared_ptr single_finite_no_ports(std::string segment_name) { - return segment::Definition::create(segment_name, [](segment::Builder& s) { + return Segment::create(segment_name, [](segment::IBuilder& s) { auto rx_source = s.make_object("rx_source", test::nodes::finite_int_rx_source()); auto rx_sink = s.make_object("rx_sink", test::nodes::int_sink()); s.make_edge(rx_source, rx_sink); }); } -std::shared_ptr single_finite_no_ports_will_throw(std::string segment_name) +std::shared_ptr single_finite_no_ports_will_throw(std::string segment_name) { - return segment::Definition::create(segment_name, [](segment::Builder& s) { + return Segment::create(segment_name, [](segment::IBuilder& s) { auto rx_source = s.make_object("rx_source", test::nodes::finite_int_rx_source()); auto rx_sink = s.make_object("rx_sink", test::nodes::int_sink_throw_on_even()); s.make_edge(rx_source, rx_sink); diff --git a/cpp/mrc/src/tests/segments/common_segments.hpp b/cpp/mrc/src/tests/segments/common_segments.hpp index 3ebb3972f..164b7327e 100644 --- a/cpp/mrc/src/tests/segments/common_segments.hpp +++ b/cpp/mrc/src/tests/segments/common_segments.hpp @@ -17,11 +17,11 @@ #pragma once -#include "mrc/segment/definition.hpp" +#include "mrc/pipeline/segment.hpp" namespace test::segments { -std::shared_ptr single_finite_no_ports(std::string name); -std::shared_ptr single_finite_no_ports_will_throw(std::string name); +std::shared_ptr single_finite_no_ports(std::string name); +std::shared_ptr single_finite_no_ports_will_throw(std::string name); } // namespace test::segments diff --git a/cpp/mrc/src/tests/test_codable.cpp b/cpp/mrc/src/tests/test_codable.cpp index a1cbe870a..36cf16f2e 100644 --- a/cpp/mrc/src/tests/test_codable.cpp +++ b/cpp/mrc/src/tests/test_codable.cpp @@ -17,13 +17,14 @@ #include "common.hpp" -#include "internal/data_plane/resources.hpp" -#include "internal/network/resources.hpp" +#include "internal/data_plane/data_plane_resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/remote_descriptor/storage.hpp" #include "internal/resources/manager.hpp" #include "internal/resources/partition_resources.hpp" #include "internal/runtime/partition.hpp" #include "internal/runtime/runtime.hpp" +#include "internal/system/system.hpp" #include "internal/system/system_provider.hpp" #include "internal/ucx/registration_cache.hpp" @@ -116,15 +117,15 @@ class TestCodable : public ::testing::Test protected: void SetUp() override { - auto resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + auto resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { // todo(#114) - propose: remove this option entirely options.enable_server(true); options.architect_url("localhost:13337"); options.placement().resources_strategy(PlacementResources::Dedicated); }))); - m_runtime = std::make_unique(std::move(resources)); + m_runtime = std::make_unique(std::move(resources)); DVLOG(10) << "Setup Complete"; } @@ -136,7 +137,7 @@ class TestCodable : public ::testing::Test DVLOG(10) << "Teardown Complete"; } - std::unique_ptr m_runtime; + std::unique_ptr m_runtime; }; TEST_F(TestCodable, Objects) diff --git a/cpp/mrc/src/tests/test_control_plane.cpp b/cpp/mrc/src/tests/test_control_plane.cpp index e49992e83..96d85945c 100644 --- a/cpp/mrc/src/tests/test_control_plane.cpp +++ b/cpp/mrc/src/tests/test_control_plane.cpp @@ -21,10 +21,10 @@ #include "internal/control_plane/client/connections_manager.hpp" #include "internal/control_plane/client/instance.hpp" #include "internal/control_plane/server.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/resources/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/runtime/partition.hpp" #include "internal/runtime/runtime.hpp" #include "internal/system/partitions.hpp" @@ -64,8 +64,8 @@ using namespace mrc::memory::literals; static auto make_runtime(std::function options_lambda = [](Options& options) {}) { - auto resources = std::make_unique( - internal::system::SystemProvider(make_system([&](Options& options) { + auto resources = std::make_unique( + system::SystemProvider(tests::make_system([&](Options& options) { options.topology().user_cpuset("0-3"); options.topology().restrict_gpus(true); options.placement().resources_strategy(PlacementResources::Dedicated); @@ -73,7 +73,7 @@ static auto make_runtime(std::function options_lambda = options_lambda(options); }))); - return std::make_unique(std::move(resources)); + return std::make_unique(std::move(resources)); } class TestControlPlane : public ::testing::Test @@ -86,7 +86,7 @@ class TestControlPlane : public ::testing::Test TEST_F(TestControlPlane, LifeCycle) { auto sr = make_runtime(); - auto server = std::make_unique(sr->partition(0).resources().runnable()); + auto server = std::make_unique(sr->partition(0).resources().runnable()); server->service_start(); server->service_await_live(); @@ -100,7 +100,7 @@ TEST_F(TestControlPlane, LifeCycle) TEST_F(TestControlPlane, SingleClientConnectDisconnect) { auto sr = make_runtime(); - auto server = std::make_unique(sr->partition(0).resources().runnable()); + auto server = std::make_unique(sr->partition(0).resources().runnable()); server->service_start(); server->service_await_live(); @@ -124,7 +124,7 @@ TEST_F(TestControlPlane, SingleClientConnectDisconnect) TEST_F(TestControlPlane, DoubleClientConnectExchangeDisconnect) { auto sr = make_runtime(); - auto server = std::make_unique(sr->partition(0).resources().runnable()); + auto server = std::make_unique(sr->partition(0).resources().runnable()); server->service_start(); server->service_await_live(); @@ -191,7 +191,7 @@ TEST_F(TestControlPlane, DoubleClientPubSub) GTEST_SKIP(); auto sr = make_runtime(); - auto server = std::make_unique(sr->partition(0).resources().runnable()); + auto server = std::make_unique(sr->partition(0).resources().runnable()); server->service_start(); server->service_await_live(); @@ -293,7 +293,7 @@ TEST_F(TestControlPlane, DoubleClientPubSub) // TEST_F(TestControlPlane, DoubleClientPubSubBuffers) // { // auto sr = make_runtime(); -// auto server = std::make_unique(sr->partition(0).resources().runnable()); +// auto server = std::make_unique(sr->partition(0).resources().runnable()); // server->service_start(); // server->service_await_live(); diff --git a/cpp/mrc/src/tests/test_control_plane_components.cpp b/cpp/mrc/src/tests/test_control_plane_components.cpp index 9f8edac27..bccd39690 100644 --- a/cpp/mrc/src/tests/test_control_plane_components.cpp +++ b/cpp/mrc/src/tests/test_control_plane_components.cpp @@ -33,7 +33,7 @@ #include using namespace mrc; -using namespace mrc::internal::control_plane; +using namespace mrc::control_plane; class TestControlPlaneComponents : public ::testing::Test {}; diff --git a/cpp/mrc/src/tests/test_grpc.cpp b/cpp/mrc/src/tests/test_grpc.cpp index cda1fee6a..68acc2913 100644 --- a/cpp/mrc/src/tests/test_grpc.cpp +++ b/cpp/mrc/src/tests/test_grpc.cpp @@ -23,7 +23,8 @@ #include "internal/grpc/stream_writer.hpp" #include "internal/resources/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" +#include "internal/system/system.hpp" #include "internal/system/system_provider.hpp" #include "mrc/channel/status.hpp" @@ -45,7 +46,6 @@ #include #include #include -#include #include #include @@ -54,10 +54,14 @@ #include #include #include +#include #include #include #include +// Avoid forward declaring template specialization base classes +// IWYU pragma: no_forward_declare grpc::ServerAsyncReaderWriter + using namespace mrc; using namespace mrc::codable; @@ -66,8 +70,8 @@ class TestRPC : public ::testing::Test protected: void SetUp() override { - m_resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + m_resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { // todo(#114) - propose: remove this option entirely // options.architect_url("localhost:13337"); options.topology().user_cpuset("0-8"); @@ -75,7 +79,7 @@ class TestRPC : public ::testing::Test options.placement().resources_strategy(PlacementResources::Dedicated); }))); - m_server = std::make_unique(m_resources->partition(0).runnable()); + m_server = std::make_unique(m_resources->partition(0).runnable()); m_channel = grpc::CreateChannel("localhost:13337", grpc::InsecureChannelCredentials()); m_stub = mrc::testing::TestService::NewStub(m_channel); @@ -89,10 +93,10 @@ class TestRPC : public ::testing::Test m_resources.reset(); } - std::unique_ptr m_resources; + std::unique_ptr m_resources; std::shared_ptr m_channel; std::shared_ptr m_stub; - std::unique_ptr m_server; + std::unique_ptr m_server; }; TEST_F(TestRPC, ServerLifeCycle) @@ -106,8 +110,8 @@ TEST_F(TestRPC, ServerLifeCycle) // server.register_service(service); } -using stream_server_t = internal::rpc::ServerStream; -using stream_client_t = internal::rpc::ClientStream; +using stream_server_t = rpc::ServerStream; +using stream_client_t = rpc::ClientStream; TEST_F(TestRPC, Alternative) { diff --git a/cpp/mrc/src/tests/test_memory.cpp b/cpp/mrc/src/tests/test_memory.cpp index fd7c49e84..2544827d3 100644 --- a/cpp/mrc/src/tests/test_memory.cpp +++ b/cpp/mrc/src/tests/test_memory.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include @@ -60,12 +59,12 @@ class TestMemory : public ::testing::Test TEST_F(TestMemory, UcxRegisterePinnedMemoryArena) { - auto context = std::make_shared(); - auto regcache = std::make_shared(context); + auto context = std::make_shared(); + auto regcache = std::make_shared(context); auto pinned = std::make_unique(); auto logger = memory::make_unique_resource(std::move(pinned), "pinned_resource"); - auto ucx = memory::make_shared_resource(std::move(logger), regcache, 0); + auto ucx = memory::make_shared_resource(std::move(logger), regcache, 0); auto arena = memory::make_shared_resource(ucx, 64_MiB); auto arena_log = memory::make_shared_resource(arena, "arena_resource"); @@ -91,12 +90,12 @@ TEST_F(TestMemory, UcxRegisterePinnedMemoryArena) TEST_F(TestMemory, UcxRegisteredCudaMemoryArena) { - auto context = std::make_shared(); - auto regcache = std::make_shared(context); + auto context = std::make_shared(); + auto regcache = std::make_shared(context); auto cuda = std::make_unique(0); auto logger = memory::make_unique_resource(std::move(cuda), "cuda_resource"); - auto ucx = memory::make_shared_resource(std::move(logger), regcache, 0); + auto ucx = memory::make_shared_resource(std::move(logger), regcache, 0); auto arena = memory::make_shared_resource(ucx, 64_MiB); auto arena_log = memory::make_shared_resource(arena, "arena_resource"); @@ -114,7 +113,7 @@ TEST_F(TestMemory, UcxRegisteredCudaMemoryArena) TEST_F(TestMemory, CallbackAdaptor) { - internal::memory::CallbackBuilder builder; + memory::CallbackBuilder builder; std::atomic_size_t calls = 0; std::atomic_size_t bytes = 0; @@ -134,8 +133,7 @@ TEST_F(TestMemory, CallbackAdaptor) auto malloc = std::make_unique(); auto logger = mrc::memory::make_unique_resource(std::move(malloc), "malloc"); - auto callback = mrc::memory::make_shared_resource(std::move(logger), - std::move(builder)); + auto callback = mrc::memory::make_shared_resource(std::move(logger), std::move(builder)); EXPECT_EQ(calls, 0); EXPECT_EQ(bytes, 0); @@ -176,7 +174,7 @@ class TickOnDestruct TEST_F(TestMemory, TransientPool) { - internal::memory::CallbackBuilder builder; + memory::CallbackBuilder builder; std::atomic_size_t calls = 0; std::atomic_size_t bytes = 0; @@ -196,10 +194,9 @@ TEST_F(TestMemory, TransientPool) auto malloc = std::make_unique(); auto logger = mrc::memory::make_unique_resource(std::move(malloc), "malloc"); - auto callback = mrc::memory::make_shared_resource(std::move(logger), - std::move(builder)); + auto callback = mrc::memory::make_shared_resource(std::move(logger), std::move(builder)); - internal::memory::TransientPool pool(10_MiB, 4, callback); + memory::TransientPool pool(10_MiB, 4, callback); EXPECT_ANY_THROW(pool.await_buffer(11_MiB)); @@ -236,14 +233,14 @@ TEST_F(TestMemory, TransientPool) auto buffer = pool.await_buffer(6_MiB); // default constructible - internal::memory::TransientBuffer other; + memory::TransientBuffer other; // move and test void* gets properly nullified other = std::move(buffer); EXPECT_EQ(buffer.data(), nullptr); std::byte* start = static_cast(other.data()) + 1; - internal::memory::TransientBuffer offset_buffer(start, other.bytes() - 1, other); + memory::TransientBuffer offset_buffer(start, other.bytes() - 1, other); other.release(); offset_buffer.release(); diff --git a/cpp/mrc/src/tests/test_network.cpp b/cpp/mrc/src/tests/test_network.cpp index 61e3a3ae5..1a14cebf4 100644 --- a/cpp/mrc/src/tests/test_network.cpp +++ b/cpp/mrc/src/tests/test_network.cpp @@ -15,21 +15,23 @@ * limitations under the License. */ +#include "tests/common.hpp" + #include "internal/control_plane/client.hpp" #include "internal/control_plane/client/connections_manager.hpp" #include "internal/control_plane/client/instance.hpp" #include "internal/data_plane/client.hpp" +#include "internal/data_plane/data_plane_resources.hpp" #include "internal/data_plane/request.hpp" -#include "internal/data_plane/resources.hpp" #include "internal/data_plane/server.hpp" #include "internal/data_plane/tags.hpp" #include "internal/memory/device_resources.hpp" #include "internal/memory/host_resources.hpp" #include "internal/memory/transient_pool.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/resources/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/system/system.hpp" #include "internal/system/system_provider.hpp" #include "internal/ucx/memory_block.hpp" @@ -56,17 +58,16 @@ #include #include #include -#include #include #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -74,17 +75,6 @@ using namespace mrc; using namespace mrc::memory::literals; -static std::shared_ptr make_system(std::function updater = nullptr) -{ - auto options = std::make_shared(); - if (updater) - { - updater(*options); - } - - return internal::system::make_system(std::move(options)); -} - class TestNetwork : public ::testing::Test {}; @@ -106,8 +96,8 @@ TEST_F(TestNetwork, ResourceManager) // using options.placement().resources_strategy(PlacementResources::Shared) // will test if cudaSetDevice is being properly called by the network services // since all network services for potentially multiple devices are colocated on a single thread - auto resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + auto resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { options.enable_server(true); options.architect_url("localhost:13337"); options.placement().resources_strategy(PlacementResources::Dedicated); @@ -166,8 +156,8 @@ TEST_F(TestNetwork, CommsSendRecv) // using options.placement().resources_strategy(PlacementResources::Shared) // will test if cudaSetDevice is being properly called by the network services // since all network services for potentially multiple devices are colocated on a single thread - auto resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + auto resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { options.enable_server(true); options.architect_url("localhost:13337"); options.placement().resources_strategy(PlacementResources::Dedicated); @@ -206,8 +196,8 @@ TEST_F(TestNetwork, CommsSendRecv) int src = 42; int dst = -1; - internal::data_plane::Request send_req; - internal::data_plane::Request recv_req; + data_plane::Request send_req; + data_plane::Request recv_req; r1.client().async_p2p_recv(&dst, sizeof(int), 0, recv_req); r0.client().async_p2p_send(&src, sizeof(int), 0, id_1, send_req); @@ -228,8 +218,8 @@ TEST_F(TestNetwork, CommsGet) // using options.placement().resources_strategy(PlacementResources::Shared) // will test if cudaSetDevice is being properly called by the network services // since all network services for potentially multiple devices are colocated on a single thread - auto resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + auto resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { options.enable_server(true); options.architect_url("localhost:13337"); options.placement().resources_strategy(PlacementResources::Dedicated); @@ -277,7 +267,7 @@ TEST_F(TestNetwork, CommsGet) auto id_0 = resources->partition(0).network()->control_plane().instance_id(); auto id_1 = resources->partition(1).network()->control_plane().instance_id(); - internal::data_plane::Request get_req; + data_plane::Request get_req; r1.client().async_get(dst.data(), 1_MiB, id_0, src.data(), src_keys, get_req); @@ -299,8 +289,8 @@ TEST_F(TestNetwork, PersistentEagerDataPlaneTaggedRecv) // using options.placement().resources_strategy(PlacementResources::Shared) // will test if cudaSetDevice is being properly called by the network services // since all network services for potentially multiple devices are colocated on a single thread - auto resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + auto resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { options.enable_server(true); options.architect_url("localhost:13337"); options.placement().resources_strategy(PlacementResources::Dedicated); @@ -333,12 +323,11 @@ TEST_F(TestNetwork, PersistentEagerDataPlaneTaggedRecv) const std::uint64_t tag = 20919; std::atomic counter = 0; - auto recv_sink = std::make_unique>( - [&](internal::memory::TransientBuffer buffer) { - EXPECT_EQ(buffer.bytes(), 128); - counter++; - r0.server().deserialize_source().drop_edge(tag); - }); + auto recv_sink = std::make_unique>([&](memory::TransientBuffer buffer) { + EXPECT_EQ(buffer.bytes(), 128); + counter++; + r0.server().deserialize_source().drop_edge(tag); + }); auto deser_source = r0.server().deserialize_source().get_source(tag); @@ -353,7 +342,7 @@ TEST_F(TestNetwork, PersistentEagerDataPlaneTaggedRecv) auto endpoint = r1.client().endpoint_shared(r0.instance_id()); - internal::data_plane::Request req; + data_plane::Request req; auto buffer = resources->partition(1).host().make_buffer(128); auto send_tag = tag | TAG_EGR_MSG; r1.client().async_send(buffer.data(), buffer.bytes(), send_tag, *endpoint, req); diff --git a/cpp/mrc/src/tests/test_next.cpp b/cpp/mrc/src/tests/test_next.cpp index 1413ae1ac..da54e0a3f 100644 --- a/cpp/mrc/src/tests/test_next.cpp +++ b/cpp/mrc/src/tests/test_next.cpp @@ -15,10 +15,12 @@ * limitations under the License. */ -#include "internal/runnable/resources.hpp" -#include "internal/system/resources.hpp" +#include "tests/common.hpp" + +#include "internal/runnable/runnable_resources.hpp" #include "internal/system/system.hpp" #include "internal/system/system_provider.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/channel/ingress.hpp" #include "mrc/data/reusable_pool.hpp" @@ -38,6 +40,7 @@ #include "mrc/options/engine_groups.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/segment.hpp" #include "mrc/runnable/context.hpp" #include "mrc/runnable/launch_control.hpp" #include "mrc/runnable/launch_options.hpp" @@ -45,11 +48,9 @@ #include "mrc/runnable/runner.hpp" #include "mrc/runnable/types.hpp" #include "mrc/segment/builder.hpp" -#include "mrc/segment/definition.hpp" #include "mrc/segment/egress_ports.hpp" #include "mrc/segment/object.hpp" #include "mrc/segment/runnable.hpp" -#include "mrc/segment/segment.hpp" #include "mrc/type_traits.hpp" #include "mrc/utils/macros.hpp" @@ -72,24 +73,13 @@ using namespace mrc; -static std::shared_ptr make_system(std::function updater = nullptr) -{ - auto options = std::make_shared(); - if (updater) - { - updater(*options); - } - - return internal::system::make_system(std::move(options)); -} - class TestNext : public ::testing::Test { protected: void SetUp() override { - m_system_resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + m_system_resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { options.topology().user_cpuset("0-3"); options.topology().restrict_gpus(true); options.engine_factories().set_engine_factory_options("thread_pool", [](EngineFactoryOptions& options) { @@ -99,7 +89,7 @@ class TestNext : public ::testing::Test }); }))); - m_resources = std::make_unique(*m_system_resources, 0); + m_resources = std::make_unique(*m_system_resources, 0); } void TearDown() override @@ -108,8 +98,8 @@ class TestNext : public ::testing::Test m_system_resources.reset(); } - std::unique_ptr m_system_resources; - std::unique_ptr m_resources; + std::unique_ptr m_system_resources; + std::unique_ptr m_resources; }; class ExGenSource : public node::GenericSource @@ -708,16 +698,16 @@ TEST_F(TestNext, PrivateInheritance) TEST_F(TestNext, Segment) { - auto segment = segment::Definition::create("test", segment::EgressPorts({"test"}), [](segment::Builder& s) {}); + auto segment = Segment::create("test", segment::EgressPorts({"test"}), [](segment::IBuilder& s) {}); segment::EgressPorts ports({"test"}); - // segment::Segment seg("test", ports, [](segment::Builder& builder) {}); + // segment::Segment seg("test", ports, [](segment::IBuilder& builder) {}); } TEST_F(TestNext, SegmentRunnable) { - auto node = std::make_shared>("ex_gen_source"); + auto node = std::make_shared>(); EXPECT_TRUE(node->is_source()); EXPECT_FALSE(node->is_sink()); @@ -732,7 +722,7 @@ TEST_F(TestNext, SegmentRunnable) TEST_F(TestNext, SegmentBuilder) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { auto src = segment.make_source("x_src", [&](rxcpp::subscriber s) { s.on_next("One"); s.on_next("Two"); diff --git a/cpp/mrc/src/tests/test_partitions.cpp b/cpp/mrc/src/tests/test_partitions.cpp index 8b2ae9d50..99107f042 100644 --- a/cpp/mrc/src/tests/test_partitions.cpp +++ b/cpp/mrc/src/tests/test_partitions.cpp @@ -42,7 +42,6 @@ #include using namespace mrc; -using namespace internal; using namespace system; // iwyu is getting confused between std::uint32_t and boost::uint32_t diff --git a/cpp/mrc/src/tests/test_pipeline.cpp b/cpp/mrc/src/tests/test_pipeline.cpp index ef01e15ca..1b6e9c85f 100644 --- a/cpp/mrc/src/tests/test_pipeline.cpp +++ b/cpp/mrc/src/tests/test_pipeline.cpp @@ -17,9 +17,10 @@ #include "nodes/common_nodes.hpp" #include "pipelines/common_pipelines.hpp" +#include "tests/common.hpp" #include "internal/pipeline/manager.hpp" -#include "internal/pipeline/pipeline.hpp" +#include "internal/pipeline/pipeline_definition.hpp" // IWYU pragma: keep #include "internal/pipeline/types.hpp" #include "internal/resources/manager.hpp" #include "internal/system/system.hpp" @@ -30,9 +31,7 @@ #include "mrc/channel/channel.hpp" #include "mrc/channel/status.hpp" #include "mrc/core/addresses.hpp" -#include "mrc/core/executor.hpp" #include "mrc/data/reusable_pool.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/node/queue.hpp" #include "mrc/node/rx_node.hpp" #include "mrc/node/rx_sink.hpp" @@ -41,6 +40,7 @@ #include "mrc/options/options.hpp" #include "mrc/options/placement.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/runnable/context.hpp" #include "mrc/runnable/types.hpp" @@ -80,32 +80,28 @@ using namespace mrc; class TestPipeline : public ::testing::Test {}; -static std::shared_ptr make_system(std::function updater = nullptr) +static std::shared_ptr unwrap(std::unique_ptr pipeline) { - auto options = std::make_shared(); - if (updater) - { - updater(*options); - } + std::shared_ptr shared_pipeline = std::move(pipeline); - return internal::system::make_system(std::move(options)); -} + // Convert it to the full implementation + auto full_pipeline = std::dynamic_pointer_cast(shared_pipeline); -static std::shared_ptr unwrap(internal::pipeline::IPipeline& pipeline) -{ - return internal::pipeline::Pipeline::unwrap(pipeline); + CHECK(full_pipeline) << "Must pass a non-null pipeline pointer to register_pipeline"; + + return std::move(full_pipeline); } -static void run_custom_manager(std::unique_ptr pipeline, - internal::pipeline::SegmentAddresses&& update, +static void run_custom_manager(std::unique_ptr pipeline, + pipeline::SegmentAddresses&& update, bool delayed_stop = false) { - auto resources = internal::resources::Manager(internal::system::SystemProvider(make_system([](Options& options) { + auto resources = resources::Manager(system::SystemProvider(tests::make_system([](Options& options) { options.topology().user_cpuset("0-1"); options.topology().restrict_gpus(true); }))); - auto manager = std::make_unique(unwrap(*pipeline), resources); + auto manager = std::make_unique(unwrap(std::move(pipeline)), resources); auto f = std::async([&] { if (delayed_stop) @@ -122,17 +118,17 @@ static void run_custom_manager(std::unique_ptr pi f.get(); } -static void run_manager(std::unique_ptr pipeline, bool delayed_stop = false) +static void run_manager(std::unique_ptr pipeline, bool delayed_stop = false) { - auto resources = internal::resources::Manager(internal::system::SystemProvider(make_system([](Options& options) { + auto resources = resources::Manager(system::SystemProvider(tests::make_system([](Options& options) { options.topology().user_cpuset("0"); options.topology().restrict_gpus(true); mrc::channel::set_default_channel_size(64); }))); - auto manager = std::make_unique(unwrap(*pipeline), resources); + auto manager = std::make_unique(unwrap(std::move(pipeline)), resources); - internal::pipeline::SegmentAddresses update; + pipeline::SegmentAddresses update; update[segment_address_encode(segment_name_hash("seg_1"), 0)] = 0; auto f = std::async([&] { @@ -152,7 +148,7 @@ static void run_manager(std::unique_ptr pipeline, TEST_F(TestPipeline, PortNamingService) { - internal::utils::CollisionDetector hasher; + utils::CollisionDetector hasher; auto p1 = hasher.register_name("test 1"); auto p2 = hasher.register_name("test 2"); @@ -174,9 +170,9 @@ TEST_F(TestPipeline, LifeCycleWithException) TEST_F(TestPipeline, LifeCycleWithExceptionAndInfiniteSource) { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); - auto segment = pipeline->make_segment("seg_1", [](segment::Builder& s) { + auto segment = pipeline->make_segment("seg_1", [](segment::IBuilder& s) { auto rx_source = s.make_object("rx_source", test::nodes::infinite_int_rx_source()); auto rx_sink = s.make_object("rx_sink", test::nodes::int_sink_throw_on_even()); s.make_edge(rx_source, rx_sink); @@ -187,9 +183,9 @@ TEST_F(TestPipeline, LifeCycleWithExceptionAndInfiniteSource) TEST_F(TestPipeline, LifeCycleStop) { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); - auto segment = pipeline->make_segment("seg_1", [](segment::Builder& s) { + auto segment = pipeline->make_segment("seg_1", [](segment::IBuilder& s) { auto rx_source = s.make_object("rx_source", test::nodes::infinite_int_rx_source()); auto rx_sink = s.make_object("rx_sink", test::nodes::int_sink()); s.make_edge(rx_source, rx_sink); @@ -200,9 +196,9 @@ TEST_F(TestPipeline, LifeCycleStop) TEST_F(TestPipeline, Queue) { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); - auto segment = pipeline->make_segment("seg_1", [](segment::Builder& s) { + auto segment = pipeline->make_segment("seg_1", [](segment::IBuilder& s) { auto source = s.make_object("source", test::nodes::infinite_int_rx_source()); auto queue = s.make_object("queue", std::make_unique>()); auto sink = s.make_object("sink", test::nodes::int_sink()); @@ -215,8 +211,8 @@ TEST_F(TestPipeline, Queue) TEST_F(TestPipeline, InitializerThrows) { - auto pipeline = pipeline::make_pipeline(); - auto segment = pipeline->make_segment("seg_1", [](segment::Builder& s) { + auto pipeline = mrc::make_pipeline(); + auto segment = pipeline->make_segment("seg_1", [](segment::IBuilder& s) { throw std::runtime_error("no bueno"); }); EXPECT_ANY_THROW(run_manager(std::move(pipeline))); @@ -224,10 +220,10 @@ TEST_F(TestPipeline, InitializerThrows) TEST_F(TestPipeline, DuplicateNameInSegment) { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); // this should fail to register the int_sink because of a duplicate name - auto segment = pipeline->make_segment("seg_1", [](segment::Builder& s) { + auto segment = pipeline->make_segment("seg_1", [](segment::IBuilder& s) { auto rx_source = s.make_object("rx_source", test::nodes::finite_int_rx_source()); auto rx_sink = s.make_object("rx_source", test::nodes::int_sink()); s.make_edge(rx_source, rx_sink); @@ -267,19 +263,19 @@ TEST_F(TestPipeline, MultiSegmentLoadBalancer) // we collect the fiber id for the sink runnable processing each data element, // then we count the unique fiber ids collected - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); int count = 1000; std::mutex mutex; std::vector ranks; - pipeline->make_segment("seg_1", segment::EgressPorts({"i"}), [count](segment::Builder& s) { + pipeline->make_segment("seg_1", segment::EgressPorts({"i"}), [count](segment::IBuilder& s) { auto src = s.make_object("src", test::nodes::finite_int_rx_source(count)); auto egress = s.get_egress("i"); s.make_edge(src, egress); }); - pipeline->make_segment("seg_2", segment::IngressPorts({"i"}), [&mutex, &ranks](segment::Builder& s) mutable { + pipeline->make_segment("seg_2", segment::IngressPorts({"i"}), [&mutex, &ranks](segment::IBuilder& s) mutable { auto sink = s.make_sink("sink", [&](int x) { VLOG(1) << runnable::Context::get_runtime_context().info() << ": data=" << x; std::lock_guard lock(mutex); @@ -290,7 +286,7 @@ TEST_F(TestPipeline, MultiSegmentLoadBalancer) }); // run 1 copy of seg_1 and 2 copies of seg_2 all on parition 0 - internal::pipeline::SegmentAddresses update; + pipeline::SegmentAddresses update; update[segment_address_encode(segment_name_hash("seg_1"), 0)] = 0; update[segment_address_encode(segment_name_hash("seg_2"), 0)] = 0; update[segment_address_encode(segment_name_hash("seg_2"), 1)] = 0; @@ -310,9 +306,9 @@ TEST_F(TestPipeline, MultiSegmentLoadBalancer) TEST_F(TestPipeline, UnmatchedIngress) { - std::function init = [](mrc::segment::Builder& builder) {}; + std::function init = [](mrc::segment::IBuilder& builder) {}; - auto pipe = pipeline::make_pipeline(); + auto pipe = mrc::make_pipeline(); pipe->make_segment("TestSegment1", segment::IngressPorts({"some_port"}), init); @@ -320,16 +316,16 @@ TEST_F(TestPipeline, UnmatchedIngress) opt1->topology().user_cpuset("0"); opt1->topology().restrict_gpus(true); - mrc::Executor exec1{opt1}; + Executor exec1{opt1}; EXPECT_ANY_THROW(exec1.register_pipeline(std::move(pipe))); } TEST_F(TestPipeline, UnmatchedEgress) { - std::function init = [](mrc::segment::Builder& builder) {}; + std::function init = [](mrc::segment::IBuilder& builder) {}; - auto pipe = pipeline::make_pipeline(); + auto pipe = mrc::make_pipeline(); pipe->make_segment("TestSegment1", segment::EgressPorts({"some_port"}), init); @@ -344,9 +340,9 @@ TEST_F(TestPipeline, UnmatchedEgress) TEST_F(TestPipeline, RequiresMoreManifolds) { - std::function init = [](mrc::segment::Builder& builder) {}; + std::function init = [](mrc::segment::IBuilder& builder) {}; - auto pipe = pipeline::make_pipeline(); + auto pipe = mrc::make_pipeline(); pipe->make_segment("TestSegment1", segment::EgressPorts({"some_port"}), init); pipe->make_segment("TestSegment2", segment::IngressPorts({"some_port"}), init); @@ -409,7 +405,7 @@ TEST_F(TestPipeline, ReusablePool) TEST_F(TestPipeline, ReusableSource) { - auto pipe = pipeline::make_pipeline(); + auto pipe = mrc::make_pipeline(); auto pool = data::ReusablePool::create(32); auto opt = std::make_shared(); @@ -425,7 +421,7 @@ TEST_F(TestPipeline, ReusableSource) pool->add_item(std::make_unique()); } - auto init = [&exec, pool](segment::Builder& segment) { + auto init = [&exec, pool](segment::IBuilder& segment) { auto src = segment.make_source>("src", [pool](rxcpp::subscriber> s) { while (s.is_subscribed()) @@ -460,7 +456,7 @@ TEST_F(TestPipeline, ReusableSource) TEST_F(TestPipeline, Nodes1k) { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); std::size_t count = 1000; std::size_t recv_count = 0; @@ -468,7 +464,7 @@ TEST_F(TestPipeline, Nodes1k) auto start = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now(); - auto segment = pipeline->make_segment("seg_1", [&](segment::Builder& s) { + auto segment = pipeline->make_segment("seg_1", [&](segment::IBuilder& s) { auto rx_source = s.make_source("rx_source", [&start, count](rxcpp::subscriber s) { VLOG(1) << runnable::Context::get_runtime_context().info(); start = std::chrono::high_resolution_clock::now(); @@ -515,7 +511,7 @@ TEST_F(TestPipeline, Nodes1k) TEST_F(TestPipeline, EngineFactories) { - auto topology = mrc::internal::system::Topology::Create(); + auto topology = mrc::system::Topology::Create(); if (topology->core_count() < 8) { diff --git a/cpp/mrc/src/tests/test_remote_descriptor.cpp b/cpp/mrc/src/tests/test_remote_descriptor.cpp index 6b43b3966..df4468897 100644 --- a/cpp/mrc/src/tests/test_remote_descriptor.cpp +++ b/cpp/mrc/src/tests/test_remote_descriptor.cpp @@ -20,14 +20,15 @@ #include "internal/control_plane/client.hpp" #include "internal/control_plane/client/connections_manager.hpp" #include "internal/control_plane/client/instance.hpp" -#include "internal/network/resources.hpp" +#include "internal/network/network_resources.hpp" #include "internal/remote_descriptor/manager.hpp" #include "internal/remote_descriptor/storage.hpp" #include "internal/resources/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/runtime/partition.hpp" #include "internal/runtime/runtime.hpp" +#include "internal/system/system.hpp" #include "internal/system/system_provider.hpp" #include "mrc/codable/fundamental_types.hpp" // IWYU pragma: keep @@ -55,15 +56,15 @@ class TestRD : public ::testing::Test protected: void SetUp() override { - auto resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + auto resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { // todo(#114) - propose: remove this option entirely options.enable_server(true); options.architect_url("localhost:13337"); options.placement().resources_strategy(PlacementResources::Dedicated); }))); - m_runtime = std::make_unique(std::move(resources)); + m_runtime = std::make_unique(std::move(resources)); } void TearDown() override @@ -71,7 +72,7 @@ class TestRD : public ::testing::Test m_runtime.reset(); } - std::unique_ptr m_runtime; + std::unique_ptr m_runtime; }; TEST_F(TestRD, LifeCycle) @@ -91,7 +92,7 @@ TEST_F(TestRD, LifeCycle) EXPECT_EQ(rd_manager.size(), 1); // use the internal implementation to transfer ownership and recreate - auto handle = internal::remote_descriptor::Manager::unwrap_handle(std::move(rd)); + auto handle = remote_descriptor::Manager::unwrap_handle(std::move(rd)); EXPECT_FALSE(rd); // recreate from handle @@ -132,7 +133,7 @@ TEST_F(TestRD, RemoteRelease) EXPECT_EQ(rd_manager_0.size(), 1); EXPECT_EQ(rd_manager_1.size(), 0); - auto handle = internal::remote_descriptor::Manager::unwrap_handle(std::move(rd)); + auto handle = remote_descriptor::Manager::unwrap_handle(std::move(rd)); EXPECT_FALSE(rd); auto rd2 = rd_manager_1.make_remote_descriptor(std::move(handle)); diff --git a/cpp/mrc/src/tests/test_resources.cpp b/cpp/mrc/src/tests/test_resources.cpp index 5ace30790..b6b4c953f 100644 --- a/cpp/mrc/src/tests/test_resources.cpp +++ b/cpp/mrc/src/tests/test_resources.cpp @@ -15,10 +15,11 @@ * limitations under the License. */ -#include "internal/resources/forward.hpp" +#include "tests/common.hpp" + #include "internal/resources/manager.hpp" #include "internal/resources/partition_resources.hpp" -#include "internal/runnable/resources.hpp" +#include "internal/runnable/runnable_resources.hpp" #include "internal/system/system.hpp" #include "internal/system/system_provider.hpp" @@ -30,48 +31,38 @@ #include #include -#include #include -#include using namespace mrc; -using namespace internal; // iwyu is getting confused between std::uint32_t and boost::uint32_t // IWYU pragma: no_include class TestResources : public ::testing::Test -{ - protected: - static std::shared_ptr make_system(std::function updater = nullptr) - { - auto options = std::make_shared(); - if (updater) - { - updater(*options); - } +{}; - return system::make_system(std::move(options)); - } -}; +TEST_F(TestResources, Lifetime) +{ + auto resources = tests::make_threading_resources(); +} TEST_F(TestResources, GetRuntime) { - auto resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + auto resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { // todo(#114) - propose: this is the default and only option options.placement().resources_strategy(PlacementResources::Dedicated); }))); - EXPECT_ANY_THROW(internal::resources::Manager::get_resources()); - EXPECT_ANY_THROW(internal::resources::Manager::get_partition()); + EXPECT_ANY_THROW(resources::Manager::get_resources()); + EXPECT_ANY_THROW(resources::Manager::get_partition()); resources->partition(0) .runnable() .main() .enqueue([] { - auto& resources = internal::resources::Manager::get_resources(); - auto& partition = internal::resources::Manager::get_partition(); + auto& resources = resources::Manager::get_resources(); + auto& partition = resources::Manager::get_partition(); EXPECT_EQ(partition.partition_id(), 0); }) .get(); @@ -79,21 +70,21 @@ TEST_F(TestResources, GetRuntime) TEST_F(TestResources, GetRuntimeShared) { - auto resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { + auto resources = std::make_unique( + system::SystemProvider(tests::make_system([](Options& options) { // todo(#114) - propose: remove this option entirely options.placement().resources_strategy(PlacementResources::Shared); }))); - EXPECT_ANY_THROW(internal::resources::Manager::get_resources()); - EXPECT_ANY_THROW(internal::resources::Manager::get_partition()); + EXPECT_ANY_THROW(resources::Manager::get_resources()); + EXPECT_ANY_THROW(resources::Manager::get_partition()); resources->partition(0) .runnable() .main() .enqueue([] { - auto& resources = internal::resources::Manager::get_resources(); - EXPECT_ANY_THROW(internal::resources::Manager::get_partition()); + auto& resources = resources::Manager::get_resources(); + EXPECT_ANY_THROW(resources::Manager::get_partition()); }) .get(); } diff --git a/cpp/mrc/src/tests/test_runnable.cpp b/cpp/mrc/src/tests/test_runnable.cpp index 302be6d86..c5bc0a048 100644 --- a/cpp/mrc/src/tests/test_runnable.cpp +++ b/cpp/mrc/src/tests/test_runnable.cpp @@ -15,10 +15,10 @@ * limitations under the License. */ -#include "internal/runnable/resources.hpp" -#include "internal/system/resources.hpp" -#include "internal/system/system.hpp" -#include "internal/system/system_provider.hpp" +#include "tests/common.hpp" + +#include "internal/runnable/runnable_resources.hpp" +#include "internal/system/threading_resources.hpp" #include "mrc/edge/edge_builder.hpp" #include "mrc/node/operators/muxer.hpp" @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -61,34 +60,22 @@ using namespace mrc; #define MRC_DEFAULT_FIBER_PRIORITY 0 -static std::shared_ptr make_system(std::function updater = nullptr) -{ - auto options = std::make_shared(); - if (updater) - { - updater(*options); - } - - return internal::system::make_system(std::move(options)); -} - class TestRunnable : public ::testing::Test { protected: void SetUp() override { - m_system_resources = std::make_unique( - internal::system::SystemProvider(make_system([](Options& options) { - options.topology().user_cpuset("0-3"); - options.topology().restrict_gpus(true); - options.engine_factories().set_engine_factory_options("thread_pool", [](EngineFactoryOptions& options) { - options.engine_type = runnable::EngineType::Thread; - options.allow_overlap = false; - options.cpu_count = 2; - }); - }))); - - m_resources = std::make_unique(*m_system_resources, 0); + m_system_resources = tests::make_threading_resources([](Options& options) { + options.topology().user_cpuset("0-3"); + options.topology().restrict_gpus(true); + options.engine_factories().set_engine_factory_options("thread_pool", [](EngineFactoryOptions& options) { + options.engine_type = runnable::EngineType::Thread; + options.allow_overlap = false; + options.cpu_count = 2; + }); + }); + + m_resources = std::make_unique(*m_system_resources, 0); } void TearDown() override @@ -97,8 +84,8 @@ class TestRunnable : public ::testing::Test m_system_resources.reset(); } - std::unique_ptr m_system_resources; - std::unique_ptr m_resources; + std::unique_ptr m_system_resources; + std::unique_ptr m_resources; }; class TestGenericRunnable final : public runnable::RunnableWithContext<> diff --git a/cpp/mrc/src/tests/test_system.cpp b/cpp/mrc/src/tests/test_system.cpp index 3363edbe2..3118d8b69 100644 --- a/cpp/mrc/src/tests/test_system.cpp +++ b/cpp/mrc/src/tests/test_system.cpp @@ -15,17 +15,20 @@ * limitations under the License. */ +#include "tests/common.hpp" + #include "internal/system/fiber_pool.hpp" -#include "internal/system/resources.hpp" #include "internal/system/system.hpp" -#include "internal/system/system_provider.hpp" #include "internal/system/thread.hpp" #include "internal/system/thread_pool.hpp" +#include "internal/system/threading_resources.hpp" #include "internal/system/topology.hpp" #include "mrc/core/bitmap.hpp" +#include "mrc/exceptions/runtime_error.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/system.hpp" #include "mrc/types.hpp" #include "mrc/utils/thread_local_shared_pointer.hpp" @@ -43,12 +46,12 @@ #include #include #include +#include #include using namespace mrc; -using namespace internal; -using system::System; +using system::SystemDefinition; using system::ThreadPool; // iwyu is getting confused between std::uint32_t and boost::uint32_t @@ -71,24 +74,22 @@ class TestSystem : public ::testing::Test TEST_F(TestSystem, LifeCycle) { - auto system = system::make_system(make_options()); + auto system = mrc::make_system(make_options()); } TEST_F(TestSystem, FiberPool) { - auto system = system::make_system(make_options([](Options& options) { + auto resources = tests::make_threading_resources([](Options& options) { // ensure we have 4 logical cpus options.topology().user_cpuset("0-255"); - })); + }); CpuSet cpu_set; cpu_set.on(0); cpu_set.on(2); EXPECT_EQ(cpu_set.weight(), 2); - system::Resources resources((system::SystemProvider(system))); - - auto pool = resources.make_fiber_pool(cpu_set); + auto pool = resources->make_fiber_pool(cpu_set); EXPECT_EQ(pool.thread_count(), 2); @@ -138,29 +139,25 @@ TEST_F(TestSystem, FiberPool) TEST_F(TestSystem, ImpossibleCoreCount) { - auto system = system::make_system(make_options([](Options& options) { + auto resources = tests::make_threading_resources([](Options& options) { // ensure we have 2 logical cpus options.topology().user_cpuset("0,1"); - })); + }); CpuSet cpu_set; cpu_set.on(0); cpu_set.on(99999999); EXPECT_EQ(cpu_set.weight(), 2); - system::Resources resources((system::SystemProvider(system))); - - EXPECT_ANY_THROW(auto pool = resources.make_fiber_pool(cpu_set)); + EXPECT_ANY_THROW(auto pool = resources->make_fiber_pool(cpu_set)); } TEST_F(TestSystem, ThreadLocalResource) { - auto system = system::make_system(make_options()); - - system::Resources resources((system::SystemProvider(system))); + auto resources = tests::make_threading_resources(); - auto pool0 = resources.make_fiber_pool(CpuSet("0,1")); - auto pool1 = resources.make_fiber_pool(CpuSet("2,3")); + auto pool0 = resources->make_fiber_pool(CpuSet("0,1")); + auto pool1 = resources->make_fiber_pool(CpuSet("2,3")); auto i0 = std::make_shared(0); auto i1 = std::make_shared(2); @@ -210,26 +207,67 @@ TEST_F(TestSystem, ThreadLocalResource) EXPECT_EQ(j1, 2); } -TEST_F(TestSystem, ThreadInitializersAndFinalizers) +TEST_F(TestSystem, ThreadInitializersAndFinalizersOnSystem) +{ + auto system = tests::make_system([](Options& options) { + options.topology().user_cpuset("0-1"); + options.topology().restrict_gpus(true); + }); + + std::atomic init_counter = 0; + std::atomic fini_counter = 0; + + system->add_thread_initializer([&init_counter] { + init_counter++; + }); + + system->add_thread_finalizer([&fini_counter] { + fini_counter++; + }); + + EXPECT_EQ(init_counter, 0); + EXPECT_EQ(fini_counter, 0); + + auto resources = tests::make_threading_resources(std::move(system)); + + EXPECT_EQ(init_counter, 2); + EXPECT_EQ(fini_counter, 0); + + std::make_unique(resources->make_thread(CpuSet("0"), [] { + VLOG(10) << "test thread"; + }))->join(); + + EXPECT_EQ(init_counter, 3); + EXPECT_EQ(fini_counter, 1); + + resources.reset(); + + EXPECT_EQ(init_counter, 3); + EXPECT_EQ(fini_counter, 3); +} + +TEST_F(TestSystem, ThreadInitializersAndFinalizersOnResources) { - auto system = system::make_system(make_options([](Options& options) { + auto system = tests::make_system([](Options& options) { options.topology().user_cpuset("0-1"); options.topology().restrict_gpus(true); - })); + }); + + auto system_cpuset = system->topology().cpu_set(); - auto resources = std::make_unique((system::SystemProvider(system))); + auto resources = tests::make_threading_resources(std::move(system)); std::atomic init_counter = 0; std::atomic fini_counter = 0; - resources->register_thread_local_initializer(system->topology().cpu_set(), [&init_counter] { + resources->register_thread_local_initializer(system_cpuset, [&init_counter] { init_counter++; }); EXPECT_EQ(init_counter, 2); EXPECT_EQ(fini_counter, 0); - resources->register_thread_local_finalizer(system->topology().cpu_set(), [&fini_counter] { + resources->register_thread_local_finalizer(system_cpuset, [&fini_counter] { fini_counter++; }); @@ -248,16 +286,14 @@ TEST_F(TestSystem, ThreadInitializersAndFinalizers) TEST_F(TestSystem, ThreadPool) { - auto system = system::make_system(make_options([](Options& options) { + auto resources = tests::make_threading_resources([](Options& options) { options.topology().user_cpuset("0-3"); options.topology().restrict_gpus(true); - })); + }); std::atomic counter = 0; - system::Resources resources((system::SystemProvider(system))); - - auto thread_pool = std::make_unique(resources, CpuSet("2-3"), 2); + auto thread_pool = std::make_unique(*resources, CpuSet("2-3"), 2); auto f = [&counter] { ++counter; @@ -280,3 +316,16 @@ TEST_F(TestSystem, ThreadPool) EXPECT_EQ(counter, 3); EXPECT_EQ(ids.size(), 2); } + +TEST_F(TestSystem, ThreadFiberPoolException) +{ + auto resources = tests::make_threading_resources(); + + auto pool = resources->make_fiber_pool(CpuSet("0")); + + auto future = pool.enqueue(0, []() -> int { + throw exceptions::MrcRuntimeError("Test exception"); + }); + + EXPECT_ANY_THROW(future.get()); +} diff --git a/cpp/mrc/src/tests/test_topology.cpp b/cpp/mrc/src/tests/test_topology.cpp index 8e82d1734..9a0095798 100644 --- a/cpp/mrc/src/tests/test_topology.cpp +++ b/cpp/mrc/src/tests/test_topology.cpp @@ -97,14 +97,14 @@ TEST_F(TestTopology, Bitmap) TEST_F(TestTopology, TopologyOptions) { auto options = std::make_unique(); - auto topology = internal::system::Topology::Create(*options); + auto topology = system::Topology::Create(*options); EXPECT_GT(topology->cpu_count(), 1); auto full_numa = topology->numa_count(); options->use_process_cpuset(false); options->user_cpuset("0"); - topology = internal::system::Topology::Create(*options); + topology = system::Topology::Create(*options); EXPECT_EQ(topology->cpu_count(), 1); EXPECT_EQ(topology->numa_count(), 1); @@ -113,12 +113,12 @@ TEST_F(TestTopology, TopologyOptions) // impossible cpu_set options->user_cpuset("9999999"); - EXPECT_ANY_THROW(topology = internal::system::Topology::Create(*options)); + EXPECT_ANY_THROW(topology = system::Topology::Create(*options)); // should receive a warning options->user_cpuset("0,9999999"); LOG(INFO) << "*** expect a warning below this mark ***"; - topology = internal::system::Topology::Create(*options); + topology = system::Topology::Create(*options); LOG(INFO) << "*** expect a warning above this mark ***"; if (full_numa > 1) @@ -126,7 +126,7 @@ TEST_F(TestTopology, TopologyOptions) options->restrict_numa_domains(false); options->use_process_cpuset(false); options->user_cpuset("0"); - topology = internal::system::Topology::Create(*options); + topology = system::Topology::Create(*options); EXPECT_EQ(topology->cpu_count(), 1); EXPECT_EQ(topology->numa_count(), full_numa); } @@ -142,7 +142,7 @@ TEST_F(TestTopology, HwlocDev) hwloc_topology_init(&topology); auto* cpu_set = hwloc_bitmap_alloc(); - EXPECT_EQ(mrc::internal::system::DeviceInfo::GetDeviceCpuset(topology, 0, cpu_set), 0); + EXPECT_EQ(mrc::system::DeviceInfo::GetDeviceCpuset(topology, 0, cpu_set), 0); char* cpuset_string = nullptr; hwloc_bitmap_asprintf(&cpuset_string, cpu_set); @@ -172,7 +172,7 @@ TEST_F(TestTopology, HwlocDev) TEST_F(TestTopology, ExportXML) { - auto topology = internal::system::Topology::Create(); + auto topology = system::Topology::Create(); auto xml = topology->export_xml(); auto pos = xml.find("object type=\"Machine\""); @@ -181,9 +181,9 @@ TEST_F(TestTopology, ExportXML) TEST_F(TestTopology, Codable) { - auto topology = internal::system::Topology::Create(); + auto topology = system::Topology::Create(); auto encoded = topology->serialize(); - auto decoded = internal::system::Topology::Create(encoded); + auto decoded = system::Topology::Create(encoded); EXPECT_EQ(topology->cpu_set().str(), decoded->cpu_set().str()); EXPECT_EQ(topology->cpu_count(), decoded->cpu_count()); diff --git a/cpp/mrc/src/tests/test_ucx.cpp b/cpp/mrc/src/tests/test_ucx.cpp index 017deac1a..a80321017 100644 --- a/cpp/mrc/src/tests/test_ucx.cpp +++ b/cpp/mrc/src/tests/test_ucx.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ #include using namespace mrc; -using namespace internal::ucx; +using namespace ucx; class TestUCX : public ::testing::Test { diff --git a/cpp/mrc/tests/benchmarking/test_benchmarking.hpp b/cpp/mrc/tests/benchmarking/test_benchmarking.hpp index 4907e54c2..99de4e475 100644 --- a/cpp/mrc/tests/benchmarking/test_benchmarking.hpp +++ b/cpp/mrc/tests/benchmarking/test_benchmarking.hpp @@ -19,11 +19,10 @@ #include "mrc/benchmarking/segment_watcher.hpp" #include "mrc/benchmarking/tracer.hpp" -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/node/rx_node.hpp" #include "mrc/node/rx_sink.hpp" #include "mrc/node/rx_source.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/segment/builder.hpp" #include "mrc/segment/object.hpp" @@ -56,7 +55,7 @@ class LatencyBenchmarkTests : public ::testing::Test std::uniform_int_distribution<> dist(10, 100); m_iterations = dist(generator); - auto init = [this](segment::Builder& segment) { + auto init = [this](segment::IBuilder& segment) { std::string src_name = "nsrc"; std::string int_name = "n1"; std::string sink_name = "nsink"; @@ -85,7 +84,7 @@ class LatencyBenchmarkTests : public ::testing::Test segment.make_edge(internal, sink); }; - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); auto segment = pipeline->make_segment("bench_segment", init); std::shared_ptr executor = std::make_shared(); @@ -118,7 +117,7 @@ class ThroughputBenchmarkTests : public ::testing::Test std::uniform_int_distribution<> dist(10, 100); m_iterations = dist(generator); - auto init = [this](segment::Builder& segment) { + auto init = [this](segment::IBuilder& segment) { std::string src_name = "nsrc"; std::string int_name = "n1"; std::string sink_name = "nsink"; @@ -147,7 +146,7 @@ class ThroughputBenchmarkTests : public ::testing::Test segment.make_edge(internal, sink); }; - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); auto segment = pipeline->make_segment("bench_segment", init); std::shared_ptr executor = std::make_shared(); diff --git a/cpp/mrc/tests/benchmarking/test_stat_gather.cpp b/cpp/mrc/tests/benchmarking/test_stat_gather.cpp index aa6f86ce1..1b698198f 100644 --- a/cpp/mrc/tests/benchmarking/test_stat_gather.cpp +++ b/cpp/mrc/tests/benchmarking/test_stat_gather.cpp @@ -21,9 +21,8 @@ #include "mrc/benchmarking/trace_statistics.hpp" #include "mrc/benchmarking/util.hpp" -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/options/options.hpp" +#include "mrc/pipeline/executor.hpp" #include @@ -41,6 +40,11 @@ void stat_check_helper(nlohmann::json metrics, EXPECT_EQ(metrics["component_emissions_total"].get(), emit); } +std::string build_global_name(const std::string& segment_name, const std::string& component_name) +{ + return "/" + segment_name + "/" + component_name; +} + namespace mrc { TEST_F(StatGatherTest, TestStatisticsOperatorGather) @@ -53,19 +57,21 @@ TEST_F(StatGatherTest, TestStatisticsOperatorGather) executor.start(); executor.join(); + std::string seg_name = "segment_stats_test"; std::set required_components = {"src", "internal_1", "internal_2", "sink"}; auto framework_stats_info = TraceStatistics::aggregate(); - auto& component_metrics = framework_stats_info["aggregations"]["components"]["metrics"]; + auto& metrics = framework_stats_info["aggregations"]["components"]["metrics"]; for (const auto& component : required_components) { - EXPECT_EQ(component_metrics.contains(component), true) << component << " not found"; + EXPECT_EQ(metrics.contains(build_global_name(seg_name, component)), true) + << build_global_name(seg_name, component) << " not found"; } - stat_check_helper(component_metrics["src"], 0, 0, 0, m_iterations); - stat_check_helper(component_metrics["internal_1"], 0, m_iterations, 0, m_iterations); - stat_check_helper(component_metrics["internal_2"], 0, m_iterations, 0, m_iterations); - stat_check_helper(component_metrics["sink"], 0, m_iterations, 0, 0); + stat_check_helper(metrics[build_global_name(seg_name, "src")], 0, 0, 0, m_iterations); + stat_check_helper(metrics[build_global_name(seg_name, "internal_1")], 0, m_iterations, 0, m_iterations); + stat_check_helper(metrics[build_global_name(seg_name, "internal_2")], 0, m_iterations, 0, m_iterations); + stat_check_helper(metrics[build_global_name(seg_name, "sink")], 0, m_iterations, 0, 0); TraceStatistics::reset(); } @@ -80,19 +86,21 @@ TEST_F(StatGatherTest, TestStatisticsChannelGather) executor.start(); executor.join(); + std::string seg_name = "segment_stats_test"; std::set required_components = {"src", "internal_1", "internal_2", "sink"}; auto framework_stats_info = TraceStatistics::aggregate(); - auto& component_metrics = framework_stats_info["aggregations"]["components"]["metrics"]; + auto& metrics = framework_stats_info["aggregations"]["components"]["metrics"]; for (const auto& component : required_components) { - EXPECT_EQ(component_metrics.contains(component), true); + EXPECT_EQ(metrics.contains(build_global_name(seg_name, component)), true) + << build_global_name(seg_name, component) << " not found"; } - stat_check_helper(component_metrics["src"], 0, 0, m_iterations, 0); - stat_check_helper(component_metrics["internal_1"], m_iterations, 0, m_iterations, 0); - stat_check_helper(component_metrics["internal_2"], m_iterations, 0, m_iterations, 0); - stat_check_helper(component_metrics["sink"], m_iterations, 0, 0, 0); + stat_check_helper(metrics[build_global_name(seg_name, "src")], 0, 0, m_iterations, 0); + stat_check_helper(metrics[build_global_name(seg_name, "internal_1")], m_iterations, 0, m_iterations, 0); + stat_check_helper(metrics[build_global_name(seg_name, "internal_2")], m_iterations, 0, m_iterations, 0); + stat_check_helper(metrics[build_global_name(seg_name, "sink")], m_iterations, 0, 0, 0); TraceStatistics::reset(); } @@ -108,17 +116,28 @@ TEST_F(StatGatherTest, TestStatisticsFullGather) executor.start(); executor.join(); + std::string seg_name = "segment_stats_test"; + auto framework_stats_info = TraceStatistics::aggregate(); - auto& component_metrics = framework_stats_info["aggregations"]["components"]["metrics"]; + auto& metrics = framework_stats_info["aggregations"]["components"]["metrics"]; for (const auto& component : m_components) { - EXPECT_EQ(component_metrics.contains(component), true); + EXPECT_EQ(metrics.contains(build_global_name(seg_name, component)), true) + << build_global_name(seg_name, component) << " not found"; } - stat_check_helper(component_metrics["src"], 0, 0, m_iterations, m_iterations); - stat_check_helper(component_metrics["internal_1"], m_iterations, m_iterations, m_iterations, m_iterations); - stat_check_helper(component_metrics["internal_2"], m_iterations, m_iterations, m_iterations, m_iterations); - stat_check_helper(component_metrics["sink"], m_iterations, m_iterations, 0, 0); + stat_check_helper(metrics[build_global_name(seg_name, "src")], 0, 0, m_iterations, m_iterations); + stat_check_helper(metrics[build_global_name(seg_name, "internal_1")], + m_iterations, + m_iterations, + m_iterations, + m_iterations); + stat_check_helper(metrics[build_global_name(seg_name, "internal_2")], + m_iterations, + m_iterations, + m_iterations, + m_iterations); + stat_check_helper(metrics[build_global_name(seg_name, "sink")], m_iterations, m_iterations, 0, 0); TraceStatistics::reset(); } diff --git a/cpp/mrc/tests/benchmarking/test_stat_gather.hpp b/cpp/mrc/tests/benchmarking/test_stat_gather.hpp index 41449b4c5..746be4356 100644 --- a/cpp/mrc/tests/benchmarking/test_stat_gather.hpp +++ b/cpp/mrc/tests/benchmarking/test_stat_gather.hpp @@ -23,7 +23,6 @@ #include "mrc/pipeline/pipeline.hpp" #include "mrc/segment/builder.hpp" #include "mrc/segment/object.hpp" -#include "mrc/segment/segment.hpp" #include #include @@ -55,9 +54,9 @@ class StatGatherTest : public ::testing::Test std::uniform_int_distribution<> dist(10, 100); m_iterations = dist(generator); - m_pipeline = pipeline::make_pipeline(); + m_pipeline = mrc::make_pipeline(); - auto init = [this](segment::Builder& segment) { + auto init = [this](segment::IBuilder& segment) { auto src = segment.make_source("src", [this](rxcpp::subscriber s) { for (auto i = 0; i < m_iterations; ++i) { @@ -92,15 +91,13 @@ class StatGatherTest : public ::testing::Test segment.make_edge(internal_2, sink); }; - auto segdef = Segment::create("segment_stats_test", init); - - m_pipeline->register_segment(segdef); + m_pipeline->make_segment("segment_stats_test", init); } void TearDown() override {} std::size_t m_iterations; - std::unique_ptr m_pipeline; + std::unique_ptr m_pipeline; std::shared_ptr m_resources; std::set m_components = {"src", "internal_1", "internal_2", "sink"}; }; diff --git a/cpp/mrc/tests/benchmarking/test_utils.cpp b/cpp/mrc/tests/benchmarking/test_utils.cpp index 6c949174a..fc9c4c549 100644 --- a/cpp/mrc/tests/benchmarking/test_utils.cpp +++ b/cpp/mrc/tests/benchmarking/test_utils.cpp @@ -25,9 +25,9 @@ #include "mrc/benchmarking/trace_statistics.hpp" #include "mrc/benchmarking/tracer.hpp" #include "mrc/benchmarking/util.hpp" -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/options/options.hpp" +#include "mrc/pipeline/executor.hpp" +#include "mrc/pipeline/pipeline.hpp" #include #include diff --git a/cpp/mrc/tests/coroutines/test_event.cpp b/cpp/mrc/tests/coroutines/test_event.cpp index 61326e0b3..68689637d 100644 --- a/cpp/mrc/tests/coroutines/test_event.cpp +++ b/cpp/mrc/tests/coroutines/test_event.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include using namespace mrc; diff --git a/cpp/mrc/tests/coroutines/test_latch.cpp b/cpp/mrc/tests/coroutines/test_latch.cpp index 5be3b31e7..1136bf76e 100644 --- a/cpp/mrc/tests/coroutines/test_latch.cpp +++ b/cpp/mrc/tests/coroutines/test_latch.cpp @@ -44,6 +44,7 @@ #include #include +#include using namespace mrc; diff --git a/cpp/mrc/tests/coroutines/test_ring_buffer.cpp b/cpp/mrc/tests/coroutines/test_ring_buffer.cpp index a5b0163a2..fb9afa1c4 100644 --- a/cpp/mrc/tests/coroutines/test_ring_buffer.cpp +++ b/cpp/mrc/tests/coroutines/test_ring_buffer.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include diff --git a/cpp/mrc/tests/logging/test_logging.cpp b/cpp/mrc/tests/logging/test_logging.cpp index 0d26a82bb..f72cb113c 100644 --- a/cpp/mrc/tests/logging/test_logging.cpp +++ b/cpp/mrc/tests/logging/test_logging.cpp @@ -21,6 +21,8 @@ #include +#include + namespace mrc { TEST_CLASS(Logging); diff --git a/cpp/mrc/tests/modules/dynamic_module.cpp b/cpp/mrc/tests/modules/dynamic_module.cpp index 94aeab4be..3db4e08cd 100644 --- a/cpp/mrc/tests/modules/dynamic_module.cpp +++ b/cpp/mrc/tests/modules/dynamic_module.cpp @@ -41,7 +41,7 @@ class DynamicSourceModule : public SegmentModule DynamicSourceModule(std::string module_name, nlohmann::json config); protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; }; @@ -50,7 +50,7 @@ DynamicSourceModule::DynamicSourceModule(std::string module_name, nlohmann::json SegmentModule(std::move(module_name), std::move(config)) {} -void DynamicSourceModule::initialize(segment::Builder& builder) +void DynamicSourceModule::initialize(segment::IBuilder& builder) { unsigned int count{1}; diff --git a/cpp/mrc/tests/modules/test_mirror_tap_module.cpp b/cpp/mrc/tests/modules/test_mirror_tap_module.cpp index 00da9d9fa..7f68a354b 100644 --- a/cpp/mrc/tests/modules/test_mirror_tap_module.cpp +++ b/cpp/mrc/tests/modules/test_mirror_tap_module.cpp @@ -17,9 +17,7 @@ #include "test_modules.hpp" -#include "mrc/core/executor.hpp" #include "mrc/cuda/device_guard.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/experimental/modules/mirror_tap/mirror_tap.hpp" #include "mrc/modules/properties/persistent.hpp" #include "mrc/node/operators/broadcast.hpp" @@ -28,6 +26,7 @@ #include "mrc/node/rx_source.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/segment/builder.hpp" #include "mrc/segment/egress_ports.hpp" @@ -81,7 +80,7 @@ TEST_F(TestMirrorTapModule, InitailizationTest) auto config = nlohmann::json(); auto mirror_tap = std::make_shared>(test_name + "_mirror_tap", config); - auto init_wrapper_main = [&mirror_tap, &test_name](segment::Builder& builder) { + auto init_wrapper_main = [&mirror_tap, &test_name](segment::IBuilder& builder) { builder.init_module(mirror_tap); auto source = builder.make_source(test_name + "_main_source", @@ -95,7 +94,7 @@ TEST_F(TestMirrorTapModule, InitailizationTest) builder.make_edge(mirror_tap->output_port("output"), sink); }; - auto init_wrapper_mirrored = [&mirror_tap, &test_name](segment::Builder& builder) { + auto init_wrapper_mirrored = [&mirror_tap, &test_name](segment::IBuilder& builder) { auto mirror_ingress = builder.get_ingress(mirror_tap->tap_egress_port_name()); auto mirror_sink = builder.make_sink(test_name + "_mirror_sink", [](std::string input) {}); @@ -135,7 +134,7 @@ TEST_F(TestMirrorTapModule, SinglePipelineMirrorTapTest) auto config = nlohmann::json(); auto mirror_tap = std::make_shared>(test_name + "_mirror_tap", config); - auto init_wrapper_main = [&packets_main, &mirror_tap, &test_name](segment::Builder& builder) { + auto init_wrapper_main = [&packets_main, &mirror_tap, &test_name](segment::IBuilder& builder) { builder.init_module(mirror_tap); auto source = builder.make_source(test_name + "_main_source", @@ -161,7 +160,7 @@ TEST_F(TestMirrorTapModule, SinglePipelineMirrorTapTest) builder.make_edge(mirror_tap->output_port("output"), sink); }; - auto init_wrapper_mirrored = [&packets_mirrored, &mirror_tap, &test_name](segment::Builder& builder) { + auto init_wrapper_mirrored = [&packets_mirrored, &mirror_tap, &test_name](segment::IBuilder& builder) { auto mirror_ingress = builder.get_ingress(mirror_tap->tap_egress_port_name()); auto mirror_sink = builder.make_sink(test_name + "_mirror_sink", [&packets_mirrored](std::string input) { @@ -213,7 +212,7 @@ TEST_F(TestMirrorTapModule, SinglePipelineMultiInlineMirrorTapTest) auto mirror_tap_one = std::make_shared>(test_name + "_mirror_tap_one", config); auto mirror_tap_two = std::make_shared>(test_name + "_mirror_tap_two", config); - auto init_wrapper_main = [&packets_main, &mirror_tap_one, &mirror_tap_two, &test_name](segment::Builder& builder) { + auto init_wrapper_main = [&packets_main, &mirror_tap_one, &mirror_tap_two, &test_name](segment::IBuilder& builder) { builder.init_module(mirror_tap_one); builder.init_module(mirror_tap_two); @@ -250,7 +249,7 @@ TEST_F(TestMirrorTapModule, SinglePipelineMultiInlineMirrorTapTest) auto multi_sink_mirror_one = std::make_shared>(test_name + "_multi_sink_mirror_1"); - auto init_wrapper_mirrored_one = [&mirror_tap_one, &multi_sink_mirror_one, test_name](segment::Builder& builder) { + auto init_wrapper_mirrored_one = [&mirror_tap_one, &multi_sink_mirror_one, test_name](segment::IBuilder& builder) { auto mirror_ingress_one = builder.get_ingress(mirror_tap_one->tap_egress_port_name()); builder.init_module(multi_sink_mirror_one); @@ -259,7 +258,7 @@ TEST_F(TestMirrorTapModule, SinglePipelineMultiInlineMirrorTapTest) auto multi_sink_mirror_two = std::make_shared>(test_name + "_multi_sink_mirror_2"); - auto init_wrapper_mirrored_two = [&mirror_tap_two, &multi_sink_mirror_two, test_name](segment::Builder& builder) { + auto init_wrapper_mirrored_two = [&mirror_tap_two, &multi_sink_mirror_two, test_name](segment::IBuilder& builder) { auto mirror_ingress_two = builder.get_ingress(mirror_tap_two->tap_egress_port_name()); builder.init_module(multi_sink_mirror_two); @@ -318,7 +317,7 @@ TEST_F(TestMirrorTapModule, SinglePipelineMultiMirrorTapTest) auto mirror_tap_three = std::make_shared>(test_name + "_mirror_tap_three", config); auto multi_sink_main = std::make_shared>(test_name + "_multi_sink_main"); auto init_wrapper_main = [&mirror_tap_one, &mirror_tap_two, &mirror_tap_three, &multi_sink_main, &test_name]( - segment::Builder& builder) { + segment::IBuilder& builder) { builder.init_module(mirror_tap_one); builder.init_module(mirror_tap_two); builder.init_module(mirror_tap_three); @@ -340,7 +339,7 @@ TEST_F(TestMirrorTapModule, SinglePipelineMultiMirrorTapTest) auto multi_sink_mirror = std::make_shared>(test_name + "_multi_sink_mirror"); auto init_wrapper_mirrored = - [&mirror_tap_one, &mirror_tap_two, &mirror_tap_three, &multi_sink_mirror](segment::Builder& builder) { + [&mirror_tap_one, &mirror_tap_two, &mirror_tap_three, &multi_sink_mirror](segment::IBuilder& builder) { auto mirror_ingress_one = builder.get_ingress(mirror_tap_one->tap_egress_port_name()); auto mirror_ingress_two = builder.get_ingress(mirror_tap_two->tap_egress_port_name()); auto mirror_ingress_three = builder.get_ingress(mirror_tap_three->tap_egress_port_name()); diff --git a/cpp/mrc/tests/modules/test_mirror_tap_orchestrator.cpp b/cpp/mrc/tests/modules/test_mirror_tap_orchestrator.cpp index 1ee0cdc66..ceeba44e2 100644 --- a/cpp/mrc/tests/modules/test_mirror_tap_orchestrator.cpp +++ b/cpp/mrc/tests/modules/test_mirror_tap_orchestrator.cpp @@ -17,9 +17,7 @@ #include "test_modules.hpp" -#include "mrc/core/executor.hpp" #include "mrc/cuda/device_guard.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/experimental/modules/mirror_tap/mirror_tap_orchestrator.hpp" #include "mrc/modules/properties/persistent.hpp" #include "mrc/node/operators/broadcast.hpp" @@ -27,6 +25,7 @@ #include "mrc/node/rx_source.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/segment/builder.hpp" #include "mrc/segment/egress_ports.hpp" @@ -59,7 +58,7 @@ TEST_F(TestMirrorTapUtil, SinglePipelineTapAndBufferTest) auto config = nlohmann::json(); - auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::Builder& builder) { + auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::IBuilder& builder) { auto source = builder.make_source(test_name + "_main_source", [packet_count](rxcpp::subscriber& sub) { if (sub.is_subscribed()) @@ -81,7 +80,7 @@ TEST_F(TestMirrorTapUtil, SinglePipelineTapAndBufferTest) builder.make_edge(source, sink); }; - auto init_wrapper_mirrored = [&packets_mirrored, test_name](segment::Builder& builder) { + auto init_wrapper_mirrored = [&packets_mirrored, test_name](segment::IBuilder& builder) { auto mirror_sink = builder.make_sink(test_name + "_mirror_sink", [&packets_mirrored](std::string input) { VLOG(10) << "tick -> " << input << std::endl @@ -134,7 +133,7 @@ TEST_F(TestMirrorTapUtil, SinglePipelineTapAndBufferWithAdditionalPortsTest) auto config = nlohmann::json(); - auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::Builder& builder) { + auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::IBuilder& builder) { auto source = builder.make_source(test_name + "_main_source", [packet_count](rxcpp::subscriber& sub) { if (sub.is_subscribed()) @@ -170,7 +169,7 @@ TEST_F(TestMirrorTapUtil, SinglePipelineTapAndBufferWithAdditionalPortsTest) builder.make_edge(extra_source, extra_egress); }; - auto init_wrapper_mirrored = [&packets_mirrored, &packets_non_mirrored, test_name](segment::Builder& builder) { + auto init_wrapper_mirrored = [&packets_mirrored, &packets_non_mirrored, test_name](segment::IBuilder& builder) { auto mirror_sink = builder.make_sink(test_name + "_mirror_sink", [&packets_mirrored](std::string input) { packets_mirrored++; diff --git a/cpp/mrc/tests/modules/test_module_registry.cpp b/cpp/mrc/tests/modules/test_module_registry.cpp index ecc4bf1ca..62b9f9353 100644 --- a/cpp/mrc/tests/modules/test_module_registry.cpp +++ b/cpp/mrc/tests/modules/test_module_registry.cpp @@ -17,8 +17,6 @@ #include "test_modules.hpp" -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/modules/module_registry.hpp" #include "mrc/modules/plugins.hpp" #include "mrc/modules/properties/persistent.hpp" @@ -27,12 +25,12 @@ #include "mrc/node/rx_sink.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/segment/builder.hpp" #include "mrc/segment/object.hpp" #include "mrc/version.hpp" -#include #include #include #include @@ -41,6 +39,7 @@ #include #include +#include #include #include #include @@ -189,7 +188,7 @@ std::string get_modules_path() std::vector path_buffer(sz_path_buffer + 1); readlink(link_id.c_str(), path_buffer.data(), sz_path_buffer); - boost::filesystem::path whereami(path_buffer.data()); + std::filesystem::path whereami(path_buffer.data()); std::string modules_path = whereami.parent_path().string() + "/modules/"; @@ -261,7 +260,7 @@ TEST_F(TestModuleRegistry, DynamicModuleRegistrationTest) unsigned int packet_count{0}; - auto init_wrapper = [&packet_count](segment::Builder& builder) { + auto init_wrapper = [&packet_count](segment::IBuilder& builder) { auto config = nlohmann::json(); unsigned int source_count{42}; config["source_count"] = source_count; diff --git a/cpp/mrc/tests/modules/test_modules.hpp b/cpp/mrc/tests/modules/test_modules.hpp index cecb0ee44..415c0111f 100644 --- a/cpp/mrc/tests/modules/test_modules.hpp +++ b/cpp/mrc/tests/modules/test_modules.hpp @@ -19,16 +19,15 @@ #include "../test_mrc.hpp" // IWYU pragma: keep -#include "mrc/core/executor.hpp" #include "mrc/modules/properties/persistent.hpp" #include "mrc/modules/segment_modules.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" #include "mrc/pipeline/pipeline.hpp" +#include "mrc/pipeline/segment.hpp" #include "mrc/segment/builder.hpp" #include "mrc/segment/egress_ports.hpp" #include "mrc/segment/ingress_ports.hpp" -#include "mrc/segment/segment.hpp" #include #include @@ -62,13 +61,13 @@ class TestModules : public ::testing::Test protected: void SetUp() override { - m_pipeline = pipeline::make_pipeline(); + m_pipeline = mrc::make_pipeline(); m_resources = std::make_shared(); } void TearDown() override {} - std::unique_ptr m_pipeline; + std::unique_ptr m_pipeline; std::shared_ptr m_resources; }; @@ -85,13 +84,13 @@ class [[maybe_unused]] MultiSourceModule : public modules::SegmentModule {} protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; }; template -void MultiSourceModule::initialize(segment::Builder& builder) +void MultiSourceModule::initialize(segment::IBuilder& builder) { for (std::size_t i = 0; i < SourceCountV; ++i) { @@ -144,7 +143,7 @@ class [[maybe_unused]] MultiSinkModule : public modules::SegmentModule, public m std::size_t get_received(std::size_t index) const; protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; @@ -160,7 +159,7 @@ std::size_t MultiSinkModule::get_received(std::size_t ind } template -void MultiSinkModule::initialize(segment::Builder& builder) +void MultiSinkModule::initialize(segment::IBuilder& builder) { for (std::size_t i = 0; i < SinkCountV; ++i) { diff --git a/cpp/mrc/tests/modules/test_segment_modules.cpp b/cpp/mrc/tests/modules/test_segment_modules.cpp index 81635fcb8..6c23a930f 100644 --- a/cpp/mrc/tests/modules/test_segment_modules.cpp +++ b/cpp/mrc/tests/modules/test_segment_modules.cpp @@ -17,8 +17,6 @@ #include "test_modules.hpp" -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/modules/properties/persistent.hpp" #include "mrc/modules/sample_modules.hpp" #include "mrc/modules/segment_modules.hpp" @@ -26,6 +24,7 @@ #include "mrc/node/rx_source.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/segment/builder.hpp" #include "mrc/segment/object.hpp" @@ -68,7 +67,7 @@ TEST_F(TestSegmentModules, ModuleInitializationTest) { using namespace modules; - auto init_wrapper = [](segment::Builder& builder) { + auto init_wrapper = [](segment::IBuilder& builder) { auto config_1 = nlohmann::json(); auto config_2 = nlohmann::json(); config_2["config_key_1"] = true; @@ -130,7 +129,7 @@ TEST_F(TestSegmentModules, ModuleEndToEndTest) unsigned int packets_2{0}; unsigned int packets_3{0}; - auto init_wrapper = [&packets_1, &packets_2, &packets_3](segment::Builder& builder) { + auto init_wrapper = [&packets_1, &packets_2, &packets_3](segment::IBuilder& builder) { auto simple_mod = builder.make_module("ModuleEndToEndTest_mod1"); auto configurable_mod = builder.make_module("ModuleEndToEndTest_mod2"); @@ -224,7 +223,7 @@ TEST_F(TestSegmentModules, ModuleAsSourceTest) unsigned int packet_count{0}; - auto init_wrapper = [&packet_count](segment::Builder& builder) { + auto init_wrapper = [&packet_count](segment::IBuilder& builder) { auto config = nlohmann::json(); unsigned int source_count{42}; config["source_count"] = source_count; @@ -259,7 +258,7 @@ TEST_F(TestSegmentModules, ModuleAsSinkTest) unsigned int packet_count{0}; - auto init_wrapper = [&packet_count](segment::Builder& builder) { + auto init_wrapper = [&packet_count](segment::IBuilder& builder) { auto source = builder.make_source("source", [&packet_count](rxcpp::subscriber& sub) { if (sub.is_subscribed()) { @@ -297,7 +296,7 @@ TEST_F(TestSegmentModules, ModuleChainingTest) using namespace modules; auto sink_mod = std::make_shared("ModuleChainingTest_mod2"); - auto init_wrapper = [&sink_mod](segment::Builder& builder) { + auto init_wrapper = [&sink_mod](segment::IBuilder& builder) { auto config = nlohmann::json(); unsigned int source_count{42}; config["source_count"] = source_count; @@ -328,7 +327,7 @@ TEST_F(TestSegmentModules, ModuleNestingTest) unsigned int packet_count{0}; - auto init_wrapper = [&packet_count](segment::Builder& builder) { + auto init_wrapper = [&packet_count](segment::IBuilder& builder) { auto nested_mod = builder.make_module("ModuleNestingTest_mod1"); auto nested_sink = builder.make_sink("nested_sink", [&packet_count](std::string input) { @@ -360,7 +359,7 @@ TEST_F(TestSegmentModules, ModuleTemplateTest) unsigned int packet_count_1{0}; unsigned int packet_count_2{0}; - auto init_wrapper = [&packet_count_1, &packet_count_2](segment::Builder& builder) { + auto init_wrapper = [&packet_count_1, &packet_count_2](segment::IBuilder& builder) { using data_type_1_t = int; using data_type_2_t = std::string; @@ -426,7 +425,7 @@ TEST_F(TestSegmentModules, ModuleTemplateWithInitTest) unsigned int packet_count_1{0}; unsigned int packet_count_2{0}; - auto init_wrapper = [&packet_count_1, &packet_count_2](segment::Builder& builder) { + auto init_wrapper = [&packet_count_1, &packet_count_2](segment::IBuilder& builder) { using data_type_1_t = int; using data_type_2_t = std::string; diff --git a/cpp/mrc/tests/modules/test_stream_buffer_modules.cpp b/cpp/mrc/tests/modules/test_stream_buffer_modules.cpp index 07eb8bb2a..c5cb376f8 100644 --- a/cpp/mrc/tests/modules/test_stream_buffer_modules.cpp +++ b/cpp/mrc/tests/modules/test_stream_buffer_modules.cpp @@ -17,9 +17,7 @@ #include "test_modules.hpp" -#include "mrc/core/executor.hpp" #include "mrc/cuda/device_guard.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/experimental/modules/stream_buffer/stream_buffer_base.hpp" #include "mrc/experimental/modules/stream_buffer/stream_buffer_immediate.hpp" #include "mrc/experimental/modules/stream_buffer/stream_buffer_module.hpp" @@ -28,6 +26,7 @@ #include "mrc/node/rx_source.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/segment/builder.hpp" #include "mrc/segment/object.hpp" @@ -58,7 +57,7 @@ TEST_F(TestStreamBufferModule, InitailizationTest) { using namespace modules; - auto init_wrapper = [](segment::Builder& builder) { + auto init_wrapper = [](segment::IBuilder& builder) { auto config1 = nlohmann::json(); auto mirror_buffer1 = builder.make_module("mirror_tap", config1); }; @@ -84,7 +83,7 @@ TEST_F(TestStreamBufferModule, SinglePipelineImmediateStreamBufferRawThroughputT unsigned int packet_count{100000}; unsigned int packets_main{0}; - auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::Builder& builder) { + auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::IBuilder& builder) { auto source = builder.make_source(test_name + "_main_source", [packet_count](rxcpp::subscriber& sub) { if (sub.is_subscribed()) @@ -135,7 +134,7 @@ TEST_F(TestStreamBufferModule, SinglePipelineImmediateStreamBufferConstantRateTh unsigned int packet_count{10000}; unsigned int packets_main{0}; - auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::Builder& builder) { + auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::IBuilder& builder) { auto source = builder.make_source( test_name + "_main_source", [packet_count](rxcpp::subscriber& sub) { @@ -188,7 +187,7 @@ TEST_F(TestStreamBufferModule, SinglePipelineImmediateStreamBufferVariableRateTh unsigned int packet_count{100000}; unsigned int packets_main{0}; - auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::Builder& builder) { + auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::IBuilder& builder) { auto source = builder.make_source( test_name + "_main_source", [packet_count](rxcpp::subscriber& sub) { @@ -248,7 +247,7 @@ TEST_F(TestStreamBufferModule, SinglePipelineImmediateStreamBufferBurstThroughpu auto config = nlohmann::json{{"buffer_size", 1024}}; - auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::Builder& builder) { + auto init_wrapper_main = [&packets_main, packet_count, test_name](segment::IBuilder& builder) { auto source = builder.make_source( test_name + "_main_source", [packet_count](rxcpp::subscriber& sub) { diff --git a/cpp/mrc/tests/test_channel.cpp b/cpp/mrc/tests/test_channel.cpp index 57cb3997b..6d796dba6 100644 --- a/cpp/mrc/tests/test_channel.cpp +++ b/cpp/mrc/tests/test_channel.cpp @@ -35,6 +35,7 @@ #include // for uint64_t #include // for ref, reference_wrapper #include +#include #include // IWYU thinks algorithm is needed for: auto channel = std::make_shared>(2); // IWYU pragma: no_include diff --git a/cpp/mrc/tests/test_executor.cpp b/cpp/mrc/tests/test_executor.cpp index 59383e540..e8da2fe0b 100644 --- a/cpp/mrc/tests/test_executor.cpp +++ b/cpp/mrc/tests/test_executor.cpp @@ -15,14 +15,13 @@ * limitations under the License. */ -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/node/rx_node.hpp" #include "mrc/node/rx_sink.hpp" #include "mrc/node/rx_source.hpp" #include "mrc/options/engine_groups.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/runnable/context.hpp" #include "mrc/runnable/launch_options.hpp" @@ -31,7 +30,6 @@ #include "mrc/segment/egress_ports.hpp" #include "mrc/segment/ingress_ports.hpp" #include "mrc/segment/object.hpp" -#include "mrc/segment/segment.hpp" #include #include @@ -65,7 +63,7 @@ class TestExecutor : public ::testing::Test // static std::pair, std::shared_ptr>> // make_two_node_pipeline() // { - // auto pipeline = pipeline::make_pipeline(); + // auto pipeline = mrc::make_pipeline(); // auto source = std::make_shared>("source", "channel"); // auto sink = std::make_shared>("sink", "channel"); @@ -74,14 +72,14 @@ class TestExecutor : public ::testing::Test // return std::make_pair(std::move(pipeline), std::move(source)); // } - static std::unique_ptr make_pipeline() + static std::unique_ptr make_pipeline() { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); - auto segment_initializer = [](segment::Builder& seg) {}; + auto segment_initializer = [](segment::IBuilder& seg) {}; // ideally we make this a true source (seg_1) and true source (seg_4) - auto seg_1 = Segment::create("seg_1", segment::EgressPorts({"my_int2"}), [](segment::Builder& s) { + pipeline->make_segment("seg_1", segment::EgressPorts({"my_int2"}), [](segment::IBuilder& s) { auto src = s.make_source("rx_source", [](rxcpp::subscriber s) { s.on_next(1); s.on_next(2); @@ -91,25 +89,25 @@ class TestExecutor : public ::testing::Test auto egress = s.get_egress("my_int2"); s.make_edge(src, egress); }); - auto seg_2 = Segment::create("seg_2", - segment::IngressPorts({"my_int2"}), - segment::EgressPorts({"my_int3"}), - [](segment::Builder& s) { - // pure pass-thru - auto in = s.get_ingress("my_int2"); - auto out = s.get_egress("my_int3"); - s.make_edge(in, out); - }); - auto seg_3 = Segment::create("seg_3", - segment::IngressPorts({"my_int3"}), - segment::EgressPorts({"my_int4"}), - [](segment::Builder& s) { - // pure pass-thru - auto in = s.get_ingress("my_int3"); - auto out = s.get_egress("my_int4"); - s.make_edge(in, out); - }); - auto seg_4 = Segment::create("seg_4", segment::IngressPorts({"my_int4"}), [](segment::Builder& s) { + pipeline->make_segment("seg_2", + segment::IngressPorts({"my_int2"}), + segment::EgressPorts({"my_int3"}), + [](segment::IBuilder& s) { + // pure pass-thru + auto in = s.get_ingress("my_int2"); + auto out = s.get_egress("my_int3"); + s.make_edge(in, out); + }); + pipeline->make_segment("seg_3", + segment::IngressPorts({"my_int3"}), + segment::EgressPorts({"my_int4"}), + [](segment::IBuilder& s) { + // pure pass-thru + auto in = s.get_ingress("my_int3"); + auto out = s.get_egress("my_int4"); + s.make_edge(in, out); + }); + pipeline->make_segment("seg_4", segment::IngressPorts({"my_int4"}), [](segment::IBuilder& s) { // pure pass-thru auto in = s.get_ingress("my_int4"); auto sink = s.make_sink("rx_sink", rxcpp::make_observer_dynamic([&](int x) { @@ -119,11 +117,6 @@ class TestExecutor : public ::testing::Test s.make_edge(in, sink); }); - pipeline->register_segment(seg_1); - pipeline->register_segment(seg_2); - pipeline->register_segment(seg_3); - pipeline->register_segment(seg_4); - return pipeline; } @@ -138,7 +131,7 @@ class TestExecutor : public ::testing::Test TEST_F(TestExecutor, LifeCycleSingleSegment) { - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); auto options = make_options(); options->engine_factories().set_engine_factory_options("single_use_threads", [](EngineFactoryOptions& options) { @@ -153,7 +146,7 @@ TEST_F(TestExecutor, LifeCycleSingleSegment) std::atomic src_count = 0; std::atomic node_count = 0; - auto segment = Segment::create("seg_1", [&next_count, &src_count, &node_count](segment::Builder& s) { + pipeline->make_segment("seg_1", [&next_count, &src_count, &node_count](segment::IBuilder& s) { auto rx_source = s.make_source("rx_source", [](rxcpp::subscriber s) { s.on_next(1.0F); s.on_next(2.0F); @@ -191,8 +184,6 @@ TEST_F(TestExecutor, LifeCycleSingleSegment) s.make_edge(rx_node, rx_sink); }); - pipeline->register_segment(segment); - executor.register_pipeline(std::move(pipeline)); executor.start(); @@ -222,11 +213,11 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentOpMuxer) { Executor executor(make_options()); - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); std::atomic next_count = 0; - auto segment = Segment::create("seg_1", [&next_count](segment::Builder& s) { + pipeline->make_segment("seg_1", [&next_count](segment::IBuilder& s) { auto rx_source = s.make_source("rx_source", [](rxcpp::subscriber s) { DVLOG(1) << runnable::Context::get_runtime_context().info(); s.on_next(1.0F); @@ -244,8 +235,6 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentOpMuxer) s.make_edge(rx_source, rx_sink); }); - pipeline->register_segment(segment); - executor.register_pipeline(std::move(pipeline)); executor.start(); @@ -261,11 +250,11 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentOpMuxerOnThreads) Executor executor(std::move(options)); - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); std::atomic next_count = 0; - auto segment = Segment::create("seg_1", [&next_count](segment::Builder& s) { + pipeline->make_segment("seg_1", [&next_count](segment::IBuilder& s) { auto rx_source = s.make_source("rx_source", [](rxcpp::subscriber s) { DVLOG(1) << runnable::Context::get_runtime_context().info(); s.on_next(1.0F); @@ -283,8 +272,6 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentOpMuxerOnThreads) s.make_edge(rx_source, rx_sink); }); - pipeline->register_segment(segment); - executor.register_pipeline(std::move(pipeline)); executor.start(); @@ -300,7 +287,7 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentConcurrentSource) Executor executor(std::move(options)); - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); std::mutex mutex; std::set unique_thread_ids; @@ -310,7 +297,7 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentConcurrentSource) unique_thread_ids.insert(id); }; - auto segment = Segment::create("seg_1", [&add_thread_id](segment::Builder& s) { + pipeline->make_segment("seg_1", [&add_thread_id](segment::IBuilder& s) { auto rx_source = s.make_source("rx_source", [](rxcpp::subscriber s) { auto thread_id_hash = std::hash()(std::this_thread::get_id()); DVLOG(1) << runnable::Context::get_runtime_context().info() << ": hash=" << thread_id_hash; @@ -331,8 +318,6 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentConcurrentSource) s.make_edge(rx_source, rx_sink); }); - pipeline->register_segment(segment); - executor.register_pipeline(std::move(pipeline)); executor.start(); @@ -348,7 +333,7 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentConcurrentSourceWithStaggeredShutdown Executor executor(std::move(options)); - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); std::mutex mutex; std::set unique_thread_ids; @@ -358,7 +343,7 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentConcurrentSourceWithStaggeredShutdown unique_thread_ids.insert(id); }; - auto segment = Segment::create("seg_1", [&add_thread_id](segment::Builder& s) { + pipeline->make_segment("seg_1", [&add_thread_id](segment::IBuilder& s) { auto rx_source = s.make_source("rx_source", [](rxcpp::subscriber s) { auto thread_id_hash = std::hash()(std::this_thread::get_id()); auto& ctx = runnable::Context::get_runtime_context(); @@ -385,8 +370,6 @@ TEST_F(TestExecutor, LifeCycleSingleSegmentConcurrentSourceWithStaggeredShutdown s.make_edge(rx_source, rx_sink); }); - pipeline->register_segment(segment); - executor.register_pipeline(std::move(pipeline)); executor.start(); diff --git a/cpp/mrc/tests/test_node.cpp b/cpp/mrc/tests/test_node.cpp index 8ba8cf15e..428c41d2c 100644 --- a/cpp/mrc/tests/test_node.cpp +++ b/cpp/mrc/tests/test_node.cpp @@ -18,14 +18,13 @@ #include "test_mrc.hpp" #include "mrc/channel/status.hpp" // for Status -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/node/rx_node.hpp" #include "mrc/node/rx_sink.hpp" #include "mrc/node/rx_source.hpp" #include "mrc/options/options.hpp" #include "mrc/options/placement.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" #include "mrc/runnable/context.hpp" #include "mrc/runnable/launch_options.hpp" @@ -68,12 +67,12 @@ INSTANTIATE_TEST_SUITE_P(TestNode, ParallelTests, testing::Values(1, 2, 4)); TEST_F(TestNode, GenericEndToEnd) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic next_count = 0; std::atomic complete_count = 0; - auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { DVLOG(1) << "In Initializer" << std::endl; auto sourceStr1 = seg.make_source("src1", [&](rxcpp::subscriber& s) { @@ -149,12 +148,12 @@ TEST_F(TestNode, GenericEndToEnd) TEST_F(TestNode, GenericEndToEndComponent) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic next_count = 0; std::atomic complete_count = 0; - auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { DVLOG(1) << "In Initializer" << std::endl; auto sourceStr1 = seg.make_source("src1", [&](rxcpp::subscriber& s) { @@ -234,14 +233,14 @@ TEST_F(TestNode, GenericEndToEndComponent) // ======= Replace SourceRoundRobinPolicy with approprate Operator ======= // TEST_F(TestNode, EnsureMoveSemantics) // { -// auto p = pipeline::make_pipeline(); +// auto p = mrc::make_pipeline(); // std::atomic next_count = 0; // std::atomic complete_count = 0; // CopyMoveCounter::reset(); -// auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { +// auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { // auto source = seg.make_source("src1", [&](rxcpp::subscriber& s) { // s.on_next(CopyMoveCounter(1)); // s.on_next(CopyMoveCounter(2)); @@ -314,13 +313,13 @@ TEST_F(TestNode, GenericEndToEndComponent) TEST_F(TestNode, SourceEpilogue) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic next_count = 0; std::atomic complete_count = 0; std::atomic tap_count = 0; - auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { auto source = seg.make_source("src1", [&](rxcpp::subscriber& s) { s.on_next(1); s.on_next(2); @@ -368,13 +367,13 @@ TEST_F(TestNode, SourceEpilogue) TEST_F(TestNode, SinkPrologue) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic next_count = 0; std::atomic complete_count = 0; std::atomic tap_count = 0; - auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { auto source = seg.make_source("src1", [&](rxcpp::subscriber& s) { s.on_next(1); s.on_next(2); @@ -422,14 +421,14 @@ TEST_F(TestNode, SinkPrologue) TEST_F(TestNode, NodePrologueEpilogue) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic sink_sum = 0; std::atomic complete_count = 0; std::atomic prologue_tap_sum = 0; std::atomic epilogue_tap_sum = 0; - auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { auto source = seg.make_source("src1", [&](rxcpp::subscriber& s) { s.on_next(1); s.on_next(2); @@ -489,12 +488,12 @@ TEST_F(TestNode, NodePrologueEpilogue) TEST_F(TestNode, RxNodeComponentThrows) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic throw_count = 0; std::atomic sink_call_count = 0; std::atomic complete_count = 0; - auto my_segment = p->make_segment("test_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("test_segment", [&](segment::IBuilder& seg) { auto source = seg.make_source("source", [&](rxcpp::subscriber& s) { s.on_next(1); s.on_next(2); @@ -547,7 +546,7 @@ TEST_F(TestNode, RxNodeComponentThrows) TEST_P(ParallelTests, SourceMultiThread) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic next_count = 0; std::atomic complete_count = 0; @@ -561,7 +560,7 @@ TEST_P(ParallelTests, SourceMultiThread) ParallelTester parallel_test(source_thread_count); - auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { auto source = seg.make_source("src1", [&](rxcpp::subscriber& s) { auto& context = mrc::runnable::Context::get_runtime_context(); @@ -634,7 +633,7 @@ TEST_P(ParallelTests, SourceMultiThread) TEST_P(ParallelTests, SinkMultiThread) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic next_count = 0; std::atomic complete_count = 0; @@ -648,7 +647,7 @@ TEST_P(ParallelTests, SinkMultiThread) ParallelTester parallel_test(thread_count); - auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { auto source = seg.make_source("src1", [&](rxcpp::subscriber& s) { auto& context = mrc::runnable::Context::get_runtime_context(); @@ -708,7 +707,7 @@ TEST_P(ParallelTests, SinkMultiThread) TEST_P(ParallelTests, NodeMultiThread) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic next_count = 0; std::atomic complete_count = 0; @@ -722,7 +721,7 @@ TEST_P(ParallelTests, NodeMultiThread) ParallelTester parallel_test(thread_count); - auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { auto source = seg.make_source("src1", [&](rxcpp::subscriber& s) { auto& context = mrc::runnable::Context::get_runtime_context(); diff --git a/cpp/mrc/tests/test_pipeline.cpp b/cpp/mrc/tests/test_pipeline.cpp index 583d052cc..c34731302 100644 --- a/cpp/mrc/tests/test_pipeline.cpp +++ b/cpp/mrc/tests/test_pipeline.cpp @@ -15,15 +15,14 @@ * limitations under the License. */ -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/node/rx_sink.hpp" #include "mrc/node/rx_source.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" +#include "mrc/pipeline/segment.hpp" #include "mrc/segment/builder.hpp" -#include "mrc/segment/definition.hpp" #include "mrc/segment/egress_ports.hpp" #include "mrc/segment/ingress_ports.hpp" #include "mrc/segment/object.hpp" @@ -48,7 +47,7 @@ class TestPipeline : public ::testing::Test protected: void SetUp() override { - m_pipeline = std::move(pipeline::make_pipeline()); + m_pipeline = std::move(mrc::make_pipeline()); m_options = std::make_unique(); m_options->topology().user_cpuset("0"); @@ -56,7 +55,7 @@ class TestPipeline : public ::testing::Test void TearDown() override {} - std::unique_ptr m_pipeline; + std::unique_ptr m_pipeline; std::unique_ptr m_options; }; @@ -67,17 +66,16 @@ TEST_F(TestPipeline, LifeCycle) // note: i'm not sure if the top-level segment definition require types or just names // types might be useful for both count enforcement/zipping type-to-name, but also // make the instantiation of the serialization/deserialization network stack simplier - auto segment_initializer = [&counter](segment::Builder& seg) { + auto segment_initializer = [&counter](segment::IBuilder& seg) { ++counter; // Segment initialization code here. }; - auto segment = segment::Definition::create("seg_1", - segment::IngressPorts({"my_int"}), - segment::EgressPorts({"my_float"}), - segment_initializer); + m_pipeline->make_segment("seg_1", + segment::IngressPorts({"my_int"}), + segment::EgressPorts({"my_float"}), + segment_initializer); - m_pipeline->register_segment(segment); // EXPECT_EQ(m_pipeline->segment_count(), 1); EXPECT_EQ(counter.load(), 0); @@ -96,11 +94,11 @@ TEST_F(TestPipeline, LifeCycle) TEST_F(TestPipeline, DuplicateSegments) { - auto segment_initializer = [](segment::Builder& seg) {}; - auto seg_1 = segment::Definition::create("seg_1", - segment::IngressPorts({"my_int1"}), - segment::EgressPorts({"my_int2"}), - segment_initializer); + auto segment_initializer = [](segment::IBuilder& seg) {}; + std::shared_ptr seg_1 = Segment::create("seg_1", + segment::IngressPorts({"my_int1"}), + segment::EgressPorts({"my_int2"}), + segment_initializer); m_pipeline->register_segment(seg_1); EXPECT_ANY_THROW(m_pipeline->register_segment(seg_1)); } @@ -112,27 +110,28 @@ TEST_F(TestPipeline, TwoSegment) std::atomic next_count = 0; std::atomic complete_count = 0; - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); - auto seg_1 = pipeline->make_segment("seg_1", segment::EgressPorts({"float_port"}), [](segment::Builder& seg) { - auto rx_source = seg.make_source("rx_source", [](rxcpp::subscriber s) { - LOG(INFO) << "emit 1"; - s.on_next(1.0F); - LOG(INFO) << "emit 2"; - s.on_next(2.0F); - LOG(INFO) << "emit 3"; - s.on_next(3.0F); - LOG(INFO) << "issuing complete"; - s.on_completed(); - }); + auto seg_1 = + pipeline->make_segment("seg_1", segment::EgressPorts({"float_port"}), [](segment::IBuilder& seg) { + auto rx_source = seg.make_source("rx_source", [](rxcpp::subscriber s) { + LOG(INFO) << "emit 1"; + s.on_next(1.0F); + LOG(INFO) << "emit 2"; + s.on_next(2.0F); + LOG(INFO) << "emit 3"; + s.on_next(3.0F); + LOG(INFO) << "issuing complete"; + s.on_completed(); + }); - auto my_float_egress = seg.get_egress("float_port"); + auto my_float_egress = seg.get_egress("float_port"); - seg.make_edge(rx_source, my_float_egress); - }); + seg.make_edge(rx_source, my_float_egress); + }); auto seg_2 = - pipeline->make_segment("seg_2", segment::IngressPorts({"float_port"}), [&](segment::Builder& seg) { + pipeline->make_segment("seg_2", segment::IngressPorts({"float_port"}), [&](segment::IBuilder& seg) { auto my_float_ingress = seg.get_ingress("float_port"); auto rx_sink = seg.make_sink("rx_sink", @@ -169,12 +168,11 @@ TEST_F(TestPipeline, TwoSegmentManualTag) std::atomic next_count = 0; std::atomic complete_count = 0; - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); auto seg_1 = - pipeline->make_segment("seg_1", segment::EgressPorts>({"float_port"}), [](segment::Builder& seg) { - auto rx_source = seg.make_source("rx_source", [](rxcpp::subscriber s) { - s.on_next(1.0f); + pipeline->make_segment("seg_1", segment::EgressPorts>({"float_port"}), [](segment::IBuilder& seg) +{ auto rx_source = seg.make_source("rx_source", [](rxcpp::subscriber s) { s.on_next(1.0f); s.on_next(2.0f); s.on_next(3.0f); s.on_completed(); @@ -196,7 +194,7 @@ TEST_F(TestPipeline, TwoSegmentManualTag) }); auto seg_2 = - pipeline->make_segment("seg_2", segment::IngressPorts({"float_port"}), [&](segment::Builder& seg) { + pipeline->make_segment("seg_2", segment::IngressPorts({"float_port"}), [&](segment::IBuilder& seg) { auto my_float_ingress = seg.get_ingress("float_port"); auto rx_sink = seg.make_sink("rx_sink", @@ -234,12 +232,11 @@ TEST_F(TestPipeline, TwoSegmentManualTagImmediateStop) std::atomic next_count = 0; std::atomic complete_count = 0; - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); auto seg_1 = - pipeline->make_segment("seg_1", segment::EgressPorts>({"float_port"}), [](segment::Builder& seg) { - auto rx_source = - seg.make_source("rx_source", [](rxcpp::subscriber s) { s.on_completed(); }); + pipeline->make_segment("seg_1", segment::EgressPorts>({"float_port"}), [](segment::IBuilder& seg) +{ auto rx_source = seg.make_source("rx_source", [](rxcpp::subscriber s) { s.on_completed(); }); auto seg_2_addr = seg.make_address("seg_2"); @@ -257,7 +254,7 @@ TEST_F(TestPipeline, TwoSegmentManualTagImmediateStop) }); auto seg_2 = - pipeline->make_segment("seg_2", segment::IngressPorts({"float_port"}), [&](segment::Builder& seg) { + pipeline->make_segment("seg_2", segment::IngressPorts({"float_port"}), [&](segment::IBuilder& seg) { auto my_float_ingress = seg.get_ingress("float_port"); auto rx_sink = seg.make_sink("rx_sink", @@ -300,9 +297,9 @@ TEST_F(TestPipeline, Architect) std::atomic next_count = 0; std::atomic complete_count = 0; - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); - auto seg_1 = pipeline->make_segment("seg_1", EgressPorts({"float_port"}), [](segment::Builder& seg) { + auto seg_1 = pipeline->make_segment("seg_1", EgressPorts({"float_port"}), [](segment::IBuilder& seg) { auto rx_source = seg.make_source("rx_source", [](rxcpp::subscriber s) { s.on_next(1.0f); s.on_next(2.0f); @@ -315,7 +312,7 @@ TEST_F(TestPipeline, Architect) seg.make_edge(rx_source, my_float_egress); }); - auto seg_2 = pipeline->make_segment("seg_2", IngressPorts({"float_port"}), [&](segment::Builder& seg) { + auto seg_2 = pipeline->make_segment("seg_2", IngressPorts({"float_port"}), [&](segment::IBuilder& seg) { auto my_float_ingress = seg.get_ingress("float_port"); auto rx_sink = seg.make_sink("rx_sink", diff --git a/cpp/mrc/tests/test_segment.cpp b/cpp/mrc/tests/test_segment.cpp index 6641addda..be1bbc29c 100644 --- a/cpp/mrc/tests/test_segment.cpp +++ b/cpp/mrc/tests/test_segment.cpp @@ -18,8 +18,6 @@ #include "test_segment.hpp" #include "mrc/benchmarking/trace_statistics.hpp" -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" #include "mrc/exceptions/runtime_error.hpp" #include "mrc/node/operators/broadcast.hpp" #include "mrc/node/rx_node.hpp" @@ -28,9 +26,10 @@ #include "mrc/node/rx_source_base.hpp" #include "mrc/options/options.hpp" #include "mrc/options/topology.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" +#include "mrc/pipeline/segment.hpp" #include "mrc/segment/builder.hpp" -#include "mrc/segment/definition.hpp" #include "mrc/segment/ingress_port.hpp" #include "mrc/segment/object.hpp" #include "mrc/segment/ports.hpp" @@ -55,52 +54,52 @@ namespace mrc { TEST_F(TestSegment, CreateSegmentDefinition) { - auto segdef = segment::Definition::create("segment_test", m_initializer); + auto segdef = Segment::create("segment_test", m_initializer); } TEST_F(TestSegment, InitializeSegmentFromDefinition) { - auto segdef = segment::Definition::create("segment_test", m_initializer); - // // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_initializer); + // // auto builder = std::make_unique(segdef, 42); } // --- // TEST_F(TestSegment, CreateSegmentDefinitionIngressOnly) { - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_initializer); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_initializer); } TEST_F(TestSegment, InitializeSegmentIngressOnlyFromDefinition) { - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_initializer); - // // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_initializer); + // // auto builder = std::make_unique(segdef, 42); } // --- // TEST_F(TestSegment, CreateSegmentDefinitionEgressOnly) { - auto segdef = segment::Definition::create("segment_test", m_egress_multi_port, m_initializer); + auto segdef = Segment::create("segment_test", m_egress_multi_port, m_initializer); } TEST_F(TestSegment, InitializeSegmentEgressOnlyFromDefinition) { - auto segdef = segment::Definition::create("segment_test", m_egress_multi_port, m_initializer); - // // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_egress_multi_port, m_initializer); + // // auto builder = std::make_unique(segdef, 42); } // --- // TEST_F(TestSegment, CreateSegmentDefinitionIngressEgress) { - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_egress_multi_port, m_initializer); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_egress_multi_port, m_initializer); } TEST_F(TestSegment, InitializeSegmentIngressEgressFromDefinition) { - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_egress_multi_port, m_initializer); - // // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_egress_multi_port, m_initializer); + // // auto builder = std::make_unique(segdef, 42); EXPECT_EQ(segdef->name(), "segment_test"); /* @@ -142,15 +141,15 @@ TEST_F(TestSegment, UserLambdaIsCalled) EXPECT_EQ(m_initializer_called, false); - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_egress_multi_port, m_initializer); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_egress_multi_port, m_initializer); + // auto builder = std::make_unique(segdef, 42); EXPECT_EQ(m_initializer_called, true); } TEST_F(TestSegment, SegmentRxSinkCreation) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { auto x = segment.make_sink( "x_sink", [](std::string x) { @@ -161,13 +160,13 @@ TEST_F(TestSegment, SegmentRxSinkCreation) }); }; - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); - // // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); + // // auto builder = std::make_unique(segdef, 42); } TEST_F(TestSegment, SegmentRxSourceCreation) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { auto x = segment.make_source("x_src", [&](rxcpp::subscriber s) { s.on_next("One"); s.on_next("Two"); @@ -176,13 +175,13 @@ TEST_F(TestSegment, SegmentRxSourceCreation) }); }; - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); - // // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); + // // auto builder = std::make_unique(segdef, 42); } TEST_F(TestSegment, SegmentRxNodeCreation) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { auto x = segment.make_node("x"); auto y = segment.make_node("y", rxcpp::operators::map([](std::string s) -> double { @@ -198,13 +197,13 @@ TEST_F(TestSegment, SegmentRxNodeCreation) })); }; - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); + // auto builder = std::make_unique(segdef, 42); } TEST_F(TestSegment, SegmentRxNodeStaticEdges) { - auto init = [this](segment::Builder& segment) { + auto init = [this](segment::IBuilder& segment) { auto x = segment.make_node("x"); // Compiler error, can't create a node with no operations that has disperate input/output types // auto x2 = segment.make_node("x"); @@ -226,13 +225,13 @@ TEST_F(TestSegment, SegmentRxNodeStaticEdges) segment.make_edge(z, w); }; - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); + // auto builder = std::make_unique(segdef, 42); } TEST_F(TestSegment, SegmentRxNodeValidTypeConversionWorks) { - auto init = [this](segment::Builder& segment) { + auto init = [this](segment::IBuilder& segment) { auto x = segment.make_node("x"); // Compiler error, can't create a node with no operations that has disperate input/output types // auto x2 = segment.make_node("x"); @@ -259,14 +258,14 @@ TEST_F(TestSegment, SegmentRxNodeValidTypeConversionWorks) segment.make_edge(w, k); }; - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); + // auto builder = std::make_unique(segdef, 42); } /* dynamic edges are python only TEST_F(SegmentTests, SegmentRxNodeDynamicEdges) { - auto init = [this](segment::Builder& segment) { + auto init = [this](segment::IBuilder& segment) { auto x = segment.make_node("x"); // Compiler error, can't create a node with no operations that has disperate input/output types // auto x2 = segment.make_node("x"); @@ -288,8 +287,8 @@ TEST_F(SegmentTests, SegmentRxNodeDynamicEdges) EXPECT_EQ(segment.node_count(), m_InterfaceNodeCount + 4); }; - auto segdef = segment::Definition::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", m_ingress_multi_port, m_egress_multi_port, init); + // auto builder = std::make_unique(segdef, 42); } @@ -297,7 +296,7 @@ TEST_F(SegmentTests, SegmentRxNodeDynamicEdges) TEST_F(TestSegment, SegmentEndToEndTest) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { auto src = segment.make_source("src", [&](rxcpp::subscriber& s) { for (size_t i = 0; i < 10 && s.is_subscribed(); i++) { @@ -335,14 +334,14 @@ TEST_F(TestSegment, SegmentEndToEndTest) segment.make_edge(internal, sink); }; - auto segdef = segment::Definition::create("segment_test", init); + auto segdef = Segment::create("segment_test", init); // move to internal tests to access the builder - // // auto builder = std::make_unique(segdef, 42); + // // auto builder = std::make_unique(segdef, 42); } TEST_F(TestSegment, CompileTimeConversionValuesWorkAsExpected) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { auto src = segment.make_source("src", [&](rxcpp::subscriber& s) { for (size_t i = 0; i < 10 && s.is_subscribed(); i++) { @@ -400,13 +399,13 @@ TEST_F(TestSegment, CompileTimeConversionValuesWorkAsExpected) segment.make_edge(convert_3_sizet, sink); }; - auto segdef = segment::Definition::create("segment_test", init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", init); + // auto builder = std::make_unique(segdef, 42); } TEST_F(TestSegment, RuntimeConversionValuesWorkAsExpected) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { auto src = segment.make_source("src", [&](rxcpp::subscriber& s) { for (size_t i = 0; i < 10 && s.is_subscribed(); i++) { @@ -466,13 +465,13 @@ TEST_F(TestSegment, RuntimeConversionValuesWorkAsExpected) segment.make_edge("convert_3_sizet", "sink"); }; - auto segdef = segment::Definition::create("segment_test", init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", init); + // auto builder = std::make_unique(segdef, 42); } TEST_F(TestSegment, SegmentEndToEndTestRx) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { auto src = segment.make_source("src", [&](rxcpp::subscriber s) { s.on_next("One"); s.on_next("Two"); @@ -506,11 +505,11 @@ TEST_F(TestSegment, SegmentEndToEndTestRx) segment.make_edge(internal, sink); }; - auto segdef = segment::Definition::create("segment_test", init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", init); + // auto builder = std::make_unique(segdef, 42); } -void execute_pipeline(std::unique_ptr pipeline) +void execute_pipeline(std::unique_ptr pipeline) { auto options = std::make_unique(); options->topology().user_cpuset("0"); @@ -522,12 +521,12 @@ void execute_pipeline(std::unique_ptr pipeline) TEST_F(TestSegment, ChannelClose) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); int next_count = 0; int complete_count = 0; - auto my_segment = p->make_segment("my_segment", [&](segment::Builder& seg) { + auto my_segment = p->make_segment("my_segment", [&](segment::IBuilder& seg) { DVLOG(1) << "In Initializer" << std::endl; auto sourceStr1 = seg.make_source("src1", [&](rxcpp::subscriber& s) { @@ -573,7 +572,7 @@ TEST_F(TestSegment, SegmentEndToEndTestSinkOutput) unsigned int iterations{10}; std::atomic sink_results{0}; - auto init = [&](segment::Builder& segment) { + auto init = [&](segment::IBuilder& segment) { auto src = segment.make_source("src", [&](rxcpp::subscriber& s) { for (size_t i = 0; i < iterations && s.is_subscribed(); i++) { @@ -599,8 +598,8 @@ TEST_F(TestSegment, SegmentEndToEndTestSinkOutput) segment.make_edge(internal, sink); }; - auto segdef = segment::Definition::create("segment_test", init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", init); + // auto builder = std::make_unique(segdef, 42); } TEST_F(TestSegment, SegmentSingleSourceTwoNodesException) @@ -610,7 +609,7 @@ TEST_F(TestSegment, SegmentSingleSourceTwoNodesException) float sink2_results{0}; std::mutex mux; - auto init = [&](segment::Builder& segment) { + auto init = [&](segment::IBuilder& segment) { auto src = segment.make_source("src", [&](rxcpp::subscriber& s) { for (size_t i = 0; i < iterations && s.is_subscribed(); i++) { @@ -655,8 +654,8 @@ TEST_F(TestSegment, SegmentSingleSourceTwoNodesException) segment.make_edge(str_half_length, sink2); }; - auto segdef = segment::Definition::create("segment_test", init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", init); + // auto builder = std::make_unique(segdef, 42); } TEST_F(TestSegment, SegmentSingleSourceTwoNodes) @@ -666,7 +665,7 @@ TEST_F(TestSegment, SegmentSingleSourceTwoNodes) float sink2_results{0}; std::mutex mux; - auto init = [&](segment::Builder& segment) { + auto init = [&](segment::IBuilder& segment) { auto src = segment.make_source("src", [&](rxcpp::subscriber& s) { for (size_t i = 0; i < iterations && s.is_subscribed(); i++) { @@ -715,11 +714,11 @@ TEST_F(TestSegment, SegmentSingleSourceTwoNodes) segment.make_edge(str_half_length, sink2); }; - auto segdef = segment::Definition::create("segment_test", init); - // // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", init); + // // auto builder = std::make_unique(segdef, 42); - auto pipeline = pipeline::make_pipeline(); - pipeline->register_segment(segdef); + auto pipeline = mrc::make_pipeline(); + pipeline->register_segment(std::move(segdef)); execute_pipeline(std::move(pipeline)); EXPECT_EQ(sink1_results, 11 * iterations); @@ -735,7 +734,7 @@ TEST_F(TestSegment, SegmentSingleSourceMultiNodes) std::array sink_results; sink_results.fill(0); - auto init = [&](segment::Builder& segment) { + auto init = [&](segment::IBuilder& segment) { auto src = segment.make_source("src", [&](rxcpp::subscriber& s) { for (size_t i = 0; i < iterations && s.is_subscribed(); i++) { @@ -772,11 +771,11 @@ TEST_F(TestSegment, SegmentSingleSourceMultiNodes) } }; - auto segdef = segment::Definition::create("segment_test", init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", init); + // auto builder = std::make_unique(segdef, 42); - auto pipeline = pipeline::make_pipeline(); - pipeline->register_segment(segdef); + auto pipeline = mrc::make_pipeline(); + pipeline->register_segment(std::move(segdef)); execute_pipeline(std::move(pipeline)); @@ -788,7 +787,7 @@ TEST_F(TestSegment, SegmentSingleSourceMultiNodes) TEST_F(TestSegment, EnsureMove) { - auto init = [&](segment::Builder& segment) { + auto init = [&](segment::IBuilder& segment) { auto src = segment.make_source("src", [](rxcpp::subscriber& s) { if (s.is_subscribed()) { @@ -812,17 +811,17 @@ TEST_F(TestSegment, EnsureMove) segment.make_edge(src, sink); }; - auto segdef = segment::Definition::create("segment_test", init); + auto segdef = Segment::create("segment_test", init); - auto pipeline = pipeline::make_pipeline(); - pipeline->register_segment(segdef); + auto pipeline = mrc::make_pipeline(); + pipeline->register_segment(std::move(segdef)); execute_pipeline(std::move(pipeline)); } TEST_F(TestSegment, EnsureMoveMultiChildren) { constexpr unsigned int NumChildren{10}; - auto init = [&](segment::Builder& segment) { + auto init = [&](segment::IBuilder& segment) { auto src = segment.make_source("src", [](rxcpp::subscriber& s) { if (s.is_subscribed()) { @@ -863,9 +862,9 @@ TEST_F(TestSegment, EnsureMoveMultiChildren) } }; - auto segdef = segment::Definition::create("segment_test", init); - auto pipeline = pipeline::make_pipeline(); - pipeline->register_segment(segdef); + auto segdef = Segment::create("segment_test", init); + auto pipeline = mrc::make_pipeline(); + pipeline->register_segment(std::move(segdef)); execute_pipeline(std::move(pipeline)); } @@ -912,7 +911,7 @@ TEST_F(TestSegment, EnsureMoveConstructor) } { // Test only one child - auto init = [&](segment::Builder& segment) { + auto init = [&](segment::IBuilder& segment) { auto src = segment.make_source("src", [](rxcpp::subscriber& s) { if (s.is_subscribed()) { @@ -938,13 +937,13 @@ TEST_F(TestSegment, EnsureMoveConstructor) segment.make_edge(src, sink); }; - auto segdef = segment::Definition::create("segment_test", init); - // auto builder = std::make_unique(segdef, 42); + auto segdef = Segment::create("segment_test", init); + // auto builder = std::make_unique(segdef, 42); } { // Test multiple children constexpr unsigned int NumChildren{10}; - auto init = [&](segment::Builder& segment) { + auto init = [&](segment::IBuilder& segment) { auto src = segment.make_source("src", [](rxcpp::subscriber& s) { if (s.is_subscribed()) { @@ -978,9 +977,9 @@ TEST_F(TestSegment, EnsureMoveConstructor) } }; - auto segdef = segment::Definition::create("segment_test", init); - auto pipeline = pipeline::make_pipeline(); - pipeline->register_segment(segdef); + auto segdef = Segment::create("segment_test", init); + auto pipeline = mrc::make_pipeline(); + pipeline->register_segment(std::move(segdef)); execute_pipeline(std::move(pipeline)); } } @@ -992,7 +991,7 @@ TEST_F(TestSegment, SegmentTestRxcppHigherLevelNodes) TraceStatistics::trace_channels(); TraceStatistics::trace_operators(); - auto init = [&iterations](segment::Builder& segment) { + auto init = [&iterations](segment::IBuilder& segment) { auto src = segment.make_source("src", [&iterations](rxcpp::subscriber s) { for (auto i = 0; i < iterations; ++i) { @@ -1053,38 +1052,38 @@ TEST_F(TestSegment, SegmentTestRxcppHigherLevelNodes) TraceStatistics::reset(); - auto segdef = segment::Definition::create("segment_stats_test", init); - auto pipeline = pipeline::make_pipeline(); - pipeline->register_segment(segdef); + auto segdef = Segment::create("segment_stats_test", init); + auto pipeline = mrc::make_pipeline(); + pipeline->register_segment(std::move(segdef)); execute_pipeline(std::move(pipeline)); nlohmann::json j = TraceStatistics::aggregate(); auto _j = j["aggregations"]["components"]["metrics"]; // std::cerr << j.dump(2); - EXPECT_EQ(_j.contains("src"), true); - auto src_json = j["src"]; + EXPECT_EQ(_j.contains("/segment_stats_test/src"), true); + auto src_json = j["/segment_stats_test/src"]; // stat_check_helper(src_json, 0, 0, iterations, iterations); - EXPECT_EQ(_j.contains("internal_1"), true); - auto i1_json = j["internal_1"]; + EXPECT_EQ(_j.contains("/segment_stats_test/internal_1"), true); + auto i1_json = j["/segment_stats_test/internal_1"]; // stat_check_helper(i1_json, iterations, iterations, iterations, iterations); - EXPECT_EQ(_j.contains("internal_2"), true); - auto i2_json = j["internal_1"]; + EXPECT_EQ(_j.contains("/segment_stats_test/internal_2"), true); + auto i2_json = j["/segment_stats_test/internal_1"]; // stat_check_helper(i2_json, iterations, iterations, iterations, iterations); - EXPECT_EQ(_j.contains("sink"), true); - auto sink_json = j["sink"]; + EXPECT_EQ(_j.contains("/segment_stats_test/sink"), true); + auto sink_json = j["/segment_stats_test/sink"]; // stat_check_helper(sink_json, iterations, iterations, 0, 0); TraceStatistics::reset(); } TEST_F(TestSegment, SegmentGetEgressError) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { segment.get_egress("test"); }; - auto segdef = segment::Definition::create("segment_test", init); + auto segdef = Segment::create("segment_test", init); /* try @@ -1103,13 +1102,13 @@ TEST_F(TestSegment, SegmentGetEgressError) TEST_F(TestSegment, SegmentGetEgressNotEgressError) { - auto init = [](segment::Builder& segment) { + auto init = [](segment::IBuilder& segment) { auto src = segment.make_source("test", [&](rxcpp::subscriber& s) { s.on_completed(); }); segment.get_egress("test"); }; - auto segdef = segment::Definition::create("segment_test", init); + auto segdef = Segment::create("segment_test", init); /* try diff --git a/cpp/mrc/tests/test_segment.hpp b/cpp/mrc/tests/test_segment.hpp index 17a9c70d0..bdc385969 100644 --- a/cpp/mrc/tests/test_segment.hpp +++ b/cpp/mrc/tests/test_segment.hpp @@ -34,7 +34,7 @@ #include namespace mrc::segment { -class Builder; +class IBuilder; struct ObjectProperties; } // namespace mrc::segment @@ -58,7 +58,7 @@ class TestSegment : public ::testing::Test protected: void SetUp() override { - m_pipeline = pipeline::make_pipeline(); + m_pipeline = mrc::make_pipeline(); m_resources = std::make_shared(); } @@ -81,10 +81,10 @@ class TestSegment : public ::testing::Test // Sum of nodes created by Ingress Types and Egress Types size_t m_InterfaceNodeCount; - std::function m_initializer = [this](segment::Builder& s) { + std::function m_initializer = [this](segment::IBuilder& s) { this->m_initializer_called = true; }; - std::unique_ptr m_pipeline; + std::unique_ptr m_pipeline; std::shared_ptr m_resources; }; diff --git a/docs/quickstart/cpp/ex00_simple_pipeline/README.md b/docs/quickstart/cpp/ex00_simple_pipeline/README.md index 910d15fdf..04859323d 100644 --- a/docs/quickstart/cpp/ex00_simple_pipeline/README.md +++ b/docs/quickstart/cpp/ex00_simple_pipeline/README.md @@ -6,9 +6,9 @@ This example illustrates how to create a simple pipeline with a single source, n - Node: Transforms the `int` to a `float` by multiplying it by 2.5, resulting in a float - Sink: Prints any received `float` value and counts the number of emitted items -Each of the objects in the Segment is created using the `segment::Builder::make_XXX(NAME, ...)` function where `XXX` is replace with either `source`, `sink` or `node`. +Each of the objects in the Segment is created using the `segment::IBuilder::make_XXX(NAME, ...)` function where `XXX` is replace with either `source`, `sink` or `node`. -Once each object is created, they can be linked together using `segment::Builder::make_edge(SOURCE, SINK)`. There are a few rules when making edges: +Once each object is created, they can be linked together using `segment::IBuilder::make_edge(SOURCE, SINK)`. There are a few rules when making edges: - Objects deriving from `mrc::node::SourceProperties` can only appear in the left-hand argument of make_edge() - Objects deriving from `mrc::node::SinkProperties` can only appear in the right-hand argument of make_edge() @@ -22,7 +22,7 @@ Once each object is created, they can be linked together using `segment::Builder The first "node" that we will be creating is a source. Source objects have no upstream dependencies and are responsible for producing data to be consume by downstream object. -To create a source, you call `make_source` on the `segment::Builder` object passing a name and a lambda of type `std::function<(rxcpp::subscriber)>` Please see https://reactivex.io/RxCpp/ and navigate to rxcpp::subscriber for more detail on the lambda type. where `T` is the type of object that the source will be producing. In our example, we are creating integers so the source object looks like: +To create a source, you call `make_source` on the `segment::IBuilder` object passing a name and a lambda of type `std::function<(rxcpp::subscriber)>` Please see https://reactivex.io/RxCpp/ and navigate to rxcpp::subscriber for more detail on the lambda type. where `T` is the type of object that the source will be producing. In our example, we are creating integers so the source object looks like: ```cpp auto source = s.make_source("int_source", [](rxcpp::subscriber s) { diff --git a/docs/quickstart/cpp/ex00_simple_pipeline/simple_pipeline.cpp b/docs/quickstart/cpp/ex00_simple_pipeline/simple_pipeline.cpp index 1ef91554e..dd8fddd05 100644 --- a/docs/quickstart/cpp/ex00_simple_pipeline/simple_pipeline.cpp +++ b/docs/quickstart/cpp/ex00_simple_pipeline/simple_pipeline.cpp @@ -18,7 +18,6 @@ #include #include #include -#include using namespace mrc; @@ -31,13 +30,13 @@ int main(int argc, char* argv[]) Executor executor(std::move(options)); // create pipeline object - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); // counter external to the segment object that will be incremented by the sink std::atomic counter = 0; // create a segment - a pipeline can consist of multiple segments; however in this example we will use only one - auto seg = segment::Definition::create("quickstart", [&counter](segment::Builder& s) { + auto seg = Segment::create("quickstart", [&counter](segment::IBuilder& s) { // Source // This first "node" is a source node which has no upstream dependencies. It is responsible for producing data // to be consume by downstream nodes @@ -78,7 +77,7 @@ int main(int argc, char* argv[]) }); // register segments with the pipeline - pipeline->register_segment(seg); + pipeline->register_segment(std::move(seg)); // register the pipeline with the executor executor.register_pipeline(std::move(pipeline)); diff --git a/docs/quickstart/cpp/ex02_pipeline_with_library/pipeline_with_library.cpp b/docs/quickstart/cpp/ex02_pipeline_with_library/pipeline_with_library.cpp index 40b3e8663..77a7c4017 100644 --- a/docs/quickstart/cpp/ex02_pipeline_with_library/pipeline_with_library.cpp +++ b/docs/quickstart/cpp/ex02_pipeline_with_library/pipeline_with_library.cpp @@ -20,7 +20,6 @@ #include #include #include -#include using namespace mrc; using namespace mrc::quickstart::cpp::common; @@ -36,10 +35,10 @@ int main(int argc, char* argv[]) Executor executor(std::move(options)); // create pipeline object - auto pipeline = pipeline::make_pipeline(); + auto pipeline = mrc::make_pipeline(); // create a segment - a pipeline can consist of multiple segments; however in this example we will use only one - auto seg = segment::Definition::create("quickstart", [&counter](segment::Builder& s) { + auto seg = Segment::create("quickstart", [&counter](segment::IBuilder& s) { // Source // This first "node" is a source node which has no upstream dependencies. It is responsible for producing data // to be consume by downstream nodes @@ -75,7 +74,7 @@ int main(int argc, char* argv[]) }); // register segments with the pipeline - pipeline->register_segment(seg); + pipeline->register_segment(std::move(seg)); // register the pipeline with the executor executor.register_pipeline(std::move(pipeline)); diff --git a/docs/quickstart/environment_cpp.yml b/docs/quickstart/environment_cpp.yml index dd72cfca9..379bf6477 100644 --- a/docs/quickstart/environment_cpp.yml +++ b/docs/quickstart/environment_cpp.yml @@ -17,9 +17,9 @@ dependencies: - cython=0.29.24 - doxygen=1.9.2 - gcc_linux-64=11.2 - - gmock=1.10 + - gmock=1.13 - graphviz=3.0 - - gtest=1.10 + - gtest=1.13 - gxx_linux-64=11.2 - isort - libtool @@ -30,7 +30,6 @@ dependencies: - pkg-config=0.29 - python=3.10 - scikit-build>=0.12 - - spdlog=1.8.5 - mrc=23.07 - sysroot_linux-64=2.17 - pip: diff --git a/docs/quickstart/hybrid/mrc_qs_hybrid/common/nodes.cpp b/docs/quickstart/hybrid/mrc_qs_hybrid/common/nodes.cpp index ccdaea93d..10b060ae6 100644 --- a/docs/quickstart/hybrid/mrc_qs_hybrid/common/nodes.cpp +++ b/docs/quickstart/hybrid/mrc_qs_hybrid/common/nodes.cpp @@ -134,7 +134,7 @@ PYBIND11_MODULE(nodes, m) std::shared_ptr>>(m, "DataObjectSource", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name, size_t count) { + .def(py::init<>([](mrc::segment::IBuilder& parent, const std::string& name, size_t count) { auto stage = parent.construct_object(name, count); return stage; @@ -146,7 +146,7 @@ PYBIND11_MODULE(nodes, m) py::class_, mrc::segment::ObjectProperties, std::shared_ptr>>(m, "DataObjectNode", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name) { + .def(py::init<>([](mrc::segment::IBuilder& parent, const std::string& name) { auto stage = parent.construct_object(name); return stage; @@ -157,7 +157,7 @@ PYBIND11_MODULE(nodes, m) py::class_, mrc::segment::ObjectProperties, std::shared_ptr>>(m, "DataObjectSink", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name) { + .def(py::init<>([](mrc::segment::IBuilder& parent, const std::string& name) { auto stage = parent.construct_object(name); return stage; diff --git a/docs/quickstart/hybrid/mrc_qs_hybrid/ex01_wrap_nodes/nodes.cpp b/docs/quickstart/hybrid/mrc_qs_hybrid/ex01_wrap_nodes/nodes.cpp index d365a34b8..ea30b6b48 100644 --- a/docs/quickstart/hybrid/mrc_qs_hybrid/ex01_wrap_nodes/nodes.cpp +++ b/docs/quickstart/hybrid/mrc_qs_hybrid/ex01_wrap_nodes/nodes.cpp @@ -127,7 +127,7 @@ PYBIND11_MODULE(nodes, m) std::shared_ptr>>(m, "MyDataObjectSource", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name, size_t count) { + .def(py::init<>([](mrc::segment::IBuilder& parent, const std::string& name, size_t count) { auto stage = parent.construct_object(name, count); return stage; @@ -141,7 +141,7 @@ PYBIND11_MODULE(nodes, m) std::shared_ptr>>(m, "MyDataObjectNode", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name) { + .def(py::init<>([](mrc::segment::IBuilder& parent, const std::string& name) { auto stage = parent.construct_object(name); return stage; @@ -154,7 +154,7 @@ PYBIND11_MODULE(nodes, m) std::shared_ptr>>(m, "MyDataObjectSink", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name) { + .def(py::init<>([](mrc::segment::IBuilder& parent, const std::string& name) { auto stage = parent.construct_object(name); return stage; diff --git a/external/utilities b/external/utilities index ad81faac9..a5b9689e3 160000 --- a/external/utilities +++ b/external/utilities @@ -1 +1 @@ -Subproject commit ad81faac968919678988dc33cc89c85ddd52a643 +Subproject commit a5b9689e3a82fe5b49245b0a02c907ea70aed7b8 diff --git a/mrc.code-workspace b/mrc.code-workspace index 8f1e7678c..f38bb38e9 100644 --- a/mrc.code-workspace +++ b/mrc.code-workspace @@ -199,9 +199,6 @@ "source.organizeImports": true }, "editor.formatOnSave": true, - "editor.rulers": [ - 120 - ], "editor.tabSize": 4 }, "cmake.configureArgs": [ @@ -209,6 +206,7 @@ "-DMRC_PYTHON_INPLACE_BUILD:BOOL=ON" // Allow inplace build for python. Use `pip install -e .` from the python folder to install ], "cmake.format.allowOptionalArgumentIndentation": true, + "editor.rulers": [120], "files.insertFinalNewline": true, "files.trimTrailingWhitespace": true, "files.watcherExclude": { diff --git a/python/mrc/_pymrc/CMakeLists.txt b/python/mrc/_pymrc/CMakeLists.txt index e3314f550..b1aa4eb77 100644 --- a/python/mrc/_pymrc/CMakeLists.txt +++ b/python/mrc/_pymrc/CMakeLists.txt @@ -32,7 +32,6 @@ add_library(pymrc src/segment_modules.cpp src/segment.cpp src/subscriber.cpp - src/system.cpp src/types.cpp src/utilities/acquire_gil.cpp src/utilities/deserializers.cpp diff --git a/python/mrc/_pymrc/include/pymrc/executor.hpp b/python/mrc/_pymrc/include/pymrc/executor.hpp index 8beabe9ec..c339d925a 100644 --- a/python/mrc/_pymrc/include/pymrc/executor.hpp +++ b/python/mrc/_pymrc/include/pymrc/executor.hpp @@ -24,10 +24,13 @@ #include namespace mrc { -class Executor; class Options; } // namespace mrc +namespace mrc::pipeline { +class IExecutor; +} + namespace mrc::pymrc { class Pipeline; @@ -66,12 +69,12 @@ class Executor void join(); std::shared_ptr join_async(); - std::shared_ptr get_executor() const; + std::shared_ptr get_executor() const; private: SharedFuture m_join_future; - std::shared_ptr m_exec; + std::shared_ptr m_exec; }; class PyBoostFuture diff --git a/python/mrc/_pymrc/include/pymrc/module_registry.hpp b/python/mrc/_pymrc/include/pymrc/module_registry.hpp index fdaabee77..25ca7ca28 100644 --- a/python/mrc/_pymrc/include/pymrc/module_registry.hpp +++ b/python/mrc/_pymrc/include/pymrc/module_registry.hpp @@ -25,7 +25,7 @@ #include namespace mrc::segment { -class Builder; +class IBuilder; } // namespace mrc::segment namespace mrc::pymrc { @@ -53,12 +53,12 @@ class ModuleRegistryProxy static void register_module(std::string name, const registry_version_t& release_version, - std::function fn_py_initializer); + std::function fn_py_initializer); static void register_module(std::string name, std::string registry_namespace, const registry_version_t& release_version, - std::function fn_py_initializer); + std::function fn_py_initializer); static void unregister_module(const std::string& name, const std::string& registry_namespace, bool optional = true); diff --git a/python/mrc/_pymrc/include/pymrc/pipeline.hpp b/python/mrc/_pymrc/include/pymrc/pipeline.hpp index f68050d23..0f663e479 100644 --- a/python/mrc/_pymrc/include/pymrc/pipeline.hpp +++ b/python/mrc/_pymrc/include/pymrc/pipeline.hpp @@ -24,10 +24,10 @@ #include namespace mrc::pipeline { -class Pipeline; +class IPipeline; } // namespace mrc::pipeline namespace mrc::segment { -class Builder; +class IBuilder; } // namespace mrc::segment namespace mrc::pymrc { @@ -46,7 +46,7 @@ class Pipeline * @param name Segment name * @param init initializer used to define segment internals */ - void make_segment(const std::string& name, const std::function& init); + void make_segment(const std::string& name, const std::function& init); /** * @brief @@ -60,12 +60,17 @@ class Pipeline void make_segment(const std::string& name, pybind11::list ingress_port_info, pybind11::list egress_port_info, - const std::function& init); + const std::function& init); - std::unique_ptr swap(); + /** + * @brief Get the wrapped object held by this Python proxy object + * + * @return std::shared_ptr + */ + std::shared_ptr get_wrapped() const; private: - std::unique_ptr m_pipeline; + std::shared_ptr m_pipeline; }; #pragma GCC visibility pop diff --git a/python/mrc/_pymrc/include/pymrc/py_segment_module.hpp b/python/mrc/_pymrc/include/pymrc/py_segment_module.hpp index 1b546421e..81d5e121e 100644 --- a/python/mrc/_pymrc/include/pymrc/py_segment_module.hpp +++ b/python/mrc/_pymrc/include/pymrc/py_segment_module.hpp @@ -27,7 +27,7 @@ #include namespace mrc::segment { -class Builder; +class IBuilder; } // namespace mrc::segment namespace mrc::pymrc { @@ -48,13 +48,13 @@ class PythonSegmentModule : public mrc::modules::SegmentModule friend ModuleRegistryProxy; public: - using py_initializer_t = std::function; + using py_initializer_t = std::function; PythonSegmentModule(std::string module_name); PythonSegmentModule(std::string module_name, nlohmann::json config); protected: - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; private: diff --git a/python/mrc/_pymrc/include/pymrc/segment.hpp b/python/mrc/_pymrc/include/pymrc/segment.hpp index f972c9d29..2da23cace 100644 --- a/python/mrc/_pymrc/include/pymrc/segment.hpp +++ b/python/mrc/_pymrc/include/pymrc/segment.hpp @@ -58,9 +58,9 @@ namespace mrc::pymrc { * Relates to https://github.com/pybind/pybind11/issues/1241 -- for a general solution see pydrake's WrapFunction * method. * - * We need to force pybind to pass us a function that expects a mrc::segment::Builder* not a mrc::segment::Builder&. If - * not it'll try to make a copy and mrc::segment::Builder isnt' copy-constructable. Once we have that, we wrap it with - * our reference based function. + * We need to force pybind to pass us a function that expects a mrc::segment::IBuilder* not a mrc::segment::IBuilder&. + * If not it'll try to make a copy and mrc::segment::IBuilder isnt' copy-constructable. Once we have that, we wrap it + * with our reference based function. * * @tparam ClassT Class where the init method binding is defined. * @tparam ArgsT any additional arguments to pass to the initializer function @@ -69,14 +69,14 @@ namespace mrc::pymrc { */ template auto wrap_segment_init_callback(void (ClassT::*method)(const std::string&, - const std::function&)) + const std::function&)) { // Build up the function we're going to return, the signature on this function is what forces python to give us // a pointer. auto func = [method](ClassT* self, const std::string& name, - const std::function& f_to_wrap) { - auto f_wrapped = [f_to_wrap](mrc::segment::Builder& t, ArgsT... args) { + const std::function& f_to_wrap) { + auto f_wrapped = [f_to_wrap](mrc::segment::IBuilder& t, ArgsT... args) { f_to_wrap(&t, std::forward(args)...); }; @@ -92,9 +92,9 @@ auto wrap_segment_init_callback(void (ClassT::*method)(const std::string&, * Relates to https://github.com/pybind/pybind11/issues/1241 -- for a general solution see pydrake's WrapFunction * method. * - * We need to force pybind to pass us a function that expects a mrc::segment::Builder* not a mrc::segment::Builder&. If - * not it'll try to make a copy and mrc::segment::Builder isn't copy-constructable. Once we have that, we wrap it with - * our reference based function. + * We need to force pybind to pass us a function that expects a mrc::segment::IBuilder* not a mrc::segment::IBuilder&. + * If not it'll try to make a copy and mrc::segment::IBuilder isn't copy-constructable. Once we have that, we wrap it + * with our reference based function. * * @tparam ClassT Class where the init method binding is defined. * @tparam ArgsT any additional arguments to pass to the initializer function @@ -106,7 +106,7 @@ auto wrap_segment_init_callback( void (ClassT::*method)(const std::string&, pybind11::list, pybind11::list, - const std::function&)) + const std::function&)) { // Build up the function we're going to return, the signature on this function is what forces python to give us // a pointer. @@ -114,8 +114,8 @@ auto wrap_segment_init_callback( const std::string& name, pybind11::list ingress_port_ids, pybind11::list egress_port_ids, - const std::function& f_to_wrap) { - auto f_wrapped = [f_to_wrap](mrc::segment::Builder& t, ArgsT... args) { + const std::function& f_to_wrap) { + auto f_wrapped = [f_to_wrap](mrc::segment::IBuilder& t, ArgsT... args) { f_to_wrap(&t, std::forward(args)...); }; @@ -131,32 +131,32 @@ auto wrap_segment_init_callback( class BuilderProxy { public: - static std::shared_ptr make_source(mrc::segment::Builder& self, + static std::shared_ptr make_source(mrc::segment::IBuilder& self, const std::string& name, pybind11::iterator source_iterator); - static std::shared_ptr make_source(mrc::segment::Builder& self, + static std::shared_ptr make_source(mrc::segment::IBuilder& self, const std::string& name, pybind11::iterable source_iter); - static std::shared_ptr make_source(mrc::segment::Builder& self, + static std::shared_ptr make_source(mrc::segment::IBuilder& self, const std::string& name, pybind11::function gen_factory); static std::shared_ptr make_source( - mrc::segment::Builder& self, + mrc::segment::IBuilder& self, const std::string& name, const std::function& f); - static std::shared_ptr make_source_component(mrc::segment::Builder& self, + static std::shared_ptr make_source_component(mrc::segment::IBuilder& self, const std::string& name, pybind11::iterator source_iterator); - static std::shared_ptr make_source_component(mrc::segment::Builder& self, + static std::shared_ptr make_source_component(mrc::segment::IBuilder& self, const std::string& name, pybind11::iterable source_iter); - static std::shared_ptr make_source_component(mrc::segment::Builder& self, + static std::shared_ptr make_source_component(mrc::segment::IBuilder& self, const std::string& name, pybind11::function gen_factory); @@ -180,20 +180,20 @@ class BuilderProxy * sink = segment.make_sink("test", my_on_next, my_on_error, my_on_completed) * ``` */ - static std::shared_ptr make_sink(mrc::segment::Builder& self, + static std::shared_ptr make_sink(mrc::segment::IBuilder& self, const std::string& name, OnNextFunction on_next, OnErrorFunction on_error, OnCompleteFunction on_completed); - static std::shared_ptr make_sink_component(mrc::segment::Builder& self, + static std::shared_ptr make_sink_component(mrc::segment::IBuilder& self, const std::string& name, OnNextFunction on_next, OnErrorFunction on_error, OnCompleteFunction on_completed); // Deprecated. This must come first - static std::shared_ptr make_node(mrc::segment::Builder& self, + static std::shared_ptr make_node(mrc::segment::IBuilder& self, const std::string& name, OnDataFunction on_data); @@ -203,53 +203,53 @@ class BuilderProxy * This will create and return a new lambda function with the following signature: * (py) @param name : Unique name of the node that will be created in the MRC Segment. */ - static std::shared_ptr make_node(mrc::segment::Builder& self, + static std::shared_ptr make_node(mrc::segment::IBuilder& self, const std::string& name, pybind11::args operators); static std::shared_ptr make_node_full( - mrc::segment::Builder& self, + mrc::segment::IBuilder& self, const std::string& name, std::function sub_fn); - static std::shared_ptr make_node_component(mrc::segment::Builder& self, + static std::shared_ptr make_node_component(mrc::segment::IBuilder& self, const std::string& name, pybind11::args operators); - static void make_edge(mrc::segment::Builder& self, + static void make_edge(mrc::segment::IBuilder& self, std::shared_ptr source, std::shared_ptr sink); - static void splice_edge(mrc::segment::Builder& self, + static void splice_edge(mrc::segment::IBuilder& self, std::string& source, std::string& sink, std::shared_ptr splice_input, std::shared_ptr splice_output) {} - static std::shared_ptr get_ingress(mrc::segment::Builder& self, + static std::shared_ptr get_ingress(mrc::segment::IBuilder& self, const std::string& name); - static std::shared_ptr get_egress(mrc::segment::Builder& self, + static std::shared_ptr get_egress(mrc::segment::IBuilder& self, const std::string& name); - static std::shared_ptr load_module_from_registry(mrc::segment::Builder& self, + static std::shared_ptr load_module_from_registry(mrc::segment::IBuilder& self, const std::string& module_id, const std::string& registry_namespace, std::string module_name, pybind11::dict config = {}); - static void register_module_input(mrc::segment::Builder& self, + static void register_module_input(mrc::segment::IBuilder& self, std::string input_name, std::shared_ptr object); - static void register_module_output(mrc::segment::Builder& self, + static void register_module_output(mrc::segment::IBuilder& self, std::string output_name, std::shared_ptr object); - static pybind11::dict get_current_module_config(mrc::segment::Builder& self); + static pybind11::dict get_current_module_config(mrc::segment::IBuilder& self); - static void init_module(mrc::segment::Builder& self, std::shared_ptr module); + static void init_module(mrc::segment::IBuilder& self, std::shared_ptr module); }; #pragma GCC visibility pop diff --git a/python/mrc/_pymrc/include/pymrc/system.hpp b/python/mrc/_pymrc/include/pymrc/system.hpp deleted file mode 100644 index cca2f45a3..000000000 --- a/python/mrc/_pymrc/include/pymrc/system.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2022-2023, 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. - */ -#pragma once - -#include "mrc/engine/system/iresources.hpp" -#include "mrc/engine/system/isystem.hpp" - -#include - -namespace mrc { -class Options; -} // namespace mrc - -namespace mrc::pymrc { - -class System final : public internal::system::ISystem -{ - public: - System(std::shared_ptr options); - ~System() final = default; -}; - -class SystemResources final : public internal::system::IResources -{ - public: - SystemResources(std::shared_ptr system); - ~SystemResources() final = default; - - private: - void add_gil_initializer(); - void add_gil_finalizer(); -}; - -} // namespace mrc::pymrc diff --git a/python/mrc/_pymrc/include/pymrc/watchers.hpp b/python/mrc/_pymrc/include/pymrc/watchers.hpp index da8acabb7..af28566d9 100644 --- a/python/mrc/_pymrc/include/pymrc/watchers.hpp +++ b/python/mrc/_pymrc/include/pymrc/watchers.hpp @@ -27,7 +27,7 @@ #include namespace mrc::segment { -class Builder; +class IBuilder; struct ObjectProperties; } // namespace mrc::segment @@ -54,19 +54,19 @@ class LatencyWatcher : public latency_watcher_t LatencyWatcher(std::shared_ptr executor, std::function payload_init); void make_segment(const std::string& name, - const std::function& init); + const std::function& init); - std::shared_ptr make_tracer_source(mrc::segment::Builder& seg, + std::shared_ptr make_tracer_source(mrc::segment::IBuilder& seg, const std::string& name, bool force_sequential = false); std::shared_ptr make_traced_node( - mrc::segment::Builder& seg, + mrc::segment::IBuilder& seg, const std::string& name, std::function map_f); std::shared_ptr make_tracer_sink( - mrc::segment::Builder& seg, + mrc::segment::IBuilder& seg, const std::string& name, std::function sink_f); @@ -85,19 +85,19 @@ class ThroughputWatcher : public throughput_watcher_t std::function payload_init); void make_segment(const std::string& name, - const std::function& init); + const std::function& init); - std::shared_ptr make_tracer_source(mrc::segment::Builder& seg, + std::shared_ptr make_tracer_source(mrc::segment::IBuilder& seg, const std::string& name, bool force_sequential = false); std::shared_ptr make_traced_node( - mrc::segment::Builder& seg, + mrc::segment::IBuilder& seg, const std::string& name, std::function map_f); std::shared_ptr make_tracer_sink( - mrc::segment::Builder& seg, + mrc::segment::IBuilder& seg, const std::string& name, std::function sink_f); diff --git a/python/mrc/_pymrc/src/executor.cpp b/python/mrc/_pymrc/src/executor.cpp index 2d07fc826..a62e2c1e7 100644 --- a/python/mrc/_pymrc/src/executor.cpp +++ b/python/mrc/_pymrc/src/executor.cpp @@ -18,17 +18,17 @@ #include "pymrc/executor.hpp" // IWYU pragma: associated #include "pymrc/pipeline.hpp" -#include "pymrc/system.hpp" -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" +#include "mrc/pipeline/executor.hpp" #include "mrc/pipeline/pipeline.hpp" // IWYU pragma: keep +#include "mrc/pipeline/system.hpp" #include "mrc/types.hpp" #include #include #include #include +#include #include #include #include @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,92 @@ namespace mrc::pymrc { namespace py = pybind11; +std::function create_gil_initializer() +{ + bool has_pydevd_trace = false; + + // We check if there is a debugger by looking at sys.gettrace() and seeing if the function contains 'pydevd' + // somewhere in the module name. Its important to get this right because calling `debugpy.debug_this_thread()` + // will fail if there is no debugger and can dramatically alter performanc + auto sys = pybind11::module_::import("sys"); + + auto trace_func = sys.attr("gettrace")(); + + if (!trace_func.is_none()) + { + // Convert it to a string to quickly get its module and name + auto trace_func_str = pybind11::str(trace_func); + + if (!trace_func_str.attr("find")("pydevd").equal(pybind11::int_(-1))) + { + VLOG(10) << "Found pydevd trace function. Will attempt to enable debugging for MRC threads."; + has_pydevd_trace = true; + } + } + + return [has_pydevd_trace] { + pybind11::gil_scoped_acquire gil; + + // Increment the ref once to prevent creating and destroying the thread state constantly + gil.inc_ref(); + + try + { + // Try to load debugpy only if we found a trace function + if (has_pydevd_trace) + { + auto debugpy = pybind11::module_::import("debugpy"); + + auto debug_this_thread = debugpy.attr("debug_this_thread"); + + debug_this_thread(); + + VLOG(10) << "Debugging enabled from mrc threads"; + } + } catch (pybind11::error_already_set& err) + { + if (err.matches(PyExc_ImportError)) + { + VLOG(10) << "Debugging disabled. Breakpoints will not be hit. Could import error on debugpy"; + // Fail silently + } + else + { + VLOG(10) << "Debugging disabled. Breakpoints will not be hit. Unknown error: " << err.what(); + // Rethrow everything else + throw; + } + } + }; +} + +std::function create_gil_finalizer() +{ + bool python_finalizing = _Py_IsFinalizing() != 0; + + if (python_finalizing) + { + // If python if finalizing, dont worry about thread state + return nullptr; + } + + // Ensure we dont have the GIL here otherwise this deadlocks. + return [] { + bool python_finalizing = _Py_IsFinalizing() != 0; + + if (python_finalizing) + { + // If python if finalizing, dont worry about thread state + return; + } + + pybind11::gil_scoped_acquire gil; + + // Decrement the ref to destroy the GIL states + gil.dec_ref(); + }; +} + class StopIteration : public py::stop_iteration { public: @@ -136,9 +223,16 @@ Executor::Executor(std::shared_ptr options) auto result = pthread_sigmask(SIG_BLOCK, &sigset, &pysigset); // Now create the executor - auto system = std::make_unique(options); - auto resources = std::make_unique(std::move(system)); - m_exec = std::make_shared(std::move(resources)); + auto system = mrc::make_system(options); + + // Now add the gil initializers and finalizers + system->add_thread_initializer(create_gil_initializer()); + system->add_thread_finalizer(create_gil_finalizer()); + + // Must release the GIL while we create the executor + pybind11::gil_scoped_release nogil; + + m_exec = mrc::make_executor(std::move(system)); } Executor::~Executor() @@ -163,7 +257,7 @@ Executor::~Executor() void Executor::register_pipeline(pymrc::Pipeline& pipeline) { - m_exec->register_pipeline(pipeline.swap()); + m_exec->register_pipeline(pipeline.get_wrapped()); } void Executor::start() @@ -217,7 +311,7 @@ std::shared_ptr Executor::join_async() return std::make_shared(std::move(py_fiber_future)); } -std::shared_ptr Executor::get_executor() const +std::shared_ptr Executor::get_executor() const { return m_exec; } diff --git a/python/mrc/_pymrc/src/module_registry.cpp b/python/mrc/_pymrc/src/module_registry.cpp index 123e01298..424eb2b68 100644 --- a/python/mrc/_pymrc/src/module_registry.cpp +++ b/python/mrc/_pymrc/src/module_registry.cpp @@ -69,7 +69,7 @@ pybind11::cpp_function ModuleRegistryProxy::get_module_constructor(const std::st void ModuleRegistryProxy::register_module(std::string name, const registry_version_t& release_version, - std::function fn_py_initializer) + std::function fn_py_initializer) { register_module(name, "default", release_version, fn_py_initializer); } @@ -77,7 +77,7 @@ void ModuleRegistryProxy::register_module(std::string name, void ModuleRegistryProxy::register_module(std::string name, std::string registry_namespace, const registry_version_t& release_version, - std::function fn_py_initializer) + std::function fn_py_initializer) { VLOG(2) << "Registering python module: " << registry_namespace << "::" << name; auto fn_constructor = [fn_py_initializer](std::string name, nlohmann::json config) { diff --git a/python/mrc/_pymrc/src/pipeline.cpp b/python/mrc/_pymrc/src/pipeline.cpp index 3a144a8e0..e5d2fd53a 100644 --- a/python/mrc/_pymrc/src/pipeline.cpp +++ b/python/mrc/_pymrc/src/pipeline.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include namespace mrc::pymrc { @@ -162,13 +161,13 @@ PipelineEgressInfo collect_egress_info(py::list ids) } } // namespace -Pipeline::Pipeline() : m_pipeline(mrc::pipeline::make_pipeline()) {} +Pipeline::Pipeline() : m_pipeline(mrc::make_pipeline()) {} Pipeline::~Pipeline() = default; -void Pipeline::make_segment(const std::string& name, const std::function& init) +void Pipeline::make_segment(const std::string& name, const std::function& init) { - auto init_wrapper = [=](mrc::segment::Builder& seg) { + auto init_wrapper = [=](mrc::segment::IBuilder& seg) { py::gil_scoped_acquire gil; init(seg); }; @@ -179,14 +178,14 @@ void Pipeline::make_segment(const std::string& name, const std::function& init) + const std::function& init) { if (ingress_port_info.empty() && egress_port_info.empty()) { return make_segment(name, init); } - auto init_wrapper = [init](mrc::segment::Builder& seg) { + auto init_wrapper = [init](mrc::segment::IBuilder& seg) { py::gil_scoped_acquire gil; init(seg); }; @@ -202,10 +201,9 @@ void Pipeline::make_segment(const std::string& name, m_pipeline->make_segment(name, ingress_ports, egress_ports, init_wrapper); } -std::unique_ptr Pipeline::swap() +std::shared_ptr Pipeline::get_wrapped() const { - auto tmp = std::move(m_pipeline); - m_pipeline = mrc::pipeline::make_pipeline(); - return std::move(tmp); + return m_pipeline; } + } // namespace mrc::pymrc diff --git a/python/mrc/_pymrc/src/py_segment_module.cpp b/python/mrc/_pymrc/src/py_segment_module.cpp index 8c9fd477c..d9e44621f 100644 --- a/python/mrc/_pymrc/src/py_segment_module.cpp +++ b/python/mrc/_pymrc/src/py_segment_module.cpp @@ -33,7 +33,7 @@ PythonSegmentModule::PythonSegmentModule(std::string module_name, nlohmann::json SegmentModule(std::move(module_name), std::move(config)) {} -void PythonSegmentModule::initialize(segment::Builder& builder) +void PythonSegmentModule::initialize(segment::IBuilder& builder) { VLOG(2) << "Calling PythonSegmentModule::initialize"; m_py_initialize(builder); diff --git a/python/mrc/_pymrc/src/segment.cpp b/python/mrc/_pymrc/src/segment.cpp index 93d79ba4d..4e60e63e4 100644 --- a/python/mrc/_pymrc/src/segment.cpp +++ b/python/mrc/_pymrc/src/segment.cpp @@ -220,7 +220,7 @@ class PyIteratorWrapper std::function m_iter_factory; }; -std::shared_ptr build_source(mrc::segment::Builder& self, +std::shared_ptr build_source(mrc::segment::IBuilder& self, const std::string& name, PyIteratorWrapper iter_wrapper) { @@ -257,7 +257,7 @@ std::shared_ptr build_source(mrc::segment::Build return self.construct_object>(name, wrapper); } -std::shared_ptr build_source_component(mrc::segment::Builder& self, +std::shared_ptr build_source_component(mrc::segment::IBuilder& self, const std::string& name, PyIteratorWrapper iter_wrapper) { @@ -287,49 +287,49 @@ std::shared_ptr build_source_component(mrc::segm return self.construct_object>(name, std::move(get_next)); } -std::shared_ptr BuilderProxy::make_source(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_source(mrc::segment::IBuilder& self, const std::string& name, py::iterator source_iterator) { return build_source(self, name, PyIteratorWrapper(std::move(source_iterator))); } -std::shared_ptr BuilderProxy::make_source(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_source(mrc::segment::IBuilder& self, const std::string& name, py::iterable source_iterable) { return build_source(self, name, PyIteratorWrapper(std::move(source_iterable))); } -std::shared_ptr BuilderProxy::make_source(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_source(mrc::segment::IBuilder& self, const std::string& name, py::function gen_factory) { return build_source(self, name, PyIteratorWrapper(std::move(gen_factory))); } -std::shared_ptr BuilderProxy::make_source_component(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_source_component(mrc::segment::IBuilder& self, const std::string& name, pybind11::iterator source_iterator) { return build_source_component(self, name, PyIteratorWrapper(std::move(source_iterator))); } -std::shared_ptr BuilderProxy::make_source_component(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_source_component(mrc::segment::IBuilder& self, const std::string& name, py::iterable source_iterable) { return build_source_component(self, name, PyIteratorWrapper(std::move(source_iterable))); } -std::shared_ptr BuilderProxy::make_source_component(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_source_component(mrc::segment::IBuilder& self, const std::string& name, pybind11::function gen_factory) { return build_source_component(self, name, PyIteratorWrapper(std::move(gen_factory))); } -std::shared_ptr BuilderProxy::make_sink(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_sink(mrc::segment::IBuilder& self, const std::string& name, OnNextFunction on_next, OnErrorFunction on_error, @@ -338,7 +338,7 @@ std::shared_ptr BuilderProxy::make_sink(mrc::seg return self.make_sink(name, on_next, on_error, on_completed); } -std::shared_ptr BuilderProxy::make_sink_component(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_sink_component(mrc::segment::IBuilder& self, const std::string& name, OnNextFunction on_next, OnErrorFunction on_error, @@ -347,7 +347,7 @@ std::shared_ptr BuilderProxy::make_sink_componen return self.make_sink_component(name, on_next, on_error, on_completed); } -std::shared_ptr BuilderProxy::get_ingress(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::get_ingress(mrc::segment::IBuilder& self, const std::string& name) { auto it_caster = node::PortRegistry::s_port_to_type_index.find(name); @@ -360,7 +360,7 @@ std::shared_ptr BuilderProxy::get_ingress(mrc::s return self.get_ingress(name); } -std::shared_ptr BuilderProxy::get_egress(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::get_egress(mrc::segment::IBuilder& self, const std::string& name) { auto it_caster = node::PortRegistry::s_port_to_type_index.find(name); @@ -374,7 +374,7 @@ std::shared_ptr BuilderProxy::get_egress(mrc::se return self.get_egress(name); } -std::shared_ptr BuilderProxy::make_node(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_node(mrc::segment::IBuilder& self, const std::string& name, OnDataFunction on_data) { @@ -386,7 +386,7 @@ std::shared_ptr BuilderProxy::make_node(mrc::seg return BuilderProxy::make_node(self, name, py::args(py::make_tuple(py::cast(OperatorsProxy::map(on_data))))); } -std::shared_ptr BuilderProxy::make_node(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_node(mrc::segment::IBuilder& self, const std::string& name, pybind11::args operators) { @@ -404,7 +404,7 @@ std::shared_ptr BuilderProxy::make_node(mrc::seg } std::shared_ptr BuilderProxy::make_node_full( - mrc::segment::Builder& self, + mrc::segment::IBuilder& self, const std::string& name, std::function sub_fn) { @@ -442,7 +442,7 @@ std::shared_ptr BuilderProxy::make_node_full( return node; } -std::shared_ptr BuilderProxy::make_node_component(mrc::segment::Builder& self, +std::shared_ptr BuilderProxy::make_node_component(mrc::segment::IBuilder& self, const std::string& name, pybind11::args operators) { @@ -458,7 +458,7 @@ std::shared_ptr BuilderProxy::make_node_componen } std::shared_ptr BuilderProxy::load_module_from_registry( - mrc::segment::Builder& self, + mrc::segment::IBuilder& self, const std::string& module_id, const std::string& registry_namespace, std::string module_name, @@ -469,33 +469,33 @@ std::shared_ptr BuilderProxy::load_module_from_regi return self.load_module_from_registry(module_id, registry_namespace, std::move(module_name), std::move(json_config)); } -void BuilderProxy::init_module(mrc::segment::Builder& self, std::shared_ptr smodule) +void BuilderProxy::init_module(mrc::segment::IBuilder& self, std::shared_ptr smodule) { self.init_module(smodule); } -void BuilderProxy::register_module_input(mrc::segment::Builder& self, +void BuilderProxy::register_module_input(mrc::segment::IBuilder& self, std::string input_name, std::shared_ptr object) { self.register_module_input(std::move(input_name), object); } -void BuilderProxy::register_module_output(mrc::segment::Builder& self, +void BuilderProxy::register_module_output(mrc::segment::IBuilder& self, std::string output_name, std::shared_ptr object) { self.register_module_output(std::move(output_name), object); } -py::dict BuilderProxy::get_current_module_config(mrc::segment::Builder& self) +py::dict BuilderProxy::get_current_module_config(mrc::segment::IBuilder& self) { auto json_config = self.get_current_module_config(); return cast_from_json(json_config); } -void BuilderProxy::make_edge(mrc::segment::Builder& self, +void BuilderProxy::make_edge(mrc::segment::IBuilder& self, std::shared_ptr source, std::shared_ptr sink) { diff --git a/python/mrc/_pymrc/src/system.cpp b/python/mrc/_pymrc/src/system.cpp deleted file mode 100644 index 7e0189d25..000000000 --- a/python/mrc/_pymrc/src/system.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. - */ - -#include "pymrc/system.hpp" - -#include "mrc/engine/system/isystem.hpp" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace mrc::pymrc { - -System::System(std::shared_ptr options) : internal::system::ISystem(std::move(options)) {} - -SystemResources::SystemResources(std::shared_ptr system) : internal::system::IResources(std::move(system)) -{ - add_gil_initializer(); - add_gil_finalizer(); -} - -void SystemResources::add_gil_initializer() -{ - bool has_pydevd_trace = false; - - // We check if there is a debugger by looking at sys.gettrace() and seeing if the function contains 'pydevd' - // somewhere in the module name. Its important to get this right because calling `debugpy.debug_this_thread()` - // will fail if there is no debugger and can dramatically alter performanc - auto sys = pybind11::module_::import("sys"); - - auto trace_func = sys.attr("gettrace")(); - - if (!trace_func.is_none()) - { - // Convert it to a string to quickly get its module and name - auto trace_func_str = pybind11::str(trace_func); - - if (!trace_func_str.attr("find")("pydevd").equal(pybind11::int_(-1))) - { - VLOG(10) << "Found pydevd trace function. Will attempt to enable debugging for MRC threads."; - has_pydevd_trace = true; - } - } - - // Release the GIL for the remainder - pybind11::gil_scoped_release nogil; - - internal::system::IResources::add_thread_initializer([has_pydevd_trace] { - pybind11::gil_scoped_acquire gil; - - // Increment the ref once to prevent creating and destroying the thread state constantly - gil.inc_ref(); - - try - { - // Try to load debugpy only if we found a trace function - if (has_pydevd_trace) - { - auto debugpy = pybind11::module_::import("debugpy"); - - auto debug_this_thread = debugpy.attr("debug_this_thread"); - - debug_this_thread(); - - VLOG(10) << "Debugging enabled from mrc threads"; - } - } catch (pybind11::error_already_set& err) - { - if (err.matches(PyExc_ImportError)) - { - VLOG(10) << "Debugging disabled. Breakpoints will not be hit. Could import error on debugpy"; - // Fail silently - } - else - { - VLOG(10) << "Debugging disabled. Breakpoints will not be hit. Unknown error: " << err.what(); - // Rethrow everything else - throw; - } - } - }); -} - -void SystemResources::add_gil_finalizer() -{ - bool python_finalizing = _Py_IsFinalizing() != 0; - - if (python_finalizing) - { - // If python if finalizing, dont worry about thread state - return; - } - - // Ensure we dont have the GIL here otherwise this deadlocks. - - internal::system::IResources::add_thread_finalizer([] { - bool python_finalizing = _Py_IsFinalizing() != 0; - - if (python_finalizing) - { - // If python if finalizing, dont worry about thread state - return; - } - - pybind11::gil_scoped_acquire gil; - - // Decrement the ref to destroy the GIL states - gil.dec_ref(); - }); -} - -} // namespace mrc::pymrc diff --git a/python/mrc/_pymrc/src/watchers.cpp b/python/mrc/_pymrc/src/watchers.cpp index 8b77b3826..d474d7ae4 100644 --- a/python/mrc/_pymrc/src/watchers.cpp +++ b/python/mrc/_pymrc/src/watchers.cpp @@ -63,11 +63,11 @@ LatencyWatcher::LatencyWatcher(std::shared_ptr executor, {} void LatencyWatcher::make_segment(const std::string& name, - const std::function& init) + const std::function& init) { pymrc::Pipeline pipeline; - auto tracer_init_wrapper = [this, init](mrc::segment::Builder& seg) { + auto tracer_init_wrapper = [this, init](mrc::segment::IBuilder& seg) { init(seg, *this); }; @@ -75,7 +75,7 @@ void LatencyWatcher::make_segment(const std::string& name, m_executor->register_pipeline(pipeline); } -std::shared_ptr LatencyWatcher::make_tracer_source(mrc::segment::Builder& seg, +std::shared_ptr LatencyWatcher::make_tracer_source(mrc::segment::IBuilder& seg, const std::string& name, bool force_sequential) { @@ -90,7 +90,7 @@ std::shared_ptr LatencyWatcher::make_tracer_sour } std::shared_ptr LatencyWatcher::make_traced_node( - mrc::segment::Builder& seg, + mrc::segment::IBuilder& seg, const std::string& name, std::function map_f) { @@ -117,7 +117,7 @@ std::shared_ptr LatencyWatcher::make_traced_node } std::shared_ptr LatencyWatcher::make_tracer_sink( - mrc::segment::Builder& seg, + mrc::segment::IBuilder& seg, const std::string& name, std::function sink_f) { @@ -161,11 +161,11 @@ ThroughputWatcher::ThroughputWatcher(std::shared_ptr executor, {} void ThroughputWatcher::make_segment(const std::string& name, - const std::function& init) + const std::function& init) { pymrc::Pipeline pipeline; - auto tracer_init_wrapper = [this, init](mrc::segment::Builder& seg) { + auto tracer_init_wrapper = [this, init](mrc::segment::IBuilder& seg) { init(seg, *this); }; @@ -173,7 +173,7 @@ void ThroughputWatcher::make_segment(const std::string& name, m_executor->register_pipeline(pipeline); } -std::shared_ptr ThroughputWatcher::make_tracer_source(mrc::segment::Builder& seg, +std::shared_ptr ThroughputWatcher::make_tracer_source(mrc::segment::IBuilder& seg, const std::string& name, bool force_sequential) { @@ -188,7 +188,7 @@ std::shared_ptr ThroughputWatcher::make_tracer_s } std::shared_ptr ThroughputWatcher::make_traced_node( - mrc::segment::Builder& seg, + mrc::segment::IBuilder& seg, const std::string& name, std::function map_f) { @@ -215,7 +215,7 @@ std::shared_ptr ThroughputWatcher::make_traced_n } std::shared_ptr ThroughputWatcher::make_tracer_sink( - mrc::segment::Builder& seg, + mrc::segment::IBuilder& seg, const std::string& name, std::function sink_f) { diff --git a/python/mrc/_pymrc/tests/test_executor.cpp b/python/mrc/_pymrc/tests/test_executor.cpp index aa1e05a11..41e284d91 100644 --- a/python/mrc/_pymrc/tests/test_executor.cpp +++ b/python/mrc/_pymrc/tests/test_executor.cpp @@ -50,7 +50,7 @@ TEST_F(TestExecutor, Execute) std::atomic counter = 0; pymrc::Pipeline p; - auto init = [&counter](mrc::segment::Builder& seg) { + auto init = [&counter](mrc::segment::IBuilder& seg) { auto src = seg.make_source("src", [](rxcpp::subscriber& s) { if (s.is_subscribed()) { diff --git a/python/mrc/_pymrc/tests/test_pipeline.cpp b/python/mrc/_pymrc/tests/test_pipeline.cpp index 8b53f49bd..68091ba14 100644 --- a/python/mrc/_pymrc/tests/test_pipeline.cpp +++ b/python/mrc/_pymrc/tests/test_pipeline.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -79,9 +80,9 @@ PYMRC_TEST_CLASS(Pipeline); // TEST_F(TestPipeline, MakeSegment) // { // pymrc::Pipeline p; -// p.make_segment("turtle"s, [](mrc::segment::Builder& seg) {}); -// p.make_segment("lizard"s, [](mrc::segment::Builder& seg) {}); -// p.make_segment("frog"s, [](mrc::segment::Builder& seg) {}); +// p.make_segment("turtle"s, [](mrc::segment::IBuilder& seg) {}); +// p.make_segment("lizard"s, [](mrc::segment::IBuilder& seg) {}); +// p.make_segment("frog"s, [](mrc::segment::IBuilder& seg) {}); // auto pipe_ptr = p.swap(); // EXPECT_EQ(pipe_ptr->segment_count(), 3); @@ -95,7 +96,7 @@ TEST_F(TestPipeline, Execute) std::atomic counter = 0; pymrc::Pipeline p; - auto init = [&counter](mrc::segment::Builder& seg) { + auto init = [&counter](mrc::segment::IBuilder& seg) { auto src = seg.make_source("src", [](rxcpp::subscriber& s) { if (s.is_subscribed()) { @@ -140,8 +141,8 @@ TEST_F(TestPipeline, DynamicPortConstructionGood) { pymrc::PortBuilderUtil::register_port_util(); - std::string name = "xyz"; - std::function init = [](mrc::segment::Builder& builder) { + std::string name = "xyz"; + std::function init = [](mrc::segment::IBuilder& builder) { std::cerr << "Builder called" << std::endl; }; @@ -186,8 +187,8 @@ TEST_F(TestPipeline, DynamicPortConstructionBadDuplicatePorts) { pymrc::PortBuilderUtil::register_port_util(); - std::string name = "xyz"; - std::function init = [](mrc::segment::Builder& builder) { + std::string name = "xyz"; + std::function init = [](mrc::segment::IBuilder& builder) { std::cerr << "Builder called" << std::endl; }; @@ -233,8 +234,8 @@ TEST_F(TestPipeline, DynamicPortsIngressEgressMultiSegmentSingleExecutor) std::vector source_segment_egress_ids{"source_1", "source_2", "source_3", "source_4"}; std::vector intermediate_segment_egress_ids{"internal_1", "internal_2", "internal_3", "internal_4"}; - std::function seg1_init = - [source_segment_egress_ids](mrc::segment::Builder& builder) { + std::function seg1_init = + [source_segment_egress_ids](mrc::segment::IBuilder& builder) { for (int i = 0; i < source_segment_egress_ids.size(); i++) { auto src = builder.make_source( @@ -257,7 +258,7 @@ TEST_F(TestPipeline, DynamicPortsIngressEgressMultiSegmentSingleExecutor) py::gil_scoped_acquire gil; auto egress_test = builder.get_egress(source_segment_egress_ids[i]); - EXPECT_TRUE(source_segment_egress_ids[i] == egress_test->name()); + EXPECT_TRUE(std::get<0>(builder.normalize_name(source_segment_egress_ids[i])) == egress_test->name()); EXPECT_TRUE(egress_test->is_sink()); builder.make_edge(src, egress_test); } @@ -265,12 +266,12 @@ TEST_F(TestPipeline, DynamicPortsIngressEgressMultiSegmentSingleExecutor) LOG(INFO) << "Finished TestSegment1 Initialization"; }; - std::function seg2_init = - [source_segment_egress_ids, intermediate_segment_egress_ids](mrc::segment::Builder& builder) { + std::function seg2_init = + [source_segment_egress_ids, intermediate_segment_egress_ids](mrc::segment::IBuilder& builder) { for (auto ingress_it : source_segment_egress_ids) { auto ingress_test = builder.get_ingress(ingress_it); - EXPECT_TRUE(ingress_it == ingress_test->name()); + EXPECT_TRUE(std::get<0>(builder.normalize_name(ingress_it)) == ingress_test->name()); EXPECT_TRUE(ingress_test->is_source()); } @@ -284,8 +285,8 @@ TEST_F(TestPipeline, DynamicPortsIngressEgressMultiSegmentSingleExecutor) LOG(INFO) << "Finished TestSegment2 Initialization"; }; - std::function seg3_init = - [&sink_count, intermediate_segment_egress_ids](mrc::segment::Builder& builder) { + std::function seg3_init = + [&sink_count, intermediate_segment_egress_ids](mrc::segment::IBuilder& builder) { for (int i = 0; i < intermediate_segment_egress_ids.size(); ++i) { auto ingress = builder.get_ingress(intermediate_segment_egress_ids[i]); diff --git a/python/mrc/core/node.cpp b/python/mrc/core/node.cpp index e335ac7c4..bbbdfe658 100644 --- a/python/mrc/core/node.cpp +++ b/python/mrc/core/node.cpp @@ -52,7 +52,7 @@ PYBIND11_MODULE(node, py_mod) py::class_, mrc::segment::ObjectProperties, std::shared_ptr>>(py_mod, "Broadcast") - .def(py::init<>([](mrc::segment::Builder& builder, std::string name) { + .def(py::init<>([](mrc::segment::IBuilder& builder, std::string name) { auto node = builder.construct_object(name); return node; diff --git a/python/mrc/core/pipeline.cpp b/python/mrc/core/pipeline.cpp index 7cae96959..2f1dcf970 100644 --- a/python/mrc/core/pipeline.cpp +++ b/python/mrc/core/pipeline.cpp @@ -54,14 +54,14 @@ PYBIND11_MODULE(pipeline, py_mod) .def( "make_segment", wrap_segment_init_callback( - static_cast&)>( + static_cast&)>( &Pipeline::make_segment))) .def("make_segment", wrap_segment_init_callback( static_cast&)>( + const std::function&)>( &Pipeline::make_segment))); py_mod.attr("__version__") = MRC_CONCAT_STR(mrc_VERSION_MAJOR << "." << mrc_VERSION_MINOR << "." diff --git a/python/mrc/core/segment.cpp b/python/mrc/core/segment.cpp index 99d2269ef..ed87f83f2 100644 --- a/python/mrc/core/segment.cpp +++ b/python/mrc/core/segment.cpp @@ -27,9 +27,9 @@ #include "pymrc/utils.hpp" #include "mrc/edge/edge_connector.hpp" +#include "mrc/pipeline/segment.hpp" #include "mrc/runnable/launch_options.hpp" #include "mrc/segment/builder.hpp" -#include "mrc/segment/definition.hpp" #include "mrc/segment/object.hpp" #include "mrc/utils/string_utils.hpp" #include "mrc/version.hpp" @@ -104,8 +104,8 @@ PYBIND11_MODULE(segment, py_mod) py::overload_cast<>(&mrc::segment::ObjectProperties::launch_options), py::return_value_policy::reference_internal); - auto Builder = py::class_(py_mod, "Builder"); - auto Definition = py::class_(py_mod, "Definition"); + auto Builder = py::class_(py_mod, "Builder"); + auto Segment = py::class_(py_mod, "Segment"); init_segment_modules(py_mod); init_segment_module_registry(py_mod); @@ -120,37 +120,37 @@ PYBIND11_MODULE(segment, py_mod) */ Builder.def( "make_source", - static_cast (*)(mrc::segment::Builder&, + static_cast (*)(mrc::segment::IBuilder&, const std::string&, py::iterator)>(&BuilderProxy::make_source)); Builder.def( "make_source", - static_cast (*)(mrc::segment::Builder&, + static_cast (*)(mrc::segment::IBuilder&, const std::string&, py::iterable)>(&BuilderProxy::make_source), py::return_value_policy::reference_internal); Builder.def( "make_source", - static_cast (*)(mrc::segment::Builder&, + static_cast (*)(mrc::segment::IBuilder&, const std::string&, py::function)>(&BuilderProxy::make_source)); Builder.def("make_source_component", - static_cast (*)(mrc::segment::Builder&, + static_cast (*)(mrc::segment::IBuilder&, const std::string&, py::iterator)>( &BuilderProxy::make_source_component)); Builder.def("make_source_component", - static_cast (*)(mrc::segment::Builder&, + static_cast (*)(mrc::segment::IBuilder&, const std::string&, py::iterable)>( &BuilderProxy::make_source_component)); Builder.def("make_source_component", - static_cast (*)(mrc::segment::Builder&, + static_cast (*)(mrc::segment::IBuilder&, const std::string&, py::function)>( &BuilderProxy::make_source_component)); @@ -191,9 +191,10 @@ PYBIND11_MODULE(segment, py_mod) py::arg("on_error").none(true) = py::none(), py::arg("on_complete").none(true) = py::none()); - Builder.def("make_node", - py::overload_cast(&BuilderProxy::make_node), - py::return_value_policy::reference_internal); + Builder.def( + "make_node", + py::overload_cast(&BuilderProxy::make_node), + py::return_value_policy::reference_internal); /** * Construct a new 'pure' python::object -> python::object node @@ -202,9 +203,10 @@ PYBIND11_MODULE(segment, py_mod) * (py) @param name : Unique name of the node that will be created in the MRC Segment. * python-function which will be called on each data element as it flows through the node. */ - Builder.def("make_node", - py::overload_cast(&BuilderProxy::make_node), - py::return_value_policy::reference_internal); + Builder.def( + "make_node", + py::overload_cast(&BuilderProxy::make_node), + py::return_value_policy::reference_internal); Builder.def("make_node_component", &BuilderProxy::make_node_component, py::return_value_policy::reference_internal); diff --git a/python/mrc/core/segment/module_definitions/segment_module_registry.cpp b/python/mrc/core/segment/module_definitions/segment_module_registry.cpp index 1a9a177f5..0ae7b5728 100644 --- a/python/mrc/core/segment/module_definitions/segment_module_registry.cpp +++ b/python/mrc/core/segment/module_definitions/segment_module_registry.cpp @@ -65,7 +65,8 @@ void init_segment_module_registry(py::module_& smodule) SegmentModuleRegistry.def_static( "register_module", - static_cast&, std::function)>( + static_cast< + void (*)(std::string, const std::vector&, std::function)>( &ModuleRegistryProxy::register_module), py::arg("name"), py::arg("release_version"), @@ -76,7 +77,7 @@ void init_segment_module_registry(py::module_& smodule) static_cast&, - std::function)>(&ModuleRegistryProxy::register_module), + std::function)>(&ModuleRegistryProxy::register_module), py::arg("name"), py::arg("registry_namespace"), py::arg("release_version"), diff --git a/python/mrc/core/segment/module_definitions/segment_modules.cpp b/python/mrc/core/segment/module_definitions/segment_modules.cpp index 73e574a6f..08332dd40 100644 --- a/python/mrc/core/segment/module_definitions/segment_modules.cpp +++ b/python/mrc/core/segment/module_definitions/segment_modules.cpp @@ -33,7 +33,7 @@ namespace mrc::pymrc { namespace py = pybind11; -void PySegmentModule::initialize(segment::Builder& builder) +void PySegmentModule::initialize(segment::IBuilder& builder) { PYBIND11_OVERLOAD_PURE(void, mrc::modules::SegmentModule, initialize, builder); } diff --git a/python/mrc/core/segment/module_definitions/segment_modules.hpp b/python/mrc/core/segment/module_definitions/segment_modules.hpp index 91aea02ff..113c313e4 100644 --- a/python/mrc/core/segment/module_definitions/segment_modules.hpp +++ b/python/mrc/core/segment/module_definitions/segment_modules.hpp @@ -24,7 +24,7 @@ #include namespace mrc::segment { -class Builder; +class IBuilder; } namespace mrc::pymrc { @@ -34,7 +34,7 @@ class PySegmentModule : public mrc::modules::SegmentModule { using mrc::modules::SegmentModule::SegmentModule; - void initialize(segment::Builder& builder) override; + void initialize(segment::IBuilder& builder) override; std::string module_type_name() const override; }; diff --git a/python/mrc/tests/test_edges.cpp b/python/mrc/tests/test_edges.cpp index c9bc8e349..1e9cc0359 100644 --- a/python/mrc/tests/test_edges.cpp +++ b/python/mrc/tests/test_edges.cpp @@ -311,18 +311,18 @@ GENERATE_NODE_TYPES(TestNodeComponent, NodeComponent); GENERATE_NODE_TYPES(TestSink, Sink); GENERATE_NODE_TYPES(TestSinkComponent, SinkComponent); -#define CREATE_TEST_NODE_CLASS(class_name) \ - py::class_, \ - mrc::segment::ObjectProperties, \ - std::shared_ptr>>(py_mod, #class_name) \ - .def(py::init<>( \ - [](mrc::segment::Builder& parent, const std::string& name, py::dict counter, size_t msg_count) { \ - auto stage = parent.construct_object(name, name, std::move(counter), msg_count); \ - return stage; \ - }), \ - py::arg("parent"), \ - py::arg("name"), \ - py::arg("counter"), \ +#define CREATE_TEST_NODE_CLASS(class_name) \ + py::class_, \ + mrc::segment::ObjectProperties, \ + std::shared_ptr>>(py_mod, #class_name) \ + .def(py::init<>( \ + [](mrc::segment::IBuilder& parent, const std::string& name, py::dict counter, size_t msg_count) { \ + auto stage = parent.construct_object(name, name, std::move(counter), msg_count); \ + return stage; \ + }), \ + py::arg("parent"), \ + py::arg("name"), \ + py::arg("counter"), \ py::arg("msg_count") = 5); PYBIND11_MODULE(test_edges_cpp, py_mod) diff --git a/python/tests/test_stat_gather.py b/python/tests/test_stat_gather.py index 132ccfeca..3060b4ac7 100644 --- a/python/tests/test_stat_gather.py +++ b/python/tests/test_stat_gather.py @@ -103,6 +103,9 @@ def test_stat_gather_operators(): ("python_node_2x_2", "internal"), ("python_node_2x_3", "internal"), ("python_sink_double", "sink")] + # Convert to global names + required_components = [(f"/stat_gather_operators/{name}", node_type) for name, node_type in required_components] + framework_stats_info = mrc.benchmarking.get_tracing_stats() component_metrics = framework_stats_info["aggregations"]["components"]["metrics"] @@ -129,6 +132,9 @@ def test_stat_gather_channels(): ("python_node_2x_2", "internal"), ("python_node_2x_3", "internal"), ("python_sink_double", "sink")] + # Convert to global names + required_components = [(f"/stat_gather_channels/{name}", node_type) for name, node_type in required_components] + framework_stats_info = mrc.benchmarking.get_tracing_stats() component_metrics = framework_stats_info["aggregations"]["components"]["metrics"] @@ -155,6 +161,9 @@ def test_stat_gather_full(): ("python_node_2x_2", "internal"), ("python_node_2x_3", "internal"), ("python_sink_double", "sink")] + # Convert to global names + required_components = [(f"/stat_gather_full/{name}", node_type) for name, node_type in required_components] + framework_stats_info = mrc.benchmarking.get_tracing_stats() component_metrics = framework_stats_info["aggregations"]["components"]["metrics"] @@ -179,6 +188,9 @@ def test_stat_gather_full_noreset(): ("python_node_2x_2", "internal"), ("python_node_2x_3", "internal"), ("python_sink_double", "sink")] + # Convert to global names + required_components = [(f"/stat_gather_full_noreset/{name}", node_type) for name, node_type in required_components] + # TODO(devin): If we have two segments in the same binary, with the same node names, they will have their stats # merged. Is this what we want? for i in range(1, 5): @@ -208,6 +220,11 @@ def test_stat_gather_full_noreset_start_stop(): ("python_node_2x_2", "internal"), ("python_node_2x_3", "internal"), ("python_sink_double", "sink")] + # Convert to global names + required_components = [ + (f"/stat_gather_full_noreset_start_stop/{name}", node_type) for name, node_type in required_components + ] + active_trace_count = 0 for i in range(1, 10): # Randomly pause tracing between runs to verify counts are correct