Skip to content

Commit

Permalink
Refactor axis spaces into separate TUs
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Apr 12, 2022
1 parent 40a6711 commit f4396bd
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 112 deletions.
3 changes: 3 additions & 0 deletions nvbench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions nvbench/axes_metadata.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
#include <nvbench/axis_iteration_space.cuh>
#include <nvbench/float64_axis.cuh>
#include <nvbench/int64_axis.cuh>
#include <nvbench/linear_axis_space.cuh>
#include <nvbench/string_axis.cuh>
#include <nvbench/type_axis.cuh>
#include <nvbench/types.cuh>
#include <nvbench/user_axis_space.cuh>
#include <nvbench/zip_axis_space.cuh>

#include <functional>
#include <memory>
Expand Down
34 changes: 0 additions & 34 deletions nvbench/axis_iteration_space.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,4 @@ protected:
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<iteration_space_base> 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<std::size_t> input_indices,
std::vector<std::size_t> output_indices);
~zip_axis_space();

std::unique_ptr<iteration_space_base> 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 user_axis_space : iteration_space_base
{
user_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices);
~user_axis_space();
};

using make_user_space_signature =
std::unique_ptr<iteration_space_base>(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices);

} // namespace nvbench
79 changes: 1 addition & 78 deletions nvbench/axis_iteration_space.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "axis_iteration_space.cuh"

#include <nvbench/type_axis.cuh>
#include <nvbench/linear_axis_space.cuh>

namespace nvbench
{
Expand Down Expand Up @@ -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<detail::axis_index> &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<iteration_space_base> linear_axis_space::do_clone() const
{
return std::make_unique<linear_axis_space>(*this);
}

zip_axis_space::zip_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> 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<std::size_t> locs = m_output_indices;
auto update_func = [=](std::size_t inc_index,
std::vector<detail::axis_index> &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<iteration_space_base> zip_axis_space::do_clone() const
{
return std::make_unique<zip_axis_space>(*this);
}

user_axis_space::user_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices)
: iteration_space_base(std::move(input_indices), std::move(output_indices))
{}
user_axis_space::~user_axis_space() = default;

} // namespace nvbench
37 changes: 37 additions & 0 deletions nvbench/linear_axis_space.cuh
Original file line number Diff line number Diff line change
@@ -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 <nvbench/axis_iteration_space.cuh>

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<iteration_space_base> 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
60 changes: 60 additions & 0 deletions nvbench/linear_axis_space.cxx
Original file line number Diff line number Diff line change
@@ -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 <nvbench/type_axis.cuh>

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<detail::axis_index> &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<iteration_space_base> linear_axis_space::do_clone() const
{
return std::make_unique<linear_axis_space>(*this);
}

} // namespace nvbench
37 changes: 37 additions & 0 deletions nvbench/user_axis_space.cuh
Original file line number Diff line number Diff line change
@@ -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 <nvbench/axis_iteration_space.cuh>

namespace nvbench
{

struct user_axis_space : iteration_space_base
{
user_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices);
~user_axis_space();
};

using make_user_space_signature =
std::unique_ptr<iteration_space_base>(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices);

} // namespace nvbench
32 changes: 32 additions & 0 deletions nvbench/user_axis_space.cxx
Original file line number Diff line number Diff line change
@@ -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 <nvbench/type_axis.cuh>

namespace nvbench
{

user_axis_space::user_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices)
: iteration_space_base(std::move(input_indices), std::move(output_indices))
{}
user_axis_space::~user_axis_space() = default;

} // namespace nvbench
38 changes: 38 additions & 0 deletions nvbench/zip_axis_space.cuh
Original file line number Diff line number Diff line change
@@ -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 <nvbench/axis_iteration_space.cuh>

namespace nvbench
{

struct zip_axis_space final : iteration_space_base
{
zip_axis_space(std::vector<std::size_t> input_indices,
std::vector<std::size_t> output_indices);
~zip_axis_space();

std::unique_ptr<iteration_space_base> 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
Loading

0 comments on commit f4396bd

Please sign in to comment.