diff --git a/.devcontainer/conda/Dockerfile b/.devcontainer/conda/Dockerfile new file mode 100644 index 000000000..d1ffbce77 --- /dev/null +++ b/.devcontainer/conda/Dockerfile @@ -0,0 +1,18 @@ +# 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. + +FROM rapidsai/devcontainers:23.04-cuda11.8-mambaforge-ubuntu22.04 AS base + +ENV PATH="${PATH}:/workspaces/mrc/.devcontainer/bin" diff --git a/.devcontainer/conda/devcontainer.json b/.devcontainer/conda/devcontainer.json new file mode 100644 index 000000000..219f6748b --- /dev/null +++ b/.devcontainer/conda/devcontainer.json @@ -0,0 +1,92 @@ +// SPDX-FileCopyrightText: Copyright (c) 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. +{ + "name": "mrc-dev", + "build": { + "dockerfile": "Dockerfile" + }, + "hostRequirements": { + "gpu": true + }, + "capAdd":[ + "SYS_NICE", + "SYS_PTRACE" + ], + "securityOpt": [ + "seccomp=unconfined" + ], + "runArgs": [ + "--network=host" + ], + "containerEnv": { + "HOST_MRC_ROOT": "${localWorkspaceFolder}", + "MRC_ROOT": "${containerWorkspaceFolder}", + "DEFAULT_CONDA_ENV": "mrc", + "MAMBA_NO_BANNER": "1", + "VAULT_HOST": "https://vault.ops.k8s.rapids.ai" + }, + "initializeCommand": [ "${localWorkspaceFolder}/.devcontainer/conda/initialize-command.sh" ], + "remoteUser": "coder", + "mounts": [ + { + "type": "bind", + "source": "${localWorkspaceFolder}/.cache/conda/envs", + "target": "/home/coder/.conda/envs" + }, + { + "type": "bind", + "source": "${localWorkspaceFolder}/../.conda/pkgs", + "target": "/home/coder/.conda/pkgs" + }, + { + "type": "bind", + "source": "${localWorkspaceFolder}/../.config", // parent folder because sister repos are sibling dirs + "target": "/home/coder/.config" + }, + { + "type": "bind", + "source": "${localWorkspaceFolder}/.devcontainer/opt/mrc", + "target": "/opt/mrc" + }, + ], + "features": { + "ghcr.io/devcontainers/features/dotnet:1": {} + }, + "customizations": { + "vscode": { + "extensions": [ + "eamodio.gitlens", + "formulahendry.terminal", + "hbenl.vscode-test-explorer", + "josetr.cmake-language-support-vscode", + "llvm-vs-code-extensions.vscode-clangd", + "matepek.vscode-catch2-test-adapter", + "ms-dotnettools.vscode-dotnet-runtime", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools-extension-pack", + "ms-vscode.cpptools-themes", + "ms-vscode.cpptools", + "ms-vscode.test-adapter-converter", + "xaver.clang-format" + ], + "settings": { + "cmake.cmakePath": "/tmp/.current-conda-env/bin/cmake", + "cmake.languageSupport.dotnetPath": "/usr/bin/dotnet", + "C_Cpp.intelliSenseEngine": "disabled", + "python.terminal.activateEnvironment": false + } + } + }, +} diff --git a/.devcontainer/conda/initialize-command.sh b/.devcontainer/conda/initialize-command.sh new file mode 100755 index 000000000..807451923 --- /dev/null +++ b/.devcontainer/conda/initialize-command.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# 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. + +# create the parent conda folder so it's found when mounting +mkdir -p ../.conda + +# create a config directory if it does not exist so it's found when mounting +mkdir -p ../.config diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 704e4519b..3c3973d03 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,3 +1,17 @@ +// SPDX-FileCopyrightText: Copyright (c) 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. { "build": { "args": { @@ -36,13 +50,15 @@ "hostRequirements": { "gpu": true }, + "initializeCommand": [ "${localWorkspaceFolder}/.devcontainer/initialize-command.sh" ], "mounts": [ + "source=${localEnv:HOME}/.config,target=/home/${localEnv:USER}/.config,type=bind", // Mount the necessary files for GDB pretty-printing to work - "source=${localWorkspaceFolder}/.devcontainer/home/.gdbinit,target=/home/${localEnv:USER}/.gdbinit,type=bind", - "source=${localWorkspaceFolder}/.devcontainer/home/.config/gdb,target=/home/${localEnv:USER}/.config/gdb,type=bind", - // Mount the Github CLI config directory to allow using the Github CLI - "source=${localEnv:HOME}/.config/gh,target=/home/${localEnv:USER}/.config/gh,type=bind", + "source=${localWorkspaceFolder}/.devcontainer/opt/mrc/etc/.gdbinit,target=/home/${localEnv:USER}/.gdbinit,type=bind", ], + "features": { + "ghcr.io/devcontainers/features/git-lfs": {} + }, "name": "mrc-dev", "overrideCommand": true, // infinite loop of sleeps, "remoteUser": "${localEnv:USER}", diff --git a/.devcontainer/home/.gdbinit b/.devcontainer/home/.gdbinit deleted file mode 100644 index 43e108353..000000000 --- a/.devcontainer/home/.gdbinit +++ /dev/null @@ -1,3 +0,0 @@ -add-auto-load-safe-path /opt/conda - -source ~/.config/gdb/enable_conda_libstd_pretty_print.py diff --git a/.devcontainer/init.sh b/.devcontainer/init.sh new file mode 100755 index 000000000..abb8593c0 --- /dev/null +++ b/.devcontainer/init.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 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. + +# create the github config directory if it does not exist so it's found when mounting +mkdir -p ~/.config/gh diff --git a/.devcontainer/initialize-command.sh b/.devcontainer/initialize-command.sh new file mode 100755 index 000000000..807451923 --- /dev/null +++ b/.devcontainer/initialize-command.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# 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. + +# create the parent conda folder so it's found when mounting +mkdir -p ../.conda + +# create a config directory if it does not exist so it's found when mounting +mkdir -p ../.config diff --git a/.devcontainer/opt/mrc/bin/post-attach-command.sh b/.devcontainer/opt/mrc/bin/post-attach-command.sh new file mode 100755 index 000000000..eb00a5061 --- /dev/null +++ b/.devcontainer/opt/mrc/bin/post-attach-command.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 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. + +# Ensure our ~/.config directory has the correct permissions. If ~/.config did +# not exist, and you mount ~/.config/gh from the host, then ~/.config will be +# created with root permissions which can break things + +conda_env_find(){ + conda env list | grep "${@}" >/dev/null 2>/dev/null +} + +ENV_NAME=${ENV_NAME:-mrc} + +sed -ri "s/conda activate base/conda activate $ENV_NAME/g" ~/.bashrc; + +if conda_env_find "${ENV_NAME}" ; \ + +then mamba env update --name ${ENV_NAME} -f ${MRC_ROOT}/ci/conda/environments/dev_env.yml --prune; \ +else mamba env create --name ${ENV_NAME} -f ${MRC_ROOT}/ci/conda/environments/dev_env.yml; \ +fi diff --git a/.github/ISSUE_TEMPLATE/submit_question.yml b/.devcontainer/opt/mrc/bin/update-content-command.sh old mode 100644 new mode 100755 similarity index 52% rename from .github/ISSUE_TEMPLATE/submit_question.yml rename to .devcontainer/opt/mrc/bin/update-content-command.sh index 221115449..2e025db79 --- a/.github/ISSUE_TEMPLATE/submit_question.yml +++ b/.devcontainer/opt/mrc/bin/update-content-command.sh @@ -1,4 +1,5 @@ -# SPDX-FileCopyrightText: Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +#!/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,22 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: Submit Question -description: Ask a general question about MRC -title: "[QST]: " -labels: ["question"] +# Ensure our ~/.config directory has the correct permissions. If ~/.config did +# not exist, and you mount ~/.config/gh from the host, then ~/.config will be +# created with root permissions which can break things -body: - - type: markdown - attributes: - value: | - Thanks for taking the time to ask us a question! - - - type: textarea - id: question - attributes: - label: What is your question? - description: Please be specific and we will answer your question as soon as possible. - placeholder: Does MRC integrate with XYZ software? - validations: - required: true +if [[ ! -f ~/.config/.gdbinit ]]; then + cp /opt/mrc/etc/.gdbinit ~/.config/.gdbinit +fi diff --git a/.devcontainer/opt/mrc/conda/Dockerfile b/.devcontainer/opt/mrc/conda/Dockerfile new file mode 100644 index 000000000..d1ffbce77 --- /dev/null +++ b/.devcontainer/opt/mrc/conda/Dockerfile @@ -0,0 +1,18 @@ +# 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. + +FROM rapidsai/devcontainers:23.04-cuda11.8-mambaforge-ubuntu22.04 AS base + +ENV PATH="${PATH}:/workspaces/mrc/.devcontainer/bin" diff --git a/.devcontainer/opt/mrc/conda/devcontainer.json b/.devcontainer/opt/mrc/conda/devcontainer.json new file mode 100644 index 000000000..6046d60a1 --- /dev/null +++ b/.devcontainer/opt/mrc/conda/devcontainer.json @@ -0,0 +1,92 @@ +// SPDX-FileCopyrightText: Copyright (c) 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. +{ + "name": "mrc-dev", + "build": { + "dockerfile": "Dockerfile" + }, + "hostRequirements": { + "gpu": true + }, + "capAdd":[ + "SYS_NICE", + "SYS_PTRACE" + ], + "securityOpt": [ + "seccomp=unconfined" + ], + "runArgs": [ + "--network=host" + ], + "containerEnv": { + "HOST_MRC_ROOT": "${localWorkspaceFolder}", + "MRC_ROOT": "${containerWorkspaceFolder}", + "DEFAULT_CONDA_ENV": "mrc", + "MAMBA_NO_BANNER": "1", + "VAULT_HOST": "https://vault.ops.k8s.rapids.ai" + }, + "initializeCommand": [ "${localWorkspaceFolder}/.devcontainer/initialize-command.sh" ], + "remoteUser": "coder", + "mounts": [ + { + "type": "bind", + "source": "${localWorkspaceFolder}/.cache/conda/envs", + "target": "/home/coder/.conda/envs" + }, + { + "type": "bind", + "source": "${localWorkspaceFolder}/../.conda/pkgs", + "target": "/home/coder/.conda/pkgs" + }, + { + "type": "bind", + "source": "${localWorkspaceFolder}/../.config", // parent folder because sister repos are sibling dirs + "target": "/home/coder/.config" + }, + { + "type": "bind", + "source": "${localWorkspaceFolder}/.devcontainer/opt/mrc", + "target": "/opt/mrc" + }, + ], + "features": { + "ghcr.io/devcontainers/features/dotnet:1": {} + }, + "customizations": { + "vscode": { + "extensions": [ + "eamodio.gitlens", + "formulahendry.terminal", + "hbenl.vscode-test-explorer", + "josetr.cmake-language-support-vscode", + "llvm-vs-code-extensions.vscode-clangd", + "matepek.vscode-catch2-test-adapter", + "ms-dotnettools.vscode-dotnet-runtime", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools-extension-pack", + "ms-vscode.cpptools-themes", + "ms-vscode.cpptools", + "ms-vscode.test-adapter-converter", + "xaver.clang-format" + ], + "settings": { + "cmake.cmakePath": "/tmp/.current-conda-env/bin/cmake", + "cmake.languageSupport.dotnetPath": "/usr/bin/dotnet", + "C_Cpp.intelliSenseEngine": "disabled", + "python.terminal.activateEnvironment": false + } + } + }, +} diff --git a/.devcontainer/opt/mrc/conda/initialize-command.sh b/.devcontainer/opt/mrc/conda/initialize-command.sh new file mode 100755 index 000000000..807451923 --- /dev/null +++ b/.devcontainer/opt/mrc/conda/initialize-command.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# 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. + +# create the parent conda folder so it's found when mounting +mkdir -p ../.conda + +# create a config directory if it does not exist so it's found when mounting +mkdir -p ../.config diff --git a/.devcontainer/opt/mrc/etc/.gdbinit b/.devcontainer/opt/mrc/etc/.gdbinit new file mode 100644 index 000000000..0fa2be45f --- /dev/null +++ b/.devcontainer/opt/mrc/etc/.gdbinit @@ -0,0 +1,3 @@ +add-auto-load-safe-path /opt/conda + +source /opt/mrc/etc/enable_conda_libstd_pretty_print.py diff --git a/.devcontainer/home/.config/gdb/enable_conda_libstd_pretty_print.py b/.devcontainer/opt/mrc/etc/enable_conda_libstd_pretty_print.py similarity index 100% rename from .devcontainer/home/.config/gdb/enable_conda_libstd_pretty_print.py rename to .devcontainer/opt/mrc/etc/enable_conda_libstd_pretty_print.py diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..0fee73782 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: Copyright (c) 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. + +blank_issues_enabled: true +contact_links: + - name: Ask a Question + url: https://github.com/nv-morpheus/morpheus/discussions + about: Please ask any questions here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..539f7f686 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,9 @@ +## Description + + + + +## Checklist +- [ ] I am familiar with the [Contributing Guidelines](https://github.com/nv-morpheus/Morpheus/blob/main/docs/source/developer_guide/contributing.md). +- [ ] New or existing tests cover these changes. +- [ ] The documentation is up to date with these changes. diff --git a/.github/workflows/add_to_project.yml b/.github/workflows/add_to_project.yml deleted file mode 100644 index 572804724..000000000 --- a/.github/workflows/add_to_project.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Add new issue/PR to project - -on: - issues: - types: - - opened - - pull_request_target: - types: - - opened - -jobs: - add-to-project: - name: Add issue or PR to project - runs-on: ubuntu-latest - steps: - - uses: actions/add-to-project@v0.3.0 - with: - project-url: https://github.com/orgs/nv-morpheus/projects/2 - github-token: ${{ github.token}} diff --git a/.github/workflows/ci_pipe.yml b/.github/workflows/ci_pipe.yml index 225d95f33..0c6da79f4 100644 --- a/.github/workflows/ci_pipe.yml +++ b/.github/workflows/ci_pipe.yml @@ -20,15 +20,27 @@ on: workflow_call: inputs: run_check: + description: 'Runs the check stage to verify code integrity' required: true type: boolean - run_package_conda: + conda_run_build: + description: 'Runs the conda-build stage to ensure the conda package builds successfully' required: true type: boolean + conda_upload_label: + description: 'The label to use when uploading the conda package. Leave empty to disable uploading' + required: true + type: string container: + description: 'The container to use for all stages except the test stage' required: true type: string test_container: + description: 'The container to use for the test stage' + required: true + type: string + pr_info: + description: 'The JSON string containing the PR information' required: true type: string secrets: @@ -39,6 +51,11 @@ on: NGC_API_KEY: required: true +# We only support ubuntu, so bash is the default +defaults: + run: + shell: bash + env: CHANGE_TARGET: "${{ github.base_ref }}" GH_TOKEN: "${{ github.token }}" @@ -66,7 +83,7 @@ jobs: check: if: ${{ inputs.run_check }} name: Check - runs-on: [self-hosted, linux, amd64, cpu4] + runs-on: linux-amd64-cpu4 timeout-minutes: 60 container: credentials: @@ -97,7 +114,7 @@ jobs: build: name: Build - runs-on: [self-hosted, linux, amd64, cpu16] + runs-on: linux-amd64-cpu16 timeout-minutes: 60 container: credentials: @@ -132,7 +149,7 @@ jobs: test: name: Test needs: [build] - runs-on: [self-hosted, linux, amd64, gpu-v100-525-1] + runs-on: linux-amd64-gpu-v100-latest-1 timeout-minutes: 60 container: credentials: @@ -171,7 +188,7 @@ jobs: codecov: name: Code Coverage - runs-on: [self-hosted, linux, amd64, gpu-v100-525-1] + runs-on: linux-amd64-gpu-v100-latest-1 timeout-minutes: 60 container: credentials: @@ -182,6 +199,7 @@ jobs: NVIDIA_VISIBLE_DEVICES: ${{ env.NVIDIA_VISIBLE_DEVICES }} PARALLEL_LEVEL: '10' image: ${{ inputs.test_container }} + options: "--cap-add=sys_nice --cap-add=sys_ptrace" strategy: fail-fast: true @@ -212,7 +230,7 @@ jobs: documentation: name: Documentation needs: [build] - runs-on: [self-hosted, linux, amd64, cpu4] + runs-on: linux-amd64-cpu4 timeout-minutes: 60 container: credentials: @@ -243,7 +261,7 @@ jobs: benchmark: name: Benchmark needs: [build] - runs-on: [self-hosted, linux, amd64, cpu4] + runs-on: linux-amd64-cpu4 timeout-minutes: 60 container: credentials: @@ -281,9 +299,9 @@ jobs: package: name: Package - if: ${{ inputs.run_package_conda }} + if: ${{ inputs.conda_run_build }} needs: [benchmark, documentation, test] - runs-on: [self-hosted, linux, amd64, cpu16] + runs-on: linux-amd64-cpu16 timeout-minutes: 60 container: credentials: @@ -312,4 +330,6 @@ jobs: shell: bash env: CONDA_TOKEN: "${{ secrets.CONDA_TOKEN }}" - run: ./mrc/ci/scripts/github/conda.sh + SCRIPT_ARGS: "${{ inputs.conda_upload_label != '' && 'upload' || '' }}" + CONDA_PKG_LABEL: "${{ inputs.conda_upload_label }}" + run: ./mrc/ci/scripts/github/conda.sh $SCRIPT_ARGS diff --git a/.github/workflows/label-external-issues.yml b/.github/workflows/label-external-issues.yml new file mode 100644 index 000000000..de7d668df --- /dev/null +++ b/.github/workflows/label-external-issues.yml @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: Copyright (c) 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. + +name: Triage outside issues + +on: + issues: + types: + - opened + +env: + GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_PAT }} + +jobs: + Label-Issue: + runs-on: ubuntu-latest + # Only run if the issue author is not part of NV-Morpheus + if: ${{ ! contains(fromJSON('["OWNER", "MEMBER", "CONTRIBUTOR"]'), github.event.issue.author_association)}} + steps: + - name: add-triage-label + run: | + issue_url=${{ github.event.issue.html_url }} + gh issue edit ${issue_url} --add-label "Needs Triage" + + - name: add-comment-to-issue + run: | + issue_url=${{ github.event.issue.html_url }} + author=${{ github.event.issue.user.login }} + echo ${author} + gh issue comment ${issue_url} --body "Hi @${author}! + + Thanks for submitting this issue - our team has been notified and we'll get back to you as soon as we can! + In the meantime, feel free to add any relevant information to this issue." diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index e310aa2d1..f10b02fea 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -43,13 +43,39 @@ permissions: statuses: none jobs: + prepare: + name: Prepare + runs-on: ubuntu-latest + container: + image: rapidsai/ci:latest + steps: + - name: Get PR Info + id: get-pr-info + uses: rapidsai/shared-action-workflows/get-pr-info@branch-23.08 + if: ${{ startsWith(github.ref_name, 'pull-request/') }} + outputs: + is_pr: ${{ startsWith(github.ref_name, 'pull-request/') }} + is_main_branch: ${{ github.ref_name == 'main' }} + is_dev_branch: ${{ startsWith(github.ref_name, 'branch-') }} + has_conda_build_label: ${{ steps.get-pr-info.outcome == 'success' && contains(fromJSON(steps.get-pr-info.outputs.pr-info).labels.*.name, 'conda-build') || false }} + pr_info: ${{ steps.get-pr-info.outcome == 'success' && steps.get-pr-info.outputs.pr-info || '' }} ci_pipe: + name: CI Pipeline + needs: [prepare] uses: ./.github/workflows/ci_pipe.yml with: - run_check: ${{ startsWith(github.ref_name, 'pull-request/') }} - run_package_conda: ${{ !startsWith(github.ref_name, 'pull-request/') }} - container: nvcr.io/ea-nvidia-morpheus/morpheus:mrc-ci-driver-230315 - test_container: nvcr.io/ea-nvidia-morpheus/morpheus:mrc-ci-test-230315 + # Run checks for any PR branch + run_check: ${{ fromJSON(needs.prepare.outputs.is_pr) }} + # Run conda-build for main/dev branches and PRs with the conda-build label + conda_run_build: ${{ !fromJSON(needs.prepare.outputs.is_pr) || fromJSON(needs.prepare.outputs.has_conda_build_label) }} + # Update conda package only for non PR branches. Use 'main' for main branch and 'dev' for all other branches + conda_upload_label: ${{ !fromJSON(needs.prepare.outputs.is_pr) && (fromJSON(needs.prepare.outputs.is_main_branch) && 'main' || 'dev') || '' }} + # Build container + container: nvcr.io/ea-nvidia-morpheus/morpheus:mrc-ci-build-230711 + # Test container + test_container: nvcr.io/ea-nvidia-morpheus/morpheus:mrc-ci-test-230711 + # Info about the PR. Empty for non PR branches. Useful for extracting PR number, title, etc. + pr_info: ${{ needs.prepare.outputs.pr_info }} secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} CONDA_TOKEN: ${{ secrets.CONDA_TOKEN }} diff --git a/.gitmodules b/.gitmodules index cdeafc917..76d78c90c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "morpheus_utils"] path = external/utilities url = https://github.com/nv-morpheus/utilities.git - branch = branch-23.03 + branch = branch-23.07 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f19e9aef..c10b0f7d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,56 @@ +# MRC 23.07.00 (19 Jul 2023) + +## 🚨 Breaking Changes + +- Remove `mrc::internals` namespace and cleanup class names ([#328](https://github.com/nv-morpheus/MRC/pull/328)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- Switch to using `cuda-toolkit` over `cudatoolkit` ([#320](https://github.com/nv-morpheus/MRC/pull/320)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- Update to Python 3.10 ([#317](https://github.com/nv-morpheus/MRC/pull/317)) [@cwharris](https://github.com/cwharris) + +## 🐛 Bug Fixes + +- Fixing actions running on non-PR branches ([#354](https://github.com/nv-morpheus/MRC/pull/354)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- Fix the conda build with RMM 23.02 ([#348](https://github.com/nv-morpheus/MRC/pull/348)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- Workaround GCC 11.3 compiler bug ([#339](https://github.com/nv-morpheus/MRC/pull/339)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- use correct ostream.h header location ([#333](https://github.com/nv-morpheus/MRC/pull/333)) [@cwharris](https://github.com/cwharris) +- Bug fix -- in some situations it was possible for persistent modules to overwrite each other ([#331](https://github.com/nv-morpheus/MRC/pull/331)) [@drobison00](https://github.com/drobison00) +- Release an RxNodeComponent edge on error ([#327](https://github.com/nv-morpheus/MRC/pull/327)) [@dagardner-nv](https://github.com/dagardner-nv) +- RxNodeComponent should set exceptions on the context ([#326](https://github.com/nv-morpheus/MRC/pull/326)) [@dagardner-nv](https://github.com/dagardner-nv) +- Update python debug detection for new version of `debugpy` ([#322](https://github.com/nv-morpheus/MRC/pull/322)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- Fix nullptr dereference in NvmlState ([#319](https://github.com/nv-morpheus/MRC/pull/319)) [@cwharris](https://github.com/cwharris) +- Dynamically loading `libnvidia-ml.so.1` instead of directly linking ([#313](https://github.com/nv-morpheus/MRC/pull/313)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- fix libabseil package name typo ([#310](https://github.com/nv-morpheus/MRC/pull/310)) [@cwharris](https://github.com/cwharris) + +## 📖 Documentation + +- Fix a few minor type-o's in comments ([#332](https://github.com/nv-morpheus/MRC/pull/332)) [@dagardner-nv](https://github.com/dagardner-nv) +- Fix license headers to only use a single /* comment to exclude it from doxygen ([#307](https://github.com/nv-morpheus/MRC/pull/307)) [@dagardner-nv](https://github.com/dagardner-nv) + +## 🚀 New Features + +- Use libgrpc=1.54 ([#353](https://github.com/nv-morpheus/MRC/pull/353)) [@cwharris](https://github.com/cwharris) +- Adding option to configure running the conda-build CI step with labels ([#349](https://github.com/nv-morpheus/MRC/pull/349)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- Upgrade RMM version to 23.06 ([#346](https://github.com/nv-morpheus/MRC/pull/346)) [@cwharris](https://github.com/cwharris) +- Create label-external-issues.yml ([#323](https://github.com/nv-morpheus/MRC/pull/323)) [@jarmak-nv](https://github.com/jarmak-nv) +- Support RMM 22.12 with Python 3.8 ([#318](https://github.com/nv-morpheus/MRC/pull/318)) [@cwharris](https://github.com/cwharris) +- Update to Python 3.10 ([#317](https://github.com/nv-morpheus/MRC/pull/317)) [@cwharris](https://github.com/cwharris) +- Adding an `update-version.sh` script and CI check to keep versions up to date ([#314](https://github.com/nv-morpheus/MRC/pull/314)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- Update to RMM 23.02 ([#309](https://github.com/nv-morpheus/MRC/pull/309)) [@cwharris](https://github.com/cwharris) +- Devcontainer Updates ([#297](https://github.com/nv-morpheus/MRC/pull/297)) [@cwharris](https://github.com/cwharris) +- add git-lfs and gh config dir ([#273](https://github.com/nv-morpheus/MRC/pull/273)) [@cwharris](https://github.com/cwharris) + +## 🛠️ Improvements + +- New CI images with rapids 23.06 ([#351](https://github.com/nv-morpheus/MRC/pull/351)) [@dagardner-nv](https://github.com/dagardner-nv) +- Remove patch from pybind11 ([#335](https://github.com/nv-morpheus/MRC/pull/335)) [@dagardner-nv](https://github.com/dagardner-nv) +- Remove `boost::filesystem` ([#334](https://github.com/nv-morpheus/MRC/pull/334)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- Remove `mrc::internals` namespace and cleanup class names ([#328](https://github.com/nv-morpheus/MRC/pull/328)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- Switch to using `cuda-toolkit` over `cudatoolkit` ([#320](https://github.com/nv-morpheus/MRC/pull/320)) [@mdemoret-nv](https://github.com/mdemoret-nv) +- GH Infra Updates: PR Template, Discussions, Add To Project Action ([#316](https://github.com/nv-morpheus/MRC/pull/316)) [@jarmak-nv](https://github.com/jarmak-nv) +- Use ARC V2 self-hosted runners for GPU jobs ([#315](https://github.com/nv-morpheus/MRC/pull/315)) [@jjacobelli](https://github.com/jjacobelli) +- Use newly built CI images with CUDA 11.8 ([#311](https://github.com/nv-morpheus/MRC/pull/311)) [@dagardner-nv](https://github.com/dagardner-nv) +- bump version to 23.07 ([#306](https://github.com/nv-morpheus/MRC/pull/306)) [@dagardner-nv](https://github.com/dagardner-nv) +- Use ARC V2 self-hosted runners for CPU jobs ([#302](https://github.com/nv-morpheus/MRC/pull/302)) [@jjacobelli](https://github.com/jjacobelli) + # MRC 23.03.00 (29 Mar 2023) ## 🚨 Breaking Changes diff --git a/CMakeLists.txt b/CMakeLists.txt index e19c3a8ba..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 "22.10" 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) @@ -63,7 +63,7 @@ list(PREPEND CMAKE_MODULE_PATH "${MRC_CMAKE_MODULE_PATH_EXTENSIONS}") list(PREPEND CMAKE_PREFIX_PATH "${MRC_CMAKE_PREFIX_PATH_EXTENSIONS}") # Load morpheus utils and update CMake paths -set(MORPHEUS_UTILS_RAPIDS_CMAKE_VERSION ${MRC_RAPIDS_VERSION}) +set(MORPHEUS_UTILS_RAPIDS_VERSION ${MRC_RAPIDS_VERSION}) set(MORPHEUS_UTILS_RAPIDS_CPM_INIT_OVERRIDE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/rapids_cpm_package_overrides.json") include(morpheus_utils/load) @@ -78,7 +78,7 @@ morpheus_utils_initialize_package_manager( morpheus_utils_initialize_cuda_arch(mrc) project(mrc - VERSION 23.03.00 + VERSION 23.07.00 LANGUAGES C CXX ) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08281aae7..b437ba321 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -77,41 +77,41 @@ Some options: #### Clone MRC repository ```bash -export MRC_HOME=$(pwd)/mrc -git clone --recurse-submodules git@github.com:nv-morpheus/mrc.git $MRC_HOME -cd $MRC_HOME +export MRC_ROOT=$(pwd)/mrc +git clone --recurse-submodules git@github.com:nv-morpheus/mrc.git $MRC_ROOT +cd $MRC_ROOT ``` #### Create MRC Conda environment ```bash # note: `mamba` may be used in place of `conda` for better performance. -conda env create -n mrc --file $MRC_HOME/ci/conda/environments/dev_env.yml +conda env create -n mrc --file $MRC_ROOT/ci/conda/environments/dev_env.yml conda activate mrc ``` #### Build MRC ```bash -mkdir $MRC_HOME/build -cd $MRC_HOME/build +mkdir $MRC_ROOT/build +cd $MRC_ROOT/build cmake .. make -j $(nproc) ``` #### Run MRC C++ Tests ```bash -export MRC_TEST_INTERNAL_DATA_PATH=$MRC_HOME/src/tests -$MRC_HOME/build/src/tests/test_mrc_private.x -$MRC_HOME/build/tests/test_mrc.x -$MRC_HOME/build/tests/logging/test_mrc_logging.x +export MRC_TEST_INTERNAL_DATA_PATH=$MRC_ROOT/cpp/mrc/src/tests +$MRC_ROOT/build/cpp/mrcsrc/tests/test_mrc_private.x +$MRC_ROOT/build/cpp/mrctests/test_mrc.x +$MRC_ROOT/build/cpp/mrctests/logging/test_mrc_logging.x ``` ### Install MRC Python ```bash -pip install -e $MRC_HOME/build/python +pip install -e $MRC_ROOT/build/python ``` #### Run MRC Python Tests ```bash -pytest $MRC_HOME/python +pytest $MRC_ROOT/python ``` ### Building API Documentation @@ -148,7 +148,7 @@ Thirdparty code included in the source tree (that is not pulled in as an externa Ex: ```c++ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/Dockerfile b/Dockerfile index 266d514c4..cae834533 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,13 +17,13 @@ ARG FROM_IMAGE="rapidsai/ci" -ARG CUDA_VER=11.4.1 +ARG CUDA_VER=11.8.0 ARG LINUX_DISTRO=ubuntu ARG LINUX_VER=20.04 -ARG PYTHON_VER=3.8 +ARG PYTHON_VER=3.10 # ============= base =================== -FROM ${FROM_IMAGE}:cuda11.4.1-ubuntu20.04-py3.8 AS base +FROM ${FROM_IMAGE}:cuda11.8.0-ubuntu20.04-py3.10 AS base ARG PROJ_NAME=mrc @@ -55,16 +55,11 @@ ENV CMAKE_CUDA_COMPILER_LAUNCHER= ENV CMAKE_CXX_COMPILER_LAUNCHER= ENV CMAKE_C_COMPILER_LAUNCHER= -# ============ driver ================== -FROM base as driver +# ============ build ================== +FROM base as build -RUN --mount=type=cache,target=/var/cache/apt \ - apt update && \ - DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC \ - apt install --no-install-recommends -y \ - libnvidia-compute-525 \ - && \ - rm -rf /var/lib/apt/lists/* +# Add any build only dependencies here. For now there is none but we need the +# target to get the CI runner build scripts to work # ============ test ================== FROM base as test @@ -103,8 +98,7 @@ ARG USERNAME=morpheus ARG USER_UID=1000 ARG USER_GID=$USER_UID -RUN groupadd --gid $USER_GID $USERNAME && \ - useradd --uid $USER_UID --gid $USER_GID -m $USERNAME && \ +RUN useradd --uid $USER_UID --gid $USER_GID -m $USERNAME && \ usermod --shell /bin/bash $USERNAME && \ echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \ chmod 0440 /etc/sudoers.d/$USERNAME && \ diff --git a/README.md b/README.md index 69e559c65..0f05e754a 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ If you choose to use Mamba rather than Conda, simply replace `conda` with `mamba #### Python Bindings ```bash # If needed, create a new conda environment -conda create --name mrc python=3.8 +conda create --name mrc python=3.10 # Activate the newly created conda environment conda activate mrc @@ -69,7 +69,7 @@ conda install -c rapidsai -c nvidia -c conda-forge mrc #### C++ Bindings ```bash # If needed, create a new conda environment -conda create --name mrc python=3.8 +conda create --name mrc python=3.10 # Activate the newly created conda environment conda activate mrc @@ -81,7 +81,7 @@ conda install -c rapidsai -c nvidia -c conda-forge libmrc #### Full MRC Library ```bash # If needed, create a new conda environment -conda create --name mrc python=3.8 +conda create --name mrc python=3.10 # Activate the newly created conda environment conda activate mrc @@ -110,46 +110,46 @@ Installing via source is for more advanced users and is necessary to try MRC fea #### Clone MRC repository ```bash -export MRC_HOME=$(pwd)/mrc -git clone --recurse-submodules git@github.com:nv-morpheus/mrc.git $MRC_HOME -cd $MRC_HOME +export MRC_ROOT=$(pwd)/mrc +git clone --recurse-submodules git@github.com:nv-morpheus/mrc.git $MRC_ROOT +cd $MRC_ROOT ``` #### Create MRC Conda Environment ```bash # note: `mamba` may be used in place of `conda` for better performance. -conda env create -n mrc-dev --file $MRC_HOME/ci/conda/environments/dev_env.yml +conda env create -n mrc-dev --file $MRC_ROOT/ci/conda/environments/dev_env.yml conda activate mrc-dev ``` #### Build MRC ```bash -mkdir $MRC_HOME/build -cd $MRC_HOME/build +mkdir $MRC_ROOT/build +cd $MRC_ROOT/build cmake .. make -j $(nproc) ``` #### Run MRC C++ Tests ```bash -export MRC_TEST_INTERNAL_DATA_PATH=$MRC_HOME/src/tests -$MRC_HOME/build/src/tests/test_mrc_private.x -$MRC_HOME/build/tests/test_mrc.x -$MRC_HOME/build/tests/logging/test_mrc_logging.x +export MRC_TEST_INTERNAL_DATA_PATH=$MRC_ROOT/cpp/mrc/src/tests +$MRC_ROOT/build/cpp/mrc/src/tests/test_mrc_private.x +$MRC_ROOT/build/cpp/mrc/tests/test_mrc.x +$MRC_ROOT/build/cpp/mrc/tests/logging/test_mrc_logging.x ``` #### Install MRC Python Bindings ```bash -pip install -e $MRC_HOME/build/python +pip install -e $MRC_ROOT/build/python ``` #### Run MRC Python Tests ```bash -pytest $MRC_HOME/python +pytest $MRC_ROOT/python ``` ### Docker Installation -A Dockerfile is provided at `$MRC_HOME` and can be built with +A Dockerfile is provided at `$MRC_ROOT` and can be built with ```bash docker build -t mrc:latest . ``` @@ -196,7 +196,7 @@ Thirdparty code included in the source tree (that is not pulled in as an externa Ex: ``` -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/ci/conda/README.md b/ci/conda/README.md index afef29543..56e6045fb 100644 --- a/ci/conda/README.md +++ b/ci/conda/README.md @@ -3,7 +3,7 @@ To build the Conda packages, it's recommended to run the provided scripts from a docker container. To build the container, `mrc-conda-build`, run the following: ```bash -cd ${MRC_HOME} +cd ${MRC_ROOT} docker buildx build --target developement -t mrc-conda-build . ``` @@ -20,10 +20,10 @@ docker run --rm -ti -v $PWD:/work \ mrc-conda-build ./ci/conda/recipes/run_conda_build.sh ``` -This will save the conda packages to `${MRC_HOME}/.conda-bld`. To install from this location, use the following: +This will save the conda packages to `${MRC_ROOT}/.conda-bld`. To install from this location, use the following: ```bash -conda install -c file://${MRC_HOME}/.conda-bld mrc +conda install -c file://${MRC_ROOT}/.conda-bld mrc ``` ## Uploading the Conda Package diff --git a/ci/conda/environments/ci_env.yml b/ci/conda/environments/ci_env.yml index 103ffe8c4..ad05425dd 100644 --- a/ci/conda/environments/ci_env.yml +++ b/ci/conda/environments/ci_env.yml @@ -19,3 +19,4 @@ channels: - conda-forge dependencies: - codecov=2.1 + - conda-merge>=0.2 diff --git a/ci/conda/environments/dev_env.yml b/ci/conda/environments/dev_env.yml index 5bc4f0498..58d83d9a7 100644 --- a/ci/conda/environments/dev_env.yml +++ b/ci/conda/environments/dev_env.yml @@ -1,8 +1,26 @@ +# SPDX-FileCopyrightText: Copyright (c) 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. + +# Dependencies needed for development environment. Runtime deps are in meta.yml +name: mrc channels: - - conda-forge - rapidsai + - nvidia/label/cuda-11.8.0 - nvidia - rapidsai-nightly + - conda-forge dependencies: - autoconf>=2.69 - bash-completion @@ -10,46 +28,42 @@ dependencies: - boost-cpp=1.74 - ccache - cmake=3.24 - - cuda-nvml-dev=11.4 - - cudatoolkit=11.4 - - cython=0.29.24 + - cuda-toolkit # Version comes from the channel above + - cxx-compiler # Sets up the distro versions of our compilers - doxygen=1.9.2 + - flake8 - flatbuffers=2.0 - - gcc_linux-64=11.2 - gcovr=5.0 - gdb - 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.46 - - gtest=1.10 - - gxx_linux-64=11.2 + - libgrpc=1.54.0 + - 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.20 - - librmm=22.10 + - libprotobuf=3.21 + - librmm=23.06 - libtool - ninja=1.10 - nlohmann_json=3.9 - numactl-libs-cos7-x86_64 - - numpy=1.21.2 - - nvcc_linux-64=11.4 + - numpy>=1.21 - pip - pkg-config=0.29 - pybind11-stubgen=0.10 - - python=3.8 - - scikit-build>=0.12 - - spdlog=1.8.5 + - pytest + - pytest-timeout + - python=3.10 + - scikit-build>=0.17 - sysroot_linux-64=2.17 - - ucx=1.13 - - pip: - - cython - - flake8 - - numpy==1.21.2 - - pytest - - pytest-timeout - - yapf + - ucx=1.14 + - yapf + + # Remove once `mamba repoquery whoneeds cudatoolkit` is empty. For now, we need to specify a version + - cudatoolkit=11.8 diff --git a/ci/conda/recipes/libmrc/build.sh b/ci/conda/recipes/libmrc/build.sh index 34246be6f..3bdbf295f 100644 --- a/ci/conda/recipes/libmrc/build.sh +++ b/ci/conda/recipes/libmrc/build.sh @@ -51,17 +51,17 @@ export CC=${GCC} export CXX=${GXX} # Common CMake args -CMAKE_ARGS="-DCMAKE_MESSAGE_CONTEXT_SHOW=ON ${CMAKE_ARGS}" -CMAKE_ARGS="-DCMAKE_INSTALL_PREFIX=$PREFIX ${CMAKE_ARGS}" -CMAKE_ARGS="-DCMAKE_INSTALL_LIBDIR=lib ${CMAKE_ARGS}" CMAKE_ARGS="-DBUILD_SHARED_LIBS=ON ${CMAKE_ARGS}" CMAKE_ARGS="-DCMAKE_BUILD_TYPE=${MRC_BUILD_TYPE} ${CMAKE_ARGS}" -CMAKE_ARGS="-DMRC_USE_CONDA=ON ${CMAKE_ARGS}" -CMAKE_ARGS="-DMRC_USE_CCACHE=OFF ${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}" CMAKE_ARGS="-DMRC_BUILD_PYTHON=ON ${CMAKE_ARGS}" -CMAKE_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES=-"ALL"} ${CMAKE_ARGS}" -CMAKE_ARGS="-DPython_EXECUTABLE=${PYTHON} ${CMAKE_ARGS}" CMAKE_ARGS="-DMRC_RAPIDS_VERSION=${rapids_version} ${CMAKE_ARGS}" +CMAKE_ARGS="-DMRC_USE_CCACHE=OFF ${CMAKE_ARGS}" +CMAKE_ARGS="-DMRC_USE_CONDA=ON ${CMAKE_ARGS}" +CMAKE_ARGS="-DPython_EXECUTABLE=${PYTHON} ${CMAKE_ARGS}" CMAKE_ARGS="-DUCX_VERSION=${ucx} ${CMAKE_ARGS}" echo "CC : ${CC}" diff --git a/ci/conda/recipes/libmrc/conda_build_config.yaml b/ci/conda/recipes/libmrc/conda_build_config.yaml index 11ef76893..008688e98 100644 --- a/ci/conda/recipes/libmrc/conda_build_config.yaml +++ b/ci/conda/recipes/libmrc/conda_build_config.yaml @@ -20,48 +20,53 @@ cxx_compiler_version: - 11.2 cuda_compiler: - - nvcc + - cuda-nvcc cuda_compiler_version: - - 11.4 + - 11.8 python: - 3.8 - - 3.9 + - 3.10 + - 3.10 # Setup the dependencies to build with multiple versions of RAPIDS -rapids_version: # Keep around compatibility with current version -1 - - 22.08 - - 22.08 - - 22.10 - +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 -abseil_cpp: - - 20211102.0 - - 20220623.0 - - 20220623.0 +libabseil: + - 20230125.0 + - 20230125.0 + - 20230125.0 -grpc_cpp: - - 1.46 - - 1.46 - - 1.46 +libgrpc: + - 1.51 + - 1.51 + - 1.54 -# UCX 1.12 is required for RAPIDS 22.06 ucx: - 1.13 - - 1.13 - - 1.13 + - 1.14 + - 1.14 +libprotobuf: + - 3.21 + - 3.21 + - 3.21 zip_keys: + - python - rapids_version - - abseil_cpp - - grpc_cpp + - libabseil + - libgrpc - ucx + - libprotobuf # The following mimic what is available in the pinning feedstock: # https://github.com/conda-forge/conda-forge-pinning-feedstock/blob/main/recipe/conda_build_config.yaml @@ -73,9 +78,6 @@ gflags: - 2.2 glog: - 0.6 -libprotobuf: - - 3.20 - pin_run_as_build: boost-cpp: diff --git a/ci/conda/recipes/libmrc/meta.yaml b/ci/conda/recipes/libmrc/meta.yaml index 60b0e7545..6abbd7c19 100644 --- a/ci/conda/recipes/libmrc/meta.yaml +++ b/ci/conda/recipes/libmrc/meta.yaml @@ -15,8 +15,8 @@ {% set version = environ.get('GIT_VERSION', '0.0.0.dev').lstrip('v') + environ.get('VERSION_SUFFIX', '') %} {% set minor_version = version.split('.')[0] + '.' + version.split('.')[1] %} -{% set py_version = environ.get('CONDA_PY', '3.8') %} -{% set cuda_version = '.'.join(environ.get('CUDA', '11.4').split('.')[:2]) %} +{% set py_version = environ.get('CONDA_PY', '3.10') %} +{% set cuda_version = '.'.join(environ.get('CUDA', '11.8').split('.')[:2]) %} {% set cuda_major = cuda_version.split('.')[0] %} package: @@ -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 @@ -43,6 +43,7 @@ requirements: - autoconf >=2.69 - ccache - cmake >=3.24 + - cuda-cudart-dev # Needed by CMake to compile a test application - libtool - ninja - numactl-libs-cos7-x86_64 @@ -50,28 +51,28 @@ requirements: - sysroot_linux-64 >=2.17 host: # Libraries necessary to build. Keep sorted! - - abseil-cpp - boost-cpp - - cuda-nvml-dev {{ cuda_version }}.* - - cudatoolkit {{ cuda_version }}.* - - cython 0.29.* + - cuda-cudart-dev + - cuda-nvml-dev - doxygen 1.9.2.* - flatbuffers 2.0.* - gflags - glog - - gmock 1.10.* - - grpc-cpp - - gtest 1.10.* + - gmock 1.13.* + - libgrpc + - gtest 1.13.* + - libabseil - libhwloc 2.5.* - libprotobuf - librmm {{ rapids_version }} - nlohmann_json 3.9.1 - pybind11-abi # See: https://conda-forge.org/docs/maintainer/knowledge_base.html#pybind11-abi-constraints - - pybind11-stubgen 0.10 + - pybind11-stubgen 0.10.5 - python {{ python }} - - scikit-build >=0.12 - - spdlog 1.8.5 + - scikit-build >=0.17 - ucx + # Need to specify cudatoolkit to get correct version. Remove once all libraries migrate to cuda-toolkit + - cudatoolkit {{ cuda_version }}.* outputs: - name: libmrc @@ -92,23 +93,27 @@ outputs: - sysroot_linux-64 2.17 host: # Any libraries with weak run_exports need to go here to be added to the run. Keep sorted! - - abseil-cpp # Needed for transitive run_exports from grpc-cpp. Does not need a version - boost-cpp - - flatbuffers 2.0.* - - gflags + - cuda-cudart # Needed to allow pin_compatible to work - glog - - grpc-cpp + - libgrpc + - libabseil # Needed for transitive run_exports from libgrpc. Does not need a version - libhwloc 2.5.* - - libprotobuf # Needed for transitive run_exports from grpc-cpp. Does not need a version + - libprotobuf # Needed for transitive run_exports from libgrpc. Does not need a version - librmm {{ rapids_version }} - nlohmann_json 3.9.* - ucx + # Need to specify cudatoolkit to get correct version. Remove once all libraries migrate to cuda-toolkit + - cudatoolkit {{ cuda_version }}.* run: # Manually add any packages necessary for run that do not have run_exports. Keep sorted! - - {{ pin_compatible('flatbuffers', max_pin='x.x')}} + - {{ pin_compatible('cuda-cudart', min_pin='x.x', max_pin='x') }} - {{ pin_compatible('nlohmann_json', max_pin='x.x')}} - {{ pin_compatible('ucx', max_pin='x.x')}} - boost-cpp # Needed to use pin_run_as_build + run_constrained: + # Since we dont explicitly require this but other packages might, constrain the versions + - {{ pin_compatible('cudatoolkit', min_pin='x.x', max_pin='x') }} test: script: test_libmrc.sh files: @@ -121,13 +126,16 @@ outputs: - {{ pin_subpackage("mrc", max_pin="x.x") }} ignore_run_exports: - pypy + missing_dso_whitelist: + - $RPATH/ld-linux-x86-64.so.2 # From python + - $RPATH/libc.so.6 # From python + - $RPATH/libpthread.so.0 # Sample modules include_recipe: False script: move_mrc_files.sh requirements: host: # Only should need libmrc and python. Keep sorted! - {{ pin_subpackage('libmrc', exact=True) }} - - abseil-cpp # mrc does not require abseil at build time. See https://github.com/conda-forge/arrow-cpp-feedstock/issues/814 - python {{ python }} run: - {{ pin_subpackage('libmrc', exact=True) }} @@ -146,11 +154,11 @@ outputs: - numpy - nvtx - pytest - - cuml {{ rapids_version }}.* # Ensure we can install cuml. This can cause issues solving abseil-cpp + - cuml {{ rapids_version }}.* # Ensure we can install cuml. This can cause issues solving libabseil about: - home: https://www.nvidia.com/ - summary: A GPU accelerated streaming data library with python bindings - license: Apache-2.0 + home: https://github.com/nv-morpheus/MRC license_family: Apache license_file: LICENSE + license: Apache-2.0 + summary: A GPU accelerated streaming data library with python bindings diff --git a/ci/conda/recipes/run_conda_build.sh b/ci/conda/recipes/run_conda_build.sh index 3b3d65727..bbdc3ed2e 100755 --- a/ci/conda/recipes/run_conda_build.sh +++ b/ci/conda/recipes/run_conda_build.sh @@ -40,13 +40,6 @@ export CONDA_COMMAND=${CONDA_COMMAND:-"mambabuild"} # Get the path to the morpheus git folder export MRC_ROOT=${MRC_ROOT:-$(git rev-parse --show-toplevel)} -export CUDA="$(conda list | grep cudatoolkit | egrep -o "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+")" -export PYTHON_VER="$(python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")" -export CUDA=11.4.1 -echo "CUDA : ${CUDA}" -echo "PYTHON_VER : ${PYTHON_VER}" -echo "" - export PARALLEL_LEVEL=${PARALLEL_LEVEL:-$(nproc)} # Export variables for the cache @@ -60,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=() @@ -99,13 +95,11 @@ fi # Choose default variants if hasArg quick; then # For quick build, just do most recent version of rapids - CONDA_ARGS_ARRAY+=("--variants" "{python: 3.8, rapids_version: 22.10}") -else - CONDA_ARGS_ARRAY+=("--variants" "{python: 3.8}") + CONDA_ARGS_ARRAY+=("--variants" "{rapids_version: 23.06}") fi # And default channels -CONDA_ARGS_ARRAY+=("-c" "rapidsai" "-c" "nvidia" "-c" "conda-forge" "-c" "main") +CONDA_ARGS_ARRAY+=("-c" "rapidsai" "-c" "nvidia/label/cuda-11.8.0" "-c" "nvidia" "-c" "conda-forge" "-c" "main") # Set GIT_VERSION to set the project version inside of meta.yaml export GIT_VERSION="$(get_version)" 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/release/update-version.sh b/ci/release/update-version.sh new file mode 100755 index 000000000..8e4895f23 --- /dev/null +++ b/ci/release/update-version.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 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. + +## Usage +# Either supply full versions: +# `bash update-version.sh ` +# Format is YY.MM.PP - no leading 'v' or trailing 'a' +# Or no versions: +# `bash update-version.sh` + +set -e + +# If the user has not supplied the versions, determine them from the git tags +if [[ "$#" -ne 2 ]]; then + echo "No versions were provided. Using last 2 git tags to determined current and next version" + + # Current version comes from the previous alpha tag + CURRENT_FULL_VERSION=$(git tag --merged HEAD --list 'v*' | sort --version-sort | tail -n 2 | head -n 1 | tr -d 'va') + # Next version comes from the latest alpha tag + NEXT_FULL_VERSION=$(git tag --merged HEAD --list 'v*' | sort --version-sort | tail -n 1 | tr -d 'va') +else + # User has supplied current and next arguments + CURRENT_FULL_VERSION=$1 + NEXT_FULL_VERSION=$2 +fi + +CURRENT_MAJOR=$(echo ${CURRENT_FULL_VERSION} | awk '{split($0, a, "."); print a[1]}') +CURRENT_MINOR=$(echo ${CURRENT_FULL_VERSION} | awk '{split($0, a, "."); print a[2]}') +CURRENT_PATCH=$(echo ${CURRENT_FULL_VERSION} | awk '{split($0, a, "."); print a[3]}') +CURRENT_SHORT_TAG=${CURRENT_MAJOR}.${CURRENT_MINOR} + +NEXT_MAJOR=$(echo ${NEXT_FULL_VERSION} | awk '{split($0, a, "."); print a[1]}') +NEXT_MINOR=$(echo ${NEXT_FULL_VERSION} | awk '{split($0, a, "."); print a[2]}') +NEXT_PATCH=$(echo ${NEXT_FULL_VERSION} | awk '{split($0, a, "."); print a[3]}') +NEXT_SHORT_TAG=${NEXT_MAJOR}.${NEXT_MINOR} + +# Need to distutils-normalize the versions for some use cases +CURRENT_SHORT_TAG_PEP440=$(python -c "from setuptools.extern import packaging; print(packaging.version.Version('${CURRENT_SHORT_TAG}'))") +NEXT_SHORT_TAG_PEP440=$(python -c "from setuptools.extern import packaging; print(packaging.version.Version('${NEXT_SHORT_TAG}'))") + +echo "Preparing release $CURRENT_FULL_VERSION (PEP ${CURRENT_SHORT_TAG_PEP440}) => $NEXT_FULL_VERSION (PEP ${NEXT_SHORT_TAG_PEP440})" + +# Inplace sed replace; workaround for Linux and Mac +function sed_runner() { + sed -i.bak ''"$1"'' $2 && rm -f ${2}.bak +} + +# .gitmodules +git submodule set-branch -b branch-${NEXT_SHORT_TAG} morpheus_utils + +# Root CMakeLists.txt +sed_runner 's/'"VERSION ${CURRENT_FULL_VERSION}.*"'/'"VERSION ${NEXT_FULL_VERSION}"'/g' CMakeLists.txt + +# Quickstart CMakeLists.txt +sed_runner 's/'"VERSION ${CURRENT_FULL_VERSION}.*"'/'"VERSION ${NEXT_FULL_VERSION}"'/g' docs/quickstart/CMakeLists.txt + +# Quickstart environment file +sed_runner "s/mrc=${CURRENT_SHORT_TAG}/mrc=${NEXT_SHORT_TAG}/g" docs/quickstart/environment_cpp.yml diff --git a/ci/scripts/fix_all.sh b/ci/scripts/fix_all.sh index 79fd1ac2f..84e76b707 100755 --- a/ci/scripts/fix_all.sh +++ b/ci/scripts/fix_all.sh @@ -1,5 +1,5 @@ #!/bin/bash -# SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# 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"); @@ -29,6 +29,23 @@ if [[ "${SKIP_COPYRIGHT}" == "" ]]; then python3 ./ci/scripts/copyright.py --fix-all --git-modified-only ./ 2>&1 fi +# Run include-what-you-use (before clang-format so it can fix the include order) +if [[ "${SKIP_IWYU}" == "" ]]; then + + if [[ "${IWYU_TOOL}" == "" ]]; then + IWYU_TOOL=$(find_iwyu_tool) + fi + + if [[ -x "${IWYU_TOOL}" ]]; then + echo "Running include-what-you-use from '${IWYU_TOOL}'..." + set -x + ${IWYU_TOOL} -j $(get_num_proc) -p ${BUILD_DIR} cpp python | fix_includes.py --nosafe_headers --nocomments + set +x + else + echo "Skipping include-what-you-use. Could not find iwyu_tool.py at '${IWYU_TOOL}'" + fi +fi + # Run clang-format if [[ "${SKIP_CLANG_FORMAT}" == "" ]]; then @@ -56,21 +73,6 @@ if [[ "${SKIP_CLANG_TIDY}" == "" ]]; then fi fi -# Run include-what-you-use -if [[ "${SKIP_IWYU}" == "" ]]; then - - if [[ "${IWYU_TOOL}" == "" ]]; then - IWYU_TOOL=$(find_iwyu_tool) - fi - - if [[ -x "${IWYU_TOOL}" ]]; then - echo "Running include-what-you-use from '${IWYU_TOOL}'..." - ${IWYU_TOOL} -j 0 -p ${BUILD_DIR} ${CPP_MODIFIED_FILES[@]} 2>&1 - else - echo "Skipping include-what-you-use. Could not find iwyu_tool.py at '${IWYU_TOOL}'" - fi -fi - # Run isort if [[ "${SKIP_ISORT}" == "" ]]; then echo "Running isort..." diff --git a/ci/scripts/github/build.sh b/ci/scripts/github/build.sh index c1eae4d58..e63f04eef 100755 --- a/ci/scripts/github/build.sh +++ b/ci/scripts/github/build.sh @@ -30,13 +30,14 @@ sccache --version if [[ "${BUILD_CC}" == "gcc" ]]; then rapids-logger "Building with GCC" - gcc --version - g++ --version + x86_64-conda-linux-gnu-cc --version + x86_64-conda-linux-gnu-c++ --version CMAKE_FLAGS="${CMAKE_BUILD_ALL_FEATURES} ${CMAKE_CACHE_FLAGS}" elif [[ "${BUILD_CC}" == "gcc-coverage" ]]; then rapids-logger "Building with GCC with gcov profile '-g -fprofile-arcs -ftest-coverage" - gcc --version - g++ --version + x86_64-conda-linux-gnu-cc --version + x86_64-conda-linux-gnu-c++ --version + x86_64-conda-linux-gnu-gcov --version CMAKE_FLAGS="${CMAKE_BUILD_ALL_FEATURES} ${CMAKE_BUILD_WITH_CODECOV} ${CMAKE_CACHE_FLAGS}" else rapids-logger "Building with Clang" diff --git a/ci/scripts/github/checks.sh b/ci/scripts/github/checks.sh index 34d1aca95..4ea5c5583 100755 --- a/ci/scripts/github/checks.sh +++ b/ci/scripts/github/checks.sh @@ -29,6 +29,9 @@ cmake -B build -G Ninja ${CMAKE_BUILD_ALL_FEATURES} . rapids-logger "Building targets that generate source code" cmake --build build --target mrc_style_checks --parallel ${PARALLEL_LEVEL} +rapids-logger "Checking versions" +${MRC_ROOT}/ci/scripts/version_checks.sh + rapids-logger "Running C++ style checks" ${MRC_ROOT}/ci/scripts/cpp_checks.sh diff --git a/ci/scripts/github/common.sh b/ci/scripts/github/common.sh index 8765d51e6..02684da2f 100644 --- a/ci/scripts/github/common.sh +++ b/ci/scripts/github/common.sh @@ -37,6 +37,7 @@ export BUILD_CC=${BUILD_CC:-"gcc"} export CONDA_ENV_YML="${MRC_ROOT}/ci/conda/environments/dev_env.yml" export CONDA_CLANG_ENV_YML="${MRC_ROOT}/ci/conda/environments/clang_env.yml" +export CONDA_CI_ENV_YML="${MRC_ROOT}/ci/conda/environments/ci_env.yml" export CMAKE_BUILD_ALL_FEATURES="-DCMAKE_MESSAGE_CONTEXT_SHOW=ON -DMRC_BUILD_BENCHMARKS=ON -DMRC_BUILD_EXAMPLES=ON -DMRC_BUILD_PYTHON=ON -DMRC_BUILD_TESTS=ON -DMRC_USE_CONDA=ON -DMRC_PYTHON_BUILD_STUBS=ON" export CMAKE_BUILD_WITH_CODECOV="-DCMAKE_BUILD_TYPE=Debug -DMRC_ENABLE_CODECOV=ON -DMRC_PYTHON_PERFORM_INSTALL:BOOL=ON -DMRC_PYTHON_INPLACE_BUILD:BOOL=ON" @@ -73,10 +74,33 @@ function print_env_vars() { function update_conda_env() { rapids-logger "Checking for updates to conda env" - rapids-mamba-retry env update -n mrc -q --file ${CONDA_ENV_YML} - rapids-mamba-retry env update -n mrc -q --file ${CONDA_CLANG_ENV_YML} + + # Deactivate the environment first before updating conda deactivate + + # Make sure we have the conda-merge package installed + if [[ -z "$(conda list | grep conda-merge)" ]]; then + 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 + condatmpdir=$(mktemp -d) + + # Merge the environments together so we can use --prune. Otherwise --prune + # will clobber the last env update + 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 --prune --file ${condatmpdir}/merged_env.yml + + # Delete the temp directory + rm -rf ${condatmpdir} + + # Finally, reactivate conda activate mrc + + rapids-logger "Final Conda Environment" + conda list } print_env_vars diff --git a/ci/scripts/github/conda.sh b/ci/scripts/github/conda.sh index d9854de8f..3b8104ad3 100755 --- a/ci/scripts/github/conda.sh +++ b/ci/scripts/github/conda.sh @@ -39,4 +39,4 @@ conda info rapids-logger "Building Conda Package" # Run the conda build and upload -${MRC_ROOT}/ci/conda/recipes/run_conda_build.sh upload +${MRC_ROOT}/ci/conda/recipes/run_conda_build.sh "$@" diff --git a/ci/scripts/version_checks.sh b/ci/scripts/version_checks.sh new file mode 100755 index 000000000..f26ffe144 --- /dev/null +++ b/ci/scripts/version_checks.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 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. + +# set -x + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +source ${SCRIPT_DIR}/common.sh + +# Run the update version script +UPDATE_VERSION_OUTPUT=`${MRC_ROOT}/ci/release/update-version.sh` + +# If any diffs were found, the versions were out of date +VERSIONS_OUT_OF_DATE=$(git diff --name-only) + +if [[ "${VERSIONS_OUT_OF_DATE}" != "" ]]; then + echo -e "\n\n>>>> FAILED: version check; begin output\n\n" + echo -e "${UPDATE_VERSION_OUTPUT}" + echo -e "\n\nThe following files have out of date versions:" + echo -e "${VERSIONS_OUT_OF_DATE}" + echo -e "\n\n>>>> FAILED: version check; end output\n\n" \ + "To update the versions, run the following and commit the results:\n" \ + " ./ci/release/update-version.sh\n\n" + exit 1 +fi diff --git a/cpp/mrc/CMakeLists.txt b/cpp/mrc/CMakeLists.txt index 04424e300..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 @@ -166,7 +160,6 @@ target_link_libraries(libmrc mrc_protos mrc_architect_protos rmm::rmm - CUDA::nvml CUDA::cudart rxcpp::rxcpp glog::glog @@ -180,8 +173,8 @@ target_link_libraries(libmrc PRIVATE hwloc::hwloc prometheus-cpp::core # private in MR !199 - ucx::ucs ucx::ucp + ucx::ucs ) target_include_directories(libmrc @@ -206,10 +199,6 @@ target_compile_features(libmrc PUBLIC cxx_std_20) set_target_properties(libmrc PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) -# Finally, set the install RPATH to include the stubs folder for CUDA::nvml. If thats made private, this can be removed -set_target_properties(libmrc PROPERTIES INSTALL_RPATH - "${CMAKE_INSTALL_PREFIX}/lib:\$ORIGIN:${CMAKE_INSTALL_PREFIX}/lib/stubs") - # ################################################################################################## # - install targets -------------------------------------------------------------------------------- @@ -277,4 +266,3 @@ rapids_export(BUILD ${PROJECT_NAME} DOCUMENTATION doc_string FINAL_CODE_BLOCK code_string ) - diff --git a/cpp/mrc/benchmarks/bench_coroutines.cpp b/cpp/mrc/benchmarks/bench_coroutines.cpp index e56862c12..443806ccc 100644 --- a/cpp/mrc/benchmarks/bench_coroutines.cpp +++ b/cpp/mrc/benchmarks/bench_coroutines.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/benchmarks/bench_fibers.cpp b/cpp/mrc/benchmarks/bench_fibers.cpp index d1b997ba5..bd75ae526 100644 --- a/cpp/mrc/benchmarks/bench_fibers.cpp +++ b/cpp/mrc/benchmarks/bench_fibers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/benchmarks/bench_mrc.cpp b/cpp/mrc/benchmarks/bench_mrc.cpp index d37b370d0..ecf37f77c 100644 --- a/cpp/mrc/benchmarks/bench_mrc.cpp +++ b/cpp/mrc/benchmarks/bench_mrc.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/benchmarks/bench_segment.cpp b/cpp/mrc/benchmarks/bench_segment.cpp index 6960ebe18..2ddeed4e2 100644 --- a/cpp/mrc/benchmarks/bench_segment.cpp +++ b/cpp/mrc/benchmarks/bench_segment.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/benchmarks/main.cpp b/cpp/mrc/benchmarks/main.cpp index 895e7af84..83096235d 100644 --- a/cpp/mrc/benchmarks/main.cpp +++ b/cpp/mrc/benchmarks/main.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/api.hpp b/cpp/mrc/include/mrc/api.hpp index e82782489..ede97c7e9 100644 --- a/cpp/mrc/include/mrc/api.hpp +++ b/cpp/mrc/include/mrc/api.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/benchmarking/segment_watcher.hpp b/cpp/mrc/include/mrc/benchmarking/segment_watcher.hpp index cc85e088b..f22889e36 100644 --- a/cpp/mrc/include/mrc/benchmarking/segment_watcher.hpp +++ b/cpp/mrc/include/mrc/benchmarking/segment_watcher.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/benchmarking/trace_statistics.hpp b/cpp/mrc/include/mrc/benchmarking/trace_statistics.hpp index 119817197..34b60f8f0 100644 --- a/cpp/mrc/include/mrc/benchmarking/trace_statistics.hpp +++ b/cpp/mrc/include/mrc/benchmarking/trace_statistics.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/benchmarking/tracer.hpp b/cpp/mrc/include/mrc/benchmarking/tracer.hpp index a415e5563..38a8e52d2 100644 --- a/cpp/mrc/include/mrc/benchmarking/tracer.hpp +++ b/cpp/mrc/include/mrc/benchmarking/tracer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/benchmarking/util.hpp b/cpp/mrc/include/mrc/benchmarking/util.hpp index ef0cf916a..ea293194f 100644 --- a/cpp/mrc/include/mrc/benchmarking/util.hpp +++ b/cpp/mrc/include/mrc/benchmarking/util.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/channel/buffered_channel.hpp b/cpp/mrc/include/mrc/channel/buffered_channel.hpp index 3ff6988d9..b434ef160 100644 --- a/cpp/mrc/include/mrc/channel/buffered_channel.hpp +++ b/cpp/mrc/include/mrc/channel/buffered_channel.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/channel/channel.hpp b/cpp/mrc/include/mrc/channel/channel.hpp index d91da2ab0..33adf1430 100644 --- a/cpp/mrc/include/mrc/channel/channel.hpp +++ b/cpp/mrc/include/mrc/channel/channel.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/channel/egress.hpp b/cpp/mrc/include/mrc/channel/egress.hpp index 0dbb865ff..e21d7479a 100644 --- a/cpp/mrc/include/mrc/channel/egress.hpp +++ b/cpp/mrc/include/mrc/channel/egress.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/channel/forward.hpp b/cpp/mrc/include/mrc/channel/forward.hpp index ccebeec62..4ffb0ca90 100644 --- a/cpp/mrc/include/mrc/channel/forward.hpp +++ b/cpp/mrc/include/mrc/channel/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/channel/ingress.hpp b/cpp/mrc/include/mrc/channel/ingress.hpp index 26b35e42f..29d931052 100644 --- a/cpp/mrc/include/mrc/channel/ingress.hpp +++ b/cpp/mrc/include/mrc/channel/ingress.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/channel/null_channel.hpp b/cpp/mrc/include/mrc/channel/null_channel.hpp index b6e8c9b8a..baf8ad83c 100644 --- a/cpp/mrc/include/mrc/channel/null_channel.hpp +++ b/cpp/mrc/include/mrc/channel/null_channel.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/channel/recent_channel.hpp b/cpp/mrc/include/mrc/channel/recent_channel.hpp index 2212253fd..2b85f2150 100644 --- a/cpp/mrc/include/mrc/channel/recent_channel.hpp +++ b/cpp/mrc/include/mrc/channel/recent_channel.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/channel/status.hpp b/cpp/mrc/include/mrc/channel/status.hpp index e86accf79..91f6b2800 100644 --- a/cpp/mrc/include/mrc/channel/status.hpp +++ b/cpp/mrc/include/mrc/channel/status.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/channel/types.hpp b/cpp/mrc/include/mrc/channel/types.hpp index 3bac75c4e..298c6dfd1 100644 --- a/cpp/mrc/include/mrc/channel/types.hpp +++ b/cpp/mrc/include/mrc/channel/types.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/api.hpp b/cpp/mrc/include/mrc/codable/api.hpp index 1a6276ca4..64e0f5d61 100644 --- a/cpp/mrc/include/mrc/codable/api.hpp +++ b/cpp/mrc/include/mrc/codable/api.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/codable_protocol.hpp b/cpp/mrc/include/mrc/codable/codable_protocol.hpp index 36e3c01cd..6d14fe873 100644 --- a/cpp/mrc/include/mrc/codable/codable_protocol.hpp +++ b/cpp/mrc/include/mrc/codable/codable_protocol.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/decode.hpp b/cpp/mrc/include/mrc/codable/decode.hpp index 6cd2c126b..b6939141d 100644 --- a/cpp/mrc/include/mrc/codable/decode.hpp +++ b/cpp/mrc/include/mrc/codable/decode.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/encode.hpp b/cpp/mrc/include/mrc/codable/encode.hpp index 31a2ef45b..eb88badd0 100644 --- a/cpp/mrc/include/mrc/codable/encode.hpp +++ b/cpp/mrc/include/mrc/codable/encode.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/encoded_object.hpp b/cpp/mrc/include/mrc/codable/encoded_object.hpp index e8eb4569c..086e4f0df 100644 --- a/cpp/mrc/include/mrc/codable/encoded_object.hpp +++ b/cpp/mrc/include/mrc/codable/encoded_object.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/encoding_options.hpp b/cpp/mrc/include/mrc/codable/encoding_options.hpp index dcf7fc725..85a7fc705 100644 --- a/cpp/mrc/include/mrc/codable/encoding_options.hpp +++ b/cpp/mrc/include/mrc/codable/encoding_options.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/forward.hpp b/cpp/mrc/include/mrc/codable/forward.hpp index 21b5b314c..f1196d013 100644 --- a/cpp/mrc/include/mrc/codable/forward.hpp +++ b/cpp/mrc/include/mrc/codable/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/fundamental_types.hpp b/cpp/mrc/include/mrc/codable/fundamental_types.hpp index a2d51f320..fb0e6b058 100644 --- a/cpp/mrc/include/mrc/codable/fundamental_types.hpp +++ b/cpp/mrc/include/mrc/codable/fundamental_types.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/memory.hpp b/cpp/mrc/include/mrc/codable/memory.hpp index 6db6f737f..985ef4d4b 100644 --- a/cpp/mrc/include/mrc/codable/memory.hpp +++ b/cpp/mrc/include/mrc/codable/memory.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/memory_resources.hpp b/cpp/mrc/include/mrc/codable/memory_resources.hpp index bb8401400..0ae3d6338 100644 --- a/cpp/mrc/include/mrc/codable/memory_resources.hpp +++ b/cpp/mrc/include/mrc/codable/memory_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/protobuf_message.hpp b/cpp/mrc/include/mrc/codable/protobuf_message.hpp index d26628cc2..95965f125 100644 --- a/cpp/mrc/include/mrc/codable/protobuf_message.hpp +++ b/cpp/mrc/include/mrc/codable/protobuf_message.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/storage_forwarder.hpp b/cpp/mrc/include/mrc/codable/storage_forwarder.hpp index f36edde52..bed6e3cdd 100644 --- a/cpp/mrc/include/mrc/codable/storage_forwarder.hpp +++ b/cpp/mrc/include/mrc/codable/storage_forwarder.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/type_traits.hpp b/cpp/mrc/include/mrc/codable/type_traits.hpp index 8a5711036..dbb5df128 100644 --- a/cpp/mrc/include/mrc/codable/type_traits.hpp +++ b/cpp/mrc/include/mrc/codable/type_traits.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/codable/types.hpp b/cpp/mrc/include/mrc/codable/types.hpp index c5afa22ce..7b4aebc87 100644 --- a/cpp/mrc/include/mrc/codable/types.hpp +++ b/cpp/mrc/include/mrc/codable/types.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/constants.hpp b/cpp/mrc/include/mrc/constants.hpp index 1b987d540..27a6cdc8b 100644 --- a/cpp/mrc/include/mrc/constants.hpp +++ b/cpp/mrc/include/mrc/constants.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/control_plane/api.hpp b/cpp/mrc/include/mrc/control_plane/api.hpp index 9413dca8a..33ac7d6e4 100644 --- a/cpp/mrc/include/mrc/control_plane/api.hpp +++ b/cpp/mrc/include/mrc/control_plane/api.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/control_plane/subscription_service_forwarder.hpp b/cpp/mrc/include/mrc/control_plane/subscription_service_forwarder.hpp index f4dc9ba62..1f692784d 100644 --- a/cpp/mrc/include/mrc/control_plane/subscription_service_forwarder.hpp +++ b/cpp/mrc/include/mrc/control_plane/subscription_service_forwarder.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/addresses.hpp b/cpp/mrc/include/mrc/core/addresses.hpp index 85e7976be..8f0e56f17 100644 --- a/cpp/mrc/include/mrc/core/addresses.hpp +++ b/cpp/mrc/include/mrc/core/addresses.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/bitmap.hpp b/cpp/mrc/include/mrc/core/bitmap.hpp index 2543b6005..d3fbc97b3 100644 --- a/cpp/mrc/include/mrc/core/bitmap.hpp +++ b/cpp/mrc/include/mrc/core/bitmap.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/concepts/not_void.hpp b/cpp/mrc/include/mrc/core/concepts/not_void.hpp index 8ad6cadc3..abc0bbf5e 100644 --- a/cpp/mrc/include/mrc/core/concepts/not_void.hpp +++ b/cpp/mrc/include/mrc/core/concepts/not_void.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/context.hpp b/cpp/mrc/include/mrc/core/context.hpp index c8380430d..f1e82529a 100644 --- a/cpp/mrc/include/mrc/core/context.hpp +++ b/cpp/mrc/include/mrc/core/context.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/device_partition.hpp b/cpp/mrc/include/mrc/core/device_partition.hpp index d71c540ed..aa3d851f5 100644 --- a/cpp/mrc/include/mrc/core/device_partition.hpp +++ b/cpp/mrc/include/mrc/core/device_partition.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/error.hpp b/cpp/mrc/include/mrc/core/error.hpp index 3dbb2b162..08b3864e9 100644 --- a/cpp/mrc/include/mrc/core/error.hpp +++ b/cpp/mrc/include/mrc/core/error.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/executor.hpp b/cpp/mrc/include/mrc/core/executor.hpp deleted file mode 100644 index 29aa1ea34..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/expected.hpp b/cpp/mrc/include/mrc/core/expected.hpp index cb903b25d..9333d630c 100644 --- a/cpp/mrc/include/mrc/core/expected.hpp +++ b/cpp/mrc/include/mrc/core/expected.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/fiber_meta_data.hpp b/cpp/mrc/include/mrc/core/fiber_meta_data.hpp index fcdaa984c..8efc9e73c 100644 --- a/cpp/mrc/include/mrc/core/fiber_meta_data.hpp +++ b/cpp/mrc/include/mrc/core/fiber_meta_data.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/fiber_pool.hpp b/cpp/mrc/include/mrc/core/fiber_pool.hpp index 23be99730..09838d473 100644 --- a/cpp/mrc/include/mrc/core/fiber_pool.hpp +++ b/cpp/mrc/include/mrc/core/fiber_pool.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/host_partition.hpp b/cpp/mrc/include/mrc/core/host_partition.hpp index adaa6fe80..3006fa6b6 100644 --- a/cpp/mrc/include/mrc/core/host_partition.hpp +++ b/cpp/mrc/include/mrc/core/host_partition.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/logging.hpp b/cpp/mrc/include/mrc/core/logging.hpp index 46eb97a08..8e1fac6b8 100644 --- a/cpp/mrc/include/mrc/core/logging.hpp +++ b/cpp/mrc/include/mrc/core/logging.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/runtime.hpp b/cpp/mrc/include/mrc/core/runtime.hpp index a0cc9cbaf..633d68d42 100644 --- a/cpp/mrc/include/mrc/core/runtime.hpp +++ b/cpp/mrc/include/mrc/core/runtime.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/spin_lock_mutex.hpp b/cpp/mrc/include/mrc/core/spin_lock_mutex.hpp index a20bba40c..60603d8d5 100644 --- a/cpp/mrc/include/mrc/core/spin_lock_mutex.hpp +++ b/cpp/mrc/include/mrc/core/spin_lock_mutex.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/task_queue.hpp b/cpp/mrc/include/mrc/core/task_queue.hpp index e4d7334e9..492f0a165 100644 --- a/cpp/mrc/include/mrc/core/task_queue.hpp +++ b/cpp/mrc/include/mrc/core/task_queue.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/thread.hpp b/cpp/mrc/include/mrc/core/thread.hpp index 964fac57b..638bea627 100644 --- a/cpp/mrc/include/mrc/core/thread.hpp +++ b/cpp/mrc/include/mrc/core/thread.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/thread_barrier.hpp b/cpp/mrc/include/mrc/core/thread_barrier.hpp index e3cbdef43..44a0858e1 100644 --- a/cpp/mrc/include/mrc/core/thread_barrier.hpp +++ b/cpp/mrc/include/mrc/core/thread_barrier.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/userspace_threads.hpp b/cpp/mrc/include/mrc/core/userspace_threads.hpp index 91dc3b149..19e36c9c2 100644 --- a/cpp/mrc/include/mrc/core/userspace_threads.hpp +++ b/cpp/mrc/include/mrc/core/userspace_threads.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/core/utils.hpp b/cpp/mrc/include/mrc/core/utils.hpp index 4e657d729..84e2f8e06 100644 --- a/cpp/mrc/include/mrc/core/utils.hpp +++ b/cpp/mrc/include/mrc/core/utils.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -19,6 +19,8 @@ #include "mrc/utils/macros.hpp" +#include + #include #include #include @@ -26,6 +28,7 @@ #include #include #include +#include namespace mrc { @@ -54,47 +57,47 @@ std::set extract_keys(const std::map& stdmap) } // RAII will execute a function when destroyed. -template class Unwinder { public: + explicit Unwinder(std::function unwind_fn) : m_unwind_fn(std::move(unwind_fn)) {} + ~Unwinder() { - if (!!m_function) + if (!!m_unwind_fn) { try { - (*m_function)(); + m_unwind_fn(); } catch (...) { + LOG(ERROR) << "Fatal error during unwinder function"; std::terminate(); } } } - explicit Unwinder(FunctionT* function_arg) : m_function(function_arg) {} - void detach() { - m_function = nullptr; + m_unwind_fn = nullptr; } Unwinder() = delete; Unwinder(const Unwinder&) = delete; Unwinder& operator=(const Unwinder&) = delete; + static Unwinder create(std::function unwind_fn) + { + return Unwinder(std::move(unwind_fn)); + } + private: - FunctionT* m_function; + std::function m_unwind_fn; }; -#define MRC_UNWIND(var_name, function) MRC_UNWIND_EXPLICIT(uw_func_##var_name, var_name, function) - -#define MRC_UNWIND_AUTO(function) \ - MRC_UNWIND_EXPLICIT(MRC_UNIQUE_VAR_NAME(uw_func_), MRC_UNIQUE_VAR_NAME(un_obj_), function) +#define MRC_UNWIND(unwinder_name, function) mrc::Unwinder unwinder_name(function); -#define MRC_UNWIND_EXPLICIT(function_name, unwinder_name, function) \ - auto function_name = (function); \ - mrc::Unwinder unwinder_name(std::addressof(function_name)) +#define MRC_UNWIND_AUTO(function) MRC_UNWIND(MRC_UNIQUE_VAR_NAME(__un_obj_), function) template std::pair, std::set> set_compare(const std::set& cur_set, const std::set& new_set) diff --git a/cpp/mrc/include/mrc/core/watcher.hpp b/cpp/mrc/include/mrc/core/watcher.hpp index 41b690baa..7ecc5e6dc 100644 --- a/cpp/mrc/include/mrc/core/watcher.hpp +++ b/cpp/mrc/include/mrc/core/watcher.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/concepts/awaitable.hpp b/cpp/mrc/include/mrc/coroutines/concepts/awaitable.hpp index 248322e60..845699450 100644 --- a/cpp/mrc/include/mrc/coroutines/concepts/awaitable.hpp +++ b/cpp/mrc/include/mrc/coroutines/concepts/awaitable.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/concepts/buffer.hpp b/cpp/mrc/include/mrc/coroutines/concepts/buffer.hpp index d76027221..bbdfb65bc 100644 --- a/cpp/mrc/include/mrc/coroutines/concepts/buffer.hpp +++ b/cpp/mrc/include/mrc/coroutines/concepts/buffer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/concepts/executor.hpp b/cpp/mrc/include/mrc/coroutines/concepts/executor.hpp index d6cc15b91..87de79f74 100644 --- a/cpp/mrc/include/mrc/coroutines/concepts/executor.hpp +++ b/cpp/mrc/include/mrc/coroutines/concepts/executor.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/concepts/promise.hpp b/cpp/mrc/include/mrc/coroutines/concepts/promise.hpp index b8ffc717e..118e37a4c 100644 --- a/cpp/mrc/include/mrc/coroutines/concepts/promise.hpp +++ b/cpp/mrc/include/mrc/coroutines/concepts/promise.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/concepts/range_of.hpp b/cpp/mrc/include/mrc/coroutines/concepts/range_of.hpp index f1c64caa6..6709e38b2 100644 --- a/cpp/mrc/include/mrc/coroutines/concepts/range_of.hpp +++ b/cpp/mrc/include/mrc/coroutines/concepts/range_of.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/detail/void_value.hpp b/cpp/mrc/include/mrc/coroutines/detail/void_value.hpp index 0d9065626..64a30ec3c 100644 --- a/cpp/mrc/include/mrc/coroutines/detail/void_value.hpp +++ b/cpp/mrc/include/mrc/coroutines/detail/void_value.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/event.hpp b/cpp/mrc/include/mrc/coroutines/event.hpp index 1e2f8bac6..a98947ff4 100644 --- a/cpp/mrc/include/mrc/coroutines/event.hpp +++ b/cpp/mrc/include/mrc/coroutines/event.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/generator.hpp b/cpp/mrc/include/mrc/coroutines/generator.hpp index 6fff9e059..304fd132d 100644 --- a/cpp/mrc/include/mrc/coroutines/generator.hpp +++ b/cpp/mrc/include/mrc/coroutines/generator.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/latch.hpp b/cpp/mrc/include/mrc/coroutines/latch.hpp index 06f849b02..96bf20cf6 100644 --- a/cpp/mrc/include/mrc/coroutines/latch.hpp +++ b/cpp/mrc/include/mrc/coroutines/latch.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/ring_buffer.hpp b/cpp/mrc/include/mrc/coroutines/ring_buffer.hpp index 95ad0d9d8..d266d91c6 100644 --- a/cpp/mrc/include/mrc/coroutines/ring_buffer.hpp +++ b/cpp/mrc/include/mrc/coroutines/ring_buffer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/coroutines/schedule_policy.hpp b/cpp/mrc/include/mrc/coroutines/schedule_policy.hpp index 175006387..f6b9a83bb 100644 --- a/cpp/mrc/include/mrc/coroutines/schedule_policy.hpp +++ b/cpp/mrc/include/mrc/coroutines/schedule_policy.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/sync_wait.hpp b/cpp/mrc/include/mrc/coroutines/sync_wait.hpp index a07f40313..bb3036a11 100644 --- a/cpp/mrc/include/mrc/coroutines/sync_wait.hpp +++ b/cpp/mrc/include/mrc/coroutines/sync_wait.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/task.hpp b/cpp/mrc/include/mrc/coroutines/task.hpp index e1e4a439e..88a40b317 100644 --- a/cpp/mrc/include/mrc/coroutines/task.hpp +++ b/cpp/mrc/include/mrc/coroutines/task.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/thread_local_context.hpp b/cpp/mrc/include/mrc/coroutines/thread_local_context.hpp index 4b69ff897..adf4c56e1 100644 --- a/cpp/mrc/include/mrc/coroutines/thread_local_context.hpp +++ b/cpp/mrc/include/mrc/coroutines/thread_local_context.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/thread_pool.hpp b/cpp/mrc/include/mrc/coroutines/thread_pool.hpp index 0729528c2..ed1f2c879 100644 --- a/cpp/mrc/include/mrc/coroutines/thread_pool.hpp +++ b/cpp/mrc/include/mrc/coroutines/thread_pool.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/coroutines/when_all.hpp b/cpp/mrc/include/mrc/coroutines/when_all.hpp index 8b11045fc..bbdedf2a9 100644 --- a/cpp/mrc/include/mrc/coroutines/when_all.hpp +++ b/cpp/mrc/include/mrc/coroutines/when_all.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/cuda/common.hpp b/cpp/mrc/include/mrc/cuda/common.hpp index 86c791054..ae981b22b 100644 --- a/cpp/mrc/include/mrc/cuda/common.hpp +++ b/cpp/mrc/include/mrc/cuda/common.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/cuda/device_guard.hpp b/cpp/mrc/include/mrc/cuda/device_guard.hpp index 7d369da93..18a1c246e 100644 --- a/cpp/mrc/include/mrc/cuda/device_guard.hpp +++ b/cpp/mrc/include/mrc/cuda/device_guard.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/cuda/sync.hpp b/cpp/mrc/include/mrc/cuda/sync.hpp index 397c405f2..ef2a9bfb0 100644 --- a/cpp/mrc/include/mrc/cuda/sync.hpp +++ b/cpp/mrc/include/mrc/cuda/sync.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/data/reusable_pool.hpp b/cpp/mrc/include/mrc/data/reusable_pool.hpp index 752839089..1f27a500e 100644 --- a/cpp/mrc/include/mrc/data/reusable_pool.hpp +++ b/cpp/mrc/include/mrc/data/reusable_pool.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/edge/deferred_edge.hpp b/cpp/mrc/include/mrc/edge/deferred_edge.hpp index 2bfe19f55..bf333b88b 100644 --- a/cpp/mrc/include/mrc/edge/deferred_edge.hpp +++ b/cpp/mrc/include/mrc/edge/deferred_edge.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/edge/edge_adapter_registry.hpp b/cpp/mrc/include/mrc/edge/edge_adapter_registry.hpp index 4f63e9e6d..e28ba9112 100644 --- a/cpp/mrc/include/mrc/edge/edge_adapter_registry.hpp +++ b/cpp/mrc/include/mrc/edge/edge_adapter_registry.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/edge/edge_builder.hpp b/cpp/mrc/include/mrc/edge/edge_builder.hpp index 581b7da41..78e88b577 100644 --- a/cpp/mrc/include/mrc/edge/edge_builder.hpp +++ b/cpp/mrc/include/mrc/edge/edge_builder.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/edge/edge_connector.hpp b/cpp/mrc/include/mrc/edge/edge_connector.hpp index 447f1caf3..6df92b1f2 100644 --- a/cpp/mrc/include/mrc/edge/edge_connector.hpp +++ b/cpp/mrc/include/mrc/edge/edge_connector.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/edge/forward.hpp b/cpp/mrc/include/mrc/edge/forward.hpp index c837577b8..13c6a63a6 100644 --- a/cpp/mrc/include/mrc/edge/forward.hpp +++ b/cpp/mrc/include/mrc/edge/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 ffe48e4da..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 cb228d62a..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 8f5332858..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 7c9347a52..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 5acbf375c..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 e9e1bdc0e..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/exceptions/runtime_error.hpp b/cpp/mrc/include/mrc/exceptions/runtime_error.hpp index 7e9887ef7..b5398deb7 100644 --- a/cpp/mrc/include/mrc/exceptions/runtime_error.hpp +++ b/cpp/mrc/include/mrc/exceptions/runtime_error.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 fa3ac3c11..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 @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 a78a465a3..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 @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 843a8b8c4..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 @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_base.hpp b/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_base.hpp index 93f036f21..245adee6b 100644 --- a/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_base.hpp +++ b/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_base.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_immediate.hpp b/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_immediate.hpp index 06e74f334..6fe86cd93 100644 --- a/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_immediate.hpp +++ b/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_immediate.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 34f3bc9a0..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 @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/experimental/modules/stream_buffer/stream_buffer_traits.hpp b/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_traits.hpp index 8433e2636..91d072a84 100644 --- a/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_traits.hpp +++ b/cpp/mrc/include/mrc/experimental/modules/stream_buffer/stream_buffer_traits.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/forward.hpp b/cpp/mrc/include/mrc/forward.hpp index 4eb296c25..e2ecd105f 100644 --- a/cpp/mrc/include/mrc/forward.hpp +++ b/cpp/mrc/include/mrc/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 a0d856052..974729468 100644 --- a/cpp/mrc/include/mrc/manifold/composite_manifold.hpp +++ b/cpp/mrc/include/mrc/manifold/composite_manifold.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 4b922539c..81e9ac94d 100644 --- a/cpp/mrc/include/mrc/manifold/connectable.hpp +++ b/cpp/mrc/include/mrc/manifold/connectable.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/egress.hpp b/cpp/mrc/include/mrc/manifold/egress.hpp index e4127eb74..781122d61 100644 --- a/cpp/mrc/include/mrc/manifold/egress.hpp +++ b/cpp/mrc/include/mrc/manifold/egress.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/manifold/factory.hpp b/cpp/mrc/include/mrc/manifold/factory.hpp index aa29f0bfd..e51fd2457 100644 --- a/cpp/mrc/include/mrc/manifold/factory.hpp +++ b/cpp/mrc/include/mrc/manifold/factory.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/ingress.hpp b/cpp/mrc/include/mrc/manifold/ingress.hpp index 926da1247..060446b79 100644 --- a/cpp/mrc/include/mrc/manifold/ingress.hpp +++ b/cpp/mrc/include/mrc/manifold/ingress.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/manifold/interface.hpp b/cpp/mrc/include/mrc/manifold/interface.hpp index 12bc2baa2..5c3d28fa4 100644 --- a/cpp/mrc/include/mrc/manifold/interface.hpp +++ b/cpp/mrc/include/mrc/manifold/interface.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d8ad5873c..d88168dd7 100644 --- a/cpp/mrc/include/mrc/manifold/load_balancer.hpp +++ b/cpp/mrc/include/mrc/manifold/load_balancer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 48d84f377..4cb567341 100644 --- a/cpp/mrc/include/mrc/manifold/manifold.hpp +++ b/cpp/mrc/include/mrc/manifold/manifold.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/adaptors.hpp b/cpp/mrc/include/mrc/memory/adaptors.hpp index e5273a3ab..7c9d877fd 100644 --- a/cpp/mrc/include/mrc/memory/adaptors.hpp +++ b/cpp/mrc/include/mrc/memory/adaptors.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/memory/buffer.hpp b/cpp/mrc/include/mrc/memory/buffer.hpp index f72802987..9cadb3636 100644 --- a/cpp/mrc/include/mrc/memory/buffer.hpp +++ b/cpp/mrc/include/mrc/memory/buffer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/memory/buffer_view.hpp b/cpp/mrc/include/mrc/memory/buffer_view.hpp index 289a474a0..604a1c537 100644 --- a/cpp/mrc/include/mrc/memory/buffer_view.hpp +++ b/cpp/mrc/include/mrc/memory/buffer_view.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/memory/codable/buffer.hpp b/cpp/mrc/include/mrc/memory/codable/buffer.hpp index 4d9c1484c..e10e83808 100644 --- a/cpp/mrc/include/mrc/memory/codable/buffer.hpp +++ b/cpp/mrc/include/mrc/memory/codable/buffer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/memory/literals.hpp b/cpp/mrc/include/mrc/memory/literals.hpp index be554ae8b..680b881a4 100644 --- a/cpp/mrc/include/mrc/memory/literals.hpp +++ b/cpp/mrc/include/mrc/memory/literals.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/memory/memory_kind.hpp b/cpp/mrc/include/mrc/memory/memory_kind.hpp index f40291bf0..b0bdceef7 100644 --- a/cpp/mrc/include/mrc/memory/memory_kind.hpp +++ b/cpp/mrc/include/mrc/memory/memory_kind.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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/memory/resources/device/cuda_malloc_resource.hpp b/cpp/mrc/include/mrc/memory/resources/device/cuda_malloc_resource.hpp index 2ffaed9fe..28a359c50 100644 --- a/cpp/mrc/include/mrc/memory/resources/device/cuda_malloc_resource.hpp +++ b/cpp/mrc/include/mrc/memory/resources/device/cuda_malloc_resource.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/memory/resources/host/malloc_memory_resource.hpp b/cpp/mrc/include/mrc/memory/resources/host/malloc_memory_resource.hpp index eafd639fd..112aefe14 100644 --- a/cpp/mrc/include/mrc/memory/resources/host/malloc_memory_resource.hpp +++ b/cpp/mrc/include/mrc/memory/resources/host/malloc_memory_resource.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/memory/resources/host/pinned_memory_resource.hpp b/cpp/mrc/include/mrc/memory/resources/host/pinned_memory_resource.hpp index 088cda100..6c65e0aff 100644 --- a/cpp/mrc/include/mrc/memory/resources/host/pinned_memory_resource.hpp +++ b/cpp/mrc/include/mrc/memory/resources/host/pinned_memory_resource.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/memory/resources/logging_resource.hpp b/cpp/mrc/include/mrc/memory/resources/logging_resource.hpp index 2c2cacae4..056e14cea 100644 --- a/cpp/mrc/include/mrc/memory/resources/logging_resource.hpp +++ b/cpp/mrc/include/mrc/memory/resources/logging_resource.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/memory/resources/memory_resource.hpp b/cpp/mrc/include/mrc/memory/resources/memory_resource.hpp index a21b4cf7e..33137e2e8 100644 --- a/cpp/mrc/include/mrc/memory/resources/memory_resource.hpp +++ b/cpp/mrc/include/mrc/memory/resources/memory_resource.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/metrics/counter.hpp b/cpp/mrc/include/mrc/metrics/counter.hpp index 0ed458974..48abca8d2 100644 --- a/cpp/mrc/include/mrc/metrics/counter.hpp +++ b/cpp/mrc/include/mrc/metrics/counter.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/metrics/registry.hpp b/cpp/mrc/include/mrc/metrics/registry.hpp index f7c72e8b8..3828f520f 100644 --- a/cpp/mrc/include/mrc/metrics/registry.hpp +++ b/cpp/mrc/include/mrc/metrics/registry.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/modules/module_registry.hpp b/cpp/mrc/include/mrc/modules/module_registry.hpp index 010432574..348dd434d 100644 --- a/cpp/mrc/include/mrc/modules/module_registry.hpp +++ b/cpp/mrc/include/mrc/modules/module_registry.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/modules/module_registry_util.hpp b/cpp/mrc/include/mrc/modules/module_registry_util.hpp index ce344eb5c..a09925e12 100644 --- a/cpp/mrc/include/mrc/modules/module_registry_util.hpp +++ b/cpp/mrc/include/mrc/modules/module_registry_util.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/modules/plugins.hpp b/cpp/mrc/include/mrc/modules/plugins.hpp index 43d9aa641..5a7202fca 100644 --- a/cpp/mrc/include/mrc/modules/plugins.hpp +++ b/cpp/mrc/include/mrc/modules/plugins.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/modules/properties/persistent.hpp b/cpp/mrc/include/mrc/modules/properties/persistent.hpp index c62932ee7..792d6ba38 100644 --- a/cpp/mrc/include/mrc/modules/properties/persistent.hpp +++ b/cpp/mrc/include/mrc/modules/properties/persistent.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/modules/sample_modules.hpp b/cpp/mrc/include/mrc/modules/sample_modules.hpp index 860c55599..23db4db57 100644 --- a/cpp/mrc/include/mrc/modules/sample_modules.hpp +++ b/cpp/mrc/include/mrc/modules/sample_modules.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 31bc93be5..3cabb0d03 100644 --- a/cpp/mrc/include/mrc/modules/segment_modules.hpp +++ b/cpp/mrc/include/mrc/modules/segment_modules.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 9d1de39cc..b86340fe6 100644 --- a/cpp/mrc/include/mrc/mrc.hpp +++ b/cpp/mrc/include/mrc/mrc.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/node/forward.hpp b/cpp/mrc/include/mrc/node/forward.hpp index b048ec0e6..90fea7138 100644 --- a/cpp/mrc/include/mrc/node/forward.hpp +++ b/cpp/mrc/include/mrc/node/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/generic_node.hpp b/cpp/mrc/include/mrc/node/generic_node.hpp index e13ab4d42..a228c37d7 100644 --- a/cpp/mrc/include/mrc/node/generic_node.hpp +++ b/cpp/mrc/include/mrc/node/generic_node.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/generic_sink.hpp b/cpp/mrc/include/mrc/node/generic_sink.hpp index e54f63d92..de0fbec7c 100644 --- a/cpp/mrc/include/mrc/node/generic_sink.hpp +++ b/cpp/mrc/include/mrc/node/generic_sink.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/generic_source.hpp b/cpp/mrc/include/mrc/node/generic_source.hpp index 04b229c1f..19956d422 100644 --- a/cpp/mrc/include/mrc/node/generic_source.hpp +++ b/cpp/mrc/include/mrc/node/generic_source.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/operators/broadcast.hpp b/cpp/mrc/include/mrc/node/operators/broadcast.hpp index c3bfde7ae..553739c1c 100644 --- a/cpp/mrc/include/mrc/node/operators/broadcast.hpp +++ b/cpp/mrc/include/mrc/node/operators/broadcast.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/operators/conditional.hpp b/cpp/mrc/include/mrc/node/operators/conditional.hpp index cc32c7ccc..250942b7c 100644 --- a/cpp/mrc/include/mrc/node/operators/conditional.hpp +++ b/cpp/mrc/include/mrc/node/operators/conditional.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/operators/muxer.hpp b/cpp/mrc/include/mrc/node/operators/muxer.hpp index 73dfab409..52620d5eb 100644 --- a/cpp/mrc/include/mrc/node/operators/muxer.hpp +++ b/cpp/mrc/include/mrc/node/operators/muxer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/operators/router.hpp b/cpp/mrc/include/mrc/node/operators/router.hpp index a8c59598c..4261e8c4b 100644 --- a/cpp/mrc/include/mrc/node/operators/router.hpp +++ b/cpp/mrc/include/mrc/node/operators/router.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/port_registry.hpp b/cpp/mrc/include/mrc/node/port_registry.hpp index b8cfe8015..226e57d22 100644 --- a/cpp/mrc/include/mrc/node/port_registry.hpp +++ b/cpp/mrc/include/mrc/node/port_registry.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/queue.hpp b/cpp/mrc/include/mrc/node/queue.hpp index c8076eab9..81038feaf 100644 --- a/cpp/mrc/include/mrc/node/queue.hpp +++ b/cpp/mrc/include/mrc/node/queue.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/rx_epilogue_tap.hpp b/cpp/mrc/include/mrc/node/rx_epilogue_tap.hpp index e4fdd891b..8781cd3fb 100644 --- a/cpp/mrc/include/mrc/node/rx_epilogue_tap.hpp +++ b/cpp/mrc/include/mrc/node/rx_epilogue_tap.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/rx_execute.hpp b/cpp/mrc/include/mrc/node/rx_execute.hpp index 2a5962909..43a639ebe 100644 --- a/cpp/mrc/include/mrc/node/rx_execute.hpp +++ b/cpp/mrc/include/mrc/node/rx_execute.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/rx_node.hpp b/cpp/mrc/include/mrc/node/rx_node.hpp index 299a2a3af..34a48fd0d 100644 --- a/cpp/mrc/include/mrc/node/rx_node.hpp +++ b/cpp/mrc/include/mrc/node/rx_node.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -234,6 +234,10 @@ class RxNodeComponent : public WritableProvider, public WritableAcceptor // Forward to the writable edge this->get_writable_edge()->await_write(std::move(message)); }, + [this](std::exception_ptr ptr) { + WritableAcceptor::release_edge_connection(); + runnable::Context::get_runtime_context().set_exception(std::move(ptr)); + }, [this]() { // On completion, release connections WritableAcceptor::release_edge_connection(); diff --git a/cpp/mrc/include/mrc/node/rx_prologue_tap.hpp b/cpp/mrc/include/mrc/node/rx_prologue_tap.hpp index 555109d18..511099f49 100644 --- a/cpp/mrc/include/mrc/node/rx_prologue_tap.hpp +++ b/cpp/mrc/include/mrc/node/rx_prologue_tap.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/rx_runnable.hpp b/cpp/mrc/include/mrc/node/rx_runnable.hpp index 5339af4a9..369b06f25 100644 --- a/cpp/mrc/include/mrc/node/rx_runnable.hpp +++ b/cpp/mrc/include/mrc/node/rx_runnable.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/rx_sink.hpp b/cpp/mrc/include/mrc/node/rx_sink.hpp index 030c95e42..43c7fc2dd 100644 --- a/cpp/mrc/include/mrc/node/rx_sink.hpp +++ b/cpp/mrc/include/mrc/node/rx_sink.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/rx_sink_base.hpp b/cpp/mrc/include/mrc/node/rx_sink_base.hpp index aa638e96f..89d4a8c8f 100644 --- a/cpp/mrc/include/mrc/node/rx_sink_base.hpp +++ b/cpp/mrc/include/mrc/node/rx_sink_base.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/rx_source.hpp b/cpp/mrc/include/mrc/node/rx_source.hpp index 1bd0fe800..034d669ff 100644 --- a/cpp/mrc/include/mrc/node/rx_source.hpp +++ b/cpp/mrc/include/mrc/node/rx_source.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/rx_source_base.hpp b/cpp/mrc/include/mrc/node/rx_source_base.hpp index 5ca1355e5..58876d3c6 100644 --- a/cpp/mrc/include/mrc/node/rx_source_base.hpp +++ b/cpp/mrc/include/mrc/node/rx_source_base.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/rx_subscribable.hpp b/cpp/mrc/include/mrc/node/rx_subscribable.hpp index 4f40ae8d8..51e254093 100644 --- a/cpp/mrc/include/mrc/node/rx_subscribable.hpp +++ b/cpp/mrc/include/mrc/node/rx_subscribable.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/sink_channel_owner.hpp b/cpp/mrc/include/mrc/node/sink_channel_owner.hpp index ede2a7233..8997e3a8d 100644 --- a/cpp/mrc/include/mrc/node/sink_channel_owner.hpp +++ b/cpp/mrc/include/mrc/node/sink_channel_owner.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/sink_properties.hpp b/cpp/mrc/include/mrc/node/sink_properties.hpp index 15151166c..af56b0fe0 100644 --- a/cpp/mrc/include/mrc/node/sink_properties.hpp +++ b/cpp/mrc/include/mrc/node/sink_properties.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/source_channel_owner.hpp b/cpp/mrc/include/mrc/node/source_channel_owner.hpp index 09af31467..226492e5e 100644 --- a/cpp/mrc/include/mrc/node/source_channel_owner.hpp +++ b/cpp/mrc/include/mrc/node/source_channel_owner.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/source_properties.hpp b/cpp/mrc/include/mrc/node/source_properties.hpp index 4d647d750..12166eb43 100644 --- a/cpp/mrc/include/mrc/node/source_properties.hpp +++ b/cpp/mrc/include/mrc/node/source_properties.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/node/type_traits.hpp b/cpp/mrc/include/mrc/node/type_traits.hpp index f689d903b..31b7f0209 100644 --- a/cpp/mrc/include/mrc/node/type_traits.hpp +++ b/cpp/mrc/include/mrc/node/type_traits.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/options/engine_groups.hpp b/cpp/mrc/include/mrc/options/engine_groups.hpp index cd94d1879..984509fda 100644 --- a/cpp/mrc/include/mrc/options/engine_groups.hpp +++ b/cpp/mrc/include/mrc/options/engine_groups.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/options/fiber_pool.hpp b/cpp/mrc/include/mrc/options/fiber_pool.hpp index 470dad420..3e8297f35 100644 --- a/cpp/mrc/include/mrc/options/fiber_pool.hpp +++ b/cpp/mrc/include/mrc/options/fiber_pool.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/options/options.hpp b/cpp/mrc/include/mrc/options/options.hpp index 141812162..5455c75c7 100644 --- a/cpp/mrc/include/mrc/options/options.hpp +++ b/cpp/mrc/include/mrc/options/options.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/options/placement.hpp b/cpp/mrc/include/mrc/options/placement.hpp index 447607e2f..c84caf2bf 100644 --- a/cpp/mrc/include/mrc/options/placement.hpp +++ b/cpp/mrc/include/mrc/options/placement.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/options/resources.hpp b/cpp/mrc/include/mrc/options/resources.hpp index c4cc2f346..3b602694f 100644 --- a/cpp/mrc/include/mrc/options/resources.hpp +++ b/cpp/mrc/include/mrc/options/resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/options/services.hpp b/cpp/mrc/include/mrc/options/services.hpp index 4b3a625fb..2f0fc0c46 100644 --- a/cpp/mrc/include/mrc/options/services.hpp +++ b/cpp/mrc/include/mrc/options/services.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/options/topology.hpp b/cpp/mrc/include/mrc/options/topology.hpp index 9e440799e..da98239c8 100644 --- a/cpp/mrc/include/mrc/options/topology.hpp +++ b/cpp/mrc/include/mrc/options/topology.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 2f3c6117e..9167db16e 100644 --- a/cpp/mrc/include/mrc/pipeline/pipeline.hpp +++ b/cpp/mrc/include/mrc/pipeline/pipeline.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 25fff972e..b4a50697e 100644 --- a/cpp/mrc/include/mrc/engine/system/isystem.hpp +++ b/cpp/mrc/include/mrc/pipeline/system.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/pubsub/api.hpp b/cpp/mrc/include/mrc/pubsub/api.hpp index 9fa0a294d..4d792bb5d 100644 --- a/cpp/mrc/include/mrc/pubsub/api.hpp +++ b/cpp/mrc/include/mrc/pubsub/api.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/pubsub/forward.hpp b/cpp/mrc/include/mrc/pubsub/forward.hpp index ab2280459..899681136 100644 --- a/cpp/mrc/include/mrc/pubsub/forward.hpp +++ b/cpp/mrc/include/mrc/pubsub/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/pubsub/publisher.hpp b/cpp/mrc/include/mrc/pubsub/publisher.hpp index 0af2d9b28..c97d4a4dc 100644 --- a/cpp/mrc/include/mrc/pubsub/publisher.hpp +++ b/cpp/mrc/include/mrc/pubsub/publisher.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/pubsub/publisher_policy.hpp b/cpp/mrc/include/mrc/pubsub/publisher_policy.hpp index 460750b16..cbe14eed2 100644 --- a/cpp/mrc/include/mrc/pubsub/publisher_policy.hpp +++ b/cpp/mrc/include/mrc/pubsub/publisher_policy.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/pubsub/subscriber.hpp b/cpp/mrc/include/mrc/pubsub/subscriber.hpp index 2fd62dbca..5d3a78bc4 100644 --- a/cpp/mrc/include/mrc/pubsub/subscriber.hpp +++ b/cpp/mrc/include/mrc/pubsub/subscriber.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/context.hpp b/cpp/mrc/include/mrc/runnable/context.hpp index df2a39072..090804972 100644 --- a/cpp/mrc/include/mrc/runnable/context.hpp +++ b/cpp/mrc/include/mrc/runnable/context.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/detail/type_traits.hpp b/cpp/mrc/include/mrc/runnable/detail/type_traits.hpp index b6313dca4..d33d7be84 100644 --- a/cpp/mrc/include/mrc/runnable/detail/type_traits.hpp +++ b/cpp/mrc/include/mrc/runnable/detail/type_traits.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/engine.hpp b/cpp/mrc/include/mrc/runnable/engine.hpp index c02be1a64..1c8f95212 100644 --- a/cpp/mrc/include/mrc/runnable/engine.hpp +++ b/cpp/mrc/include/mrc/runnable/engine.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 e3b0223f2..efb2995e9 100644 --- a/cpp/mrc/include/mrc/runnable/engine_factory.hpp +++ b/cpp/mrc/include/mrc/runnable/engine_factory.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/fiber_context.hpp b/cpp/mrc/include/mrc/runnable/fiber_context.hpp index 0b3c2807c..954609be7 100644 --- a/cpp/mrc/include/mrc/runnable/fiber_context.hpp +++ b/cpp/mrc/include/mrc/runnable/fiber_context.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/forward.hpp b/cpp/mrc/include/mrc/runnable/forward.hpp index 6b9963281..1f999d19f 100644 --- a/cpp/mrc/include/mrc/runnable/forward.hpp +++ b/cpp/mrc/include/mrc/runnable/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/internal_service.hpp b/cpp/mrc/include/mrc/runnable/internal_service.hpp index c29982c12..b1a498acb 100644 --- a/cpp/mrc/include/mrc/runnable/internal_service.hpp +++ b/cpp/mrc/include/mrc/runnable/internal_service.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/launch_control.hpp b/cpp/mrc/include/mrc/runnable/launch_control.hpp index d4bc88448..67371a218 100644 --- a/cpp/mrc/include/mrc/runnable/launch_control.hpp +++ b/cpp/mrc/include/mrc/runnable/launch_control.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/launch_control_config.hpp b/cpp/mrc/include/mrc/runnable/launch_control_config.hpp index 535a7fce5..9e9817930 100644 --- a/cpp/mrc/include/mrc/runnable/launch_control_config.hpp +++ b/cpp/mrc/include/mrc/runnable/launch_control_config.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/launch_options.hpp b/cpp/mrc/include/mrc/runnable/launch_options.hpp index a4b1b10cf..f6cb0d2b5 100644 --- a/cpp/mrc/include/mrc/runnable/launch_options.hpp +++ b/cpp/mrc/include/mrc/runnable/launch_options.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/launchable.hpp b/cpp/mrc/include/mrc/runnable/launchable.hpp index 493428bb0..1800b8e21 100644 --- a/cpp/mrc/include/mrc/runnable/launchable.hpp +++ b/cpp/mrc/include/mrc/runnable/launchable.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/launcher.hpp b/cpp/mrc/include/mrc/runnable/launcher.hpp index 6ab9e79d1..b7a40b1d1 100644 --- a/cpp/mrc/include/mrc/runnable/launcher.hpp +++ b/cpp/mrc/include/mrc/runnable/launcher.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/runnable/runnable.hpp b/cpp/mrc/include/mrc/runnable/runnable.hpp index b6559c9d5..35469603c 100644 --- a/cpp/mrc/include/mrc/runnable/runnable.hpp +++ b/cpp/mrc/include/mrc/runnable/runnable.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 5923813ce..33df5459c 100644 --- a/cpp/mrc/include/mrc/pipeline/resources.hpp +++ b/cpp/mrc/include/mrc/runnable/runnable_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 be3ab16cd..c2539b601 100644 --- a/cpp/mrc/include/mrc/runnable/runner.hpp +++ b/cpp/mrc/include/mrc/runnable/runner.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/runnable/runner_event.hpp b/cpp/mrc/include/mrc/runnable/runner_event.hpp index 1b72e88b3..5334febea 100644 --- a/cpp/mrc/include/mrc/runnable/runner_event.hpp +++ b/cpp/mrc/include/mrc/runnable/runner_event.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/thread_context.hpp b/cpp/mrc/include/mrc/runnable/thread_context.hpp index d56f0a181..d695faf90 100644 --- a/cpp/mrc/include/mrc/runnable/thread_context.hpp +++ b/cpp/mrc/include/mrc/runnable/thread_context.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/type_traits.hpp b/cpp/mrc/include/mrc/runnable/type_traits.hpp index 531a5896e..b6dd71deb 100644 --- a/cpp/mrc/include/mrc/runnable/type_traits.hpp +++ b/cpp/mrc/include/mrc/runnable/type_traits.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runnable/types.hpp b/cpp/mrc/include/mrc/runnable/types.hpp index ba672501e..6a65b3df8 100644 --- a/cpp/mrc/include/mrc/runnable/types.hpp +++ b/cpp/mrc/include/mrc/runnable/types.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runtime/api.hpp b/cpp/mrc/include/mrc/runtime/api.hpp index 2fe98531c..e5ea0d778 100644 --- a/cpp/mrc/include/mrc/runtime/api.hpp +++ b/cpp/mrc/include/mrc/runtime/api.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runtime/forward.hpp b/cpp/mrc/include/mrc/runtime/forward.hpp index 5364bb44e..6f7123ccf 100644 --- a/cpp/mrc/include/mrc/runtime/forward.hpp +++ b/cpp/mrc/include/mrc/runtime/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runtime/remote_descriptor.hpp b/cpp/mrc/include/mrc/runtime/remote_descriptor.hpp index e32a5822b..d84ff903a 100644 --- a/cpp/mrc/include/mrc/runtime/remote_descriptor.hpp +++ b/cpp/mrc/include/mrc/runtime/remote_descriptor.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/runtime/remote_descriptor_handle.hpp b/cpp/mrc/include/mrc/runtime/remote_descriptor_handle.hpp index 05da1c5c8..71b5cf587 100644 --- a/cpp/mrc/include/mrc/runtime/remote_descriptor_handle.hpp +++ b/cpp/mrc/include/mrc/runtime/remote_descriptor_handle.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/runtime/remote_descriptor_manager.hpp b/cpp/mrc/include/mrc/runtime/remote_descriptor_manager.hpp index c7162b2c1..976bd20ce 100644 --- a/cpp/mrc/include/mrc/runtime/remote_descriptor_manager.hpp +++ b/cpp/mrc/include/mrc/runtime/remote_descriptor_manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/segment/builder.hpp b/cpp/mrc/include/mrc/segment/builder.hpp index 0962f5c38..a35f571c9 100644 --- a/cpp/mrc/include/mrc/segment/builder.hpp +++ b/cpp/mrc/include/mrc/segment/builder.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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" @@ -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)...); + + return make_object(std::move(name), std::move(uptr)); +} - ::add_stats_watcher_if_rx_source(*uptr, ns_name); - ::add_stats_watcher_if_rx_sink(*uptr, ns_name); +template +std::shared_ptr> IBuilder::make_object(std::string name, std::unique_ptr node) +{ + std::shared_ptr> segment_object{nullptr}; - return make_object(std::move(ns_name), std::move(uptr)); + 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; } -} // namespace mrc::segment \ No newline at end of file +// 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/component.hpp b/cpp/mrc/include/mrc/segment/component.hpp index aa3a1be02..3e25f9b63 100644 --- a/cpp/mrc/include/mrc/segment/component.hpp +++ b/cpp/mrc/include/mrc/segment/component.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/segment/context.hpp b/cpp/mrc/include/mrc/segment/context.hpp index 713c4e00b..485f05d20 100644 --- a/cpp/mrc/include/mrc/segment/context.hpp +++ b/cpp/mrc/include/mrc/segment/context.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/segment/definition.hpp b/cpp/mrc/include/mrc/segment/definition.hpp deleted file mode 100644 index f43fd9788..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 897a24204..7fe52a5ce 100644 --- a/cpp/mrc/include/mrc/segment/egress_port.hpp +++ b/cpp/mrc/include/mrc/segment/egress_port.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/egress_ports.hpp b/cpp/mrc/include/mrc/segment/egress_ports.hpp index 0a2d3ab15..0e3d74862 100644 --- a/cpp/mrc/include/mrc/segment/egress_ports.hpp +++ b/cpp/mrc/include/mrc/segment/egress_ports.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/segment/forward.hpp b/cpp/mrc/include/mrc/segment/forward.hpp index 2982d0372..7ce590512 100644 --- a/cpp/mrc/include/mrc/segment/forward.hpp +++ b/cpp/mrc/include/mrc/segment/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 dc7be2941..fec6d469e 100644 --- a/cpp/mrc/include/mrc/segment/ingress_port.hpp +++ b/cpp/mrc/include/mrc/segment/ingress_port.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/ingress_ports.hpp b/cpp/mrc/include/mrc/segment/ingress_ports.hpp index 72713ae61..1d7f0f664 100644 --- a/cpp/mrc/include/mrc/segment/ingress_ports.hpp +++ b/cpp/mrc/include/mrc/segment/ingress_ports.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 9d389a88a..2ccc80094 100644 --- a/cpp/mrc/include/mrc/segment/object.hpp +++ b/cpp/mrc/include/mrc/segment/object.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c61a8ad37..4f4807e75 100644 --- a/cpp/mrc/include/mrc/segment/ports.hpp +++ b/cpp/mrc/include/mrc/segment/ports.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 6914fe797..ab5b590ca 100644 --- a/cpp/mrc/include/mrc/segment/runnable.hpp +++ b/cpp/mrc/include/mrc/segment/runnable.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 4e678f53b..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/include/mrc/segment/utils.hpp b/cpp/mrc/include/mrc/segment/utils.hpp index 3df29c895..513f2ddd9 100644 --- a/cpp/mrc/include/mrc/segment/utils.hpp +++ b/cpp/mrc/include/mrc/segment/utils.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/type_traits.hpp b/cpp/mrc/include/mrc/type_traits.hpp index d8bb459ad..4f1477abf 100644 --- a/cpp/mrc/include/mrc/type_traits.hpp +++ b/cpp/mrc/include/mrc/type_traits.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/types.hpp b/cpp/mrc/include/mrc/types.hpp index fe1babbbc..063e00831 100644 --- a/cpp/mrc/include/mrc/types.hpp +++ b/cpp/mrc/include/mrc/types.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/utils/bytes_to_string.hpp b/cpp/mrc/include/mrc/utils/bytes_to_string.hpp index 8d48424a4..6ed8d0e89 100644 --- a/cpp/mrc/include/mrc/utils/bytes_to_string.hpp +++ b/cpp/mrc/include/mrc/utils/bytes_to_string.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/utils/logging.hpp b/cpp/mrc/include/mrc/utils/logging.hpp index 6653320f1..1e1042912 100644 --- a/cpp/mrc/include/mrc/utils/logging.hpp +++ b/cpp/mrc/include/mrc/utils/logging.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/utils/macros.hpp b/cpp/mrc/include/mrc/utils/macros.hpp index 20ab0dabd..1cd662cf2 100644 --- a/cpp/mrc/include/mrc/utils/macros.hpp +++ b/cpp/mrc/include/mrc/utils/macros.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/utils/runtime_validation_utils.hpp b/cpp/mrc/include/mrc/utils/runtime_validation_utils.hpp index c630a4887..3e6891ebc 100644 --- a/cpp/mrc/include/mrc/utils/runtime_validation_utils.hpp +++ b/cpp/mrc/include/mrc/utils/runtime_validation_utils.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/utils/sfinae_concept.hpp b/cpp/mrc/include/mrc/utils/sfinae_concept.hpp index eca3a45c2..aed4a8319 100644 --- a/cpp/mrc/include/mrc/utils/sfinae_concept.hpp +++ b/cpp/mrc/include/mrc/utils/sfinae_concept.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/utils/sort_indexes.hpp b/cpp/mrc/include/mrc/utils/sort_indexes.hpp index 12c67b2de..e9986170c 100644 --- a/cpp/mrc/include/mrc/utils/sort_indexes.hpp +++ b/cpp/mrc/include/mrc/utils/sort_indexes.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/utils/string_utils.hpp b/cpp/mrc/include/mrc/utils/string_utils.hpp index bbc2e97ca..a835189f3 100644 --- a/cpp/mrc/include/mrc/utils/string_utils.hpp +++ b/cpp/mrc/include/mrc/utils/string_utils.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/utils/thread_local_shared_pointer.hpp b/cpp/mrc/include/mrc/utils/thread_local_shared_pointer.hpp index 40aab1403..64bffc7d4 100644 --- a/cpp/mrc/include/mrc/utils/thread_local_shared_pointer.hpp +++ b/cpp/mrc/include/mrc/utils/thread_local_shared_pointer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/include/mrc/utils/type_utils.hpp b/cpp/mrc/include/mrc/utils/type_utils.hpp index cd88442b8..c7fce9e7a 100644 --- a/cpp/mrc/include/mrc/utils/type_utils.hpp +++ b/cpp/mrc/include/mrc/utils/type_utils.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/codable/codable_storage.cpp b/cpp/mrc/src/internal/codable/codable_storage.cpp index 77621c991..c59a274a0 100644 --- a/cpp/mrc/src/internal/codable/codable_storage.cpp +++ b/cpp/mrc/src/internal/codable/codable_storage.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d9481928a..14931ea24 100644 --- a/cpp/mrc/src/internal/codable/codable_storage.hpp +++ b/cpp/mrc/src/internal/codable/codable_storage.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 878895fe9..a4db24dac 100644 --- a/cpp/mrc/src/internal/codable/decodable_storage_view.cpp +++ b/cpp/mrc/src/internal/codable/decodable_storage_view.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 150756248..8e07cd797 100644 --- a/cpp/mrc/src/internal/codable/decodable_storage_view.hpp +++ b/cpp/mrc/src/internal/codable/decodable_storage_view.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 298ecbef3..62ed0c651 100644 --- a/cpp/mrc/src/internal/codable/storage_resources.hpp +++ b/cpp/mrc/src/internal/codable/storage_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c45436770..3ae474ad7 100644 --- a/cpp/mrc/src/internal/codable/storage_view.cpp +++ b/cpp/mrc/src/internal/codable/storage_view.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 50259b364..a39259266 100644 --- a/cpp/mrc/src/internal/codable/storage_view.hpp +++ b/cpp/mrc/src/internal/codable/storage_view.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 992cda81d..7a85adc2e 100644 --- a/cpp/mrc/src/internal/control_plane/client.cpp +++ b/cpp/mrc/src/internal/control_plane/client.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 2f3f715f2..0a07991a6 100644 --- a/cpp/mrc/src/internal/control_plane/client.hpp +++ b/cpp/mrc/src/internal/control_plane/client.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c89c070b1..76cc2477e 100644 --- a/cpp/mrc/src/internal/control_plane/client/connections_manager.cpp +++ b/cpp/mrc/src/internal/control_plane/client/connections_manager.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 09f425f11..8c1015c92 100644 --- a/cpp/mrc/src/internal/control_plane/client/connections_manager.hpp +++ b/cpp/mrc/src/internal/control_plane/client/connections_manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 9eac6157f..65c0040ad 100644 --- a/cpp/mrc/src/internal/control_plane/client/instance.cpp +++ b/cpp/mrc/src/internal/control_plane/client/instance.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 57570c85e..9ab69161c 100644 --- a/cpp/mrc/src/internal/control_plane/client/instance.hpp +++ b/cpp/mrc/src/internal/control_plane/client/instance.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 f99bab4d7..1970e3574 100644 --- a/cpp/mrc/src/internal/control_plane/client/state_manager.cpp +++ b/cpp/mrc/src/internal/control_plane/client/state_manager.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 70d98a65a..9a600688c 100644 --- a/cpp/mrc/src/internal/control_plane/client/state_manager.hpp +++ b/cpp/mrc/src/internal/control_plane/client/state_manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d41f00bef..50e6e2351 100644 --- a/cpp/mrc/src/internal/control_plane/client/subscription_service.cpp +++ b/cpp/mrc/src/internal/control_plane/client/subscription_service.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 cc7e134a6..7561c1d89 100644 --- a/cpp/mrc/src/internal/control_plane/resources.hpp +++ b/cpp/mrc/src/internal/control_plane/control_plane_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 126aa1792..332677441 100644 --- a/cpp/mrc/src/internal/control_plane/proto_helpers.hpp +++ b/cpp/mrc/src/internal/control_plane/proto_helpers.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 8336c1f18..aa980aba8 100644 --- a/cpp/mrc/src/internal/control_plane/server.cpp +++ b/cpp/mrc/src/internal/control_plane/server.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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; @@ -204,7 +204,7 @@ void Server::do_service_await_join() /** * @brief Stream Acceptor * - * The while loop of this method says active as long as the grpc server is still accepting connections. + * The while loop of this method stays active as long as the grpc server is still accepting connections. * There are multiple way this can be implemented depending the service requirements, one might choose * to preallocate N number of streams and issues them all to the CQ. This is an alternative method which * creates a single stream and waits for it to get initialized, then creates another. The current implementation is @@ -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 85d97241d..d3d319502 100644 --- a/cpp/mrc/src/internal/control_plane/server.hpp +++ b/cpp/mrc/src/internal/control_plane/server.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 25b020fd8..ce94790f1 100644 --- a/cpp/mrc/src/internal/control_plane/server/client_instance.hpp +++ b/cpp/mrc/src/internal/control_plane/server/client_instance.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 1f0fefa9a..617c3b4c6 100644 --- a/cpp/mrc/src/internal/control_plane/server/connection_manager.cpp +++ b/cpp/mrc/src/internal/control_plane/server/connection_manager.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b45a28e6b..34d328df1 100644 --- a/cpp/mrc/src/internal/control_plane/server/connection_manager.hpp +++ b/cpp/mrc/src/internal/control_plane/server/connection_manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 45942badc..c406e9ef9 100644 --- a/cpp/mrc/src/internal/control_plane/server/subscription_manager.cpp +++ b/cpp/mrc/src/internal/control_plane/server/subscription_manager.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 60682fd37..9081922a0 100644 --- a/cpp/mrc/src/internal/control_plane/server/subscription_manager.hpp +++ b/cpp/mrc/src/internal/control_plane/server/subscription_manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -35,13 +35,13 @@ class StateUpdate; class UpdateSubscriptionServiceRequest; } // namespace mrc::protos -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { class Role; class ClientInstance; /** - * @brief A specialize TaggedManager to synchronize tag and instance_id information across between a collection of + * @brief A specialized TaggedIssuer to synchronize tag and instance_id information across between a collection of * client-side objects with common linkages, e.g. the Publisher/Subscriber services which form the building blocks for * Ingress/EgressPorts use instances of SubscriptionService for Publishers to get control plane updates to the list of * Subscribers. @@ -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 2168d1e7d..0f9fcfadc 100644 --- a/cpp/mrc/src/internal/control_plane/server/tagged_issuer.cpp +++ b/cpp/mrc/src/internal/control_plane/server/tagged_issuer.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 191d4ee31..db0e12b20 100644 --- a/cpp/mrc/src/internal/control_plane/server/tagged_issuer.hpp +++ b/cpp/mrc/src/internal/control_plane/server/tagged_issuer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -28,7 +28,7 @@ #include #include -namespace mrc::internal::control_plane::server { +namespace mrc::control_plane::server { /** * @brief Creates masked tags. @@ -70,9 +70,9 @@ class Tagged * This is the primary base class for a control plane server-side stateful service which can be updated by the client * and state updates driven independently via the issue_update() method. * - * TaggedManager is not thread-safe or protected in anyway. The global state mutex should protect all TaggedManagers. + * TaggedIssuer is not thread-safe or protected in anyway. The global state mutex should protect all TaggedIssuers. * - * In most scenarios, the service side will have a batched updated which will periodically visit each TaggedManager and + * In most scenarios, the service side will have a batched updated which will periodically visit each TaggedIssuer and * call issue_update(); however, depending on the service request/update message, the call may also require an immediate * update. */ @@ -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 e70bf2103..7ecf1df33 100644 --- a/cpp/mrc/src/internal/control_plane/server/update_issuer.hpp +++ b/cpp/mrc/src/internal/control_plane/server/update_issuer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ab7e73d3f..a1425eb25 100644 --- a/cpp/mrc/src/internal/control_plane/server/versioned_issuer.hpp +++ b/cpp/mrc/src/internal/control_plane/server/versioned_issuer.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 f601ad5c0..58ab6dc7f 100644 --- a/cpp/mrc/src/internal/data_plane/callbacks.cpp +++ b/cpp/mrc/src/internal/data_plane/callbacks.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c2b69c174..b86244f4b 100644 --- a/cpp/mrc/src/internal/data_plane/callbacks.hpp +++ b/cpp/mrc/src/internal/data_plane/callbacks.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 681ddb762..0f0a5ee4c 100644 --- a/cpp/mrc/src/internal/data_plane/client.cpp +++ b/cpp/mrc/src/internal/data_plane/client.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 be11c42af..7b02b1451 100644 --- a/cpp/mrc/src/internal/data_plane/client.hpp +++ b/cpp/mrc/src/internal/data_plane/client.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 8b094537b..3ecf2d3f6 100644 --- a/cpp/mrc/src/internal/data_plane/resources.cpp +++ b/cpp/mrc/src/internal/data_plane/data_plane_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 25f0d2f8e..62f85f75f 100644 --- a/cpp/mrc/src/internal/data_plane/resources.hpp +++ b/cpp/mrc/src/internal/data_plane/data_plane_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 2f207f67b..32b2ad69e 100644 --- a/cpp/mrc/src/internal/data_plane/request.cpp +++ b/cpp/mrc/src/internal/data_plane/request.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 0952b41dd..ee64ebc45 100644 --- a/cpp/mrc/src/internal/data_plane/request.hpp +++ b/cpp/mrc/src/internal/data_plane/request.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 aa767ad10..a230ad934 100644 --- a/cpp/mrc/src/internal/data_plane/server.cpp +++ b/cpp/mrc/src/internal/data_plane/server.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ad2ebfa56..fa56146bd 100644 --- a/cpp/mrc/src/internal/data_plane/server.hpp +++ b/cpp/mrc/src/internal/data_plane/server.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/data_plane/tags.hpp b/cpp/mrc/src/internal/data_plane/tags.hpp index 6bfc46021..462840c5f 100644 --- a/cpp/mrc/src/internal/data_plane/tags.hpp +++ b/cpp/mrc/src/internal/data_plane/tags.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 95a184fea..de630115d 100644 --- a/cpp/mrc/src/internal/executor/executor.cpp +++ b/cpp/mrc/src/internal/executor/executor_definition.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 8232fcf8d..653db9d53 100644 --- a/cpp/mrc/src/internal/executor/executor.hpp +++ b/cpp/mrc/src/internal/executor/executor_definition.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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; - void register_pipeline(std::unique_ptr ipipeline); + static std::shared_ptr unwrap(std::shared_ptr object); + + 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 35eab74a4..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/forward.hpp b/cpp/mrc/src/internal/forward.hpp index 01139971b..26bb56adc 100644 --- a/cpp/mrc/src/internal/forward.hpp +++ b/cpp/mrc/src/internal/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/grpc/client_streaming.hpp b/cpp/mrc/src/internal/grpc/client_streaming.hpp index 5582925ca..8ee6bd82e 100644 --- a/cpp/mrc/src/internal/grpc/client_streaming.hpp +++ b/cpp/mrc/src/internal/grpc/client_streaming.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 707476044..7bea6239e 100644 --- a/cpp/mrc/src/internal/grpc/progress_engine.hpp +++ b/cpp/mrc/src/internal/grpc/progress_engine.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 79c75d819..437a22e69 100644 --- a/cpp/mrc/src/internal/grpc/promise_handler.hpp +++ b/cpp/mrc/src/internal/grpc/promise_handler.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 1cb672e29..9e0c0ecb4 100644 --- a/cpp/mrc/src/internal/grpc/server.cpp +++ b/cpp/mrc/src/internal/grpc/server.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 6a31cf440..cacd4602d 100644 --- a/cpp/mrc/src/internal/grpc/server.hpp +++ b/cpp/mrc/src/internal/grpc/server.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 a12806638..0d4da8b44 100644 --- a/cpp/mrc/src/internal/grpc/server_streaming.hpp +++ b/cpp/mrc/src/internal/grpc/server_streaming.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 05d5572d5..063a8bfad 100644 --- a/cpp/mrc/src/internal/memory/block_manager.hpp +++ b/cpp/mrc/src/internal/memory/block_manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 1da2cf040..96f00b539 100644 --- a/cpp/mrc/src/internal/memory/callback_adaptor.hpp +++ b/cpp/mrc/src/internal/memory/callback_adaptor.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 405d94227..907eb1a4a 100644 --- a/cpp/mrc/src/internal/memory/device_resources.cpp +++ b/cpp/mrc/src/internal/memory/device_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 7efc6b710..a769c9ae3 100644 --- a/cpp/mrc/src/internal/memory/device_resources.hpp +++ b/cpp/mrc/src/internal/memory/device_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 5e567a3bd..e3272d1a0 100644 --- a/cpp/mrc/src/internal/memory/forward.hpp +++ b/cpp/mrc/src/internal/memory/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 3fed6aea0..c98c78618 100644 --- a/cpp/mrc/src/internal/memory/host_resources.cpp +++ b/cpp/mrc/src/internal/memory/host_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 1100e01f7..0759daeef 100644 --- a/cpp/mrc/src/internal/memory/host_resources.hpp +++ b/cpp/mrc/src/internal/memory/host_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b3483ee13..4874b1475 100644 --- a/cpp/mrc/src/internal/memory/memory_block.hpp +++ b/cpp/mrc/src/internal/memory/memory_block.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 66c19f02a..f16931458 100644 --- a/cpp/mrc/src/internal/memory/transient_pool.cpp +++ b/cpp/mrc/src/internal/memory/transient_pool.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 41654120b..066b00dad 100644 --- a/cpp/mrc/src/internal/memory/transient_pool.hpp +++ b/cpp/mrc/src/internal/memory/transient_pool.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 6b05f767a..b28a0d14f 100644 --- a/cpp/mrc/src/internal/network/resources.cpp +++ b/cpp/mrc/src/internal/network/network_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b4fc019f3..b542299fc 100644 --- a/cpp/mrc/src/internal/network/resources.hpp +++ b/cpp/mrc/src/internal/network/network_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 cbd188dfa..93946abbe 100644 --- a/cpp/mrc/src/internal/pipeline/controller.cpp +++ b/cpp/mrc/src/internal/pipeline/controller.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 080bd5234..14c9e528b 100644 --- a/cpp/mrc/src/internal/pipeline/controller.hpp +++ b/cpp/mrc/src/internal/pipeline/controller.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 0f3140dbe..b191d42e9 100644 --- a/cpp/mrc/src/internal/pipeline/forward.hpp +++ b/cpp/mrc/src/internal/pipeline/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 0541842c6..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 b7b340eb2..0487fdfb9 100644 --- a/cpp/mrc/src/internal/pipeline/manager.cpp +++ b/cpp/mrc/src/internal/pipeline/manager.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 71ee6bde6..cce46c347 100644 --- a/cpp/mrc/src/internal/pipeline/manager.hpp +++ b/cpp/mrc/src/internal/pipeline/manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d78023fa8..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 9b61dddc6..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 cf09eff8d..50e3abca1 100644 --- a/cpp/mrc/src/internal/pipeline/instance.cpp +++ b/cpp/mrc/src/internal/pipeline/pipeline_instance.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c5f9ab834..d9f2489b8 100644 --- a/cpp/mrc/src/internal/pipeline/instance.hpp +++ b/cpp/mrc/src/internal/pipeline/pipeline_instance.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c1b5a086f..2a336fe94 100644 --- a/cpp/mrc/src/internal/pipeline/resources.cpp +++ b/cpp/mrc/src/internal/pipeline/pipeline_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c33b480bc..898516be2 100644 --- a/cpp/mrc/src/internal/pipeline/resources.hpp +++ b/cpp/mrc/src/internal/pipeline/pipeline_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 41803098f..6a1cead0f 100644 --- a/cpp/mrc/src/internal/pipeline/port_graph.cpp +++ b/cpp/mrc/src/internal/pipeline/port_graph.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 3906f4209..c889c9df3 100644 --- a/cpp/mrc/src/internal/pipeline/port_graph.hpp +++ b/cpp/mrc/src/internal/pipeline/port_graph.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 db30e8aec..68699b57e 100644 --- a/cpp/mrc/src/internal/pipeline/types.hpp +++ b/cpp/mrc/src/internal/pipeline/types.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/placement_group.hpp b/cpp/mrc/src/internal/placement_group.hpp index ba8f42939..3c675b32d 100644 --- a/cpp/mrc/src/internal/placement_group.hpp +++ b/cpp/mrc/src/internal/placement_group.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/pubsub/base.hpp b/cpp/mrc/src/internal/pubsub/base.hpp index c26e985d5..14b040333 100644 --- a/cpp/mrc/src/internal/pubsub/base.hpp +++ b/cpp/mrc/src/internal/pubsub/base.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 42d3c3ba7..6399fa332 100644 --- a/cpp/mrc/src/internal/pubsub/forward.hpp +++ b/cpp/mrc/src/internal/pubsub/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 70ae7f92a..dcaf27272 100644 --- a/cpp/mrc/src/internal/pubsub/publisher_round_robin.cpp +++ b/cpp/mrc/src/internal/pubsub/publisher_round_robin.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 f301443d0..2ea517e44 100644 --- a/cpp/mrc/src/internal/pubsub/publisher_service.cpp +++ b/cpp/mrc/src/internal/pubsub/publisher_service.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 dbc89a31e..c5531230d 100644 --- a/cpp/mrc/src/internal/pubsub/publisher_service.hpp +++ b/cpp/mrc/src/internal/pubsub/publisher_service.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 971231a84..c53dac546 100644 --- a/cpp/mrc/src/internal/pubsub/subscriber_service.cpp +++ b/cpp/mrc/src/internal/pubsub/subscriber_service.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b30b31fa3..6bfa33b32 100644 --- a/cpp/mrc/src/internal/pubsub/subscriber_service.hpp +++ b/cpp/mrc/src/internal/pubsub/subscriber_service.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 29549fab0..406a91e7b 100644 --- a/cpp/mrc/src/internal/remote_descriptor/decodable_storage.cpp +++ b/cpp/mrc/src/internal/remote_descriptor/decodable_storage.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 7ba1152b2..c618f7ccd 100644 --- a/cpp/mrc/src/internal/remote_descriptor/decodable_storage.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/decodable_storage.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 844cad8ba..266a8f3d3 100644 --- a/cpp/mrc/src/internal/remote_descriptor/forward.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 4b647c9d4..fe73a61bc 100644 --- a/cpp/mrc/src/internal/remote_descriptor/manager.cpp +++ b/cpp/mrc/src/internal/remote_descriptor/manager.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 263d5aa22..43a1a99fe 100644 --- a/cpp/mrc/src/internal/remote_descriptor/manager.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c2822b6a2..02a87cc4b 100644 --- a/cpp/mrc/src/internal/remote_descriptor/messages.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/messages.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 5be8590c1..6759f37cd 100644 --- a/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.cpp +++ b/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 57e79bd3e..381b03874 100644 --- a/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/remote_descriptor.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ce4667bc2..a593da476 100644 --- a/cpp/mrc/src/internal/remote_descriptor/storage.cpp +++ b/cpp/mrc/src/internal/remote_descriptor/storage.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ad1fcd648..79fef4443 100644 --- a/cpp/mrc/src/internal/remote_descriptor/storage.hpp +++ b/cpp/mrc/src/internal/remote_descriptor/storage.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b3a735e1e..f2d47b675 100644 --- a/cpp/mrc/src/internal/resources/forward.hpp +++ b/cpp/mrc/src/internal/resources/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 5a992e3b0..b47334c04 100644 --- a/cpp/mrc/src/internal/resources/manager.cpp +++ b/cpp/mrc/src/internal/resources/manager.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 f58f886ab..a823bbe27 100644 --- a/cpp/mrc/src/internal/resources/manager.hpp +++ b/cpp/mrc/src/internal/resources/manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 a535eff3e..c6bbb4b9e 100644 --- a/cpp/mrc/src/internal/resources/partition_resources.cpp +++ b/cpp/mrc/src/internal/resources/partition_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 9d906901b..d1e832471 100644 --- a/cpp/mrc/src/internal/resources/partition_resources.hpp +++ b/cpp/mrc/src/internal/resources/partition_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 fc3b41d1f..1983a23d6 100644 --- a/cpp/mrc/src/internal/resources/partition_resources_base.cpp +++ b/cpp/mrc/src/internal/resources/partition_resources_base.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 0e486cd48..75d774556 100644 --- a/cpp/mrc/src/internal/resources/partition_resources_base.hpp +++ b/cpp/mrc/src/internal/resources/partition_resources_base.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d03a7af0f..4ebe57491 100644 --- a/cpp/mrc/src/internal/runnable/engine.cpp +++ b/cpp/mrc/src/internal/runnable/engine.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 5b62ca5ec..afed43e3c 100644 --- a/cpp/mrc/src/internal/runnable/engine.hpp +++ b/cpp/mrc/src/internal/runnable/engine.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 27947c2d2..db3857bfa 100644 --- a/cpp/mrc/src/internal/runnable/engine_factory.cpp +++ b/cpp/mrc/src/internal/runnable/engine_factory.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 a5e630bbe..e8df4b4bd 100644 --- a/cpp/mrc/src/internal/runnable/engine_factory.hpp +++ b/cpp/mrc/src/internal/runnable/engine_factory.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 166395f94..aadd29f1d 100644 --- a/cpp/mrc/src/internal/runnable/engines.cpp +++ b/cpp/mrc/src/internal/runnable/engines.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b5dc279c4..4c4100a79 100644 --- a/cpp/mrc/src/internal/runnable/engines.hpp +++ b/cpp/mrc/src/internal/runnable/engines.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 2325cadf5..10dc1eb51 100644 --- a/cpp/mrc/src/internal/runnable/fiber_engine.cpp +++ b/cpp/mrc/src/internal/runnable/fiber_engine.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 656d8f223..4d6986398 100644 --- a/cpp/mrc/src/internal/runnable/fiber_engine.hpp +++ b/cpp/mrc/src/internal/runnable/fiber_engine.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 04fb0d49b..87dfa5556 100644 --- a/cpp/mrc/src/internal/runnable/fiber_engines.cpp +++ b/cpp/mrc/src/internal/runnable/fiber_engines.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 2533c01d0..72590324a 100644 --- a/cpp/mrc/src/internal/runnable/fiber_engines.hpp +++ b/cpp/mrc/src/internal/runnable/fiber_engines.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ac4c65800..4fa98f1ce 100644 --- a/cpp/mrc/src/internal/runnable/resources.cpp +++ b/cpp/mrc/src/internal/runnable/runnable_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d401da431..fbce3895e 100644 --- a/cpp/mrc/src/internal/runnable/resources.hpp +++ b/cpp/mrc/src/internal/runnable/runnable_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 9908c180e..fb18c3b60 100644 --- a/cpp/mrc/src/internal/runnable/thread_engine.cpp +++ b/cpp/mrc/src/internal/runnable/thread_engine.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 1f94284a0..b94ca677c 100644 --- a/cpp/mrc/src/internal/runnable/thread_engine.hpp +++ b/cpp/mrc/src/internal/runnable/thread_engine.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d860af0c5..23f9c430a 100644 --- a/cpp/mrc/src/internal/runnable/thread_engines.cpp +++ b/cpp/mrc/src/internal/runnable/thread_engines.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 55bb811cd..a89149756 100644 --- a/cpp/mrc/src/internal/runnable/thread_engines.hpp +++ b/cpp/mrc/src/internal/runnable/thread_engines.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ad39e61f8..7289936b8 100644 --- a/cpp/mrc/src/internal/runtime/partition.cpp +++ b/cpp/mrc/src/internal/runtime/partition.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 a1d8b1a74..4bda20727 100644 --- a/cpp/mrc/src/internal/runtime/partition.hpp +++ b/cpp/mrc/src/internal/runtime/partition.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b9a1dbc10..7b2ea0576 100644 --- a/cpp/mrc/src/internal/runtime/runtime.cpp +++ b/cpp/mrc/src/internal/runtime/runtime.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c34399566..3edbb69e0 100644 --- a/cpp/mrc/src/internal/runtime/runtime.hpp +++ b/cpp/mrc/src/internal/runtime/runtime.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ff4b126ff..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 946687236..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 1429f62e2..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 597543420..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 a07b0bbf0..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 efe172e4f..1f04f50f6 100644 --- a/cpp/mrc/src/internal/segment/definition.cpp +++ b/cpp/mrc/src/internal/segment/segment_definition.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 380a39c56..871b7a2ca 100644 --- a/cpp/mrc/src/internal/segment/instance.cpp +++ b/cpp/mrc/src/internal/segment/segment_instance.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 df9416ebb..addd38dd1 100644 --- a/cpp/mrc/src/internal/segment/instance.hpp +++ b/cpp/mrc/src/internal/segment/segment_instance.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 8a8c657f7..01c51b014 100644 --- a/cpp/mrc/src/internal/service.cpp +++ b/cpp/mrc/src/internal/service.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 a78e0b846..f707321e2 100644 --- a/cpp/mrc/src/internal/service.hpp +++ b/cpp/mrc/src/internal/service.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d1623e251..b9f3461f2 100644 --- a/cpp/mrc/src/internal/system/device_info.cpp +++ b/cpp/mrc/src/internal/system/device_info.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -17,45 +17,156 @@ #include "internal/system/device_info.hpp" -#include "mrc/cuda/common.hpp" // IWYU pragma: associated +#include "mrc/cuda/common.hpp" #include +#include #include +#include +#include +#include #include #include +#include +#include #include +#include +#include #include #include +#include #include +namespace mrc::system { +struct NvmlHandle; +struct NvmlState; + #define TEST_BIT(_n, _p) (_n & (1UL << _p)) -#define MRC_CHECK_NVML(expression) \ - { \ - auto status = (expression); \ - if (status != NVML_SUCCESS) \ - { \ - LOG(FATAL) << "NVML failed: " << nvmlErrorString(status); \ - } \ +#define MRC_CHECK_NVML(expression) \ + { \ + auto __status = (expression); \ + if (__status != NVML_SUCCESS) \ + { \ + LOG(FATAL) << "NVML failed running '" << #expression \ + << "'. Error msg: " << NvmlState::handle().nvmlErrorString(__status); \ + } \ + } + +#define LOAD_NVTX_SYM(dll_ptr, function_var) \ + function_var = reinterpret_cast(dlsym(dll_ptr, #function_var)); \ + if (function_var == nullptr) \ + { \ + throw std::runtime_error("Failed to load symbol " #function_var " from libnvidia-ml.so.1"); \ + } + +/** + * @brief This class wraps all calls to NVML and ensures that the library is dynamically loaded at runtime using + * `dlopen`. This is necessary to remove the link dependency to `libnvidia-ml.so` which is a driver library. Because + * driver libraries are loaded into the docker container via the NVIDIA container runtime, we do not want to directly + * link to them. As well, if the driver is not found, we can still run MRC without GPUs. This gives us an oportunity to + * catch the missing library instead of the OS throwing an error. + * + */ +struct NvmlHandle +{ + NvmlHandle() + { + // First, try to open the library dynamically + m_nvml_dll = dlopen("libnvidia-ml.so.1", RTLD_LOCAL | RTLD_LAZY); + + // Throw an error if missing + if (m_nvml_dll == nullptr) + { + throw std::runtime_error("Could not open libnvidia-ml.so.1"); + } + + // Increment the dll counter since this was successfully loaded + s_dll_counter++; + + // Now load the symbols. Keep init first + LOAD_NVTX_SYM(m_nvml_dll, nvmlInit_v2); + + // Keep the rest of the functions sorted. Must match list of functions below! + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetCount_v2); + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetHandleByIndex_v2); + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetMemoryInfo); + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetMigMode); + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetName); + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetPciInfo_v3); + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetPowerManagementLimit); + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetPowerUsage); + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetTotalEnergyConsumption); + LOAD_NVTX_SYM(m_nvml_dll, nvmlDeviceGetUUID); + LOAD_NVTX_SYM(m_nvml_dll, nvmlErrorString); + LOAD_NVTX_SYM(m_nvml_dll, nvmlShutdown); + } + + ~NvmlHandle() + { + // Close the library on shutdown. Double check we only call dlclose when the last instance is being destroyed + if (m_nvml_dll != nullptr && --s_dll_counter == 0) + { + dlclose(m_nvml_dll); + } } -namespace { + // NOLINTBEGIN(readability-identifier-naming) + // Keep the init function up top + decltype(&::nvmlInit_v2) nvmlInit_v2{nullptr}; + + // Keep the rest of the functions sorted. Add new ones as necessary + decltype(&::nvmlDeviceGetCount_v2) nvmlDeviceGetCount_v2{nullptr}; + decltype(&::nvmlDeviceGetHandleByIndex_v2) nvmlDeviceGetHandleByIndex_v2{nullptr}; + decltype(&::nvmlDeviceGetMemoryInfo) nvmlDeviceGetMemoryInfo{nullptr}; + decltype(&::nvmlDeviceGetMigMode) nvmlDeviceGetMigMode{nullptr}; + decltype(&::nvmlDeviceGetName) nvmlDeviceGetName{nullptr}; + decltype(&::nvmlDeviceGetPciInfo_v3) nvmlDeviceGetPciInfo_v3{nullptr}; + decltype(&::nvmlDeviceGetPowerManagementLimit) nvmlDeviceGetPowerManagementLimit{nullptr}; + decltype(&::nvmlDeviceGetPowerUsage) nvmlDeviceGetPowerUsage{nullptr}; + decltype(&::nvmlDeviceGetTotalEnergyConsumption) nvmlDeviceGetTotalEnergyConsumption{nullptr}; + decltype(&::nvmlDeviceGetUUID) nvmlDeviceGetUUID{nullptr}; + decltype(&::nvmlErrorString) nvmlErrorString{nullptr}; + decltype(&::nvmlShutdown) nvmlShutdown{nullptr}; + // NOLINTEND(readability-identifier-naming) + + private: + void* m_nvml_dll{nullptr}; + + static std::atomic_int s_dll_counter; +}; + +// Init the dll counter +std::atomic_int NvmlHandle::s_dll_counter = 0; + struct NvmlState { NvmlState() { - auto nvml_status = nvmlInit_v2(); + try + { + // Try to load the NVML library. If its not found, operate without GPUs + m_nvml_handle = std::make_unique(); + } catch (std::runtime_error e) + { + LOG(WARNING) << "NVML: " << e.what() << ". Setting DeviceCount to 0, CUDA will not be initialized"; + return; + } + + // Initialize NVML. Must happen first + auto nvml_status = m_nvml_handle->nvmlInit_v2(); + if (nvml_status != NVML_SUCCESS) { - LOG(WARNING) << "NVML: Error initializing due to '" << nvmlErrorString(nvml_status) + LOG(WARNING) << "NVML: Error initializing due to '" << m_nvml_handle->nvmlErrorString(nvml_status) << "'. Setting DeviceCount to 0, CUDA will not be initialized"; return; } unsigned int visible_devices = 0; - CHECK_EQ(nvmlDeviceGetCount_v2(&visible_devices), NVML_SUCCESS); + MRC_CHECK_NVML(m_nvml_handle->nvmlDeviceGetCount_v2(&visible_devices)); for (decltype(visible_devices) i = 0; i < visible_devices; i++) { @@ -63,15 +174,15 @@ struct NvmlState unsigned int current_mig_mode; unsigned int pending_mig_mode; - auto device_status = nvmlDeviceGetHandleByIndex_v2(i, &device_handle); + auto device_status = m_nvml_handle->nvmlDeviceGetHandleByIndex_v2(i, &device_handle); if (device_status != NVML_SUCCESS) { - LOG(WARNING) << "NVML: " << nvmlErrorString(device_status) << "; device with index " << i + LOG(WARNING) << "NVML: " << m_nvml_handle->nvmlErrorString(device_status) << "; device with index " << i << " will be ignored"; continue; } - auto mig_status = nvmlDeviceGetMigMode(device_handle, ¤t_mig_mode, &pending_mig_mode); + auto mig_status = m_nvml_handle->nvmlDeviceGetMigMode(device_handle, ¤t_mig_mode, &pending_mig_mode); if (mig_status == NVML_SUCCESS && (current_mig_mode == NVML_DEVICE_MIG_ENABLE || pending_mig_mode == NVML_DEVICE_MIG_ENABLE)) { @@ -102,7 +213,15 @@ struct NvmlState } ~NvmlState() { - CHECK_EQ(nvmlShutdown(), NVML_SUCCESS) << "Failed to Shutdown NVML"; + if (m_nvml_handle) + { + MRC_CHECK_NVML(m_nvml_handle->nvmlShutdown()); + } + } + + NvmlHandle& get_handle() + { + return *m_nvml_handle; } const std::set& accessible_nvml_device_indexes() const @@ -115,12 +234,27 @@ struct NvmlState return m_using_mig; } + /** + * @brief Gets the singleton instance to NvmlState + * + * @return NvmlState& + */ static NvmlState& instance() { static NvmlState state; return state; } + /** + * @brief Static method to shorten `NvmlState::instance().get_handle()` + * + * @return NvmlHandle& + */ + static NvmlHandle& handle() + { + return NvmlState::instance().get_handle(); + } + private: // this object can also hold the list of device handles that we have access to. // - nvmlDeviceGetCount_v2 - will tell us the total number of devices we have access to, i.e. the range of [0, N) @@ -130,21 +264,19 @@ struct NvmlState std::set m_accessible_indexes; bool m_using_mig{false}; -}; -} // namespace - -namespace mrc::internal::system { + std::unique_ptr m_nvml_handle; +}; -nvmlDevice_t DeviceInfo::GetHandleById(unsigned int device_id) +nvmlDevice_t get_handle_by_id(unsigned int device_id) { nvmlDevice_t handle; - CHECK_EQ(nvmlDeviceGetHandleByIndex(device_id, &handle), NVML_SUCCESS); + MRC_CHECK_NVML(NvmlState::handle().nvmlDeviceGetHandleByIndex_v2(device_id, &handle)); return handle; } /* -cpu_set DeviceInfo::Affinity(int device_id) +cpu_set DeviceInfo::Affinity(unsigned int device_id) { nvmlDevice_t gpu = DeviceInfo::GetHandleById(device_id); unsigned long cpu_mask = 0; @@ -166,6 +298,16 @@ cpu_set DeviceInfo::Affinity(int device_id) } */ +std::size_t DeviceInfo::AccessibleDeviceCount() +{ + return NvmlState::instance().accessible_nvml_device_indexes().size(); +} + +std::set DeviceInfo::AccessibleDeviceIndexes() +{ + return NvmlState::instance().accessible_nvml_device_indexes(); +} + std::size_t DeviceInfo::Alignment() { struct cudaDeviceProp properties; @@ -173,56 +315,85 @@ std::size_t DeviceInfo::Alignment() return properties.textureAlignment; } -double DeviceInfo::PowerUsage(int device_id) +unsigned long long DeviceInfo::DeviceTotalMemory(unsigned int device_id) { - unsigned int power; - CHECK_EQ(nvmlDeviceGetPowerUsage(DeviceInfo::GetHandleById(device_id), &power), NVML_SUCCESS); - return static_cast(power) * 0.001; + nvmlMemory_t info; + MRC_CHECK_NVML(NvmlState::handle().nvmlDeviceGetMemoryInfo(get_handle_by_id(device_id), &info)); + return info.total; } -double DeviceInfo::PowerLimit(int device_id) +auto DeviceInfo::EnergyConsumption(unsigned int device_id) -> double { - unsigned int limit; - CHECK_EQ(nvmlDeviceGetPowerManagementLimit(DeviceInfo::GetHandleById(device_id), &limit), NVML_SUCCESS); - return static_cast(limit) * 0.001; + unsigned long long energy; + MRC_CHECK_NVML(NvmlState::handle().nvmlDeviceGetTotalEnergyConsumption(get_handle_by_id(device_id), &energy)); + return static_cast(energy) * 0.001; } -std::string DeviceInfo::UUID(int device_id) +// This function is taken directly from `hwloc/nvml.h` and updated to use NvmlHandle instead +auto DeviceInfo::GetDeviceCpuset(hwloc_topology_t topology, unsigned int device_id, hwloc_cpuset_t set) -> int +{ +/* If we're on Linux, use the sysfs mechanism to get the local cpus */ +#define HWLOC_NVML_DEVICE_SYSFS_PATH_MAX 128 + std::array path; + nvmlReturn_t nvres; + nvmlPciInfo_t pci; + + if (hwloc_topology_is_thissystem(topology) == 0) + { + errno = EINVAL; + return -1; + } + + nvres = NvmlState::handle().nvmlDeviceGetPciInfo_v3(get_handle_by_id(device_id), &pci); + if (NVML_SUCCESS != nvres) + { + errno = EINVAL; + return -1; + } + + sprintf(path.data(), "/sys/bus/pci/devices/%04x:%02x:%02x.0/local_cpus", pci.domain, pci.bus, pci.device); + + if (hwloc_linux_read_path_as_cpumask(path.data(), set) < 0 || (hwloc_bitmap_iszero(set) != 0)) + { + hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology)); + } + + return 0; +} + +std::string DeviceInfo::Name(unsigned int device_id) { std::array buffer; - CHECK_EQ(nvmlDeviceGetUUID(DeviceInfo::GetHandleById(device_id), buffer.data(), 256), NVML_SUCCESS); + MRC_CHECK_NVML(NvmlState::handle().nvmlDeviceGetName(get_handle_by_id(device_id), buffer.data(), 256)); return buffer.data(); } -std::string DeviceInfo::PCIeBusID(int device_id) +std::string DeviceInfo::PCIeBusID(unsigned int device_id) { nvmlPciInfo_t info; - CHECK_EQ(nvmlDeviceGetPciInfo_v3(DeviceInfo::GetHandleById(device_id), &info), NVML_SUCCESS); + MRC_CHECK_NVML(NvmlState::handle().nvmlDeviceGetPciInfo_v3(get_handle_by_id(device_id), &info)); return info.busId; } -std::size_t DeviceInfo::AccessibleDevices() -{ - return NvmlState::instance().accessible_nvml_device_indexes().size(); -} - -std::set DeviceInfo::AccessibleDeviceIndexes() +double DeviceInfo::PowerLimit(unsigned int device_id) { - return NvmlState::instance().accessible_nvml_device_indexes(); + unsigned int limit; + MRC_CHECK_NVML(NvmlState::handle().nvmlDeviceGetPowerManagementLimit(get_handle_by_id(device_id), &limit)); + return static_cast(limit) * 0.001; } -nvmlMemory_t DeviceInfo::MemoryInfo(int device_id) +double DeviceInfo::PowerUsage(unsigned int device_id) { - nvmlMemory_t info; - MRC_CHECK_NVML(nvmlDeviceGetMemoryInfo(DeviceInfo::GetHandleById(device_id), &info)); - return info; + unsigned int power; + MRC_CHECK_NVML(NvmlState::handle().nvmlDeviceGetPowerUsage(get_handle_by_id(device_id), &power)); + return static_cast(power) * 0.001; } -std::string DeviceInfo::Name(int device_id) +std::string DeviceInfo::UUID(unsigned int device_id) { std::array buffer; - CHECK_EQ(nvmlDeviceGetName(DeviceInfo::GetHandleById(device_id), buffer.data(), 256), NVML_SUCCESS); + MRC_CHECK_NVML(NvmlState::handle().nvmlDeviceGetUUID(get_handle_by_id(device_id), buffer.data(), 256)); 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 4df6b0cc3..ce73031bc 100644 --- a/cpp/mrc/src/internal/system/device_info.hpp +++ b/cpp/mrc/src/internal/system/device_info.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -17,28 +17,35 @@ #pragma once -#include - #include #include #include -namespace mrc::internal::system { +// DO NOT INCLUDE !!!! + +// NOLINTBEGIN(readability-identifier-naming) +using hwloc_cpuset_t = struct hwloc_bitmap_s*; +using hwloc_topology_t = struct hwloc_topology*; +using nvmlDevice_t = struct nvmlDevice_st*; +// NOLINTEND(readability-identifier-naming) + +namespace mrc::system { struct DeviceInfo { - static nvmlDevice_t GetHandleById(unsigned int device_id); // NOLINT - // static auto Affinity(int device_id) -> cpu_set; - static auto Alignment() -> std::size_t; // NOLINT - static auto EnergyConsumption(int device_id) -> double; // NOLINT - static auto MemoryInfo(int device_id) -> nvmlMemory_t; // NOLINT - static auto PowerUsage(int device_id) -> double; // NOLINT - static auto PowerLimit(int device_id) -> double; // NOLINT - static auto UUID(int device_id) -> std::string; // NOLINT - static auto PCIeBusID(int device_id) -> std::string; // NOLINT - static auto Name(int) -> std::string; // NOLINT - static auto AccessibleDeviceIndexes() -> std::set; // NOLINT - static auto AccessibleDevices() -> std::size_t; // NOLINT + // NOLINTBEGIN(readability-identifier-naming) + static auto AccessibleDeviceCount() -> std::size_t; + static auto AccessibleDeviceIndexes() -> std::set; + static auto Alignment() -> std::size_t; + static auto DeviceTotalMemory(unsigned int device_id) -> unsigned long long; + static auto EnergyConsumption(unsigned int device_id) -> double; + static auto GetDeviceCpuset(hwloc_topology_t topology, unsigned int device_id, hwloc_cpuset_t set) -> int; + static auto Name(unsigned int device_id) -> std::string; + static auto PCIeBusID(unsigned int device_id) -> std::string; + static auto PowerLimit(unsigned int device_id) -> double; + static auto PowerUsage(unsigned int device_id) -> double; + static auto UUID(unsigned int device_id) -> std::string; + // 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 fb7ae5c55..75860c784 100644 --- a/cpp/mrc/src/internal/system/device_partition.cpp +++ b/cpp/mrc/src/internal/system/device_partition.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 5c38c3949..2cc7209fc 100644 --- a/cpp/mrc/src/internal/system/device_partition.hpp +++ b/cpp/mrc/src/internal/system/device_partition.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 84698a176..11a3234c8 100644 --- a/cpp/mrc/src/internal/system/engine_factory_cpu_sets.cpp +++ b/cpp/mrc/src/internal/system/engine_factory_cpu_sets.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d603a72d1..2dd300389 100644 --- a/cpp/mrc/src/internal/system/engine_factory_cpu_sets.hpp +++ b/cpp/mrc/src/internal/system/engine_factory_cpu_sets.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 844f2176a..2eec52f12 100644 --- a/cpp/mrc/src/internal/system/fiber_manager.cpp +++ b/cpp/mrc/src/internal/system/fiber_manager.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d147cb173..09e055c56 100644 --- a/cpp/mrc/src/internal/system/fiber_manager.hpp +++ b/cpp/mrc/src/internal/system/fiber_manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d2e6e2fc9..256acb923 100644 --- a/cpp/mrc/src/internal/system/fiber_pool.cpp +++ b/cpp/mrc/src/internal/system/fiber_pool.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 04fd5f73f..857401bb7 100644 --- a/cpp/mrc/src/internal/system/fiber_pool.hpp +++ b/cpp/mrc/src/internal/system/fiber_pool.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 cc8c54947..8753acedf 100644 --- a/cpp/mrc/src/internal/system/fiber_priority_scheduler.hpp +++ b/cpp/mrc/src/internal/system/fiber_priority_scheduler.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 3731d9758..709be264e 100644 --- a/cpp/mrc/src/internal/system/fiber_task_queue.cpp +++ b/cpp/mrc/src/internal/system/fiber_task_queue.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 188bf128a..c58c8190b 100644 --- a/cpp/mrc/src/internal/system/fiber_task_queue.hpp +++ b/cpp/mrc/src/internal/system/fiber_task_queue.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 154237af5..c3e938415 100644 --- a/cpp/mrc/src/internal/system/forward.hpp +++ b/cpp/mrc/src/internal/system/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 21a63496a..0c8c15a23 100644 --- a/cpp/mrc/src/internal/system/gpu_info.cpp +++ b/cpp/mrc/src/internal/system/gpu_info.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 f6b80e764..396912ca3 100644 --- a/cpp/mrc/src/internal/system/gpu_info.hpp +++ b/cpp/mrc/src/internal/system/gpu_info.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 bdd3029b8..b27f3f7d1 100644 --- a/cpp/mrc/src/internal/system/host_partition.cpp +++ b/cpp/mrc/src/internal/system/host_partition.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b44d05c4f..222cb925f 100644 --- a/cpp/mrc/src/internal/system/host_partition.hpp +++ b/cpp/mrc/src/internal/system/host_partition.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 e6c977f72..953833435 100644 --- a/cpp/mrc/src/internal/system/host_partition_provider.cpp +++ b/cpp/mrc/src/internal/system/host_partition_provider.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 7bf786021..c66eb1665 100644 --- a/cpp/mrc/src/internal/system/host_partition_provider.hpp +++ b/cpp/mrc/src/internal/system/host_partition_provider.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 fc299d6db..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 ab91a3dee..c78e07224 100644 --- a/cpp/mrc/src/internal/system/partition.cpp +++ b/cpp/mrc/src/internal/system/partition.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 fe20b54cd..b64358ecd 100644 --- a/cpp/mrc/src/internal/system/partition.hpp +++ b/cpp/mrc/src/internal/system/partition.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 2c63b5a60..33feb2c77 100644 --- a/cpp/mrc/src/internal/system/partition_provider.cpp +++ b/cpp/mrc/src/internal/system/partition_provider.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d310a9832..88fef21ba 100644 --- a/cpp/mrc/src/internal/system/partition_provider.hpp +++ b/cpp/mrc/src/internal/system/partition_provider.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c21420ee6..01fbeacca 100644 --- a/cpp/mrc/src/internal/system/partitions.cpp +++ b/cpp/mrc/src/internal/system/partitions.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 6cf03b2bb..82dd80af7 100644 --- a/cpp/mrc/src/internal/system/partitions.hpp +++ b/cpp/mrc/src/internal/system/partitions.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 39029de4e..175505126 100644 --- a/cpp/mrc/src/internal/system/system.cpp +++ b/cpp/mrc/src/internal/system/system.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 1c3fdcf64..649dbf63d 100644 --- a/cpp/mrc/src/internal/system/system.hpp +++ b/cpp/mrc/src/internal/system/system.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 4e6453d85..4416cf4e4 100644 --- a/cpp/mrc/src/internal/system/system_provider.cpp +++ b/cpp/mrc/src/internal/system/system_provider.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 e49145cdb..d90d09e2c 100644 --- a/cpp/mrc/src/internal/system/system_provider.hpp +++ b/cpp/mrc/src/internal/system/system_provider.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 780f42ef9..413e86f6c 100644 --- a/cpp/mrc/src/internal/system/thread.cpp +++ b/cpp/mrc/src/internal/system/thread.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 e33fef0eb..aa8669da0 100644 --- a/cpp/mrc/src/internal/system/thread.hpp +++ b/cpp/mrc/src/internal/system/thread.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 21a0491e3..f3ff7814f 100644 --- a/cpp/mrc/src/internal/system/thread_pool.cpp +++ b/cpp/mrc/src/internal/system/thread_pool.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 8854921f9..9c0b45745 100644 --- a/cpp/mrc/src/internal/system/thread_pool.hpp +++ b/cpp/mrc/src/internal/system/thread_pool.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 e9a620a1f..27001092a 100644 --- a/cpp/mrc/src/internal/system/resources.cpp +++ b/cpp/mrc/src/internal/system/threading_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b1724ccd0..d92788cd9 100644 --- a/cpp/mrc/src/internal/system/resources.hpp +++ b/cpp/mrc/src/internal/system/threading_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 59f5b2a90..b43008bde 100644 --- a/cpp/mrc/src/internal/system/topology.cpp +++ b/cpp/mrc/src/internal/system/topology.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -29,8 +29,6 @@ #include #include #include -#include -#include #include #include @@ -45,7 +43,7 @@ // Topology -namespace mrc::internal::system { +namespace mrc::system { std::shared_ptr Topology::Create() { @@ -81,13 +79,12 @@ std::shared_ptr Topology::Create(const TopologyOptions& options) { GpuInfo info; - auto* device = DeviceInfo::GetHandleById(i); info.m_name = DeviceInfo::Name(i); info.m_uuid = DeviceInfo::UUID(i); info.m_pcie_bus_id = DeviceInfo::PCIeBusID(i); - info.m_memory_capacity = DeviceInfo::MemoryInfo(i).total; - auto rc = hwloc_nvml_get_device_cpuset(system_topology, device, &info.m_cpu_set.bitmap()); - CHECK_EQ(rc, 0); + info.m_memory_capacity = DeviceInfo::DeviceTotalMemory(i); + CHECK_EQ(DeviceInfo::GetDeviceCpuset(system_topology, i, &info.m_cpu_set.bitmap()), 0) << "Invalid GPU device " + "CPU set"; auto v = info.cpu_set().vec(); info.m_cpustr = print_ranges(find_ranges(v)); @@ -387,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 15386c535..11dfd1295 100644 --- a/cpp/mrc/src/internal/system/topology.hpp +++ b/cpp/mrc/src/internal/system/topology.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/all.hpp b/cpp/mrc/src/internal/ucx/all.hpp index 554b21836..fa00e32cf 100644 --- a/cpp/mrc/src/internal/ucx/all.hpp +++ b/cpp/mrc/src/internal/ucx/all.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/ucx/common.hpp b/cpp/mrc/src/internal/ucx/common.hpp index 0a5a95b24..737e05ebf 100644 --- a/cpp/mrc/src/internal/ucx/common.hpp +++ b/cpp/mrc/src/internal/ucx/common.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 48372f3d4..69c323280 100644 --- a/cpp/mrc/src/internal/ucx/context.cpp +++ b/cpp/mrc/src/internal/ucx/context.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 786a9068d..90fbc0e30 100644 --- a/cpp/mrc/src/internal/ucx/context.hpp +++ b/cpp/mrc/src/internal/ucx/context.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 aa50225be..acda3afed 100644 --- a/cpp/mrc/src/internal/ucx/endpoint.cpp +++ b/cpp/mrc/src/internal/ucx/endpoint.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d8c591ea3..389387ba8 100644 --- a/cpp/mrc/src/internal/ucx/endpoint.hpp +++ b/cpp/mrc/src/internal/ucx/endpoint.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 8d9cb22d2..4fe9ccb46 100644 --- a/cpp/mrc/src/internal/ucx/forward.hpp +++ b/cpp/mrc/src/internal/ucx/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 7bad4ee3c..f6d44538c 100644 --- a/cpp/mrc/src/internal/ucx/memory_block.cpp +++ b/cpp/mrc/src/internal/ucx/memory_block.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 cc871383d..0d0e8670e 100644 --- a/cpp/mrc/src/internal/ucx/memory_block.hpp +++ b/cpp/mrc/src/internal/ucx/memory_block.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 0593ab848..529e62607 100644 --- a/cpp/mrc/src/internal/ucx/primitive.hpp +++ b/cpp/mrc/src/internal/ucx/primitive.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 765611b85..2796bf84e 100644 --- a/cpp/mrc/src/internal/ucx/receive_manager.cpp +++ b/cpp/mrc/src/internal/ucx/receive_manager.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 b073e1b77..0e81f766a 100644 --- a/cpp/mrc/src/internal/ucx/receive_manager.hpp +++ b/cpp/mrc/src/internal/ucx/receive_manager.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 da63be1b1..29393cf40 100644 --- a/cpp/mrc/src/internal/ucx/registration_cache.hpp +++ b/cpp/mrc/src/internal/ucx/registration_cache.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 52eafb2da..a0b04ead7 100644 --- a/cpp/mrc/src/internal/ucx/registration_resource.hpp +++ b/cpp/mrc/src/internal/ucx/registration_resource.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 cd47ffa36..771e3f065 100644 --- a/cpp/mrc/src/internal/ucx/remote_registration_cache.hpp +++ b/cpp/mrc/src/internal/ucx/remote_registration_cache.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 4a33bc43b..88aa3e877 100644 --- a/cpp/mrc/src/internal/ucx/ucx.hpp +++ b/cpp/mrc/src/internal/ucx/ucx.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 827d7a257..48c70f0fa 100644 --- a/cpp/mrc/src/internal/ucx/ucx_fwd.hpp +++ b/cpp/mrc/src/internal/ucx/ucx_fwd.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d17d71daa..458dd9814 100644 --- a/cpp/mrc/src/internal/ucx/resources.cpp +++ b/cpp/mrc/src/internal/ucx/ucx_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 1b9a5622e..122e690bd 100644 --- a/cpp/mrc/src/internal/ucx/resources.hpp +++ b/cpp/mrc/src/internal/ucx/ucx_resources.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 a53505e46..af14540c1 100644 --- a/cpp/mrc/src/internal/ucx/utils.hpp +++ b/cpp/mrc/src/internal/ucx/utils.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c22100e9e..1bbef1c2f 100644 --- a/cpp/mrc/src/internal/ucx/worker.cpp +++ b/cpp/mrc/src/internal/ucx/worker.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d551f8f18..4306807e1 100644 --- a/cpp/mrc/src/internal/ucx/worker.hpp +++ b/cpp/mrc/src/internal/ucx/worker.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 03be78d6b..6e6d46a4d 100644 --- a/cpp/mrc/src/internal/utils/collision_detector.cpp +++ b/cpp/mrc/src/internal/utils/collision_detector.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 f21fcd157..bf6c7a6ba 100644 --- a/cpp/mrc/src/internal/utils/collision_detector.hpp +++ b/cpp/mrc/src/internal/utils/collision_detector.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/contains.hpp b/cpp/mrc/src/internal/utils/contains.hpp index 57af2c852..61d613692 100644 --- a/cpp/mrc/src/internal/utils/contains.hpp +++ b/cpp/mrc/src/internal/utils/contains.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/utils/exception_guard.cpp b/cpp/mrc/src/internal/utils/exception_guard.cpp index 789bd9f5e..4ab6b21d7 100644 --- a/cpp/mrc/src/internal/utils/exception_guard.cpp +++ b/cpp/mrc/src/internal/utils/exception_guard.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 6a8b12974..03d65315a 100644 --- a/cpp/mrc/src/internal/utils/exception_guard.hpp +++ b/cpp/mrc/src/internal/utils/exception_guard.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/internal/utils/parse_config.cpp b/cpp/mrc/src/internal/utils/parse_config.cpp index d3579fceb..7d49ce615 100644 --- a/cpp/mrc/src/internal/utils/parse_config.cpp +++ b/cpp/mrc/src/internal/utils/parse_config.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/utils/parse_config.hpp b/cpp/mrc/src/internal/utils/parse_config.hpp index 9a7b0158b..d9efc39bd 100644 --- a/cpp/mrc/src/internal/utils/parse_config.hpp +++ b/cpp/mrc/src/internal/utils/parse_config.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/utils/parse_ints.cpp b/cpp/mrc/src/internal/utils/parse_ints.cpp index fc84ed650..60c716982 100644 --- a/cpp/mrc/src/internal/utils/parse_ints.cpp +++ b/cpp/mrc/src/internal/utils/parse_ints.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/utils/parse_ints.hpp b/cpp/mrc/src/internal/utils/parse_ints.hpp index 75a5d7d36..fc8ec081b 100644 --- a/cpp/mrc/src/internal/utils/parse_ints.hpp +++ b/cpp/mrc/src/internal/utils/parse_ints.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/utils/ranges.hpp b/cpp/mrc/src/internal/utils/ranges.hpp index 837f3efa3..826aee87a 100644 --- a/cpp/mrc/src/internal/utils/ranges.hpp +++ b/cpp/mrc/src/internal/utils/ranges.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/utils/shared_resource_bit_map.cpp b/cpp/mrc/src/internal/utils/shared_resource_bit_map.cpp index dcb71a8c2..97b4cbd1f 100644 --- a/cpp/mrc/src/internal/utils/shared_resource_bit_map.cpp +++ b/cpp/mrc/src/internal/utils/shared_resource_bit_map.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/internal/utils/shared_resource_bit_map.hpp b/cpp/mrc/src/internal/utils/shared_resource_bit_map.hpp index beb068287..4376c92f8 100644 --- a/cpp/mrc/src/internal/utils/shared_resource_bit_map.hpp +++ b/cpp/mrc/src/internal/utils/shared_resource_bit_map.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/benchmarking/trace_statistics.cpp b/cpp/mrc/src/public/benchmarking/trace_statistics.cpp index 4efb84c4b..bf95752e0 100644 --- a/cpp/mrc/src/public/benchmarking/trace_statistics.cpp +++ b/cpp/mrc/src/public/benchmarking/trace_statistics.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/benchmarking/tracer.cpp b/cpp/mrc/src/public/benchmarking/tracer.cpp index ac5d02191..1e3a942b4 100644 --- a/cpp/mrc/src/public/benchmarking/tracer.cpp +++ b/cpp/mrc/src/public/benchmarking/tracer.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/benchmarking/util.cpp b/cpp/mrc/src/public/benchmarking/util.cpp index 6802d91da..c39676716 100644 --- a/cpp/mrc/src/public/benchmarking/util.cpp +++ b/cpp/mrc/src/public/benchmarking/util.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/channel/channel.cpp b/cpp/mrc/src/public/channel/channel.cpp index 03ef8fdbc..8a2c2fc7b 100644 --- a/cpp/mrc/src/public/channel/channel.cpp +++ b/cpp/mrc/src/public/channel/channel.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/codable/encoded_object.cpp b/cpp/mrc/src/public/codable/encoded_object.cpp index 7591829fd..c371b07e2 100644 --- a/cpp/mrc/src/public/codable/encoded_object.cpp +++ b/cpp/mrc/src/public/codable/encoded_object.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/codable/memory.cpp b/cpp/mrc/src/public/codable/memory.cpp index a5fe5c640..734ccbbb1 100644 --- a/cpp/mrc/src/public/codable/memory.cpp +++ b/cpp/mrc/src/public/codable/memory.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/core/addresses.cpp b/cpp/mrc/src/public/core/addresses.cpp index be82067b4..1d2eb0d6a 100644 --- a/cpp/mrc/src/public/core/addresses.cpp +++ b/cpp/mrc/src/public/core/addresses.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/core/bitmap.cpp b/cpp/mrc/src/public/core/bitmap.cpp index 67dfa07fd..1dd51f2a6 100644 --- a/cpp/mrc/src/public/core/bitmap.cpp +++ b/cpp/mrc/src/public/core/bitmap.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/core/executor.cpp b/cpp/mrc/src/public/core/executor.cpp deleted file mode 100644 index 6bc074c84..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/core/fiber_pool.cpp b/cpp/mrc/src/public/core/fiber_pool.cpp index 3d23a3035..4e199ea7c 100644 --- a/cpp/mrc/src/public/core/fiber_pool.cpp +++ b/cpp/mrc/src/public/core/fiber_pool.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/core/logging.cpp b/cpp/mrc/src/public/core/logging.cpp index 69553191d..a8813277e 100644 --- a/cpp/mrc/src/public/core/logging.cpp +++ b/cpp/mrc/src/public/core/logging.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/core/thread.cpp b/cpp/mrc/src/public/core/thread.cpp index 45f06bfa0..0553a8fe0 100644 --- a/cpp/mrc/src/public/core/thread.cpp +++ b/cpp/mrc/src/public/core/thread.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/coroutines/event.cpp b/cpp/mrc/src/public/coroutines/event.cpp index 8e82e0e98..b191cf103 100644 --- a/cpp/mrc/src/public/coroutines/event.cpp +++ b/cpp/mrc/src/public/coroutines/event.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/coroutines/sync_wait.cpp b/cpp/mrc/src/public/coroutines/sync_wait.cpp index a9c010b32..5df18bc6a 100644 --- a/cpp/mrc/src/public/coroutines/sync_wait.cpp +++ b/cpp/mrc/src/public/coroutines/sync_wait.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/coroutines/thread_local_context.cpp b/cpp/mrc/src/public/coroutines/thread_local_context.cpp index e42f6c9f6..d16429fd3 100644 --- a/cpp/mrc/src/public/coroutines/thread_local_context.cpp +++ b/cpp/mrc/src/public/coroutines/thread_local_context.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/coroutines/thread_pool.cpp b/cpp/mrc/src/public/coroutines/thread_pool.cpp index 39b74b894..e2724409e 100644 --- a/cpp/mrc/src/public/coroutines/thread_pool.cpp +++ b/cpp/mrc/src/public/coroutines/thread_pool.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/cuda/device_guard.cpp b/cpp/mrc/src/public/cuda/device_guard.cpp index 7c695282c..5661c724e 100644 --- a/cpp/mrc/src/public/cuda/device_guard.cpp +++ b/cpp/mrc/src/public/cuda/device_guard.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/cuda/sync.cpp b/cpp/mrc/src/public/cuda/sync.cpp index 3c8767cea..0702b3584 100644 --- a/cpp/mrc/src/public/cuda/sync.cpp +++ b/cpp/mrc/src/public/cuda/sync.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/edge/edge_adapter_registry.cpp b/cpp/mrc/src/public/edge/edge_adapter_registry.cpp index 1da345330..73ae161dc 100644 --- a/cpp/mrc/src/public/edge/edge_adapter_registry.cpp +++ b/cpp/mrc/src/public/edge/edge_adapter_registry.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/edge/edge_builder.cpp b/cpp/mrc/src/public/edge/edge_builder.cpp index aae61e24a..ff21e9a4a 100644 --- a/cpp/mrc/src/public/edge/edge_builder.cpp +++ b/cpp/mrc/src/public/edge/edge_builder.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/manifold/manifold.cpp b/cpp/mrc/src/public/manifold/manifold.cpp index a19bc9110..a1a3cca25 100644 --- a/cpp/mrc/src/public/manifold/manifold.cpp +++ b/cpp/mrc/src/public/manifold/manifold.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/memory/buffer_view.cpp b/cpp/mrc/src/public/memory/buffer_view.cpp index 8812abcaf..3c90b3bcd 100644 --- a/cpp/mrc/src/public/memory/buffer_view.cpp +++ b/cpp/mrc/src/public/memory/buffer_view.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/memory/codable/buffer.cpp b/cpp/mrc/src/public/memory/codable/buffer.cpp index bf860cef5..0433d2f94 100644 --- a/cpp/mrc/src/public/memory/codable/buffer.cpp +++ b/cpp/mrc/src/public/memory/codable/buffer.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/metrics/counter.cpp b/cpp/mrc/src/public/metrics/counter.cpp index 24b0bba0e..34a83a191 100644 --- a/cpp/mrc/src/public/metrics/counter.cpp +++ b/cpp/mrc/src/public/metrics/counter.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/metrics/registry.cpp b/cpp/mrc/src/public/metrics/registry.cpp index 69ae15c4a..610da6896 100644 --- a/cpp/mrc/src/public/metrics/registry.cpp +++ b/cpp/mrc/src/public/metrics/registry.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/modules/module_registry.cpp b/cpp/mrc/src/public/modules/module_registry.cpp index e922c5d4a..b6d23c2de 100644 --- a/cpp/mrc/src/public/modules/module_registry.cpp +++ b/cpp/mrc/src/public/modules/module_registry.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/modules/plugins.cpp b/cpp/mrc/src/public/modules/plugins.cpp index e547e5232..0f93f435f 100644 --- a/cpp/mrc/src/public/modules/plugins.cpp +++ b/cpp/mrc/src/public/modules/plugins.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 0fe56ed9a..fe850615c 100644 --- a/cpp/mrc/src/public/modules/sample_modules.cpp +++ b/cpp/mrc/src/public/modules/sample_modules.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c4160608e..fb37d52eb 100644 --- a/cpp/mrc/src/public/modules/segment_modules.cpp +++ b/cpp/mrc/src/public/modules/segment_modules.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/node/port_registry.cpp b/cpp/mrc/src/public/node/port_registry.cpp index e3d23269b..67f6da3c5 100644 --- a/cpp/mrc/src/public/node/port_registry.cpp +++ b/cpp/mrc/src/public/node/port_registry.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/options/engine_groups.cpp b/cpp/mrc/src/public/options/engine_groups.cpp index c96b3a5e8..bc1b29abc 100644 --- a/cpp/mrc/src/public/options/engine_groups.cpp +++ b/cpp/mrc/src/public/options/engine_groups.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/options/fiber_pool.cpp b/cpp/mrc/src/public/options/fiber_pool.cpp index 99ee5d389..1af8e520b 100644 --- a/cpp/mrc/src/public/options/fiber_pool.cpp +++ b/cpp/mrc/src/public/options/fiber_pool.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/options/options.cpp b/cpp/mrc/src/public/options/options.cpp index a55a51ff2..6a74eca28 100644 --- a/cpp/mrc/src/public/options/options.cpp +++ b/cpp/mrc/src/public/options/options.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/options/placement.cpp b/cpp/mrc/src/public/options/placement.cpp index 83c4dfdcb..e3a392d69 100644 --- a/cpp/mrc/src/public/options/placement.cpp +++ b/cpp/mrc/src/public/options/placement.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/options/resources.cpp b/cpp/mrc/src/public/options/resources.cpp index 745e445bf..d7119a972 100644 --- a/cpp/mrc/src/public/options/resources.cpp +++ b/cpp/mrc/src/public/options/resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/options/services.cpp b/cpp/mrc/src/public/options/services.cpp index 368689c0b..738031a53 100644 --- a/cpp/mrc/src/public/options/services.cpp +++ b/cpp/mrc/src/public/options/services.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/options/topology.cpp b/cpp/mrc/src/public/options/topology.cpp index 8e8e70382..770e8a232 100644 --- a/cpp/mrc/src/public/options/topology.cpp +++ b/cpp/mrc/src/public/options/topology.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 609347242..465871084 100644 --- a/cpp/mrc/src/public/pipeline/pipeline.cpp +++ b/cpp/mrc/src/public/pipeline/pipeline.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 9ec2c8c81..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/context.cpp b/cpp/mrc/src/public/runnable/context.cpp index bd4aba3c9..8e1aa510e 100644 --- a/cpp/mrc/src/public/runnable/context.cpp +++ b/cpp/mrc/src/public/runnable/context.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/runnable/launcher.cpp b/cpp/mrc/src/public/runnable/launcher.cpp index c1131349e..0f8ac43ba 100644 --- a/cpp/mrc/src/public/runnable/launcher.cpp +++ b/cpp/mrc/src/public/runnable/launcher.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/runnable.cpp b/cpp/mrc/src/public/runnable/runnable.cpp index b7dc8fc22..58c6cbc2f 100644 --- a/cpp/mrc/src/public/runnable/runnable.cpp +++ b/cpp/mrc/src/public/runnable/runnable.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/runnable/runner.cpp b/cpp/mrc/src/public/runnable/runner.cpp index f06e09f41..5545fa628 100644 --- a/cpp/mrc/src/public/runnable/runner.cpp +++ b/cpp/mrc/src/public/runnable/runner.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/runnable/types.cpp b/cpp/mrc/src/public/runnable/types.cpp index d34b8ac6f..e46e01ebe 100644 --- a/cpp/mrc/src/public/runnable/types.cpp +++ b/cpp/mrc/src/public/runnable/types.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/runtime/remote_descriptor.cpp b/cpp/mrc/src/public/runtime/remote_descriptor.cpp index 891819a0f..f27db18e9 100644 --- a/cpp/mrc/src/public/runtime/remote_descriptor.cpp +++ b/cpp/mrc/src/public/runtime/remote_descriptor.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/segment/builder.cpp b/cpp/mrc/src/public/segment/builder.cpp deleted file mode 100644 index 3d3460be8..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); - ns_pop(); - - // 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 -> '" << smodule->component_prefix() << "'"; - m_backend.add_module(m_namespace_prefix, smodule); - } -} - -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 63eaae5b8..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/public/utils/bytes_to_string.cpp b/cpp/mrc/src/public/utils/bytes_to_string.cpp index 3ee095cb6..0b136ef27 100644 --- a/cpp/mrc/src/public/utils/bytes_to_string.cpp +++ b/cpp/mrc/src/public/utils/bytes_to_string.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/utils/thread_utils.cpp b/cpp/mrc/src/public/utils/thread_utils.cpp index a594032e2..4ba1c913b 100644 --- a/cpp/mrc/src/public/utils/thread_utils.cpp +++ b/cpp/mrc/src/public/utils/thread_utils.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/utils/thread_utils.hpp b/cpp/mrc/src/public/utils/thread_utils.hpp index b5fec41ec..eaf338ab5 100644 --- a/cpp/mrc/src/public/utils/thread_utils.hpp +++ b/cpp/mrc/src/public/utils/thread_utils.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/public/utils/type_utils.cpp b/cpp/mrc/src/public/utils/type_utils.cpp index 974a026a0..52fcd057f 100644 --- a/cpp/mrc/src/public/utils/type_utils.cpp +++ b/cpp/mrc/src/public/utils/type_utils.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/tests/common.cpp b/cpp/mrc/src/tests/common.cpp index 91fdb13ae..6e4d915bb 100644 --- a/cpp/mrc/src/tests/common.cpp +++ b/cpp/mrc/src/tests/common.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 9b057f525..3c0825e6d 100644 --- a/cpp/mrc/src/tests/common.hpp +++ b/cpp/mrc/src/tests/common.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/nodes/common_nodes.cpp b/cpp/mrc/src/tests/nodes/common_nodes.cpp index 02cdf928c..f7432f670 100644 --- a/cpp/mrc/src/tests/nodes/common_nodes.cpp +++ b/cpp/mrc/src/tests/nodes/common_nodes.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/tests/nodes/common_nodes.hpp b/cpp/mrc/src/tests/nodes/common_nodes.hpp index 29ecee094..aa1ff13d2 100644 --- a/cpp/mrc/src/tests/nodes/common_nodes.hpp +++ b/cpp/mrc/src/tests/nodes/common_nodes.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/tests/pipelines/common_pipelines.hpp b/cpp/mrc/src/tests/pipelines/common_pipelines.hpp index 82b8b142d..0ef8d88cd 100644 --- a/cpp/mrc/src/tests/pipelines/common_pipelines.hpp +++ b/cpp/mrc/src/tests/pipelines/common_pipelines.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 78b6bad5e..5157ef5d6 100644 --- a/cpp/mrc/src/tests/pipelines/multi_segment.cpp +++ b/cpp/mrc/src/tests/pipelines/multi_segment.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 8d9a7e0ab..2a986ecb1 100644 --- a/cpp/mrc/src/tests/pipelines/single_segment.cpp +++ b/cpp/mrc/src/tests/pipelines/single_segment.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 943f640db..9e0f6b61d 100644 --- a/cpp/mrc/src/tests/segments/common_segments.cpp +++ b/cpp/mrc/src/tests/segments/common_segments.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 96ed0dadf..164b7327e 100644 --- a/cpp/mrc/src/tests/segments/common_segments.hpp +++ b/cpp/mrc/src/tests/segments/common_segments.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 cdc28c380..36cf16f2e 100644 --- a/cpp/mrc/src/tests/test_codable.cpp +++ b/cpp/mrc/src/tests/test_codable.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 69c3587c1..96d85945c 100644 --- a/cpp/mrc/src/tests/test_control_plane.cpp +++ b/cpp/mrc/src/tests/test_control_plane.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c0f42d12f..bccd39690 100644 --- a/cpp/mrc/src/tests/test_control_plane_components.cpp +++ b/cpp/mrc/src/tests/test_control_plane_components.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_expected.cpp b/cpp/mrc/src/tests/test_expected.cpp index 1de9a1f49..8488184aa 100644 --- a/cpp/mrc/src/tests/test_expected.cpp +++ b/cpp/mrc/src/tests/test_expected.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/tests/test_grpc.cpp b/cpp/mrc/src/tests/test_grpc.cpp index 9ef755c4b..68acc2913 100644 --- a/cpp/mrc/src/tests/test_grpc.cpp +++ b/cpp/mrc/src/tests/test_grpc.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_main.cpp b/cpp/mrc/src/tests/test_main.cpp index 9849c2436..742106503 100644 --- a/cpp/mrc/src/tests/test_main.cpp +++ b/cpp/mrc/src/tests/test_main.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/tests/test_memory.cpp b/cpp/mrc/src/tests/test_memory.cpp index cfa3bf051..2544827d3 100644 --- a/cpp/mrc/src/tests/test_memory.cpp +++ b/cpp/mrc/src/tests/test_memory.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 e957472da..1a14cebf4 100644 --- a/cpp/mrc/src/tests/test_network.cpp +++ b/cpp/mrc/src/tests/test_network.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 317152129..da54e0a3f 100644 --- a/cpp/mrc/src/tests/test_next.cpp +++ b/cpp/mrc/src/tests/test_next.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d01af1e6b..99107f042 100644 --- a/cpp/mrc/src/tests/test_partitions.cpp +++ b/cpp/mrc/src/tests/test_partitions.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 7dee25c8a..1b6e9c85f 100644 --- a/cpp/mrc/src/tests/test_pipeline.cpp +++ b/cpp/mrc/src/tests/test_pipeline.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_ranges.cpp b/cpp/mrc/src/tests/test_ranges.cpp index 415c9a2d8..475cd13e3 100644 --- a/cpp/mrc/src/tests/test_ranges.cpp +++ b/cpp/mrc/src/tests/test_ranges.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/tests/test_remote_descriptor.cpp b/cpp/mrc/src/tests/test_remote_descriptor.cpp index ce87020df..df4468897 100644 --- a/cpp/mrc/src/tests/test_remote_descriptor.cpp +++ b/cpp/mrc/src/tests/test_remote_descriptor.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 bde91cc85..b6b4c953f 100644 --- a/cpp/mrc/src/tests/test_resources.cpp +++ b/cpp/mrc/src/tests/test_resources.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_reusable_pool.cpp b/cpp/mrc/src/tests/test_reusable_pool.cpp index 329ad1f5f..7a8dbc7d6 100644 --- a/cpp/mrc/src/tests/test_reusable_pool.cpp +++ b/cpp/mrc/src/tests/test_reusable_pool.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/src/tests/test_runnable.cpp b/cpp/mrc/src/tests/test_runnable.cpp index 03abe9c8a..c5bc0a048 100644 --- a/cpp/mrc/src/tests/test_runnable.cpp +++ b/cpp/mrc/src/tests/test_runnable.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 2ec2486a5..3118d8b69 100644 --- a/cpp/mrc/src/tests/test_system.cpp +++ b/cpp/mrc/src/tests/test_system.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 fa513c12e..9a0095798 100644 --- a/cpp/mrc/src/tests/test_topology.cpp +++ b/cpp/mrc/src/tests/test_topology.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -98,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); @@ -114,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) @@ -127,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,10 +141,8 @@ TEST_F(TestTopology, HwlocDev) hwloc_topology_t topology; hwloc_topology_init(&topology); - auto* device = internal::system::DeviceInfo::GetHandleById(0); auto* cpu_set = hwloc_bitmap_alloc(); - auto rc = hwloc_nvml_get_device_cpuset(topology, device, cpu_set); - EXPECT_EQ(rc, 0); + EXPECT_EQ(mrc::system::DeviceInfo::GetDeviceCpuset(topology, 0, cpu_set), 0); char* cpuset_string = nullptr; hwloc_bitmap_asprintf(&cpuset_string, cpu_set); @@ -175,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\""); @@ -184,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 79d3b0d0e..a80321017 100644 --- a/cpp/mrc/src/tests/test_ucx.cpp +++ b/cpp/mrc/src/tests/test_ucx.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/src/tools/topology_exporter.cpp b/cpp/mrc/src/tools/topology_exporter.cpp index 273e82bdf..cf4ecf627 100644 --- a/cpp/mrc/src/tools/topology_exporter.cpp +++ b/cpp/mrc/src/tools/topology_exporter.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -28,7 +28,6 @@ #include using namespace mrc; -using namespace internal; int main(int argc, char* argv[]) { diff --git a/cpp/mrc/tests/benchmarking/test_benchmarking.cpp b/cpp/mrc/tests/benchmarking/test_benchmarking.cpp index 3ca680006..5395ab8bd 100644 --- a/cpp/mrc/tests/benchmarking/test_benchmarking.cpp +++ b/cpp/mrc/tests/benchmarking/test_benchmarking.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/benchmarking/test_benchmarking.hpp b/cpp/mrc/tests/benchmarking/test_benchmarking.hpp index 2f9f4cf50..99de4e475 100644 --- a/cpp/mrc/tests/benchmarking/test_benchmarking.hpp +++ b/cpp/mrc/tests/benchmarking/test_benchmarking.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_main.cpp b/cpp/mrc/tests/benchmarking/test_main.cpp index 98a2e4ed4..88a0dcb70 100644 --- a/cpp/mrc/tests/benchmarking/test_main.cpp +++ b/cpp/mrc/tests/benchmarking/test_main.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/benchmarking/test_stat_gather.cpp b/cpp/mrc/tests/benchmarking/test_stat_gather.cpp index 3d6f814dd..1b698198f 100644 --- a/cpp/mrc/tests/benchmarking/test_stat_gather.cpp +++ b/cpp/mrc/tests/benchmarking/test_stat_gather.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 38100d1b7..746be4356 100644 --- a/cpp/mrc/tests/benchmarking/test_stat_gather.hpp +++ b/cpp/mrc/tests/benchmarking/test_stat_gather.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ca03f5a0e..fc9c4c549 100644 --- a/cpp/mrc/tests/benchmarking/test_utils.cpp +++ b/cpp/mrc/tests/benchmarking/test_utils.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 258dfc236..68689637d 100644 --- a/cpp/mrc/tests/coroutines/test_event.cpp +++ b/cpp/mrc/tests/coroutines/test_event.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c39451e17..1136bf76e 100644 --- a/cpp/mrc/tests/coroutines/test_latch.cpp +++ b/cpp/mrc/tests/coroutines/test_latch.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d2db09705..fb9afa1c4 100644 --- a/cpp/mrc/tests/coroutines/test_ring_buffer.cpp +++ b/cpp/mrc/tests/coroutines/test_ring_buffer.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include diff --git a/cpp/mrc/tests/coroutines/test_task.cpp b/cpp/mrc/tests/coroutines/test_task.cpp index 56e5c3258..ffc40a3ef 100644 --- a/cpp/mrc/tests/coroutines/test_task.cpp +++ b/cpp/mrc/tests/coroutines/test_task.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/logging/test_logging.cpp b/cpp/mrc/tests/logging/test_logging.cpp index 10ae7829b..f72cb113c 100644 --- a/cpp/mrc/tests/logging/test_logging.cpp +++ b/cpp/mrc/tests/logging/test_logging.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -21,6 +21,8 @@ #include +#include + namespace mrc { TEST_CLASS(Logging); diff --git a/cpp/mrc/tests/logging/test_main.cpp b/cpp/mrc/tests/logging/test_main.cpp index eb685b610..64d55c89d 100644 --- a/cpp/mrc/tests/logging/test_main.cpp +++ b/cpp/mrc/tests/logging/test_main.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/modules/dynamic_module.cpp b/cpp/mrc/tests/modules/dynamic_module.cpp index 057532f99..3db4e08cd 100644 --- a/cpp/mrc/tests/modules/dynamic_module.cpp +++ b/cpp/mrc/tests/modules/dynamic_module.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ec2ebbb0d..7f68a354b 100644 --- a/cpp/mrc/tests/modules/test_mirror_tap_module.cpp +++ b/cpp/mrc/tests/modules/test_mirror_tap_module.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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()); @@ -380,4 +379,4 @@ TEST_F(TestMirrorTapModule, SinglePipelineMultiMirrorTapTest) EXPECT_EQ(multi_sink_main->get_received(i), 4); EXPECT_EQ(multi_sink_mirror->get_received(i), 4); } -} \ No newline at end of file +} diff --git a/cpp/mrc/tests/modules/test_mirror_tap_orchestrator.cpp b/cpp/mrc/tests/modules/test_mirror_tap_orchestrator.cpp index ccb067e72..ceeba44e2 100644 --- a/cpp/mrc/tests/modules/test_mirror_tap_orchestrator.cpp +++ b/cpp/mrc/tests/modules/test_mirror_tap_orchestrator.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 81c6baf83..62b9f9353 100644 --- a/cpp/mrc/tests/modules/test_module_registry.cpp +++ b/cpp/mrc/tests/modules/test_module_registry.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_module_util.cpp b/cpp/mrc/tests/modules/test_module_util.cpp index f6a5cb219..989ec4ed1 100644 --- a/cpp/mrc/tests/modules/test_module_util.cpp +++ b/cpp/mrc/tests/modules/test_module_util.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/modules/test_modules.hpp b/cpp/mrc/tests/modules/test_modules.hpp index 933b50971..415c0111f 100644 --- a/cpp/mrc/tests/modules/test_modules.hpp +++ b/cpp/mrc/tests/modules/test_modules.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 d7147e328..6c23a930f 100644 --- a/cpp/mrc/tests/modules/test_segment_modules.cpp +++ b/cpp/mrc/tests/modules/test_segment_modules.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ee81cedf1..c5cb376f8 100644 --- a/cpp/mrc/tests/modules/test_stream_buffer_modules.cpp +++ b/cpp/mrc/tests/modules/test_stream_buffer_modules.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 5ef7b4c3c..6d796dba6 100644 --- a/cpp/mrc/tests/test_channel.cpp +++ b/cpp/mrc/tests/test_channel.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_edges.cpp b/cpp/mrc/tests/test_edges.cpp index 3df49b567..86e42dfb5 100644 --- a/cpp/mrc/tests/test_edges.cpp +++ b/cpp/mrc/tests/test_edges.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -28,6 +28,7 @@ #include "mrc/node/operators/combine_latest.hpp" #include "mrc/node/operators/node_component.hpp" #include "mrc/node/operators/router.hpp" +#include "mrc/node/rx_node.hpp" #include "mrc/node/sink_channel_owner.hpp" #include "mrc/node/sink_properties.hpp" #include "mrc/node/source_channel_owner.hpp" @@ -36,6 +37,7 @@ #include #include #include +#include // for observable_member #include #include @@ -278,6 +280,25 @@ class TestNodeComponent : public NodeComponent } }; +template +class TestRxNodeComponent : public RxNodeComponent +{ + using base_t = node::RxNodeComponent; + + public: + using typename base_t::stream_fn_t; + + void make_stream(stream_fn_t fn) + { + return base_t::make_stream([this, fn](auto&&... args) { + stream_fn_called = true; + return fn(std::forward(args)...); + }); + } + + bool stream_fn_called = false; +}; + template class TestSinkComponent : public WritableProvider { @@ -517,6 +538,26 @@ TEST_F(TestEdges, SourceToNodeComponentToSinkComponent) source->run(); } +TEST_F(TestEdges, SourceToRxNodeComponentToSinkComponent) +{ + auto source = std::make_shared>(); + auto node = std::make_shared>(); + auto sink = std::make_shared>(); + + mrc::make_edge(*source, *node); + mrc::make_edge(*node, *sink); + + node->make_stream([=](rxcpp::observable input) { + return input.map([](int i) { + return i * 2; + }); + }); + + source->run(); + + EXPECT_TRUE(node->stream_fn_called); +} + TEST_F(TestEdges, SourceComponentToNodeToSinkComponent) { auto source = std::make_shared>(); @@ -825,6 +866,10 @@ TEST_F(TestEdges, CreateAndDestroy) auto x = std::make_shared>(); } + { + auto x = std::make_shared>(); + } + { auto x = std::make_shared>(); } @@ -927,4 +972,28 @@ TEST_F(TestEdges, EdgeTapWithSpliceComponent) source->run(); sink->run(); } + +TEST_F(TestEdges, EdgeTapWithSpliceRxComponent) +{ + auto source = std::make_shared>(); + auto node = std::make_shared>(); + auto sink = std::make_shared>(); + + // Original edge + mrc::make_edge(*source, *sink); + + node->make_stream([=](rxcpp::observable input) { + return input.map([](int i) { + return i * 2; + }); + }); + + // Tap edge + mrc::edge::EdgeBuilder::splice_edge(*source, *sink, *node, *node); + + source->run(); + sink->run(); + + EXPECT_TRUE(node->stream_fn_called); +} } // namespace mrc diff --git a/cpp/mrc/tests/test_executor.cpp b/cpp/mrc/tests/test_executor.cpp index 38a03ca50..e8da2fe0b 100644 --- a/cpp/mrc/tests/test_executor.cpp +++ b/cpp/mrc/tests/test_executor.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_macros.cpp b/cpp/mrc/tests/test_macros.cpp index 3ae21b7e8..07787dcae 100644 --- a/cpp/mrc/tests/test_macros.cpp +++ b/cpp/mrc/tests/test_macros.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/test_main.cpp b/cpp/mrc/tests/test_main.cpp index 99695559f..296a2a279 100644 --- a/cpp/mrc/tests/test_main.cpp +++ b/cpp/mrc/tests/test_main.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/test_metrics.cpp b/cpp/mrc/tests/test_metrics.cpp index a9a84b4e3..2a274902c 100644 --- a/cpp/mrc/tests/test_metrics.cpp +++ b/cpp/mrc/tests/test_metrics.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/test_mrc.cpp b/cpp/mrc/tests/test_mrc.cpp index 374ea927d..31376ce2a 100644 --- a/cpp/mrc/tests/test_mrc.cpp +++ b/cpp/mrc/tests/test_mrc.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/test_mrc.hpp b/cpp/mrc/tests/test_mrc.hpp index ffc4f8fe8..e8971c3c5 100644 --- a/cpp/mrc/tests/test_mrc.hpp +++ b/cpp/mrc/tests/test_mrc.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/cpp/mrc/tests/test_node.cpp b/cpp/mrc/tests/test_node.cpp index 596687bb5..428c41d2c 100644 --- a/cpp/mrc/tests/test_node.cpp +++ b/cpp/mrc/tests/test_node.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -17,14 +17,14 @@ #include "test_mrc.hpp" -#include "mrc/core/executor.hpp" -#include "mrc/engine/pipeline/ipipeline.hpp" +#include "mrc/channel/status.hpp" // for Status #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" @@ -45,6 +45,7 @@ #include #include #include +#include // for runtime_error #include #include #include @@ -66,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) { @@ -147,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) { @@ -232,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)); @@ -312,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); @@ -366,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); @@ -420,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); @@ -485,6 +486,54 @@ TEST_F(TestNode, NodePrologueEpilogue) EXPECT_EQ(epilogue_tap_sum, 20); } +TEST_F(TestNode, RxNodeComponentThrows) +{ + 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::IBuilder& seg) { + auto source = seg.make_source("source", [&](rxcpp::subscriber& s) { + s.on_next(1); + s.on_next(2); + s.on_next(3); + s.on_completed(); + }); + + auto node_comp = seg.make_node_component("node", rxcpp::operators::map([&](int i) -> int { + ++throw_count; + throw std::runtime_error("test"); + return 0; + })); + + auto sink = seg.make_sink( + "sinkInt", + [&](const int& x) { + ++sink_call_count; + }, + [&]() { + ++complete_count; + }); + + seg.make_edge(source, node_comp); + seg.make_edge(node_comp, sink); + }); + + auto options = std::make_unique(); + options->topology().user_cpuset("0"); + + Executor exec(std::move(options)); + exec.register_pipeline(std::move(p)); + exec.start(); + + EXPECT_THROW(exec.join(), std::runtime_error); + + EXPECT_EQ(throw_count, 1); + EXPECT_EQ(sink_call_count, 0); + EXPECT_EQ(complete_count, 0); +} + // the parallel tests: // - SourceMultiThread // - SinkMultiThread @@ -497,7 +546,7 @@ TEST_F(TestNode, NodePrologueEpilogue) TEST_P(ParallelTests, SourceMultiThread) { - auto p = pipeline::make_pipeline(); + auto p = mrc::make_pipeline(); std::atomic next_count = 0; std::atomic complete_count = 0; @@ -511,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(); @@ -584,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; @@ -598,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(); @@ -658,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; @@ -672,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 c30b37b9a..c34731302 100644 --- a/cpp/mrc/tests/test_pipeline.cpp +++ b/cpp/mrc/tests/test_pipeline.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 c429609bd..be1bbc29c 100644 --- a/cpp/mrc/tests/test_segment.cpp +++ b/cpp/mrc/tests/test_segment.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 075dbfbef..bdc385969 100644 --- a/cpp/mrc/tests/test_segment.hpp +++ b/cpp/mrc/tests/test_segment.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/cpp/mrc/tests/test_thread.cpp b/cpp/mrc/tests/test_thread.cpp index ce773c5ef..c19753734 100644 --- a/cpp/mrc/tests/test_thread.cpp +++ b/cpp/mrc/tests/test_thread.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/docs/quickstart/CMakeLists.txt b/docs/quickstart/CMakeLists.txt index 98271b9d6..1b87c4b87 100644 --- a/docs/quickstart/CMakeLists.txt +++ b/docs/quickstart/CMakeLists.txt @@ -28,7 +28,7 @@ list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../external/utili include(morpheus_utils/load) project(mrc-quickstart - VERSION 23.03 + VERSION 23.07.00 LANGUAGES C CXX ) @@ -39,7 +39,8 @@ rapids_cpm_init() # Set the option prefix to match the outer project before including. Must be before find_package(mrc) set(OPTION_PREFIX "MRC") -morpheus_utils_python_ensure_loaded() + +morpheus_utils_python_configure() rapids_find_package(mrc REQUIRED) rapids_find_package(CUDAToolkit REQUIRED) diff --git a/docs/quickstart/README.md b/docs/quickstart/README.md index ac6f01b99..1000ae9d8 100644 --- a/docs/quickstart/README.md +++ b/docs/quickstart/README.md @@ -23,7 +23,7 @@ If you've alredy followed the MRC library installation instructions in the [main ```bash # Change directory to the quickstart root -cd ${MRC_HOME}/docs/quickstart/ +cd ${MRC_ROOT}/docs/quickstart/ # Update the existing MRC conda environment. Here, we assume the environment is named `mrc`, but you can change this to the environment name you used, if different conda env update -n mrc -f environment_cpp.yml @@ -39,7 +39,7 @@ pip install -e python If you haven't installed MRC or would like to create an entirely new Conda environment for the Quick Start Guide, run: ```bash # Change directory to the quickstart root -cd ${MRC_HOME}/docs/quickstart/ +cd ${MRC_ROOT}/docs/quickstart/ # Create a new MRC conda environment. Here, we assume the environment is named `mrc-quickstart` conda env create -n mrc-quickstart -f environment_cpp.yml @@ -62,7 +62,7 @@ If you encounter errors building the examples, this is mostly likely caused for A comprehensive overview of building MRC from source is provided in the [MRC README](../../README.md#source-installation). To build the Quick Start Guide examples, simply run ```bash -cd ${MRC_HOME}/docs/quickstart +cd ${MRC_ROOT}/docs/quickstart # Build the QSG including the C++ examples ./compile.sh diff --git a/docs/quickstart/cpp/common/include/nodes.hpp b/docs/quickstart/cpp/common/include/nodes.hpp index 3a64aed17..d2e5eaf89 100644 --- a/docs/quickstart/cpp/common/include/nodes.hpp +++ b/docs/quickstart/cpp/common/include/nodes.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/docs/quickstart/cpp/common/src/nodes.cpp b/docs/quickstart/cpp/common/src/nodes.cpp index 16e7993c7..bf19a26dc 100644 --- a/docs/quickstart/cpp/common/src/nodes.cpp +++ b/docs/quickstart/cpp/common/src/nodes.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 3a9bdf273..dd8fddd05 100644 --- a/docs/quickstart/cpp/ex00_simple_pipeline/simple_pipeline.cpp +++ b/docs/quickstart/cpp/ex00_simple_pipeline/simple_pipeline.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/ex01_node_library/include/nodes.hpp b/docs/quickstart/cpp/ex01_node_library/include/nodes.hpp index fed8b9e86..112e91c1c 100644 --- a/docs/quickstart/cpp/ex01_node_library/include/nodes.hpp +++ b/docs/quickstart/cpp/ex01_node_library/include/nodes.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/docs/quickstart/cpp/ex01_node_library/src/nodes.cpp b/docs/quickstart/cpp/ex01_node_library/src/nodes.cpp index fa3b8eca5..bf8f5f428 100644 --- a/docs/quickstart/cpp/ex01_node_library/src/nodes.cpp +++ b/docs/quickstart/cpp/ex01_node_library/src/nodes.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 8b393c496..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 @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 @@ -50,8 +49,9 @@ int main(int argc, char* argv[]) // A Node is both a Source and a Sink, it connects to an upstream provider/source and a downstream // subscriber/sink. This examples accects an upstream int and provides a downstream float which is the input // value scaled by 2.5. - auto node = s.make_node("int_x2_to_float", - rxcpp::operators::map([](const int& data) { return float(2.5F * data); })); + auto node = s.make_node("int_x2_to_float", rxcpp::operators::map([](const int& data) { + return float(2.5F * data); + })); // Sink // Sinks are terminators. They only accept upstream connections and do not provide the ability to pass data on. @@ -74,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 bb5408d10..379bf6477 100644 --- a/docs/quickstart/environment_cpp.yml +++ b/docs/quickstart/environment_cpp.yml @@ -12,26 +12,25 @@ dependencies: - benchmark=1.6.0 - ccache - cmake=3.22 - - cuda-nvml-dev=11.4 - - cudatoolkit=11.4 + - cuda-nvml-dev=11.8 + - cudatoolkit=11.8 - 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 - ninja=1.10 - numactl-libs-cos7-x86_64 - - numpy=1.21.2 - - nvcc_linux-64=11.4 + - numpy>=1.21 + - nvcc_linux-64=11.8 - pkg-config=0.29 - - python=3.8 + - python=3.10 - scikit-build>=0.12 - - spdlog=1.8.5 - - mrc=23.03 + - mrc=23.07 - sysroot_linux-64=2.17 - pip: - cython diff --git a/docs/quickstart/hybrid/mrc_qs_hybrid/common/data.cpp b/docs/quickstart/hybrid/mrc_qs_hybrid/common/data.cpp index f52dcb56e..663dd254e 100644 --- a/docs/quickstart/hybrid/mrc_qs_hybrid/common/data.cpp +++ b/docs/quickstart/hybrid/mrc_qs_hybrid/common/data.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/docs/quickstart/hybrid/mrc_qs_hybrid/common/nodes.cpp b/docs/quickstart/hybrid/mrc_qs_hybrid/common/nodes.cpp index da52f218a..10b060ae6 100644 --- a/docs/quickstart/hybrid/mrc_qs_hybrid/common/nodes.cpp +++ b/docs/quickstart/hybrid/mrc_qs_hybrid/common/nodes.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -78,8 +78,12 @@ class DataObjectNode output.on_next(std::move(x)); }, - [&](std::exception_ptr error_ptr) { output.on_error(error_ptr); }, - [&]() { output.on_completed(); })); + [&](std::exception_ptr error_ptr) { + output.on_error(error_ptr); + }, + [&]() { + output.on_completed(); + })); }; } @@ -127,9 +131,10 @@ PYBIND11_MODULE(nodes, m) py::class_, mrc::segment::ObjectProperties, - std::shared_ptr>>( - m, "DataObjectSource", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name, size_t count) { + std::shared_ptr>>(m, + "DataObjectSource", + py::multiple_inheritance()) + .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 +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; @@ -152,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/ex00_wrap_data_objects/data.cpp b/docs/quickstart/hybrid/mrc_qs_hybrid/ex00_wrap_data_objects/data.cpp index 1002f18f6..f64b21caa 100644 --- a/docs/quickstart/hybrid/mrc_qs_hybrid/ex00_wrap_data_objects/data.cpp +++ b/docs/quickstart/hybrid/mrc_qs_hybrid/ex00_wrap_data_objects/data.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * 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 924221286..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 @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -74,8 +74,12 @@ class MyDataObjectNode output.on_next(std::move(x)); }, - [&](std::exception_ptr error_ptr) { output.on_error(error_ptr); }, - [&]() { output.on_completed(); })); + [&](std::exception_ptr error_ptr) { + output.on_error(error_ptr); + }, + [&]() { + output.on_completed(); + })); }; } @@ -120,9 +124,10 @@ PYBIND11_MODULE(nodes, m) py::class_, mrc::segment::ObjectProperties, - std::shared_ptr>>( - m, "MyDataObjectSource", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name, size_t count) { + std::shared_ptr>>(m, + "MyDataObjectSource", + py::multiple_inheritance()) + .def(py::init<>([](mrc::segment::IBuilder& parent, const std::string& name, size_t count) { auto stage = parent.construct_object(name, count); return stage; @@ -133,9 +138,10 @@ PYBIND11_MODULE(nodes, m) py::class_, mrc::segment::ObjectProperties, - std::shared_ptr>>( - m, "MyDataObjectNode", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name) { + std::shared_ptr>>(m, + "MyDataObjectNode", + py::multiple_inheritance()) + .def(py::init<>([](mrc::segment::IBuilder& parent, const std::string& name) { auto stage = parent.construct_object(name); return stage; @@ -145,9 +151,10 @@ PYBIND11_MODULE(nodes, m) py::class_, mrc::segment::ObjectProperties, - std::shared_ptr>>( - m, "MyDataObjectSink", py::multiple_inheritance()) - .def(py::init<>([](mrc::segment::Builder& parent, const std::string& name) { + std::shared_ptr>>(m, + "MyDataObjectSink", + py::multiple_inheritance()) + .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/setup.cfg b/docs/quickstart/hybrid/setup.cfg index 61fd95a25..ebc3e2d13 100644 --- a/docs/quickstart/hybrid/setup.cfg +++ b/docs/quickstart/hybrid/setup.cfg @@ -22,8 +22,7 @@ license = Apache classifiers = Intended Audience :: Developers Programming Language :: Python - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 [options] zip_safe = False diff --git a/docs/quickstart/python/setup.cfg b/docs/quickstart/python/setup.cfg index d63ec1a90..fa7fc2a0e 100644 --- a/docs/quickstart/python/setup.cfg +++ b/docs/quickstart/python/setup.cfg @@ -22,8 +22,7 @@ license = Apache classifiers = Intended Audience :: Developers Programming Language :: Python - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 [options] zip_safe = False diff --git a/external/utilities b/external/utilities index 0fb0b0aab..a5b9689e3 160000 --- a/external/utilities +++ b/external/utilities @@ -1 +1 @@ -Subproject commit 0fb0b0aab16f758adf28d1626945544172406585 +Subproject commit a5b9689e3a82fe5b49245b0a02c907ea70aed7b8 diff --git a/mrc.code-workspace b/mrc.code-workspace index f8c88c4bb..30e2eec34 100644 --- a/mrc.code-workspace +++ b/mrc.code-workspace @@ -195,9 +195,6 @@ "source.organizeImports": true }, "editor.formatOnSave": true, - "editor.rulers": [ - 120 - ], "editor.tabSize": 4 }, "cmake.configureArgs": [ @@ -205,6 +202,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/protos/mrc/protos/architect.proto b/protos/mrc/protos/architect.proto index b5f918dad..f0d29f406 100644 --- a/protos/mrc/protos/architect.proto +++ b/protos/mrc/protos/architect.proto @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022,NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/protos/mrc/protos/codable.proto b/protos/mrc/protos/codable.proto index 67e034fda..7aeeb4bd0 100644 --- a/protos/mrc/protos/codable.proto +++ b/protos/mrc/protos/codable.proto @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022,NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/protos/mrc/protos/remote_descriptor.proto b/protos/mrc/protos/remote_descriptor.proto index 8eda7794e..0231357f5 100644 --- a/protos/mrc/protos/remote_descriptor.proto +++ b/protos/mrc/protos/remote_descriptor.proto @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022,NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/protos/mrc/protos/tensor_meta_data.proto b/protos/mrc/protos/tensor_meta_data.proto index 56f0f64fe..aac8574da 100644 --- a/protos/mrc/protos/tensor_meta_data.proto +++ b/protos/mrc/protos/tensor_meta_data.proto @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022,NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/protos/mrc/protos/test.proto b/protos/mrc/protos/test.proto index bfcfacbc1..8fddce236 100644 --- a/protos/mrc/protos/test.proto +++ b/protos/mrc/protos/test.proto @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2018-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 03aa35d73..b9efadd17 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -19,7 +19,7 @@ find_package(CUDAToolkit REQUIRED) # Ensure python is configured -morpheus_utils_python_ensure_loaded() +morpheus_utils_python_configure() morpheus_utils_print_python_info() 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/codable_object.hpp b/python/mrc/_pymrc/include/pymrc/codable_object.hpp index 02e907e49..b49ee5a51 100644 --- a/python/mrc/_pymrc/include/pymrc/codable_object.hpp +++ b/python/mrc/_pymrc/include/pymrc/codable_object.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/edge_adapter.hpp b/python/mrc/_pymrc/include/pymrc/edge_adapter.hpp index 5d9effebd..c5389bdb7 100644 --- a/python/mrc/_pymrc/include/pymrc/edge_adapter.hpp +++ b/python/mrc/_pymrc/include/pymrc/edge_adapter.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/executor.hpp b/python/mrc/_pymrc/include/pymrc/executor.hpp index 2dc75923b..c339d925a 100644 --- a/python/mrc/_pymrc/include/pymrc/executor.hpp +++ b/python/mrc/_pymrc/include/pymrc/executor.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/forward.hpp b/python/mrc/_pymrc/include/pymrc/forward.hpp index 4962de64a..eb4851dcd 100644 --- a/python/mrc/_pymrc/include/pymrc/forward.hpp +++ b/python/mrc/_pymrc/include/pymrc/forward.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/logging.hpp b/python/mrc/_pymrc/include/pymrc/logging.hpp index 864af8acd..d0d72532c 100644 --- a/python/mrc/_pymrc/include/pymrc/logging.hpp +++ b/python/mrc/_pymrc/include/pymrc/logging.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -25,7 +25,7 @@ namespace mrc::pymrc { /** * @brief Python's logging lib is a pure-python impl, as such the log levels are not defined * in the C API. - * https://docs.python.org/3.8/library/logging.html#logging-levels + * https://docs.python.org/3.10/library/logging.html#logging-levels */ namespace py_log_levels { constexpr int NOTSET = 0; diff --git a/python/mrc/_pymrc/include/pymrc/module_registry.hpp b/python/mrc/_pymrc/include/pymrc/module_registry.hpp index afbf96d4d..25ca7ca28 100644 --- a/python/mrc/_pymrc/include/pymrc/module_registry.hpp +++ b/python/mrc/_pymrc/include/pymrc/module_registry.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/module_wrappers/pickle.hpp b/python/mrc/_pymrc/include/pymrc/module_wrappers/pickle.hpp index 0d88c20e4..3a3e8aa3a 100644 --- a/python/mrc/_pymrc/include/pymrc/module_wrappers/pickle.hpp +++ b/python/mrc/_pymrc/include/pymrc/module_wrappers/pickle.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/module_wrappers/shared_memory.hpp b/python/mrc/_pymrc/include/pymrc/module_wrappers/shared_memory.hpp index 020e6f334..03c35c27b 100644 --- a/python/mrc/_pymrc/include/pymrc/module_wrappers/shared_memory.hpp +++ b/python/mrc/_pymrc/include/pymrc/module_wrappers/shared_memory.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/node.hpp b/python/mrc/_pymrc/include/pymrc/node.hpp index 7471b5740..f5d72e7c3 100644 --- a/python/mrc/_pymrc/include/pymrc/node.hpp +++ b/python/mrc/_pymrc/include/pymrc/node.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/options.hpp b/python/mrc/_pymrc/include/pymrc/options.hpp index 75680a83b..d7762a6d7 100644 --- a/python/mrc/_pymrc/include/pymrc/options.hpp +++ b/python/mrc/_pymrc/include/pymrc/options.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/pipeline.hpp b/python/mrc/_pymrc/include/pymrc/pipeline.hpp index 073c1e5a1..0f663e479 100644 --- a/python/mrc/_pymrc/include/pymrc/pipeline.hpp +++ b/python/mrc/_pymrc/include/pymrc/pipeline.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/plugins.hpp b/python/mrc/_pymrc/include/pymrc/plugins.hpp index d747716da..5390addbc 100644 --- a/python/mrc/_pymrc/include/pymrc/plugins.hpp +++ b/python/mrc/_pymrc/include/pymrc/plugins.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/port_builders.hpp b/python/mrc/_pymrc/include/pymrc/port_builders.hpp index 659a32eb0..eb98a663a 100644 --- a/python/mrc/_pymrc/include/pymrc/port_builders.hpp +++ b/python/mrc/_pymrc/include/pymrc/port_builders.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/py_segment_module.hpp b/python/mrc/_pymrc/include/pymrc/py_segment_module.hpp index 60dc46147..81d5e121e 100644 --- a/python/mrc/_pymrc/include/pymrc/py_segment_module.hpp +++ b/python/mrc/_pymrc/include/pymrc/py_segment_module.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 082a278db..2da23cace 100644 --- a/python/mrc/_pymrc/include/pymrc/segment.hpp +++ b/python/mrc/_pymrc/include/pymrc/segment.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/segment_modules.hpp b/python/mrc/_pymrc/include/pymrc/segment_modules.hpp index b3f741748..c671470d0 100644 --- a/python/mrc/_pymrc/include/pymrc/segment_modules.hpp +++ b/python/mrc/_pymrc/include/pymrc/segment_modules.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/subscriber.hpp b/python/mrc/_pymrc/include/pymrc/subscriber.hpp index 1215ac4c6..5a079906f 100644 --- a/python/mrc/_pymrc/include/pymrc/subscriber.hpp +++ b/python/mrc/_pymrc/include/pymrc/subscriber.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/system.hpp b/python/mrc/_pymrc/include/pymrc/system.hpp deleted file mode 100644 index b2053804d..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/types.hpp b/python/mrc/_pymrc/include/pymrc/types.hpp index 3b166190b..fcaa9942b 100644 --- a/python/mrc/_pymrc/include/pymrc/types.hpp +++ b/python/mrc/_pymrc/include/pymrc/types.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/utilities/acquire_gil.hpp b/python/mrc/_pymrc/include/pymrc/utilities/acquire_gil.hpp index fd2125bb5..c6456de66 100644 --- a/python/mrc/_pymrc/include/pymrc/utilities/acquire_gil.hpp +++ b/python/mrc/_pymrc/include/pymrc/utilities/acquire_gil.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/utilities/deserializers.hpp b/python/mrc/_pymrc/include/pymrc/utilities/deserializers.hpp index 08fee0613..1bea9003f 100644 --- a/python/mrc/_pymrc/include/pymrc/utilities/deserializers.hpp +++ b/python/mrc/_pymrc/include/pymrc/utilities/deserializers.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/utilities/function_wrappers.hpp b/python/mrc/_pymrc/include/pymrc/utilities/function_wrappers.hpp index be7aabb11..f6f5c3c30 100644 --- a/python/mrc/_pymrc/include/pymrc/utilities/function_wrappers.hpp +++ b/python/mrc/_pymrc/include/pymrc/utilities/function_wrappers.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/utilities/object_cache.hpp b/python/mrc/_pymrc/include/pymrc/utilities/object_cache.hpp index 32597ad01..2721eb5db 100644 --- a/python/mrc/_pymrc/include/pymrc/utilities/object_cache.hpp +++ b/python/mrc/_pymrc/include/pymrc/utilities/object_cache.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/utilities/object_wrappers.hpp b/python/mrc/_pymrc/include/pymrc/utilities/object_wrappers.hpp index 7bff43688..f20c55794 100644 --- a/python/mrc/_pymrc/include/pymrc/utilities/object_wrappers.hpp +++ b/python/mrc/_pymrc/include/pymrc/utilities/object_wrappers.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/utilities/serializers.hpp b/python/mrc/_pymrc/include/pymrc/utilities/serializers.hpp index 940bd309f..6c3088440 100644 --- a/python/mrc/_pymrc/include/pymrc/utilities/serializers.hpp +++ b/python/mrc/_pymrc/include/pymrc/utilities/serializers.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/utils.hpp b/python/mrc/_pymrc/include/pymrc/utils.hpp index 7e7112362..f80838c3d 100644 --- a/python/mrc/_pymrc/include/pymrc/utils.hpp +++ b/python/mrc/_pymrc/include/pymrc/utils.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/include/pymrc/watchers.hpp b/python/mrc/_pymrc/include/pymrc/watchers.hpp index cb8258532..af28566d9 100644 --- a/python/mrc/_pymrc/include/pymrc/watchers.hpp +++ b/python/mrc/_pymrc/include/pymrc/watchers.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 244ebc2e0..a62e2c1e7 100644 --- a/python/mrc/_pymrc/src/executor.cpp +++ b/python/mrc/_pymrc/src/executor.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/logging.cpp b/python/mrc/_pymrc/src/logging.cpp index 464760dc1..1150340e8 100644 --- a/python/mrc/_pymrc/src/logging.cpp +++ b/python/mrc/_pymrc/src/logging.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/module_registry.cpp b/python/mrc/_pymrc/src/module_registry.cpp index 8eeecf0b9..424eb2b68 100644 --- a/python/mrc/_pymrc/src/module_registry.cpp +++ b/python/mrc/_pymrc/src/module_registry.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/module_wrappers/pickle.cpp b/python/mrc/_pymrc/src/module_wrappers/pickle.cpp index ed07e0be9..fd6e99290 100644 --- a/python/mrc/_pymrc/src/module_wrappers/pickle.cpp +++ b/python/mrc/_pymrc/src/module_wrappers/pickle.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/module_wrappers/shared_memory.cpp b/python/mrc/_pymrc/src/module_wrappers/shared_memory.cpp index 1daaa3f2e..9a4106f76 100644 --- a/python/mrc/_pymrc/src/module_wrappers/shared_memory.cpp +++ b/python/mrc/_pymrc/src/module_wrappers/shared_memory.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/node.cpp b/python/mrc/_pymrc/src/node.cpp index d14b4fd59..c3a1563e5 100644 --- a/python/mrc/_pymrc/src/node.cpp +++ b/python/mrc/_pymrc/src/node.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/operators.cpp b/python/mrc/_pymrc/src/operators.cpp index 6d7b5c94b..cb0b679e1 100644 --- a/python/mrc/_pymrc/src/operators.cpp +++ b/python/mrc/_pymrc/src/operators.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/options.cpp b/python/mrc/_pymrc/src/options.cpp index 0479df4c6..ca433580b 100644 --- a/python/mrc/_pymrc/src/options.cpp +++ b/python/mrc/_pymrc/src/options.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/pipeline.cpp b/python/mrc/_pymrc/src/pipeline.cpp index d130b5511..e5d2fd53a 100644 --- a/python/mrc/_pymrc/src/pipeline.cpp +++ b/python/mrc/_pymrc/src/pipeline.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/plugins.cpp b/python/mrc/_pymrc/src/plugins.cpp index d56bc8c69..4397e2e1b 100644 --- a/python/mrc/_pymrc/src/plugins.cpp +++ b/python/mrc/_pymrc/src/plugins.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/py_segment_module.cpp b/python/mrc/_pymrc/src/py_segment_module.cpp index cd8dd83d3..d9e44621f 100644 --- a/python/mrc/_pymrc/src/py_segment_module.cpp +++ b/python/mrc/_pymrc/src/py_segment_module.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 12bd3f1e4..4e60e63e4 100644 --- a/python/mrc/_pymrc/src/segment.cpp +++ b/python/mrc/_pymrc/src/segment.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/segment_modules.cpp b/python/mrc/_pymrc/src/segment_modules.cpp index c62e75d5b..a494fee3e 100644 --- a/python/mrc/_pymrc/src/segment_modules.cpp +++ b/python/mrc/_pymrc/src/segment_modules.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/subscriber.cpp b/python/mrc/_pymrc/src/subscriber.cpp index 221e9c48b..35f795175 100644 --- a/python/mrc/_pymrc/src/subscriber.cpp +++ b/python/mrc/_pymrc/src/subscriber.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/system.cpp b/python/mrc/_pymrc/src/system.cpp deleted file mode 100644 index 7c0231615..000000000 --- a/python/mrc/_pymrc/src/system.cpp +++ /dev/null @@ -1,132 +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()) - { - auto trace_module = pybind11::getattr(trace_func, "__module__", pybind11::none()); - - if (!trace_module.is_none() && !trace_module.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/tracers.cpp b/python/mrc/_pymrc/src/tracers.cpp index 21aad6c87..3bb9281cb 100644 --- a/python/mrc/_pymrc/src/tracers.cpp +++ b/python/mrc/_pymrc/src/tracers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -15,4 +15,4 @@ * limitations under the License. */ -#include "pymrc/tracers.hpp" \ No newline at end of file +#include "pymrc/tracers.hpp" diff --git a/python/mrc/_pymrc/src/types.cpp b/python/mrc/_pymrc/src/types.cpp index b8abbbb7f..c0418a5a6 100644 --- a/python/mrc/_pymrc/src/types.cpp +++ b/python/mrc/_pymrc/src/types.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/utilities/acquire_gil.cpp b/python/mrc/_pymrc/src/utilities/acquire_gil.cpp index dd970b036..43998d3c0 100644 --- a/python/mrc/_pymrc/src/utilities/acquire_gil.cpp +++ b/python/mrc/_pymrc/src/utilities/acquire_gil.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/utilities/deserializers.cpp b/python/mrc/_pymrc/src/utilities/deserializers.cpp index 6ef2de1fb..31746ffda 100644 --- a/python/mrc/_pymrc/src/utilities/deserializers.cpp +++ b/python/mrc/_pymrc/src/utilities/deserializers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/utilities/function_wrappers.cpp b/python/mrc/_pymrc/src/utilities/function_wrappers.cpp index fa529e1f5..4d7b6756e 100644 --- a/python/mrc/_pymrc/src/utilities/function_wrappers.cpp +++ b/python/mrc/_pymrc/src/utilities/function_wrappers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/utilities/object_cache.cpp b/python/mrc/_pymrc/src/utilities/object_cache.cpp index 93e9beff2..604a21200 100644 --- a/python/mrc/_pymrc/src/utilities/object_cache.cpp +++ b/python/mrc/_pymrc/src/utilities/object_cache.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/utilities/object_wrappers.cpp b/python/mrc/_pymrc/src/utilities/object_wrappers.cpp index aec9b4e93..e87d63029 100644 --- a/python/mrc/_pymrc/src/utilities/object_wrappers.cpp +++ b/python/mrc/_pymrc/src/utilities/object_wrappers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/utilities/serializers.cpp b/python/mrc/_pymrc/src/utilities/serializers.cpp index 9dd8a2b8c..e5378116c 100644 --- a/python/mrc/_pymrc/src/utilities/serializers.cpp +++ b/python/mrc/_pymrc/src/utilities/serializers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/utils.cpp b/python/mrc/_pymrc/src/utils.cpp index 881abdc31..ba6a70584 100644 --- a/python/mrc/_pymrc/src/utils.cpp +++ b/python/mrc/_pymrc/src/utils.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/src/watchers.cpp b/python/mrc/_pymrc/src/watchers.cpp index 567ca21d5..d474d7ae4 100644 --- a/python/mrc/_pymrc/src/watchers.cpp +++ b/python/mrc/_pymrc/src/watchers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_codable_pyobject.cpp b/python/mrc/_pymrc/tests/test_codable_pyobject.cpp index 1c511d173..520f21448 100644 --- a/python/mrc/_pymrc/tests/test_codable_pyobject.cpp +++ b/python/mrc/_pymrc/tests/test_codable_pyobject.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/tests/test_executor.cpp b/python/mrc/_pymrc/tests/test_executor.cpp index 2cdf86eb9..41e284d91 100644 --- a/python/mrc/_pymrc/tests/test_executor.cpp +++ b/python/mrc/_pymrc/tests/test_executor.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_main.cpp b/python/mrc/_pymrc/tests/test_main.cpp index a315af04a..dcd082f12 100644 --- a/python/mrc/_pymrc/tests/test_main.cpp +++ b/python/mrc/_pymrc/tests/test_main.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/tests/test_object_cache.cpp b/python/mrc/_pymrc/tests/test_object_cache.cpp index 2d5cb1a09..14bb0b006 100644 --- a/python/mrc/_pymrc/tests/test_object_cache.cpp +++ b/python/mrc/_pymrc/tests/test_object_cache.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/tests/test_pickle_wrapper.cpp b/python/mrc/_pymrc/tests/test_pickle_wrapper.cpp index 41540f900..193252013 100644 --- a/python/mrc/_pymrc/tests/test_pickle_wrapper.cpp +++ b/python/mrc/_pymrc/tests/test_pickle_wrapper.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/tests/test_pipeline.cpp b/python/mrc/_pymrc/tests/test_pipeline.cpp index a88cd1172..68091ba14 100644 --- a/python/mrc/_pymrc/tests/test_pipeline.cpp +++ b/python/mrc/_pymrc/tests/test_pipeline.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/_pymrc/tests/test_pymrc.hpp b/python/mrc/_pymrc/tests/test_pymrc.hpp index 1f847563b..8f8210027 100644 --- a/python/mrc/_pymrc/tests/test_pymrc.hpp +++ b/python/mrc/_pymrc/tests/test_pymrc.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/tests/test_serializers.cpp b/python/mrc/_pymrc/tests/test_serializers.cpp index 5c405268b..cbf5147c5 100644 --- a/python/mrc/_pymrc/tests/test_serializers.cpp +++ b/python/mrc/_pymrc/tests/test_serializers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/tests/test_shmem_wrapper.cpp b/python/mrc/_pymrc/tests/test_shmem_wrapper.cpp index ff38552c1..c184d7fb2 100644 --- a/python/mrc/_pymrc/tests/test_shmem_wrapper.cpp +++ b/python/mrc/_pymrc/tests/test_shmem_wrapper.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/_pymrc/tests/test_utils.cpp b/python/mrc/_pymrc/tests/test_utils.cpp index 04bb9071f..a802009fc 100644 --- a/python/mrc/_pymrc/tests/test_utils.cpp +++ b/python/mrc/_pymrc/tests/test_utils.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/benchmarking/trace_statistics.cpp b/python/mrc/benchmarking/trace_statistics.cpp index 5622b6c16..cb211ef7d 100644 --- a/python/mrc/benchmarking/trace_statistics.cpp +++ b/python/mrc/benchmarking/trace_statistics.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/benchmarking/tracers.cpp b/python/mrc/benchmarking/tracers.cpp index 4b8f88211..15ff31f22 100644 --- a/python/mrc/benchmarking/tracers.cpp +++ b/python/mrc/benchmarking/tracers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/benchmarking/watchers.cpp b/python/mrc/benchmarking/watchers.cpp index cefcd4a03..2a4b3418f 100644 --- a/python/mrc/benchmarking/watchers.cpp +++ b/python/mrc/benchmarking/watchers.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/core/common.cpp b/python/mrc/core/common.cpp index e73eef600..741fec61b 100644 --- a/python/mrc/core/common.cpp +++ b/python/mrc/core/common.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/core/executor.cpp b/python/mrc/core/executor.cpp index 3adbf01fd..8169733a2 100644 --- a/python/mrc/core/executor.cpp +++ b/python/mrc/core/executor.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/core/logging.cpp b/python/mrc/core/logging.cpp index 4ad374c13..35cb01143 100644 --- a/python/mrc/core/logging.cpp +++ b/python/mrc/core/logging.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/core/node.cpp b/python/mrc/core/node.cpp index 987612f76..bbbdfe658 100644 --- a/python/mrc/core/node.cpp +++ b/python/mrc/core/node.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/operators.cpp b/python/mrc/core/operators.cpp index a2348ef2c..b74ff96ec 100644 --- a/python/mrc/core/operators.cpp +++ b/python/mrc/core/operators.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/core/options.cpp b/python/mrc/core/options.cpp index e432b1899..015c8642c 100644 --- a/python/mrc/core/options.cpp +++ b/python/mrc/core/options.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/core/pipeline.cpp b/python/mrc/core/pipeline.cpp index 8833e6571..2f1dcf970 100644 --- a/python/mrc/core/pipeline.cpp +++ b/python/mrc/core/pipeline.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/plugins.cpp b/python/mrc/core/plugins.cpp index 781ae1168..42803c54e 100644 --- a/python/mrc/core/plugins.cpp +++ b/python/mrc/core/plugins.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/core/segment.cpp b/python/mrc/core/segment.cpp index c86331add..ed87f83f2 100644 --- a/python/mrc/core/segment.cpp +++ b/python/mrc/core/segment.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/mirror_tap_orchestrator.cpp b/python/mrc/core/segment/module_definitions/mirror_tap_orchestrator.cpp index c842afc97..570bd3c69 100644 --- a/python/mrc/core/segment/module_definitions/mirror_tap_orchestrator.cpp +++ b/python/mrc/core/segment/module_definitions/mirror_tap_orchestrator.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/core/segment/module_definitions/mirror_tap_orchestrator.hpp b/python/mrc/core/segment/module_definitions/mirror_tap_orchestrator.hpp index a075a020d..bcf2a2e74 100644 --- a/python/mrc/core/segment/module_definitions/mirror_tap_orchestrator.hpp +++ b/python/mrc/core/segment/module_definitions/mirror_tap_orchestrator.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -24,4 +24,4 @@ namespace mrc::pymrc { void register_mirror_tap_modules(); void init_mirror_tap_orchestrator(pybind11::module_& module); #pragma GCC visibility pop -} // namespace mrc::pymrc \ No newline at end of file +} // namespace mrc::pymrc 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 ef347c3ba..0ae7b5728 100644 --- a/python/mrc/core/segment/module_definitions/segment_module_registry.cpp +++ b/python/mrc/core/segment/module_definitions/segment_module_registry.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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_module_registry.hpp b/python/mrc/core/segment/module_definitions/segment_module_registry.hpp index 01fd4f28e..66dad2365 100644 --- a/python/mrc/core/segment/module_definitions/segment_module_registry.hpp +++ b/python/mrc/core/segment/module_definitions/segment_module_registry.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/core/segment/module_definitions/segment_modules.cpp b/python/mrc/core/segment/module_definitions/segment_modules.cpp index 6b788d0dd..08332dd40 100644 --- a/python/mrc/core/segment/module_definitions/segment_modules.cpp +++ b/python/mrc/core/segment/module_definitions/segment_modules.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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 ec1e4aebf..113c313e4 100644 --- a/python/mrc/core/segment/module_definitions/segment_modules.hpp +++ b/python/mrc/core/segment/module_definitions/segment_modules.hpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/core/subscriber.cpp b/python/mrc/core/subscriber.cpp index f1f0455f5..656ff6884 100644 --- a/python/mrc/core/subscriber.cpp +++ b/python/mrc/core/subscriber.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/tests/sample_modules.cpp b/python/mrc/tests/sample_modules.cpp index 07c7c780e..8bd6d354e 100644 --- a/python/mrc/tests/sample_modules.cpp +++ b/python/mrc/tests/sample_modules.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/mrc/tests/test_edges.cpp b/python/mrc/tests/test_edges.cpp index f1cac770d..1e9cc0359 100644 --- a/python/mrc/tests/test_edges.cpp +++ b/python/mrc/tests/test_edges.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -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/mrc/tests/utils.cpp b/python/mrc/tests/utils.cpp index 66785dcf0..35a64d6e5 100644 --- a/python/mrc/tests/utils.cpp +++ b/python/mrc/tests/utils.cpp @@ -1,4 +1,4 @@ -/** +/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * diff --git a/python/setup.py b/python/setup.py index 717d81e3c..cc37c7077 100644 --- a/python/setup.py +++ b/python/setup.py @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages +from setuptools import find_namespace_packages from setuptools import setup import versioneer @@ -23,22 +23,19 @@ # - Python package generation ------------------------------------------------ setup( - name='mrc', + name="mrc", description="mrc", version=versioneer.get_version(), classifiers=[ - "Intended Audience :: Developers", - "Programming Language :: Python", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9" + "Intended Audience :: Developers", "Programming Language :: Python", "Programming Language :: Python :: 3.10" ], author="NVIDIA Corporation", setup_requires=[], include_package_data=True, - packages=find_packages(include=['mrc', 'mrc.*'], exclude=['tests']), + packages=find_namespace_packages(include=["mrc*"], exclude=["tests", "mrc.core.segment.module_definitions"]), package_data={ "mrc": ["_pymrc/*.so"] # Add the pymrc library for the root package }, license="Apache", - cmdclass=versioneer.get_cmdclass()) + cmdclass=versioneer.get_cmdclass(), + zip_safe=False) diff --git a/python/tests/test_segment_modules.py b/python/tests/test_segment_modules.py index 08c78fc36..8b6b96908 100644 --- a/python/tests/test_segment_modules.py +++ b/python/tests/test_segment_modules.py @@ -117,7 +117,6 @@ def on_complete(): def test_py_constructor(): - config = {"config_key_1": True} registry = mrc.ModuleRegistry @@ -312,11 +311,41 @@ def on_complete(): def test_py_module_nesting(): - def gen_data(): - for i in range(0, 43): - yield True + def init_wrapper(builder: mrc.Builder): + global packet_count + packet_count = 0 + + def on_next(input): global packet_count packet_count += 1 + logging.info("Sinking {}".format(input)) + + def on_error(): + pass + + def on_complete(): + pass + + nested_mod = builder.load_module("NestedModule", "mrc_unittest", "ModuleNestingTest_mod1", {}) + nested_sink = builder.make_sink("nested_sink", on_next, on_error, on_complete) + + builder.make_edge(nested_mod.output_port("nested_module_output"), nested_sink) + + pipeline = mrc.Pipeline() + pipeline.make_segment("ModuleNesting_Segment", init_wrapper) + + options = mrc.Options() + options.topology.user_cpuset = "0-1" + + executor = mrc.Executor(options) + executor.register_pipeline(pipeline) + executor.start() + executor.join() + + assert packet_count == 4 + + +def test_py_modules_dont_overwrite(): def init_wrapper(builder: mrc.Builder): global packet_count @@ -334,9 +363,18 @@ def on_complete(): pass nested_mod = builder.load_module("NestedModule", "mrc_unittest", "ModuleNestingTest_mod1", {}) + + # Make sure we can't re-register the same name + with pytest.raises(RuntimeError): + this_should_fail = builder.load_module( # noqa + "NestedModule", "mrc_unittest", "ModuleNestingTest_mod1", {}) + + nested_mod2 = builder.load_module("NestedModule", "mrc_unittest", "ModuleNestingTest_mod2", {}) nested_sink = builder.make_sink("nested_sink", on_next, on_error, on_complete) + nested_sink2 = builder.make_sink("nested_sink2", on_next, on_error, on_complete) builder.make_edge(nested_mod.output_port("nested_module_output"), nested_sink) + builder.make_edge(nested_mod2.output_port("nested_module_output"), nested_sink2) pipeline = mrc.Pipeline() pipeline.make_segment("ModuleNesting_Segment", init_wrapper) @@ -349,7 +387,7 @@ def on_complete(): executor.start() executor.join() - assert packet_count == 4 + assert packet_count == 8 if (__name__ in ("__main__", )): @@ -358,5 +396,6 @@ def on_complete(): test_py_module_as_sink() test_py_module_chaining() test_py_module_nesting() + test_py_modules_dont_overwrite() test_py_constructor() test_py_module_initialization() 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