IExecutionContext#
Fully qualified name: omni::graph::exec::unstable::IExecutionContext
-
class IExecutionContext : public omni::core::Generated<omni::graph::exec::unstable::IExecutionContext_abi>#
Stores and provides access to the execution state of the graph.
The execution graph is only a description of what needs to be executed. The actual graph state is stored separately in an instance of this object.
The execution context allows computing the same graph description within multiple contexts. It also enables the ability to perform this computation concurrently. Some example use cases of this class:
Computing the state of a graph at a time different than the current time (e.g. asynchronous caching, fake dynamics)
Computing the state of a graph with a inputs different than the current input state (e.g. double solve)
All execution begins with a call to one of the execute methods on this interface. omni::graph::exec::unstable::IExecutionContext::execute() is used to execute the entire execution graph while omni::graph::exec::unstable::IExecutionContext::executeNode() can be used to execute only a part of the graph.
Part of this interface defines a key/value store. The key in this store is an omni::graph::exec::unstable::ExecutionPath. The value is an implementation of omni::graph::exec::unstable::IExecutionStateInfo, which in addition to storing computation state, can also store user defined data. The computation state and user data can be accessed with the
getStateInfo/getNodeDatamethods (though the latter is slightly faster) and set with thesetNodeData.Another feature of omni::graph::exec::unstable::IExecutionContext is the ability to quickly search for nodes using a particular definition and apply a function on them. Definitions can be searched by name or by pointer (see omni::graph::exec::unstable::IExecutionContext::applyOnEach()). These methods are used extensively during Graph Construction .
See Execution Concepts for an in-depth guide on how this object is used during execution.
- Thread Safety
Since multiple threads can concurrently traverse a graph, implementors of methods within this class should expect that multiple threads will be accessing this object in parallel.
Subclassed by omni::graph::exec::unstable::ImplementsCastWithoutAcquire< IExecutionContext, Rest… >
Public Functions
- inline Status execute(
- const ExecutionPath &path,
- omni::core::ObjectParam<INode> node,
On-demand execution method. Executes the given node.
The given path must not be
nullptr.The given node must not be
nullptr.See Error Handling to understand the error handling/reporting responsibilities of implementors of this method.
- Thread Safety
See thread safety information in interface description.
- inline IExecutionStateInfo *getStateInfo(
- const ExecutionTask &task,
Retrieves the state info for the node in the given task.
The task’s upstream path and node are hashed for the lookup.
The returned omni::graph::exec::unstable::IExecutionStateInfo will not have omni::core::IObject::acquire() called on it.
This method always returns a valid pointer.
See omni::graph::exec::unstable::IExecutionContext::getStateInfo_abi() for further details.
- Thread Safety
See thread safety information in interface description.
- inline IExecutionStateInfo *getStateInfo(
- const ExecutionPath &path,
Retrieves the state info at the given execution path.
The returned omni::graph::exec::unstable::IExecutionStateInfo will not have omni::core::IObject::acquire() called on it.
This method always returns a valid pointer.
See omni::graph::exec::unstable::IExecutionContext::getStateInfo_abi() for further details.
- Thread Safety
See thread safety information in interface description.
-
template<typename T>
inline T *getStateInfoAs( - const ExecutionTask &info,
Access state for the node in a given task. The returned object will be the given template type.
nullptrmay be returned if the retrieved omni::graph::exec::unstable::IExecutionStateInfo could not be casted toT.See omni::graph::exec::unstable::IExecutionContext::getStateInfo_abi() for further details.
- Thread Safety
See thread safety information in interface description.
-
template<typename T>
inline T *getStateInfoAs( - const ExecutionPath &path,
Access state for a given execution path. The returned object will be the given template type.
nullptrmay be returned if the retrieved omni::graph::exec::unstable::IExecutionStateInfo could not be casted toT.See omni::graph::exec::unstable::IExecutionContext::getStateInfo_abi() for further details.
- Thread Safety
See thread safety information in interface description.
-
template<typename T>
inline T *getStateInfoAs( - const ExecutionPath &path,
- omni::core::ObjectParam<INode> node,
Access state for a given node under the given execution path. The returned object will be the given template type.
nullptrmay be returned if the retrieved omni::graph::exec::unstable::IExecutionStateInfo could not be casted toT.The given
nodemay benullptr.See omni::graph::exec::unstable::IExecutionContext::getStateInfo_abi() for further details.
- Thread Safety
See thread safety information in interface description.
-
template<typename T>
inline omni::expected<Span<T>, omni::core::Result> getNodeDataAs( - omni::core::TypeId desiredType,
- const ExecutionPath &path,
- omni::core::ObjectParam<INode> node,
- NodeDataKey key,
Returns a pointer to a value stored in a node’s key/value datastore.
The node whose key/value datastore should be used is identified by combining the given
pathandnode.nodemay benullptr.The type
Tmust match the type specified indesiredType. Prefer using OMNI_GRAPH_EXEC_GET_NODE_DATA_AS() instead of this method, which will ensuredesiredTypeandTmatch.If
desiredTypedoes not match the type of the stored data, omni::core::kResultInvalidDataType is returned.If no data exists at the given
key(i.e omni::graph::exec::unstable::IExecutionContext::setNodeData() has not previously been called at the givenkey), omni::core::kResultNotFound is returned.The returned span may point to
nullptrif omni::graph::exec::unstable::IExecutionContext::setNodeData() was previously called with anullptrdata pointer.- Thread Safety
See thread safety information in interface description.
-
template<typename T>
inline omni::expected<Span<T>, omni::core::Result> getNodeDataAs( - omni::core::TypeId desiredType,
- const ExecutionTask &path,
- NodeDataKey key,
Returns a pointer to a value stored in a node’s key/value datastore.
The node whose key/value datastore should be used is identified by combining the given path and node in the given task.
The type
Tmust match the type specified indesiredType. Prefer using OMNI_GRAPH_EXEC_GET_NODE_DATA_AS() instead of this method, which will populate thedesiredTypefor you.If
desiredTypedoes not match the type of the stored data, omni::core::kResultInvalidDataType is returned.If no data exists at the given
key(i.e omni::graph::exec::unstable::IExecutionContext::setNodeData() has not previously been called at the givenkey), omni::core::kResultNotFound is returned.The returned span may point to
nullptrif omni::graph::exec::unstable::IExecutionContext::setNodeData() was previously called with anullptrdata pointer.- Thread Safety
See thread safety information in interface description.
-
template<typename SpecifiedT, typename DataT>
inline DataT *setNodeData( - omni::core::TypeId itemType,
- const ExecutionPath &path,
- omni::core::ObjectParam<INode> node,
- NodeDataKey key,
- std::unique_ptr<DataT> data,
Stores a value in a node’s key/value datastore.
The node whose key/value datastore should be used is identified by combining the given
pathandnode.nodemay benullptr.If a value is already stored at the given
keyit will be replaced.SpecifiedT,itemType, andDataTdescribe the type of the supplied data and must all be the same type. Prefer using OMNI_GRAPH_EXEC_SET_NODE_DATA() instead of this method, which will populate theitemTypefor you.datamay benullptr.Returns a pointer to
data.- Thread Safety
See thread safety information in interface description.
-
template<typename SpecifiedT, typename DataT>
inline DataT *setNodeData( - omni::core::TypeId itemType,
- const ExecutionTask &path,
- NodeDataKey key,
- std::unique_ptr<DataT> data,
Stores a value in a node’s key/value datastore.
The node whose key/value datastore should be used is identified by combining the given path and node in the given task.
If a value is already stored at the given
keyit will be replaced.SpecifiedT,itemType, andDataTdescribe the type of the supplied data and must all be the same type. Prefer using OMNI_GRAPH_EXEC_SET_NODE_DATA() instead of this method, which will populate theitemTypefor you.datamay benullptr.Returns a pointer to
data.- Thread Safety
See thread safety information in interface description.
-
template<typename Fn>
inline void applyOnEach(
) noexcept# Discover all execution paths leading to given definition and invoke given function with each of them.
This inline implementation wraps lambda into IApplyOnEachFunction
The supplied function should have the signature of
void(const ExecutionPath&).The given
callbackis free to invoke this method.- Thread Safety
The given function will be called serially by this method. However, other threads may also invoke this method, meaning the callback must coordinate access to shared data.
-
template<typename Fn>
inline void applyOnEach(
) noexcept# Discover all execution paths leading to definition with the given name and invoke the given function with each of them.
This inline implementation wraps lambda into IApplyOnEachFunction
The supplied function should have the signature of
void(const ExecutionPath&).The given
callbackis free to invoke this method.- Thread Safety
The given function will be called serially by this method. However, other threads may also invoke this method, meaning the callback must coordinate access to shared data.
- inline omni::graph::exec::unstable::Stamp getExecutionStamp(
Current execution version. Incremented with each execution of the context.
- Thread Safety
See thread safety information in interface description.
-
inline bool inExecute() noexcept#
Returns
trueif context is currently executing.- Thread Safety
See thread safety information in interface description.
-
inline bool isExecutingThread() noexcept#
Returns
trueif the current thread is one, of potentially many, which started this context’s execution. In other words, invoking this method in any thread that kickstarted this context’s execution will returntrue.When a given context’s execution from within a thread completes, that thread will no longer be associated with that context as a “kickstarting” thread, so any subsequent calls to this method from within that same thread will return
falseuntil execution is invoked on the context once again.Note, do not assume that the “main” thread acts as an evaluation kickstarter to any given context.
- Thread Safety
See thread safety information in interface description.
-
inline omni::graph::exec::unstable::Status execute() noexcept#
Main execution method. Executes the entire execution graph.
See Error Handling to understand the error handling/reporting responsibilities of implementors of this method.
- Thread Safety
See thread safety information in interface description.
- inline omni::graph::exec::unstable::Status executeNode(
- const omni::graph::exec::unstable::ExecutionPath &upstreamPath,
- omni::core::ObjectParam<omni::graph::exec::unstable::INode> node,
On-demand execution method. Executes the given node.
The given path must not be
nullptr.The given node must not be
nullptr.See Error Handling to understand the error handling/reporting responsibilities of implementors of this method.
- Thread Safety
See thread safety information in interface description.
-
inline void initialize() noexcept#
Context initialization. Responsible to propagate initialization to graphs.
- Thread Safety
See thread safety information in interface description.
- inline omni::graph::exec::unstable::IExecutionStateInfo *getStateInfo(
- const omni::graph::exec::unstable::ExecutionPath &path,
- omni::core::ObjectParam<omni::graph::exec::unstable::INode> node,
Access state for a given execution path.
If the given node is not
nullptr, a copy of the given path with the node appended will be used as the lookup key.This method always returns a valid pointer.
- Thread Safety
See thread safety information in interface description.
Warning
This method should be used for read only access by downstream nodes, example accessing graph state when executing downstream nodes. Extra care needs to be taken if this state has to be mutated concurrently.
-
inline void *castWithoutAcquire(omni::core::TypeId id) noexcept#
Casts this object to the type described the the given id.
Returns
nullptrif the cast was not successful.Unlike omni::core::IObject::cast(), this casting method does not call omni::core::IObject::acquire().
- Thread Safety
This method is thread safe.
-
inline uint32_t getUseCount() noexcept#
Returns the number of different instances (this included) referencing the current object.
- Thread Safety
This method is thread safe.
-
inline void *cast(omni::core::TypeId id) noexcept#
Returns a pointer to the interface defined by the given type id if this object implements the type id’s interface.
Objects can support multiple interfaces, even interfaces that are in different inheritance chains.
The returned object will have omni::core::IObject::acquire() called on it before it is returned, meaning it is up to the caller to call omni::core::IObject::release() on the returned pointer.
The returned pointer can be safely
reinterpret_cast<>to the type id’s C++ class. For example, “omni.windowing.IWindow” can be cast toomni::windowing::IWindow.Do not directly use this method, rather use a wrapper function like omni::core::cast() or omni::core::ObjectPtr::as().
- Thread Safety
This method is thread safe.
-
inline void acquire() noexcept#
Increments the object’s reference count.
Objects may have multiple reference counts (e.g. one per interface implemented). As such, it is important that you call omni::core::IObject::release() on the same pointer from which you called omni::core::IObject::acquire().
Do not directly use this method, rather use omni::core::ObjectPtr, which will manage calling omni::core::IObject::acquire() and omni::core::IObject::release() for you.
- Thread Safety
This method is thread safe.
-
inline void release() noexcept#
Decrements the objects reference count.
Most implementations will destroy the object if the reference count reaches 0 (though this is not a requirement).
Objects may have multiple reference counts (e.g. one per interface implemented). As such, it is important that you call omni::core::IObject::release() on the same pointer from which you called omni::core::IObject::acquire().
Do not directly use this method, rather use omni::core::ObjectPtr, which will manage calling omni::core::IObject::acquire() and omni::core::IObject::release() for you.
- Thread Safety
This method is thread safe.
Protected Functions
-
virtual Stamp getExecutionStamp_abi() noexcept = 0#
Current execution version. Incremented with each execution of the context.
- Thread Safety
See thread safety information in interface description.
-
virtual bool inExecute_abi() noexcept = 0#
Returns
trueif context is currently executing.- Thread Safety
See thread safety information in interface description.
-
virtual bool isExecutingThread_abi() noexcept = 0#
Returns
trueif the current thread is one, of potentially many, which started this context’s execution. In other words, invoking this method in any thread that kickstarted this context’s execution will returntrue.When a given context’s execution from within a thread completes, that thread will no longer be associated with that context as a “kickstarting” thread, so any subsequent calls to this method from within that same thread will return
falseuntil execution is invoked on the context once again.Note, do not assume that the “main” thread acts as an evaluation kickstarter to any given context.
- Thread Safety
See thread safety information in interface description.
-
virtual Status execute_abi() noexcept = 0#
Main execution method. Executes the entire execution graph.
See Error Handling to understand the error handling/reporting responsibilities of implementors of this method.
- Thread Safety
See thread safety information in interface description.
- virtual Status executeNode_abi(
- const ExecutionPath *upstreamPath,
- INode *node,
On-demand execution method. Executes the given node.
The given path must not be
nullptr.The given node must not be
nullptr.See Error Handling to understand the error handling/reporting responsibilities of implementors of this method.
- Thread Safety
See thread safety information in interface description.
-
virtual void initialize_abi() noexcept = 0#
Context initialization. Responsible to propagate initialization to graphs.
- Thread Safety
See thread safety information in interface description.
- virtual IExecutionStateInfo *getStateInfo_abi(
- const ExecutionPath *path,
- INode *node,
Access state for a given execution path.
If the given node is not
nullptr, a copy of the given path with the node appended will be used as the lookup key.This method always returns a valid pointer.
- Thread Safety
See thread safety information in interface description.
Warning
This method should be used for read only access by downstream nodes, example accessing graph state when executing downstream nodes. Extra care needs to be taken if this state has to be mutated concurrently.
- virtual omni::core::Result getNodeData_abi(
- const ExecutionPath *path,
- INode *node,
- NodeDataKey key,
- omni::core::TypeId *outTypeId,
- void **outPtr,
- uint64_t *outItemSize,
- uint64_t *outItemCount,
Returns a value from a node’s key/value datastore.
The node from which to grab data is identified by the given
pathandnode. Thenodemay benullptr.The
keyis used as a look-up in the node’s key/value datastore.The type of each data item is returned in
outTypeId.outPtrwill be updated with a pointer to the actual data.outPtrmust not benullptr.outItemSizestore the size of each item in the returned array.outItemSizemust not benullptroutItemCountcontains the number of items returned (i.e. the number of itemsoutPtrpoints to). For an array, this will be greater than 1.outItemCountmust not benullptr.If the key is not found, omni::core::kResultNotFound is returned.
The returned
datamay point tonullptrif omni::graph::exec::unstable::IExecutionContext::setNodeData() was previously called with anullptrdata pointer.pathmust not benullptr.See Error Handling to understand the error handling/reporting responsibilities of implementors of this method.
- Thread Safety
See thread safety information in interface description.
- virtual void setNodeData_abi(
- const ExecutionPath *path,
- INode *node,
- NodeDataKey key,
- omni::core::TypeId typeId,
- void *data,
- uint64_t itemSize,
- uint64_t itemCount,
- NodeDataDeleterFn *deleter,
Sets a value in a node’s key/value datastore.
The node in which to set the data is identified by the given path and node.
pathmust not benullptr. Thenodemay benullptr.The
keyis used as a look-up in the node’s key/value datastore.The type of each data item is set with
typeId.If data already exists at the given key, it will be replaced.
datapoints to an array of data items.datamay benullptr.itemSizeis the size of each item in the given array.itemCountcontains the number of items pointed to bydata. For an array, this will be greater than 1.deleteris a function used to deletedatawhen either a new value is set at the key or the context is invalidated. Ifdeleterisnullptr, it is up to the calling code to manage the lifetime of thedata.- Thread Safety
See thread safety information in interface description.
- virtual void applyOnEachDef_abi(
- IDef *def,
- IApplyOnEachFunction *callback,
Discover all execution paths leading to the given definition and invoke the given function with each of them.
Implementations of this interface may cache results to remove the traversal cost for subsequent call. Any change in the execution graph topology will invalidate this cache.
This method must not be called during graph construction.
defis the definition for which to look. This pointer may benullptr.callbackis the callback to execute with each path to given definition. This pointer must not benullptr.The given
callbackis free to invoke this method.- Thread Safety
The given
callbackwill be called serially by this method. However, other threads may also invoke this method, meaning thecallbackmust coordinate access to shared data.
- virtual void applyOnEachDefWithName_abi(
- const ConstName *name,
- IApplyOnEachFunction *callback,
Discover all execution paths leading to definitions with the given name and invoke the given function with each of them.
Implementation of this interface may cache results to remove the traversal cost for subsequent calls. Any change in the execution graph topology will invalidate this cache.
This method must not be called during graph construction.
nameis the name of definition for which to look. This pointer must not benullptr.callbackis the callback to execute with each path to given definition. This pointer must not benullptr.The given
callbackis free to invoke this method.- Thread Safety
The given
callbackwill be called serially by this method. However, other threads may also invoke this method, meaning thecallbackmust coordinate access to shared data.
- virtual void *castWithoutAcquire_abi( ) noexcept = 0#
Casts this object to the type described the the given id.
Returns
nullptrif the cast was not successful.Unlike omni::core::IObject::cast(), this casting method does not call omni::core::IObject::acquire().
- Thread Safety
This method is thread safe.
-
virtual uint32_t getUseCount_abi() noexcept = 0#
Returns the number of different instances (this included) referencing the current object.
- Thread Safety
This method is thread safe.
-
virtual void *cast_abi(TypeId id) noexcept = 0#
Returns a pointer to the interface defined by the given type id if this object implements the type id’s interface.
Objects can support multiple interfaces, even interfaces that are in different inheritance chains.
The returned object will have omni::core::IObject::acquire() called on it before it is returned, meaning it is up to the caller to call omni::core::IObject::release() on the returned pointer.
The returned pointer can be safely
reinterpret_cast<>to the type id’s C++ class. For example, “omni.windowing.IWindow” can be cast toomni::windowing::IWindow.Do not directly use this method, rather use a wrapper function like omni::core::cast() or omni::core::ObjectPtr::as().
- Thread Safety
This method is thread safe.
-
virtual void acquire_abi() noexcept = 0#
Increments the object’s reference count.
Objects may have multiple reference counts (e.g. one per interface implemented). As such, it is important that you call omni::core::IObject::release() on the same pointer from which you called omni::core::IObject::acquire().
Do not directly use this method, rather use omni::core::ObjectPtr, which will manage calling omni::core::IObject::acquire() and omni::core::IObject::release() for you.
- Thread Safety
This method is thread safe.
-
virtual void release_abi() noexcept = 0#
Decrements the objects reference count.
Most implementations will destroy the object if the reference count reaches 0 (though this is not a requirement).
Objects may have multiple reference counts (e.g. one per interface implemented). As such, it is important that you call omni::core::IObject::release() on the same pointer from which you called omni::core::IObject::acquire().
Do not directly use this method, rather use omni::core::ObjectPtr, which will manage calling omni::core::IObject::acquire() and omni::core::IObject::release() for you.
- Thread Safety
This method is thread safe.