From 5416cbeb7e34f36ce3ea572538764091e0e658cb Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Wed, 17 Jul 2019 17:22:32 -0600 Subject: [PATCH] Add ArrayHandleMultiplexer testing to BenchmarkFieldAlgorithms --- benchmarking/BenchmarkFieldAlgorithms.cxx | 122 +++++++++++++++++----- benchmarking/Benchmarker.h | 1 + 2 files changed, 95 insertions(+), 28 deletions(-) diff --git a/benchmarking/BenchmarkFieldAlgorithms.cxx b/benchmarking/BenchmarkFieldAlgorithms.cxx index 6878d952c..f10cb58ef 100644 --- a/benchmarking/BenchmarkFieldAlgorithms.cxx +++ b/benchmarking/BenchmarkFieldAlgorithms.cxx @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -312,6 +313,8 @@ class BenchmarkFieldAlgorithms using InterpVariantHandle = vtkm::cont::VariantArrayHandleBase; using EdgeIdVariantHandle = vtkm::cont::VariantArrayHandleBase; + using ValueMultiplexerHandle = vtkm::cont::ArrayHandleMultiplexer; + private: template struct BenchBlackScholes @@ -349,8 +352,10 @@ private: this->OptionYears = vtkm::cont::make_ArrayHandle(this->years); } - VTKM_CONT - vtkm::Float64 operator()() + template + VTKM_CONT static vtkm::Float64 Run(const StockPriceType& stockPrice, + const OptionStrikeType& optionStrike, + const OptionYearsType& optionYears) { vtkm::cont::ArrayHandle callResultHandle, putResultHandle; const Value RISKFREE = 0.02f; @@ -361,12 +366,17 @@ private: BlackScholes worklet(RISKFREE, VOLATILITY); vtkm::worklet::DispatcherMapField> dispatcher(worklet); - dispatcher.Invoke( - this->StockPrice, this->OptionStrike, this->OptionYears, callResultHandle, putResultHandle); + dispatcher.Invoke(stockPrice, optionStrike, optionYears, callResultHandle, putResultHandle); return timer.GetElapsedTime(); } + VTKM_CONT + vtkm::Float64 operator()() + { + return this->Run(this->StockPrice, this->OptionStrike, this->OptionYears); + } + virtual std::string Type() const { return std::string("Static"); } VTKM_CONT @@ -391,25 +401,35 @@ private: ValueVariantHandle dstrikes(this->OptionStrike); ValueVariantHandle doptions(this->OptionYears); - vtkm::cont::ArrayHandle callResultHandle, putResultHandle; - const Value RISKFREE = 0.02f; - const Value VOLATILITY = 0.30f; - - Timer timer{ DeviceAdapter() }; - timer.Start(); - BlackScholes worklet(RISKFREE, VOLATILITY); - vtkm::worklet::DispatcherMapField> dispatcher(worklet); - - dispatcher.Invoke(dstocks, dstrikes, doptions, callResultHandle, putResultHandle); - - return timer.GetElapsedTime(); + return this->Run(dstocks, dstrikes, doptions); } virtual std::string Type() const { return std::string("Dynamic"); } }; + template + struct BenchBlackScholesMultiplexer : public BenchBlackScholes + { + + VTKM_CONT + vtkm::Float64 operator()() + { + ValueMultiplexerHandle mstocks( + vtkm::cont::make_ArrayHandleCast(this->StockPrice)); + ValueMultiplexerHandle mstrikes( + vtkm::cont::make_ArrayHandleCast(this->OptionStrike)); + ValueMultiplexerHandle moptions( + vtkm::cont::make_ArrayHandleCast(this->OptionYears)); + + return this->Run(mstocks, mstrikes, moptions); + } + + virtual std::string Type() const { return std::string("Multiplexer"); } + }; + VTKM_MAKE_BENCHMARK(BlackScholes, BenchBlackScholes); VTKM_MAKE_BENCHMARK(BlackScholesDynamic, BenchBlackScholesDynamic); + VTKM_MAKE_BENCHMARK(BlackScholesMultiplexer, BenchBlackScholesMultiplexer); template struct BenchMath @@ -493,8 +513,38 @@ private: virtual std::string Type() const { return std::string("Dynamic"); } }; + template + struct BenchMathMultiplexer : public BenchMath + { + + VTKM_CONT + vtkm::Float64 operator()() + { + vtkm::cont::ArrayHandle temp1; + vtkm::cont::ArrayHandle temp2; + vtkm::cont::ArrayHandleMultiplexer> mInput( + vtkm::cont::make_ArrayHandleCast>(this->InputHandle)); + ValueMultiplexerHandle mTemp1(vtkm::cont::make_ArrayHandleCast(temp1)); + ValueMultiplexerHandle mTemp2(vtkm::cont::make_ArrayHandleCast(temp2)); + + Timer timer{ DeviceAdapter() }; + timer.Start(); + + vtkm::worklet::Invoker invoke(DeviceAdapter{}); + invoke(Mag{}, mInput, mTemp1); + invoke(Sin{}, mTemp1, mTemp2); + invoke(Square{}, mTemp2, mTemp1); + invoke(Cos{}, mTemp1, mTemp2); + + return timer.GetElapsedTime(); + } + + virtual std::string Type() const { return std::string("Multiplexer"); } + }; + VTKM_MAKE_BENCHMARK(Math, BenchMath); VTKM_MAKE_BENCHMARK(MathDynamic, BenchMathDynamic); + VTKM_MAKE_BENCHMARK(MathMultiplexer, BenchMathMultiplexer); template struct BenchFusedMath @@ -517,19 +567,22 @@ private: this->InputHandle = vtkm::cont::make_ArrayHandle(this->input); } - VTKM_CONT - vtkm::Float64 operator()() + template + VTKM_CONT static vtkm::Float64 Run(const InputHandleType& inputHandle) { - vtkm::cont::ArrayHandle result; + vtkm::cont::ArrayHandle result; Timer timer{ DeviceAdapter() }; timer.Start(); vtkm::worklet::DispatcherMapField dispatcher; - dispatcher.Invoke(this->InputHandle, result); + dispatcher.Invoke(inputHandle, result); return timer.GetElapsedTime(); } + VTKM_CONT + vtkm::Float64 operator()() { return this->Run(this->InputHandle); } + virtual std::string Type() const { return std::string("Static"); } VTKM_CONT @@ -554,21 +607,31 @@ private: vtkm::cont::VariantArrayHandleBase dinput(this->InputHandle); - vtkm::cont::ArrayHandle result; - - Timer timer{ DeviceAdapter() }; - timer.Start(); - vtkm::worklet::DispatcherMapField dispatcher; - dispatcher.Invoke(dinput, result); - - return timer.GetElapsedTime(); + return this->Run(dinput); } virtual std::string Type() const { return std::string("Dynamic"); } }; + template + struct BenchFusedMathMultiplexer : public BenchFusedMath + { + + VTKM_CONT + vtkm::Float64 operator()() + { + vtkm::cont::ArrayHandleMultiplexer> mInput( + vtkm::cont::make_ArrayHandleCast>(this->InputHandle)); + + return this->Run(mInput); + } + + virtual std::string Type() const { return std::string("Multiplexer"); } + }; + VTKM_MAKE_BENCHMARK(FusedMath, BenchFusedMath); VTKM_MAKE_BENCHMARK(FusedMathDynamic, BenchFusedMathDynamic); + VTKM_MAKE_BENCHMARK(FusedMathMultiplexer, BenchFusedMathMultiplexer); template struct BenchEdgeInterp @@ -877,6 +940,7 @@ public: std::cout << DIVIDER << "\nBenchmarking BlackScholes\n"; VTKM_RUN_BENCHMARK(BlackScholes, ValueTypes(), id); VTKM_RUN_BENCHMARK(BlackScholesDynamic, ValueTypes(), id); + VTKM_RUN_BENCHMARK(BlackScholesMultiplexer, ValueTypes(), id); } if (benchmarks & MATH) @@ -884,6 +948,7 @@ public: std::cout << DIVIDER << "\nBenchmarking Multiple Math Worklets\n"; VTKM_RUN_BENCHMARK(Math, ValueTypes(), id); VTKM_RUN_BENCHMARK(MathDynamic, ValueTypes(), id); + VTKM_RUN_BENCHMARK(MathMultiplexer, ValueTypes(), id); } if (benchmarks & FUSED_MATH) @@ -891,6 +956,7 @@ public: std::cout << DIVIDER << "\nBenchmarking Single Fused Math Worklet\n"; VTKM_RUN_BENCHMARK(FusedMath, ValueTypes(), id); VTKM_RUN_BENCHMARK(FusedMathDynamic, ValueTypes(), id); + VTKM_RUN_BENCHMARK(FusedMathMultiplexer, ValueTypes(), id); } if (benchmarks & INTERPOLATE_FIELD) diff --git a/benchmarking/Benchmarker.h b/benchmarking/Benchmarker.h index 7120d8520..39b12aa59 100644 --- a/benchmarking/Benchmarker.h +++ b/benchmarking/Benchmarker.h @@ -283,6 +283,7 @@ public: VTKM_CONT bool operator()(DeviceAdapter id, MakerFunctor&& makerFunctor, T t) { auto func = makerFunctor(t, id); + std::cout << "Running '" << func.Description() << "'" << std::endl; this->GatherSamples(func); this->PrintSummary(); return true;