-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify vecmem/alpaka interaction #670
base: main
Are you sure you want to change the base?
Changes from all commits
7dbdf6b
923e1b6
f807b17
cb0bcdf
7ec7495
c31bcb2
286b2c4
2fb81d2
fb1cfaa
056984d
7cabd3d
15b65b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* traccc library, part of the ACTS project (R&D line) | ||
* | ||
* (c) 2024 CERN for the benefit of the ACTS project | ||
* | ||
* Mozilla Public License Version 2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
// VecMem include(s). | ||
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what the exact logic should be here... 🤔 Generally, I think I'd try to organise this code like: // define the generic host_device_types trait
#ifdef TRACCC_HAVE_VECMEM_CUDA
#include <vecmem/memory/cuda/device_memory_resource.hpp>
...
template <>
struct host_device_types<::alpaka::TagGpuCudaRt> {
using device_memory_resource = ::vecmem::cuda::host_memory_resource;
...
#endif
#ifdef TRACCC_HAVE_VECMEM_SYCL
#include <vecmem/memory/sycl/device_memory_resource.hpp>
...
#endif I.e. we should just depend on all the headers/libraries in this header that are available to us during the build. And declare the trait specializations for all the available types / environments. The decision about which environment is being chosen for the Alpaka build, should be a separate one. That choice should be able to select between all the available options, presented by this header. And yes, the |
||
#include <vecmem/memory/cuda/device_memory_resource.hpp> | ||
#include <vecmem/memory/cuda/host_memory_resource.hpp> | ||
#include <vecmem/memory/cuda/managed_memory_resource.hpp> | ||
#include <vecmem/utils/cuda/copy.hpp> | ||
|
||
#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) | ||
#include <vecmem/memory/hip/device_memory_resource.hpp> | ||
#include <vecmem/memory/hip/host_memory_resource.hpp> | ||
#include <vecmem/memory/hip/managed_memory_resource.hpp> | ||
#include <vecmem/utils/hip/copy.hpp> | ||
|
||
#elif defined(ALPAKA_ACC_SYCL_ENABLED) | ||
#include <vecmem/memory/sycl/device_memory_resource.hpp> | ||
#include <vecmem/memory/sycl/host_memory_resource.hpp> | ||
#include <vecmem/utils/sycl/copy.hpp> | ||
|
||
#else | ||
#include <vecmem/memory/memory_resource.hpp> | ||
#include <vecmem/utils/copy.hpp> | ||
#endif | ||
|
||
#include <alpaka/alpaka.hpp> | ||
|
||
// Forward declarations so we can compile the types below | ||
namespace vecmem { | ||
class host_memory_resource; | ||
class copy; | ||
namespace cuda { | ||
class host_memory_resource; | ||
class device_memory_resource; | ||
class managed_memory_resource; | ||
class copy; | ||
} // namespace cuda | ||
namespace hip { | ||
class host_memory_resource; | ||
class device_memory_resource; | ||
class managed_memory_resource; | ||
class copy; | ||
} // namespace hip | ||
namespace sycl { | ||
class host_memory_resource; | ||
class device_memory_resource; | ||
class managed_memory_resource; | ||
class copy; | ||
} // namespace sycl | ||
} // namespace vecmem | ||
|
||
namespace traccc::alpaka::vecmem { | ||
// For all CPU accelerators (except SYCL), just use host | ||
template <typename T> | ||
struct host_device_types { | ||
using device_memory_resource = ::vecmem::host_memory_resource; | ||
using host_memory_resource = ::vecmem::host_memory_resource; | ||
using managed_memory_resource = ::vecmem::host_memory_resource; | ||
using device_copy = ::vecmem::copy; | ||
}; | ||
template <> | ||
struct host_device_types<::alpaka::TagGpuCudaRt> { | ||
using device_memory_resource = ::vecmem::cuda::host_memory_resource; | ||
using host_memory_resource = ::vecmem::cuda::host_memory_resource; | ||
using managed_memory_resource = ::vecmem::cuda::managed_memory_resource; | ||
using device_copy = ::vecmem::cuda::copy; | ||
}; | ||
template <> | ||
struct host_device_types<::alpaka::TagGpuHipRt> { | ||
using device_memory_resource = ::vecmem::hip::device_memory_resource; | ||
using host_memory_resource = ::vecmem::hip::host_memory_resource; | ||
using managed_memory_resource = ::vecmem::hip::managed_memory_resource; | ||
using device_copy = ::vecmem::hip::copy; | ||
}; | ||
template <> | ||
struct host_device_types<::alpaka::TagCpuSycl> { | ||
using device_memory_resource = ::vecmem::sycl::device_memory_resource; | ||
using host_memory_resource = ::vecmem::sycl::host_memory_resource; | ||
using managed_memory_resource = ::vecmem::sycl::host_memory_resource; | ||
using device_copy = ::vecmem::sycl::copy; | ||
}; | ||
template <> | ||
struct host_device_types<::alpaka::TagFpgaSyclIntel> { | ||
using device_memory_resource = ::vecmem::sycl::device_memory_resource; | ||
using host_memory_resource = ::vecmem::sycl::host_memory_resource; | ||
using managed_memory_resource = ::vecmem::sycl::host_memory_resource; | ||
using device_copy = ::vecmem::sycl::copy; | ||
}; | ||
template <> | ||
struct host_device_types<::alpaka::TagGpuSyclIntel> { | ||
using device_memory_resource = ::vecmem::sycl::device_memory_resource; | ||
using host_memory_resource = ::vecmem::sycl::host_memory_resource; | ||
using device_copy = ::vecmem::sycl::copy; | ||
}; | ||
} // namespace traccc::alpaka::vecmem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not absolutely necessary to do it in this PR, but this header should eventually be in the
src/
directory. Generally we'll have to avoid any public dependence on the Alpaka headers in this library. Just like how we avoid any public CUDA or SYCL dependence in those libraries. (Not counting some coding mishaps, that still appear in some places...)