2017-07-06 20:08:40 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-07-06 20:08:40 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
2017-12-29 22:21:29 +00:00
|
|
|
#include "Benchmarker.h"
|
2017-07-06 20:08:40 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2019-02-15 19:47:07 +00:00
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
2019-12-26 19:48:51 +00:00
|
|
|
#include <vtkm/cont/Invoker.h>
|
2017-07-06 20:08:40 +00:00
|
|
|
#include <vtkm/cont/Timer.h>
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
#include <vtkm/worklet/WorkletMapField.h>
|
2017-07-06 20:08:40 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
namespace
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Make this global so benchmarks can access the current device id:
|
|
|
|
vtkm::cont::InitializeResult Config;
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const vtkm::UInt64 COPY_SIZE_MIN = (1 << 10); // 1 KiB
|
|
|
|
const vtkm::UInt64 COPY_SIZE_MAX = (1 << 30); // 1 GiB
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
using TestTypes = vtkm::List<vtkm::Float32>;
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
//------------- Functors for benchmarks --------------------------------------
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Reads all values in ArrayHandle.
|
|
|
|
struct ReadValues : vtkm::worklet::WorkletMapField
|
|
|
|
{
|
|
|
|
using ControlSignature = void(FieldIn);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
template <typename T>
|
|
|
|
VTKM_EXEC void operator()(const T& val) const
|
|
|
|
{
|
|
|
|
if (val < 0)
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
// We don't really do anything with this, we just need to do *something*
|
|
|
|
// to prevent the compiler from optimizing out the array accesses.
|
|
|
|
this->RaiseError("Unexpected value.");
|
2017-07-06 20:08:40 +00:00
|
|
|
}
|
2019-12-26 19:48:51 +00:00
|
|
|
}
|
|
|
|
};
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Writes values to ArrayHandle.
|
|
|
|
struct WriteValues : vtkm::worklet::WorkletMapField
|
|
|
|
{
|
|
|
|
using ControlSignature = void(FieldOut);
|
|
|
|
using ExecutionSignature = void(_1, InputIndex);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
template <typename T>
|
|
|
|
VTKM_EXEC void operator()(T& val, vtkm::Id idx) const
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
val = static_cast<T>(idx);
|
|
|
|
}
|
|
|
|
};
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Reads and writes values to ArrayHandle.
|
|
|
|
struct ReadWriteValues : vtkm::worklet::WorkletMapField
|
|
|
|
{
|
|
|
|
using ControlSignature = void(FieldInOut);
|
|
|
|
using ExecutionSignature = void(_1, InputIndex);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
template <typename T>
|
|
|
|
VTKM_EXEC void operator()(T& val, vtkm::Id idx) const
|
|
|
|
{
|
|
|
|
val += static_cast<T>(idx);
|
|
|
|
}
|
|
|
|
};
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2020-07-24 01:34:45 +00:00
|
|
|
// Takes a vector of data and creates a fresh ArrayHandle with memory just allocated
|
|
|
|
// in the control environment.
|
|
|
|
template <typename T>
|
|
|
|
vtkm::cont::ArrayHandle<T> CreateFreshArrayHandle(const std::vector<T>& vec)
|
|
|
|
{
|
|
|
|
return vtkm::cont::make_ArrayHandleMove(std::vector<T>(vec));
|
|
|
|
}
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
//------------- Benchmark functors -------------------------------------------
|
|
|
|
|
|
|
|
// Copies NumValues from control environment to execution environment and
|
|
|
|
// accesses them as read-only.
|
|
|
|
template <typename ValueType>
|
|
|
|
void BenchContToExecRead(benchmark::State& state)
|
|
|
|
{
|
|
|
|
using ArrayType = vtkm::cont::ArrayHandle<ValueType>;
|
|
|
|
|
|
|
|
const vtkm::cont::DeviceAdapterId device = Config.Device;
|
|
|
|
const vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(state.range(0));
|
|
|
|
const vtkm::Id numValues = static_cast<vtkm::Id>(numBytes / sizeof(ValueType));
|
2017-07-06 20:08:40 +00:00
|
|
|
|
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
std::ostringstream desc;
|
|
|
|
desc << "Control --> Execution (read-only): " << numValues << " values ("
|
|
|
|
<< vtkm::cont::GetHumanReadableSize(numBytes) << ")";
|
|
|
|
state.SetLabel(desc.str());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2020-07-16 16:32:32 +00:00
|
|
|
std::vector<ValueType> vec(static_cast<std::size_t>(numValues), 2);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::Invoker invoker{ device };
|
|
|
|
vtkm::cont::Timer timer{ device };
|
|
|
|
for (auto _ : state)
|
|
|
|
{
|
|
|
|
(void)_;
|
2020-07-24 01:34:45 +00:00
|
|
|
|
|
|
|
// Make a fresh array each iteration to force a copy from control to execution each time.
|
|
|
|
// (Prevents unified memory devices from caching data.)
|
|
|
|
ArrayType array = CreateFreshArrayHandle(vec);
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Start();
|
|
|
|
invoker(ReadValues{}, array);
|
|
|
|
timer.Stop();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetIterationTime(timer.GetElapsedTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
const int64_t iterations = static_cast<int64_t>(state.iterations());
|
|
|
|
state.SetBytesProcessed(static_cast<int64_t>(numBytes) * iterations);
|
|
|
|
state.SetItemsProcessed(static_cast<int64_t>(numValues) * iterations);
|
|
|
|
}
|
|
|
|
VTKM_BENCHMARK_TEMPLATES_OPTS(BenchContToExecRead,
|
|
|
|
->Range(COPY_SIZE_MIN, COPY_SIZE_MAX)
|
|
|
|
->ArgName("Bytes"),
|
|
|
|
TestTypes);
|
|
|
|
|
|
|
|
// Writes values to ArrayHandle in execution environment. There is no actual
|
|
|
|
// copy between control/execution in this case.
|
|
|
|
template <typename ValueType>
|
|
|
|
void BenchContToExecWrite(benchmark::State& state)
|
|
|
|
{
|
|
|
|
using ArrayType = vtkm::cont::ArrayHandle<ValueType>;
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const vtkm::cont::DeviceAdapterId device = Config.Device;
|
|
|
|
const vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(state.range(0));
|
|
|
|
const vtkm::Id numValues = static_cast<vtkm::Id>(numBytes / sizeof(ValueType));
|
2017-07-06 20:08:40 +00:00
|
|
|
|
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
std::ostringstream desc;
|
|
|
|
desc << "Copying from Control --> Execution (write-only): " << numValues << " values ("
|
|
|
|
<< vtkm::cont::GetHumanReadableSize(numBytes) << ")";
|
|
|
|
state.SetLabel(desc.str());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
ArrayType array;
|
|
|
|
array.Allocate(numValues);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::Invoker invoker{ device };
|
|
|
|
vtkm::cont::Timer timer{ device };
|
|
|
|
for (auto _ : state)
|
|
|
|
{
|
|
|
|
(void)_;
|
|
|
|
timer.Start();
|
|
|
|
invoker(WriteValues{}, array);
|
|
|
|
timer.Stop();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetIterationTime(timer.GetElapsedTime());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const int64_t iterations = static_cast<int64_t>(state.iterations());
|
|
|
|
state.SetBytesProcessed(static_cast<int64_t>(numBytes) * iterations);
|
|
|
|
state.SetItemsProcessed(static_cast<int64_t>(numValues) * iterations);
|
|
|
|
}
|
|
|
|
VTKM_BENCHMARK_TEMPLATES_OPTS(BenchContToExecWrite,
|
|
|
|
->Range(COPY_SIZE_MIN, COPY_SIZE_MAX)
|
|
|
|
->ArgName("Bytes"),
|
|
|
|
TestTypes);
|
|
|
|
|
|
|
|
// Copies NumValues from control environment to execution environment and
|
|
|
|
// both reads and writes them.
|
|
|
|
template <typename ValueType>
|
|
|
|
void BenchContToExecReadWrite(benchmark::State& state)
|
|
|
|
{
|
|
|
|
using ArrayType = vtkm::cont::ArrayHandle<ValueType>;
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const vtkm::cont::DeviceAdapterId device = Config.Device;
|
|
|
|
const vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(state.range(0));
|
|
|
|
const vtkm::Id numValues = static_cast<vtkm::Id>(numBytes / sizeof(ValueType));
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
{
|
|
|
|
std::ostringstream desc;
|
|
|
|
desc << "Control --> Execution (read-write): " << numValues << " values ("
|
|
|
|
<< vtkm::cont::GetHumanReadableSize(numBytes) << ")";
|
|
|
|
state.SetLabel(desc.str());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2020-07-16 16:32:32 +00:00
|
|
|
std::vector<ValueType> vec(static_cast<std::size_t>(numValues), 2);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::Invoker invoker{ device };
|
|
|
|
vtkm::cont::Timer timer{ device };
|
|
|
|
for (auto _ : state)
|
|
|
|
{
|
|
|
|
(void)_;
|
2020-07-24 01:34:45 +00:00
|
|
|
|
|
|
|
// Make a fresh array each iteration to force a copy from control to execution each time.
|
|
|
|
// (Prevents unified memory devices from caching data.)
|
|
|
|
ArrayType array = CreateFreshArrayHandle(vec);
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Start();
|
|
|
|
invoker(ReadWriteValues{}, array);
|
|
|
|
timer.Stop();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetIterationTime(timer.GetElapsedTime());
|
2020-07-24 01:34:45 +00:00
|
|
|
|
|
|
|
// Remove data from execution environment so it has to be transferred again.
|
|
|
|
array.ReleaseResourcesExecution();
|
2019-12-26 19:48:51 +00:00
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const int64_t iterations = static_cast<int64_t>(state.iterations());
|
|
|
|
state.SetBytesProcessed(static_cast<int64_t>(numBytes) * iterations);
|
|
|
|
state.SetItemsProcessed(static_cast<int64_t>(numValues) * iterations);
|
|
|
|
}
|
|
|
|
VTKM_BENCHMARK_TEMPLATES_OPTS(BenchContToExecReadWrite,
|
|
|
|
->Range(COPY_SIZE_MIN, COPY_SIZE_MAX)
|
|
|
|
->ArgName("Bytes"),
|
|
|
|
TestTypes);
|
|
|
|
|
|
|
|
// Copies NumValues from control environment to execution environment and
|
|
|
|
// back, then accesses them as read-only.
|
|
|
|
template <typename ValueType>
|
|
|
|
void BenchRoundTripRead(benchmark::State& state)
|
|
|
|
{
|
|
|
|
using ArrayType = vtkm::cont::ArrayHandle<ValueType>;
|
2019-01-09 16:11:49 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const vtkm::cont::DeviceAdapterId device = Config.Device;
|
|
|
|
const vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(state.range(0));
|
|
|
|
const vtkm::Id numValues = static_cast<vtkm::Id>(numBytes / sizeof(ValueType));
|
2017-07-06 20:08:40 +00:00
|
|
|
|
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
std::ostringstream desc;
|
|
|
|
desc << "Copying from Control --> Execution --> Control (read-only): " << numValues
|
|
|
|
<< " values (" << vtkm::cont::GetHumanReadableSize(numBytes) << ")";
|
|
|
|
state.SetLabel(desc.str());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2020-07-16 16:32:32 +00:00
|
|
|
std::vector<ValueType> vec(static_cast<std::size_t>(numValues), 2);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::Invoker invoker{ device };
|
|
|
|
vtkm::cont::Timer timer{ device };
|
|
|
|
for (auto _ : state)
|
|
|
|
{
|
|
|
|
(void)_;
|
2020-07-24 01:34:45 +00:00
|
|
|
|
|
|
|
// Make a fresh array each iteration to force a copy from control to execution each time.
|
|
|
|
// (Prevents unified memory devices from caching data.)
|
|
|
|
ArrayType array = CreateFreshArrayHandle(vec);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Start();
|
|
|
|
invoker(ReadValues{}, array);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Copy back to host and read:
|
2020-07-24 01:34:45 +00:00
|
|
|
// (Note, this probably does not copy. The array exists in both control and execution for read.)
|
2020-01-28 19:14:32 +00:00
|
|
|
auto portal = array.ReadPortal();
|
2019-12-26 19:48:51 +00:00
|
|
|
for (vtkm::Id i = 0; i < numValues; ++i)
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
benchmark::DoNotOptimize(portal.Get(i));
|
2017-07-06 20:08:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Stop();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetIterationTime(timer.GetElapsedTime());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const int64_t iterations = static_cast<int64_t>(state.iterations());
|
|
|
|
state.SetBytesProcessed(static_cast<int64_t>(numBytes) * iterations);
|
|
|
|
state.SetItemsProcessed(static_cast<int64_t>(numValues) * iterations);
|
|
|
|
}
|
|
|
|
VTKM_BENCHMARK_TEMPLATES_OPTS(BenchRoundTripRead,
|
|
|
|
->Range(COPY_SIZE_MIN, COPY_SIZE_MAX)
|
|
|
|
->ArgName("Bytes"),
|
|
|
|
TestTypes);
|
|
|
|
|
|
|
|
// Copies NumValues from control environment to execution environment and
|
|
|
|
// back, then reads and writes them in-place.
|
|
|
|
template <typename ValueType>
|
|
|
|
void BenchRoundTripReadWrite(benchmark::State& state)
|
|
|
|
{
|
|
|
|
using ArrayType = vtkm::cont::ArrayHandle<ValueType>;
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const vtkm::cont::DeviceAdapterId device = Config.Device;
|
|
|
|
const vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(state.range(0));
|
|
|
|
const vtkm::Id numValues = static_cast<vtkm::Id>(numBytes / sizeof(ValueType));
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
{
|
|
|
|
std::ostringstream desc;
|
|
|
|
desc << "Copying from Control --> Execution --> Control (read-write): " << numValues
|
|
|
|
<< " values (" << vtkm::cont::GetHumanReadableSize(numBytes) << ")";
|
|
|
|
state.SetLabel(desc.str());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
std::vector<ValueType> vec(static_cast<std::size_t>(numValues));
|
|
|
|
|
|
|
|
vtkm::cont::Invoker invoker{ device };
|
|
|
|
vtkm::cont::Timer timer{ device };
|
|
|
|
for (auto _ : state)
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
(void)_;
|
2020-07-24 01:34:45 +00:00
|
|
|
|
|
|
|
// Make a fresh array each iteration to force a copy from control to execution each time.
|
|
|
|
// (Prevents unified memory devices from caching data.)
|
|
|
|
ArrayType array = CreateFreshArrayHandle(vec);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Start();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Do work on device:
|
|
|
|
invoker(ReadWriteValues{}, array);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2020-07-24 01:34:45 +00:00
|
|
|
// Copy back to host and read/write:
|
2020-01-28 19:14:32 +00:00
|
|
|
auto portal = array.WritePortal();
|
2019-12-26 19:48:51 +00:00
|
|
|
for (vtkm::Id i = 0; i < numValues; ++i)
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
portal.Set(i, portal.Get(i) - static_cast<ValueType>(i));
|
2017-07-06 20:08:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Stop();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetIterationTime(timer.GetElapsedTime());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const int64_t iterations = static_cast<int64_t>(state.iterations());
|
|
|
|
state.SetBytesProcessed(static_cast<int64_t>(numBytes) * iterations);
|
|
|
|
state.SetItemsProcessed(static_cast<int64_t>(numValues) * iterations);
|
|
|
|
}
|
|
|
|
VTKM_BENCHMARK_TEMPLATES_OPTS(BenchRoundTripReadWrite,
|
|
|
|
->Range(COPY_SIZE_MIN, COPY_SIZE_MAX)
|
|
|
|
->ArgName("Bytes"),
|
|
|
|
TestTypes);
|
|
|
|
|
|
|
|
// Write NumValues to device allocated memory and copies them back to control
|
|
|
|
// for reading.
|
|
|
|
template <typename ValueType>
|
|
|
|
void BenchExecToContRead(benchmark::State& state)
|
|
|
|
{
|
|
|
|
using ArrayType = vtkm::cont::ArrayHandle<ValueType>;
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const vtkm::cont::DeviceAdapterId device = Config.Device;
|
|
|
|
const vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(state.range(0));
|
|
|
|
const vtkm::Id numValues = static_cast<vtkm::Id>(numBytes / sizeof(ValueType));
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
{
|
|
|
|
std::ostringstream desc;
|
|
|
|
desc << "Copying from Execution --> Control (read-only on control): " << numValues
|
|
|
|
<< " values (" << vtkm::cont::GetHumanReadableSize(numBytes) << ")";
|
|
|
|
state.SetLabel(desc.str());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::Invoker invoker{ device };
|
|
|
|
vtkm::cont::Timer timer{ device };
|
|
|
|
for (auto _ : state)
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
(void)_;
|
2020-07-24 01:34:45 +00:00
|
|
|
ArrayType array;
|
|
|
|
array.Allocate(numValues);
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Time the copy:
|
|
|
|
timer.Start();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Allocate/write data on device
|
|
|
|
invoker(WriteValues{}, array);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Read back on host:
|
2020-01-28 19:14:32 +00:00
|
|
|
auto portal = array.WritePortal();
|
2019-12-26 19:48:51 +00:00
|
|
|
for (vtkm::Id i = 0; i < numValues; ++i)
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
benchmark::DoNotOptimize(portal.Get(i));
|
2017-07-06 20:08:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Stop();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetIterationTime(timer.GetElapsedTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
const int64_t iterations = static_cast<int64_t>(state.iterations());
|
|
|
|
state.SetBytesProcessed(static_cast<int64_t>(numBytes) * iterations);
|
|
|
|
state.SetItemsProcessed(static_cast<int64_t>(numValues) * iterations);
|
|
|
|
};
|
|
|
|
VTKM_BENCHMARK_TEMPLATES_OPTS(BenchExecToContRead,
|
|
|
|
->Range(COPY_SIZE_MIN, COPY_SIZE_MAX)
|
|
|
|
->ArgName("Bytes"),
|
|
|
|
TestTypes);
|
|
|
|
|
|
|
|
// Write NumValues to device allocated memory and copies them back to control
|
|
|
|
// and overwrites them.
|
|
|
|
template <typename ValueType>
|
|
|
|
void BenchExecToContWrite(benchmark::State& state)
|
|
|
|
{
|
|
|
|
using ArrayType = vtkm::cont::ArrayHandle<ValueType>;
|
|
|
|
|
|
|
|
const vtkm::cont::DeviceAdapterId device = Config.Device;
|
|
|
|
const vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(state.range(0));
|
|
|
|
const vtkm::Id numValues = static_cast<vtkm::Id>(numBytes / sizeof(ValueType));
|
2017-07-06 20:08:40 +00:00
|
|
|
|
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
std::ostringstream desc;
|
|
|
|
desc << "Copying from Execution --> Control (write-only on control): " << numValues
|
|
|
|
<< " values (" << vtkm::cont::GetHumanReadableSize(numBytes) << ")";
|
|
|
|
state.SetLabel(desc.str());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::Invoker invoker{ device };
|
|
|
|
vtkm::cont::Timer timer{ device };
|
|
|
|
for (auto _ : state)
|
|
|
|
{
|
|
|
|
(void)_;
|
2020-07-24 01:34:45 +00:00
|
|
|
ArrayType array;
|
|
|
|
array.Allocate(numValues);
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Start();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Allocate/write data on device
|
|
|
|
invoker(WriteValues{}, array);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Read back on host:
|
2020-01-28 19:14:32 +00:00
|
|
|
auto portal = array.WritePortal();
|
2019-12-26 19:48:51 +00:00
|
|
|
for (vtkm::Id i = 0; i < numValues; ++i)
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
portal.Set(i, portal.Get(i) - static_cast<ValueType>(i));
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Stop();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetIterationTime(timer.GetElapsedTime());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const int64_t iterations = static_cast<int64_t>(state.iterations());
|
|
|
|
state.SetBytesProcessed(static_cast<int64_t>(numBytes) * iterations);
|
|
|
|
state.SetItemsProcessed(static_cast<int64_t>(numValues) * iterations);
|
|
|
|
}
|
|
|
|
VTKM_BENCHMARK_TEMPLATES_OPTS(BenchExecToContWrite,
|
|
|
|
->Range(COPY_SIZE_MIN, COPY_SIZE_MAX)
|
|
|
|
->ArgName("Bytes"),
|
|
|
|
TestTypes);
|
|
|
|
|
|
|
|
// Write NumValues to device allocated memory and copies them back to control
|
|
|
|
// for reading and writing.
|
|
|
|
template <typename ValueType>
|
|
|
|
void BenchExecToContReadWrite(benchmark::State& state)
|
|
|
|
{
|
|
|
|
using ArrayType = vtkm::cont::ArrayHandle<ValueType>;
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
const vtkm::cont::DeviceAdapterId device = Config.Device;
|
|
|
|
const vtkm::UInt64 numBytes = static_cast<vtkm::UInt64>(state.range(0));
|
|
|
|
const vtkm::Id numValues = static_cast<vtkm::Id>(numBytes / sizeof(ValueType));
|
2017-07-06 20:08:40 +00:00
|
|
|
|
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
std::ostringstream desc;
|
|
|
|
desc << "Copying from Execution --> Control (read-write on control): " << numValues
|
|
|
|
<< " values (" << vtkm::cont::GetHumanReadableSize(numBytes) << ")";
|
|
|
|
state.SetLabel(desc.str());
|
|
|
|
}
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::Invoker invoker{ device };
|
|
|
|
vtkm::cont::Timer timer{ device };
|
|
|
|
for (auto _ : state)
|
|
|
|
{
|
|
|
|
(void)_;
|
2020-07-24 01:34:45 +00:00
|
|
|
ArrayType array;
|
|
|
|
array.Allocate(numValues);
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Start();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Allocate/write data on device
|
|
|
|
invoker(WriteValues{}, array);
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Read back on host:
|
2020-01-28 19:14:32 +00:00
|
|
|
auto portal = array.WritePortal();
|
2019-12-26 19:48:51 +00:00
|
|
|
for (vtkm::Id i = 0; i < numValues; ++i)
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
benchmark::DoNotOptimize(portal.Get(i));
|
2017-07-06 20:08:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
timer.Stop();
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetIterationTime(timer.GetElapsedTime());
|
2017-07-06 20:08:40 +00:00
|
|
|
}
|
2019-12-26 19:48:51 +00:00
|
|
|
|
|
|
|
const int64_t iterations = static_cast<int64_t>(state.iterations());
|
|
|
|
state.SetBytesProcessed(static_cast<int64_t>(numBytes) * iterations);
|
|
|
|
state.SetItemsProcessed(static_cast<int64_t>(numValues) * iterations);
|
2017-07-06 20:08:40 +00:00
|
|
|
}
|
2019-12-26 19:48:51 +00:00
|
|
|
VTKM_BENCHMARK_TEMPLATES_OPTS(BenchExecToContReadWrite,
|
|
|
|
->Range(COPY_SIZE_MIN, COPY_SIZE_MAX)
|
|
|
|
->ArgName("Bytes"),
|
|
|
|
TestTypes);
|
|
|
|
|
|
|
|
} // end anon namespace
|
2017-07-06 20:08:40 +00:00
|
|
|
|
2018-12-20 15:10:09 +00:00
|
|
|
int main(int argc, char* argv[])
|
2017-07-06 20:08:40 +00:00
|
|
|
{
|
2020-03-19 19:15:32 +00:00
|
|
|
auto opts = vtkm::cont::InitializeOptions::RequireDevice;
|
|
|
|
|
|
|
|
// Initialize command line args
|
|
|
|
std::vector<char*> args(argv, argv + argc);
|
|
|
|
vtkm::bench::detail::InitializeArgs(&argc, args, opts);
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// Parse VTK-m options:
|
2020-03-19 19:15:32 +00:00
|
|
|
Config = vtkm::cont::Initialize(argc, args.data(), opts);
|
2018-12-20 15:11:27 +00:00
|
|
|
|
2020-03-19 19:15:32 +00:00
|
|
|
// This occurs when it is help
|
|
|
|
if (opts == vtkm::cont::InitializeOptions::None)
|
|
|
|
{
|
|
|
|
std::cout << Config.Usage << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(Config.Device);
|
|
|
|
}
|
2018-12-20 15:11:27 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
// handle benchmarking related args and run benchmarks:
|
2020-03-19 19:15:32 +00:00
|
|
|
VTKM_EXECUTE_BENCHMARKS(argc, args.data());
|
2017-07-06 20:08:40 +00:00
|
|
|
}
|