Files
nvbench/testing/axes_metadata.cu
Allison Piper e8c8877d36 Squashed commit of the following:
commit 4b309e6ad8
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Sat Apr 6 13:19:14 2024 +0000

    Minor cleanups

commit 476ed2ceae
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Sat Apr 6 12:53:37 2024 +0000

    WAR compiler ice in nlohmann json.

    Only seeing this on GCC 9 + CTK 11.1. Seems to be
    having trouble with the `[[no_unique_address]]` optimization.

commit a9bf1d3e42
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Sat Apr 6 00:24:47 2024 +0000

    Bump nlohmann json.

commit 80980fe373
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Sat Apr 6 00:22:07 2024 +0000

    Fix llvm filesystem support

commit f6099e6311
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 23:18:44 2024 +0000

    Drop MSVC 2017 testing.

commit 5ae50a8ef5
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 23:02:32 2024 +0000

    Add mroe missing headers.

commit b2a9ae04d9
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 22:37:56 2024 +0000

    Remove old CUDA+MSVC builds and make windows build-only.

commit 5b18c26a28
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 22:37:07 2024 +0000

    Fix header for std::min/max.

    Why do I always think it's utility instead of algorithm....

commit 6a409efa2d
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 22:18:18 2024 +0000

    Temporarily disable CUPTI on all windows builds.

commit f432f88866
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 21:42:52 2024 +0000

    Fix warnings on MSVC.

commit 829787649b
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 21:03:16 2024 +0000

    More flailing about in powershell.

commit 21742e6bea
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 20:36:08 2024 +0000

    Cleanup filesystem header handling.

commit de3d202635
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 20:09:00 2024 +0000

    Windows CI debugging.

commit a4151667ff
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 19:45:40 2024 +0000

    Quotation mark madness

commit dd04f3befe
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 19:27:27 2024 +0000

    Temporarily disable NVML on windows CI until new containers are ready.

commit f3952848c4
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 19:25:22 2024 +0000

    WAR issues on gcc-7.

commit 198986875e
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 19:25:04 2024 +0000

    More matrix/devcontainer updates.

commit b9712f8696
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 18:30:35 2024 +0000

    Fix windows build scripts.

commit 943f268280
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 18:18:33 2024 +0000

    Fix warnings with clang host compiler.

commit 7063e1d60a
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 18:14:28 2024 +0000

    More devcontainer hijinks.

commit 06532fde81
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 17:51:25 2024 +0000

    More matrix updates.

commit 78a265ea55
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 17:34:00 2024 +0000

    Support CLI CMake options for windows ci scripts.

commit 670895c867
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 17:31:59 2024 +0000

    Add missing devcontainers.

commit b121823e74
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 17:22:54 2024 +0000

    Build for `all-major` architectures in presets.

    We can get away with this because we require CMake 3.23.1.
    This was added in 3.23.

commit fccfd44685
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 17:22:08 2024 +0000

    Update matrix file.

commit e7d43ba90e
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 16:23:48 2024 +0000

    Consolidate build/test jobs.

commit c4044056ec
Author: Allison Piper <alliepiper16@gmail.com>
Date:   Fri Apr 5 16:04:11 2024 +0000

    Add missing build script.
2024-04-06 13:56:10 +00:00

242 lines
7.5 KiB
Plaintext

