Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
orrery::backend::UsmArray< T > Class Template Reference

An owning, movable, cache-line-aligned shared USM allocation. More...

#include <orrery/backend/sycl_usm.hpp>

Public Member Functions

 UsmArray () noexcept=default
 An empty array, owning nothing.
 UsmArray (sycl::queue &queue, std::size_t count)
 count default-initialised elements of shared USM from queue's device.
 UsmArray (const UsmArray &)=delete
UsmArrayoperator= (const UsmArray &)=delete
 UsmArray (UsmArray &&other) noexcept
UsmArrayoperator= (UsmArray &&other) noexcept
T * data () const noexcept
 The pointer, valid in host code and in device code alike.
std::size_t size () const noexcept
bool empty () const noexcept
std::span< T > span () const noexcept

Detailed Description

template<typename T>
class orrery::backend::UsmArray< T >

An owning, movable, cache-line-aligned shared USM allocation.

The project forbids owning raw pointers (section 4), and sycl::malloc_shared hands back exactly that, paired with a sycl::free that needs the same queue the allocation was made against. This is the RAII wrapper that makes the pair impossible to separate.

Aligned to a cache line for the reason core/aligned_allocator.hpp gives for the host arrays: the kernel reads these as contiguous component arrays, and an allocation that starts mid-line makes every vector load of the first elements straddle two lines. ADR-0005 sets out the argument, which does not stop being true because the reader is a GPU.

Constructor & Destructor Documentation

◆ UsmArray()

template<typename T>
orrery::backend::UsmArray< T >::UsmArray ( sycl::queue & queue,
std::size_t count )
inline

count default-initialised elements of shared USM from queue's device.

Throws std::bad_alloc when the runtime cannot satisfy the request, which is a setup-boundary failure of the kind section 4 permits exceptions at. No kernel is on the stack at this point.

Member Function Documentation

◆ data()

template<typename T>
T * orrery::backend::UsmArray< T >::data ( ) const
inlinenodiscardnoexcept

The pointer, valid in host code and in device code alike.

This is the property the whole file is about. The value returned here is what a kernel captures, and it is the same number the host dereferences.


The documentation for this class was generated from the following file: