Use device id names where possible.

This commit is contained in:
Allison Vacanti 2018-08-29 13:47:51 -07:00
parent 731bb729f2
commit a8fa8d9184
6 changed files with 29 additions and 51 deletions

@ -32,7 +32,7 @@ void throwFailedRuntimeDeviceTransfer(const std::string& className,
vtkm::cont::DeviceAdapterId deviceId) vtkm::cont::DeviceAdapterId deviceId)
{ //Should we support typeid() instead of className? { //Should we support typeid() instead of className?
const std::string msg = "VTK-m was unable to transfer " + className + " to DeviceAdapter[id=" + const std::string msg = "VTK-m was unable to transfer " + className + " to DeviceAdapter[id=" +
std::to_string(deviceId.GetValue()) + std::to_string(deviceId.GetValue()) + ", name=" + deviceId.GetName() +
"]. This is generally caused by asking for execution on a DeviceAdapter that " "]. This is generally caused by asking for execution on a DeviceAdapter that "
"isn't compiled into VTK-m. In the case of CUDA it can also be caused by accidentally " "isn't compiled into VTK-m. In the case of CUDA it can also be caused by accidentally "
"compiling source files as C++ files instead of CUDA."; "compiling source files as C++ files instead of CUDA.";

@ -93,31 +93,28 @@ RuntimeDeviceTracker::~RuntimeDeviceTracker()
} }
VTKM_CONT VTKM_CONT
void RuntimeDeviceTracker::CheckDevice(vtkm::cont::DeviceAdapterId deviceId, void RuntimeDeviceTracker::CheckDevice(vtkm::cont::DeviceAdapterId deviceId) const
const vtkm::cont::DeviceAdapterNameType& deviceName) const
{ {
if (!deviceId.IsValueValid()) if (!deviceId.IsValueValid())
{ {
std::stringstream message; std::stringstream message;
message << "Device '" << deviceName << "' has invalid ID of " << (int)deviceId.GetValue(); message << "Device '" << deviceId.GetName() << "' has invalid ID of "
<< (int)deviceId.GetValue();
throw vtkm::cont::ErrorBadValue(message.str()); throw vtkm::cont::ErrorBadValue(message.str());
} }
} }
VTKM_CONT VTKM_CONT
bool RuntimeDeviceTracker::CanRunOnImpl(vtkm::cont::DeviceAdapterId deviceId, bool RuntimeDeviceTracker::CanRunOnImpl(vtkm::cont::DeviceAdapterId deviceId) const
const vtkm::cont::DeviceAdapterNameType& deviceName) const
{ {
this->CheckDevice(deviceId, deviceName); this->CheckDevice(deviceId);
return this->Internals->RuntimeValid[deviceId.GetValue()]; return this->Internals->RuntimeValid[deviceId.GetValue()];
} }
VTKM_CONT VTKM_CONT
void RuntimeDeviceTracker::SetDeviceState(vtkm::cont::DeviceAdapterId deviceId, void RuntimeDeviceTracker::SetDeviceState(vtkm::cont::DeviceAdapterId deviceId, bool state)
const vtkm::cont::DeviceAdapterNameType& deviceName,
bool state)
{ {
this->CheckDevice(deviceId, deviceName); this->CheckDevice(deviceId);
this->Internals->RuntimeValid[deviceId.GetValue()] = state; this->Internals->RuntimeValid[deviceId.GetValue()] = state;
} }
@ -167,18 +164,16 @@ void RuntimeDeviceTracker::DeepCopy(const vtkm::cont::RuntimeDeviceTracker& src)
} }
VTKM_CONT VTKM_CONT
void RuntimeDeviceTracker::ForceDeviceImpl(vtkm::cont::DeviceAdapterId deviceId, void RuntimeDeviceTracker::ForceDeviceImpl(vtkm::cont::DeviceAdapterId deviceId, bool runtimeExists)
const vtkm::cont::DeviceAdapterNameType& deviceName,
bool runtimeExists)
{ {
if (!runtimeExists) if (!runtimeExists)
{ {
std::stringstream message; std::stringstream message;
message << "Cannot force to device '" << deviceName message << "Cannot force to device '" << deviceId.GetName()
<< "' because that device is not available on this system"; << "' because that device is not available on this system";
throw vtkm::cont::ErrorBadValue(message.str()); throw vtkm::cont::ErrorBadValue(message.str());
} }
this->CheckDevice(deviceId, deviceName); this->CheckDevice(deviceId);
std::fill_n(this->Internals->RuntimeValid, VTKM_MAX_DEVICE_ADAPTER_ID, false); std::fill_n(this->Internals->RuntimeValid, VTKM_MAX_DEVICE_ADAPTER_ID, false);

@ -64,8 +64,7 @@ public:
template <typename DeviceAdapterTag> template <typename DeviceAdapterTag>
VTKM_CONT bool CanRunOn(DeviceAdapterTag device) const VTKM_CONT bool CanRunOn(DeviceAdapterTag device) const
{ {
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>; return this->CanRunOnImpl(device);
return this->CanRunOnImpl(device, Traits::GetName());
} }
/// Report a failure to allocate memory on a device, this will flag the /// Report a failure to allocate memory on a device, this will flag the
@ -76,8 +75,7 @@ public:
VTKM_CONT void ReportAllocationFailure(DeviceAdapterTag device, VTKM_CONT void ReportAllocationFailure(DeviceAdapterTag device,
const vtkm::cont::ErrorBadAllocation&) const vtkm::cont::ErrorBadAllocation&)
{ {
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>; this->SetDeviceState(device, false);
this->SetDeviceState(device, Traits::GetName(), false);
} }
/// Report a failure to allocate memory on a device, this will flag the /// Report a failure to allocate memory on a device, this will flag the
@ -85,10 +83,9 @@ public:
/// the filter. /// the filter.
/// ///
VTKM_CONT void ReportAllocationFailure(vtkm::cont::DeviceAdapterId deviceId, VTKM_CONT void ReportAllocationFailure(vtkm::cont::DeviceAdapterId deviceId,
const std::string& name,
const vtkm::cont::ErrorBadAllocation&) const vtkm::cont::ErrorBadAllocation&)
{ {
this->SetDeviceState(deviceId, name, false); this->SetDeviceState(deviceId, false);
} }
//@{ //@{
@ -96,15 +93,13 @@ public:
template <typename DeviceAdapterTag> template <typename DeviceAdapterTag>
VTKM_CONT void ReportBadDeviceFailure(DeviceAdapterTag device, const vtkm::cont::ErrorBadDevice&) VTKM_CONT void ReportBadDeviceFailure(DeviceAdapterTag device, const vtkm::cont::ErrorBadDevice&)
{ {
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>; this->SetDeviceState(device, false);
this->SetDeviceState(device, Traits::GetName(), false);
} }
VTKM_CONT void ReportBadDeviceFailure(vtkm::cont::DeviceAdapterId deviceId, VTKM_CONT void ReportBadDeviceFailure(vtkm::cont::DeviceAdapterId deviceId,
const std::string& name,
const vtkm::cont::ErrorBadDevice&) const vtkm::cont::ErrorBadDevice&)
{ {
this->SetDeviceState(deviceId, name, false); this->SetDeviceState(deviceId, false);
} }
//@} //@}
@ -114,9 +109,8 @@ public:
template <typename DeviceAdapterTag> template <typename DeviceAdapterTag>
VTKM_CONT void ResetDevice(DeviceAdapterTag device) VTKM_CONT void ResetDevice(DeviceAdapterTag device)
{ {
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>;
vtkm::cont::RuntimeDeviceInformation<DeviceAdapterTag> runtimeDevice; vtkm::cont::RuntimeDeviceInformation<DeviceAdapterTag> runtimeDevice;
this->SetDeviceState(device, Traits::GetName(), runtimeDevice.Exists()); this->SetDeviceState(device, runtimeDevice.Exists());
} }
/// Reset the tracker to its default state for default devices. /// Reset the tracker to its default state for default devices.
@ -180,8 +174,7 @@ public:
template <typename DeviceAdapterTag> template <typename DeviceAdapterTag>
VTKM_CONT void DisableDevice(DeviceAdapterTag device) VTKM_CONT void DisableDevice(DeviceAdapterTag device)
{ {
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>; this->SetDeviceState(device, false);
this->SetDeviceState(device, Traits::GetName(), false);
} }
/// \brief Disable all devices except the specified one. /// \brief Disable all devices except the specified one.
@ -199,9 +192,8 @@ public:
template <typename DeviceAdapterTag> template <typename DeviceAdapterTag>
VTKM_CONT void ForceDevice(DeviceAdapterTag device) VTKM_CONT void ForceDevice(DeviceAdapterTag device)
{ {
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>;
vtkm::cont::RuntimeDeviceInformation<DeviceAdapterTag> runtimeDevice; vtkm::cont::RuntimeDeviceInformation<DeviceAdapterTag> runtimeDevice;
this->ForceDeviceImpl(device, Traits::GetName(), runtimeDevice.Exists()); this->ForceDeviceImpl(device, runtimeDevice.Exists());
} }
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
@ -213,25 +205,19 @@ private:
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
VTKM_CONT VTKM_CONT
void CheckDevice(vtkm::cont::DeviceAdapterId deviceId, void CheckDevice(vtkm::cont::DeviceAdapterId deviceId) const;
const vtkm::cont::DeviceAdapterNameType& deviceName) const;
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
VTKM_CONT VTKM_CONT
bool CanRunOnImpl(vtkm::cont::DeviceAdapterId deviceId, bool CanRunOnImpl(vtkm::cont::DeviceAdapterId deviceId) const;
const vtkm::cont::DeviceAdapterNameType& deviceName) const;
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
VTKM_CONT VTKM_CONT
void SetDeviceState(vtkm::cont::DeviceAdapterId deviceId, void SetDeviceState(vtkm::cont::DeviceAdapterId deviceId, bool state);
const vtkm::cont::DeviceAdapterNameType& deviceName,
bool state);
VTKM_CONT_EXPORT VTKM_CONT_EXPORT
VTKM_CONT VTKM_CONT
void ForceDeviceImpl(vtkm::cont::DeviceAdapterId deviceId, void ForceDeviceImpl(vtkm::cont::DeviceAdapterId deviceId, bool runtimeExists);
const vtkm::cont::DeviceAdapterNameType& deviceName,
bool runtimeExists);
}; };
/// \brief Get the \c RuntimeDeviceTracker for the current thread. /// \brief Get the \c RuntimeDeviceTracker for the current thread.

