Skip to content

Commit

Permalink
Define RAFT_WEAK_FUNCTION
Browse files Browse the repository at this point in the history
  • Loading branch information
ahendriksen committed Apr 27, 2023
1 parent 7cdef04 commit 0368286
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions cpp/include/raft/core/detail/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@
#define RAFT_INLINE_CONDITIONAL inline
#endif // RAFT_COMPILED

// The RAFT_WEAK_FUNCTION specificies that:
//
// 1. A function may be defined in multiple translation units (like inline)
//
// 2. Must still emit an external symbol (unlike inline). This enables declaring
// a function signature in an `-ext` header and defining it in a source file.
//
// From
// https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes:
//
// "The weak attribute causes a declaration of an external symbol to be emitted
// as a weak symbol rather than a global."
#define RAFT_WEAK_FUNCTION __attribute__((weak))

/**
* Some macro magic to remove optional parentheses of a macro argument.
* See https://stackoverflow.com/a/62984543
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include <cuda_fp16.h> // __half
#include <raft/core/detail/macros.hpp> // RAFT_WEAK_FUNCTION
#include <raft/distance/distance_types.hpp> // raft::distance::DistanceType
#include <raft/neighbors/detail/ivf_pq_fp_8bit.cuh> // raft::neighbors::ivf_pq::detail::fp_8bit
#include <raft/neighbors/ivf_pq_types.hpp> // raft::neighbors::ivf_pq::codebook_gen
Expand All @@ -30,7 +31,8 @@ namespace raft::neighbors::ivf_pq::detail {
// is_local_topk_feasible is not inline here, because we would have to define it
// here as well. That would run the risk of the definitions here and in the
// -inl.cuh header diverging.
auto is_local_topk_feasible(uint32_t k, uint32_t n_probes, uint32_t n_queries) -> bool;
auto RAFT_WEAK_FUNCTION is_local_topk_feasible(uint32_t k, uint32_t n_probes, uint32_t n_queries)
-> bool;

template <typename OutT,
typename LutT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static_assert((kMaxCapacity >= 32) && !(kMaxCapacity & (kMaxCapacity - 1)),
"kMaxCapacity must be a power of two, not smaller than the WarpSize.");

// using weak attribute here, because it may be compiled multiple times.
auto __attribute__((weak)) is_local_topk_feasible(uint32_t k, uint32_t n_probes, uint32_t n_queries)
auto RAFT_WEAK_FUNCTION is_local_topk_feasible(uint32_t k, uint32_t n_probes, uint32_t n_queries)
-> bool
{
if (k > kMaxCapacity) { return false; } // warp_sort not possible
Expand Down

0 comments on commit 0368286

Please sign in to comment.