Skip to content

Commit

Permalink
Extend clang-tidy application
Browse files Browse the repository at this point in the history
  • Loading branch information
davschneller committed Sep 2, 2024
1 parent ab86398 commit ef42a16
Show file tree
Hide file tree
Showing 26 changed files with 580 additions and 531 deletions.
72 changes: 53 additions & 19 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,33 @@
#
# SPDX-License-Identifier: BSD-3-Clause

Checks: '-*,clang-diagnostic-*,cppcoreguidelines-avoid-non-const-global-variables,llvm-*,-llvm-else-after-return,-llvm-header-guard,-llvm-qualified-auto,misc-*,misc-const-correctness,misc-misplaced-const,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,modernize-use-override,modernize-use-equals-default,performance-move-const-arg,readability-non-const-parameter,readability-const-return-type,readability-identifier-naming'
Checks: |
-*,
clang-diagnostic-*,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-no-malloc,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
llvm-*,
-llvm-else-after-return,
-llvm-header-guard,
-llvm-qualified-auto,
misc-*,
-misc-non-private-member-variables-in-classes,
-misc-unused-parameters,
-misc-no-recursion,
modernize-*,
performance-*,
readability-*,
-readability-else-after-return,
-readability-identifier-length,
-readability-magic-numbers,
-readability-function-cognitive-complexity,
WarningsAsErrors: '*'
CheckOptions:
# - key: readability-identifier-naming.AbstractClassCase
Expand Down Expand Up @@ -72,7 +98,7 @@ CheckOptions:
# - key: readability-identifier-naming.ConstexprMethodSuffix
# value: CamelCase
- key: readability-identifier-naming.ConstexprVariableCase
value: camelBack
value: CamelCase
# - key: readability-identifier-naming.ConstexprVariablePrefix
# value: CamelCase
# - key: readability-identifier-naming.ConstexprVariableSuffix
Expand All @@ -95,8 +121,8 @@ CheckOptions:
# value: CamelCase
# - key: readability-identifier-naming.FunctionSuffix
# value: CamelCase
# - key: readability-identifier-naming.GlobalConstantCase
# value: CamelCase
- key: readability-identifier-naming.GlobalConstantCase
value: CamelCase
# - key: readability-identifier-naming.GlobalConstantPrefix
# value: CamelCase
# - key: readability-identifier-naming.GlobalConstantSuffix
Expand Down Expand Up @@ -159,10 +185,12 @@ CheckOptions:
# value: CamelCase
- key: readability-identifier-naming.MemberCase
value: camelBack
- key: readability-identifier-naming.MemberPrefix
value: ""
- key: readability-identifier-naming.MemberIgnoredRegexp
value: "^m_|_$" # TODO: temporary! Remove after more refactoring.
# - key: readability-identifier-naming.MemberPrefix
# value: ""
# - key: readability-identifier-naming.MemberSuffix
# value: CamelCase
# value: ""
# - key: readability-identifier-naming.MethodCase
# value: CamelCase
# - key: readability-identifier-naming.MethodPrefix
Expand Down Expand Up @@ -195,8 +223,8 @@ CheckOptions:
# value: CamelCase
# - key: readability-identifier-naming.PrivateMemberCase
# value: CamelCase
- key: readability-identifier-naming.PrivateMemberPrefix
value: "m_"
# - key: readability-identifier-naming.PrivateMemberPrefix
# value: CamelCase
# - key: readability-identifier-naming.PrivateMemberSuffix
# value: CamelCase
# - key: readability-identifier-naming.PrivateMethodCase
Expand Down Expand Up @@ -229,8 +257,8 @@ CheckOptions:
# value: CamelCase
# - key: readability-identifier-naming.PublicMethodSuffix
# value: CamelCase
# - key: readability-identifier-naming.StaticConstantCase
# value: CamelCase
- key: readability-identifier-naming.StaticConstantCase
value: CamelCase
# - key: readability-identifier-naming.StaticConstantPrefix
# value: CamelCase
# - key: readability-identifier-naming.StaticConstantSuffix
Expand All @@ -247,26 +275,26 @@ CheckOptions:
# value: CamelCase
# - key: readability-identifier-naming.StructSuffix
# value: CamelCase
# - key: readability-identifier-naming.TemplateParameterCase
# value: CamelCase
- key: readability-identifier-naming.TemplateParameterCase
value: CamelCase
# - key: readability-identifier-naming.TemplateParameterPrefix
# value: CamelCase
# - key: readability-identifier-naming.TemplateParameterSuffix
# value: CamelCase
# - key: readability-identifier-naming.TemplateTemplateParameterCase
# value: CamelCase
- key: readability-identifier-naming.TemplateTemplateParameterCase
value: CamelCase
# - key: readability-identifier-naming.TemplateTemplateParameterPrefix
# value: CamelCase
# - key: readability-identifier-naming.TemplateTemplateParameterSuffix
# value: CamelCase
# - key: readability-identifier-naming.TypeAliasCase
# value: CamelCase
- key: readability-identifier-naming.TypeAliasCase
value: CamelCase
# - key: readability-identifier-naming.TypeAliasPrefix
# value: CamelCase
# - key: readability-identifier-naming.TypeAliasSuffix
# value: CamelCase
# - key: readability-identifier-naming.TypedefCase
# value: CamelCase
- key: readability-identifier-naming.TypedefCase
value: CamelCase
# - key: readability-identifier-naming.TypedefPrefix
# value: CamelCase
# - key: readability-identifier-naming.TypedefSuffix
Expand Down Expand Up @@ -301,3 +329,9 @@ CheckOptions:
# value: CamelCase
# - key: readability-identifier-naming.VirtualMethodSuffix
# value: CamelCase

