diff --git a/nvbench/CMakeLists.txt b/nvbench/CMakeLists.txt index 45438b9..d29b145 100644 --- a/nvbench/CMakeLists.txt +++ b/nvbench/CMakeLists.txt @@ -11,6 +11,7 @@ set(srcs device_manager.cu float64_axis.cxx int64_axis.cxx + linear_axis_space.cxx markdown_printer.cu named_values.cxx option_parser.cu @@ -21,6 +22,8 @@ set(srcs string_axis.cxx type_axis.cxx type_strings.cxx + user_axis_space.cxx + zip_axis_space.cxx detail/measure_cold.cu detail/measure_hot.cu diff --git a/nvbench/axes_metadata.cuh b/nvbench/axes_metadata.cuh index 9454b52..4f04bb0 100644 --- a/nvbench/axes_metadata.cuh +++ b/nvbench/axes_metadata.cuh @@ -21,9 +21,12 @@ #include #include #include +#include #include #include #include +#include +#include #include #include diff --git a/nvbench/axis_iteration_space.cuh b/nvbench/axis_iteration_space.cuh index 913e5df..a32b054 100644 --- a/nvbench/axis_iteration_space.cuh +++ b/nvbench/axis_iteration_space.cuh @@ -23,6 +23,21 @@ namespace nvbench { +/*! + * Base class for all axi and axes iteration spaces. + * + * If we consider an axi to be a container of values, iteration_spaces + * would be the different types of iterators supported by that container. + * + * With that in mind we get the following mapping: + * * linear_axis_space is equivalant to a forward iterator. + * + * * zip_axis_space is equivalant to a zip iterator. + * + * * user_axis_space is equivalant to a transform iterator. + * + * + */ struct iteration_space_base { using axes_type = std::vector>; @@ -32,62 +47,53 @@ struct iteration_space_base nvbench::detail::axis_space_iterator::AdvanceSignature; using UpdateSignature = nvbench::detail::axis_space_iterator::UpdateSignature; + /*! + * Construct a new iteration_space_base + * + * @param[input_indices] + * @param[output_indices] + */ iteration_space_base(std::vector input_indices, - std::vector output_indices); + std::vector output_indices); virtual ~iteration_space_base(); [[nodiscard]] std::unique_ptr clone() const; [[nodiscard]] std::vector> clone_as_linear() const; - [[nodiscard]] detail::axis_space_iterator get_iterator(const axes_type &axes) const; + /*! + * Construct a new iteration_space_base + * + */ + [[nodiscard]] detail::axis_space_iterator + get_iterator(const axes_type &axes) const; + + /*! + * Construct a new iteration_space_base + * + */ [[nodiscard]] std::size_t get_size(const axes_type &axes) const; + + /*! + * Construct a new iteration_space_base + * + */ [[nodiscard]] std::size_t get_active_count(const axes_type &axes) const; + /*! + * Construct a new iteration_space_base + * + */ [[nodiscard]] bool contains(std::size_t input_index) const; protected: std::vector m_input_indices; std::vector m_output_indices; - virtual std::unique_ptr do_clone() const = 0; + virtual std::unique_ptr do_clone() const = 0; virtual detail::axis_space_iterator do_get_iterator(axes_info info) const = 0; - virtual std::size_t do_get_size(const axes_info &info) const = 0; - virtual std::size_t do_get_active_count(const axes_info &info) const = 0; -}; - -struct linear_axis_space final : iteration_space_base -{ - linear_axis_space(std::size_t in, std::size_t out); - ~linear_axis_space(); - - std::unique_ptr do_clone() const override; - detail::axis_space_iterator do_get_iterator(axes_info info) const override; - std::size_t do_get_size(const axes_info &info) const override; - std::size_t do_get_active_count(const axes_info &info) const override; -}; - -struct zip_axis_space final : iteration_space_base -{ - zip_axis_space(std::vector input_indices, - std::vector output_indices); - ~zip_axis_space(); - - std::unique_ptr do_clone() const override; - detail::axis_space_iterator do_get_iterator(axes_info info) const override; - std::size_t do_get_size(const axes_info &info) const override; - std::size_t do_get_active_count(const axes_info &info) const override; + virtual std::size_t do_get_size(const axes_info &info) const = 0; + virtual std::size_t do_get_active_count(const axes_info &info) const = 0; }; -struct user_axis_space : iteration_space_base -{ - user_axis_space(std::vector input_indices, - std::vector output_indices); - ~user_axis_space(); -}; - -using make_user_space_signature = - std::unique_ptr(std::vector input_indices, - std::vector output_indices); - } // namespace nvbench diff --git a/nvbench/axis_iteration_space.cxx b/nvbench/axis_iteration_space.cxx index c8a158a..12010ca 100644 --- a/nvbench/axis_iteration_space.cxx +++ b/nvbench/axis_iteration_space.cxx @@ -19,6 +19,7 @@ #include "axis_iteration_space.cuh" #include +#include namespace nvbench { @@ -93,82 +94,4 @@ bool iteration_space_base::contains(std::size_t in_index) const return iter != m_input_indices.end(); } -linear_axis_space::linear_axis_space(std::size_t in_index, - std::size_t out_index) - : iteration_space_base({in_index}, {out_index}) -{} - -linear_axis_space::~linear_axis_space() = default; - -detail::axis_space_iterator linear_axis_space::do_get_iterator(axes_info info) const -{ - std::size_t loc(m_output_indices[0]); - auto update_func = [=](std::size_t inc_index, - std::vector &indices) { - indices[loc] = info[0]; - indices[loc].index = inc_index; - }; - - return detail::make_space_iterator(1, info[0].size, update_func); -} - -std::size_t linear_axis_space::do_get_size(const axes_info &info) const -{ - return info[0].size; -} - -std::size_t linear_axis_space::do_get_active_count(const axes_info &info) const -{ - return info[0].active_size; -} - -std::unique_ptr linear_axis_space::do_clone() const -{ - return std::make_unique(*this); -} - -zip_axis_space::zip_axis_space(std::vector input_indices, - std::vector output_indices) - : iteration_space_base(std::move(input_indices), std::move(output_indices)) -{} - -zip_axis_space::~zip_axis_space() = default; - -detail::axis_space_iterator zip_axis_space::do_get_iterator(axes_info info) const -{ - std::vector locs = m_output_indices; - auto update_func = [=](std::size_t inc_index, - std::vector &indices) { - for (std::size_t i = 0; i < info.size(); ++i) - { - detail::axis_index temp = info[i]; - temp.index = inc_index; - indices[locs[i]] = temp; - } - }; - - return detail::make_space_iterator(locs.size(), info[0].size, update_func); -} - -std::size_t zip_axis_space::do_get_size(const axes_info &info) const -{ - return info[0].size; -} - -std::size_t zip_axis_space::do_get_active_count(const axes_info &info) const -{ - return info[0].active_size; -} - -std::unique_ptr zip_axis_space::do_clone() const -{ - return std::make_unique(*this); -} - -user_axis_space::user_axis_space(std::vector input_indices, - std::vector output_indices) - : iteration_space_base(std::move(input_indices), std::move(output_indices)) -{} -user_axis_space::~user_axis_space() = default; - } // namespace nvbench diff --git a/nvbench/linear_axis_space.cuh b/nvbench/linear_axis_space.cuh new file mode 100644 index 0000000..603937b --- /dev/null +++ b/nvbench/linear_axis_space.cuh @@ -0,0 +1,37 @@ +/* + * Copyright 2022 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. + */ + +#pragma once + +#include + +namespace nvbench +{ + +struct linear_axis_space final : iteration_space_base +{ + linear_axis_space(std::size_t in, std::size_t out); + ~linear_axis_space(); + + std::unique_ptr do_clone() const override; + detail::axis_space_iterator do_get_iterator(axes_info info) const override; + std::size_t do_get_size(const axes_info &info) const override; + std::size_t do_get_active_count(const axes_info &info) const override; +}; + +} // namespace nvbench diff --git a/nvbench/linear_axis_space.cxx b/nvbench/linear_axis_space.cxx new file mode 100644 index 0000000..7e08065 --- /dev/null +++ b/nvbench/linear_axis_space.cxx @@ -0,0 +1,60 @@ +/* + * Copyright 2022 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 "linear_axis_space.cuh" + +#include + +namespace nvbench +{ + +linear_axis_space::linear_axis_space(std::size_t in_index, + std::size_t out_index) + : iteration_space_base({in_index}, {out_index}) +{} + +linear_axis_space::~linear_axis_space() = default; + +detail::axis_space_iterator linear_axis_space::do_get_iterator(axes_info info) const +{ + std::size_t loc(m_output_indices[0]); + auto update_func = [=](std::size_t inc_index, + std::vector &indices) { + indices[loc] = info[0]; + indices[loc].index = inc_index; + }; + + return detail::make_space_iterator(1, info[0].size, update_func); +} + +std::size_t linear_axis_space::do_get_size(const axes_info &info) const +{ + return info[0].size; +} + +std::size_t linear_axis_space::do_get_active_count(const axes_info &info) const +{ + return info[0].active_size; +} + +std::unique_ptr linear_axis_space::do_clone() const +{ + return std::make_unique(*this); +} + +} // namespace nvbench diff --git a/nvbench/user_axis_space.cuh b/nvbench/user_axis_space.cuh new file mode 100644 index 0000000..a4df3b0 --- /dev/null +++ b/nvbench/user_axis_space.cuh @@ -0,0 +1,37 @@ +/* + * Copyright 2022 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. + */ + +#pragma once + +#include + +namespace nvbench +{ + +struct user_axis_space : iteration_space_base +{ + user_axis_space(std::vector input_indices, + std::vector output_indices); + ~user_axis_space(); +}; + +using make_user_space_signature = + std::unique_ptr(std::vector input_indices, + std::vector output_indices); + +} // namespace nvbench diff --git a/nvbench/user_axis_space.cxx b/nvbench/user_axis_space.cxx new file mode 100644 index 0000000..3176907 --- /dev/null +++ b/nvbench/user_axis_space.cxx @@ -0,0 +1,32 @@ +/* + * Copyright 2022 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 "user_axis_space.cuh" + +#include + +namespace nvbench +{ + +user_axis_space::user_axis_space(std::vector input_indices, + std::vector output_indices) + : iteration_space_base(std::move(input_indices), std::move(output_indices)) +{} +user_axis_space::~user_axis_space() = default; + +} // namespace nvbench diff --git a/nvbench/zip_axis_space.cuh b/nvbench/zip_axis_space.cuh new file mode 100644 index 0000000..94aa1af --- /dev/null +++ b/nvbench/zip_axis_space.cuh @@ -0,0 +1,38 @@ +/* + * Copyright 2022 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. + */ + +#pragma once + +#include + +namespace nvbench +{ + +struct zip_axis_space final : iteration_space_base +{ + zip_axis_space(std::vector input_indices, + std::vector output_indices); + ~zip_axis_space(); + + std::unique_ptr do_clone() const override; + detail::axis_space_iterator do_get_iterator(axes_info info) const override; + std::size_t do_get_size(const axes_info &info) const override; + std::size_t do_get_active_count(const axes_info &info) const override; +}; + +} // namespace nvbench diff --git a/nvbench/zip_axis_space.cxx b/nvbench/zip_axis_space.cxx new file mode 100644 index 0000000..6f2edbd --- /dev/null +++ b/nvbench/zip_axis_space.cxx @@ -0,0 +1,64 @@ +/* + * Copyright 2022 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 "zip_axis_space.cuh" + +#include + +namespace nvbench +{ + +zip_axis_space::zip_axis_space(std::vector input_indices, + std::vector output_indices) + : iteration_space_base(std::move(input_indices), std::move(output_indices)) +{} + +zip_axis_space::~zip_axis_space() = default; + +detail::axis_space_iterator zip_axis_space::do_get_iterator(axes_info info) const +{ + std::vector locs = m_output_indices; + auto update_func = [=](std::size_t inc_index, + std::vector &indices) { + for (std::size_t i = 0; i < info.size(); ++i) + { + detail::axis_index temp = info[i]; + temp.index = inc_index; + indices[locs[i]] = temp; + } + }; + + return detail::make_space_iterator(locs.size(), info[0].size, update_func); +} + +std::size_t zip_axis_space::do_get_size(const axes_info &info) const +{ + return info[0].size; +} + +std::size_t zip_axis_space::do_get_active_count(const axes_info &info) const +{ + return info[0].active_size; +} + +std::unique_ptr zip_axis_space::do_clone() const +{ + return std::make_unique(*this); +} + +} // namespace nvbench