mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Use thread_local in GetGlobalRuntimeDeviceTracker if possible
It will reduce the cost of getting the thread runtime device tracker, and will have a better runtime overhead if user constructs a lot of short lived threads that use VTK-m.
This commit is contained in:
parent
53d50015f3
commit
c95db1fc78
@ -0,0 +1,5 @@
|
||||
# Use thread_local in GetGlobalRuntimeDeviceTracker function if possible
|
||||
|
||||
It will reduce the cost of getting the thread runtime device tracker,
|
||||
and will have a better runtime overhead if user constructs a lot of
|
||||
short lived threads that use VTK-m.
|
@ -158,6 +158,7 @@ void RuntimeDeviceTracker::ForceDeviceImpl(vtkm::cont::DeviceAdapterId deviceId,
|
||||
VTKM_CONT
|
||||
vtkm::cont::RuntimeDeviceTracker GetGlobalRuntimeDeviceTracker()
|
||||
{
|
||||
#if defined(VTKM_CLANG) && (__apple_build_version__ < 8000000)
|
||||
static std::mutex mtx;
|
||||
static std::map<std::thread::id, vtkm::cont::RuntimeDeviceTracker> globalTrackers;
|
||||
std::thread::id this_id = std::this_thread::get_id();
|
||||
@ -174,6 +175,9 @@ vtkm::cont::RuntimeDeviceTracker GetGlobalRuntimeDeviceTracker()
|
||||
globalTrackers[this_id] = tracker;
|
||||
return tracker;
|
||||
}
|
||||
#else
|
||||
return runtimeDeviceTracker;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
@ -237,6 +237,10 @@ private:
|
||||
/// to check over and over again, VTK-m uses per thread runtime device tracker
|
||||
/// so that these choices are marked and shared.
|
||||
///
|
||||
/// Xcode's clang only supports thread_local from version 8
|
||||
#if !(defined(VTKM_CLANG) && (__apple_build_version__ < 8000000))
|
||||
thread_local static vtkm::cont::RuntimeDeviceTracker runtimeDeviceTracker;
|
||||
#endif
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
vtkm::cont::RuntimeDeviceTracker GetGlobalRuntimeDeviceTracker();
|
||||
|
Loading…
Reference in New Issue
Block a user