Fix warious warnings

This commit is contained in:
Georgy Evtushenko
2023-09-22 11:58:09 -07:00
parent a1eea54585
commit f3a1fa2a9f
10 changed files with 42 additions and 25 deletions

View File

@@ -35,7 +35,7 @@ struct l2flush
if (m_l2_size > 0)
{
void *buffer = m_l2_buffer;
NVBENCH_CUDA_CALL(cudaMalloc(&buffer, m_l2_size));
NVBENCH_CUDA_CALL(cudaMalloc(&buffer, static_cast<std::size_t>(m_l2_size)));
m_l2_buffer = reinterpret_cast<int *>(buffer);
}
}
@@ -52,7 +52,8 @@ struct l2flush
{
if (m_l2_size > 0)
{
NVBENCH_CUDA_CALL(cudaMemsetAsync(m_l2_buffer, 0, m_l2_size, stream));
NVBENCH_CUDA_CALL(
cudaMemsetAsync(m_l2_buffer, 0, static_cast<std::size_t>(m_l2_size), stream));
}
}

View File

@@ -34,6 +34,15 @@ namespace nvbench::detail
template <typename T>
struct ring_buffer
{
private:
using buffer_t = typename std::vector<T>;
using diff_t = typename buffer_t::difference_type;
buffer_t m_buffer;
std::size_t m_index{0};
bool m_full{false};
public:
/**
* Create a new ring buffer with the requested capacity.
*/
@@ -49,9 +58,9 @@ struct ring_buffer
[[nodiscard]] auto begin() { return m_buffer.begin(); }
[[nodiscard]] auto begin() const { return m_buffer.begin(); }
[[nodiscard]] auto cbegin() const { return m_buffer.cbegin(); }
[[nodiscard]] auto end() { return m_buffer.begin() + this->size(); }
[[nodiscard]] auto end() const { return m_buffer.begin() + this->size(); }
[[nodiscard]] auto cend() const { return m_buffer.cbegin() + this->size(); }
[[nodiscard]] auto end() { return m_buffer.begin() + static_cast<diff_t>(this->size()); }
[[nodiscard]] auto end() const { return m_buffer.begin() + static_cast<diff_t>(this->size()); }
[[nodiscard]] auto cend() const { return m_buffer.cbegin() + static_cast<diff_t>(this->size()); }
// clang-format on
/** @} */
@@ -113,11 +122,6 @@ struct ring_buffer
return m_buffer[back_index];
}
/**@}*/
private:
std::vector<T> m_buffer;
std::size_t m_index{0};
bool m_full{false};
};
} // namespace nvbench::detail

View File

@@ -154,7 +154,7 @@ struct device_info
[[nodiscard]] std::size_t get_global_memory_bus_bandwidth() const
{ // 2 is for DDR, CHAR_BITS to convert bus_width to bytes.
return 2 * this->get_global_memory_bus_peak_clock_rate() *
(this->get_global_memory_bus_width() / CHAR_BIT);
static_cast<std::size_t>(this->get_global_memory_bus_width() / CHAR_BIT);
}
/// @return The size of the L2 cache in bytes.

View File

@@ -16,12 +16,12 @@
* limitations under the License.
*/
#include <nvbench/device_manager.cuh>
#include <cuda_runtime_api.h>
#include <nvbench/cuda_call.cuh>
#include <nvbench/detail/device_scope.cuh>
#include <cuda_runtime_api.h>
#include <nvbench/detail/throw.cuh>
#include <nvbench/device_manager.cuh>
namespace nvbench
{
@@ -44,4 +44,13 @@ device_manager::device_manager()
}
}
const nvbench::device_info &device_manager::get_device(int id)
{
if (id < 0)
{
NVBENCH_THROW(std::runtime_error, "Negative index: {}.", id);
}
return m_devices.at(static_cast<std::size_t>(id));
}
} // namespace nvbench

View File

@@ -54,7 +54,7 @@ struct device_manager
/**
* @return The device_info object corresponding to `id`.
*/
[[nodiscard]] const nvbench::device_info &get_device(int id) { return m_devices.at(id); }
[[nodiscard]] const nvbench::device_info &get_device(int id);
/**
* @return A vector containing device_info objects for all detected CUDA

View File

@@ -69,13 +69,16 @@ struct int64_axis final : public axis_base
int64_axis_flags get_flags() const { return m_flags; }
// Helper functions for pow2 conversions:
static nvbench::int64_t compute_pow2(nvbench::int64_t exponent) { return 1ll << exponent; }
static nvbench::int64_t compute_pow2(nvbench::int64_t exponent)
{
return nvbench::int64_t{1} << exponent;
}
// UB if value < 0.
static nvbench::int64_t compute_log2(nvbench::int64_t value)
{
// TODO use <bit> functions in C++20?
nvbench::uint64_t bits = static_cast<nvbench::int64_t>(value);
nvbench::uint64_t bits = static_cast<nvbench::uint64_t>(value);
nvbench::int64_t exponent = 0;
while ((bits >>= 1) != 0ull)
{

View File

@@ -43,9 +43,9 @@ struct launch
// move-only
launch(const launch &) = delete;
launch(launch &&) = default;
launch(launch &&) = delete;
launch &operator=(const launch &) = delete;
launch &operator=(launch &&) = default;
launch &operator=(launch &&) = delete;
/**
* @return a CUDA stream that all kernels and other stream-ordered CUDA work

View File

@@ -365,7 +365,7 @@ void option_parser::parse_range(option_parser::arg_iterator_t first,
}
auto check_params = [&first, &last](std::size_t num_params) {
const std::size_t rem_args = std::distance(first, last) - 1;
const std::size_t rem_args = static_cast<std::size_t>(std::distance(first, last) - 1);
if (rem_args < num_params)
{
NVBENCH_THROW(std::runtime_error,
@@ -444,7 +444,7 @@ void option_parser::parse_range(option_parser::arg_iterator_t first,
this->disable_blocking_kernel();
first += 1;
}
else if (arg == "--quiet" | arg == "-q")
else if (arg == "--quiet" || arg == "-q")
{
// Setting this flag prevents the default stdout printer from being
// added.
@@ -726,7 +726,7 @@ try
catch (std::invalid_argument &)
{}
m_benchmarks.push_back(idx >= 0 ? mgr.get_benchmark(idx).clone()
m_benchmarks.push_back(idx >= 0 ? mgr.get_benchmark(static_cast<std::size_t>(idx)).clone()
: mgr.get_benchmark(name).clone());
// Initialize the new benchmark with any global arguments:

View File

@@ -78,9 +78,9 @@ struct printer_base
// move-only
printer_base(const printer_base &) = delete;
printer_base(printer_base &&) = default;
printer_base(printer_base &&) = delete;
printer_base &operator=(const printer_base &) = delete;
printer_base &operator=(printer_base &&) = default;
printer_base &operator=(printer_base &&) = delete;
/*!
* Called once with the command line arguments used to invoke the current

View File

@@ -67,7 +67,7 @@ std::size_t type_axis::get_type_index(const std::string &input_string) const
m_input_strings);
}
return it - m_input_strings.cbegin();
return static_cast<std::size_t>(it - m_input_strings.cbegin());
}
} // namespace nvbench