diff --git a/Python/Plugins/CMakeLists.txt b/Python/Plugins/CMakeLists.txt index 5a3530a00b7..cf0fe9e754c 100644 --- a/Python/Plugins/CMakeLists.txt +++ b/Python/Plugins/CMakeLists.txt @@ -47,7 +47,6 @@ endmacro() add_plugin_binding_if(Gnn Acts::PluginGnn ACTS_BUILD_PLUGIN_GNN) add_plugin_binding_if(Covfie Acts::PluginCovfie ACTS_BUILD_PLUGIN_TRACCC) add_plugin_binding_if(Detray Acts::PluginDetray ACTS_BUILD_PLUGIN_TRACCC) -add_plugin_binding_if(Vecmem Acts::PluginDetray ACTS_BUILD_PLUGIN_TRACCC) add_plugin_binding_if(DD4hep ActsPluginDD4hep ACTS_BUILD_PLUGIN_DD4HEP) add_plugin_binding_if(Geant4 ActsPluginGeant4 ACTS_BUILD_PLUGIN_GEANT4) add_plugin_binding_if(GeoModel Acts::PluginGeoModel ACTS_BUILD_PLUGIN_GEOMODEL) @@ -56,5 +55,13 @@ add_plugin_binding_if(Svg Acts::PluginActSVG ACTS_BUILD_PLUGIN_ACTSVG) add_plugin_binding_if(TGeo Acts::PluginRoot ACTS_BUILD_PLUGIN_ROOT) add_plugin_binding_if(Root Acts::PluginRoot ACTS_BUILD_PLUGIN_ROOT) +# ---- Traccc: host always, device gated ---- +add_plugin_binding_if(TracccHost "traccc::core;traccc::device_common;traccc::io" ACTS_BUILD_PLUGIN_TRACCC) +add_plugin_binding_if(TracccCuda "traccc::cuda" ACTS_BUILD_PLUGIN_TRACCC AND ACTS_ENABLE_CUDA) + +# ---- Vecmem: host always, device gated ---- +add_plugin_binding_if(VecmemHost vecmem::core ACTS_BUILD_PLUGIN_TRACCC) +add_plugin_binding_if(VecmemCuda "vecmem::cuda;traccc::cuda" ACTS_BUILD_PLUGIN_TRACCC AND ACTS_ENABLE_CUDA) + # Propagate the list of built plugins to the parent scope set(_plugins_built "${_plugins_built}" PARENT_SCOPE) diff --git a/Python/Plugins/src/TracccCuda.cpp b/Python/Plugins/src/TracccCuda.cpp new file mode 100644 index 00000000000..8d8d3a941d5 --- /dev/null +++ b/Python/Plugins/src/TracccCuda.cpp @@ -0,0 +1,27 @@ +// 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 "ActsPython/Utilities/Helpers.hpp" +#include "ActsPython/Utilities/Macros.hpp" + +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace pybind11::literals; + +PYBIND11_MODULE(ActsPluginsPythonBindingsTraccc, traccc) { + auto cuda = traccc.def_submodule("cuda", "CUDA backend bindings"); + + py::class_>( + cuda, "stream") + .def(py::init<>()); +} diff --git a/Python/Plugins/src/TracccHost.cpp b/Python/Plugins/src/TracccHost.cpp new file mode 100644 index 00000000000..380f8a2bac1 --- /dev/null +++ b/Python/Plugins/src/TracccHost.cpp @@ -0,0 +1,33 @@ +// 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 "ActsPython/Utilities/Helpers.hpp" +#include "ActsPython/Utilities/Macros.hpp" + +#include +#include + +#include + +namespace py = pybind11; +using namespace pybind11::literals; + +PYBIND11_MODULE(ActsPluginsPythonBindingsTraccc, traccc) { + auto host = traccc.def_submodule("host", "CPU backend bindings"); + + // ---- traccc types ---- + py::class_>( + host, "memory_resource") + .def(py::init([](vecmem::memory_resource& main, + vecmem::memory_resource* host) { + return std::make_shared(main, host); + }), + py::arg("main"), py::arg("host") = nullptr, + py::keep_alive<1, 2>(), // keep main alive + py::keep_alive<1, 3>()); // keep host alive +} diff --git a/Python/Plugins/src/VecmemCuda.cpp b/Python/Plugins/src/VecmemCuda.cpp new file mode 100644 index 00000000000..6d75917c8e0 --- /dev/null +++ b/Python/Plugins/src/VecmemCuda.cpp @@ -0,0 +1,49 @@ +// 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 "ActsPython/Utilities/Helpers.hpp" +#include "ActsPython/Utilities/Macros.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace py = pybind11; +using namespace pybind11::literals; + +PYBIND11_MODULE(ActsPluginsPythonBindingsVecmem, vecmem) { + auto cuda = vecmem.def_submodule("cuda", "CUDA backend bindings"); + + py::class_>( + cuda, "host_memory_resource") + .def(py::init<>()); + + py::class_>( + cuda, "device_memory_resource") + .def(py::init<>()); + + py::class_>( + cuda, "stream") + .def(py::init<>()); + + py::class_>(cuda, "async_copy") + .def(py::init([](traccc::cuda::stream& s) { + return std::make_shared(s.cudaStream()); + }), + py::arg("stream"), py::keep_alive<1, 2>()); +} diff --git a/Python/Plugins/src/Vecmem.cpp b/Python/Plugins/src/VecmemHost.cpp similarity index 51% rename from Python/Plugins/src/Vecmem.cpp rename to Python/Plugins/src/VecmemHost.cpp index 91e503666e3..5ad43b4a55e 100644 --- a/Python/Plugins/src/Vecmem.cpp +++ b/Python/Plugins/src/VecmemHost.cpp @@ -13,20 +13,23 @@ #include #include -#include +#include namespace py = pybind11; using namespace pybind11::literals; PYBIND11_MODULE(ActsPluginsPythonBindingsVecmem, vecmem) { - { - py::class_>(vecmem, - "MemoryResource"); - - py::class_>( - vecmem, "HostMemoryResource") - .def(py::init<>()); - } + auto host = vecmem.def_submodule("host", "CPU backend bindings"); + + py::class_>( + host, "memory_resource"); + + py::class_>(vecmem, "copy"); + + py::class_>( + host, "host_memory_resource") + .def(py::init<>()); + py::class_>(host, "copy") + .def(py::init<>()); }