[llvm] [libsycl] add USM alloc/free functions (PR #184111)
Sergey Semenov via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 5 09:57:36 PST 2026
================
@@ -0,0 +1,124 @@
+// REQUIRES: any-device
+// RUN: %clangxx %sycl_options %s -o %t.out
+// RUN: %t.out
+
+#include <sycl/sycl.hpp>
+
+#include <cstddef>
+#include <iostream>
+#include <tuple>
+
+using namespace sycl;
+
+constexpr size_t Align = 256;
+
+struct alignas(Align) Aligned {
+ int x;
+};
+
+int main() {
+ queue q;
+ context ctx = q.get_context();
+ device d = q.get_device();
+
+ auto check = [&q](size_t Alignment, auto AllocFn, int Line = __builtin_LINE(),
+ int Case = 0) {
+ // First allocation might naturally be over-aligned. Do several of them to
+ // do the verification;
+ decltype(AllocFn()) Arr[10];
+ for (auto *&Elem : Arr)
+ Elem = AllocFn();
+ for (auto *Ptr : Arr) {
+ auto v = reinterpret_cast<uintptr_t>(Ptr);
+ if ((v & (Alignment - 1)) != 0) {
+ std::cout << "Failed at line " << Line << ", case " << Case
+ << std::endl;
+ assert(false && "Not properly aligned!");
+ break; // To be used with commented out assert above.
+ }
+ }
+ for (auto *Ptr : Arr)
+ free(Ptr, q);
+ };
+
+ // The strictest (largest) fundamental alignment of any type is the alignment
+ // of max_align_t. This is, however, smaller than the minimal alignment
+ // returned by the underlyging runtime as of now.
----------------
sergey-semenov wrote:
```suggestion
// returned by the underlying runtime as of now.
```
https://github.com/llvm/llvm-project/pull/184111
More information about the llvm-commits
mailing list