2014-06-10 18:53:34 +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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2014-06-10 18:53:34 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2014-06-10 18:53:34 +00:00
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2014-06-10 18:53:34 +00:00
|
|
|
// 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_Timer_h
|
|
|
|
#define vtk_m_cont_Timer_h
|
|
|
|
|
2019-01-09 16:11:49 +00:00
|
|
|
#include <vtkm/ListTag.h>
|
2014-06-10 18:53:34 +00:00
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
2019-01-09 16:11:49 +00:00
|
|
|
#include <vtkm/cont/DeviceAdapterListTag.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/vtkm_cont_export.h>
|
2014-06-10 18:53:34 +00:00
|
|
|
|
2019-02-28 18:32:09 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2019-01-09 16:11:49 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
class EnabledDeviceTimerImpls;
|
2019-02-28 18:32:09 +00:00
|
|
|
}
|
2014-06-10 18:53:34 +00:00
|
|
|
|
2019-01-09 16:11:49 +00:00
|
|
|
/// A class that can be used to time operations in VTK-m that might be occuring
|
|
|
|
/// in parallel. Users are recommended to provide a device adapter at construction
|
|
|
|
/// time which matches the one being used to execute algorithms to ensure that thread
|
|
|
|
/// synchronization is correct and accurate.
|
|
|
|
/// If no device adapter is provided at construction time, the maximum
|
|
|
|
/// elapsed time of all enabled deivces will be returned. Normally cuda is expected to
|
|
|
|
/// have the longest execution time if enabled.
|
|
|
|
/// Per device adapter time query is also supported. It's useful when users want to reuse
|
|
|
|
/// the same timer to measure the cuda kernal call as well as the cuda device execution.
|
2019-02-27 22:23:44 +00:00
|
|
|
/// It is also possible to change the device adapter after construction by calling the form
|
|
|
|
/// of the Reset method with a new DeviceAdapterId.
|
2014-06-10 18:53:34 +00:00
|
|
|
///
|
|
|
|
/// The there is no guaranteed resolution of the time but should generally be
|
|
|
|
/// good to about a millisecond.
|
|
|
|
///
|
2019-01-09 16:11:49 +00:00
|
|
|
class VTKM_CONT_EXPORT Timer
|
2014-06-10 18:53:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2019-01-09 16:11:49 +00:00
|
|
|
Timer();
|
|
|
|
|
2019-02-27 22:15:18 +00:00
|
|
|
VTKM_CONT Timer(vtkm::cont::DeviceAdapterId device);
|
2014-06-10 18:53:34 +00:00
|
|
|
|
2019-01-09 16:11:49 +00:00
|
|
|
VTKM_CONT ~Timer();
|
|
|
|
|
|
|
|
/// Resets the timer.
|
|
|
|
VTKM_CONT void Reset();
|
|
|
|
|
2019-02-27 22:23:44 +00:00
|
|
|
/// Resets the timer and changes the device to time on.
|
|
|
|
VTKM_CONT void Reset(vtkm::cont::DeviceAdapterId device);
|
|
|
|
|
2019-01-09 16:11:49 +00:00
|
|
|
/// Start would call Reset function before starting the timer for convenience
|
|
|
|
VTKM_CONT void Start();
|
|
|
|
|
|
|
|
VTKM_CONT void Stop();
|
|
|
|
|
2019-02-28 18:32:09 +00:00
|
|
|
VTKM_CONT bool Started() const;
|
2019-01-09 16:11:49 +00:00
|
|
|
|
2019-02-28 18:32:09 +00:00
|
|
|
VTKM_CONT bool Stopped() const;
|
2019-01-09 16:11:49 +00:00
|
|
|
|
|
|
|
/// Used to check if Timer has finished the synchronization to get the result from the device.
|
2019-02-28 18:32:09 +00:00
|
|
|
VTKM_CONT bool Ready() const;
|
2019-01-09 16:11:49 +00:00
|
|
|
|
|
|
|
/// Get the elapsed time measured by the given device adapter. If no device is
|
|
|
|
/// specified, the max time of all device measurements will be returned.
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2019-02-28 18:32:09 +00:00
|
|
|
vtkm::Float64 GetElapsedTime(
|
|
|
|
vtkm::cont::DeviceAdapterId id = vtkm::cont::DeviceAdapterTagAny()) const;
|
|
|
|
|
|
|
|
/// Returns the device for which this timer is synchronized. If the device adapter has the same
|
|
|
|
/// id as DeviceAdapterTagAny, then the timer will synchronize all devices.
|
|
|
|
VTKM_CONT vtkm::cont::DeviceAdapterId GetDevice() const { return this->Device; }
|
2014-06-10 18:53:34 +00:00
|
|
|
|
|
|
|
private:
|
2019-01-09 16:11:49 +00:00
|
|
|
VTKM_CONT void Init();
|
2014-06-10 18:53:34 +00:00
|
|
|
/// Some timers are ill-defined when copied, so disallow that for all timers.
|
2019-01-09 16:11:49 +00:00
|
|
|
VTKM_CONT Timer(const Timer&) = delete;
|
|
|
|
VTKM_CONT void operator=(const Timer&) = delete;
|
2014-06-10 18:53:34 +00:00
|
|
|
|
2019-01-09 16:11:49 +00:00
|
|
|
DeviceAdapterId Device;
|
2019-02-28 18:32:09 +00:00
|
|
|
std::unique_ptr<detail::EnabledDeviceTimerImpls> Internal;
|
2014-06-10 18:53:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
|
|
|
#endif //vtk_m_cont_Timer_h
|