From 84ac233e3d361c6b55f3f8c1e519c6b4ce9a3ba8 Mon Sep 17 00:00:00 2001 From: Andrey Alekseenko Date: Fri, 12 Mar 2021 15:46:48 +0000 Subject: [PATCH] Add DeviceAccessor ctor from const DeviceBuffer A bit hacky, but better preserves the intent behind declaring DeviceBuffer const. Part of preparatory work for #3932. --- src/gromacs/gpu_utils/devicebuffer_sycl.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gromacs/gpu_utils/devicebuffer_sycl.h b/src/gromacs/gpu_utils/devicebuffer_sycl.h index ff83c6d27c..187b7cf931 100644 --- a/src/gromacs/gpu_utils/devicebuffer_sycl.h +++ b/src/gromacs/gpu_utils/devicebuffer_sycl.h @@ -150,6 +150,18 @@ public: gmx::internal::PlaceholderAccessor(getSyclBuffer(buffer)) { } + //! Construct read-only Accessor from a const DeviceBuffer (must be initialized) + DeviceAccessor(const DeviceBuffer& buffer) : + gmx::internal::PlaceholderAccessor(getSyclBuffer(const_cast&>(buffer))) + { + /* There were some discussions about making it possible to create read-only sycl::accessor + * from a const sycl::buffer (https://github.com/KhronosGroup/SYCL-Docs/issues/10), but + * it did not make it into the SYCL2020 standard. So, we have to use const_cast above */ + /* Using static_assert to ensure that only mode::read accessors can be created from a + * const DeviceBuffer. static_assert provides better error messages than std::enable_if. */ + static_assert(mode == cl::sycl::access::mode::read, + "Can not create non-read-only accessor from a const DeviceBuffer"); + } private: //! Helper function to get sycl:buffer object from DeviceBuffer wrapper, with a sanity check. -- 2.22.0