From 415252c6626bb28ee1e6f666380c820a77ecc9e0 Mon Sep 17 00:00:00 2001 From: Haocheng LIU Date: Wed, 9 Jan 2019 11:11:49 -0500 Subject: [PATCH] Introduce asynchronous and device independent timer The timer class now is asynchronous and device independent. it's using an similiar API as vtkOpenGLRenderTimer with Start(), Stop(), Reset(), Ready(), and GetElapsedTime() function. For convenience and backward compability, Each Start() function call will call Reset() internally and each GetElapsedTime() function call will call Stop() function if it hasn't been called yet for keeping backward compatibility purpose. Bascially it can be used in two modes: * Create a Timer without any device info. vtkm::cont::Timer time; * It would enable timers for all enabled devices on the machine. Users can get a specific elapsed time by passing a device id into the GetElapsedtime function. If no device is provided, it would pick the maximum of all timer results - the logic behind this decision is that if cuda is disabled, openmp, serial and tbb roughly give the same results; if cuda is enabled it's safe to return the maximum elapsed time since users are more interested in the device execution time rather than the kernal launch time. The Ready function can be handy here to query the status of the timer. * Create a Timer with a device id. vtkm::cont::Timer time((vtkm::cont::DeviceAdapterTagCuda())); * It works as the old timer that times for a specific device id. --- benchmarking/BenchmarkArrayTransfer.cxx | 27 +- benchmarking/BenchmarkAtomicArray.cxx | 33 ++- benchmarking/BenchmarkCopySpeeds.cxx | 4 +- benchmarking/BenchmarkDeviceAdapter.cxx | 44 ++- benchmarking/BenchmarkFieldAlgorithms.cxx | 46 +++- benchmarking/BenchmarkFilters.cxx | 38 ++- benchmarking/BenchmarkRayTracing.cxx | 3 +- benchmarking/BenchmarkTopologyAlgorithms.cxx | 21 +- .../asynchronize-device-independent-timer.md | 65 +++++ examples/clipping/Clipping.cxx | 10 +- .../contour_tree_augmented/ContourTreeApp.cxx | 4 +- examples/game_of_life/GameOfLife.cxx | 3 +- examples/hello_world/HelloWorld.cxx | 3 +- examples/unified_memory/UnifiedMemory.cu | 6 +- vtkm/cont/CMakeLists.txt | 1 + vtkm/cont/DeviceAdapterAlgorithm.h | 62 ++++- vtkm/cont/Timer.cxx | 254 ++++++++++++++++++ vtkm/cont/Timer.h | 83 ++++-- .../DeviceAdapterTimerImplementationCuda.cu | 61 ++++- .../DeviceAdapterTimerImplementationCuda.h | 14 +- .../tbb/internal/DeviceAdapterAlgorithmTBB.h | 48 +++- vtkm/cont/testing/TestingDeviceAdapter.h | 28 +- vtkm/cont/testing/UnitTestTimer.cxx | 90 ++++++- vtkm/filter/ContourTreeUniformAugmented.hxx | 5 +- vtkm/rendering/MapperCylinder.cxx | 7 +- vtkm/rendering/MapperPoint.cxx | 7 +- vtkm/rendering/MapperQuad.cxx | 7 +- vtkm/rendering/MapperRayTracer.cxx | 7 +- vtkm/rendering/MapperVolume.cxx | 7 +- .../raytracing/BoundingVolumeHierarchy.cxx | 17 +- vtkm/rendering/raytracing/Camera.cxx | 8 +- .../raytracing/ConnectivityTracer.cxx | 15 +- .../raytracing/MeshConnectivityBuilder.cxx | 18 +- .../raytracing/MeshConnectivityContainers.cxx | 1 - vtkm/rendering/raytracing/RayTracer.cxx | 11 +- .../raytracing/VolumeRendererStructured.cxx | 9 +- vtkm/worklet/ContourTreeUniformAugmented.h | 24 +- vtkm/worklet/KernelSplatter.h | 6 +- vtkm/worklet/VertexClustering.h | 21 +- .../UnitTestBoundingIntervalHierarchy.cxx | 9 +- .../testing/UnitTestWaveletCompressor.cxx | 27 +- .../testing/UnitTestWaveletGenerator.cxx | 3 +- vtkm/worklet/wavelets/WaveletDWT.h | 37 +-- 43 files changed, 950 insertions(+), 244 deletions(-) create mode 100644 docs/changelog/asynchronize-device-independent-timer.md create mode 100644 vtkm/cont/Timer.cxx diff --git a/benchmarking/BenchmarkArrayTransfer.cxx b/benchmarking/BenchmarkArrayTransfer.cxx index f09718afa..7bbc9d161 100644 --- a/benchmarking/BenchmarkArrayTransfer.cxx +++ b/benchmarking/BenchmarkArrayTransfer.cxx @@ -45,7 +45,7 @@ struct BenchmarkArrayTransfer { using Algo = vtkm::cont::DeviceAdapterAlgorithm; using StorageTag = vtkm::cont::StorageTagBasic; - using Timer = vtkm::cont::Timer; + using Timer = vtkm::cont::Timer; //------------- Functors for benchmarks -------------------------------------- @@ -171,7 +171,8 @@ struct BenchmarkArrayTransfer ArrayType array = vtkm::cont::make_ArrayHandle(vec); // Time the copy: - Timer timer; + Timer timer{ DeviceAdapter() }; + timer.Start(); ReadValues functor(array.PrepareForInput(DeviceAdapter()), ValueTypeTraits::ZeroInitialization()); Algo::Schedule(functor, this->NumValues); @@ -212,9 +213,11 @@ struct BenchmarkArrayTransfer ArrayType array; // Time the write: - Timer timer; + Timer timer{ DeviceAdapter() }; + timer.Start(); WriteValues functor(array.PrepareForOutput(this->NumValues, DeviceAdapter())); Algo::Schedule(functor, this->NumValues); + return timer.GetElapsedTime(); } }; @@ -254,7 +257,8 @@ struct BenchmarkArrayTransfer ArrayType array = vtkm::cont::make_ArrayHandle(vec); // Time the copy: - Timer timer; + Timer timer{ DeviceAdapter() }; + timer.Start(); ReadWriteValues functor(array.PrepareForInPlace(DeviceAdapter())); Algo::Schedule(functor, this->NumValues); return timer.GetElapsedTime(); @@ -301,7 +305,8 @@ struct BenchmarkArrayTransfer array.ReleaseResourcesExecution(); // Time the copy: - Timer timer; + Timer timer{ DeviceAdapter() }; + timer.Start(); // Copy to device: ReadValues functor(array.PrepareForInput(DeviceAdapter()), @@ -360,7 +365,8 @@ struct BenchmarkArrayTransfer array.ReleaseResourcesExecution(); // Time the copy: - Timer timer; + Timer timer{ DeviceAdapter() }; + timer.Start(); // Do work on device: ReadWriteValues functor(array.PrepareForInPlace(DeviceAdapter())); @@ -411,7 +417,8 @@ struct BenchmarkArrayTransfer ArrayType array; // Time the copy: - Timer timer; + Timer timer{ DeviceAdapter() }; + timer.Start(); // Allocate/write data on device WriteValues functor(array.PrepareForOutput(this->NumValues, DeviceAdapter())); @@ -464,7 +471,8 @@ struct BenchmarkArrayTransfer ArrayType array; // Time the copy: - Timer timer; + Timer timer{ DeviceAdapter() }; + timer.Start(); // Allocate/write data on device WriteValues functor(array.PrepareForOutput(this->NumValues, DeviceAdapter())); @@ -516,7 +524,8 @@ struct BenchmarkArrayTransfer ArrayType array; // Time the copy: - Timer timer; + Timer timer{ DeviceAdapter() }; + timer.Start(); // Allocate/write data on device WriteValues functor(array.PrepareForOutput(this->NumValues, DeviceAdapter())); diff --git a/benchmarking/BenchmarkAtomicArray.cxx b/benchmarking/BenchmarkAtomicArray.cxx index d829df534..92b5cb495 100644 --- a/benchmarking/BenchmarkAtomicArray.cxx +++ b/benchmarking/BenchmarkAtomicArray.cxx @@ -62,7 +62,7 @@ class BenchmarkAtomicArray { public: using Algo = vtkm::cont::DeviceAdapterAlgorithm; - using Timer = vtkm::cont::Timer; + using Timer = vtkm::cont::Timer; // Benchmarks AtomicArray::Add such that each work index writes to adjacent // indices. @@ -102,8 +102,10 @@ public: auto portal = array.PrepareForExecution(Device{}); Worker worker{ this->ArraySize, portal }; - Timer timer; + Timer timer{ Device() }; + timer.Start(); Algo::Schedule(worker, NumWrites); + return timer.GetElapsedTime(); } @@ -156,8 +158,10 @@ public: auto portal = this->Data.PrepareForOutput(this->ArraySize, Device{}); Worker worker{ this->ArraySize, portal }; - Timer timer; + Timer timer{ Device() }; + timer.Start(); Algo::Schedule(worker, NumWrites); + return timer.GetElapsedTime(); } @@ -217,8 +221,10 @@ public: auto portal = array.PrepareForExecution(Device{}); Worker worker{ this->ArraySize, this->Stride, portal }; - Timer timer; + Timer timer{ Device() }; + timer.Start(); Algo::Schedule(worker, NumWrites); + return timer.GetElapsedTime(); } @@ -276,8 +282,10 @@ public: auto portal = this->Data.PrepareForOutput(this->ArraySize, Device{}); Worker worker{ this->ArraySize, this->Stride, portal }; - Timer timer; + Timer timer{ Device() }; + timer.Start(); Algo::Schedule(worker, NumWrites); + return timer.GetElapsedTime(); } @@ -342,8 +350,10 @@ public: auto portal = array.PrepareForExecution(Device{}); Worker worker{ this->ArraySize, portal }; - Timer timer; + Timer timer{ Device() }; + timer.Start(); Algo::Schedule(worker, NumWrites); + return timer.GetElapsedTime(); } @@ -398,7 +408,8 @@ public: auto portal = this->Data.PrepareForOutput(this->ArraySize, Device{}); Worker worker{ this->ArraySize, portal }; - Timer timer; + Timer timer{ Device() }; + timer.Start(); Algo::Schedule(worker, NumWrites); return timer.GetElapsedTime(); } @@ -468,8 +479,10 @@ public: auto portal = array.PrepareForExecution(Device{}); Worker worker{ this->ArraySize, this->Stride, portal }; - Timer timer; + Timer timer{ Device() }; + timer.Start(); Algo::Schedule(worker, NumWrites); + return timer.GetElapsedTime(); } @@ -529,8 +542,10 @@ public: auto portal = this->Data.PrepareForOutput(this->ArraySize, Device{}); Worker worker{ this->ArraySize, this->Stride, portal }; - Timer timer; + Timer timer{ Device() }; + timer.Start(); Algo::Schedule(worker, NumWrites); + return timer.GetElapsedTime(); } diff --git a/benchmarking/BenchmarkCopySpeeds.cxx b/benchmarking/BenchmarkCopySpeeds.cxx index 6b56f7025..beaf2e1a9 100644 --- a/benchmarking/BenchmarkCopySpeeds.cxx +++ b/benchmarking/BenchmarkCopySpeeds.cxx @@ -74,8 +74,10 @@ struct MeasureCopySpeed VTKM_CONT vtkm::Float64 operator()() { - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ DeviceAdapter() }; + timer.Start(); Algo::Copy(this->Source, this->Destination); + return timer.GetElapsedTime(); } diff --git a/benchmarking/BenchmarkDeviceAdapter.cxx b/benchmarking/BenchmarkDeviceAdapter.cxx index 3cb5dd5af..2cb14edb5 100644 --- a/benchmarking/BenchmarkDeviceAdapter.cxx +++ b/benchmarking/BenchmarkDeviceAdapter.cxx @@ -177,7 +177,7 @@ class BenchmarkDeviceAdapter using Algorithm = vtkm::cont::DeviceAdapterAlgorithm; - using Timer = vtkm::cont::Timer; + using Timer = vtkm::cont::Timer; public: // Various kernels used by the different benchmarks to accelerate @@ -284,8 +284,10 @@ private: VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Algorithm::Copy(ValueHandle_src, ValueHandle_dst); + return timer.GetElapsedTime(); } @@ -331,8 +333,10 @@ private: VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Algorithm::CopyIf(ValueHandle, StencilHandle, OutHandle); + return timer.GetElapsedTime(); } @@ -388,8 +392,10 @@ private: VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Algorithm::LowerBounds(InputHandle, ValueHandle, OutHandle); + return timer.GetElapsedTime(); } @@ -442,7 +448,8 @@ private: VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Value tmp = Algorithm::Reduce(InputHandle, vtkm::TypeTraits::ZeroInitialization()); vtkm::Float64 time = timer.GetElapsedTime(); if (tmp != this->Result) @@ -494,7 +501,8 @@ private: VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Algorithm::ReduceByKey(KeyHandle, ValueHandle, KeysOut, ValuesOut, vtkm::Add()); return timer.GetElapsedTime(); } @@ -542,7 +550,8 @@ private: VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Algorithm::ScanInclusive(ValueHandle, OutHandle); return timer.GetElapsedTime(); } @@ -580,7 +589,8 @@ private: VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Algorithm::ScanExclusive(ValueHandle, OutHandle); return timer.GetElapsedTime(); } @@ -624,7 +634,8 @@ private: ValueArrayHandle array; Algorithm::Copy(this->ValueHandle, array); - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Algorithm::Sort(array); return timer.GetElapsedTime(); } @@ -679,7 +690,8 @@ private: Algorithm::Copy(this->KeyHandle, keys); Algorithm::Copy(this->ValueHandle, values); - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Algorithm::SortByKey(keys, values); return timer.GetElapsedTime(); } @@ -737,7 +749,8 @@ private: vtkm::cont::ArrayHandle indices; Algorithm::Copy(vtkm::cont::ArrayHandleIndex(arraySize), indices); - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); SSI::Sort(ValueHandle, indices); return timer.GetElapsedTime(); } @@ -786,7 +799,8 @@ private: { IndexArrayHandle indices; Algorithm::Copy(this->IndexHandle, indices); - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); SSI::Unique(this->ValueHandle, indices); return timer.GetElapsedTime(); } @@ -843,7 +857,8 @@ private: ValueArrayHandle array; Algorithm::Copy(this->ValueHandle, array); - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Algorithm::Unique(array); return timer.GetElapsedTime(); } @@ -900,7 +915,8 @@ private: VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + vtkm::cont::Timer timer; + timer.Start(); Algorithm::UpperBounds(InputHandle, ValueHandle, OutHandle); return timer.GetElapsedTime(); } diff --git a/benchmarking/BenchmarkFieldAlgorithms.cxx b/benchmarking/BenchmarkFieldAlgorithms.cxx index 89122a1c0..d5d2c55cc 100644 --- a/benchmarking/BenchmarkFieldAlgorithms.cxx +++ b/benchmarking/BenchmarkFieldAlgorithms.cxx @@ -316,7 +316,7 @@ class BenchmarkFieldAlgorithms { using StorageTag = vtkm::cont::StorageTagBasic; - using Timer = vtkm::cont::Timer; + using Timer = vtkm::cont::Timer; using ValueVariantHandle = vtkm::cont::VariantArrayHandleBase; using InterpVariantHandle = vtkm::cont::VariantArrayHandleBase; @@ -366,7 +366,8 @@ private: const Value RISKFREE = 0.02f; const Value VOLATILITY = 0.30f; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); BlackScholes worklet(RISKFREE, VOLATILITY); vtkm::worklet::DispatcherMapField> dispatcher(worklet); dispatcher.SetDevice(DeviceAdapterTag()); @@ -405,7 +406,8 @@ private: const Value RISKFREE = 0.02f; const Value VOLATILITY = 0.30f; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); BlackScholes worklet(RISKFREE, VOLATILITY); vtkm::worklet::DispatcherMapField> dispatcher(worklet); dispatcher.SetDevice(DeviceAdapterTag()); @@ -448,7 +450,8 @@ private: vtkm::cont::ArrayHandle tempHandle1; vtkm::cont::ArrayHandle tempHandle2; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::Invoker invoke(DeviceAdapterTag{}); invoke(Mag{}, this->InputHandle, tempHandle1); @@ -487,7 +490,8 @@ private: ValueVariantHandle dtemp1(temp1); ValueVariantHandle dtemp2(temp2); - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::Invoker invoke(DeviceAdapterTag{}); invoke(Mag{}, dinput, dtemp1); @@ -530,10 +534,12 @@ private: { vtkm::cont::ArrayHandle result; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::DispatcherMapField dispatcher; dispatcher.SetDevice(DeviceAdapterTag()); dispatcher.Invoke(this->InputHandle, result); + return timer.GetElapsedTime(); } @@ -563,10 +569,12 @@ private: vtkm::cont::ArrayHandle result; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::DispatcherMapField dispatcher; dispatcher.SetDevice(DeviceAdapterTag()); dispatcher.Invoke(dinput, result); + return timer.GetElapsedTime(); } @@ -633,10 +641,12 @@ private: { vtkm::cont::ArrayHandle result; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::DispatcherMapField dispatcher; dispatcher.SetDevice(DeviceAdapterTag()); dispatcher.Invoke(this->EdgePairHandle, this->WeightHandle, this->FieldHandle, result); + return timer.GetElapsedTime(); } @@ -666,10 +676,12 @@ private: EdgeIdVariantHandle dedges(this->EdgePairHandle); vtkm::cont::ArrayHandle result; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::DispatcherMapField dispatcher; dispatcher.SetDevice(DeviceAdapterTag()); dispatcher.Invoke(dedges, dweight, dfield, result); + return timer.GetElapsedTime(); } @@ -731,10 +743,12 @@ private: static_cast(handle.PrepareForExecution(DeviceAdapterTag())); EvalWorklet eval(function); - vtkm::cont::Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); EvalDispatcher dispatcher(eval); dispatcher.SetDevice(DeviceAdapterTag()); dispatcher.Invoke(this->Internal.Points, this->Internal.Result); + return timer.GetElapsedTime(); } @@ -767,10 +781,12 @@ private: auto sphere = vtkm::cont::make_ImplicitFunctionHandle(Internal.Sphere1); EvalWorklet eval(sphere.PrepareForExecution(DeviceAdapterTag())); - vtkm::cont::Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); EvalDispatcher dispatcher(eval); dispatcher.SetDevice(DeviceAdapterTag()); dispatcher.Invoke(this->Internal.Points, this->Internal.Result); + return timer.GetElapsedTime(); } @@ -806,10 +822,12 @@ private: auto f2 = static_cast(h2.PrepareForExecution(DeviceAdapterTag())); EvalWorklet eval(f1, f2); - vtkm::cont::Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); EvalDispatcher dispatcher(eval); dispatcher.SetDevice(DeviceAdapterTag()); dispatcher.Invoke(this->Internal.Points, this->Internal.Result); + return timer.GetElapsedTime(); } @@ -845,10 +863,12 @@ private: EvalWorklet eval(s1.PrepareForExecution(DeviceAdapterTag()), s2.PrepareForExecution(DeviceAdapterTag())); - vtkm::cont::Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); EvalDispatcher dispatcher(eval); dispatcher.SetDevice(DeviceAdapterTag()); dispatcher.Invoke(this->Internal.Points, this->Internal.Result); + return timer.GetElapsedTime(); } diff --git a/benchmarking/BenchmarkFilters.cxx b/benchmarking/BenchmarkFilters.cxx index d2a73739f..b2dfac186 100644 --- a/benchmarking/BenchmarkFilters.cxx +++ b/benchmarking/BenchmarkFilters.cxx @@ -172,7 +172,7 @@ public: template class BenchmarkFilters { - using Timer = vtkm::cont::Timer; + using Timer = vtkm::cont::Timer; enum GradOpts { @@ -229,7 +229,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -316,7 +317,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -354,7 +356,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -379,7 +382,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -403,7 +407,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -430,7 +435,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -456,7 +462,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -498,7 +505,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -542,7 +550,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -576,7 +585,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -601,7 +611,8 @@ class BenchmarkFilters VTKM_CONT vtkm::Float64 operator()() { - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); return timer.GetElapsedTime(); } @@ -650,7 +661,8 @@ class BenchmarkFilters vtkm::TopologyElementTagPoint{}); } - vtkm::cont::Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); cellSet.PrepareForInput( Device{}, vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}); this->Time = timer.GetElapsedTime(); diff --git a/benchmarking/BenchmarkRayTracing.cxx b/benchmarking/BenchmarkRayTracing.cxx index 9733ee213..b5e364dd0 100644 --- a/benchmarking/BenchmarkRayTracing.cxx +++ b/benchmarking/BenchmarkRayTracing.cxx @@ -114,7 +114,8 @@ struct BenchRayTracing VTKM_CONT vtkm::Float64 operator()() { - vtkm::cont::Timer timer; + vtkm::cont::Timer timer; + timer.Start(); RayCamera.CreateRays(Rays, Coords.GetBounds()); Tracer.Render(Rays); diff --git a/benchmarking/BenchmarkTopologyAlgorithms.cxx b/benchmarking/BenchmarkTopologyAlgorithms.cxx index dba9a2645..0f9b38fe3 100644 --- a/benchmarking/BenchmarkTopologyAlgorithms.cxx +++ b/benchmarking/BenchmarkTopologyAlgorithms.cxx @@ -140,7 +140,7 @@ class BenchmarkTopologyAlgorithms { using StorageTag = vtkm::cont::StorageTagBasic; - using Timer = vtkm::cont::Timer; + using Timer = vtkm::cont::Timer; using ValueVariantHandle = vtkm::cont::VariantArrayHandleBase; @@ -205,7 +205,8 @@ private: cellSet.SetPointDimensions(vtkm::Id3(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE)); vtkm::cont::ArrayHandle result; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::DispatcherMapTopology dispatcher; dispatcher.SetDevice(DeviceAdapterTag()); @@ -241,7 +242,8 @@ private: ValueVariantHandle dinput(this->InputHandle); vtkm::cont::ArrayHandle result; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::DispatcherMapTopology dispatcher; dispatcher.SetDevice(DeviceAdapterTag()); @@ -284,7 +286,8 @@ private: cellSet.SetPointDimensions(vtkm::Id3(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE)); vtkm::cont::ArrayHandle result; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::DispatcherMapTopology dispatcher; dispatcher.SetDevice(DeviceAdapterTag()); @@ -320,7 +323,8 @@ private: ValueVariantHandle dinput(this->InputHandle); vtkm::cont::ArrayHandle result; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); vtkm::worklet::DispatcherMapTopology dispatcher; dispatcher.SetDevice(DeviceAdapterTag()); @@ -367,7 +371,8 @@ private: ValueVariantHandle dinput(this->InputHandle); - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Classification worklet(this->IsoValue); vtkm::worklet::DispatcherMapTopology> dispatcher(worklet); @@ -401,13 +406,15 @@ private: cellSet.SetPointDimensions(vtkm::Id3(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE)); vtkm::cont::ArrayHandle result; - Timer timer; + Timer timer{ DeviceAdapterTag() }; + timer.Start(); Classification worklet(this->IsoValue); vtkm::worklet::DispatcherMapTopology> dispatcher(worklet); dispatcher.SetDevice(DeviceAdapterTag()); dispatcher.Invoke(this->InputHandle, cellSet, result); + timer.Stop(); return timer.GetElapsedTime(); } diff --git a/docs/changelog/asynchronize-device-independent-timer.md b/docs/changelog/asynchronize-device-independent-timer.md new file mode 100644 index 000000000..065540a40 --- /dev/null +++ b/docs/changelog/asynchronize-device-independent-timer.md @@ -0,0 +1,65 @@ +# Introduce asynchronous and device independent timer + +The timer class now is asynchronous and device independent. it's using an +similiar API as vtkOpenGLRenderTimer with Start(), Stop(), Reset(), Ready(), +and GetElapsedTime() function. For convenience and backward compability, Each +Start() function call will call Reset() internally. GetElapsedTime() function +can be used multiple times to time sequential operations and Stop() function +can be helpful when you want to get the elapsed time latter. + +Bascially it can be used in two modes: + +* Create a Timer without any device info. + * It would enable the timer for all enabled devices on the machine. Users can get a +specific elapsed time by passing a device id into the GetElapsedTime function. +If no device is provided, it would pick the maximum of all timer results - the +logic behind this decision is that if cuda is disabled, openmp, serial and tbb +roughly give the same results; if cuda is enabled it's safe to return the +maximum elapsed time since users are more interested in the device execution +time rather than the kernal launch time. The Ready function can be handy here +to query the status of the timer. + +``` Construct a generic timer +// Assume CUDA is enabled on the machine +vtkm::cont::Timer timer; +timer.Start(); +// Run the algorithm + +auto timeHost = timer.GetElapsedTime(vtkm::cont::DeviceAdapterTagSerial()); +// To avoid the expensive device synchronization, we query is ready here. +if (timer.IsReady()) +{ + auto timeDevice = timer.GetElapsedTime(vtkm::cont::DeviceAdapterTagCuda()); +} +// Force the synchronization. Ideally device execution time would be returned +which takes longer time than ther kernal call +auto timeGeneral = timer.GetElapsedTime(); +``` + +* Create a Timer with a specific device. + * It works as the old timer that times for a specific device id. +``` Construct a device specific timer +// Assume TBB is enabled on the machine +vtkm::cont::Timer timer{vtkm::cont::DeviceAdaptertagTBB()}; +timer.Start(); // t0 +// Run the algorithm + +// Timer would just return 0 and warn the user in the logger that an invalid +// device is used to query elapsed time +auto timeInvalid = timer.GetElapsedTime(vtkm::cont::DeviceAdapterTagSerial()); +if timer.IsReady() +{ + // Either will work and mark t1, return t1-t0 + auto time1TBB = timer.GetElapsedTime(vtkm::cont::DeviceAdapterTagTBB()); + auto time1General = timer.GetElapsedTime(); +} + +// Do something +auto time2 = timer.GetElapsedTime(); // t2 will be marked and t2-t0 will be returned + +// Do something +timer.Stop() // t3 marked + +// Do something then summarize latter +auto timeFinal = timer.GetElapsedTime(); // t3-t0 +``` diff --git a/examples/clipping/Clipping.cxx b/examples/clipping/Clipping.cxx index 02150c002..370f67443 100644 --- a/examples/clipping/Clipping.cxx +++ b/examples/clipping/Clipping.cxx @@ -85,8 +85,10 @@ int main(int argc, char* argv[]) vtkm::Float32 clipValue = std::stof(argv[argc - 2]); vtkm::worklet::Clip clip; - vtkm::cont::Timer<> total; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer total; + total.Start(); + vtkm::cont::Timer timer; + timer.Start(); bool invertClip = false; vtkm::cont::CellSetExplicit<> outputCellSet = clip.Run(input.GetCellSet(0), @@ -100,12 +102,12 @@ int main(int argc, char* argv[]) auto inCoords = input.GetCoordinateSystem(0).GetData(); - timer.Reset(); + timer.Start(); auto outCoords = clip.ProcessCellField(inCoords); vtkm::Float64 processCoordinatesTime = timer.GetElapsedTime(); output.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", outCoords)); - timer.Reset(); + timer.Start(); for (vtkm::Id i = 0; i < input.GetNumberOfFields(); ++i) { vtkm::cont::Field inField = input.GetField(i); diff --git a/examples/contour_tree_augmented/ContourTreeApp.cxx b/examples/contour_tree_augmented/ContourTreeApp.cxx index 620e22fac..64da37058 100644 --- a/examples/contour_tree_augmented/ContourTreeApp.cxx +++ b/examples/contour_tree_augmented/ContourTreeApp.cxx @@ -145,8 +145,8 @@ private: // Compute and render an isosurface for a uniform grid example int main(int argc, char* argv[]) { - // TODO: Change timing to use logging in vtkm/cont/Logging.h - vtkm::cont::Timer<> totalTime; + vtkm::cont::Timer totalTime; + totalTime.Start(); vtkm::Float64 prevTime = 0; vtkm::Float64 currTime = 0; std::cout << "ContourTreePPP2Mesh " << std::endl; diff --git a/examples/game_of_life/GameOfLife.cxx b/examples/game_of_life/GameOfLife.cxx index 93829f02a..c912e22ec 100644 --- a/examples/game_of_life/GameOfLife.cxx +++ b/examples/game_of_life/GameOfLife.cxx @@ -250,7 +250,8 @@ struct RenderGameOfLife } }; -vtkm::cont::Timer gTimer; +vtkm::cont::Timer gTimer{ vtkm::cont::DeviceAdapterTagSerial() }; +gTimer.Start(); vtkm::cont::DataSet* gData = nullptr; GameOfLife* gFilter = nullptr; RenderGameOfLife* gRenderer = nullptr; diff --git a/examples/hello_world/HelloWorld.cxx b/examples/hello_world/HelloWorld.cxx index a6d5cdb25..7705326c1 100644 --- a/examples/hello_world/HelloWorld.cxx +++ b/examples/hello_world/HelloWorld.cxx @@ -59,7 +59,7 @@ struct HelloVTKMInterop vtkm::interop::BufferState VBOState; vtkm::interop::BufferState ColorState; - vtkm::cont::Timer<> Timer; + vtkm::cont::Timer Timer; std::vector> InputData; vtkm::cont::ArrayHandle> InHandle; @@ -78,6 +78,7 @@ struct HelloVTKMInterop , OutCoords() , OutColors() { + Timer.Start(); int dim = 256; this->InputData.reserve(static_cast(dim * dim)); for (int i = 0; i < dim; ++i) diff --git a/examples/unified_memory/UnifiedMemory.cu b/examples/unified_memory/UnifiedMemory.cu index 13a615583..abbbbde8f 100644 --- a/examples/unified_memory/UnifiedMemory.cu +++ b/examples/unified_memory/UnifiedMemory.cu @@ -84,7 +84,8 @@ int main(int argc, char* argv[]) //run once to get the CUDA code warmed up dispatcher.Invoke(input, output); - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ DeviceTag() }; + timer.Start(); for (int i = 0; i < 3; ++i) { @@ -117,7 +118,8 @@ int main(int argc, char* argv[]) //run once to get the CUDA code warmed up dispatcher.Invoke(input, output); - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ DeviceTag() }; + timer.Start(); for (int i = 0; i < 3; ++i) { diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index cd5037744..db635ccd8 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -171,6 +171,7 @@ set(device_sources ArrayRangeCompute.cxx CellSetExplicit.cxx CoordinateSystem.cxx + Timer.cxx ) #----------------------------------------------------------------------------- diff --git a/vtkm/cont/DeviceAdapterAlgorithm.h b/vtkm/cont/DeviceAdapterAlgorithm.h index c2757ed66..42f0392b5 100644 --- a/vtkm/cont/DeviceAdapterAlgorithm.h +++ b/vtkm/cont/DeviceAdapterAlgorithm.h @@ -22,6 +22,7 @@ #include +#include #include #include @@ -539,6 +540,11 @@ template class DeviceAdapterTimerImplementation { public: + struct TimeStamp + { + vtkm::Int64 Seconds; + vtkm::Int64 Microseconds; + }; /// When a timer is constructed, all threads are synchronized and the /// current time is marked so that GetElapsedTime returns the number of /// seconds elapsed since the construction. @@ -548,7 +554,30 @@ public: /// number of seconds elapsed since the call to this. This method /// synchronizes all asynchronous operations. /// - VTKM_CONT void Reset() { this->StartTime = this->GetCurrentTime(); } + VTKM_CONT void Reset() + { + this->StartReady = false; + this->StopReady = false; + } + + VTKM_CONT void Start() + { + this->Reset(); + this->StartTime = this->GetCurrentTime(); + this->StartReady = true; + } + + VTKM_CONT void Stop() + { + this->StopTime = this->GetCurrentTime(); + this->StopReady = true; + } + + VTKM_CONT bool Started() { return this->StartReady; } + + VTKM_CONT bool Stopped() { return this->StopReady; } + + VTKM_CONT bool Ready() { return true; } /// Returns the elapsed time in seconds between the construction of this /// class or the last call to Reset and the time this function is called. The @@ -558,21 +587,29 @@ public: /// VTKM_CONT vtkm::Float64 GetElapsedTime() { - TimeStamp currentTime = this->GetCurrentTime(); + assert(this->StartReady); + if (!this->StartReady) + { + VTKM_LOG_S(vtkm::cont::LogLevel::Error, + "Start() function should be called first then trying to call GetElapsedTime()."); + return 0; + } + bool manualStop = true; + if (!this->StopReady) + { + manualStop = false; + this->Stop(); + } vtkm::Float64 elapsedTime; - elapsedTime = vtkm::Float64(currentTime.Seconds - this->StartTime.Seconds); - elapsedTime += (vtkm::Float64(currentTime.Microseconds - this->StartTime.Microseconds) / + elapsedTime = vtkm::Float64(this->StopTime.Seconds - this->StartTime.Seconds); + elapsedTime += (vtkm::Float64(this->StopTime.Microseconds - this->StartTime.Microseconds) / vtkm::Float64(1000000)); + // Reset StopReady flag to its original state + this->StopReady = manualStop; return elapsedTime; } - struct TimeStamp - { - vtkm::Int64 Seconds; - vtkm::Int64 Microseconds; - }; - TimeStamp StartTime; VTKM_CONT TimeStamp GetCurrentTime() { @@ -592,6 +629,11 @@ public: #endif return retval; } + + bool StartReady; + bool StopReady; + TimeStamp StartTime; + TimeStamp StopTime; }; /// \brief Class providing a device-specific runtime support detector. diff --git a/vtkm/cont/Timer.cxx b/vtkm/cont/Timer.cxx new file mode 100644 index 000000000..f354bf89c --- /dev/null +++ b/vtkm/cont/Timer.cxx @@ -0,0 +1,254 @@ +//============================================================================ +// 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 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +// Copyright 2016 UT-Battelle, LLC. +// Copyright 2016 Los Alamos National Security. +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// 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. +//============================================================================ +#include +#include +#include + +#include + +namespace vtkm +{ +namespace cont +{ + +namespace detail +{ +template +struct RemoveDisabledDevice +{ + using type = typename std::conditional, State>::type; +}; + +/// TMP code to generate enabled device timer container +using AllDeviceList = DeviceAdapterListTagCommon::list; +using EnabledDeviceList = + brigand::fold, + detail::RemoveDisabledDevice>; +struct EnabledDeviceListTag : vtkm::ListTagBase<> +{ + using list = EnabledDeviceList; +}; +using EnabledTimerImpls = + brigand::transform>; +using EnabledTimerImplTuple = brigand::as_tuple; +} + +enum class TimerDispatchTag : int +{ + Reset, + Start, + Stop, + Started, + Stopped, + Ready, + GetElapsedTime +}; + +class EnabledDeviceTimerImpls +{ +public: + EnabledDeviceTimerImpls() {} + ~EnabledDeviceTimerImpls() {} + // A tuple of enabled timer implementations + detail::EnabledTimerImplTuple timerImplTuple; +}; + +namespace detail +{ +// C++11 does not support get tuple element by type. C++14 does support that. +// Get the index of a type in tuple elements +template +struct Index; + +template class Container, class... Types> +struct Index> +{ + static const std::size_t value = 0; +}; + +template class Container, class... Types> +struct Index> +{ + static const std::size_t value = 1 + Index>::value; +}; + +struct TimerFunctor +{ + TimerFunctor() + : elapsedTime(0) + , value(true) + { + } + + template + VTKM_CONT void operator()(DeviceAdapter device, Timer* timer, TimerDispatchTag tag) + { + if (timer->Device == device || timer->Device == DeviceAdapterTagAny()) + { + auto& timerImpl = std::get::value>( + timer->Internal->timerImplTuple); + switch (tag) + { + case TimerDispatchTag::Reset: + timerImpl.Reset(); + break; + case TimerDispatchTag::Start: + timerImpl.Start(); + break; + case TimerDispatchTag::Stop: + timerImpl.Stop(); + break; + case TimerDispatchTag::Started: + value &= timerImpl.Started(); + break; + case TimerDispatchTag::Stopped: + value &= timerImpl.Stopped(); + break; + case TimerDispatchTag::Ready: + value &= timerImpl.Ready(); + break; + case TimerDispatchTag::GetElapsedTime: + { + if (timer->Device == DeviceAdapterTagAny() && + timer->DeviceForQuery == DeviceAdapterTagAny()) + { // Just want to do timing jobs + elapsedTime = std::max(elapsedTime, timerImpl.GetElapsedTime()); + break; + } + else if (timer->Device == DeviceAdapterTagAny() && timer->DeviceForQuery == device) + { // Given a generic timer, querying for a specific device time + elapsedTime = timerImpl.GetElapsedTime(); + break; + } + else if (timer->Device == device && (timer->DeviceForQuery == DeviceAdapterTagAny() || + timer->Device == timer->DeviceForQuery)) + { // Given a specific timer, querying its elapsed time + elapsedTime = timerImpl.GetElapsedTime(); + break; + } + break; + } + } + } + } + + vtkm::Float64 elapsedTime; + bool value; +}; +} + + +Timer::Timer() + : Device(vtkm::cont::DeviceAdapterTagAny()) + , DeviceForQuery(vtkm::cont::DeviceAdapterTagAny()) + , Internal(nullptr) +{ + this->Init(); +} + + +Timer::~Timer() +{ + delete this->Internal; +} + +void Timer::Init() +{ + if (!this->Internal) + { + this->Internal = new EnabledDeviceTimerImpls(); + } +} + +void Timer::Reset() +{ + detail::TimerFunctor functor; + vtkm::ListForEach(functor, detail::EnabledDeviceListTag(), this, TimerDispatchTag::Reset); +} + +void Timer::Start() +{ + + detail::TimerFunctor functor; + vtkm::ListForEach(functor, detail::EnabledDeviceListTag(), this, TimerDispatchTag::Start); +} + +void Timer::Stop() +{ + detail::TimerFunctor functor; + vtkm::ListForEach(functor, detail::EnabledDeviceListTag(), this, TimerDispatchTag::Stop); +} + +bool Timer::Started() +{ + detail::TimerFunctor functor; + vtkm::ListForEach(functor, detail::EnabledDeviceListTag(), this, TimerDispatchTag::Started); + return functor.value; +} + +bool Timer::Stopped() +{ + detail::TimerFunctor functor; + vtkm::ListForEach(functor, detail::EnabledDeviceListTag(), this, TimerDispatchTag::Stopped); + return functor.value; +} + +bool Timer::Ready() +{ + detail::TimerFunctor functor; + vtkm::ListForEach(functor, detail::EnabledDeviceListTag(), this, TimerDispatchTag::Ready); + return functor.value; +} + +vtkm::Float64 Timer::GetElapsedTime(DeviceAdapterId id) +{ + // Timer is constructed with a specific device. Only querying this device is allowed. + if (this->Device != DeviceAdapterTagAny() && (id != DeviceAdapterTagAny() && this->Device != id)) + { + VTKM_LOG_S(vtkm::cont::LogLevel::Error, + "Device '" << id.GetName() << "' is not supported for current timer" + << "(" + << this->Device.GetName() + << ")"); + return 0.0; + } + + // Timer is constructed with any device. Only querying enabled device is allowed. + vtkm::cont::RuntimeDeviceTracker tracker; + if (this->Device == DeviceAdapterTagAny() && + (id != DeviceAdapterTagAny() && !tracker.CanRunOn(id))) + { + VTKM_LOG_S(vtkm::cont::LogLevel::Error, + "Device '" << id.GetName() << "' can not run on current Device." + "Thus timer is not usable"); + return 0.0; + } + + this->DeviceForQuery = id; + detail::TimerFunctor functor; + vtkm::ListForEach( + functor, detail::EnabledDeviceListTag(), this, TimerDispatchTag::GetElapsedTime); + + return functor.elapsedTime; +} +} +} // namespace vtkm::cont diff --git a/vtkm/cont/Timer.h b/vtkm/cont/Timer.h index ac2182dba..4f07bda1f 100644 --- a/vtkm/cont/Timer.h +++ b/vtkm/cont/Timer.h @@ -20,56 +20,85 @@ #ifndef vtk_m_cont_Timer_h #define vtk_m_cont_Timer_h +#include #include +#include + +#include namespace vtkm { namespace cont { +namespace detail +{ +struct TimerFunctor; +} +class EnabledDeviceTimerImpls; -/// A class that can be used to time operations in VTK-m that might be occurring -/// in parallel. You should make sure that the device adapter for the timer -/// matches that being used to execute algorithms to ensure that the thread -/// synchronization is correct. +/// 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. /// /// The there is no guaranteed resolution of the time but should generally be /// good to about a millisecond. /// -template -class Timer +class VTKM_CONT_EXPORT Timer { + friend struct detail::TimerFunctor; + public: - /// When a timer is constructed, all threads are synchronized and the - /// current time is marked so that GetElapsedTime returns the number of - /// seconds elapsed since the construction. VTKM_CONT - Timer() - : TimerImplementation() + Timer(); + + template + VTKM_CONT Timer(DeviceAdapter id) + : Device(id) + , DeviceForQuery(DeviceAdapterTagAny()) + , Internal(nullptr) { + VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapter); + static_assert(DeviceAdapter::IsEnabled, "A disabled device is passed to the Timer"); + this->Init(); } - /// Resets the timer. All further calls to GetElapsedTime will report the - /// number of seconds elapsed since the call to this. This method - /// synchronizes all asynchronous operations. - /// - VTKM_CONT - void Reset() { this->TimerImplementation.Reset(); } + VTKM_CONT ~Timer(); - /// Returns the elapsed time in seconds between the construction of this - /// class or the last call to Reset and the time this function is called. The - /// time returned is measured in wall time. GetElapsedTime may be called any - /// number of times to get the progressive time. This method synchronizes all - /// asynchronous operations. - /// + /// Resets the timer. + VTKM_CONT void Reset(); + + /// Start would call Reset function before starting the timer for convenience + VTKM_CONT void Start(); + + VTKM_CONT void Stop(); + + VTKM_CONT bool Started(); + + VTKM_CONT bool Stopped(); + + /// Used to check if Timer has finished the synchronization to get the result from the device. + VTKM_CONT bool Ready(); + + /// 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. VTKM_CONT - vtkm::Float64 GetElapsedTime() { return this->TimerImplementation.GetElapsedTime(); } + vtkm::Float64 GetElapsedTime(DeviceAdapterId id = DeviceAdapterTagAny()); private: + VTKM_CONT void Init(); /// Some timers are ill-defined when copied, so disallow that for all timers. - VTKM_CONT Timer(const Timer&) = delete; - VTKM_CONT void operator=(const Timer&) = delete; + VTKM_CONT Timer(const Timer&) = delete; + VTKM_CONT void operator=(const Timer&) = delete; - vtkm::cont::DeviceAdapterTimerImplementation TimerImplementation; + DeviceAdapterId Device; + DeviceAdapterId DeviceForQuery; + EnabledDeviceTimerImpls* Internal; }; } } // namespace vtkm::cont diff --git a/vtkm/cont/cuda/internal/DeviceAdapterTimerImplementationCuda.cu b/vtkm/cont/cuda/internal/DeviceAdapterTimerImplementationCuda.cu index aa4615a25..4adc56fdb 100644 --- a/vtkm/cont/cuda/internal/DeviceAdapterTimerImplementationCuda.cu +++ b/vtkm/cont/cuda/internal/DeviceAdapterTimerImplementationCuda.cu @@ -33,7 +33,7 @@ DeviceAdapterTimerImplementation< vtkm::cont::DeviceAdapterTagCuda>::DeviceAdapterTimerImplementation() { VTKM_CUDA_CALL(cudaEventCreate(&this->StartEvent)); - VTKM_CUDA_CALL(cudaEventCreate(&this->EndEvent)); + VTKM_CUDA_CALL(cudaEventCreate(&this->StopEvent)); this->Reset(); } @@ -45,21 +45,72 @@ DeviceAdapterTimerImplementation< // VTKM_CUDA_CHECK_ASYNCHRONOUS_ERROR catching any issues from these calls // later. cudaEventDestroy(this->StartEvent); - cudaEventDestroy(this->EndEvent); + cudaEventDestroy(this->StopEvent); } void DeviceAdapterTimerImplementation::Reset() +{ + this->StartReady = false; + this->StopReady = false; +} + +void DeviceAdapterTimerImplementation::Start() { VTKM_CUDA_CALL(cudaEventRecord(this->StartEvent, cudaStreamPerThread)); VTKM_CUDA_CALL(cudaEventSynchronize(this->StartEvent)); + this->StartReady = true; } +void DeviceAdapterTimerImplementation::Stop() +{ + VTKM_CUDA_CALL(cudaEventRecord(this->StopEvent, cudaStreamPerThread)); + this->StopReady = true; +} + +bool DeviceAdapterTimerImplementation::Started() +{ + return this->StartReady; +} + +bool DeviceAdapterTimerImplementation::Stopped() +{ + return this->StopReady; +} + +// Callbacks without a mandated order(in independent streams) execute in undefined +// order and maybe serialized. So Instead CudaEventQuery is used here. +// Ref link: https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__STREAM.html +bool DeviceAdapterTimerImplementation::Ready() +{ + if (cudaEventQuery(this->StopEvent) == cudaSuccess) + { + return true; + } + return false; +} + + vtkm::Float64 DeviceAdapterTimerImplementation::GetElapsedTime() { - VTKM_CUDA_CALL(cudaEventRecord(this->EndEvent, cudaStreamPerThread)); - VTKM_CUDA_CALL(cudaEventSynchronize(this->EndEvent)); + assert(this->StartReady); + if (!this->StartReady) + { + VTKM_LOG_F(vtkm::cont::LogLevel::Error, + "Start() function should be called first then trying to call GetElapsedTime()."); + return 0; + } + bool manualStop = true; + if (!this->StopReady) + { + manualStop = false; + this->Stop(); + } + + VTKM_CUDA_CALL(cudaEventSynchronize(this->StopEvent)); float elapsedTimeMilliseconds; - VTKM_CUDA_CALL(cudaEventElapsedTime(&elapsedTimeMilliseconds, this->StartEvent, this->EndEvent)); + VTKM_CUDA_CALL(cudaEventElapsedTime(&elapsedTimeMilliseconds, this->StartEvent, this->StopEvent)); + // Reset Stop flag to its original state + this->StopReady = manualStop; return static_cast(0.001f * elapsedTimeMilliseconds); } } diff --git a/vtkm/cont/cuda/internal/DeviceAdapterTimerImplementationCuda.h b/vtkm/cont/cuda/internal/DeviceAdapterTimerImplementationCuda.h index fa6ee8eab..461638b82 100644 --- a/vtkm/cont/cuda/internal/DeviceAdapterTimerImplementationCuda.h +++ b/vtkm/cont/cuda/internal/DeviceAdapterTimerImplementationCuda.h @@ -50,6 +50,16 @@ public: VTKM_CONT void Reset(); + VTKM_CONT void Start(); + + VTKM_CONT void Stop(); + + VTKM_CONT bool Started(); + + VTKM_CONT bool Stopped(); + + VTKM_CONT bool Ready(); + VTKM_CONT vtkm::Float64 GetElapsedTime(); private: @@ -59,8 +69,10 @@ private: void operator=(const DeviceAdapterTimerImplementation&) = delete; + bool StartReady; + bool StopReady; cudaEvent_t StartEvent; - cudaEvent_t EndEvent; + cudaEvent_t StopEvent; }; } } // namespace vtkm::cont diff --git a/vtkm/cont/tbb/internal/DeviceAdapterAlgorithmTBB.h b/vtkm/cont/tbb/internal/DeviceAdapterAlgorithmTBB.h index 6cf6ca2a1..db9165641 100644 --- a/vtkm/cont/tbb/internal/DeviceAdapterAlgorithmTBB.h +++ b/vtkm/cont/tbb/internal/DeviceAdapterAlgorithmTBB.h @@ -336,21 +336,63 @@ class DeviceAdapterTimerImplementation { public: VTKM_CONT DeviceAdapterTimerImplementation() { this->Reset(); } + VTKM_CONT void Reset() { vtkm::cont::DeviceAdapterAlgorithm::Synchronize(); - this->StartTime = ::tbb::tick_count::now(); + this->StartReady = false; + this->StopReady = false; } + + VTKM_CONT void Start() + { + this->Reset(); + this->StartTime = ::tbb::tick_count::now(); + this->StartReady = true; + } + + VTKM_CONT void Stop() + { + this->StopTime = ::tbb::tick_count::now(); + this->StopReady = true; + } + + VTKM_CONT bool Started() { return this->StartReady; } + + VTKM_CONT bool Stopped() { return this->StopReady; } + + VTKM_CONT bool Ready() { return true; } + VTKM_CONT vtkm::Float64 GetElapsedTime() { + assert(this->StartReady); + if (!this->StartReady) + { + VTKM_LOG_S(vtkm::cont::LogLevel::Error, + "Start() function should be called first then trying to call Stop() and" + " GetElapsedTime()."); + return 0; + } + bool manualStop = true; + if (!this->StopReady) + { + manualStop = false; + this->Stop(); + } vtkm::cont::DeviceAdapterAlgorithm::Synchronize(); - ::tbb::tick_count currentTime = ::tbb::tick_count::now(); - ::tbb::tick_count::interval_t elapsedTime = currentTime - this->StartTime; + ::tbb::tick_count::interval_t elapsedTime = this->StopTime - this->StartTime; + + // Reset StopReady flag to its original state + this->StopReady = manualStop; + return static_cast(elapsedTime.seconds()); } private: + bool StartReady; + bool StopReady; ::tbb::tick_count StartTime; + ::tbb::tick_count StopTime; }; template <> diff --git a/vtkm/cont/testing/TestingDeviceAdapter.h b/vtkm/cont/testing/TestingDeviceAdapter.h index 44932a82f..92dd2da97 100644 --- a/vtkm/cont/testing/TestingDeviceAdapter.h +++ b/vtkm/cont/testing/TestingDeviceAdapter.h @@ -585,27 +585,33 @@ private: VTKM_CONT static void TestTimer() { - std::cout << "-------------------------------------------" << std::endl; - std::cout << "Testing Timer" << std::endl; + auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker(); + if (tracker.CanRunOn(DeviceAdapterTag())) + { + std::cout << "-------------------------------------------" << std::endl; + std::cout << "Testing Timer" << std::endl; - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ DeviceAdapterTag() }; + timer.Start(); - std::cout << "Timer started. Sleeping..." << std::endl; + std::cout << "Timer started. Sleeping..." << std::endl; #ifndef _WIN32 - sleep(1); + sleep(1); #else - Sleep(1000); + Sleep(1000); #endif - std::cout << "Woke up. Check time." << std::endl; + std::cout << "Woke up. Check time." << std::endl; - vtkm::Float64 elapsedTime = timer.GetElapsedTime(); + timer.Stop(); + vtkm::Float64 elapsedTime = timer.GetElapsedTime(); - std::cout << "Elapsed time: " << elapsedTime << std::endl; + std::cout << "Elapsed time: " << elapsedTime << std::endl; - VTKM_TEST_ASSERT(elapsedTime > 0.999, "Timer did not capture full second wait."); - VTKM_TEST_ASSERT(elapsedTime < 2.0, "Timer counted too far or system really busy."); + VTKM_TEST_ASSERT(elapsedTime > 0.999, "Timer did not capture full second wait."); + VTKM_TEST_ASSERT(elapsedTime < 2.0, "Timer counted too far or system really busy."); + } } VTKM_CONT diff --git a/vtkm/cont/testing/UnitTestTimer.cxx b/vtkm/cont/testing/UnitTestTimer.cxx index 03b59b7ab..4290b53a0 100644 --- a/vtkm/cont/testing/UnitTestTimer.cxx +++ b/vtkm/cont/testing/UnitTestTimer.cxx @@ -18,8 +18,13 @@ // this software. //============================================================================ +#include #include +#include +#include +#include +#include #include #include @@ -28,7 +33,10 @@ namespace void Time() { - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); + VTKM_TEST_ASSERT(timer.Started(), "Timer fails to track started status"); + VTKM_TEST_ASSERT(!timer.Stopped(), "Timer fails to track non stopped status"); #ifdef VTKM_WINDOWS Sleep(1000); @@ -37,11 +45,85 @@ void Time() #endif vtkm::Float64 elapsedTime = timer.GetElapsedTime(); + VTKM_TEST_ASSERT(!timer.Stopped(), "Timer fails to track stopped status"); - std::cout << "Elapsed time: " << elapsedTime << std::endl; + std::cout << "Elapsed time measured by any Tag: " << elapsedTime << std::endl; + VTKM_TEST_ASSERT(elapsedTime > 0.999, "General Timer did not capture full second wait."); + VTKM_TEST_ASSERT(elapsedTime < 2.0, "General Timer counted too far or system really busy."); - VTKM_TEST_ASSERT(elapsedTime > 0.999, "Timer did not capture full second wait."); - VTKM_TEST_ASSERT(elapsedTime < 2.0, "Timer counted too far or system really busy."); + vtkm::cont::RuntimeDeviceTracker tracker; + + vtkm::Float64 elapsedTimeCuda = timer.GetElapsedTime(vtkm::cont::DeviceAdapterTagCuda()); + if (tracker.CanRunOn(vtkm::cont::DeviceAdapterTagCuda())) + { + std::cout << " can on run cuda?: true" << std::endl; + std::cout << "Elapsed time measured by cuda Tag: " << elapsedTime << std::endl; + VTKM_TEST_ASSERT(elapsedTimeCuda > 0.999, "Cuda Timer did not capture full second wait."); + VTKM_TEST_ASSERT(elapsedTimeCuda < 2.0, "Cuda Timer counted too far or system really busy."); + } + else + { + VTKM_TEST_ASSERT(elapsedTimeCuda == 0.0, "Disabled Cuda Timer should return nothing."); + } + + vtkm::Float64 elapsedTimeSerial = timer.GetElapsedTime(vtkm::cont::DeviceAdapterTagSerial()); + std::cout << "Elapsed time measured by serial Tag: " << elapsedTime << std::endl; + VTKM_TEST_ASSERT(elapsedTimeSerial > 0.999, "Serial Timer did not capture full second wait."); + VTKM_TEST_ASSERT(elapsedTimeSerial < 2.0, "Serial Timer counted too far or system really busy."); + + vtkm::Float64 elapsedTimeOpenMP = timer.GetElapsedTime(vtkm::cont::DeviceAdapterTagOpenMP()); + if (vtkm::cont::DeviceAdapterTagOpenMP::IsEnabled) + { + std::cout << "Elapsed time measured by openmp Tag: " << elapsedTime << std::endl; + VTKM_TEST_ASSERT(elapsedTimeOpenMP > 0.999, "OpenMP Timer did not capture full second wait."); + VTKM_TEST_ASSERT(elapsedTimeOpenMP < 2.0, + "OpenMP Timer counted too far or system really busy."); + } + else + { + VTKM_TEST_ASSERT(elapsedTimeOpenMP == 0.0, "Disabled OpenMP Timer should return nothing."); + } + + vtkm::Float64 elapsedTimeTBB = timer.GetElapsedTime(vtkm::cont::DeviceAdapterTagTBB()); + if (vtkm::cont::DeviceAdapterTagTBB::IsEnabled) + { + std::cout << "Elapsed time measured by tbb Tag: " << elapsedTime << std::endl; + VTKM_TEST_ASSERT(elapsedTimeTBB > 0.999, "TBB Timer did not capture full second wait."); + VTKM_TEST_ASSERT(elapsedTimeTBB < 2.0, "TBB Timer counted too far or system really busy."); + } + else + { + VTKM_TEST_ASSERT(elapsedTimeOpenMP == 0.0, "Disabled TBB Timer should return nothing."); + } + + std::cout << "Reuse the timer to test continuous timing." << std::endl; +#ifdef VTKM_WINDOWS + Sleep(1000); +#else + sleep(1); +#endif + + elapsedTime = timer.GetElapsedTime(); + + std::cout << "Elapsed time measured by any Tag: " << elapsedTime << std::endl; + VTKM_TEST_ASSERT(elapsedTime > 1.999, + "General Timer did not capture two full seconds wait in second launch."); + VTKM_TEST_ASSERT(elapsedTime < 3.0, + "General Timer counted too far or system really busy in second launch."); + + timer.Stop(); + VTKM_TEST_ASSERT(timer.Stopped(), "Timer fails to track stopped status"); +#ifdef VTKM_WINDOWS + Sleep(1000); +#else + sleep(1); +#endif + + std::cout << "Elapsed time measured by any Tag with an early stop: " << elapsedTime << std::endl; + VTKM_TEST_ASSERT(elapsedTime > 1.999, + "General Timer did not capture two full seconds wait in second launch."); + VTKM_TEST_ASSERT(elapsedTime < 3.0, + "General Timer counted too far or system really busy in second launch."); } } // anonymous namespace diff --git a/vtkm/filter/ContourTreeUniformAugmented.hxx b/vtkm/filter/ContourTreeUniformAugmented.hxx index 20717685a..6cd8c1444 100644 --- a/vtkm/filter/ContourTreeUniformAugmented.hxx +++ b/vtkm/filter/ContourTreeUniformAugmented.hxx @@ -109,7 +109,8 @@ vtkm::cont::DataSet ContourTreePPP2::DoExecute(const vtkm::cont::DataSet& input, { // TODO: This should be switched to use the logging macros defined in vtkm/cont/logging.h // Start the timer - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); Timings.clear(); // Check that the field is Ok @@ -153,7 +154,7 @@ vtkm::cont::DataSet ContourTreePPP2::DoExecute(const vtkm::cont::DataSet& input, vtkm::Float64 totalTimeWorklet = 0; for (std::vector>::size_type i = 0; i < Timings.size(); i++) totalTimeWorklet += Timings[i].second; - //std::cout<<"Total time measured by worklet: "<( "Others (ContourTreePPP2 Filter): ", timer.GetElapsedTime() - totalTimeWorklet)); diff --git a/vtkm/rendering/MapperCylinder.cxx b/vtkm/rendering/MapperCylinder.cxx index 214d0d3eb..7488f59b8 100644 --- a/vtkm/rendering/MapperCylinder.cxx +++ b/vtkm/rendering/MapperCylinder.cxx @@ -136,8 +136,9 @@ void MapperCylinder::RenderCells(const vtkm::cont::DynamicCellSet& cellset, { raytracing::Logger* logger = raytracing::Logger::GetInstance(); logger->OpenLogEntry("mapper_cylinder"); - vtkm::cont::Timer<> tot_timer; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer tot_timer; + tot_timer.Start(); + vtkm::cont::Timer timer; vtkm::Bounds shapeBounds; @@ -207,7 +208,7 @@ void MapperCylinder::RenderCells(const vtkm::cont::DynamicCellSet& cellset, this->Internals->Tracer.SetColorMap(this->ColorMap); this->Internals->Tracer.Render(this->Internals->Rays); - timer.Reset(); + timer.Start(); this->Internals->Canvas->WriteToCanvas( this->Internals->Rays, this->Internals->Rays.Buffers.at(0).Buffer, camera); diff --git a/vtkm/rendering/MapperPoint.cxx b/vtkm/rendering/MapperPoint.cxx index fa401d285..efe3142a0 100644 --- a/vtkm/rendering/MapperPoint.cxx +++ b/vtkm/rendering/MapperPoint.cxx @@ -131,8 +131,9 @@ void MapperPoint::RenderCells(const vtkm::cont::DynamicCellSet& cellset, this->Internals->Tracer.Clear(); logger->OpenLogEntry("mapper_ray_tracer"); - vtkm::cont::Timer<> tot_timer; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer tot_timer; + tot_timer.Start(); + vtkm::cont::Timer timer; vtkm::Bounds coordBounds = coords.GetBounds(); vtkm::Float32 baseRadius = this->Internals->PointRadius; @@ -206,7 +207,7 @@ void MapperPoint::RenderCells(const vtkm::cont::DynamicCellSet& cellset, this->Internals->Tracer.SetColorMap(this->ColorMap); this->Internals->Tracer.Render(this->Internals->Rays); - timer.Reset(); + timer.Start(); this->Internals->Canvas->WriteToCanvas( this->Internals->Rays, this->Internals->Rays.Buffers.at(0).Buffer, camera); diff --git a/vtkm/rendering/MapperQuad.cxx b/vtkm/rendering/MapperQuad.cxx index f96c47b93..e646bf9a4 100644 --- a/vtkm/rendering/MapperQuad.cxx +++ b/vtkm/rendering/MapperQuad.cxx @@ -91,8 +91,9 @@ void MapperQuad::RenderCells(const vtkm::cont::DynamicCellSet& cellset, { raytracing::Logger* logger = raytracing::Logger::GetInstance(); logger->OpenLogEntry("mapper_ray_tracer"); - vtkm::cont::Timer<> tot_timer; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer tot_timer; + tot_timer.Start(); + vtkm::cont::Timer timer; // @@ -128,7 +129,7 @@ void MapperQuad::RenderCells(const vtkm::cont::DynamicCellSet& cellset, this->Internals->Tracer.SetColorMap(this->ColorMap); this->Internals->Tracer.Render(this->Internals->Rays); - timer.Reset(); + timer.Start(); this->Internals->Canvas->WriteToCanvas( this->Internals->Rays, this->Internals->Rays.Buffers.at(0).Buffer, camera); diff --git a/vtkm/rendering/MapperRayTracer.cxx b/vtkm/rendering/MapperRayTracer.cxx index d9ffef64a..d93905ede 100644 --- a/vtkm/rendering/MapperRayTracer.cxx +++ b/vtkm/rendering/MapperRayTracer.cxx @@ -94,8 +94,9 @@ void MapperRayTracer::RenderCells(const vtkm::cont::DynamicCellSet& cellset, { raytracing::Logger* logger = raytracing::Logger::GetInstance(); logger->OpenLogEntry("mapper_ray_tracer"); - vtkm::cont::Timer<> tot_timer; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer tot_timer; + tot_timer.Start(); + vtkm::cont::Timer timer; // make sure we start fresh this->Internals->Tracer.Clear(); @@ -133,7 +134,7 @@ void MapperRayTracer::RenderCells(const vtkm::cont::DynamicCellSet& cellset, this->Internals->Tracer.SetShadingOn(this->Internals->Shade); this->Internals->Tracer.Render(this->Internals->Rays); - timer.Reset(); + timer.Start(); this->Internals->Canvas->WriteToCanvas( this->Internals->Rays, this->Internals->Rays.Buffers.at(0).Buffer, camera); diff --git a/vtkm/rendering/MapperVolume.cxx b/vtkm/rendering/MapperVolume.cxx index 7b584579f..683596f6d 100644 --- a/vtkm/rendering/MapperVolume.cxx +++ b/vtkm/rendering/MapperVolume.cxx @@ -104,8 +104,9 @@ void MapperVolume::RenderCells(const vtkm::cont::DynamicCellSet& cellset, { raytracing::Logger* logger = raytracing::Logger::GetInstance(); logger->OpenLogEntry("mapper_volume"); - vtkm::cont::Timer<> tot_timer; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer tot_timer; + tot_timer.Start(); + vtkm::cont::Timer timer; vtkm::rendering::raytracing::VolumeRendererStructured tracer; @@ -130,7 +131,7 @@ void MapperVolume::RenderCells(const vtkm::cont::DynamicCellSet& cellset, tracer.Render(rays); - timer.Reset(); + timer.Start(); this->Internals->Canvas->WriteToCanvas(rays, rays.Buffers.at(0).Buffer, camera); if (this->Internals->CompositeBackground) diff --git a/vtkm/rendering/raytracing/BoundingVolumeHierarchy.cxx b/vtkm/rendering/raytracing/BoundingVolumeHierarchy.cxx index 0cb1770c2..4c41cf56c 100644 --- a/vtkm/rendering/raytracing/BoundingVolumeHierarchy.cxx +++ b/vtkm/rendering/raytracing/BoundingVolumeHierarchy.cxx @@ -641,7 +641,8 @@ VTKM_CONT void LinearBVHBuilder::RunOnDevice(LinearBVH& linearBVH, Device device Logger* logger = Logger::GetInstance(); logger->OpenLogEntry("bvh_constuct"); - vtkm::cont::Timer constructTimer; + vtkm::cont::Timer constructTimer{ Device() }; + constructTimer.Start(); // // // This algorithm needs at least 2 AABBs @@ -683,7 +684,8 @@ VTKM_CONT void LinearBVHBuilder::RunOnDevice(LinearBVH& linearBVH, Device device BVHData bvh(numBBoxes, linearBVH.GetAABBs(), device); - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ Device() }; + timer.Start(); // Find the extent of all bounding boxes to generate normalization for morton codes vtkm::Vec minExtent(vtkm::Infinity32(), vtkm::Infinity32(), vtkm::Infinity32()); vtkm::Vec maxExtent( @@ -710,7 +712,7 @@ VTKM_CONT void LinearBVHBuilder::RunOnDevice(LinearBVH& linearBVH, Device device vtkm::Float64 time = timer.GetElapsedTime(); logger->AddLogData("calc_extents", time); - timer.Reset(); + timer.Start(); vtkm::Vec deltaExtent = maxExtent - minExtent; vtkm::Vec inverseExtent; @@ -731,7 +733,7 @@ VTKM_CONT void LinearBVHBuilder::RunOnDevice(LinearBVH& linearBVH, Device device time = timer.GetElapsedTime(); logger->AddLogData("morton_codes", time); - timer.Reset(); + timer.Start(); linearBVH.Allocate(bvh.GetNumberOfPrimitives(), device); @@ -739,7 +741,7 @@ VTKM_CONT void LinearBVHBuilder::RunOnDevice(LinearBVH& linearBVH, Device device time = timer.GetElapsedTime(); logger->AddLogData("sort_aabbs", time); - timer.Reset(); + timer.Start(); invoke(TreeBuilder{ bvh.mortonCodes, bvh.parent, bvh.GetNumberOfPrimitives() }, bvh.leftChild, @@ -747,7 +749,7 @@ VTKM_CONT void LinearBVHBuilder::RunOnDevice(LinearBVH& linearBVH, Device device time = timer.GetElapsedTime(); logger->AddLogData("build_tree", time); - timer.Reset(); + timer.Start(); const vtkm::Int32 primitiveCount = vtkm::Int32(bvh.GetNumberOfPrimitives()); @@ -850,7 +852,8 @@ template void LinearBVH::ConstructOnDevice(Device device) { Logger* logger = Logger::GetInstance(); - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ Device() }; + timer.Start(); logger->OpenLogEntry("bvh"); if (!CanConstruct) throw vtkm::cont::ErrorBadValue( diff --git a/vtkm/rendering/raytracing/Camera.cxx b/vtkm/rendering/raytracing/Camera.cxx index ff5589fcf..4a4341307 100644 --- a/vtkm/rendering/raytracing/Camera.cxx +++ b/vtkm/rendering/raytracing/Camera.cxx @@ -758,13 +758,15 @@ template VTKM_CONT void Camera::CreateRaysImpl(Ray& rays, const vtkm::Bounds boundingBox) { Logger* logger = Logger::GetInstance(); - vtkm::cont::Timer createTimer; + vtkm::cont::Timer createTimer{ vtkm::cont::DeviceAdapterTagSerial() }; + createTimer.Start(); logger->OpenLogEntry("ray_camera"); bool ortho = this->CameraView.GetMode() == vtkm::rendering::Camera::MODE_2D; this->UpdateDimensions(rays, boundingBox, ortho); this->WriteSettingsToLog(); - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); //Set the origin of the ray back to the camera position Precision infinity; @@ -782,7 +784,7 @@ VTKM_CONT void Camera::CreateRaysImpl(Ray& rays, const vtkm::Bounds b vtkm::Float64 time = timer.GetElapsedTime(); logger->AddLogData("camera_memset", time); - timer.Reset(); + timer.Start(); //Reset the camera look vector this->Look = this->LookAt - this->Position; diff --git a/vtkm/rendering/raytracing/ConnectivityTracer.cxx b/vtkm/rendering/raytracing/ConnectivityTracer.cxx index e95a519ed..0b15a7d2e 100644 --- a/vtkm/rendering/raytracing/ConnectivityTracer.cxx +++ b/vtkm/rendering/raytracing/ConnectivityTracer.cxx @@ -1134,7 +1134,8 @@ template void ConnectivityTracer::IntersectCell(Ray& rays, detail::RayTracking& tracker) { - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); vtkm::worklet::DispatcherMapField locateDispatch; locateDispatch.Invoke(rays.HitIdx, this->Coords, @@ -1163,7 +1164,8 @@ void ConnectivityTracer::AccumulatePathLengths(Ray& rays, template void ConnectivityTracer::FindLostRays(Ray& rays, detail::RayTracking& tracker) { - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); vtkm::worklet::DispatcherMapField bumpDispatch; bumpDispatch.Invoke(rays.HitIdx, @@ -1184,7 +1186,8 @@ void ConnectivityTracer::SampleCells(Ray& rays, detail::RayTracking; using SampleC = SampleCellAssocCells; - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); VTKM_ASSERT(rays.Buffers.at(0).GetNumChannels() == 4); @@ -1231,7 +1234,8 @@ template void ConnectivityTracer::IntegrateCells(Ray& rays, detail::RayTracking& tracker) { - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); if (HasEmission) { bool divideEmisByAbsorp = false; @@ -1303,7 +1307,8 @@ void ConnectivityTracer::OffsetMinDistances(Ray& rays) template void ConnectivityTracer::FindMeshEntry(Ray& rays) { - vtkm::cont::Timer entryTimer; + vtkm::cont::Timer entryTimer{ vtkm::cont::DeviceAdapterTagSerial() }; + entryTimer.Start(); // // if ray misses the external face it will be marked RAY_EXITED_MESH // diff --git a/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx b/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx index 50f3a52a9..8ae746474 100644 --- a/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx +++ b/vtkm/rendering/raytracing/MeshConnectivityBuilder.cxx @@ -533,7 +533,8 @@ VTKM_CONT void GenerateFaceConnnectivity( vtkm::cont::ArrayHandle& uniqueFaces) { - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); vtkm::Id numCells = shapes.GetNumberOfValues(); @@ -622,7 +623,8 @@ VTKM_CONT vtkm::cont::ArrayHandle> ExtractFaces( const OffsetsHandleType& shapeOffsets) { - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); vtkm::cont::ArrayHandle> externalFacePairs; vtkm::cont::Algorithm::CopyIf(cellFaceId, uniqueFaces, externalFacePairs, IsUnique()); @@ -678,7 +680,8 @@ void MeshConnectivityBuilder::BuildConnectivity( Logger* logger = Logger::GetInstance(); logger->OpenLogEntry("mesh_conn"); //logger->AddLogData("device", GetDeviceString(DeviceAdapter())); - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); vtkm::Float32 BoundingBox[6]; BoundingBox[0] = vtkm::Float32(coordsBounds.X.Min); @@ -738,7 +741,8 @@ void MeshConnectivityBuilder::BuildConnectivity( { Logger* logger = Logger::GetInstance(); logger->OpenLogEntry("meah_conn"); - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); vtkm::Float32 BoundingBox[6]; BoundingBox[0] = vtkm::Float32(coordsBounds.X.Min); @@ -813,7 +817,8 @@ vtkm::cont::ArrayHandle> MeshConnectivityBuilder::ExternalTrianglesStructured( vtkm::cont::CellSetStructured<3>& cellSetStructured) { - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ vtkm::cont::DeviceAdapterTagSerial() }; + timer.Start(); vtkm::Id3 cellDims = cellSetStructured.GetCellDimensions(); vtkm::Id numFaces = @@ -900,7 +905,8 @@ MeshConnContainer* MeshConnectivityBuilder::BuildConnectivity( logger->OpenLogEntry("mesh_conn_construction"); MeshConnContainer* meshConn = nullptr; - vtkm::cont::Timer timer; + vtkm::cont::Timer timer{ cont::DeviceAdapterTagSerial() }; + timer.Start(); if (type == Unstructured) { diff --git a/vtkm/rendering/raytracing/MeshConnectivityContainers.cxx b/vtkm/rendering/raytracing/MeshConnectivityContainers.cxx index 3569219e3..b361db72f 100644 --- a/vtkm/rendering/raytracing/MeshConnectivityContainers.cxx +++ b/vtkm/rendering/raytracing/MeshConnectivityContainers.cxx @@ -192,7 +192,6 @@ UnstructuredSingleContainer::UnstructuredSingleContainer( Logger* logger = Logger::GetInstance(); logger->OpenLogEntry("mesh_conn_construction"); - vtkm::cont::Timer timer; Intersector.SetData(Coords, Triangles); } diff --git a/vtkm/rendering/raytracing/RayTracer.cxx b/vtkm/rendering/raytracing/RayTracer.cxx index 8fb9ee7a6..431b18962 100644 --- a/vtkm/rendering/raytracing/RayTracer.cxx +++ b/vtkm/rendering/raytracing/RayTracer.cxx @@ -281,10 +281,11 @@ void RayTracer::Clear() template void RayTracer::RenderOnDevice(Ray& rays) { - using Timer = vtkm::cont::Timer; + using Timer = vtkm::cont::Timer; Logger* logger = Logger::GetInstance(); - Timer renderTimer; + Timer renderTimer{ vtkm::cont::DeviceAdapterTagSerial() }; + renderTimer.Start(); vtkm::Float64 time = 0.; logger->OpenLogEntry("ray_tracer"); logger->AddLogData("device", GetDeviceString()); @@ -295,6 +296,7 @@ void RayTracer::RenderOnDevice(Ray& rays) if (NumberOfShapes > 0) { Timer timer; + timer.Start(); for (size_t i = 0; i < numShapes; ++i) { @@ -302,11 +304,11 @@ void RayTracer::RenderOnDevice(Ray& rays) time = timer.GetElapsedTime(); logger->AddLogData("intersect", time); - timer.Reset(); + timer.Start(); Intersectors[i]->IntersectionData(rays, ScalarField, ScalarRange); time = timer.GetElapsedTime(); logger->AddLogData("intersection_data", time); - timer.Reset(); + timer.Start(); // Calculate the color at the intersection point detail::SurfaceColor surfaceColor; @@ -314,7 +316,6 @@ void RayTracer::RenderOnDevice(Ray& rays) time = timer.GetElapsedTime(); logger->AddLogData("shade", time); - timer.Reset(); } } diff --git a/vtkm/rendering/raytracing/VolumeRendererStructured.cxx b/vtkm/rendering/raytracing/VolumeRendererStructured.cxx index dd61d7439..ddaa26dc5 100644 --- a/vtkm/rendering/raytracing/VolumeRendererStructured.cxx +++ b/vtkm/rendering/raytracing/VolumeRendererStructured.cxx @@ -793,7 +793,8 @@ template void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray& rays, Device) { - vtkm::cont::Timer renderTimer; + vtkm::cont::Timer renderTimer{ Device() }; + renderTimer.Start(); Logger* logger = Logger::GetInstance(); logger->OpenLogEntry("volume_render_structured"); logger->AddLogData("device", GetDeviceString(Device())); @@ -808,7 +809,8 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray

