class nbla::SyncedArray

class SyncedArray : public std::enable_shared_from_this<SyncedArray>

Synchronized array interface that implicitly transfers and cast arrays over devices and data types.Shared pointer of SyncedArray.

Public Functions

Array *cast(dtypes dtype, const Context &ctx, bool write_only = false, const int async_flags = AsyncFlag::NONE)

Cast and get array with dtype context.

This will return an array object with specified dtype and device with implicit synchronization over different dtypes/devices.

Parameters:
  • write_only[in] When true, just returns an Array instance requested without synchronization.

  • async_flags[in] AsyncFlag::NONE -> Synchronous synchronization AsyncFlag::ASYNC -> Asynchronous synchronization AsyncFlag::UNSAFE -> No synchronization to host AsyncFlag::ASYNC | AsyncFlag::UNSAFE -> The memory region of the source array of an asynchronous data transfer is not guranteed to be kept safe until the end of the transfer.

shared_ptr<Array> cast_sp(dtypes dtype, const Context &ctx, bool write_only = false, const int async_flags = AsyncFlag::NONE)

Cast and get array as a shared_ptr.

See also

cast

const Array *get(dtypes dtype, const Context &ctx, const int async_flags = AsyncFlag::NONE)

Get array with dtype context.

This will return an array object with specified dtype and device with implicit synchronization. Note that this function call does not move the head in array list.

TODO: Is “const” member function appropriate? This implicitly creates or modify array contents of specified dtype-context.

shared_ptr<const Array> get_sp(dtypes dtype, const Context &ctx, const int async_flags = AsyncFlag::NONE)

Get array as a shared pointer.

Array *head_array()

Get the head array.

shared_ptr<Array> head_array_sp()

Get the head array as a shared pointer.

const void *data_ptr(dtypes dtype, const Context &ctx, bool write_only = false, const int async_flags = AsyncFlag::NONE)

Get array’s ptr.

Parameters:
  • dtype[in] Enum of data type.

  • ctx[in] Descriptor of array backend.

  • write_only[in] No synchronization happens.

  • async_flags[in] AsyncFlag::NONE -> Synchronous synchronization happens. AsyncFlag::ASYNC -> Asynchronous synchronization happens. AsyncFlag::SAFE -> Same as AsyncFlag::NONE. AsyncFlag::ASYNC | AsyncFlag::SAFE -> Asynchronous synchronization happens and the synchronized source array keeps safe against the host operation.

inline dtypes dtype() const

Get dtype.

inline bool has_head_array()

Returns true if this SyncedArray has the head array.

inline string head_array_class()

Get the array class of the head.

inline Size_t get_num_arrays() const

Get the number of arrays.

inline Size_t size() const

Size.

void zero()

Fill all element with 0.

Note: This is lazily evaluated at calling of get() or cast().

void fill(float value)

Fill all element with given float value.

size_t modification_count() const

Get number of modification count.

Modification accounts for calling either cast, zero or fill.

bool clear_called() const

Get clear called flag.

void copy_from(const SyncedArray *src)

Copy values from another SynedArray.

Note

The copy is happening in a device and a dtype of source array.

bool zeroing() const

Get whether or not it fills array values obtained in cast/get call later.

This is provided to determine gradient accumulation flags in our computation graph engine, as well as to determine whether or not solver and communicator execute their operations by depending on whether gradients are updated.

shared_ptr<SyncedArray> narrow(const Size_t narrow_size, const Size_t offset)

Get a new narrowed SyncedArray.

inline bool is_narrowed() const

Returns true if this SyncedArray is narrowed.

inline bool is_child() const

Returns true if this SyncedArray has the Parent.

inline bool is_root() const

Returns true if this SyncedArray has not the Parent.

inline bool has_family() const

Returns true if this SyncedArray has a parent or child SyncedArrays.

int get_python_user_reference_counts() const

Get the refernce counts from a Python user.

void update_python_user_reference_counts(const int diff)

Update the refernce counts from a Python user.