From c3581a4869f8d3b63d2e00c7d183fddbb1e7637f Mon Sep 17 00:00:00 2001 From: Benjamin Huth Date: Thu, 9 Jan 2025 16:44:34 +0100 Subject: [PATCH 1/4] remove cugraph, update cmake --- CMakeLists.txt | 3 - .../python/acts/examples/reconstruction.py | 2 +- Examples/Python/src/ExaTrkXTrackFinding.cpp | 12 -- Plugins/ExaTrkX/CMakeLists.txt | 53 +++++---- Plugins/ExaTrkX/README.md | 1 - .../Plugins/ExaTrkX/CugraphTrackBuilding.hpp | 37 ------ Plugins/ExaTrkX/src/CugraphTrackBuilding.cpp | 84 -------------- .../src/weaklyConnectedComponentsCugraph.hpp | 108 ------------------ docs/getting_started.md | 1 - 9 files changed, 33 insertions(+), 268 deletions(-) delete mode 100644 Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/CugraphTrackBuilding.hpp delete mode 100644 Plugins/ExaTrkX/src/CugraphTrackBuilding.cpp delete mode 100644 Plugins/ExaTrkX/src/weaklyConnectedComponentsCugraph.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 04fb58d6825..a4fd002e871 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -432,9 +432,6 @@ if(ACTS_BUILD_PLUGIN_EXATRKX) and ACTS_EXATRKX_ENABLE_TORCHSCRIPT must be enabled." ) endif() - if(ACTS_EXATRKX_ENABLE_ONNX) - find_package(cugraph REQUIRED) - endif() if(ACTS_EXATRKX_ENABLE_TORCH) find_package(TorchScatter REQUIRED) endif() diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index 0e30961fe39..f81fc7e3404 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -1798,7 +1798,7 @@ def addExaTrkX( acts.examples.OnnxEdgeClassifier(**filterConfig), acts.examples.OnnxEdgeClassifier(**gnnConfig), ] - trackBuilder = acts.examples.CugraphTrackBuilding(customLogLevel()) + trackBuilder = acts.examples.BoostTrackBuilding(customLogLevel()) findingAlg = acts.examples.TrackFindingAlgorithmExaTrkX( level=customLogLevel(), diff --git a/Examples/Python/src/ExaTrkXTrackFinding.cpp b/Examples/Python/src/ExaTrkXTrackFinding.cpp index c7a30b51d2e..ffb572af214 100644 --- a/Examples/Python/src/ExaTrkXTrackFinding.cpp +++ b/Examples/Python/src/ExaTrkXTrackFinding.cpp @@ -7,7 +7,6 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/Plugins/ExaTrkX/BoostTrackBuilding.hpp" -#include "Acts/Plugins/ExaTrkX/CugraphTrackBuilding.hpp" #include "Acts/Plugins/ExaTrkX/ExaTrkXPipeline.hpp" #include "Acts/Plugins/ExaTrkX/OnnxEdgeClassifier.hpp" #include "Acts/Plugins/ExaTrkX/OnnxMetricLearning.hpp" @@ -157,17 +156,6 @@ void addExaTrkXTrackFinding(Context &ctx) { ACTS_PYTHON_MEMBER(cut); ACTS_PYTHON_STRUCT_END(); } - { - using Alg = Acts::CugraphTrackBuilding; - - auto alg = py::class_>( - mex, "CugraphTrackBuilding") - .def(py::init([](Logging::Level lvl) { - return std::make_shared( - getDefaultLogger("EdgeClassifier", lvl)); - }), - py::arg("level")); - } #endif ACTS_PYTHON_DECLARE_ALGORITHM( diff --git a/Plugins/ExaTrkX/CMakeLists.txt b/Plugins/ExaTrkX/CMakeLists.txt index 802941e7367..6d5236fa360 100644 --- a/Plugins/ExaTrkX/CMakeLists.txt +++ b/Plugins/ExaTrkX/CMakeLists.txt @@ -1,24 +1,32 @@ -set(SOURCES src/buildEdges.cpp src/ExaTrkXPipeline.cpp) +add_library( + ActsPluginExaTrkX + SHARED + src/buildEdges.cpp + src/ExaTrkXPipeline.cpp + src/BoostWalkthrough.cpp +) + +if(ACTS_EXATRKX_ENABLE_CUDA) + target_compile_definitions(ActsPluginExaTrkX PUBLIC ACTS_EXATRKX_WITH_CUDA) + target_sources(ActsPluginExaTrkX PRIVATE src/CudaTrackBuilding.cu) +endif() if(ACTS_EXATRKX_ENABLE_ONNX) - list( - APPEND - SOURCES - src/OnnxEdgeClassifier.cpp - src/OnnxMetricLearning.cpp - src/CugraphTrackBuilding.cpp + target_sources( + ActsPluginExaTrkX + PRIVATE src/OnnxEdgeClassifier.cpp src/OnnxMetricLearning.cpp ) endif() if(ACTS_EXATRKX_ENABLE_TORCH) - list( - APPEND - SOURCES - src/TorchEdgeClassifier.cpp - src/TorchMetricLearning.cpp - src/BoostTrackBuilding.cpp - src/TorchTruthGraphMetricsHook.cpp - src/TorchGraphStoreHook.cpp + target_sources( + ActsPluginExaTrkX + PRIVATE + src/TorchEdgeClassifier.cpp + src/TorchMetricLearning.cpp + src/BoostTrackBuilding.cpp + src/TorchTruthGraphMetricsHook.cpp + src/TorchGraphStoreHook.cpp ) endif() @@ -45,15 +53,21 @@ if(ACTS_EXATRKX_ENABLE_CUDA) set_target_properties( ActsPluginExaTrkX PROPERTIES - CUDA_STANDARD 17 + CUDA_STANDARD 20 CUDA_STANDARD_REQUIRED ON CUDA_SEPARABLE_COMPILATION ON ) + target_compile_options( + ActsPluginExaTrkX + PRIVATE + $<$:-g + --generate-line-info + --extended-lambda> + ) target_compile_definitions( ActsPluginExaTrkX PUBLIC CUDA_API_PER_THREAD_DEFAULT_STREAM ) - target_compile_definitions(ActsPluginExaTrkX PUBLIC NO_CUGRAPH_OPS) else() target_compile_definitions(ActsPluginExaTrkX PUBLIC ACTS_EXATRKX_CPUONLY) endif() @@ -64,10 +78,7 @@ if(ACTS_EXATRKX_ENABLE_ONNX) PUBLIC ACTS_EXATRKX_ONNX_BACKEND ) - target_link_libraries( - ActsPluginExaTrkX - PRIVATE OnnxRuntime cugraph::cugraph - ) + target_link_libraries(ActsPluginExaTrkX PRIVATE OnnxRuntime) endif() if(ACTS_EXATRKX_ENABLE_TORCH) diff --git a/Plugins/ExaTrkX/README.md b/Plugins/ExaTrkX/README.md index 8a7944bd7f2..5878ce83a15 100644 --- a/Plugins/ExaTrkX/README.md +++ b/Plugins/ExaTrkX/README.md @@ -23,7 +23,6 @@ This plugin is known to build without errors with (as of September 2022) - [libtorch](https://pytorch.org/) v1.10.2 for CUDA version 10.2 and cxx-11-abi ([download](https://download.pytorch.org/libtorch/cu102/libtorch-cxx11-abi-shared-with-deps-1.10.2%2Bcu102.zip)) *For the ONNX backend:* -- [cugraph](https://github.com/rapidsai/cugraph) v22.02.00 - [ONNX](https://github.com/microsoft/onnxruntime) v1.10.0 with CUDA support enabled *For the Torch backend* diff --git a/Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/CugraphTrackBuilding.hpp b/Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/CugraphTrackBuilding.hpp deleted file mode 100644 index 133ee79e187..00000000000 --- a/Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/CugraphTrackBuilding.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#pragma once - -#include "Acts/Plugins/ExaTrkX/Stages.hpp" -#include "Acts/Utilities/Logger.hpp" - -#include - -#include - -namespace Acts { - -class CugraphTrackBuilding final : public Acts::TrackBuildingBase { - public: - CugraphTrackBuilding(std::unique_ptr logger) - : m_logger(std::move(logger)), m_device(torch::Device(torch::kCPU)) {} - - std::vector> operator()( - std::any nodes, std::any edges, std::any edge_weights, - std::vector &spacepointIDs, - torch::Device device = torch::Device(torch::kCPU)) override; - torch::Device device() const override { return m_device; }; - - private: - std::unique_ptr m_logger; - torch::Device m_device; - const auto &logger() const { return *m_logger; } -}; - -} // namespace Acts diff --git a/Plugins/ExaTrkX/src/CugraphTrackBuilding.cpp b/Plugins/ExaTrkX/src/CugraphTrackBuilding.cpp deleted file mode 100644 index 7750cd7b3ac..00000000000 --- a/Plugins/ExaTrkX/src/CugraphTrackBuilding.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#include "Acts/Plugins/ExaTrkX/CugraphTrackBuilding.hpp" - -#include - -#include - -#include "weaklyConnectedComponentsCugraph.hpp" - -namespace Acts { - -std::vector> CugraphTrackBuilding::operator()( - std::any, std::any edges, std::any edge_weights, - std::vector &spacepointIDs, torch::Device) { - auto numSpacepoints = spacepointIDs.size(); - auto edgesAfterFiltering = std::any_cast>(edges); - auto numEdgesAfterF = edgesAfterFiltering.size() / 2; - auto gOutputCTen = std::any_cast(edge_weights); - - if (numEdgesAfterF == 0) { - return {}; - } - - // ************ - // Track Labeling with cugraph::connected_components - // ************ - std::vector rowIndices; - std::vector colIndices; - std::vector edgeWeights; - std::vector trackLabels(numSpacepoints); - std::copy(edgesAfterFiltering.begin(), - edgesAfterFiltering.begin() + numEdgesAfterF, - std::back_insert_iterator(rowIndices)); - std::copy(edgesAfterFiltering.begin() + numEdgesAfterF, - edgesAfterFiltering.end(), std::back_insert_iterator(colIndices)); - std::copy(gOutputCTen.data_ptr(), - gOutputCTen.data_ptr() + numEdgesAfterF, - std::back_insert_iterator(edgeWeights)); - - ACTS_VERBOSE("run weaklyConnectedComponents"); - weaklyConnectedComponents( - rowIndices, colIndices, edgeWeights, trackLabels, logger()); - - ACTS_DEBUG("size of components: " << trackLabels.size()); - if (trackLabels.size() == 0) { - return {}; - } - - std::vector> trackCandidates; - trackCandidates.clear(); - - int existTrkIdx = 0; - // map labeling from MCC to customized track id. - std::map trackLableToIds; - - for (auto idx = 0ul; idx < numSpacepoints; ++idx) { - int trackLabel = trackLabels[idx]; - int spacepointID = spacepointIDs[idx]; - - int trkId; - if (trackLableToIds.contains(trackLabel)) { - trkId = trackLableToIds[trackLabel]; - trackCandidates[trkId].push_back(spacepointID); - } else { - // a new track, assign the track id - // and create a vector - trkId = existTrkIdx; - trackCandidates.push_back(std::vector{trkId}); - trackLableToIds[trackLabel] = trkId; - existTrkIdx++; - } - } - - return trackCandidates; -} - -} // namespace Acts diff --git a/Plugins/ExaTrkX/src/weaklyConnectedComponentsCugraph.hpp b/Plugins/ExaTrkX/src/weaklyConnectedComponentsCugraph.hpp deleted file mode 100644 index 4eb498a326d..00000000000 --- a/Plugins/ExaTrkX/src/weaklyConnectedComponentsCugraph.hpp +++ /dev/null @@ -1,108 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#pragma once - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef CUDA_RT_CALL -#define CUDA_RT_CALL(call) \ - { \ - cudaError_t cudaStatus = call; \ - if (cudaSuccess != cudaStatus) { \ - fprintf(stderr, \ - "ERROR: CUDA RT call \"%s\" in line %d of file %s failed with " \ - "%s (%d).\n", \ - #call, __LINE__, __FILE__, cudaGetErrorString(cudaStatus), \ - cudaStatus); \ - } \ - } -#endif // CUDA_RT_CALL - -template -__global__ void weaklyConnectedComponents(std::vector& rowIndices, - std::vector& colIndices, - std::vector& edgeWeights, - std::vector& trackLabels, - const Acts::Logger& logger) { - cudaStream_t stream; - CUDA_RT_CALL(cudaStreamCreate(&stream)); - - ACTS_VERBOSE("Weakly components Start"); - ACTS_VERBOSE("edge size: " << rowIndices.size() << " " << colIndices.size()); - raft::handle_t handle{stream}; - - cugraph::graph_t graph(handle); - - // learn from matrix_market_file_utilities.cu - vertex_t maxVertexID_row = - *std::max_element(rowIndices.begin(), rowIndices.end()); - vertex_t maxVertexID_col = - *std::max_element(colIndices.begin(), colIndices.end()); - vertex_t maxVertex = std::max(maxVertexID_row, maxVertexID_col); - - vertex_t number_of_vertices = maxVertex; - rmm::device_uvector d_vertices(number_of_vertices, - handle.get_stream()); - std::vector vertex_idx(number_of_vertices); - for (vertex_t idx = 0; idx < number_of_vertices; idx++) { - vertex_idx[idx] = idx; - } - - rmm::device_uvector src_v(rowIndices.size(), handle.get_stream()); - rmm::device_uvector dst_v(colIndices.size(), handle.get_stream()); - rmm::device_uvector weights_v(edgeWeights.size(), - handle.get_stream()); - - raft::update_device(src_v.data(), rowIndices.data(), rowIndices.size(), - handle.get_stream()); - raft::update_device(dst_v.data(), colIndices.data(), colIndices.size(), - handle.get_stream()); - raft::update_device(weights_v.data(), edgeWeights.data(), edgeWeights.size(), - handle.get_stream()); - raft::update_device(d_vertices.data(), vertex_idx.data(), vertex_idx.size(), - handle.get_stream()); - - std::tie(graph, std::ignore) = - cugraph::create_graph_from_edgelist( - handle, std::move(d_vertices), std::move(src_v), std::move(dst_v), - std::move(weights_v), cugraph::graph_properties_t{true, false}, - false); - - auto graph_view = graph.view(); - CUDA_TRY(cudaDeviceSynchronize()); // for consistent performance measurement - - rmm::device_uvector d_components( - graph_view.get_number_of_vertices(), handle.get_stream()); - - ACTS_VERBOSE("2back from construct_graph"); - cugraph::weakly_connected_components(handle, graph_view, d_components.data()); - - ACTS_VERBOSE("number of components: " << d_components.size()); - raft::update_host(trackLabels.data(), d_components.data(), - d_components.size(), handle.get_stream()); -} diff --git a/docs/getting_started.md b/docs/getting_started.md index 03365dd9f40..2b99227a1e7 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -41,7 +41,6 @@ components: - [Pythia8](https://pythia.org) for some examples - [ROOT](https://root.cern.ch) >= 6.20 for the TGeo plugin and the examples - [Sphinx](https://www.sphinx-doc.org) >= 2.0 with [Breathe](https://breathe.readthedocs.io/en/latest/), [Exhale](https://exhale.readthedocs.io/en/latest/), and [recommonmark](https://recommonmark.readthedocs.io/en/latest/index.html) extensions for the documentation -- [cugraph](https://github.com/rapidsai/cugraph) for the Exa.TrkX plugin - [libtorch](https://pytorch.org/cppdocs/installing.html) for the Exa.TrkX plugin - [Pybind11](https://github.com/pybind/pybind11) for the Python bindings of the examples From d4967bef1f707dc7e67f171797a5753d8c8b50b9 Mon Sep 17 00:00:00 2001 From: Benjamin Huth Date: Thu, 9 Jan 2025 16:46:47 +0100 Subject: [PATCH 2/4] clean --- Plugins/ExaTrkX/CMakeLists.txt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Plugins/ExaTrkX/CMakeLists.txt b/Plugins/ExaTrkX/CMakeLists.txt index 6d5236fa360..2b4722be391 100644 --- a/Plugins/ExaTrkX/CMakeLists.txt +++ b/Plugins/ExaTrkX/CMakeLists.txt @@ -1,10 +1,4 @@ -add_library( - ActsPluginExaTrkX - SHARED - src/buildEdges.cpp - src/ExaTrkXPipeline.cpp - src/BoostWalkthrough.cpp -) +add_library(ActsPluginExaTrkX SHARED src/buildEdges.cpp src/ExaTrkXPipeline.cpp) if(ACTS_EXATRKX_ENABLE_CUDA) target_compile_definitions(ActsPluginExaTrkX PUBLIC ACTS_EXATRKX_WITH_CUDA) From 8df2924227d15e1cf5f03599afc90607148e3019 Mon Sep 17 00:00:00 2001 From: Benjamin Huth Date: Thu, 9 Jan 2025 16:48:20 +0100 Subject: [PATCH 3/4] clean --- Plugins/ExaTrkX/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/Plugins/ExaTrkX/CMakeLists.txt b/Plugins/ExaTrkX/CMakeLists.txt index 2b4722be391..3ea5d405b09 100644 --- a/Plugins/ExaTrkX/CMakeLists.txt +++ b/Plugins/ExaTrkX/CMakeLists.txt @@ -2,7 +2,6 @@ add_library(ActsPluginExaTrkX SHARED src/buildEdges.cpp src/ExaTrkXPipeline.cpp) if(ACTS_EXATRKX_ENABLE_CUDA) target_compile_definitions(ActsPluginExaTrkX PUBLIC ACTS_EXATRKX_WITH_CUDA) - target_sources(ActsPluginExaTrkX PRIVATE src/CudaTrackBuilding.cu) endif() if(ACTS_EXATRKX_ENABLE_ONNX) From 76b6b138406443e9d2eabd1b0589d02630807d3d Mon Sep 17 00:00:00 2001 From: Benjamin Huth Date: Thu, 9 Jan 2025 17:32:34 +0100 Subject: [PATCH 4/4] update --- Plugins/ExaTrkX/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/Plugins/ExaTrkX/CMakeLists.txt b/Plugins/ExaTrkX/CMakeLists.txt index 3ea5d405b09..651c6e32a0f 100644 --- a/Plugins/ExaTrkX/CMakeLists.txt +++ b/Plugins/ExaTrkX/CMakeLists.txt @@ -23,8 +23,6 @@ if(ACTS_EXATRKX_ENABLE_TORCH) ) endif() -add_library(ActsPluginExaTrkX SHARED ${SOURCES}) - target_include_directories( ActsPluginExaTrkX PUBLIC