Celeritas 0.7.0-dev.354+develop.b4fe4c4
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
celeritas::Stream Class Reference

PIMPL class for CUDA or HIP stream. More...

#include <Stream.hh>

Classes

struct  Impl
 PIMPL class. More...
 

Public Types

Type aliases
using StreamT = std::nullptr_t
 Stream implementation is unavailable.
 
using ResourceT = std::nullptr_t
 Stream implementation is unavailable.
 
using HostKernel = void(*)(void *)
 Stream implementation is unavailable.
 

Public Member Functions

 Stream ()
 Construct by creating a stream with the active device context.
 
 Stream (std::nullptr_t)
 Construct a null stream.
 
 Stream (Device const &device)
 Construct a stream for the given device.
 
 Stream (Stream const &)=delete
 
Streamoperator= (Stream const &)=delete
 
 Stream (Stream &&)=default
 
Streamoperator= (Stream &&)=default
 
 operator bool () const
 Whether the stream is valid (not null or moved-from).
 
StreamT get () const
 Get the CUDA stream pointer.
 
ResourceTmemory_resource ()
 Get the Thrust async allocation resource.
 
voidmalloc_async (std::size_t bytes)
 Allocate memory asynchronously on this stream if possible.
 
void free_async (void *ptr)
 Free memory asynchronously on this stream if possible.
 
void sync () const
 Block host execution until stream operations are all complete.
 
void wait (DeviceEvent const &d)
 Block stream execution until the event completes.
 
void launch_host_func (HostKernel func, void *data)
 Enqueue delayed execution of a host function.
 

Detailed Description

PIMPL class for CUDA or HIP stream.

This creates/destroys a stream on construction/destruction and provides accessors to low-level stream-related functionality. This class will typically be accessed only by low-level device implementations or advanced kernels that need to interact with the device stream.

States
  • Constructed: A valid stream created with an active device. The stream can be used for device operations.
  • Null: Explicitly constructed with nullptr. No stream is created, but the object is in a valid null state. Operations are no-ops.
Warning
This class interface changes based on available headers. Because the CUDA/HIP stream type are only defined when those paths are included and available (which isn't true for all Celeritas code) we hide the stream unless DeviceRuntimeApi has been included or the file is being compiled by a CUDA/HIP compiler. Worse, our stream class has to manage a Thrust memory resource, and in newer versions of rocthrust, its headers cannot be included at all by a non-HIP compiler. Because this class forward declares the memory resource, downstream uses must include corecel/sys/detail/AsyncMemoryResource.device.hh .

Constructor & Destructor Documentation

◆ Stream() [1/2]

celeritas::Stream::Stream ( )

Construct by creating a stream with the active device context.

Precondition
A device must be active and configured.
Deprecated:
This constructor is ambiguous: remove it.

◆ Stream() [2/2]

celeritas::Stream::Stream ( Device const device)
explicit

Construct a stream for the given device.

This delegates to the default constructor, which creates a stream on the active device. The device reference is used to enforce that a valid device has been activated before stream creation.

Precondition
The device must be valid and active.

Member Function Documentation

◆ malloc_async()

void * celeritas::Stream::malloc_async ( std::size_t  bytes)

Allocate memory asynchronously on this stream if possible.

HIP 5.1 and lower does not support async allocation.


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