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

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


================
@@ -371,4 +371,35 @@ void mock::MockLiboffload::initDefault() {
     mock::releaseDummyHandle(Address);
     return OL_SUCCESS;
   });
+
+  ON_CALL(*this, olMemAllocAligned)
+      .WillByDefault([this](ol_device_handle_t Device,
+                            ol_alloc_type_t AllocType, size_t Size,
+                            size_t Alignment,
+                            void **AllocationOut) -> ol_result_t {
+        EXPECT_NE(Device, nullptr);
+        EXPECT_TRUE(AllocType == OL_ALLOC_TYPE_DEVICE ||
+                    AllocType == OL_ALLOC_TYPE_MANAGED);
+        EXPECT_GT(Size, 0);
+        EXPECT_GT(Alignment, 0);
+        EXPECT_EQ(Alignment & (Alignment - 1), 0);
----------------
KseniyaTikhomirova wrote:

incorrect. we set EXPECT_* here for guarantees given by SYCL runtime. It doesn't fully correlate to the expectations of liboffload. 
For example, Size == 0 may be a valid value for liboffload to allocate or to throw an exception, that means that it is ok to pass this value to this call but we check here that it is not 0 because we expect runtime to handle that case without calling olMemAllocAligned. So if we see a call to this function with Size == 0 this is definitely a RT bug.
For alignment - we allow liboffload to check correctness that means that SYCL RT can pass uneven value to liboffload and it would be a valid SYCL RT behavior.

Please replace EXPECT_EQ for Alignment with returning an error.

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


More information about the llvm-commits mailing list