7 #ifndef PXR_EXEC_VDF_PARALLEL_EXECUTOR_ENGINE_H
8 #define PXR_EXEC_VDF_PARALLEL_EXECUTOR_ENGINE_H
19 #include <tbb/concurrent_unordered_map.h>
39 template <
typename DataManagerType >
42 VdfParallelExecutorEngine<DataManagerType>,
67 DataManagerType *dataManager) :
68 Base(executor, dataManager)
100 void _FinalizeEvaluation();
113 void _PublishLockedBuffers();
125 const size_t numTasks);
153 std::unique_ptr<VdfMask[]> _masks;
158 std::atomic<size_t> _num;
169 _PublishLockedDataTask(
170 DataManagerType *dataManager,
172 _LockedData *lockedData) :
174 _dataHandle(dataHandle),
175 _lockedData(lockedData)
185 std::unique_ptr<_LockedData> _lockedData;
190 _LockedData *_InsertLockedData(
198 tbb::concurrent_unordered_map<typename Base::_DataHandle, _LockedData *>
200 _LockedDataMap _lockedDataMap;
205 template <
typename DataManagerType >
214 template <
typename DataManagerType >
219 Base::_dataManager->DataManagerType::Base::Touch(output);
222 template <
typename DataManagerType >
228 const typename Base::_DataHandle dataHandle,
233 if (passToOutput && Base::_dataManager->HasInvalidationTimestampMismatch(
235 Base::_dataManager->GetDataHandle(passToOutput->
GetId()))) {
236 _LockBuffer(state, outputId, dataHandle, invocationIndex);
240 template <
typename DataManagerType >
244 _PublishLockedBuffers();
247 template <
typename DataManagerType >
252 const typename Base::_DataHandle dataHandle,
260 typename _LockedDataMap::iterator it = _lockedDataMap.find(dataHandle);
261 _LockedData *lockedData = it == _lockedDataMap.end()
262 ? _InsertLockedData(state, outputId, dataHandle)
267 Base::_dataManager->GetPrivateBufferData(dataHandle);
281 template <
typename DataManagerType >
286 if (_lockedDataMap.empty()) {
292 Base::_isolatingDispatcher.Run(
293 [&lockedDataMap = _lockedDataMap, &taskGraph = Base::_taskGraph,
294 &dataManager = Base::_dataManager] {
297 for (
const auto &
data : lockedDataMap) {
301 _PublishLockedDataTask *
const task =
302 taskGraph.template AllocateTask<_PublishLockedDataTask>(
303 dataManager,
data.first,
data.second);
304 taskGraph.RunTask(task);
308 lockedDataMap.clear();
314 Base::_isolatingDispatcher.Wait();
317 template <
typename DataManagerType >
322 const typename Base::_DataHandle dataHandle)
333 _LockedData *newData =
new _LockedData(
339 std::pair<typename _LockedDataMap::iterator, bool> res =
340 _lockedDataMap.insert(std::make_pair(dataHandle, newData));
355 else if (tasks.
size() > 1) {
356 Base::_taskGraph.RunTask(
357 Base::_taskGraph.
template AllocateTask<
358 typename Base::_ComputeAllTask>(
this, state, node));
363 return res.first->second;
366 template <
typename DataManagerType >
372 _dataManager->GetPublicBufferData(_dataHandle);
375 _lockedData->TransferOwnership(publicBuffer);
381 template <
typename DataManagerType >
385 const size_t numTasks) :
398 _masks.reset(
new VdfMask[numTasks]);
401 template <
typename DataManagerType >
408 _value->Merge(value, mask);
412 const size_t maskIdx = _num.fetch_add(1, std::memory_order_release);
413 _masks[maskIdx] =
mask;
416 template <
typename DataManagerType >
422 const size_t num = _num.load(std::memory_order_acquire);
439 for (
size_t i = 1; i < num; ++i) {
440 unionBits |= _masks[i].GetBits();
448 value->
Merge(*_value, unionBits);
VdfParallelExecutorEngineBase< VdfParallelExecutorEngine< DataManagerType >, DataManagerType > Base
VdfParallelSpeculationExecutorEngine< DataManagerType > SpeculationExecutorEngine
void TakeOwnership(VdfVector *v)
VDF_API VdfVector * AllocateCache() const
Allocate a new VdfVector with this spec's type.
#define PXR_NAMESPACE_OPEN_SCOPE
GLsizei const GLfloat * value
DataManagerType * _dataManager
A VdfMask is placed on connections to specify the data flowing through them.
const VdfNode & GetNode() const
VDF_API const VdfOutputSpec & GetSpec() const
VdfMask::Bits const & GetBits() const
Fast, compressed bit array which is capable of performing logical operations without first decompress...
VDF_API const VdfOutput * GetOutput(const OutputId &outputId) const
const TaskIdRange GetComputeTaskIds(const VdfNode &node) const
#define PEE_TRACE_SCOPE(x)
Contains a specification of how to execute a particular VdfNetwork.
const VdfSchedule & GetSchedule() const
VDF_API void Merge(const VdfVector &rhs, const VdfMask::Bits &bits)
void SetExecutorCacheMask(const VdfMask &mask)
This object is responsible for storing the executor buffer data, comprised of the executor cache vect...
DataManagerType::DataHandle _DataHandle
const VdfMask & GetExecutorCacheMask() const
VDF_API const VdfMask & GetRequestMask(const OutputId &outputId) const
#define PXR_NAMESPACE_CLOSE_SCOPE
bool VdfScheduleTaskIsInvalid(uint32_t task)
uint32_t VdfScheduleTaskIndex
Abstract base class for classes that execute a VdfNetwork to compute a requested set of values...
VdfVector * GetExecutorCache() const
VDF_API void ResizeCache(VdfVector *vector, const VdfMask::Bits &bits) const
Resize an existing VdfVector to accomodate all the data set in the bits.
VdfParallelExecutorEngine(const VdfExecutorInterface &executor, DataManagerType *dataManager)