Add ArrayHandleMultiplexer testing to BenchmarkFieldAlgorithms

This commit is contained in:
Kenneth Moreland 2019-07-17 17:22:32 -06:00
parent d451064525
commit 5416cbeb7e
2 changed files with 95 additions and 28 deletions

@ -12,6 +12,7 @@
#include <vtkm/VectorAnalysis.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleMultiplexer.h>
#include <vtkm/cont/CellSetStructured.h>
#include <vtkm/cont/ImplicitFunctionHandle.h>
#include <vtkm/cont/Initialize.h>
@ -312,6 +313,8 @@ class BenchmarkFieldAlgorithms
using InterpVariantHandle = vtkm::cont::VariantArrayHandleBase<InterpValueTypes>;
using EdgeIdVariantHandle = vtkm::cont::VariantArrayHandleBase<vtkm::TypeListTagId2>;
using ValueMultiplexerHandle = vtkm::cont::ArrayHandleMultiplexer<vtkm::FloatDefault>;
private:
template <typename Value, typename DeviceAdapter>
struct BenchBlackScholes
@ -349,8 +352,10 @@ private:
this->OptionYears = vtkm::cont::make_ArrayHandle(this->years);
}
VTKM_CONT
vtkm::Float64 operator()()
template <typename StockPriceType, typename OptionStrikeType, typename OptionYearsType>
VTKM_CONT static vtkm::Float64 Run(const StockPriceType& stockPrice,
const OptionStrikeType& optionStrike,
const OptionYearsType& optionYears)
{
vtkm::cont::ArrayHandle<Value> callResultHandle, putResultHandle;
const Value RISKFREE = 0.02f;
@ -361,12 +366,17 @@ private:
BlackScholes<Value> worklet(RISKFREE, VOLATILITY);
vtkm::worklet::DispatcherMapField<BlackScholes<Value>> 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<Value> callResultHandle, putResultHandle;
const Value RISKFREE = 0.02f;
const Value VOLATILITY = 0.30f;
Timer timer{ DeviceAdapter() };
timer.Start();
BlackScholes<Value> worklet(RISKFREE, VOLATILITY);
vtkm::worklet::DispatcherMapField<BlackScholes<Value>> 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 <typename Value, typename DeviceAdapter>
struct BenchBlackScholesMultiplexer : public BenchBlackScholes<Value, DeviceAdapter>
{
VTKM_CONT
vtkm::Float64 operator()()
{
ValueMultiplexerHandle mstocks(
vtkm::cont::make_ArrayHandleCast<vtkm::FloatDefault>(this->StockPrice));
ValueMultiplexerHandle mstrikes(
vtkm::cont::make_ArrayHandleCast<vtkm::FloatDefault>(this->OptionStrike));
ValueMultiplexerHandle moptions(
vtkm::cont::make_ArrayHandleCast<vtkm::FloatDefault>(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 <typename Value, typename DeviceAdapter>
struct BenchMath
@ -493,8 +513,38 @@ private:
virtual std::string Type() const { return std::string("Dynamic"); }
};
template <typename Value, typename DeviceAdapter>
struct BenchMathMultiplexer : public BenchMath<Value, DeviceAdapter>
{
VTKM_CONT
vtkm::Float64 operator()()
{
vtkm::cont::ArrayHandle<Value> temp1;
vtkm::cont::ArrayHandle<Value> temp2;
vtkm::cont::ArrayHandleMultiplexer<vtkm::Vec<vtkm::FloatDefault, 3>> mInput(
vtkm::cont::make_ArrayHandleCast<vtkm::Vec<vtkm::FloatDefault, 3>>(this->InputHandle));
ValueMultiplexerHandle mTemp1(vtkm::cont::make_ArrayHandleCast<vtkm::FloatDefault>(temp1));
ValueMultiplexerHandle mTemp2(vtkm::cont::make_ArrayHandleCast<vtkm::FloatDefault>(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 <typename Value, typename DeviceAdapter>
struct BenchFusedMath
@ -517,19 +567,22 @@ private:
this->InputHandle = vtkm::cont::make_ArrayHandle(this->input);
}
VTKM_CONT
vtkm::Float64 operator()()
template <typename InputHandleType>
VTKM_CONT static vtkm::Float64 Run(const InputHandleType& inputHandle)
{
vtkm::cont::ArrayHandle<Value> result;
vtkm::cont::ArrayHandle<Value, StorageTag> result;
Timer timer{ DeviceAdapter() };
timer.Start();
vtkm::worklet::DispatcherMapField<FusedMath> 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<MathTypes> dinput(this->InputHandle);
vtkm::cont::ArrayHandle<Value, StorageTag> result;
Timer timer{ DeviceAdapter() };
timer.Start();
vtkm::worklet::DispatcherMapField<FusedMath> dispatcher;
dispatcher.Invoke(dinput, result);
return timer.GetElapsedTime();
return this->Run(dinput);
}
virtual std::string Type() const { return std::string("Dynamic"); }
};
template <typename Value, typename DeviceAdapter>
struct BenchFusedMathMultiplexer : public BenchFusedMath<Value, DeviceAdapter>
{
VTKM_CONT
vtkm::Float64 operator()()
{
vtkm::cont::ArrayHandleMultiplexer<vtkm::Vec<Value, 3>> mInput(
vtkm::cont::make_ArrayHandleCast<vtkm::Vec<Value, 3>>(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 <typename Value, typename DeviceAdapter>
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)

@ -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;