@ -32,7 +32,6 @@ namespace detail
{ {
void HandleTryExecuteException(vtkm::cont::DeviceAdapterId deviceId, void HandleTryExecuteException(vtkm::cont::DeviceAdapterId deviceId,
const std::string& name,
vtkm::cont::RuntimeDeviceTracker& tracker) vtkm::cont::RuntimeDeviceTracker& tracker)
{ {
try try
@ -45,12 +44,12 @@ void HandleTryExecuteException(vtkm::cont::DeviceAdapterId deviceId,
std::cerr << "caught ErrorBadAllocation " << e.GetMessage() << std::endl; std::cerr << "caught ErrorBadAllocation " << e.GetMessage() << std::endl;
//currently we only consider OOM errors worth disabling a device for //currently we only consider OOM errors worth disabling a device for
//than we fallback to another device //than we fallback to another device
tracker.ReportAllocationFailure(deviceId, name, e); tracker.ReportAllocationFailure(deviceId, e);
} }
catch (vtkm::cont::ErrorBadDevice& e) catch (vtkm::cont::ErrorBadDevice& e)
{ {
std::cerr << "caught ErrorBadDevice: " << e.GetMessage() << std::endl; std::cerr << "caught ErrorBadDevice: " << e.GetMessage() << std::endl;
tracker.ReportBadDeviceFailure(deviceId, name, e); tracker.ReportBadDeviceFailure(deviceId, e);
} }
catch (vtkm::cont::ErrorBadType& e) catch (vtkm::cont::ErrorBadType& e)
{ {

@ -33,7 +33,6 @@ namespace detail
{ {
VTKM_CONT_EXPORT void HandleTryExecuteException(vtkm::cont::DeviceAdapterId, VTKM_CONT_EXPORT void HandleTryExecuteException(vtkm::cont::DeviceAdapterId,
const std::string&,
vtkm::cont::RuntimeDeviceTracker&); vtkm::cont::RuntimeDeviceTracker&);
template <typename DeviceTag, typename Functor, typename... Args> template <typename DeviceTag, typename Functor, typename... Args>
@ -52,8 +51,7 @@ inline bool TryExecuteIfValid(std::true_type,
} }
catch (...) catch (...)
{ {
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceTag>; detail::HandleTryExecuteException(tag, tracker);
detail::HandleTryExecuteException(tag, Traits::GetName(), tracker);
} }
} }

@ -131,9 +131,9 @@ public:
if (!this->Internals->Transfers[static_cast<std::size_t>(deviceId.GetValue())]) if (!this->Internals->Transfers[static_cast<std::size_t>(deviceId.GetValue())])
{ {
std::string msg = std::string msg =
"VTK-m was asked to transfer a VirtualObjectHandle for execution on DeviceAdapter " + "VTK-m was asked to transfer a VirtualObjectHandle for execution on DeviceAdapter '" +
std::to_string(deviceId.GetValue()) + deviceId.GetName() + "' (" + std::to_string(deviceId.GetValue()) +
". It can't as this VirtualObjectHandle was not constructed/bound with this " "). It can't as this VirtualObjectHandle was not constructed/bound with this "
"DeviceAdapter in the list of valid DeviceAdapters."; "DeviceAdapter in the list of valid DeviceAdapters.";
throw vtkm::cont::ErrorBadDevice(msg); throw vtkm::cont::ErrorBadDevice(msg);
} }