Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
USMPtrHolder.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
18#include "shambase/string.hpp"
20#include <memory>
21
22namespace sham {
23
24 template<USMKindTarget target>
26 size_t sz, std::shared_ptr<DeviceScheduler> dev_sched, std::optional<size_t> alignment) {
27
28 sycl::context &sycl_ctx = dev_sched->ctx->ctx;
29 sycl::device &dev = dev_sched->ctx->device->dev;
30 void *usm_ptr = details::internal_alloc<target>(sz, dev_sched, alignment);
31
32 return USMPtrHolder<target>(usm_ptr, sz, dev_sched);
33 }
34
35 template<USMKindTarget target>
37 std::shared_ptr<DeviceScheduler> dev_sched) {
38
39 sycl::context &sycl_ctx = dev_sched->ctx->ctx;
40 sycl::device &dev = dev_sched->ctx->device->dev;
41 void *usm_ptr = nullptr;
42
43 return USMPtrHolder<target>(usm_ptr, 0, dev_sched);
44 }
45
46 template<USMKindTarget target>
48 if (usm_ptr != nullptr) {
49 details::internal_free<target>(usm_ptr, get_bytesize(), dev_sched);
50 usm_ptr = nullptr;
51 }
52 }
53
54 template<USMKindTarget target>
56 free_ptr();
57 }
58
59 template class USMPtrHolder<device>;
60 template class USMPtrHolder<shared>;
61 template class USMPtrHolder<host>;
62
63} // namespace sham
This file contains the declaration of the USMPtrHolder class.
Class for holding a USM pointer.
void free_ptr()
Free the held pointer.
~USMPtrHolder()
USM pointer holder destructor.
static USMPtrHolder create(size_t sz, std::shared_ptr< DeviceScheduler > dev_sched, std::optional< size_t > alignment=std::nullopt)
Create a USM pointer holder.
This file contains the methods to actually allocate memory.
namespace for backends this one is named only sham since shambackends is too long to write