[llvm] [libsycl] Implement USM fill & memset queue API (PR #217933)

Kseniya Tikhomirova via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 06:55:59 PDT 2026


================
@@ -0,0 +1,38 @@
+#include <sycl/sycl.hpp>
+
+#include <cassert>
+
+constexpr std::size_t DataSize = 1024;
+
+template <typename DataT> bool verify(DataT *Ptr, int Pattern) {
+  for (std::size_t I = 0; I < DataSize; ++I)
+    if (Ptr[I] != static_cast<DataT>(Pattern))
+      return false;
+  return true;
+}
+
+template <bool VerifyOnDevice, typename DataT, typename OpT>
+void test(sycl::queue &Q, DataT *Ptr, OpT Op, int Pattern) {
+  Op(Ptr, Pattern);
+  Q.wait();
+
+  if constexpr (VerifyOnDevice) {
+    bool *Result = sycl::malloc_shared<bool>(1, Q);
+    Q.single_task<class Verify>([=]() { *Result = verify(Ptr, Pattern); });
+    Q.wait();
+    assert(*Result);
+    sycl::free(Result, Q);
+  } else {
+    assert(verify(Ptr, Pattern));
+  }
+  sycl::free(Ptr, Q);
----------------
KseniyaTikhomirova wrote:

it looks like something that doesn't belong to this function. pointer is allocated outside this call and it would be better to deallocate there as well. or move allocation inside

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


More information about the llvm-commits mailing list