Skip to content

Commit

Permalink
Inline functions that return static references must have default visi…
Browse files Browse the repository at this point in the history
…bility

In rapidsai#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 rapidsai#1651
  • Loading branch information
wence- committed Aug 20, 2024
1 parent 43d01db commit d76d30d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions include/rmm/logger.hpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,6 +16,8 @@

#pragma once

#include <rmm/detail/export.hpp>

#include <fmt/format.h>
#include <fmt/ostream.h>
#include <spdlog/sinks/basic_file_sink.h>
Expand Down Expand Up @@ -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_;
Expand Down
11 changes: 8 additions & 3 deletions include/rmm/mr/device/per_device_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,20 @@ 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.
*
* Returns a global instance of a `cuda_memory_resource` as a function local static.
*
* @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;
Expand All @@ -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}
*/
Expand Down

0 comments on commit d76d30d

Please sign in to comment.