2017-10-16 19:35:23 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-10-16 19:35:23 +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.
|
2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2017-10-16 19:35:23 +00:00
|
|
|
|
2017-12-29 22:21:29 +00:00
|
|
|
#include "Benchmarker.h"
|
2017-10-16 19:35:23 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
#include <vtkm/cont/Algorithm.h>
|
2017-10-16 19:35:23 +00:00
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
2019-12-26 19:48:51 +00:00
|
|
|
#include <vtkm/cont/RuntimeDeviceTracker.h>
|
2017-10-16 19:35:23 +00:00
|
|
|
#include <vtkm/cont/Timer.h>
|
|
|
|
|
|
|
|
#include <vtkm/internal/Configure.h>
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
#include <vtkm/List.h>
|
|
|
|
|
2017-10-16 19:35:23 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
namespace
|
2017-10-16 19:35:23 +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-10-16 19:35:23 +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
|
|
|
|
|
|
|
|
using TypeList = vtkm::List<vtkm::UInt8,
|
|
|
|
vtkm::Vec2ui_8,
|
|
|
|
vtkm::Vec3ui_8,
|
|
|
|
vtkm::Vec4ui_8,
|
|
|
|
vtkm::UInt32,
|
|
|
|
vtkm::Vec2ui_32,
|
|
|
|
vtkm::UInt64,
|
|
|
|
vtkm::Vec2ui_64,
|
|
|
|
vtkm::Float32,
|
|
|
|
vtkm::Vec2f_32,
|
|
|
|
vtkm::Float64,
|
|
|
|
vtkm::Vec2f_64,
|
|
|
|
vtkm::Pair<vtkm::UInt32, vtkm::Float32>,
|
|
|
|
vtkm::Pair<vtkm::UInt32, vtkm::Float64>,
|
|
|
|
vtkm::Pair<vtkm::UInt64, vtkm::Float32>,
|
|
|
|
vtkm::Pair<vtkm::UInt64, vtkm::Float64>>;
|
|
|
|
|
|
|
|
template <typename ValueType>
|
|
|
|
void CopySpeed(benchmark::State& state)
|
2017-10-16 19:35:23 +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-10-16 19:35:23 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetLabel(vtkm::cont::GetHumanReadableSize(numBytes));
|
2017-10-16 19:35:23 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::ArrayHandle<ValueType> src;
|
|
|
|
vtkm::cont::ArrayHandle<ValueType> dst;
|
|
|
|
src.Allocate(numValues);
|
|
|
|
dst.Allocate(numValues);
|
2017-10-16 19:35:23 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::Timer timer(device);
|
|
|
|
for (auto _ : state)
|
2017-10-16 19:35:23 +00:00
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
(void)_;
|
2019-01-09 16:11:49 +00:00
|
|
|
timer.Start();
|
2019-12-26 19:48:51 +00:00
|
|
|
vtkm::cont::Algorithm::Copy(device, src, dst);
|
|
|
|
timer.Stop();
|
2017-10-16 19:35:23 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
state.SetIterationTime(timer.GetElapsedTime());
|
2017-10-16 19:35:23 +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-10-16 19:35:23 +00:00
|
|
|
}
|
2019-12-26 19:48:51 +00:00
|
|
|
VTKM_BENCHMARK_TEMPLATES_OPTS(CopySpeed,
|
|
|
|
->Range(COPY_SIZE_MIN, COPY_SIZE_MAX)
|
|
|
|
->ArgName("Bytes"),
|
|
|
|
TypeList);
|
2017-10-16 19:35:23 +00:00
|
|
|
|
2019-12-26 19:48:51 +00:00
|
|
|
} // end anon namespace
|
2019-02-15 19:47:07 +00:00
|
|
|
|
2017-10-16 19:35:23 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2019-12-26 19:48:51 +00:00
|
|
|
// Parse VTK-m options:
|
2020-03-19 19:15:32 +00:00
|
|
|
auto opts = vtkm::cont::InitializeOptions::RequireDevice;
|
2018-12-20 15:10:09 +00:00
|
|
|
|
2020-03-19 19:15:32 +00:00
|
|
|
std::vector<char*> args(argv, argv + argc);
|
|
|
|
vtkm::bench::detail::InitializeArgs(&argc, args, opts);
|
|
|
|
|
|
|
|
// Parse VTK-m options:
|
|
|
|
Config = vtkm::cont::Initialize(argc, args.data(), opts);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2017-10-16 19:35:23 +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-10-16 19:35:23 +00:00
|
|
|
}
|