From 20fe8615a1638b5458a95487e0bd0a5ba329df0a Mon Sep 17 00:00:00 2001 From: Fabian Knorr Date: Mon, 13 Mar 2023 15:05:21 +0100 Subject: [PATCH] Address clang-tidy lints on fences --- examples/distr_io/distr_io.cc | 12 ++++++------ include/fence.h | 16 ++++++++-------- include/host_object.h | 4 ++-- include/task.h | 3 +++ test/runtime_tests.cc | 2 +- test/system/distr_tests.cc | 2 +- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/examples/distr_io/distr_io.cc b/examples/distr_io/distr_io.cc index 763f54f46..6a2e69ad5 100644 --- a/examples/distr_io/distr_io.cc +++ b/examples/distr_io/distr_io.cc @@ -154,14 +154,14 @@ int main(int argc, char* argv[]) { }); const auto files_equal = celerity::experimental::fence(q, equal).get()[0]; - fprintf(stderr, "=> Files are %sequal\n", files_equal ? "" : "NOT "); + fmt::print(stderr, "=> Files are {}equal\n", files_equal ? "" : "NOT "); return files_equal ? EXIT_SUCCESS : EXIT_FAILURE; } - fprintf(stderr, - "Usage: %s --generate to generate random data\n" - " %s --transpose to transpose\n" - " %s --compare to compare for equality\n", - argv[0], argv[0], argv[0]); + fmt::print(stderr, + "Usage: {0} --generate to generate random data\n" + " {0} --transpose to transpose\n" + " {0} --compare to compare for equality\n", + argv[0]); return EXIT_FAILURE; } diff --git a/include/fence.h b/include/fence.h index f06bde487..afce61493 100644 --- a/include/fence.h +++ b/include/fence.h @@ -28,9 +28,9 @@ class buffer_snapshot { public: buffer_snapshot() = default; - buffer_snapshot(buffer_snapshot&& other) : m_sr(other.m_sr), m_data(std::move(other.m_data)) { other.m_sr = {}; } + buffer_snapshot(buffer_snapshot&& other) noexcept : m_sr(other.m_sr), m_data(std::move(other.m_data)) { other.m_sr = {}; } - buffer_snapshot& operator=(buffer_snapshot&& other) { + buffer_snapshot& operator=(buffer_snapshot&& other) noexcept { m_sr = other.m_sr, other.m_sr = {}; m_data = std::move(other.m_data); } @@ -43,9 +43,9 @@ class buffer_snapshot { const T* get_data() const { return m_data.get(); } - inline const T& operator[](id index) const { return m_data[detail::get_linear_index(m_sr.range, index)]; } + inline const T& operator[](const id index) const { return m_data[detail::get_linear_index(m_sr.range, index)]; } - inline detail::subscript_result_t operator[](size_t index) const { return detail::subscript(*this, index); } + inline detail::subscript_result_t operator[](const size_t index) const { return detail::subscript(*this, index); } private: template @@ -62,7 +62,7 @@ class buffer_snapshot { namespace celerity::detail { template -class host_object_fence_promise : public detail::fence_promise { +class host_object_fence_promise final : public detail::fence_promise { public: explicit host_object_fence_promise(const experimental::host_object& obj) : m_host_object(obj) {} @@ -76,7 +76,7 @@ class host_object_fence_promise : public detail::fence_promise { }; template -class buffer_fence_promise : public detail::fence_promise { +class buffer_fence_promise final : public detail::fence_promise { public: explicit buffer_fence_promise(const buffer& buf, const subrange& sr) : m_buffer(buf), m_subrange(sr) {} @@ -109,7 +109,7 @@ namespace celerity::experimental { * fence and wait operations or ensure that other independent command groups are eligible to run while the fence is executed. */ template -[[nodiscard]] std::future fence(celerity::distr_queue&, const experimental::host_object& obj) { +[[nodiscard]] std::future fence(celerity::distr_queue& /* unused */, const experimental::host_object& obj) { static_assert(std::is_object_v, "host_object and host_object are not allowed as parameters to fence()"); detail::side_effect_map side_effects; @@ -127,7 +127,7 @@ template * fence and wait operations or ensure that other independent command groups are eligible to run while the fence is executed. */ template -[[nodiscard]] std::future> fence(celerity::distr_queue&, const buffer& buf, const subrange& sr) { +[[nodiscard]] std::future> fence(celerity::distr_queue& /* unused */, const buffer& buf, const subrange& sr) { detail::buffer_access_map access_map; access_map.add_access(detail::get_buffer_id(buf), std::make_unique>>(celerity::access::fixed(sr), access_mode::read, buf.get_range())); diff --git a/include/host_object.h b/include/host_object.h index 8a1350a78..bf2fcc219 100644 --- a/include/host_object.h +++ b/include/host_object.h @@ -110,7 +110,7 @@ class host_object { /// Constructs the object in-place with the given constructor arguments. template - explicit host_object(const std::in_place_t, CtorParams&&... ctor_args) // requiring std::in_place avoids overriding copy and move constructors + explicit host_object(const std::in_place_t /* tag */, CtorParams&&... ctor_args) // requiring std::in_place avoids overriding copy and move constructors : m_shared_state(std::make_shared(std::in_place, std::forward(ctor_args)...)) {} private: @@ -124,7 +124,7 @@ class host_object { T instance; template - explicit state(const std::in_place_t, CtorParams&&... ctor_args) : instance(std::forward(ctor_args)...) {} + explicit state(const std::in_place_t /* tag */, CtorParams&&... ctor_args) : instance(std::forward(ctor_args)...) {} }; detail::host_object_id get_id() const { return m_shared_state->id; } diff --git a/include/task.h b/include/task.h index 7c13ee9b6..d7a9816b4 100644 --- a/include/task.h +++ b/include/task.h @@ -99,6 +99,9 @@ namespace detail { class fence_promise { public: + fence_promise() = default; + fence_promise(const fence_promise&) = delete; + fence_promise& operator=(const fence_promise&) = delete; virtual ~fence_promise() = default; virtual void fulfill() = 0; diff --git a/test/runtime_tests.cc b/test/runtime_tests.cc index 521fbc61c..6dd29c5e4 100644 --- a/test/runtime_tests.cc +++ b/test/runtime_tests.cc @@ -1039,7 +1039,7 @@ namespace detail { q.submit([=](handler& cgh) { accessor acc(buf, cgh, all{}, write_only, no_init); - cgh.parallel_for(buf.get_range(), [=](celerity::item<2> item) { acc[item] = item.get_linear_id(); }); + cgh.parallel_for(buf.get_range(), [=](celerity::item<2> item) { acc[item] = static_cast(item.get_linear_id()); }); }); const auto check_snapshot = [&](const subrange<2>& sr, const std::vector& expected_data) { diff --git a/test/system/distr_tests.cc b/test/system/distr_tests.cc index 2a6c0b1d5..161b96fd9 100644 --- a/test/system/distr_tests.cc +++ b/test/system/distr_tests.cc @@ -363,7 +363,7 @@ namespace detail { REQUIRE(gathered_from_master.get_range() == range<3>{1, 1, 1}); CHECK(gathered_from_master[0][0][0] == 42); - int global_rank; + int global_rank = -1; MPI_Comm_rank(MPI_COMM_WORLD, &global_rank); CHECK(host_rank == global_rank); }