[llvm] [offload] Add `dlwrap::loaded` function to check for optional symbols (PR #210737)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 20 08:16:20 PDT 2026
https://github.com/blazej-smorawski created https://github.com/llvm/llvm-project/pull/210737
This PR adds a new template into `dlwrap` namespace that can be used to check if a symbol was correctly loaded. It adds and easy way to see if version of shared object in a system has required capability. We could use it to improve prefetch in CUDA backend as noted [here](https://github.com/llvm/llvm-project/blob/main/offload/plugins-nextgen/cuda/src/rtl.cpp#L912) without breaking compatibility with older platforms using CUDA older than 13.
In the case of prefetch, the new `dlwrap` API could be used like:
```cpp
bool BatchedPrefetchAvailable = dlwrap::loaded<cuMemPrefetchBatchAsync>();
if (BatchedPrefetchAvailable)
cuMemPrefetchAsync(....)
else
// Current implementation
```
Small note, to implement the prefetch we will also have to make loading of the symbols optional inside plugins too. This would require to change it [here](https://github.com/llvm/llvm-project/blob/main/offload/plugins-nextgen/cuda/dynamic_cuda/cuda.cpp#L176), but I think that the change can be a part of a PR that implements prefetch.
>From b56f231c699b16a59a35035b020a5dbcdd257b30 Mon Sep 17 00:00:00 2001
From: blazej-smorawski <blazej.smorawski at intel.com>
Date: Fri, 3 Jul 2026 13:48:27 +0200
Subject: [PATCH] [offload] Add `dlwrap::loaded` function to check for optional
symbols
---
offload/plugins-nextgen/common/include/DLWrap.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/offload/plugins-nextgen/common/include/DLWrap.h b/offload/plugins-nextgen/common/include/DLWrap.h
index 95ce86e123cd3..116cd4afe37a6 100644
--- a/offload/plugins-nextgen/common/include/DLWrap.h
+++ b/offload/plugins-nextgen/common/include/DLWrap.h
@@ -135,6 +135,8 @@ template <size_t Requested, size_t Required> constexpr void verboseAssert() {
static_assert(Requested == Required, "Arity Error");
}
+template <auto Fn> bool loaded();
+
} // namespace dlwrap
#define DLWRAP_INSTANTIATE(SYM_DEF, SYM_USE, ARITY) \
@@ -167,6 +169,9 @@ template <size_t Requested, size_t Required> constexpr void verboseAssert() {
return reinterpret_cast<T::FunctionType>(P); \
} \
}; \
+ template <> bool loaded<&(::SYMBOL)>() { \
+ return SYMBOL##_Trait::get() != nullptr; \
+ } \
}
#define DLWRAP_IMPL(SYMBOL, ARITY) \
More information about the llvm-commits
mailing list