1 //============================================================================ 2 // Copyright (c) Kitware, Inc. 3 // All rights reserved. 4 // See LICENSE.txt for details. 5 // 6 // This software is distributed WITHOUT ANY WARRANTY; without even 7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 8 // PURPOSE. See the above copyright notice for more information. 9 //============================================================================ 10 #ifndef vtk_m_cont_cuda_internal_DeviceAdapterTimerImplementationCuda_h 11 #define vtk_m_cont_cuda_internal_DeviceAdapterTimerImplementationCuda_h 12 13 #include <vtkm/cont/vtkm_cont_export.h> 14 15 #include <vtkm/Types.h> 16 17 #include <vtkm/cont/DeviceAdapterAlgorithm.h> 18 #include <vtkm/cont/cuda/internal/DeviceAdapterTagCuda.h> 19 20 #include <cuda.h> 21 22 namespace vtkm 23 { 24 namespace cont 25 { 26 27 /// 28 /// Specialization of DeviceAdapterTimerImplementation for CUDA 29 /// CUDA contains its own high resolution timer that are able 30 /// to track how long it takes to execute async kernels. 31 /// If we simply measured time on the CPU it would incorrectly 32 /// just capture how long it takes to launch a kernel. 33 template <> 34 class VTKM_CONT_EXPORT DeviceAdapterTimerImplementation<vtkm::cont::DeviceAdapterTagCuda> 35 { 36 public: 37 VTKM_CONT DeviceAdapterTimerImplementation(); 38 39 VTKM_CONT ~DeviceAdapterTimerImplementation(); 40 41 VTKM_CONT void Reset(); 42 43 VTKM_CONT void Start(); 44 45 VTKM_CONT void Stop(); 46 47 VTKM_CONT bool Started() const; 48 49 VTKM_CONT bool Stopped() const; 50 51 VTKM_CONT bool Ready() const; 52 53 VTKM_CONT vtkm::Float64 GetElapsedTime() const; 54 55 private: 56 // Copying CUDA events is problematic. 57 DeviceAdapterTimerImplementation( 58 const DeviceAdapterTimerImplementation<vtkm::cont::DeviceAdapterTagCuda>&) = delete; 59 void operator=(const DeviceAdapterTimerImplementation<vtkm::cont::DeviceAdapterTagCuda>&) = 60 delete; 61 62 bool StartReady; 63 bool StopReady; 64 cudaEvent_t StartEvent; 65 cudaEvent_t StopEvent; 66 }; 67 } 68 } // namespace vtkm::cont 69 70 71 #endif 72