cuda::experimental::places::data_place_replicated#

class data_place_replicated : public cuda::experimental::places::data_place_interface#

Replicated data place implementation.

One full copy of the data lives in each grid member’s affine memory. The data instance exposes replica 0; copies INTO the place fan out to the other replicas, and writes at the place are rejected at task creation, so a valid replicated instance is synced by construction. Each shard of a grid parallel_for reads its own replica (the dispatch rebases the instance per place).

Public Types

enum ord#

Special device ordinal values for non-device places.

Returned by get_device_ordinal() for places that don’t correspond to a specific CUDA device.

Values:

enumerator invalid = ::cuda::std::numeric_limits<int>::min()#
enumerator composite = -5#
enumerator device_auto = -4#
enumerator affine = -3#
enumerator managed = -2#
enumerator host = -1#

Public Functions

inline explicit data_place_replicated(
exec_place grid,
unsigned axes_mask = all_axes
)#

Bit a of axes_mask set = grid axis a is REPLICATED; unset axes are SHARED (their fibers use one common instance).

The default replicates over every axis (one copy per grid member).

inline data_place_replicated()#

Deferred form: the grid is bound at task acquisition.

inline virtual bool is_resolved() const override#

Whether this place is fully resolved and ready for allocation.

Returns true for places that represent a concrete memory target: host, managed, device(N), composite, green_ctx, etc. Returns false for abstract/deferred places that need further resolution: invalid, affine, device_auto.

inline virtual bool is_replicated() const noexcept override#

Whether this is a replicated data place (one copy per grid member)

inline virtual size_t instance_count() const override#

Number of data instances a dependency at this place resolves to: 1 for ordinary and composite places, one per grid member for a replicated place (see data_place::member for the r-th instance’s place)

inline size_t instance_of(size_t place_index) const#

Instance index of a linear grid place: mixed radix over the REPLICATED axes (dimension 0 fastest); shared-axis coordinates drop out.

inline size_t representative_place(size_t instance_index) const#

Linear grid place of the instance’s representative (shared coords = 0)

inline void validate_colocation() const#

Every fiber member of every instance must live at the SAME affine data place &#8212; “share” only means something where a common memory exists.

inline bool is_deferred() const noexcept#
inline virtual int get_device_ordinal() const override#

Get the device ordinal for this place.

Returns:

  • >= 0 for specific CUDA devices

  • data_place_ordinals::host (-1) for host

  • data_place_ordinals::managed (-2) for managed

  • data_place_ordinals::affine (-3) for affine

  • data_place_ordinals::device_auto (-4) for device_auto

  • data_place_ordinals::composite (-5) for composite

  • data_place_ordinals::invalid for invalid

inline virtual ::std::string to_string() const override#

Get a string representation of this place.

inline virtual size_t hash() const override#

Compute a hash value for this place.

inline virtual int cmp(
const data_place_interface &other
) const override#

Three-way comparison with another place.

Returns:

-1 if *this < other, 0 if *this == other, 1 if *this > other

inline virtual void *allocate(
::std::ptrdiff_t,
cudaStream_t
) const override#

Allocate memory at this place.

This is a standalone entry point: callers are not required to activate this place or make any particular device current beforehand, so implementations must not assume the calling thread’s current device (or context) matches this place. An implementation that needs to switch must restore the caller’s current device before returning.

Parameters:
  • size – Size of the allocation in bytes

  • stream – CUDA stream for stream-ordered allocations

Throws:

std::runtime_error – if allocation is not supported for this place type

Returns:

Pointer to allocated memory

inline virtual void deallocate(
void*,
size_t,
cudaStream_t
) const override#

Deallocate memory at this place.

Same standalone contract as allocate(): the caller’s current device is unspecified on entry and must be left unchanged on return.

Parameters:
  • ptr – Pointer to memory to deallocate

  • size – Size of the allocation

  • stream – CUDA stream for stream-ordered deallocations

inline virtual bool allocation_is_stream_ordered() const override#

Returns true if allocation/deallocation is stream-ordered.

inline ::std::shared_ptr<void> get_affine_exec_impl(
) const override#
inline const exec_place &get_grid() const noexcept#
inline virtual void *allocate_nd(
dim4 data_dims,
size_t elemsize,
cudaStream_t stream
) const#

Allocate memory at this place for a tensor with the given extents.

The default implementation ignores the tensor geometry and forwards to the byte-count allocate(); places whose physical placement depends on the geometry (composite places, whose partitioner maps element coordinates to places) override it with the real implementation.

Extents follow the dimension-0-fastest linearization convention of dim4::get_index() (the STF slice convention). Row-major callers should present reversed extents (and a coordinate-reversing partitioner).

The standalone contract of allocate() applies here as well: the caller’s current device is unspecified on entry and must be left unchanged on return.

Parameters:
  • data_dims – Extents of the tensor

  • elemsize – Size of one element in bytes

  • stream – CUDA stream for stream-ordered allocations

Returns:

Pointer to allocated memory

inline virtual CUresult mem_create(
CUmemGenericAllocationHandle *handle,
size_t size
) const#

Create a physical memory allocation for this place (VMM API)

Default implementation returns CUDA_ERROR_NOT_SUPPORTED. Subclasses that support VMM should override this.

Same standalone contract as allocate(): the caller’s current device is unspecified on entry and must be left unchanged on return. Placement must come from the explicit allocation properties (CUmemAllocationProp), not from the current device.

Parameters:
  • handle – Output parameter for the allocation handle

  • size – Size of the allocation in bytes

Returns:

CUresult indicating success or failure

inline virtual bool is_composite() const#

Whether this place is a composite place (data distributed over a grid of places by a partitioner)

inline virtual const partition_fn_t &get_partitioner() const#

Get the partitioner function for composite places.

Throws:

std::logic_error – if not a composite place