class nbla::GlobalClearBufferState

class GlobalClearBufferState

Clear buffer flags maintained in a global scope (per thread).

This is used to inform nbla::Function class which buffer flag is used when the function is called. It’s used in the forward & backward function in the nbla::CgVariable class.

Public Functions

unique_ptr<ScopedState> state(bool clear_buffer, bool clear_no_need_grad)

Set clear buffer flags globally until the life of the returned object ends.

Note that this doesn’t affect any decision of clearing buffers in the graph exeuction. It’s used to just inform anyone of the current clear buffer flag. Also, please keep in mind that the returned ScopedState instance shouldn’t be owned by any globally maintained instance because it maintains a raw pointer of a global singleton instance of this class (GlobalClearBufferState).

// Set a global clear buffer flag as true.
auto clear_buffer_state =
  SingletonManager::get<GlobalClearBufferState>()->state(true, false);

// The following will return true until clear_buffer_state is
// destroyed (at exiting this scope).
auto c = SingletonManager::get<GlobalClearBufferState>()->clear_buffer();