/*
* Copyright 2021 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 with the LLVM exception
* (the "License"); you may not use this file except in compliance with
* the License.
*
* You may obtain a copy of the License at
*
* http://llvm.org/foundation/relicensing/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <nvbench/axes_metadata.cuh>
#include <nvbench/type_list.cuh>
#include <nvbench/type_strings.cuh>
#include <nvbench/types.cuh>
#include "test_asserts.cuh"
#include <fmt/format.h>
#include <algorithm>
#include <string_view>
using int_list = nvbench::type_list<nvbench::int8_t,
nvbench::int16_t,
nvbench::int32_t,
nvbench::int64_t>;
using float_list = nvbench::type_list<nvbench::float32_t, nvbench::float64_t>;
using misc_list = nvbench::type_list<bool, void>;
using three_type_axes = nvbench::type_list<int_list, float_list, misc_list>;
using no_types = nvbench::type_list<>;
void test_default_type_axes_names()
{
using TL = nvbench::type_list<int>;
{
nvbench::axes_metadata axes{};
ASSERT(axes.get_axes().size() == 0);
}
{
nvbench::axes_metadata axes{nvbench::type_list<>{}};
ASSERT(axes.get_axes().size() == 0);
}
{
nvbench::axes_metadata axes{nvbench::type_list<TL>{}};
ASSERT(axes.get_axes().size() == 1);
ASSERT(axes.get_type_axis(0).get_name() == "T");
ASSERT(axes.get_type_axis(0).get_axis_index() == 0);
}
{
nvbench::axes_metadata axes{nvbench::type_list<TL, TL>{}};
ASSERT(axes.get_axes().size() == 2);
ASSERT(axes.get_type_axis(0).get_name() == "T");
ASSERT(axes.get_type_axis(0).get_axis_index() == 0);
ASSERT(axes.get_type_axis(1).get_name() == "U");
ASSERT(axes.get_type_axis(1).get_axis_index() == 1);
}
{
nvbench::axes_metadata axes{nvbench::type_list<TL, TL, TL>{}};
ASSERT(axes.get_axes().size() == 3);
ASSERT(axes.get_type_axis(0).get_name() == "T");
ASSERT(axes.get_type_axis(0).get_axis_index() == 0);
ASSERT(axes.get_type_axis(1).get_name() == "U");
ASSERT(axes.get_type_axis(1).get_axis_index() == 1);
ASSERT(axes.get_type_axis(2).get_name() == "V");
ASSERT(axes.get_type_axis(2).get_axis_index() == 2);
}
{
nvbench::axes_metadata axes{nvbench::type_list<TL, TL, TL, TL>{}};
ASSERT(axes.get_axes().size() == 4);
ASSERT(axes.get_type_axis(0).get_name() == "T");
ASSERT(axes.get_type_axis(0).get_axis_index() == 0);
ASSERT(axes.get_type_axis(1).get_name() == "U");
ASSERT(axes.get_type_axis(1).get_axis_index() == 1);
ASSERT(axes.get_type_axis(2).get_name() == "V");
ASSERT(axes.get_type_axis(2).get_axis_index() == 2);
ASSERT(axes.get_type_axis(3).get_name() == "W");
ASSERT(axes.get_type_axis(3).get_axis_index() == 3);
}
{
nvbench::axes_metadata axes{nvbench::type_list<TL, TL, TL, TL, TL>{}};
ASSERT(axes.get_axes().size() == 5);
ASSERT(axes.get_type_axis(0).get_name() == "T0");
ASSERT(axes.get_type_axis(0).get_axis_index() == 0);
ASSERT(axes.get_type_axis(1).get_name() == "T1");
ASSERT(axes.get_type_axis(1).get_axis_index() == 1);
ASSERT(axes.get_type_axis(2).get_name() == "T2");
ASSERT(axes.get_type_axis(2).get_axis_index() == 2);
ASSERT(axes.get_type_axis(3).get_name() == "T3");
ASSERT(axes.get_type_axis(3).get_axis_index() == 3);
ASSERT(axes.get_type_axis(4).get_name() == "T4");
ASSERT(axes.get_type_axis(4).get_axis_index() == 4);
}
}
void test_type_axes()
{
nvbench::axes_metadata axes{three_type_axes{}};
axes.set_type_axes_names({"Integer", "Float", "Other"});
ASSERT(axes.get_type_axis("Integer").get_name() == "Integer");
ASSERT(axes.get_type_axis("Float").get_name() == "Float");
ASSERT(axes.get_type_axis("Other").get_name() == "Other");
ASSERT(axes.get_type_axis(0).get_name() == "Integer");
ASSERT(axes.get_type_axis(1).get_name() == "Float");
ASSERT(axes.get_type_axis(2).get_name() == "Other");
fmt::memory_buffer buffer;
for (const auto &axis : axes.get_axes())
{
fmt::format_to(std::back_inserter(buffer), "Axis: {}\n", axis->get_name());
const auto num_values = axis->get_size();
for (std::size_t i = 0; i < num_values; ++i)
{
auto input_string = axis->get_input_string(i);
auto description = axis->get_description(i);
fmt::format_to(std::back_inserter(buffer),
" - {}{}\n",
input_string,
description.empty() ? ""
: fmt::format(" ({})", description));
}
}
const std::string ref = R"expected(Axis: Integer
- I8 (int8_t)
- I16 (int16_t)
- I32 (int32_t)
- I64 (int64_t)
Axis: Float
- F32 (float)
- F64 (double)
Axis: Other
- bool
- void
)expected";
const std::string test = fmt::to_string(buffer);
const auto diff =
std::mismatch(ref.cbegin(), ref.cend(), test.cbegin(), test.cend());
const auto idx = static_cast<std::size_t>(diff.second - test.cbegin());
ASSERT_MSG(test == ref,
"Differs at character {}.\n"
"Expected:\n\"{}\"\n\n"
"Actual:\n\"{}\"\n"
"-- ERROR --\n"
"\"{}\"",
idx,
ref,
std::string_view(test.c_str(), idx),
std::string_view(test.c_str() + idx, test.size() - idx));
}
void test_float64_axes()
{
nvbench::axes_metadata axes;
axes.add_float64_axis("F64 Axis", {0., .1, .25, .5, 1.});
ASSERT(axes.get_axes().size() == 1);
const auto &axis = axes.get_float64_axis("F64 Axis");
ASSERT(axis.get_size() == 5);
ASSERT(axis.get_value(0) == 0.);
ASSERT(axis.get_value(1) == .1);
ASSERT(axis.get_value(2) == .25);
ASSERT(axis.get_value(3) == .5);
ASSERT(axis.get_value(4) == 1.);
}
void test_int64_axes()
{
nvbench::axes_metadata axes;
axes.add_int64_axis("I64 Axis",
{10, 11, 12, 13, 14},
nvbench::int64_axis_flags::none);
ASSERT(axes.get_axes().size() == 1);
const auto &axis = axes.get_int64_axis("I64 Axis");
ASSERT(axis.get_size() == 5);
ASSERT(axis.get_value(0) == 10);
ASSERT(axis.get_value(1) == 11);
ASSERT(axis.get_value(2) == 12);
ASSERT(axis.get_value(3) == 13);
ASSERT(axis.get_value(4) == 14);
}
void test_int64_power_of_two_axes()
{
nvbench::axes_metadata axes;
axes.add_int64_axis("I64 POT Axis",
{1, 2, 3, 4, 5},
nvbench::int64_axis_flags::power_of_two);
ASSERT(axes.get_axes().size() == 1);
const auto &axis = axes.get_int64_axis("I64 POT Axis");
ASSERT(axis.get_size() == 5);
ASSERT(axis.get_value(0) == 2);
ASSERT(axis.get_value(1) == 4);
ASSERT(axis.get_value(2) == 8);
ASSERT(axis.get_value(3) == 16);
ASSERT(axis.get_value(4) == 32);
}
void test_string_axes()
{
nvbench::axes_metadata axes;
axes.add_string_axis("Strings", {"string a", "string b", "string c"});
ASSERT(axes.get_axes().size() == 1);
const auto &axis = axes.get_string_axis("Strings");
ASSERT(axis.get_size() == 3);
ASSERT(axis.get_value(0) == "string a");
ASSERT(axis.get_value(1) == "string b");
ASSERT(axis.get_value(2) == "string c");
}
int main()
{
test_default_type_axes_names();
test_type_axes();
test_float64_axes();
test_int64_axes();
test_int64_power_of_two_axes();
test_string_axes();
}