# ignore internal GCC headers (bits/)
- key: misc-include-cleaner.IgnoreHeaders
value: 'bits/.*'
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: True
15 changes: 8 additions & 7 deletions async/BufferOrigin.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <vector>

namespace async {

Expand All @@ -53,8 +52,9 @@ namespace async {
*/
class BufferOrigin {
public:
virtual ~BufferOrigin() = default;
// allocates memory in the buffer allocation zone
virtual void* malloc(size_t size) = 0;
virtual auto malloc(size_t size) -> void* = 0;

// frees memory in the buffer allocation zone
virtual void free(void* ptr) = 0;
Expand All @@ -72,15 +72,16 @@ class BufferOrigin {
virtual void touch(void* ptr, size_t size) = 0;

// memory can be accessed on host
virtual bool transparentHost() = 0;
virtual auto transparentHost() -> bool = 0;

// memory can be directly passed to MPI
virtual bool transparentMPI() = 0;
virtual auto transparentMPI() -> bool = 0;
};

class HostBufferOrigin : public BufferOrigin {
public:
void* malloc(size_t size) override { return std::malloc(size); }
~HostBufferOrigin() override = default;
auto malloc(size_t size) -> void* override { return std::malloc(size); }
void free(void* ptr) override { std::free(ptr); }
void copyTo(void* dest, const void* source, size_t size) override {
std::memcpy(dest, source, size);
Expand All @@ -92,8 +93,8 @@ class HostBufferOrigin : public BufferOrigin {
std::memcpy(dest, source, size);
}
void touch(void* ptr, size_t size) override { std::memset(ptr, 0, size); }
bool transparentHost() override { return true; }
bool transparentMPI() override { return true; }
auto transparentHost() -> bool override { return true; }
auto transparentMPI() -> bool override { return true; }
};

} // namespace async
Expand Down
24 changes: 13 additions & 11 deletions async/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,27 @@ class Config {

size_t m_alignment;

private:
Config()
: m_mode(str2mode(utils::Env::get<const char*>("ASYNC_MODE", "SYNC"))),
m_pinCore(utils::Env::get<int>("ASYNC_PIN_CORE", -1)),
m_groupSize(m_mode == MPI ? utils::Env::get("ASYNC_GROUP_SIZE", 64) : 1),
m_asyncCopy(utils::Env::get<int>("ASYNC_MPI_COPY", 0)),
m_asyncCopy(utils::Env::get<int>("ASYNC_MPI_COPY", 0) != 0),
m_alignment(utils::Env::get<size_t>("ASYNC_BUFFER_ALIGNMENT", 0)) {}

public:
static Mode mode() { return instance().m_mode; }
static auto mode() -> Mode { return instance().m_mode; }

static int getPinCore() { return instance().m_pinCore; }
static auto getPinCore() -> int { return instance().m_pinCore; }

static unsigned int groupSize() { return instance().m_groupSize; }
static auto groupSize() -> unsigned int { return instance().m_groupSize; }

static bool useAsyncCopy() { return instance().m_asyncCopy; }
static auto useAsyncCopy() -> bool { return instance().m_asyncCopy; }

static size_t alignment() { return instance().m_alignment; }
static auto alignment() -> size_t { return instance().m_alignment; }

static size_t maxSend() { return utils::Env::get<size_t>("ASYNC_MPI_MAX_SEND", 1UL << 30); }
static auto maxSend() -> size_t {
return utils::Env::get<size_t>("ASYNC_MPI_MAX_SEND", 1UL << 30);
}

static void setMode(Mode mode) { instance().m_mode = mode; }

Expand All @@ -98,19 +99,20 @@ class Config {
static void setUseAsyncCopy(bool useAsyncCopy) { instance().m_asyncCopy = useAsyncCopy; }

static void setGroupSize(unsigned int groupSize) {
if (instance().mode() == MPI)
if (Config::mode() == MPI) {
instance().m_groupSize = groupSize;
}
}

static void setAlignment(size_t alignment) { instance().m_alignment = alignment; }

private:
static Config& instance() {
static auto instance() -> Config& {
static Config config;
return config;
}

static Mode str2mode(const char* mode) {
static auto str2mode(const char* mode) -> Mode {
std::string strMode(mode);
utils::StringUtils::toUpper(strMode);

Expand Down
15 changes: 10 additions & 5 deletions async/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class Dispatcher {
ModuleBase::modules().clear();
}

auto operator=(Dispatcher&&) -> Dispatcher& = delete;
auto operator=(const Dispatcher&) -> Dispatcher& = delete;
Dispatcher(const Dispatcher&) = delete;
Dispatcher(Dispatcher&&) = delete;

#ifdef USE_MPI
void setCommunicator(MPI_Comm comm) { m_comm = comm; }
#endif
Expand Down Expand Up @@ -119,18 +124,18 @@ class Dispatcher {
/**
* @return The groups size (or 1 for synchronous and asynchnchronous thread mode)
*/
unsigned int groupSize() const { return m_groupSize; }
[[nodiscard]] auto groupSize() const -> unsigned int { return m_groupSize; }

#ifdef USE_MPI
MPI_Comm groupComm() const { return m_scheduler.groupComm(); }
[[nodiscard]] auto groupComm() const -> MPI_Comm { return m_scheduler.groupComm(); }

MPI_Comm commWorld() const { return m_scheduler.commWorld(); }
[[nodiscard]] auto commWorld() const -> MPI_Comm { return m_scheduler.commWorld(); }
#endif // USE_MPI

/**
* @return True if the process is an MPI executor
*/
bool isExecutor() const {
[[nodiscard]] auto isExecutor() const -> bool {
#ifdef USE_MPI
return m_scheduler.isExecutor();
#else // USE_MPI
Expand All @@ -146,7 +151,7 @@ class Dispatcher {
* @return False if this rank is an MPI executor that does not contribute to the
* computation.
*/
bool dispatch() {
auto dispatch() -> bool {
#ifdef USE_MPI
if (m_scheduler.isExecutor()) {
const auto& modules = ModuleBase::modules();
Expand Down
12 changes: 6 additions & 6 deletions async/ExecInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,33 @@ class ExecInfo {
HostBufferOrigin* m_hostBuffer;

public:
ExecInfo() { m_hostBuffer = new HostBufferOrigin(); }
ExecInfo() : m_hostBuffer(new HostBufferOrigin()) {}

virtual ~ExecInfo() = default;

/**
* @return True, if this is an MPI executor
*/
virtual bool isExecutor() const {
[[nodiscard]] virtual auto isExecutor() const -> bool {
return false; // Default for sync and thread
}

unsigned int numBuffers() const { return m_bufferSize.size(); }
[[nodiscard]] auto numBuffers() const -> unsigned int { return m_bufferSize.size(); }

size_t bufferSize(unsigned int id) const {
[[nodiscard]] auto bufferSize(unsigned int id) const -> size_t {
assert(id < numBuffers());
return m_bufferSize[id];
}

BufferOrigin& bufferOrigin(unsigned int id) const {
[[nodiscard]] auto bufferOrigin(unsigned int id) const -> BufferOrigin& {
assert(id < numBuffers());
return *m_bufferOrigin[id];
}

/**
* @return Read-only pointer to the buffer (Useful for executors.)
*/
virtual const void* buffer(unsigned int id) const = 0;
[[nodiscard]] virtual auto buffer(unsigned int id) const -> const void* = 0;

protected:
void addBufferInternal(size_t size) {
Expand Down
Loading

0 comments on commit ef42a16

Please sign in to comment.