From 288b1564e07e3d599d2b863c84aa969d578db428 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Tue, 21 Dec 2021 19:34:36 -0500 Subject: [PATCH] Suppress warnings on MSVC Debug builds. Also moved the config.cuh.in template into the source directory where it'll be easier to find. --- cmake/NVBenchWriteConfigHeader.cmake | 4 ++-- cmake/config.cuh.in | 25 -------------------- nvbench/CMakeLists.txt | 4 +++- nvbench/config.cuh.in | 34 ++++++++++++++++++++++++++++ nvbench/csv_printer.cu | 5 ++++ nvbench/detail/state_exec.cuh | 7 ++++++ nvbench/markdown_printer.cu | 10 ++++++++ nvbench/named_values.cxx | 5 ++++ 8 files changed, 66 insertions(+), 28 deletions(-) delete mode 100644 cmake/config.cuh.in create mode 100644 nvbench/config.cuh.in diff --git a/cmake/NVBenchWriteConfigHeader.cmake b/cmake/NVBenchWriteConfigHeader.cmake index f0c0333..2d86c94 100644 --- a/cmake/NVBenchWriteConfigHeader.cmake +++ b/cmake/NVBenchWriteConfigHeader.cmake @@ -1,4 +1,4 @@ -function(nvbench_write_config_header filepath) +function(nvbench_write_config_header in_file out_file) if (NVBench_ENABLE_NVML) set(NVBENCH_HAS_NVML 1) endif() @@ -7,5 +7,5 @@ function(nvbench_write_config_header filepath) set(NVBENCH_HAS_CUPTI 1) endif() - configure_file("${NVBench_SOURCE_DIR}/cmake/config.cuh.in" "${filepath}") + configure_file("${in_file}" "${out_file}") endfunction() diff --git a/cmake/config.cuh.in b/cmake/config.cuh.in deleted file mode 100644 index e04cce1..0000000 --- a/cmake/config.cuh.in +++ /dev/null @@ -1,25 +0,0 @@ -/* -* 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. -*/ - -#pragma once - -// Defined if NVBench has been built with NVML support. -#cmakedefine NVBENCH_HAS_NVML - -// Defined if NVBench has been built with CUPTI support. -#cmakedefine NVBENCH_HAS_CUPTI diff --git a/nvbench/CMakeLists.txt b/nvbench/CMakeLists.txt index e99699c..f86bd41 100644 --- a/nvbench/CMakeLists.txt +++ b/nvbench/CMakeLists.txt @@ -60,7 +60,9 @@ file_to_string("../docs/cli_help_axis.md" cli_help_axis_text ) -nvbench_write_config_header("${NVBench_BINARY_DIR}/nvbench/config.cuh") +nvbench_write_config_header(config.cuh.in + "${NVBench_BINARY_DIR}/nvbench/config.cuh" +) # nvbench (nvbench::nvbench) add_library(nvbench SHARED ${srcs}) diff --git a/nvbench/config.cuh.in b/nvbench/config.cuh.in new file mode 100644 index 0000000..3f51111 --- /dev/null +++ b/nvbench/config.cuh.in @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#pragma once + +// Defined if NVBench has been built with NVML support. +#cmakedefine NVBENCH_HAS_NVML + +// Defined if NVBench has been built with CUPTI support. +#cmakedefine NVBENCH_HAS_CUPTI + +#ifdef _MSC_VER +#define NVBENCH_MSVC_PUSH_DISABLE_WARNING(code) \ + __pragma(warning(push)) __pragma(warning(disable : code)) +#define NVBENCH_MSVC_POP_WARNING() __pragma(warning(pop)) +#else +#define NVBENCH_MSVC_PUSH_DISABLE_WARNING(code) +#define NVBENCH_MSVC_POP_WARNING() +#endif diff --git a/nvbench/csv_printer.cu b/nvbench/csv_printer.cu index 340b109..df64518 100644 --- a/nvbench/csv_printer.cu +++ b/nvbench/csv_printer.cu @@ -44,8 +44,13 @@ void csv_printer::do_print_benchmark_results(const benchmark_vector &benches) { return v; } + + // warning C4702: unreachable code + // This is a future-proofing fallback that's currently unused. + NVBENCH_MSVC_PUSH_DISABLE_WARNING(4702) return fmt::format("{}", v); }; + NVBENCH_MSVC_POP_WARNING() // Prepare table: nvbench::internal::table_builder table; diff --git a/nvbench/detail/state_exec.cuh b/nvbench/detail/state_exec.cuh index edde96d..98d50a0 100644 --- a/nvbench/detail/state_exec.cuh +++ b/nvbench/detail/state_exec.cuh @@ -39,6 +39,11 @@ namespace nvbench { +// warning C4702: unreachable code +// Several spurious instances in this function. MSVC 2019 seems to forget that +// sometimes the constexpr branch /isn't/ taken. +NVBENCH_MSVC_PUSH_DISABLE_WARNING(4702) + template void state::exec(ExecTags tags, KernelLauncher &&kernel_launcher) { @@ -142,4 +147,6 @@ void state::exec(ExecTags tags, KernelLauncher &&kernel_launcher) } } +NVBENCH_MSVC_POP_WARNING() + } // namespace nvbench diff --git a/nvbench/markdown_printer.cu b/nvbench/markdown_printer.cu index 23e6ee0..a23b360 100644 --- a/nvbench/markdown_printer.cu +++ b/nvbench/markdown_printer.cu @@ -229,8 +229,13 @@ void markdown_printer::do_print_benchmark_results( { return v; } + + // warning C4702: unreachable code + // This is a future-proofing fallback that's currently unused. + NVBENCH_MSVC_PUSH_DISABLE_WARNING(4702) return fmt::format("{}", v); }; + NVBENCH_MSVC_POP_WARNING() // Start printing benchmarks fmt::memory_buffer buffer; @@ -368,8 +373,13 @@ std::string markdown_printer::do_format_default(const summary &data) { return v; } + + // warning C4702: unreachable code + // This is a future-proofing fallback that's currently unused. + NVBENCH_MSVC_PUSH_DISABLE_WARNING(4702) return fmt::format("{}", v); }; + NVBENCH_MSVC_POP_WARNING() return std::visit(format_visitor, data.get_value("value")); } diff --git a/nvbench/named_values.cxx b/nvbench/named_values.cxx index cb5b1f2..1aeb4dc 100644 --- a/nvbench/named_values.cxx +++ b/nvbench/named_values.cxx @@ -18,6 +18,7 @@ #include +#include #include #include @@ -92,11 +93,15 @@ named_values::type named_values::get_type(const std::string &name) const { return nvbench::named_values::type::string; } + // warning C4702: unreachable code + // This is a future-proofing check, it'll be reachable if something breaks + NVBENCH_MSVC_PUSH_DISABLE_WARNING(4702) NVBENCH_THROW(std::runtime_error, "Unknown variant type for entry '{}'.", name); }, this->get_value(name)); + NVBENCH_MSVC_POP_WARNING() } nvbench::int64_t named_values::get_int64(const std::string &name) const