[llvm] [libsycl] Implement USM fill & memset queue API (PR #217933)
Sergey Semenov via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 15 05:10:50 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);
----------------
sergey-semenov wrote:
I think I'd prefer the simplicity of the current version over moving the deallocation to outside the function or introducing wrappers here. I added a comment that makes this transfer of ownership explicit though.
https://github.com/llvm/llvm-project/pull/217933
More information about the llvm-commits
mailing list