Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:54:13

0001 /*
0002  * SPDX-PackageName: "covfie, a part of the ACTS project"
0003  * SPDX-FileCopyrightText: 2022 CERN
0004  * SPDX-License-Identifier: MPL-2.0
0005  */
0006 
0007 #pragma once
0008 
0009 #include <memory>
0010 
0011 #include <sycl/sycl.hpp>
0012 
0013 #include <covfie/sycl/utility/unique_ptr.hpp>
0014 
0015 namespace covfie::utility::sycl {
0016 template <typename T>
0017 unique_device_ptr<T> device_allocate(::sycl::queue & queue)
0018 {
0019     static_assert(
0020         !(std::is_array_v<T> && std::extent_v<T> == 0),
0021         "Allocation pointer type cannot be an unbounded array."
0022     );
0023 
0024     return unique_device_ptr<T>(
0025         ::sycl::malloc_device<T>(1, queue), device_deleter(queue)
0026     );
0027 }
0028 
0029 template <typename T>
0030 unique_device_ptr<T> device_allocate(std::size_t n, ::sycl::queue & queue)
0031 {
0032     static_assert(
0033         std::is_array_v<T>, "Allocation pointer type must be an array type."
0034     );
0035     static_assert(
0036         std::extent_v<T> == 0, "Allocation pointer type must be unbounded."
0037     );
0038 
0039     return unique_device_ptr<T>(
0040         ::sycl::malloc_device<std::remove_extent_t<T>>(n, queue),
0041         device_deleter(queue)
0042     );
0043 }
0044 
0045 template <typename T>
0046 unique_device_ptr<T[]> device_copy_h2d(const T * h, ::sycl::queue & queue)
0047 {
0048     unique_device_ptr<T[]> r = device_allocate<T[]>(queue);
0049 
0050     queue.memcpy(r.get(), h, sizeof(T)).wait();
0051 
0052     return r;
0053 }
0054 
0055 template <typename T>
0056 unique_device_ptr<T[]>
0057 device_copy_h2d(const T * h, std::size_t n, ::sycl::queue & queue)
0058 {
0059     unique_device_ptr<T[]> r = device_allocate<T[]>(n, queue);
0060 
0061     queue.memcpy(r.get(), h, n * sizeof(T)).wait();
0062 
0063     return r;
0064 }
0065 
0066 template <typename T>
0067 unique_device_ptr<T[]> device_copy_d2d(const T * h, ::sycl::queue & queue)
0068 {
0069     unique_device_ptr<T[]> r = device_allocate<T[]>(queue);
0070 
0071     queue.memcpy(r.get(), h, sizeof(T)).wait();
0072 
0073     return r;
0074 }
0075 
0076 template <typename T>
0077 unique_device_ptr<T[]>
0078 device_copy_d2d(const T * h, std::size_t n, ::sycl::queue & queue)
0079 {
0080     unique_device_ptr<T[]> r = device_allocate<T[]>(n, queue);
0081 
0082     queue.memcpy(r.get(), h, n * sizeof(std::remove_extent_t<T>)).wait();
0083 
0084     return r;
0085 }
0086 }