timer; + vtkm::cont::Timer timer{ Device() }; + timer.Start(); vtkm::worklet::DispatcherMapField calcRayStartDispatcher( CalcRayStart(this->SpatialExtent)); calcRayStartDispatcher.SetDevice(Device()); @@ -817,7 +819,7 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray

AddLogData("calc_ray_start", time); - timer.Reset(); + timer.Start(); bool isSupportedField = (ScalarField->GetAssociation() == vtkm::cont::Field::Association::POINTS || @@ -908,7 +910,6 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray

AddLogData("sample", time); - timer.Reset(); time = renderTimer.GetElapsedTime(); logger->CloseLogEntry(time); diff --git a/vtkm/worklet/ContourTreeUniformAugmented.h b/vtkm/worklet/ContourTreeUniformAugmented.h index 1aa9247f2..2670a30eb 100644 --- a/vtkm/worklet/ContourTreeUniformAugmented.h +++ b/vtkm/worklet/ContourTreeUniformAugmented.h @@ -186,20 +186,17 @@ private: bool computeRegularStructure) { using namespace vtkm::worklet::contourtree_augmented; - // TODO: This should be switched to use the logging macros defined in vtkm/cont/logging.h - // Start the timer - vtkm::cont::Timer<> totalTime; - // Stage 1: Load the data into the mesh. This is done in the Run() method above and accessible // here via the mesh parameter. The actual data load is performed outside of the // worklet in the example contour tree app (or whoever uses the worklet) // Stage 2 : Sort the data on the mesh to initialize sortIndex & indexReverse on the mesh // Start the timer for the mesh sort - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); mesh.SortData(fieldArray); timings.push_back(std::pair("Sort Data", timer.GetElapsedTime())); - timer.Reset(); + timer.Start(); // Stage 3: Assign every mesh vertex to a peak MeshExtrema extrema(mesh.nVertices); @@ -207,7 +204,7 @@ private: extrema.BuildRegularChains(true); timings.push_back( std::pair("Join Tree Regular Chains", timer.GetElapsedTime())); - timer.Reset(); + timer.Start(); // Stage 4: Identify join saddles & construct Active Join Graph MergeTree joinTree(mesh.nVertices, true); @@ -220,7 +217,7 @@ private: joinGraph.DebugPrint("Active Graph Instantiated", __FILE__, __LINE__); joinGraph.DebugPrint("Active Graph Instantiated", __FILE__, __LINE__); #endif - timer.Reset(); + timer.Start(); // Stage 5: Compute Join Tree Hyperarcs from Active Join Graph joinGraph.MakeMergeTree(joinTree, extrema); @@ -230,14 +227,14 @@ private: joinTree.DebugPrint("Join tree Computed", __FILE__, __LINE__); joinTree.DebugPrintTree("Join tree", __FILE__, __LINE__, mesh); #endif - timer.Reset(); + timer.Start(); // Stage 6: Assign every mesh vertex to a pit extrema.SetStarts(mesh, false); extrema.BuildRegularChains(false); timings.push_back( std::pair("Spit Tree Regular Chains", timer.GetElapsedTime())); - timer.Reset(); + timer.Start(); // Stage 7: Identify split saddles & construct Active Split Graph MergeTree splitTree(mesh.nVertices, false); @@ -248,7 +245,7 @@ private: #ifdef DEBUG_PRINT splitGraph.DebugPrint("Active Graph Instantiated", __FILE__, __LINE__); #endif - timer.Reset(); + timer.Start(); // Stage 8: Compute Split Tree Hyperarcs from Active Split Graph splitGraph.MakeMergeTree(splitTree, extrema); @@ -260,7 +257,7 @@ private: joinTree.DebugPrintTree("Join tree", __FILE__, __LINE__, mesh); splitTree.DebugPrintTree("Split tree", __FILE__, __LINE__, mesh); #endif - timer.Reset(); + timer.Start(); // Stage 9: Join & Split Tree are Augmented, then combined to construct Contour Tree contourTree.Init(mesh.nVertices); @@ -269,7 +266,7 @@ private: treeMaker.ComputeHyperAndSuperStructure(); timings.push_back(std::pair( "Contour Tree Hyper and Super Structure", timer.GetElapsedTime())); - timer.Reset(); + timer.Start(); // 9.2 Then we compute the regular structure if (computeRegularStructure) @@ -277,7 +274,6 @@ private: treeMaker.ComputeRegularStructure(extrema); timings.push_back(std::pair("Contour Tree Regular Structure", timer.GetElapsedTime())); - timer.Reset(); } // Collect the output data diff --git a/vtkm/worklet/KernelSplatter.h b/vtkm/worklet/KernelSplatter.h index 62afcebfd..701fd7330 100644 --- a/vtkm/worklet/KernelSplatter.h +++ b/vtkm/worklet/KernelSplatter.h @@ -46,7 +46,9 @@ //---------------------------------------------------------------------------- #if defined(__VTKM_GAUSSIAN_SPLATTER_BENCHMARK) && !defined(START_TIMER_BLOCK) // start timer -#define START_TIMER_BLOCK(name) vtkm::cont::Timer timer_##name; +#define START_TIMER_BLOCK(name) \ + vtkm::cont::Timer timer_##name{ DeviceAdapter() }; \ + timer_##name.Start(); // stop timer #define END_TIMER_BLOCK(name) \ @@ -453,7 +455,7 @@ struct KernelSplatterFilterUniformGrid START_TIMER_BLOCK(numNeighborsExclusiveSum) vtkm::cont::DeviceAdapterAlgorithm::ScanExclusive(numNeighbors, numNeighborsExclusiveSum); - END_TIMER_BLOCK(numNeighborsExclusiveSum) + //END_TIMER_BLOCK(numNeighborsExclusiveSum) debug::OutputArrayDebug(numNeighborsExclusiveSum, "numNeighborsExclusiveSum"); //--------------------------------------------------------------- diff --git a/vtkm/worklet/VertexClustering.h b/vtkm/worklet/VertexClustering.h index 4dbfbde85..2ddbcac51 100644 --- a/vtkm/worklet/VertexClustering.h +++ b/vtkm/worklet/VertexClustering.h @@ -357,8 +357,10 @@ public: } #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK - vtkm::cont::Timer<> totalTimer; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer totalTimer; + totalTimer.Start(); + vtkm::cont::Timer timer; + timer.Start(); #endif ////////////////////////////////////////////// @@ -374,8 +376,9 @@ public: mapPointsDispatcher.Invoke(coordinates, pointCidArray); #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK + timer.stop(); std::cout << "Time map points (s): " << timer.GetElapsedTime() << std::endl; - timer.Reset(); + timer.Start(); #endif /// pass 2 : Choose a representative point from each cluster for the output: @@ -399,7 +402,7 @@ public: #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK std::cout << "Time after reducing points (s): " << timer.GetElapsedTime() << std::endl; - timer.Reset(); + timer.Start(); #endif /// Pass 3 : Decimated mesh generation @@ -415,7 +418,7 @@ public: #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK std::cout << "Time after clustering cells (s): " << timer.GetElapsedTime() << std::endl; - timer.Reset(); + timer.Start(); #endif /// preparation: Get the indexes of the clustered points to prepare for new cell array @@ -460,7 +463,7 @@ public: #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK std::cout << "Time before sort and unique with hashing (s): " << timer.GetElapsedTime() << std::endl; - timer.Reset(); + timer.Start(); #endif this->CellIdMap = vtkm::worklet::StableSortIndices::Sort(pointId3HashArray); @@ -469,7 +472,7 @@ public: #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK std::cout << "Time after sort and unique with hashing (s): " << timer.GetElapsedTime() << std::endl; - timer.Reset(); + timer.Start(); #endif // Create a temporary permutation array and use that for unhashing. @@ -485,7 +488,7 @@ public: #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK std::cout << "Time before sort and unique [no hashing] (s): " << timer.GetElapsedTime() << std::endl; - timer.Reset(); + timer.Start(); #endif this->CellIdMap = vtkm::worklet::StableSortIndices::Sort(pointId3Array); @@ -494,7 +497,7 @@ public: #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK std::cout << "Time after sort and unique [no hashing] (s): " << timer.GetElapsedTime() << std::endl; - timer.Reset(); + timer.Start(); #endif // Permute the connectivity array into a basic array handle. Use a diff --git a/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx b/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx index b8e84fd5b..b9371b1d7 100644 --- a/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx +++ b/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx @@ -72,8 +72,7 @@ void TestBoundingIntervalHierarchy(vtkm::cont::DataSet dataSet, vtkm::IdComponent numPlanes, const vtkm::cont::DeviceAdapterId& id) { - using DeviceAdapter = VTKM_DEFAULT_DEVICE_ADAPTER_TAG; - using Timer = vtkm::cont::Timer; + using Timer = vtkm::cont::Timer; vtkm::cont::DynamicCellSet cellSet = dataSet.GetCellSet(); vtkm::cont::ArrayHandleVirtualCoordinates vertices = dataSet.GetCoordinateSystem().GetData(); @@ -87,14 +86,17 @@ void TestBoundingIntervalHierarchy(vtkm::cont::DataSet dataSet, std::cout << "Built Bounding Interval Hierarchy Tree" << std::endl; Timer centroidsTimer; + centroidsTimer.Start(); vtkm::cont::ArrayHandle> centroids; vtkm::worklet::DispatcherMapTopology().Invoke( cellSet, vertices, centroids); - //std::cout << "Centroids calculation time: " << centroidsTimer.GetElapsedTime() << "\n"; + centroidsTimer.Stop(); + std::cout << "Centroids calculation time: " << centroidsTimer.GetElapsedTime() << "\n"; vtkm::cont::ArrayHandleCounting expectedCellIds(0, 1, cellSet.GetNumberOfCells()); Timer interpolationTimer; + interpolationTimer.Start(); vtkm::cont::ArrayHandle results; #ifdef VTKM_CUDA //set up stack size for cuda envinroment @@ -119,6 +121,7 @@ void TestBoundingIntervalHierarchy(vtkm::cont::DataSet dataSet, } #endif vtkm::Id numDiffs = vtkm::cont::Algorithm::Reduce(results, 0, vtkm::Add()); + interpolationTimer.Stop(); vtkm::Float64 timeDiff = interpolationTimer.GetElapsedTime(); std::cout << "No of interpolations: " << results.GetNumberOfValues() << "\n"; std::cout << "Interpolation time: " << timeDiff << "\n"; diff --git a/vtkm/worklet/testing/UnitTestWaveletCompressor.cxx b/vtkm/worklet/testing/UnitTestWaveletCompressor.cxx index 1d8f04722..c8309c9e3 100644 --- a/vtkm/worklet/testing/UnitTestWaveletCompressor.cxx +++ b/vtkm/worklet/testing/UnitTestWaveletCompressor.cxx @@ -209,7 +209,8 @@ void TestDecomposeReconstruct3D(vtkm::Float64 cratio) // Decompose - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); computationTime = compressor.WaveDecompose3D(inputArray, nLevels, sigX, sigY, sigZ, outputArray, false); elapsedTime1 = timer.GetElapsedTime(); @@ -217,14 +218,14 @@ void TestDecomposeReconstruct3D(vtkm::Float64 cratio) std::cout << " ->computation time = " << computationTime << std::endl; // Squash small coefficients - timer.Reset(); + timer.Start(); compressor.SquashCoefficients(outputArray, cratio); elapsedTime2 = timer.GetElapsedTime(); std::cout << "Squash time = " << elapsedTime2 << std::endl; // Reconstruct vtkm::cont::ArrayHandle reconstructArray; - timer.Reset(); + timer.Start(); computationTime = compressor.WaveReconstruct3D(outputArray, nLevels, sigX, sigY, sigZ, reconstructArray, false); elapsedTime3 = timer.GetElapsedTime(); @@ -237,7 +238,7 @@ void TestDecomposeReconstruct3D(vtkm::Float64 cratio) compressor.EvaluateReconstruction(inputArray, reconstructArray); - timer.Reset(); + timer.Start(); for (vtkm::Id i = 0; i < reconstructArray.GetNumberOfValues(); i++) { VTKM_TEST_ASSERT(test_equal(reconstructArray.GetPortalConstControl().Get(i), @@ -276,21 +277,22 @@ void TestDecomposeReconstruct2D(vtkm::Float64 cratio) vtkm::Float64 elapsedTime1, elapsedTime2, elapsedTime3; // Decompose - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); computationTime = compressor.WaveDecompose2D(inputArray, nLevels, sigX, sigY, outputArray, L); elapsedTime1 = timer.GetElapsedTime(); std::cout << "Decompose time = " << elapsedTime1 << std::endl; std::cout << " ->computation time = " << computationTime << std::endl; // Squash small coefficients - timer.Reset(); + timer.Start(); compressor.SquashCoefficients(outputArray, cratio); elapsedTime2 = timer.GetElapsedTime(); std::cout << "Squash time = " << elapsedTime2 << std::endl; // Reconstruct vtkm::cont::ArrayHandle reconstructArray; - timer.Reset(); + timer.Start(); computationTime = compressor.WaveReconstruct2D(outputArray, nLevels, sigX, sigY, reconstructArray, L); elapsedTime3 = timer.GetElapsedTime(); @@ -303,7 +305,7 @@ void TestDecomposeReconstruct2D(vtkm::Float64 cratio) compressor.EvaluateReconstruction(inputArray, reconstructArray); - timer.Reset(); + timer.Start(); for (vtkm::Id i = 0; i < reconstructArray.GetNumberOfValues(); i++) { VTKM_TEST_ASSERT(test_equal(reconstructArray.GetPortalConstControl().Get(i), @@ -342,28 +344,29 @@ void TestDecomposeReconstruct1D(vtkm::Float64 cratio) std::vector L; // Decompose - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); compressor.WaveDecompose(inputArray, nLevels, outputArray, L); vtkm::Float64 elapsedTime = timer.GetElapsedTime(); std::cout << "Decompose time = " << elapsedTime << std::endl; // Squash small coefficients - timer.Reset(); + timer.Start(); compressor.SquashCoefficients(outputArray, cratio); elapsedTime = timer.GetElapsedTime(); std::cout << "Squash time = " << elapsedTime << std::endl; // Reconstruct vtkm::cont::ArrayHandle reconstructArray; - timer.Reset(); + timer.Start(); compressor.WaveReconstruct(outputArray, nLevels, L, reconstructArray); elapsedTime = timer.GetElapsedTime(); std::cout << "Reconstruction time = " << elapsedTime << std::endl; compressor.EvaluateReconstruction(inputArray, reconstructArray); - timer.Reset(); + timer.Start(); for (vtkm::Id i = 0; i < reconstructArray.GetNumberOfValues(); i++) { VTKM_TEST_ASSERT(test_equal(reconstructArray.GetPortalConstControl().Get(i), diff --git a/vtkm/worklet/testing/UnitTestWaveletGenerator.cxx b/vtkm/worklet/testing/UnitTestWaveletGenerator.cxx index 6502c748c..5ec595709 100644 --- a/vtkm/worklet/testing/UnitTestWaveletGenerator.cxx +++ b/vtkm/worklet/testing/UnitTestWaveletGenerator.cxx @@ -42,7 +42,8 @@ struct WaveletGeneratorFunctor void WaveletGeneratorTest() { - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); detail::WaveletGeneratorFunctor wgFunctor; vtkm::cont::TryExecute(wgFunctor); diff --git a/vtkm/worklet/wavelets/WaveletDWT.h b/vtkm/worklet/wavelets/WaveletDWT.h index 439073b92..1d256287e 100644 --- a/vtkm/worklet/wavelets/WaveletDWT.h +++ b/vtkm/worklet/wavelets/WaveletDWT.h @@ -602,7 +602,7 @@ public: using TopDownDispatcherType = vtkm::worklet::DispatcherMapField; using FrontBackDispatcherType = vtkm::worklet::DispatcherMapField; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; vtkm::Float64 computationTime = 0.0; // First transform in X direction @@ -646,7 +646,7 @@ public: sigPretendDimY, sigPretendDimZ); LeftRightDispatcherType dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(leftExt, sigIn, rightExt, @@ -702,7 +702,7 @@ public: addLen, sigPretendDimZ); TopDownDispatcherType dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(topExt, afterX, bottomExt, @@ -753,7 +753,7 @@ public: sigPretendDimY, addLen); FrontBackDispatcherType dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(frontExt, afterY, backExt, @@ -795,7 +795,7 @@ public: using TopDownDispatcherType = vtkm::worklet::DispatcherMapField; using FrontBackDispatcherType = vtkm::worklet::DispatcherMapField; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; vtkm::Float64 computationTime = 0.0; // First, inverse transform in Z direction @@ -854,7 +854,7 @@ public: inStartY, inStartZ); // coeffIn FrontBackDispatcherType dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(ext1, ext2, ext3, @@ -927,7 +927,7 @@ public: 0, 0); TopDownDispatcherType dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(ext1, ext2, ext3, @@ -995,7 +995,7 @@ public: 0, 0); LeftRightDispatcherType dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(ext1, ext2, ext3, @@ -1489,7 +1489,8 @@ public: vtkm::worklet::DispatcherMapField dispatcher( forwardTransform); // put a timer - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); dispatcher.Invoke(sigInExtended, WaveletBase::filter.GetLowDecomposeFilter(), WaveletBase::filter.GetHighDecomposeFilter(), @@ -1643,7 +1644,8 @@ public: vtkm::worklet::DispatcherMapField dispatcher( inverseXformOdd); // use a timer - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); dispatcher.Invoke(coeffInExtended, WaveletBase::filter.GetLowReconstructFilter(), WaveletBase::filter.GetHighReconstructFilter(), @@ -1657,7 +1659,8 @@ public: vtkm::worklet::DispatcherMapField dispatcher( inverseXformEven); // use a timer - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; + timer.Start(); dispatcher.Invoke(coeffInExtended, WaveletBase::filter.GetLowReconstructFilter(), WaveletBase::filter.GetHighReconstructFilter(), @@ -1728,7 +1731,7 @@ public: using ForwardXForm = vtkm::worklet::wavelets::ForwardTransform2D; using DispatcherType = typename vtkm::worklet::DispatcherMapField; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; vtkm::Float64 computationTime = 0.0; ArrayType afterX; @@ -1767,7 +1770,7 @@ public: addLen, sigPretendDimY); DispatcherType dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(leftExt, sigIn, rightExt, @@ -1811,7 +1814,7 @@ public: sigPretendDimX, addLen); DispatcherType dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(topExt, afterX, bottomExt, @@ -1842,7 +1845,7 @@ public: using BasicArrayType = vtkm::cont::ArrayHandle; using IDWT2DWorklet = vtkm::worklet::wavelets::InverseTransform2D; using Dispatcher = vtkm::worklet::DispatcherMapField; - vtkm::cont::Timer<> timer; + vtkm::cont::Timer timer; vtkm::Float64 computationTime = 0.0; // First inverse transform on columns @@ -1891,7 +1894,7 @@ public: inStartY, // coeffIn false); // top-down Dispatcher dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(ext1, ext2, ext3, @@ -1947,7 +1950,7 @@ public: 0, true); // left-right Dispatcher dispatcher(worklet); - timer.Reset(); + timer.Start(); dispatcher.Invoke(ext1, ext2, ext3,