mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Give each thread using vtk a separate runtime device tracker
This commit is contained in:
parent
9f51f4b7e2
commit
9ae3098af8
@ -29,7 +29,10 @@
|
||||
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
#define VTKM_MAX_DEVICE_ADAPTER_ID 8
|
||||
|
||||
@ -155,8 +158,22 @@ void RuntimeDeviceTracker::ForceDeviceImpl(vtkm::cont::DeviceAdapterId deviceId,
|
||||
VTKM_CONT
|
||||
vtkm::cont::RuntimeDeviceTracker GetGlobalRuntimeDeviceTracker()
|
||||
{
|
||||
static vtkm::cont::RuntimeDeviceTracker globalTracker;
|
||||
return globalTracker;
|
||||
static std::mutex mtx;
|
||||
static std::map<std::thread::id, vtkm::cont::RuntimeDeviceTracker> globalTrackers;
|
||||
std::thread::id this_id = std::this_thread::get_id();
|
||||
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
auto iter = globalTrackers.find(this_id);
|
||||
if (iter != globalTrackers.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::cont::RuntimeDeviceTracker tracker;
|
||||
globalTrackers[this_id] = tracker;
|
||||
return tracker;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
@ -207,13 +207,13 @@ private:
|
||||
bool runtimeExists);
|
||||
};
|
||||
|
||||
/// \brief Get the global \c RuntimeDeviceTracker.
|
||||
/// \brief Get the \c RuntimeDeviceTracker for the current thread.
|
||||
///
|
||||
/// Many features in VTK-m will attempt to run algorithms on the "best
|
||||
/// available device." This often is determined at runtime as failures in
|
||||
/// one device are recorded and that device is disabled. To prevent having
|
||||
/// to check over and over again, VTK-m features generally use the global
|
||||
/// device adapter so that these choices are marked and shared.
|
||||
/// to check over and over again, VTK-m uses per thread runtime device tracker
|
||||
/// so that these choices are marked and shared.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
|
Loading…
Reference in New Issue
Block a user