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

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 22 03:54:41 PDT 2026


================
@@ -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);
+  }
+
----------------
Robertkq wrote:

We're missing one overload for `fill` according to [rev 12](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#api:queue-fill). I assume we don't have necessary dependencies yet as that's why it was omitted, should we still add the signature and comment it out or something like that? Maybe attached with a `TODO`

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


More information about the llvm-commits mailing list