mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-18 18:15:44 +00:00
Add ArrayHandleMultiplexer testing to BenchmarkFieldAlgorithms
This commit is contained in:
parent
d451064525
commit
5416cbeb7e
@ -12,6 +12,7 @@
|
|||||||
#include <vtkm/VectorAnalysis.h>
|
#include <vtkm/VectorAnalysis.h>
|
||||||
|
|
||||||
#include <vtkm/cont/ArrayHandle.h>
|
#include <vtkm/cont/ArrayHandle.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleMultiplexer.h>
|
||||||
#include <vtkm/cont/CellSetStructured.h>
|
#include <vtkm/cont/CellSetStructured.h>
|
||||||
#include <vtkm/cont/ImplicitFunctionHandle.h>
|
#include <vtkm/cont/ImplicitFunctionHandle.h>
|
||||||
#include <vtkm/cont/Initialize.h>
|
#include <vtkm/cont/Initialize.h>
|
||||||
@ -312,6 +313,8 @@ class BenchmarkFieldAlgorithms
|
|||||||
using InterpVariantHandle = vtkm::cont::VariantArrayHandleBase<InterpValueTypes>;
|
using InterpVariantHandle = vtkm::cont::VariantArrayHandleBase<InterpValueTypes>;
|
||||||
using EdgeIdVariantHandle = vtkm::cont::VariantArrayHandleBase<vtkm::TypeListTagId2>;
|
using EdgeIdVariantHandle = vtkm::cont::VariantArrayHandleBase<vtkm::TypeListTagId2>;
|
||||||
|
|
||||||
|
using ValueMultiplexerHandle = vtkm::cont::ArrayHandleMultiplexer<vtkm::FloatDefault>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename Value, typename DeviceAdapter>
|
template <typename Value, typename DeviceAdapter>
|
||||||
struct BenchBlackScholes
|
struct BenchBlackScholes
|
||||||
@ -349,8 +352,10 @@ private:
|
|||||||
this->OptionYears = vtkm::cont::make_ArrayHandle(this->years);
|
this->OptionYears = vtkm::cont::make_ArrayHandle(this->years);
|
||||||
}
|
}
|
||||||
|
|
||||||
VTKM_CONT
|
template <typename StockPriceType, typename OptionStrikeType, typename OptionYearsType>
|
||||||
vtkm::Float64 operator()()
|
VTKM_CONT static vtkm::Float64 Run(const StockPriceType& stockPrice,
|
||||||
|
const OptionStrikeType& optionStrike,
|
||||||
|
const OptionYearsType& optionYears)
|
||||||
{
|
{
|
||||||
vtkm::cont::ArrayHandle<Value> callResultHandle, putResultHandle;
|
vtkm::cont::ArrayHandle<Value> callResultHandle, putResultHandle;
|
||||||
const Value RISKFREE = 0.02f;
|
const Value RISKFREE = 0.02f;
|
||||||
@ -361,12 +366,17 @@ private:
|
|||||||
BlackScholes<Value> worklet(RISKFREE, VOLATILITY);
|
BlackScholes<Value> worklet(RISKFREE, VOLATILITY);
|
||||||
vtkm::worklet::DispatcherMapField<BlackScholes<Value>> dispatcher(worklet);
|
vtkm::worklet::DispatcherMapField<BlackScholes<Value>> dispatcher(worklet);
|
||||||
|
|
||||||
dispatcher.Invoke(
|
dispatcher.Invoke(stockPrice, optionStrike, optionYears, callResultHandle, putResultHandle);
|
||||||
this->StockPrice, this->OptionStrike, this->OptionYears, callResultHandle, putResultHandle);
|
|
||||||
|
|
||||||
return timer.GetElapsedTime();
|
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"); }
|
virtual std::string Type() const { return std::string("Static"); }
|
||||||
|
|
||||||
VTKM_CONT
|
VTKM_CONT
|
||||||
@ -391,25 +401,35 @@ private:
|
|||||||
ValueVariantHandle dstrikes(this->OptionStrike);
|
ValueVariantHandle dstrikes(this->OptionStrike);
|
||||||
ValueVariantHandle doptions(this->OptionYears);
|
ValueVariantHandle doptions(this->OptionYears);
|
||||||
|
|
||||||
vtkm::cont::ArrayHandle<Value> callResultHandle, putResultHandle;
|
return this->Run(dstocks, dstrikes, doptions);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string Type() const { return std::string("Dynamic"); }
|
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(BlackScholes, BenchBlackScholes);
|
||||||
VTKM_MAKE_BENCHMARK(BlackScholesDynamic, BenchBlackScholesDynamic);
|
VTKM_MAKE_BENCHMARK(BlackScholesDynamic, BenchBlackScholesDynamic);
|
||||||
|
VTKM_MAKE_BENCHMARK(BlackScholesMultiplexer, BenchBlackScholesMultiplexer);
|
||||||
|
|
||||||
template <typename Value, typename DeviceAdapter>
|
template <typename Value, typename DeviceAdapter>
|
||||||
struct BenchMath
|
struct BenchMath
|
||||||
@ -493,8 +513,38 @@ private:
|
|||||||
virtual std::string Type() const { return std::string("Dynamic"); }
|
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(Math, BenchMath);
|
||||||
VTKM_MAKE_BENCHMARK(MathDynamic, BenchMathDynamic);
|
VTKM_MAKE_BENCHMARK(MathDynamic, BenchMathDynamic);
|
||||||
|
VTKM_MAKE_BENCHMARK(MathMultiplexer, BenchMathMultiplexer);
|
||||||
|
|
||||||
template <typename Value, typename DeviceAdapter>
|
template <typename Value, typename DeviceAdapter>
|
||||||
struct BenchFusedMath
|
struct BenchFusedMath
|
||||||
@ -517,19 +567,22 @@ private:
|
|||||||
this->InputHandle = vtkm::cont::make_ArrayHandle(this->input);
|
this->InputHandle = vtkm::cont::make_ArrayHandle(this->input);
|
||||||
}
|
}
|
||||||
|
|
||||||
VTKM_CONT
|
template <typename InputHandleType>
|
||||||
vtkm::Float64 operator()()
|
VTKM_CONT static vtkm::Float64 Run(const InputHandleType& inputHandle)
|
||||||
{
|
{
|
||||||
vtkm::cont::ArrayHandle<Value> result;
|
vtkm::cont::ArrayHandle<Value, StorageTag> result;
|
||||||
|
|
||||||
Timer timer{ DeviceAdapter() };
|
Timer timer{ DeviceAdapter() };
|
||||||
timer.Start();
|
timer.Start();
|
||||||
vtkm::worklet::DispatcherMapField<FusedMath> dispatcher;
|
vtkm::worklet::DispatcherMapField<FusedMath> dispatcher;
|
||||||
dispatcher.Invoke(this->InputHandle, result);
|
dispatcher.Invoke(inputHandle, result);
|
||||||
|
|
||||||
return timer.GetElapsedTime();
|
return timer.GetElapsedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
vtkm::Float64 operator()() { return this->Run(this->InputHandle); }
|
||||||
|
|
||||||
virtual std::string Type() const { return std::string("Static"); }
|
virtual std::string Type() const { return std::string("Static"); }
|
||||||
|
|
||||||
VTKM_CONT
|
VTKM_CONT
|
||||||
@ -554,21 +607,31 @@ private:
|
|||||||
|
|
||||||
vtkm::cont::VariantArrayHandleBase<MathTypes> dinput(this->InputHandle);
|
vtkm::cont::VariantArrayHandleBase<MathTypes> dinput(this->InputHandle);
|
||||||
|
|
||||||
vtkm::cont::ArrayHandle<Value, StorageTag> result;
|
return this->Run(dinput);
|
||||||
|
|
||||||
Timer timer{ DeviceAdapter() };
|
|
||||||
timer.Start();
|
|
||||||
vtkm::worklet::DispatcherMapField<FusedMath> dispatcher;
|
|
||||||
dispatcher.Invoke(dinput, result);
|
|
||||||
|
|
||||||
return timer.GetElapsedTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string Type() const { return std::string("Dynamic"); }
|
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(FusedMath, BenchFusedMath);
|
||||||
VTKM_MAKE_BENCHMARK(FusedMathDynamic, BenchFusedMathDynamic);
|
VTKM_MAKE_BENCHMARK(FusedMathDynamic, BenchFusedMathDynamic);
|
||||||
|
VTKM_MAKE_BENCHMARK(FusedMathMultiplexer, BenchFusedMathMultiplexer);
|
||||||
|
|
||||||
template <typename Value, typename DeviceAdapter>
|
template <typename Value, typename DeviceAdapter>
|
||||||
struct BenchEdgeInterp
|
struct BenchEdgeInterp
|
||||||
@ -877,6 +940,7 @@ public:
|
|||||||
std::cout << DIVIDER << "\nBenchmarking BlackScholes\n";
|
std::cout << DIVIDER << "\nBenchmarking BlackScholes\n";
|
||||||
VTKM_RUN_BENCHMARK(BlackScholes, ValueTypes(), id);
|
VTKM_RUN_BENCHMARK(BlackScholes, ValueTypes(), id);
|
||||||
VTKM_RUN_BENCHMARK(BlackScholesDynamic, ValueTypes(), id);
|
VTKM_RUN_BENCHMARK(BlackScholesDynamic, ValueTypes(), id);
|
||||||
|
VTKM_RUN_BENCHMARK(BlackScholesMultiplexer, ValueTypes(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (benchmarks & MATH)
|
if (benchmarks & MATH)
|
||||||
@ -884,6 +948,7 @@ public:
|
|||||||
std::cout << DIVIDER << "\nBenchmarking Multiple Math Worklets\n";
|
std::cout << DIVIDER << "\nBenchmarking Multiple Math Worklets\n";
|
||||||
VTKM_RUN_BENCHMARK(Math, ValueTypes(), id);
|
VTKM_RUN_BENCHMARK(Math, ValueTypes(), id);
|
||||||
VTKM_RUN_BENCHMARK(MathDynamic, ValueTypes(), id);
|
VTKM_RUN_BENCHMARK(MathDynamic, ValueTypes(), id);
|
||||||
|
VTKM_RUN_BENCHMARK(MathMultiplexer, ValueTypes(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (benchmarks & FUSED_MATH)
|
if (benchmarks & FUSED_MATH)
|
||||||
@ -891,6 +956,7 @@ public:
|
|||||||
std::cout << DIVIDER << "\nBenchmarking Single Fused Math Worklet\n";
|
std::cout << DIVIDER << "\nBenchmarking Single Fused Math Worklet\n";
|
||||||
VTKM_RUN_BENCHMARK(FusedMath, ValueTypes(), id);
|
VTKM_RUN_BENCHMARK(FusedMath, ValueTypes(), id);
|
||||||
VTKM_RUN_BENCHMARK(FusedMathDynamic, ValueTypes(), id);
|
VTKM_RUN_BENCHMARK(FusedMathDynamic, ValueTypes(), id);
|
||||||
|
VTKM_RUN_BENCHMARK(FusedMathMultiplexer, ValueTypes(), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (benchmarks & INTERPOLATE_FIELD)
|
if (benchmarks & INTERPOLATE_FIELD)
|
||||||
|
@ -283,6 +283,7 @@ public:
|
|||||||
VTKM_CONT bool operator()(DeviceAdapter id, MakerFunctor&& makerFunctor, T t)
|
VTKM_CONT bool operator()(DeviceAdapter id, MakerFunctor&& makerFunctor, T t)
|
||||||
{
|
{
|
||||||
auto func = makerFunctor(t, id);
|
auto func = makerFunctor(t, id);
|
||||||
|
std::cout << "Running '" << func.Description() << "'" << std::endl;
|
||||||
this->GatherSamples(func);
|
this->GatherSamples(func);
|
||||||
this->PrintSummary();
|
this->PrintSummary();
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user