Distributed Ranges
Loading...
Searching...
No Matches
allocator.hpp
1// SPDX-FileCopyrightText: Intel Corporation
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#pragma once
6
7#include <dr/mp/global.hpp>
8
9namespace dr::mp::__detail {
10
11template <typename T> class allocator {
12
13public:
14 T *allocate(std::size_t sz) {
15 if (sz == 0) {
16 return nullptr;
17 }
18
19 T *mem = nullptr;
20
21 if (mp::use_sycl()) {
22#ifdef SYCL_LANGUAGE_VERSION
23 mem = sycl::malloc<T>(sz, sycl_queue(), sycl_mem_kind());
24#else
25 assert(false);
26#endif
27 } else {
28 mem = std_allocator_.allocate(sz);
29 }
30
31 assert(mem != nullptr);
32 return mem;
33 }
34
35 void deallocate(T *ptr, std::size_t sz) {
36 if (sz == 0) {
37 assert(ptr == nullptr);
38 return;
39 }
40 assert(ptr != nullptr);
41#ifdef SYCL_LANGUAGE_VERSION
42 if (mp::use_sycl()) {
43 sycl::free(ptr, sycl_queue());
44 return;
45 }
46#endif
47
48 std_allocator_.deallocate(ptr, sz);
49 }
50
51private:
52 std::allocator<T> std_allocator_;
53};
54
55} // namespace dr::mp::__detail
Definition: allocator.hpp:11