Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Namespaces | Functions
memoryHandle.hpp File Reference

This file contains the declaration of the memory handling and its methods. More...

#include "shambackends/MemPerfInfos.hpp"
#include "shambackends/USMPtrHolder.hpp"
#include "shambackends/details/BufferEventHandler.hpp"
#include "shambackends/details/internal_alloc.hpp"
+ Include dependency graph for memoryHandle.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  sham
 namespace for backends this one is named only sham since shambackends is too long to write
 

Functions

template<USMKindTarget target>
USMPtrHolder< target > sham::details::create_usm_ptr (size_t size, std::shared_ptr< DeviceScheduler > dev_sched, std::optional< size_t > alignment=std::nullopt)
 Create a USM pointer with at least the given size in bytes.
 
template<USMKindTarget target>
void sham::details::release_usm_ptr (USMPtrHolder< target > &&usm_ptr_hold, details::BufferEventHandler &&events)
 Release a USM pointer.
 

Detailed Description

This file contains the declaration of the memory handling and its methods.

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

The memoryHandle class is used to allocate SYCL memory. It provides a way to safely allocate, use, and deallocate memory in SYCL. This file should always be used to allocate SYCL memory, as it ensures correct memory management (including memory pooling).

Usage

To allocate SYCL memory, use the create_usm_ptr method . Here is an example:

// Allocate 1024 bytes of SYCL device memory
auto ptr = sham::details::create_usm_ptr<device>(1024, device_scheduler);

After using the SYCL memory, make sure to deallocate it using the deallocate_usm_ptr method.

// Give memory back to the memory manager (potentially pooling memory)
sham::details::memoryHandle::deallocate_usm_ptr(ptr_holder, events);

details

The memoryHandle class uses the USMPtrHolder class to manage the memory. The USMPtrHolder class is a smart pointer that manages the memory allocated using SYCL unified shared memory (USM). It provides a way to safely allocate, use, and deallocate memory in USM.

Definition in file memoryHandle.hpp.

Function Documentation

◆ create_usm_ptr()

template<USMKindTarget target>
USMPtrHolder< target > sham::details::create_usm_ptr ( size_t  size,
std::shared_ptr< DeviceScheduler dev_sched,
std::optional< size_t >  alignment = std::nullopt 
)

Create a USM pointer with at least the given size in bytes.

Note
The USM pointer may have a larger allocation than the required size.
Todo:
should be renamed to aquire_...
Template Parameters
targetThe target of the USM pointer.
Parameters
sizeThe size of the pointer in bytes.
dev_schedPointer to the device scheduler.
alignmentThe alignment of the USM pointer (optional).
Returns
USMPtrHolder<target> The newly created USM pointer.

Definition at line 30 of file memoryHandle.cpp.

+ Here is the call graph for this function:

◆ release_usm_ptr()

template<USMKindTarget target>
void sham::details::release_usm_ptr ( USMPtrHolder< target > &&  usm_ptr_hold,
details::BufferEventHandler &&  events 
)

Release a USM pointer.

Template Parameters
targetThe target of the USM pointer.
Parameters
usm_ptr_holdThe USM pointer holder to release.
eventsThe event handler to wait for completion.

Definition at line 47 of file memoryHandle.cpp.

+ Here is the call graph for this function: