[llvm] [libsycl] USM Aligned allocation functions (PR #213468)

Kseniya Tikhomirova via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 04:50:08 PDT 2026


================
@@ -115,10 +168,53 @@ int main() {
           [&]() { return Malloc(q, usm::alloc::host, property_list{}); },
           [&]() { return Malloc(d, ctx, usm::alloc::host, property_list{}); }});
 
+  auto AMalloc = [&](auto... args) {
+    return aligned_alloc(Align, 1024, args...);
+  };
+
+  CheckAll(
+      Align,
+      std::tuple{
+          [&]() { return AMalloc(q, usm::alloc::host); },
+          [&]() { return AMalloc(d, ctx, usm::alloc::host); },
+          [&]() { return AMalloc(q, usm::alloc::host, property_list{}); },
+          [&]() { return AMalloc(d, ctx, usm::alloc::host, property_list{}); },
+      });
+
   auto TMalloc = [&](auto... args) { return malloc<Aligned>(1, args...); };
   CheckAll(Align,
            std::tuple{[&]() { return TMalloc(q, usm::alloc::host); },
                       [&]() { return TMalloc(d, ctx, usm::alloc::host); }});
 
+  auto TAMalloc = [&](auto... args) {
+    return aligned_alloc<Aligned>(Align, 1, args...);
+  };
+
+  CheckAll(Align,
+           std::tuple{[&]() { return TAMalloc(q, usm::alloc::host); },
+                      [&]() { return TAMalloc(d, ctx, usm::alloc::host); }});
+
+  // Testing invalid arguments for alignment
+  assert(aligned_alloc_device(3, 1024, q) == nullptr);
+  assert(aligned_alloc_host(3, 1024, q) == nullptr);
+  if (d.has(aspect::usm_shared_allocations))
----------------
KseniyaTikhomirova wrote:

nit: just curious, why is it checked for shared allocation only?
we have aspect for any kind of allocation.
[usm_device_allocations,
 usm_host_allocations,](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:device-aspects)

please align, either add all checks or remove all. 

P.S. these aspects are true by default since liboffload is expected to always support USM (and it won't have cl_mem analog) so it doesn't even have query for these aspects. So functionally these checks does nothing here, but in terms of correct SYCL2020 usage it makes sense to check this. It is just a test -  I am ok with both options. So how to update this test is up to you.



https://github.com/llvm/llvm-project/pull/213468


More information about the llvm-commits mailing list