From d76d30de59756bc8560b908a8e861b308751d9e9 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Tue, 20 Aug 2024 15:36:00 +0000 Subject: [PATCH] Inline functions that return static references must have default visibility In #833, we gave `rmm::mr::detail::get_map` default visibility. However, there are a number of other functions that return static references that should also have this visibility so that the static reference is unique across multiple DSOs. - Closes #1651 --- include/rmm/logger.hpp | 6 ++++-- include/rmm/mr/device/per_device_resource.hpp | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/rmm/logger.hpp b/include/rmm/logger.hpp index 6213221ab..f4c7db7cd 100644 --- a/include/rmm/logger.hpp +++ b/include/rmm/logger.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ #pragma once +#include + #include #include #include @@ -105,7 +107,7 @@ struct bytes { * * @return spdlog::logger& The logger. */ -inline spdlog::logger& logger() +RMM_EXPORT inline spdlog::logger& logger() { static detail::logger_wrapper wrapped{}; return wrapped.logger_; diff --git a/include/rmm/mr/device/per_device_resource.hpp b/include/rmm/mr/device/per_device_resource.hpp index a56a784a1..5201b6549 100644 --- a/include/rmm/mr/device/per_device_resource.hpp +++ b/include/rmm/mr/device/per_device_resource.hpp @@ -89,6 +89,12 @@ namespace rmm::mr { namespace detail { +// These symbols must have default visibility so that when they are +// referenced in multiple different DSOs the linker correctly +// determines that there is only a single unique reference to the +// function symbols (and hence they return unique static references +// across different DSOs). +// See also https://github.com/rapidsai/rmm/issues/826 /** * @brief Returns a pointer to the initial resource. * @@ -96,7 +102,7 @@ namespace detail { * * @return Pointer to the static cuda_memory_resource used as the initial, default resource */ -inline device_memory_resource* initial_resource() +RMM_EXPORT inline device_memory_resource* initial_resource() { static cuda_memory_resource mr{}; return &mr; @@ -105,13 +111,12 @@ inline device_memory_resource* initial_resource() /** * @briefreturn{Reference to the lock} */ -inline std::mutex& map_lock() +RMM_EXPORT inline std::mutex& map_lock() { static std::mutex map_lock; return map_lock; } -// This symbol must have default visibility, see: https://github.com/rapidsai/rmm/issues/826 /** * @briefreturn{Reference to the map from device id -> resource} */