CPPuddle
Loading...
Searching...
No Matches
sycl_underlying_allocators.hpp
Go to the documentation of this file.
1// Copyright (c) 2023-2024 Gregor Daiß
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef SYCL_UNDERLYING_ALLOCATORS_HPP
7#define SYCL_UNDERLYING_ALLOCATORS_HPP
8
9#include <CL/sycl.hpp>
10#include <stdexcept>
11#include <string>
12
13namespace cppuddle {
14namespace memory_recycling {
15namespace detail {
17template <class T> struct sycl_host_default_allocator {
18 using value_type = T;
19 sycl_host_default_allocator() noexcept = default;
20 template <class U>
22 T *allocate(std::size_t n) {
23 static cl::sycl::queue default_queue(cl::sycl::default_selector{});
24 T *data = cl::sycl::malloc_host<T>(n, default_queue);
25 return data;
26 }
27 void deallocate(T *p, std::size_t n) {
28 static cl::sycl::queue default_queue(cl::sycl::default_selector{});
29 cl::sycl::free(p, default_queue);
30 }
31};
32template <class T, class U>
34 sycl_host_default_allocator<U> const &) noexcept {
35 return true;
36}
37template <class T, class U>
39 sycl_host_default_allocator<U> const &) noexcept {
40 return false;
41}
42
44template <class T> struct sycl_device_default_allocator {
45 using value_type = T;
46 sycl_device_default_allocator() noexcept = default;
47 template <class U>
49 T *allocate(std::size_t n) {
50 static cl::sycl::queue default_queue(cl::sycl::default_selector{});
51 T *data = cl::sycl::malloc_device<T>(n, default_queue);
52 return data;
53 }
54 void deallocate(T *p, std::size_t n) {
55 static cl::sycl::queue default_queue(cl::sycl::default_selector{});
56 cl::sycl::free(p, default_queue);
57 }
58};
59template <class T, class U>
61 sycl_device_default_allocator<U> const &) noexcept {
62 return true;
63}
64template <class T, class U>
66 sycl_device_default_allocator<U> const &) noexcept {
67 return false;
68}
69
70} // end namespace detail
71} // namespace memory_recycling
72} // end namespace cppuddle
73
74#endif
constexpr bool operator!=(recycle_allocator< T, Host_Allocator > const &, recycle_allocator< U, Host_Allocator > const &) noexcept
Definition buffer_management.hpp:830
constexpr bool operator==(recycle_allocator< T, Host_Allocator > const &, recycle_allocator< U, Host_Allocator > const &) noexcept
Definition buffer_management.hpp:821
Definition config.hpp:31
Underlying allocator for SYCL device memory (using the sycl::default_selector{})
Definition sycl_underlying_allocators.hpp:44
T * allocate(std::size_t n)
Definition sycl_underlying_allocators.hpp:49
T value_type
Definition sycl_underlying_allocators.hpp:45
void deallocate(T *p, std::size_t n)
Definition sycl_underlying_allocators.hpp:54
Underlying host allocator for SYCL pinned memory (using the sycl::default_selector{})
Definition sycl_underlying_allocators.hpp:17
T value_type
Definition sycl_underlying_allocators.hpp:18
void deallocate(T *p, std::size_t n)
Definition sycl_underlying_allocators.hpp:27
T * allocate(std::size_t n)
Definition sycl_underlying_allocators.hpp:22