Skip to content

Commit

Permalink
Visibility of static class methods (#492)
Browse files Browse the repository at this point in the history
We need to export static class methods that returns a reference to a static variable like we do with inline functions: #442

Authors:
  - Mads R. B. Kristensen (https://github.com/madsbk)

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #492
  • Loading branch information
madsbk authored Oct 7, 2024
1 parent 473e537 commit 2bd6bb4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cpp/include/kvikio/bounce_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class AllocRetain {
return _clear();
}

static AllocRetain& instance()
KVIKIO_EXPORT static AllocRetain& instance()
{
static AllocRetain _instance;
return _instance;
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/defaults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class defaults {
}
}

static defaults* instance()
KVIKIO_EXPORT static defaults* instance()
{
static defaults _instance;
return &_instance;
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/posix_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class StreamsByThread {
// cuDevicePrimaryCtxReset() or cudaDeviceReset() before program termination.
~StreamsByThread() = default;

static CUstream get(CUcontext ctx, std::thread::id thd_id)
KVIKIO_EXPORT static CUstream get(CUcontext ctx, std::thread::id thd_id)
{
static StreamsByThread _instance;

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/shim/cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class cudaAPI {
cudaAPI(cudaAPI const&) = delete;
void operator=(cudaAPI const&) = delete;

static cudaAPI& instance()
KVIKIO_EXPORT static cudaAPI& instance()
{
static cudaAPI _instance;
return _instance;
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/shim/cufile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class cuFileAPI {
cuFileAPI(cuFileAPI const&&) = delete;
void operator=(cuFileAPI const&&) = delete;

static cuFileAPI& instance()
KVIKIO_EXPORT static cuFileAPI& instance()
{
static cuFileAPI _instance;
return _instance;
Expand Down
17 changes: 16 additions & 1 deletion cpp/include/kvikio/shim/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023, NVIDIA CORPORATION.
* Copyright (c) 2021-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 @@ -23,6 +23,21 @@

namespace kvikio {

// Macros used for defining symbol visibility.
// Since KvikIO is header-only, we rely on the linker to disambiguate inline functions
// and static methods that have (or return) static references. To do this, the relevant
// function/method must have `__attribute__((visibility("default")))`. If not, then if
// KvikIO is used in two different DSOs, the function will appear twice, and there will
// be two static objects.
// See <https://gcc.gnu.org/wiki/Visibility> and <https://github.com/rapidsai/kvikio/issues/442>.
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__MINGW32__) && !defined(__MINGW64__)
#define KVIKIO_EXPORT __attribute__((visibility("default")))
#define KVIKIO_HIDDEN __attribute__((visibility("hidden")))
#else
#define KVIKIO_EXPORT
#define KVIKIO_HIDDEN
#endif

#define KVIKIO_STRINGIFY_DETAIL(x) #x
#define KVIKIO_STRINGIFY(x) KVIKIO_STRINGIFY_DETAIL(x)

Expand Down
14 changes: 0 additions & 14 deletions cpp/include/kvikio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@
#include <kvikio/error.hpp>
#include <kvikio/shim/cuda.hpp>

// Macros used for defining symbol visibility, only GLIBC is supported.
// Since KvikIO is header-only, we rely on the linker to disambiguate inline functions
// that have (or return) static references. To do this, the relevant function must have
// `__attribute__((visibility("default")))`. If not, then if KvikIO is used in two
// different DSOs, the function will appear twice, and there will be two static objects.
// See <https://github.com/rapidsai/kvikio/issues/442>.
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__MINGW32__) && !defined(__MINGW64__)
#define KVIKIO_EXPORT __attribute__((visibility("default")))
#define KVIKIO_HIDDEN __attribute__((visibility("hidden")))
#else
#define KVIKIO_EXPORT
#define KVIKIO_HIDDEN
#endif

namespace kvikio {

// cuFile defines a page size to 4 KiB
Expand Down

0 comments on commit 2bd6bb4

Please sign in to comment.