[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:08:21 PDT 2026


https://github.com/sergey-semenov updated https://github.com/llvm/llvm-project/pull/217933

>From dde5424a48bdb96e7f3f2c780747f91f0e9389ab Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Fri, 21 Aug 2026 05:57:50 -0700
Subject: [PATCH 01/11] [libsycl] Implement fill & memset queue API

---
 libsycl/include/sycl/__impl/queue.hpp  | 93 ++++++++++++++++++++++++++
 libsycl/src/detail/queue_impl.cpp      | 22 +++++-
 libsycl/src/detail/queue_impl.hpp      | 11 +++
 libsycl/src/queue.cpp                  |  8 +++
 libsycl/test/usm/fill.cpp              | 10 +++
 libsycl/test/usm/memset.cpp            | 11 +++
 libsycl/unittests/mock/helpers.cpp     | 14 ++++
 libsycl/unittests/mock/helpers.hpp     |  3 +
 libsycl/unittests/mock/mock.cpp        |  6 ++
 libsycl/unittests/queue/CMakeLists.txt |  4 +-
 libsycl/unittests/queue/fill.cpp       | 38 +++++++++++
 libsycl/unittests/queue/memset.cpp     | 37 ++++++++++
 12 files changed, 255 insertions(+), 2 deletions(-)
 create mode 100644 libsycl/test/usm/fill.cpp
 create mode 100644 libsycl/test/usm/memset.cpp
 create mode 100644 libsycl/unittests/queue/fill.cpp
 create mode 100644 libsycl/unittests/queue/memset.cpp

diff --git a/libsycl/include/sycl/__impl/queue.hpp b/libsycl/include/sycl/__impl/queue.hpp
index bd6613e95324b..46e7d726fbebc 100644
--- a/libsycl/include/sycl/__impl/queue.hpp
+++ b/libsycl/include/sycl/__impl/queue.hpp
@@ -413,6 +413,87 @@ class _LIBSYCL_EXPORT queue {
   event memcpy(void *dest, const void *src, std::size_t numBytes,
                const std::vector<event> &depEvents);
 
+  /// Submits a memset operation for USM accessible on the device associated
+  /// with the queue. Equivalent to a fill operation with an unsigned char
+  /// pattern.
+  ///
+  /// \param ptr is the pointer to memory to be set.
+  /// \param value is the value the memory should be filled with, interpreted
+  /// as an unsigned char.
+  /// \param numBytes is the number of bytes to set.
+  event memset(void *ptr, int value, std::size_t numBytes) {
+    return memset(ptr, value, numBytes, std::vector<event>{});
+  }
+
+  /// Submits a memset operation for USM accessible on the device associated
+  /// with the queue. Equivalent to a fill operation with an unsigned char
+  /// pattern.
+  ///
+  /// \param ptr is the pointer to memory to be set.
+  /// \param value is the value the memory should be filled with, interpreted
+  /// as an unsigned char.
+  /// \param numBytes is the number of bytes to set.
+  /// \param depEvent is an event that represents a dependency for the
+  /// operation.
+  event memset(void *ptr, int value, std::size_t numBytes, event depEvent) {
+    return memset(ptr, value, numBytes, std::vector<event>{depEvent});
+  }
+
+  /// Submits a memset operation for USM accessible on the device associated
+  /// with the queue. Equivalent to a fill operation with an unsigned char
+  /// pattern.
+  ///
+  /// \param ptr is the pointer to memory to be set.
+  /// \param value is the value the memory should be filled with, interpreted
+  /// as an unsigned char.
+  /// \param numBytes is the number of bytes to set.
+  /// \param depEvents is a vector of events that represent dependencies for the
+  /// operation.
+  event memset(void *ptr, int value, std::size_t numBytes,
+               const std::vector<event> &depEvents) {
+    return fill(ptr, static_cast<unsigned char>(value), numBytes, depEvents);
+  }
+
+  /// Submits a fill operation that replicates a pattern into USM accessible
+  /// on the device associated with the queue.
+  ///
+  /// \param ptr is the pointer to memory to be filled.
+  /// \param pattern is the pattern to be replicated.
+  /// \param count is the number of times the pattern is filled.
+  /// \param depEvents is a vector of events that represent dependencies for the
+  /// operation.
+  template <typename T>
+  event fill(void *ptr, const T &pattern, std::size_t count) {
+    return fill(ptr, pattern, count, std::vector<event>{});
+  }
+
+  /// Submits a fill operation that replicates a pattern into USM accessible
+  /// on the device associated with the queue.
+  ///
+  /// \param ptr is the pointer to memory to be filled.
+  /// \param pattern is the pattern to be replicated.
+  /// \param count is the number of times the pattern is filled.
+  /// \param depEvent is an event that represents a dependency for the
+  /// operation.
+  template <typename T>
+  event fill(void *ptr, const T &pattern, std::size_t count, event depEvent) {
+    return fill(ptr, pattern, count, std::vector<event>{depEvent});
+  }
+
+  /// Submits a fill operation that replicates a pattern into USM accessible
+  /// on the device associated with the queue.
+  ///
+  /// \param ptr is the pointer to memory to be filled.
+  /// \param pattern is the pattern to be replicated.
+  /// \param count is the number of times the pattern is filled.
+  /// \param depEvents is a vector of events that represent dependencies for the
+  /// operation.
+  template <typename T>
+  event fill(void *ptr, const T &pattern, std::size_t count,
+             const std::vector<event> &depEvents) {
+    return fillImpl(ptr, &pattern, sizeof(T), count, depEvents);
+  }
+
   /// Provides hints to the runtime library that data can be made available
   /// on a device earlier than Unified Shared Memory would normally require it
   /// to be available.
@@ -560,6 +641,18 @@ class _LIBSYCL_EXPORT queue {
   /// \return an event representing last kernel invocation.
   event getLastEvent();
 
+  /// Submits a fill operation that replicates a pattern into USM accessible
+  /// on the device associated with the queue.
+  ///
+  /// \param Ptr is the pointer to memory to be filled.
+  /// \param Pattern is the pattern to be replicated.
+  /// \param PatternSize is the size of the pattern in bytes.
+  /// \param Count is the number of times the pattern is filled.
+  /// \param DepEvents is a vector of events that represent dependencies for the
+  /// operation.
+  event fillImpl(void *Ptr, const void *Pattern, std::size_t PatternSize,
+                 std::size_t Count, const std::vector<event> &DepEvents);
+
   queue(const std::shared_ptr<detail::QueueImpl> &Impl) : impl(Impl) {}
   std::shared_ptr<detail::QueueImpl> impl;
 
diff --git a/libsycl/src/detail/queue_impl.cpp b/libsycl/src/detail/queue_impl.cpp
index e0700129c0fa5..bb39eaa4b5f84 100644
--- a/libsycl/src/detail/queue_impl.cpp
+++ b/libsycl/src/detail/queue_impl.cpp
@@ -194,6 +194,27 @@ QueueImpl::memcpy(void *Dest, const void *Src, std::size_t NumBytes,
   return createEvent();
 }
 
+EventImplPtr QueueImpl::fill(void *Ptr, const void *Pattern,
+                             std::size_t PatternSize, std::size_t Count,
+                             const std::vector<EventImplPtr> &DepEvents) {
+  assert(PatternSize > 0);
+  checkEventsPlatformMatch(DepEvents, MDevice.getPlatformImpl());
+  if (Count == 0) {
+    handleEventDependencies(DepEvents);
+    return createEvent();
+  }
+
+  if (!Ptr) {
+    throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
+                          "Nullptr argument in fill/memset operation");
+  }
+
+  handleEventDependencies(DepEvents);
+  callAndThrow(olMemFill, MOffloadQueue, Ptr, PatternSize, Pattern,
+               Count * PatternSize);
+  return createEvent();
+}
+
 EventImplPtr QueueImpl::prefetch(void *Ptr, std::size_t NumBytes,
                                  const std::vector<EventImplPtr> &DepEvents) {
   checkEventsPlatformMatch(DepEvents, MDevice.getPlatformImpl());
@@ -216,7 +237,6 @@ EventImplPtr QueueImpl::prefetch(void *Ptr, std::size_t NumBytes,
 
   handleEventDependencies(DepEvents);
   callAndThrow(olMemPrefetch, MOffloadQueue, Count, Mems, Sizes, Flag);
-
   return createEvent();
 }
 
diff --git a/libsycl/src/detail/queue_impl.hpp b/libsycl/src/detail/queue_impl.hpp
index c889a189a7ff4..069a211c2ec97 100644
--- a/libsycl/src/detail/queue_impl.hpp
+++ b/libsycl/src/detail/queue_impl.hpp
@@ -117,6 +117,17 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
   EventImplPtr memcpy(void *Dest, const void *Src, std::size_t NumBytes,
                       const std::vector<EventImplPtr> &DepEvents);
 
+  /// Submits a fill operation that replicates a pattern into USM.
+  ///
+  /// \param Ptr is the pointer to memory to be filled.
+  /// \param Pattern is the pattern to be replicated.
+  /// \param PatternSize is the size of the pattern.
+  /// \param Count is the number of times the pattern is filled.
+  /// \param DepEvents is a vector of dependencies for the operation.
+  EventImplPtr fill(void *Ptr, const void *Pattern, std::size_t PatternSize,
+                    std::size_t Count,
+                    const std::vector<EventImplPtr> &DepEvents);
+
   /// Submits a prefetch operation for a USM pointer.
   ///
   /// \param Ptr is a USM pointer to the memory to be prefetched to the device.
diff --git a/libsycl/src/queue.cpp b/libsycl/src/queue.cpp
index c257a09367f3f..36238609c12f9 100644
--- a/libsycl/src/queue.cpp
+++ b/libsycl/src/queue.cpp
@@ -69,4 +69,12 @@ void queue::submitKernelImpl(detail::DeviceKernelInfo &KernelInfo,
   impl->submitKernelImpl(KernelInfo, ArgData, ArgSize);
 }
 
+event queue::fillImpl(void *Ptr, const void *Pattern, std::size_t PatternSize,
+                      std::size_t Count, const std::vector<event> &DepEvents) {
+  std::shared_ptr<detail::EventImpl> EventImplPtr = impl->fill(
+      Ptr, Pattern, PatternSize, Count, detail::getSyclObjImpls(DepEvents));
+  assert(EventImplPtr);
+  return detail::createSyclObjFromImpl<event>(EventImplPtr);
+}
+
 _LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/test/usm/fill.cpp b/libsycl/test/usm/fill.cpp
new file mode 100644
index 0000000000000..9379013c91b55
--- /dev/null
+++ b/libsycl/test/usm/fill.cpp
@@ -0,0 +1,10 @@
+// REQUIRES: any-device
+// RUN: %clangxx -fsycl %s -o %t.out
+// RUN: %t.out
+
+#include "include/fill_memset_common.hpp"
+
+int main() {
+  queue Q;
+  runTests<int>(Q, [&](void *Ptr) { Q.fill(Ptr, Pattern, DataSize); });
+}
diff --git a/libsycl/test/usm/memset.cpp b/libsycl/test/usm/memset.cpp
new file mode 100644
index 0000000000000..4045b34b77564
--- /dev/null
+++ b/libsycl/test/usm/memset.cpp
@@ -0,0 +1,11 @@
+// REQUIRES: any-device
+// RUN: %clangxx -fsycl %s -o %t.out
+// RUN: %t.out
+
+#include "include/fill_memset_common.hpp"
+
+int main() {
+  queue Q;
+  runTests<unsigned char>(Q,
+                          [&](void *Ptr) { Q.memset(Ptr, Pattern, DataSize); });
+}
diff --git a/libsycl/unittests/mock/helpers.cpp b/libsycl/unittests/mock/helpers.cpp
index 2898b39daafad..1762e344219ed 100644
--- a/libsycl/unittests/mock/helpers.cpp
+++ b/libsycl/unittests/mock/helpers.cpp
@@ -308,6 +308,19 @@ void mock::MockLiboffload::initDefault() {
         EXPECT_NE(SrcDevice, nullptr);
         return OL_SUCCESS;
       });
+
+  ON_CALL(*this, olMemFill)
+      .WillByDefault([](ol_queue_handle_t Queue, void *Ptr, size_t PatternSize,
+                        const void *PatternPtr,
+                        size_t FillSize) -> ol_result_t {
+        EXPECT_NE(Queue, nullptr);
+        EXPECT_NE(Ptr, nullptr);
+        EXPECT_GT(PatternSize, 0);
+        EXPECT_NE(PatternPtr, nullptr);
+        EXPECT_GT(FillSize, 0);
+        return OL_SUCCESS;
+      });
+
   ON_CALL(*this, olMemPrefetch)
       .WillByDefault([this](ol_queue_handle_t Queue, size_t Count,
                             const void **Mems, const size_t *Sizes,
@@ -321,6 +334,7 @@ void mock::MockLiboffload::initDefault() {
         EXPECT_EQ(Flags, OL_MEM_MIGRATION_FLAG_HOST_TO_DEVICE);
         return OL_SUCCESS;
       });
+
   ON_CALL(*this, olGetMemInfo)
       .WillByDefault([this](const void *Ptr, ol_mem_info_t PropName,
                             size_t PropSize, void *PropValue) -> ol_result_t {
diff --git a/libsycl/unittests/mock/helpers.hpp b/libsycl/unittests/mock/helpers.hpp
index 50ff09b2b02c8..e29ed55b8c475 100644
--- a/libsycl/unittests/mock/helpers.hpp
+++ b/libsycl/unittests/mock/helpers.hpp
@@ -126,6 +126,9 @@ class MockLiboffload {
               (ol_queue_handle_t Queue, void *DstPtr,
                ol_device_handle_t DstDevice, const void *SrcPtr,
                ol_device_handle_t SrcDevice, size_t Size));
+  MOCK_METHOD(ol_result_t, olMemFill,
+              (ol_queue_handle_t Queue, void *Ptr, size_t PatternSize,
+               const void *PatternPtr, size_t FillSize));
   MOCK_METHOD(ol_result_t, olMemPrefetch,
               (ol_queue_handle_t Queue, size_t Count, const void **Mems,
                const size_t *Sizes, ol_mem_migration_flags_t Flags));
diff --git a/libsycl/unittests/mock/mock.cpp b/libsycl/unittests/mock/mock.cpp
index 551c14e568701..973150c25a7c9 100644
--- a/libsycl/unittests/mock/mock.cpp
+++ b/libsycl/unittests/mock/mock.cpp
@@ -117,6 +117,12 @@ ol_result_t olMemcpy(ol_queue_handle_t Queue, void *DstPtr,
                                             SrcDevice, Size);
 }
 
+ol_result_t olMemFill(ol_queue_handle_t Queue, void *Ptr, size_t PatternSize,
+                      const void *PatternPtr, size_t FillSize) {
+  return mock::getMockLiboffload().olMemFill(Queue, Ptr, PatternSize,
+                                             PatternPtr, FillSize);
+}
+
 ol_result_t olMemPrefetch(ol_queue_handle_t Queue, size_t Count,
                           const void **Mems, const size_t *Sizes,
                           ol_mem_migration_flags_t Flags) {
diff --git a/libsycl/unittests/queue/CMakeLists.txt b/libsycl/unittests/queue/CMakeLists.txt
index 418fd1789ca76..8a1adf625237c 100644
--- a/libsycl/unittests/queue/CMakeLists.txt
+++ b/libsycl/unittests/queue/CMakeLists.txt
@@ -1,6 +1,8 @@
 add_sycl_unittest(QueueTests
-    prefetch.cpp
+    fill.cpp
     memcpy.cpp
+    memset.cpp
+    prefetch.cpp
     queue.cpp
     sycl_kernel_launch.cpp
 )
diff --git a/libsycl/unittests/queue/fill.cpp b/libsycl/unittests/queue/fill.cpp
new file mode 100644
index 0000000000000..873b0bdb97486
--- /dev/null
+++ b/libsycl/unittests/queue/fill.cpp
@@ -0,0 +1,38 @@
+#include <mock/helpers.hpp>
+
+#include <sycl/__impl/queue.hpp>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using namespace sycl;
+using namespace ::testing;
+
+TEST(Queue, Fill) {
+  mock::MockWrapper Mock;
+  queue Q;
+
+  int a;
+  int *Ptr = &a;
+  int Pattern;
+  int *PatternPtr = &Pattern;
+  constexpr int FillCount = 32;
+  constexpr int FillBytes = FillCount * sizeof(int);
+
+  EXPECT_CALL(Mock.get(), olMemFill(_, Ptr, sizeof(int), PatternPtr, FillBytes))
+      .Times(3);
+  EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(2);
+  event E = Q.fill(Ptr, Pattern, FillCount);
+  Q.fill(Ptr, Pattern, FillCount, E);
+  Q.fill(Ptr, Pattern, FillCount, std::vector<event>{E});
+}
+
+TEST(Queue, FillZeroBytes) {
+  mock::MockWrapper Mock;
+  queue Q;
+  EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(2);
+  EXPECT_CALL(Mock.get(), olMemFill(_, _, _, _, _)).Times(0);
+  event E = Q.fill(nullptr, 1, 0);
+  Q.fill(nullptr, 1, 0, E);
+  Q.fill(nullptr, 1, 0, std::vector<event>{E});
+}
diff --git a/libsycl/unittests/queue/memset.cpp b/libsycl/unittests/queue/memset.cpp
new file mode 100644
index 0000000000000..7a6444811a85c
--- /dev/null
+++ b/libsycl/unittests/queue/memset.cpp
@@ -0,0 +1,37 @@
+#include <mock/helpers.hpp>
+
+#include <sycl/__impl/queue.hpp>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using namespace sycl;
+using namespace ::testing;
+
+TEST(Queue, Memset) {
+  mock::MockWrapper Mock;
+  queue Q;
+
+  int a;
+  int *Ptr = &a;
+  constexpr int FillCount = 32;
+  int Pattern = 42;
+
+  EXPECT_CALL(Mock.get(),
+              olMemFill(_, Ptr, sizeof(unsigned char), _, FillCount))
+      .Times(3);
+  EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(2);
+  event E = Q.memset(Ptr, Pattern, FillCount);
+  Q.memset(Ptr, Pattern, FillCount, E);
+  Q.memset(Ptr, Pattern, FillCount, std::vector<event>{E});
+}
+
+TEST(Queue, MemsetZeroBytes) {
+  mock::MockWrapper Mock;
+  queue Q;
+  EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(2);
+  EXPECT_CALL(Mock.get(), olMemFill(_, _, _, _, _)).Times(0);
+  event E = Q.memset(nullptr, 1, 0);
+  Q.memset(nullptr, 1, 0, E);
+  Q.memset(nullptr, 1, 0, std::vector<event>{E});
+}

>From 482d3dfb07b581c121d2293a69b3138101feb4e8 Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Thu, 3 Sep 2026 08:03:13 -0700
Subject: [PATCH 02/11] Apply comments

---
 libsycl/include/sycl/__impl/queue.hpp         |  8 +++-
 .../test/usm/include/fill_memset_common.hpp   | 42 +++++++++++++++++++
 libsycl/unittests/mock/helpers.cpp            |  1 +
 libsycl/unittests/queue/fill.cpp              | 21 ++++++----
 libsycl/unittests/queue/memset.cpp            |  8 ++++
 5 files changed, 71 insertions(+), 9 deletions(-)
 create mode 100644 libsycl/test/usm/include/fill_memset_common.hpp

diff --git a/libsycl/include/sycl/__impl/queue.hpp b/libsycl/include/sycl/__impl/queue.hpp
index 6ca7e18b7e9fa..c117fb5062581 100644
--- a/libsycl/include/sycl/__impl/queue.hpp
+++ b/libsycl/include/sycl/__impl/queue.hpp
@@ -450,6 +450,7 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
   /// \param value is the value the memory should be filled with, interpreted
   /// as an unsigned char.
   /// \param numBytes is the number of bytes to set.
+  /// \return an event that represents the status of the operation.
   event memset(void *ptr, int value, std::size_t numBytes) {
     return memset(ptr, value, numBytes, std::vector<event>{});
   }
@@ -464,6 +465,7 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
   /// \param numBytes is the number of bytes to set.
   /// \param depEvent is an event that represents a dependency for the
   /// operation.
+  /// \return an event that represents the status of the operation.
   event memset(void *ptr, int value, std::size_t numBytes, event depEvent) {
     return memset(ptr, value, numBytes, std::vector<event>{depEvent});
   }
@@ -478,6 +480,7 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
   /// \param numBytes is the number of bytes to set.
   /// \param depEvents is a vector of events that represent dependencies for the
   /// operation.
+  /// \return an event that represents the status of the operation.
   event memset(void *ptr, int value, std::size_t numBytes,
                const std::vector<event> &depEvents) {
     return fill(ptr, static_cast<unsigned char>(value), numBytes, depEvents);
@@ -489,8 +492,7 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
   /// \param ptr is the pointer to memory to be filled.
   /// \param pattern is the pattern to be replicated.
   /// \param count is the number of times the pattern is filled.
-  /// \param depEvents is a vector of events that represent dependencies for the
-  /// operation.
+  /// \return an event that represents the status of the operation.
   template <typename T>
   event fill(void *ptr, const T &pattern, std::size_t count) {
     return fill(ptr, pattern, count, std::vector<event>{});
@@ -504,6 +506,7 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
   /// \param count is the number of times the pattern is filled.
   /// \param depEvent is an event that represents a dependency for the
   /// operation.
+  /// \return an event that represents the status of the operation.
   template <typename T>
   event fill(void *ptr, const T &pattern, std::size_t count, event depEvent) {
     return fill(ptr, pattern, count, std::vector<event>{depEvent});
@@ -517,6 +520,7 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
   /// \param count is the number of times the pattern is filled.
   /// \param depEvents is a vector of events that represent dependencies for the
   /// operation.
+  /// \return an event that represents the status of the operation.
   template <typename T>
   event fill(void *ptr, const T &pattern, std::size_t count,
              const std::vector<event> &depEvents) {
diff --git a/libsycl/test/usm/include/fill_memset_common.hpp b/libsycl/test/usm/include/fill_memset_common.hpp
new file mode 100644
index 0000000000000..42bea7ad9cbf9
--- /dev/null
+++ b/libsycl/test/usm/include/fill_memset_common.hpp
@@ -0,0 +1,42 @@
+#include <sycl/sycl.hpp>
+
+#include <array>
+#include <cassert>
+
+using namespace sycl;
+
+constexpr std::size_t DataSize = 1024;
+constexpr int Pattern = 42;
+
+template <typename DataT> bool verify(DataT *Ptr) {
+  for (int I = 0; I < DataSize; ++I)
+    if (Ptr[I] != Pattern)
+      return false;
+  return true;
+}
+
+template <bool VerifyOnDevice, typename DataT, typename OpT>
+void test(queue &Q, DataT *Ptr, OpT Op) {
+  Op(Ptr);
+  Q.wait();
+
+  if constexpr (VerifyOnDevice) {
+    bool *Result = malloc_shared<bool>(1, Q);
+    Q.single_task<class Verify>([=]() { verify(Ptr); });
+    Q.wait();
+    assert(Result);
+    sycl::free(Result, Q);
+  } else {
+    Q.wait();
+    assert(verify(Ptr));
+  }
+  sycl::free(Ptr, Q);
+}
+
+template <typename DataT, typename OpT> void runTests(queue &Q, OpT Op) {
+  test<false>(Q, malloc_host<DataT>(1024, Q), Op);
+  test<true>(Q, malloc_host<DataT>(1024, Q), Op);
+  test<false>(Q, malloc_shared<DataT>(1024, Q), Op);
+  test<true>(Q, malloc_shared<DataT>(1024, Q), Op);
+  test<true>(Q, malloc_device<DataT>(1024, Q), Op);
+}
\ No newline at end of file
diff --git a/libsycl/unittests/mock/helpers.cpp b/libsycl/unittests/mock/helpers.cpp
index 58093052e6468..e45214a1d3215 100644
--- a/libsycl/unittests/mock/helpers.cpp
+++ b/libsycl/unittests/mock/helpers.cpp
@@ -315,6 +315,7 @@ void mock::MockLiboffload::initDefault() {
         EXPECT_GT(PatternSize, 0);
         EXPECT_NE(PatternPtr, nullptr);
         EXPECT_GT(FillSize, 0);
+        EXPECT_EQ(FillSize % PatternSize, 0);
         return OL_SUCCESS;
       });
 
diff --git a/libsycl/unittests/queue/fill.cpp b/libsycl/unittests/queue/fill.cpp
index 873b0bdb97486..d41785def7026 100644
--- a/libsycl/unittests/queue/fill.cpp
+++ b/libsycl/unittests/queue/fill.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
 #include <mock/helpers.hpp>
 
 #include <sycl/__impl/queue.hpp>
@@ -5,12 +13,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
-using namespace sycl;
 using namespace ::testing;
 
 TEST(Queue, Fill) {
   mock::MockWrapper Mock;
-  queue Q;
+  sycl::queue Q;
 
   int a;
   int *Ptr = &a;
@@ -22,17 +29,17 @@ TEST(Queue, Fill) {
   EXPECT_CALL(Mock.get(), olMemFill(_, Ptr, sizeof(int), PatternPtr, FillBytes))
       .Times(3);
   EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(2);
-  event E = Q.fill(Ptr, Pattern, FillCount);
+  sycl::event E = Q.fill(Ptr, Pattern, FillCount);
   Q.fill(Ptr, Pattern, FillCount, E);
-  Q.fill(Ptr, Pattern, FillCount, std::vector<event>{E});
+  Q.fill(Ptr, Pattern, FillCount, std::vector<sycl::event>{E});
 }
 
 TEST(Queue, FillZeroBytes) {
   mock::MockWrapper Mock;
-  queue Q;
+  sycl::queue Q;
   EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(2);
   EXPECT_CALL(Mock.get(), olMemFill(_, _, _, _, _)).Times(0);
-  event E = Q.fill(nullptr, 1, 0);
+  sycl::event E = Q.fill(nullptr, 1, 0);
   Q.fill(nullptr, 1, 0, E);
-  Q.fill(nullptr, 1, 0, std::vector<event>{E});
+  Q.fill(nullptr, 1, 0, std::vector<sycl::event>{E});
 }
diff --git a/libsycl/unittests/queue/memset.cpp b/libsycl/unittests/queue/memset.cpp
index 7a6444811a85c..9b510eb894f0b 100644
--- a/libsycl/unittests/queue/memset.cpp
+++ b/libsycl/unittests/queue/memset.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
 #include <mock/helpers.hpp>
 
 #include <sycl/__impl/queue.hpp>

>From 7e9ab9b85bf13a1879b1e23fa01a170dfbbc560d Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Thu, 3 Sep 2026 09:56:47 -0700
Subject: [PATCH 03/11] Apply another one

---
 libsycl/unittests/queue/memset.cpp | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libsycl/unittests/queue/memset.cpp b/libsycl/unittests/queue/memset.cpp
index 9b510eb894f0b..0f049d2b8679b 100644
--- a/libsycl/unittests/queue/memset.cpp
+++ b/libsycl/unittests/queue/memset.cpp
@@ -13,12 +13,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
-using namespace sycl;
 using namespace ::testing;
 
 TEST(Queue, Memset) {
   mock::MockWrapper Mock;
-  queue Q;
+  sycl::queue Q;
 
   int a;
   int *Ptr = &a;
@@ -29,17 +28,17 @@ TEST(Queue, Memset) {
               olMemFill(_, Ptr, sizeof(unsigned char), _, FillCount))
       .Times(3);
   EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(2);
-  event E = Q.memset(Ptr, Pattern, FillCount);
+  sycl::event E = Q.memset(Ptr, Pattern, FillCount);
   Q.memset(Ptr, Pattern, FillCount, E);
-  Q.memset(Ptr, Pattern, FillCount, std::vector<event>{E});
+  Q.memset(Ptr, Pattern, FillCount, std::vector<sycl::event>{E});
 }
 
 TEST(Queue, MemsetZeroBytes) {
   mock::MockWrapper Mock;
-  queue Q;
+  sycl::queue Q;
   EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(2);
   EXPECT_CALL(Mock.get(), olMemFill(_, _, _, _, _)).Times(0);
-  event E = Q.memset(nullptr, 1, 0);
+  sycl::event E = Q.memset(nullptr, 1, 0);
   Q.memset(nullptr, 1, 0, E);
-  Q.memset(nullptr, 1, 0, std::vector<event>{E});
+  Q.memset(nullptr, 1, 0, std::vector<sycl::event>{E});
 }

>From 4a04c87145e4aab05cd6f77713156a47030a2805 Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Thu, 3 Sep 2026 09:58:29 -0700
Subject: [PATCH 04/11] Add newline at EOF

---
 libsycl/test/usm/include/fill_memset_common.hpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libsycl/test/usm/include/fill_memset_common.hpp b/libsycl/test/usm/include/fill_memset_common.hpp
index 42bea7ad9cbf9..64b22129321d3 100644
--- a/libsycl/test/usm/include/fill_memset_common.hpp
+++ b/libsycl/test/usm/include/fill_memset_common.hpp
@@ -39,4 +39,4 @@ template <typename DataT, typename OpT> void runTests(queue &Q, OpT Op) {
   test<false>(Q, malloc_shared<DataT>(1024, Q), Op);
   test<true>(Q, malloc_shared<DataT>(1024, Q), Op);
   test<true>(Q, malloc_device<DataT>(1024, Q), Op);
-}
\ No newline at end of file
+}

>From d857b9d3ef08fa4ec22fa11536e6c6db82e36348 Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Thu, 3 Sep 2026 10:08:33 -0700
Subject: [PATCH 05/11] Drop using namespace sycl from lit test

---
 libsycl/test/usm/fill.cpp                      |  2 +-
 .../test/usm/include/fill_memset_common.hpp    | 18 ++++++++----------
 libsycl/test/usm/memset.cpp                    |  2 +-
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/libsycl/test/usm/fill.cpp b/libsycl/test/usm/fill.cpp
index 9379013c91b55..7313c2f194616 100644
--- a/libsycl/test/usm/fill.cpp
+++ b/libsycl/test/usm/fill.cpp
@@ -5,6 +5,6 @@
 #include "include/fill_memset_common.hpp"
 
 int main() {
-  queue Q;
+  sycl::queue Q;
   runTests<int>(Q, [&](void *Ptr) { Q.fill(Ptr, Pattern, DataSize); });
 }
diff --git a/libsycl/test/usm/include/fill_memset_common.hpp b/libsycl/test/usm/include/fill_memset_common.hpp
index 64b22129321d3..bbab779e1aaa1 100644
--- a/libsycl/test/usm/include/fill_memset_common.hpp
+++ b/libsycl/test/usm/include/fill_memset_common.hpp
@@ -3,8 +3,6 @@
 #include <array>
 #include <cassert>
 
-using namespace sycl;
-
 constexpr std::size_t DataSize = 1024;
 constexpr int Pattern = 42;
 
@@ -16,12 +14,12 @@ template <typename DataT> bool verify(DataT *Ptr) {
 }
 
 template <bool VerifyOnDevice, typename DataT, typename OpT>
-void test(queue &Q, DataT *Ptr, OpT Op) {
+void test(sycl::queue &Q, DataT *Ptr, OpT Op) {
   Op(Ptr);
   Q.wait();
 
   if constexpr (VerifyOnDevice) {
-    bool *Result = malloc_shared<bool>(1, Q);
+    bool *Result = sycl::malloc_shared<bool>(1, Q);
     Q.single_task<class Verify>([=]() { verify(Ptr); });
     Q.wait();
     assert(Result);
@@ -33,10 +31,10 @@ void test(queue &Q, DataT *Ptr, OpT Op) {
   sycl::free(Ptr, Q);
 }
 
-template <typename DataT, typename OpT> void runTests(queue &Q, OpT Op) {
-  test<false>(Q, malloc_host<DataT>(1024, Q), Op);
-  test<true>(Q, malloc_host<DataT>(1024, Q), Op);
-  test<false>(Q, malloc_shared<DataT>(1024, Q), Op);
-  test<true>(Q, malloc_shared<DataT>(1024, Q), Op);
-  test<true>(Q, malloc_device<DataT>(1024, Q), Op);
+template <typename DataT, typename OpT> void runTests(sycl::queue &Q, OpT Op) {
+  test<false>(Q, sycl::malloc_host<DataT>(1024, Q), Op);
+  test<true>(Q, sycl::malloc_host<DataT>(1024, Q), Op);
+  test<false>(Q, sycl::malloc_shared<DataT>(1024, Q), Op);
+  test<true>(Q, sycl::malloc_shared<DataT>(1024, Q), Op);
+  test<true>(Q, sycl::malloc_device<DataT>(1024, Q), Op);
 }
diff --git a/libsycl/test/usm/memset.cpp b/libsycl/test/usm/memset.cpp
index 4045b34b77564..bc5dd2eee3c78 100644
--- a/libsycl/test/usm/memset.cpp
+++ b/libsycl/test/usm/memset.cpp
@@ -5,7 +5,7 @@
 #include "include/fill_memset_common.hpp"
 
 int main() {
-  queue Q;
+  sycl::queue Q;
   runTests<unsigned char>(Q,
                           [&](void *Ptr) { Q.memset(Ptr, Pattern, DataSize); });
 }

>From 6909eafbcdbf426f89f7a572452284b5a75e3092 Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Mon, 7 Sep 2026 06:06:21 -0700
Subject: [PATCH 06/11] Apply comments

---
 libsycl/include/sycl/__impl/queue.hpp         | 43 ++++++++++---------
 libsycl/src/detail/queue_impl.cpp             |  8 +++-
 libsycl/src/detail/queue_impl.hpp             |  3 +-
 libsycl/src/queue.cpp                         |  8 ++--
 .../test/usm/include/fill_memset_common.hpp   | 18 ++++----
 libsycl/unittests/queue/fill.cpp              |  9 ++--
 libsycl/unittests/queue/memset.cpp            |  3 +-
 7 files changed, 48 insertions(+), 44 deletions(-)

diff --git a/libsycl/include/sycl/__impl/queue.hpp b/libsycl/include/sycl/__impl/queue.hpp
index c117fb5062581..086e19abf5abc 100644
--- a/libsycl/include/sycl/__impl/queue.hpp
+++ b/libsycl/include/sycl/__impl/queue.hpp
@@ -442,9 +442,9 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
   event memcpy(void *dest, const void *src, std::size_t numBytes,
                const std::vector<event> &depEvents);
 
-  /// Submits a memset operation for USM accessible on the device associated
-  /// with the queue. Equivalent to a fill operation with an unsigned char
-  /// pattern.
+  /// Submits a memset operation on a USM allocation that must be accessible
+  /// on the device associated with the queue. Equivalent to a fill operation
+  /// with an unsigned char pattern.
   ///
   /// \param ptr is the pointer to memory to be set.
   /// \param value is the value the memory should be filled with, interpreted
@@ -455,9 +455,9 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
     return memset(ptr, value, numBytes, std::vector<event>{});
   }
 
-  /// Submits a memset operation for USM accessible on the device associated
-  /// with the queue. Equivalent to a fill operation with an unsigned char
-  /// pattern.
+  /// Submits a memset operation on a USM allocation that must be accessible
+  /// on the device associated with the queue. Equivalent to a fill operation
+  /// with an unsigned char pattern.
   ///
   /// \param ptr is the pointer to memory to be set.
   /// \param value is the value the memory should be filled with, interpreted
@@ -470,9 +470,9 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
     return memset(ptr, value, numBytes, std::vector<event>{depEvent});
   }
 
-  /// Submits a memset operation for USM accessible on the device associated
-  /// with the queue. Equivalent to a fill operation with an unsigned char
-  /// pattern.
+  /// Submits a memset operation on a USM allocation that must be accessible
+  /// on the device associated with the queue. Equivalent to a fill operation
+  /// with an unsigned char pattern.
   ///
   /// \param ptr is the pointer to memory to be set.
   /// \param value is the value the memory should be filled with, interpreted
@@ -486,24 +486,24 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
     return fill(ptr, static_cast<unsigned char>(value), numBytes, depEvents);
   }
 
-  /// Submits a fill operation that replicates a pattern into USM accessible
-  /// on the device associated with the queue.
+  /// Submits a fill operation that replicates a pattern into a USM allocation
+  /// that must be accessible on the device associated with the queue.
   ///
   /// \param ptr is the pointer to memory to be filled.
   /// \param pattern is the pattern to be replicated.
-  /// \param count is the number of times the pattern is filled.
+  /// \param count is the number of times the pattern is replicated.
   /// \return an event that represents the status of the operation.
   template <typename T>
   event fill(void *ptr, const T &pattern, std::size_t count) {
     return fill(ptr, pattern, count, std::vector<event>{});
   }
 
-  /// Submits a fill operation that replicates a pattern into USM accessible
-  /// on the device associated with the queue.
+  /// Submits a fill operation that replicates a pattern into a USM allocation
+  /// that must be accessible on the device associated with the queue.
   ///
   /// \param ptr is the pointer to memory to be filled.
   /// \param pattern is the pattern to be replicated.
-  /// \param count is the number of times the pattern is filled.
+  /// \param count is the number of times the pattern is replicated.
   /// \param depEvent is an event that represents a dependency for the
   /// operation.
   /// \return an event that represents the status of the operation.
@@ -512,12 +512,12 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
     return fill(ptr, pattern, count, std::vector<event>{depEvent});
   }
 
-  /// Submits a fill operation that replicates a pattern into USM accessible
-  /// on the device associated with the queue.
+  /// Submits a fill operation that replicates a pattern into a USM allocation
+  /// that must be accessible on the device associated with the queue.
   ///
   /// \param ptr is the pointer to memory to be filled.
   /// \param pattern is the pattern to be replicated.
-  /// \param count is the number of times the pattern is filled.
+  /// \param count is the number of times the pattern is replicated.
   /// \param depEvents is a vector of events that represent dependencies for the
   /// operation.
   /// \return an event that represents the status of the operation.
@@ -620,15 +620,16 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
   /// \return an event representing last kernel invocation.
   event getLastEvent();
 
-  /// Submits a fill operation that replicates a pattern into USM accessible
-  /// on the device associated with the queue.
+  /// Submits a fill operation that replicates a pattern into a USM allocation
+  /// that must be accessible on the device associated with the queue.
   ///
   /// \param Ptr is the pointer to memory to be filled.
   /// \param Pattern is the pattern to be replicated.
   /// \param PatternSize is the size of the pattern in bytes.
-  /// \param Count is the number of times the pattern is filled.
+  /// \param Count is the number of times the pattern is replicated.
   /// \param DepEvents is a vector of events that represent dependencies for the
   /// operation.
+  /// \return an event that represents the status of the operation.
   event fillImpl(void *Ptr, const void *Pattern, std::size_t PatternSize,
                  std::size_t Count, const std::vector<event> &DepEvents);
 
diff --git a/libsycl/src/detail/queue_impl.cpp b/libsycl/src/detail/queue_impl.cpp
index 1def95918ea27..3b2e139e43bdd 100644
--- a/libsycl/src/detail/queue_impl.cpp
+++ b/libsycl/src/detail/queue_impl.cpp
@@ -16,6 +16,7 @@
 #include <detail/program_manager.hpp>
 
 #include <algorithm>
+#include <cstdint>
 
 _LIBSYCL_BEGIN_NAMESPACE_SYCL
 
@@ -175,7 +176,7 @@ QueueImpl::memcpy(void *Dest, const void *Src, std::size_t NumBytes,
 EventImplPtr QueueImpl::fill(void *Ptr, const void *Pattern,
                              std::size_t PatternSize, std::size_t Count,
                              const std::vector<EventImplPtr> &DepEvents) {
-  assert(PatternSize > 0);
+  assert(PatternSize > 0 && "Pattern size has to be greater than zero");
   checkEventsPlatformMatch(DepEvents, MDevice.getPlatformImpl());
   if (Count == 0) {
     handleEventDependencies(DepEvents);
@@ -186,6 +187,11 @@ EventImplPtr QueueImpl::fill(void *Ptr, const void *Pattern,
     throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
                           "Nullptr argument in fill/memset operation");
   }
+  if (Count > SIZE_MAX / PatternSize) {
+    throw sycl::exception(
+        sycl::make_error_code(sycl::errc::invalid),
+        "Total number of bytes to be filled exceeds SIZE_MAX");
+  }
 
   handleEventDependencies(DepEvents);
   callAndThrow(olMemFill, MOffloadQueue, Ptr, PatternSize, Pattern,
diff --git a/libsycl/src/detail/queue_impl.hpp b/libsycl/src/detail/queue_impl.hpp
index dd179141b745b..1cf406c91bef6 100644
--- a/libsycl/src/detail/queue_impl.hpp
+++ b/libsycl/src/detail/queue_impl.hpp
@@ -130,9 +130,10 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
   ///
   /// \param Ptr is the pointer to memory to be filled.
   /// \param Pattern is the pattern to be replicated.
-  /// \param PatternSize is the size of the pattern.
+  /// \param PatternSize is the size of the pattern in bytes.
   /// \param Count is the number of times the pattern is filled.
   /// \param DepEvents is a vector of dependencies for the operation.
+  /// \return an event impl object that represents the status of the operation.
   EventImplPtr fill(void *Ptr, const void *Pattern, std::size_t PatternSize,
                     std::size_t Count,
                     const std::vector<EventImplPtr> &DepEvents);
diff --git a/libsycl/src/queue.cpp b/libsycl/src/queue.cpp
index 40c9fb50bf27c..a8b183c7289bc 100644
--- a/libsycl/src/queue.cpp
+++ b/libsycl/src/queue.cpp
@@ -69,10 +69,6 @@ void queue::submitKernelImpl(detail::DeviceKernelInfo &KernelInfo,
   impl->submitKernelImpl(KernelInfo, ArgData, ArgSize);
 }
 
-event queue::submitWithHandler(const TypelessCGF &CGF) {
-  return detail::createSyclObjFromImpl<event>(impl->submitWithHandler(CGF));
-}
-
 event queue::fillImpl(void *Ptr, const void *Pattern, std::size_t PatternSize,
                       std::size_t Count, const std::vector<event> &DepEvents) {
   std::shared_ptr<detail::EventImpl> EventImplPtr = impl->fill(
@@ -81,4 +77,8 @@ event queue::fillImpl(void *Ptr, const void *Pattern, std::size_t PatternSize,
   return detail::createSyclObjFromImpl<event>(EventImplPtr);
 }
 
+event queue::submitWithHandler(const TypelessCGF &CGF) {
+  return detail::createSyclObjFromImpl<event>(impl->submitWithHandler(CGF));
+}
+
 _LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/test/usm/include/fill_memset_common.hpp b/libsycl/test/usm/include/fill_memset_common.hpp
index bbab779e1aaa1..acf141cef5588 100644
--- a/libsycl/test/usm/include/fill_memset_common.hpp
+++ b/libsycl/test/usm/include/fill_memset_common.hpp
@@ -1,13 +1,12 @@
 #include <sycl/sycl.hpp>
 
-#include <array>
 #include <cassert>
 
 constexpr std::size_t DataSize = 1024;
 constexpr int Pattern = 42;
 
 template <typename DataT> bool verify(DataT *Ptr) {
-  for (int I = 0; I < DataSize; ++I)
+  for (std::size_t I = 0; I < DataSize; ++I)
     if (Ptr[I] != Pattern)
       return false;
   return true;
@@ -20,21 +19,20 @@ void test(sycl::queue &Q, DataT *Ptr, OpT Op) {
 
   if constexpr (VerifyOnDevice) {
     bool *Result = sycl::malloc_shared<bool>(1, Q);
-    Q.single_task<class Verify>([=]() { verify(Ptr); });
+    Q.single_task<class Verify>([=]() { *Result = verify(Ptr); });
     Q.wait();
-    assert(Result);
+    assert(*Result);
     sycl::free(Result, Q);
   } else {
-    Q.wait();
     assert(verify(Ptr));
   }
   sycl::free(Ptr, Q);
 }
 
 template <typename DataT, typename OpT> void runTests(sycl::queue &Q, OpT Op) {
-  test<false>(Q, sycl::malloc_host<DataT>(1024, Q), Op);
-  test<true>(Q, sycl::malloc_host<DataT>(1024, Q), Op);
-  test<false>(Q, sycl::malloc_shared<DataT>(1024, Q), Op);
-  test<true>(Q, sycl::malloc_shared<DataT>(1024, Q), Op);
-  test<true>(Q, sycl::malloc_device<DataT>(1024, Q), Op);
+  test<false>(Q, sycl::malloc_host<DataT>(DataSize, Q), Op);
+  test<true>(Q, sycl::malloc_host<DataT>(DataSize, Q), Op);
+  test<false>(Q, sycl::malloc_shared<DataT>(DataSize, Q), Op);
+  test<true>(Q, sycl::malloc_shared<DataT>(DataSize, Q), Op);
+  test<true>(Q, sycl::malloc_device<DataT>(DataSize, Q), Op);
 }
diff --git a/libsycl/unittests/queue/fill.cpp b/libsycl/unittests/queue/fill.cpp
index d41785def7026..bc29a341449ce 100644
--- a/libsycl/unittests/queue/fill.cpp
+++ b/libsycl/unittests/queue/fill.cpp
@@ -19,12 +19,11 @@ TEST(Queue, Fill) {
   mock::MockWrapper Mock;
   sycl::queue Q;
 
-  int a;
-  int *Ptr = &a;
-  int Pattern;
+  int *Ptr = reinterpret_cast<int *>(1);
+  int Pattern = 42;
   int *PatternPtr = &Pattern;
   constexpr int FillCount = 32;
-  constexpr int FillBytes = FillCount * sizeof(int);
+  constexpr std::size_t FillBytes = FillCount * sizeof(int);
 
   EXPECT_CALL(Mock.get(), olMemFill(_, Ptr, sizeof(int), PatternPtr, FillBytes))
       .Times(3);
@@ -34,7 +33,7 @@ TEST(Queue, Fill) {
   Q.fill(Ptr, Pattern, FillCount, std::vector<sycl::event>{E});
 }
 
-TEST(Queue, FillZeroBytes) {
+TEST(Queue, FillZeroCount) {
   mock::MockWrapper Mock;
   sycl::queue Q;
   EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(2);
diff --git a/libsycl/unittests/queue/memset.cpp b/libsycl/unittests/queue/memset.cpp
index 0f049d2b8679b..80629659dc226 100644
--- a/libsycl/unittests/queue/memset.cpp
+++ b/libsycl/unittests/queue/memset.cpp
@@ -19,8 +19,7 @@ TEST(Queue, Memset) {
   mock::MockWrapper Mock;
   sycl::queue Q;
 
-  int a;
-  int *Ptr = &a;
+  int *Ptr = reinterpret_cast<int *>(1);
   constexpr int FillCount = 32;
   int Pattern = 42;
 

>From ffbf9fd542cb1deda7e15443dfececb466d2bf83 Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Tue, 8 Sep 2026 05:20:19 -0700
Subject: [PATCH 07/11] Address more comments

---
 .../fill_memset_common.hpp                    |  0
 libsycl/test/usm/fill.cpp                     |  2 +-
 libsycl/test/usm/memset.cpp                   |  2 +-
 libsycl/unittests/queue/fill.cpp              | 32 +++++++++++++++++++
 libsycl/unittests/queue/memcpy.cpp            | 11 +++----
 libsycl/unittests/queue/memset.cpp            | 15 +++++++++
 6 files changed, 54 insertions(+), 8 deletions(-)
 rename libsycl/test/usm/{include => Inputs}/fill_memset_common.hpp (100%)

diff --git a/libsycl/test/usm/include/fill_memset_common.hpp b/libsycl/test/usm/Inputs/fill_memset_common.hpp
similarity index 100%
rename from libsycl/test/usm/include/fill_memset_common.hpp
rename to libsycl/test/usm/Inputs/fill_memset_common.hpp
diff --git a/libsycl/test/usm/fill.cpp b/libsycl/test/usm/fill.cpp
index 7313c2f194616..03a9ba7233a5a 100644
--- a/libsycl/test/usm/fill.cpp
+++ b/libsycl/test/usm/fill.cpp
@@ -2,7 +2,7 @@
 // RUN: %clangxx -fsycl %s -o %t.out
 // RUN: %t.out
 
-#include "include/fill_memset_common.hpp"
+#include "Inputs/fill_memset_common.hpp"
 
 int main() {
   sycl::queue Q;
diff --git a/libsycl/test/usm/memset.cpp b/libsycl/test/usm/memset.cpp
index bc5dd2eee3c78..14640a237cba9 100644
--- a/libsycl/test/usm/memset.cpp
+++ b/libsycl/test/usm/memset.cpp
@@ -2,7 +2,7 @@
 // RUN: %clangxx -fsycl %s -o %t.out
 // RUN: %t.out
 
-#include "include/fill_memset_common.hpp"
+#include "Inputs/fill_memset_common.hpp"
 
 int main() {
   sycl::queue Q;
diff --git a/libsycl/unittests/queue/fill.cpp b/libsycl/unittests/queue/fill.cpp
index bc29a341449ce..6f942013b2df0 100644
--- a/libsycl/unittests/queue/fill.cpp
+++ b/libsycl/unittests/queue/fill.cpp
@@ -42,3 +42,35 @@ TEST(Queue, FillZeroCount) {
   Q.fill(nullptr, 1, 0, E);
   Q.fill(nullptr, 1, 0, std::vector<sycl::event>{E});
 }
+
+TEST(Queue, FillNullptr) {
+  mock::MockWrapper Mock;
+  sycl::queue Q;
+  sycl::event Dep = Q.fill(nullptr, 1, 0);
+  EXPECT_CALL(Mock.get(), olWaitEvents(_, _, _)).Times(0);
+  EXPECT_CALL(Mock.get(), olMemFill(_, _, _, _, _)).Times(0);
+  try {
+    Q.fill(nullptr, 1, 1);
+    FAIL() << "Expected thrown exception";
+  } catch (sycl::exception &E) {
+    EXPECT_NE(std::string(E.what()).find("Nullptr argument"),
+              std::string::npos);
+  }
+}
+
+TEST(Queue, FillBytesGTSizeMax) {
+  mock::MockWrapper Mock;
+  sycl::queue Q;
+  int *Ptr = reinterpret_cast<int *>(1);
+  sycl::event Dep = Q.fill(Ptr, 1, 0);
+  EXPECT_CALL(Mock.get(), olWaitEvents(_, _, _)).Times(0);
+  EXPECT_CALL(Mock.get(), olMemFill(_, _, _, _, _)).Times(0);
+  try {
+    Q.fill(Ptr, 1, SIZE_MAX / sizeof(int) + 1);
+    FAIL() << "Expected thrown exception";
+  } catch (sycl::exception &E) {
+    EXPECT_NE(std::string(E.what()).find(
+                  "Total number of bytes to be filled exceeds SIZE_MAX"),
+              std::string::npos);
+  }
+}
\ No newline at end of file
diff --git a/libsycl/unittests/queue/memcpy.cpp b/libsycl/unittests/queue/memcpy.cpp
index db977f79d5bef..eea434c3b62c6 100644
--- a/libsycl/unittests/queue/memcpy.cpp
+++ b/libsycl/unittests/queue/memcpy.cpp
@@ -9,7 +9,6 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
-using namespace sycl;
 using namespace ::testing;
 
 TEST(Queue, Memcpy) {
@@ -17,14 +16,14 @@ TEST(Queue, Memcpy) {
   constexpr int NMemcpies = 5;
 
   mock::MockWrapper Mock;
-  queue Q;
+  sycl::queue Q;
 
   bool IsSrcHostPtr = false;
   bool IsDstHostPtr = false;
   int *SrcPtr = reinterpret_cast<int *>(1);
   int *DstPtr = reinterpret_cast<int *>(2);
   ol_device_handle_t OLDev =
-      detail::getSyclObjImpl(Q.get_device())->getOLHandle();
+      sycl::detail::getSyclObjImpl(Q.get_device())->getOLHandle();
 
   EXPECT_CALL(Mock.get(), olGetMemInfo(_, OL_MEM_INFO_DEVICE,
                                        sizeof(ol_device_handle_t), _))
@@ -54,7 +53,7 @@ TEST(Queue, Memcpy) {
 
   EXPECT_CALL(Mock.get(), olCreateEvent(_, _, _)).Times(NMemcpies);
 
-  event Event = Q.memcpy(DstPtr, SrcPtr, NumBytes);
+  sycl::event Event = Q.memcpy(DstPtr, SrcPtr, NumBytes);
 
   EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1));
   Q.memcpy(DstPtr, SrcPtr, NumBytes, Event);
@@ -71,10 +70,10 @@ TEST(Queue, Memcpy) {
 
 TEST(Queue, MemcpyZeroBytes) {
   mock::MockWrapper Mock;
-  queue Q;
+  sycl::queue Q;
   EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(1);
   EXPECT_CALL(Mock.get(), olGetMemInfo(_, _, _, _)).Times(0);
   EXPECT_CALL(Mock.get(), olMemcpy(_, _, _, _, _, _)).Times(0);
-  event Event = Q.memcpy(nullptr, nullptr, 0);
+  sycl::event Event = Q.memcpy(nullptr, nullptr, 0);
   Q.memcpy(nullptr, nullptr, 0, Event);
 }
diff --git a/libsycl/unittests/queue/memset.cpp b/libsycl/unittests/queue/memset.cpp
index 80629659dc226..f624e2c6e54f4 100644
--- a/libsycl/unittests/queue/memset.cpp
+++ b/libsycl/unittests/queue/memset.cpp
@@ -41,3 +41,18 @@ TEST(Queue, MemsetZeroBytes) {
   Q.memset(nullptr, 1, 0, E);
   Q.memset(nullptr, 1, 0, std::vector<sycl::event>{E});
 }
+
+TEST(Queue, MemsetNullptr) {
+  mock::MockWrapper Mock;
+  sycl::queue Q;
+  sycl::event Dep = Q.memset(nullptr, 1, 0);
+  EXPECT_CALL(Mock.get(), olWaitEvents(_, _, _)).Times(0);
+  EXPECT_CALL(Mock.get(), olMemFill(_, _, _, _, _)).Times(0);
+  try {
+    Q.memset(nullptr, 1, 1);
+    FAIL() << "Expected thrown exception";
+  } catch (sycl::exception &E) {
+    EXPECT_NE(std::string(E.what()).find("Nullptr argument"),
+              std::string::npos);
+  }
+}

>From bd2c60ce2f5d4979e43965fc0da3b741828affda Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Tue, 8 Sep 2026 05:36:18 -0700
Subject: [PATCH 08/11] Strengthen thrown exception checks

---
 libsycl/unittests/queue/fill.cpp   | 2 ++
 libsycl/unittests/queue/memset.cpp | 1 +
 2 files changed, 3 insertions(+)

diff --git a/libsycl/unittests/queue/fill.cpp b/libsycl/unittests/queue/fill.cpp
index 6f942013b2df0..51551576c4822 100644
--- a/libsycl/unittests/queue/fill.cpp
+++ b/libsycl/unittests/queue/fill.cpp
@@ -53,6 +53,7 @@ TEST(Queue, FillNullptr) {
     Q.fill(nullptr, 1, 1);
     FAIL() << "Expected thrown exception";
   } catch (sycl::exception &E) {
+    EXPECT_EQ(E.code(), make_error_code(sycl::errc::invalid));
     EXPECT_NE(std::string(E.what()).find("Nullptr argument"),
               std::string::npos);
   }
@@ -69,6 +70,7 @@ TEST(Queue, FillBytesGTSizeMax) {
     Q.fill(Ptr, 1, SIZE_MAX / sizeof(int) + 1);
     FAIL() << "Expected thrown exception";
   } catch (sycl::exception &E) {
+    EXPECT_EQ(E.code(), make_error_code(sycl::errc::invalid));
     EXPECT_NE(std::string(E.what()).find(
                   "Total number of bytes to be filled exceeds SIZE_MAX"),
               std::string::npos);
diff --git a/libsycl/unittests/queue/memset.cpp b/libsycl/unittests/queue/memset.cpp
index f624e2c6e54f4..295b764d5764d 100644
--- a/libsycl/unittests/queue/memset.cpp
+++ b/libsycl/unittests/queue/memset.cpp
@@ -52,6 +52,7 @@ TEST(Queue, MemsetNullptr) {
     Q.memset(nullptr, 1, 1);
     FAIL() << "Expected thrown exception";
   } catch (sycl::exception &E) {
+    EXPECT_EQ(E.code(), make_error_code(sycl::errc::invalid));
     EXPECT_NE(std::string(E.what()).find("Nullptr argument"),
               std::string::npos);
   }

>From 3508b953599438c0bae20f9f5170869ce6fa481c Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Tue, 8 Sep 2026 06:31:21 -0700
Subject: [PATCH 09/11] Apply comment

---
 .../test/usm/Inputs/fill_memset_common.hpp    | 26 +++++++++----------
 libsycl/test/usm/fill.cpp                     |  3 ++-
 libsycl/test/usm/memset.cpp                   | 10 +++++--
 libsycl/unittests/queue/fill.cpp              |  2 ++
 4 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/libsycl/test/usm/Inputs/fill_memset_common.hpp b/libsycl/test/usm/Inputs/fill_memset_common.hpp
index acf141cef5588..8edfb8cd08000 100644
--- a/libsycl/test/usm/Inputs/fill_memset_common.hpp
+++ b/libsycl/test/usm/Inputs/fill_memset_common.hpp
@@ -3,36 +3,36 @@
 #include <cassert>
 
 constexpr std::size_t DataSize = 1024;
-constexpr int Pattern = 42;
 
-template <typename DataT> bool verify(DataT *Ptr) {
+template <typename DataT> bool verify(DataT *Ptr, int Pattern) {
   for (std::size_t I = 0; I < DataSize; ++I)
-    if (Ptr[I] != Pattern)
+    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) {
-  Op(Ptr);
+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); });
+    Q.single_task<class Verify>([=]() { *Result = verify(Ptr, Pattern); });
     Q.wait();
     assert(*Result);
     sycl::free(Result, Q);
   } else {
-    assert(verify(Ptr));
+    assert(verify(Ptr, Pattern));
   }
   sycl::free(Ptr, Q);
 }
 
-template <typename DataT, typename OpT> void runTests(sycl::queue &Q, OpT Op) {
-  test<false>(Q, sycl::malloc_host<DataT>(DataSize, Q), Op);
-  test<true>(Q, sycl::malloc_host<DataT>(DataSize, Q), Op);
-  test<false>(Q, sycl::malloc_shared<DataT>(DataSize, Q), Op);
-  test<true>(Q, sycl::malloc_shared<DataT>(DataSize, Q), Op);
-  test<true>(Q, sycl::malloc_device<DataT>(DataSize, Q), Op);
+template <typename DataT, typename OpT>
+void runTests(sycl::queue &Q, OpT Op, int Pattern = 42) {
+  test<false>(Q, sycl::malloc_host<DataT>(DataSize, Q), Op, Pattern);
+  test<true>(Q, sycl::malloc_host<DataT>(DataSize, Q), Op, Pattern);
+  test<false>(Q, sycl::malloc_shared<DataT>(DataSize, Q), Op, Pattern);
+  test<true>(Q, sycl::malloc_shared<DataT>(DataSize, Q), Op, Pattern);
+  test<true>(Q, sycl::malloc_device<DataT>(DataSize, Q), Op, Pattern);
 }
diff --git a/libsycl/test/usm/fill.cpp b/libsycl/test/usm/fill.cpp
index 03a9ba7233a5a..9a254f9341a61 100644
--- a/libsycl/test/usm/fill.cpp
+++ b/libsycl/test/usm/fill.cpp
@@ -6,5 +6,6 @@
 
 int main() {
   sycl::queue Q;
-  runTests<int>(Q, [&](void *Ptr) { Q.fill(Ptr, Pattern, DataSize); });
+  runTests<int>(
+      Q, [&](void *Ptr, int Pattern) { Q.fill(Ptr, Pattern, DataSize); });
 }
diff --git a/libsycl/test/usm/memset.cpp b/libsycl/test/usm/memset.cpp
index 14640a237cba9..b5515fb5a282a 100644
--- a/libsycl/test/usm/memset.cpp
+++ b/libsycl/test/usm/memset.cpp
@@ -4,8 +4,14 @@
 
 #include "Inputs/fill_memset_common.hpp"
 
+#include <climits>
+
 int main() {
   sycl::queue Q;
-  runTests<unsigned char>(Q,
-                          [&](void *Ptr) { Q.memset(Ptr, Pattern, DataSize); });
+  runTests<unsigned char>(
+      Q, [&](void *Ptr, int Pattern) { Q.memset(Ptr, Pattern, DataSize); });
+  // Check that the pattern is truncated to an unsigned char.
+  runTests<unsigned char>(
+      Q, [&](void *Ptr, int Pattern) { Q.memset(Ptr, Pattern, DataSize); },
+      CHAR_MAX + 42);
 }
diff --git a/libsycl/unittests/queue/fill.cpp b/libsycl/unittests/queue/fill.cpp
index 51551576c4822..a2383b90b7a1f 100644
--- a/libsycl/unittests/queue/fill.cpp
+++ b/libsycl/unittests/queue/fill.cpp
@@ -13,6 +13,8 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+#include <cstdint>
+
 using namespace ::testing;
 
 TEST(Queue, Fill) {

>From bec5494968a0b547b8f4d706cc9b0b79eb5cec07 Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Tue, 8 Sep 2026 07:42:41 -0700
Subject: [PATCH 10/11] Add missing newline at EOF

---
 libsycl/unittests/queue/fill.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libsycl/unittests/queue/fill.cpp b/libsycl/unittests/queue/fill.cpp
index a2383b90b7a1f..e3ecfb55fadca 100644
--- a/libsycl/unittests/queue/fill.cpp
+++ b/libsycl/unittests/queue/fill.cpp
@@ -77,4 +77,4 @@ TEST(Queue, FillBytesGTSizeMax) {
                   "Total number of bytes to be filled exceeds SIZE_MAX"),
               std::string::npos);
   }
-}
\ No newline at end of file
+}

>From 6c98b7e1aebdb1c5e029ce443732bf5fddcbe195 Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Mon, 14 Sep 2026 06:59:43 -0700
Subject: [PATCH 11/11] Apply comments

---
 libsycl/src/detail/queue_impl.cpp             | 27 +++++----------
 .../test/usm/Inputs/fill_memset_common.hpp    | 34 ++++++++++++-------
 libsycl/test/usm/fill.cpp                     | 25 +++++++++++++-
 libsycl/test/usm/memset.cpp                   | 11 ++++--
 libsycl/unittests/queue/memcpy.cpp            | 11 +++---
 5 files changed, 70 insertions(+), 38 deletions(-)

diff --git a/libsycl/src/detail/queue_impl.cpp b/libsycl/src/detail/queue_impl.cpp
index 3b2e139e43bdd..5dc8391e5d4f2 100644
--- a/libsycl/src/detail/queue_impl.cpp
+++ b/libsycl/src/detail/queue_impl.cpp
@@ -155,14 +155,12 @@ std::shared_ptr<EventImpl>
 QueueImpl::memcpy(void *Dest, const void *Src, std::size_t NumBytes,
                   const std::vector<EventImplPtr> &DepEvents) {
   checkEventsPlatformMatch(DepEvents, MDevice.getPlatformImpl());
-  if (NumBytes == 0) {
+  if (NumBytes == 0)
     return submitWait(DepEvents);
-  }
 
-  if (!Dest || !Src) {
+  if (!Dest || !Src)
     throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
                           "Nullptr argument in memcpy operation");
-  }
 
   ol_device_handle_t DestOLDevice = getAllocDevice(Dest);
   ol_device_handle_t SrcOLDevice = getAllocDevice(Src);
@@ -178,20 +176,16 @@ EventImplPtr QueueImpl::fill(void *Ptr, const void *Pattern,
                              const std::vector<EventImplPtr> &DepEvents) {
   assert(PatternSize > 0 && "Pattern size has to be greater than zero");
   checkEventsPlatformMatch(DepEvents, MDevice.getPlatformImpl());
-  if (Count == 0) {
-    handleEventDependencies(DepEvents);
-    return createEvent();
-  }
+  if (Count == 0)
+    return submitWait(DepEvents);
 
-  if (!Ptr) {
+  if (!Ptr)
     throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
                           "Nullptr argument in fill/memset operation");
-  }
-  if (Count > SIZE_MAX / PatternSize) {
+  if (Count > SIZE_MAX / PatternSize)
     throw sycl::exception(
         sycl::make_error_code(sycl::errc::invalid),
         "Total number of bytes to be filled exceeds SIZE_MAX");
-  }
 
   handleEventDependencies(DepEvents);
   callAndThrow(olMemFill, MOffloadQueue, Ptr, PatternSize, Pattern,
@@ -203,14 +197,11 @@ EventImplPtr QueueImpl::prefetch(void *Ptr, std::size_t NumBytes,
                                  const std::vector<EventImplPtr> &DepEvents) {
   checkEventsPlatformMatch(DepEvents, MDevice.getPlatformImpl());
 
-  if (NumBytes == 0) {
-    handleEventDependencies(DepEvents);
-    return createEvent();
-  }
-  if (!Ptr) {
+  if (NumBytes == 0)
+    return submitWait(DepEvents);
+  if (!Ptr)
     throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
                           "Nullptr argument in prefetch operation");
-  }
 
   constexpr std::size_t Count = 1;
   const void *Mems[] = {Ptr};
diff --git a/libsycl/test/usm/Inputs/fill_memset_common.hpp b/libsycl/test/usm/Inputs/fill_memset_common.hpp
index 8edfb8cd08000..5018aeb0ba4a9 100644
--- a/libsycl/test/usm/Inputs/fill_memset_common.hpp
+++ b/libsycl/test/usm/Inputs/fill_memset_common.hpp
@@ -1,18 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
 #include <sycl/sycl.hpp>
 
 #include <cassert>
+#include <cstddef>
 
-constexpr std::size_t DataSize = 1024;
+constexpr std::size_t ElementCount = 1024;
 
-template <typename DataT> bool verify(DataT *Ptr, int Pattern) {
-  for (std::size_t I = 0; I < DataSize; ++I)
+template <typename DataT, typename PatternT>
+bool verify(DataT *Ptr, PatternT Pattern) {
+  for (std::size_t I = 0; I < ElementCount; ++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) {
+// This function takes ownership of Ptr and is responsible for freeing it.
+template <bool VerifyOnDevice, typename DataT, typename OpT, typename PatternT>
+void test(sycl::queue &Q, DataT *Ptr, OpT Op, PatternT Pattern) {
   Op(Ptr, Pattern);
   Q.wait();
 
@@ -28,11 +38,11 @@ void test(sycl::queue &Q, DataT *Ptr, OpT Op, int Pattern) {
   sycl::free(Ptr, Q);
 }
 
-template <typename DataT, typename OpT>
-void runTests(sycl::queue &Q, OpT Op, int Pattern = 42) {
-  test<false>(Q, sycl::malloc_host<DataT>(DataSize, Q), Op, Pattern);
-  test<true>(Q, sycl::malloc_host<DataT>(DataSize, Q), Op, Pattern);
-  test<false>(Q, sycl::malloc_shared<DataT>(DataSize, Q), Op, Pattern);
-  test<true>(Q, sycl::malloc_shared<DataT>(DataSize, Q), Op, Pattern);
-  test<true>(Q, sycl::malloc_device<DataT>(DataSize, Q), Op, Pattern);
+template <typename DataT, typename OpT, typename PatternT = int>
+void runTests(sycl::queue &Q, OpT Op, PatternT Pattern = 42) {
+  test<false>(Q, sycl::malloc_host<DataT>(ElementCount, Q), Op, Pattern);
+  test<true>(Q, sycl::malloc_host<DataT>(ElementCount, Q), Op, Pattern);
+  test<false>(Q, sycl::malloc_shared<DataT>(ElementCount, Q), Op, Pattern);
+  test<true>(Q, sycl::malloc_shared<DataT>(ElementCount, Q), Op, Pattern);
+  test<true>(Q, sycl::malloc_device<DataT>(ElementCount, Q), Op, Pattern);
 }
diff --git a/libsycl/test/usm/fill.cpp b/libsycl/test/usm/fill.cpp
index 9a254f9341a61..ed5c2684c23d6 100644
--- a/libsycl/test/usm/fill.cpp
+++ b/libsycl/test/usm/fill.cpp
@@ -1,11 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
 // REQUIRES: any-device
 // RUN: %clangxx -fsycl %s -o %t.out
 // RUN: %t.out
 
 #include "Inputs/fill_memset_common.hpp"
 
+struct Foo {
+  unsigned char Val[3];
+  bool operator!=(const Foo &Rhs) const {
+    for (std::size_t I = 0; I < 3; ++I)
+      if (Val[I] != Rhs.Val[I])
+        return true;
+    return false;
+  }
+};
+
 int main() {
   sycl::queue Q;
   runTests<int>(
-      Q, [&](void *Ptr, int Pattern) { Q.fill(Ptr, Pattern, DataSize); });
+      Q, [&](void *Ptr, int Pattern) { Q.fill(Ptr, Pattern, ElementCount); });
+  // Liboffload handles patterns with a size that's not a power of two
+  // differently, check that case separately.
+  Foo Val({'a', 'b', 'c'});
+  runTests<Foo>(
+      Q, [&](void *Ptr, Foo Pattern) { Q.fill(Ptr, Pattern, ElementCount); },
+      Val);
 }
diff --git a/libsycl/test/usm/memset.cpp b/libsycl/test/usm/memset.cpp
index b5515fb5a282a..7b460b54c68a5 100644
--- a/libsycl/test/usm/memset.cpp
+++ b/libsycl/test/usm/memset.cpp
@@ -1,3 +1,10 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
 // REQUIRES: any-device
 // RUN: %clangxx -fsycl %s -o %t.out
 // RUN: %t.out
@@ -9,9 +16,9 @@
 int main() {
   sycl::queue Q;
   runTests<unsigned char>(
-      Q, [&](void *Ptr, int Pattern) { Q.memset(Ptr, Pattern, DataSize); });
+      Q, [&](void *Ptr, int Pattern) { Q.memset(Ptr, Pattern, ElementCount); });
   // Check that the pattern is truncated to an unsigned char.
   runTests<unsigned char>(
-      Q, [&](void *Ptr, int Pattern) { Q.memset(Ptr, Pattern, DataSize); },
+      Q, [&](void *Ptr, int Pattern) { Q.memset(Ptr, Pattern, ElementCount); },
       CHAR_MAX + 42);
 }
diff --git a/libsycl/unittests/queue/memcpy.cpp b/libsycl/unittests/queue/memcpy.cpp
index eea434c3b62c6..db977f79d5bef 100644
--- a/libsycl/unittests/queue/memcpy.cpp
+++ b/libsycl/unittests/queue/memcpy.cpp
@@ -9,6 +9,7 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
+using namespace sycl;
 using namespace ::testing;
 
 TEST(Queue, Memcpy) {
@@ -16,14 +17,14 @@ TEST(Queue, Memcpy) {
   constexpr int NMemcpies = 5;
 
   mock::MockWrapper Mock;
-  sycl::queue Q;
+  queue Q;
 
   bool IsSrcHostPtr = false;
   bool IsDstHostPtr = false;
   int *SrcPtr = reinterpret_cast<int *>(1);
   int *DstPtr = reinterpret_cast<int *>(2);
   ol_device_handle_t OLDev =
-      sycl::detail::getSyclObjImpl(Q.get_device())->getOLHandle();
+      detail::getSyclObjImpl(Q.get_device())->getOLHandle();
 
   EXPECT_CALL(Mock.get(), olGetMemInfo(_, OL_MEM_INFO_DEVICE,
                                        sizeof(ol_device_handle_t), _))
@@ -53,7 +54,7 @@ TEST(Queue, Memcpy) {
 
   EXPECT_CALL(Mock.get(), olCreateEvent(_, _, _)).Times(NMemcpies);
 
-  sycl::event Event = Q.memcpy(DstPtr, SrcPtr, NumBytes);
+  event Event = Q.memcpy(DstPtr, SrcPtr, NumBytes);
 
   EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1));
   Q.memcpy(DstPtr, SrcPtr, NumBytes, Event);
@@ -70,10 +71,10 @@ TEST(Queue, Memcpy) {
 
 TEST(Queue, MemcpyZeroBytes) {
   mock::MockWrapper Mock;
-  sycl::queue Q;
+  queue Q;
   EXPECT_CALL(Mock.get(), olWaitEvents(_, _, 1)).Times(1);
   EXPECT_CALL(Mock.get(), olGetMemInfo(_, _, _, _)).Times(0);
   EXPECT_CALL(Mock.get(), olMemcpy(_, _, _, _, _, _)).Times(0);
-  sycl::event Event = Q.memcpy(nullptr, nullptr, 0);
+  event Event = Q.memcpy(nullptr, nullptr, 0);
   Q.memcpy(nullptr, nullptr, 0, Event);
 }



More information about the llvm-commits mailing list