From 7cdef04a3df0669c2d4d4cda9a13872f6006b5e6 Mon Sep 17 00:00:00 2001 From: Allard Hendriksen Date: Thu, 27 Apr 2023 12:04:20 +0200 Subject: [PATCH] Move RAFT_INLINE_CONDITIONAL to macros.hpp --- cpp/include/raft/core/detail/macros.hpp | 22 +++++++++++++- cpp/include/raft/core/logger-inl.hpp | 2 +- cpp/include/raft/util/inline.hpp | 37 ----------------------- cpp/include/raft/util/memory_pool-inl.hpp | 2 +- 4 files changed, 23 insertions(+), 40 deletions(-) delete mode 100644 cpp/include/raft/util/inline.hpp diff --git a/cpp/include/raft/core/detail/macros.hpp b/cpp/include/raft/core/detail/macros.hpp index bfb47437ad..fb0d597850 100644 --- a/cpp/include/raft/core/detail/macros.hpp +++ b/cpp/include/raft/core/detail/macros.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, NVIDIA CORPORATION. + * Copyright (c) 2022-2023, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,26 @@ #define RAFT_INLINE_FUNCTION _RAFT_HOST_DEVICE _RAFT_FORCEINLINE #endif +// The RAFT_INLINE_CONDITIONAL is a conditional inline specifier that removes +// the inline specification when RAFT_COMPILED is defined. +// +// When RAFT_COMPILED is not defined, functions may be defined in multiple +// translation units and we do not want that to lead to linker errors. +// +// When RAFT_COMPILED is defined, this serves two purposes: +// +// 1. It triggers a multiple definition error message when memory_pool-inl.hpp +// (for instance) is accidentally included in multiple translation units. +// +// 2. We function definitions to be non-inline, because non-inline functions +// symbols are always exported in the object symbol table. For inline functions, +// the compiler may elide the external symbol, which results in linker errors. +#ifdef RAFT_COMPILED +#define RAFT_INLINE_CONDITIONAL +#else +#define RAFT_INLINE_CONDITIONAL inline +#endif // RAFT_COMPILED + /** * Some macro magic to remove optional parentheses of a macro argument. * See https://stackoverflow.com/a/62984543 diff --git a/cpp/include/raft/core/logger-inl.hpp b/cpp/include/raft/core/logger-inl.hpp index e23de66bec..a90023d01f 100644 --- a/cpp/include/raft/core/logger-inl.hpp +++ b/cpp/include/raft/core/logger-inl.hpp @@ -35,7 +35,7 @@ #define SPDLOG_HEADER_ONLY #include -#include // RAFT_INLINE_CONDITIONAL +#include // RAFT_INLINE_CONDITIONAL #include // NOLINT #include // NOLINT diff --git a/cpp/include/raft/util/inline.hpp b/cpp/include/raft/util/inline.hpp deleted file mode 100644 index 0b1e3090f2..0000000000 --- a/cpp/include/raft/util/inline.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2023, NVIDIA CORPORATION. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 - -// The RAFT_INLINE_CONDITIONAL is a conditional inline specifier that removes -// the inline specification when RAFT_COMPILED is defined. -// -// When RAFT_COMPILED is not defined, functions may be defined in multiple -// translation units and we do not want that to lead to linker errors. -// -// When RAFT_COMPILED is defined, this serves two purposes: -// -// 1. It triggers a multiple definition error message when memory_pool-inl.hpp -// (for instance) is accidentally included in multiple translation units. -// -// 2. We function definitions to be non-inline, because non-inline functions -// symbols are always exported in the object symbol table. For inline functions, -// the compiler may elide the external symbol, which results in linker errors. -#ifdef RAFT_COMPILED -#define RAFT_INLINE_CONDITIONAL -#else -#define RAFT_INLINE_CONDITIONAL inline -#endif // RAFT_COMPILED diff --git a/cpp/include/raft/util/memory_pool-inl.hpp b/cpp/include/raft/util/memory_pool-inl.hpp index 7968779e3d..a227b6e53f 100644 --- a/cpp/include/raft/util/memory_pool-inl.hpp +++ b/cpp/include/raft/util/memory_pool-inl.hpp @@ -18,7 +18,7 @@ #include #include -#include // RAFT_INLINE_CONDITIONAL +#include // RAFT_INLINE_CONDITIONAL #include #include #include