[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:17:25 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-offload
Author: blazej-smorawski
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/210737.diff
1 Files Affected:
- (modified) offload/plugins-nextgen/common/include/DLWrap.h (+5)
``````````diff
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) \
``````````
</details>
https://github.com/llvm/llvm-project/pull/210737
More information about the llvm-commits
mailing list