Skip to content
Snippets Groups Projects
Commit 9ae3098a authored by Robert Maynard's avatar Robert Maynard
Browse files

Give each thread using vtk a separate runtime device tracker

parent 9f51f4b7
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment