vtk-m/vtkm/cont/RuntimeDeviceTracker.h

124 lines
3.8 KiB
C
Raw Normal View History

2016-01-19 14:59:31 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_RuntimeDeviceTracker_h
#define vtk_m_cont_RuntimeDeviceTracker_h
2016-01-19 14:59:31 +00:00
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/ErrorBadAllocation.h>
2016-01-19 14:59:31 +00:00
#include <vtkm/cont/RuntimeDeviceInformation.h>
namespace vtkm {
namespace cont {
2016-01-19 14:59:31 +00:00
namespace detail {
struct RuntimeDeviceTrackerInternals;
}
2016-01-19 14:59:31 +00:00
/// A class that can be used to determine if a given device adapter
/// is supported on the current machine at runtime. This is a more
/// complex version of vtkm::cont::RunimeDeviceInformation, as this can
/// also track when worklets fail, why the fail, and will update the list
/// of valid runtime devices based on that information.
///
///
class VTKM_ALWAYS_EXPORT RuntimeDeviceTracker
2016-01-19 14:59:31 +00:00
{
public:
VTKM_CONT_EXPORT
VTKM_CONT
RuntimeDeviceTracker();
VTKM_CONT_EXPORT
VTKM_CONT
~RuntimeDeviceTracker();
2016-01-19 14:59:31 +00:00
/// Returns true if the given device adapter is supported on the current
/// machine.
///
template<typename DeviceAdapterTag>
VTKM_CONT
2016-01-19 14:59:31 +00:00
bool CanRunOn(DeviceAdapterTag) const
{
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>;
return this->CanRunOnImpl(Traits::GetId(), Traits::GetName());
2016-01-19 14:59:31 +00:00
}
/// Report a failure to allocate memory on a device, this will flag the
/// device as being unusable for all future invocations of the instance of
/// the filter.
2016-01-19 14:59:31 +00:00
///
template<typename DeviceAdapterTag>
VTKM_CONT
2016-01-19 14:59:31 +00:00
void ReportAllocationFailure(DeviceAdapterTag,
const vtkm::cont::ErrorBadAllocation&)
2016-01-19 14:59:31 +00:00
{
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>;
this->SetDeviceState(Traits::GetId(), Traits::GetName(), false);
2016-01-19 14:59:31 +00:00
}
/// Reset the tracker for the given device. This will discard any updates
/// caused by reported failures
2016-01-19 14:59:31 +00:00
///
template<typename DeviceAdapterTag>
VTKM_CONT
void ResetDevice(DeviceAdapterTag)
2016-01-19 14:59:31 +00:00
{
using Traits = vtkm::cont::DeviceAdapterTraits<DeviceAdapterTag>;
vtkm::cont::RuntimeDeviceInformation<DeviceAdapterTag> runtimeDevice;
this->SetDeviceState(Traits::GetId(),
Traits::GetName(),
runtimeDevice.Exists());
}
2016-01-19 14:59:31 +00:00
/// Reset the tracker to its default state for default devices.
/// Will discard any updates caused by reported failures.
///
VTKM_CONT_EXPORT
VTKM_CONT
void Reset();
2016-01-19 14:59:31 +00:00
private:
std::shared_ptr<detail::RuntimeDeviceTrackerInternals> Internals;
2016-01-19 14:59:31 +00:00
VTKM_CONT_EXPORT
VTKM_CONT
void CheckDevice(vtkm::cont::DeviceAdapterId deviceId,
const vtkm::cont::DeviceAdapterNameType &deviceName) const;
2016-01-19 14:59:31 +00:00
VTKM_CONT_EXPORT
VTKM_CONT
bool CanRunOnImpl(vtkm::cont::DeviceAdapterId deviceId,
const vtkm::cont::DeviceAdapterNameType &deviceName) const;
2016-01-19 14:59:31 +00:00
VTKM_CONT_EXPORT
VTKM_CONT
void SetDeviceState(vtkm::cont::DeviceAdapterId deviceId,
const vtkm::cont::DeviceAdapterNameType &deviceName,
bool state);
2016-01-19 14:59:31 +00:00
};
}
} // namespace vtkm::cont
2016-01-19 14:59:31 +00:00
#endif //vtk_m_filter_RuntimeDeviceTracker_h