@@ -49,6 +49,7 @@ from ._backend cimport ( # noqa: E211
4949 DPCTLQueue_MemAdvise,
5050 DPCTLQueue_Memcpy,
5151 DPCTLQueue_MemcpyWithEvents,
52+ DPCTLQueue_Memset,
5253 DPCTLQueue_Prefetch,
5354 DPCTLQueue_SubmitBarrierForEvents,
5455 DPCTLQueue_SubmitNDRange,
@@ -1594,6 +1595,48 @@ cdef class SyclQueue(_SyclQueue):
15941595
15951596 return SyclEvent._create(ERef)
15961597
1598+ cpdef memset(self , mem, int val, size_t count = 0 ):
1599+ """ Fill USM allocation ``mem`` with the byte value ``val`` and wait.
1600+
1601+ Internally, this dispatches ``sycl::queue::memset``. The operation is
1602+ byte-wise: ``count`` bytes are set, each to the same value ``val``.
1603+
1604+ Args:
1605+ mem:
1606+ Destination USM allocation, an instance of
1607+ :class:`dpctl.memory._Memory`.
1608+ val (int):
1609+ Value to fill ``mem`` with. Following ``sycl::queue::memset``,
1610+ it is interpreted as an ``unsigned char``, i.e. only the least
1611+ significant byte is used.
1612+ count (int, optional):
1613+ Number of bytes to fill. If ``0`` or greater than the size of
1614+ ``mem``, the whole allocation is filled. Default: ``0``.
1615+
1616+ Raises:
1617+ TypeError:
1618+ If ``mem`` is not an instance of :class:`dpctl.memory._Memory`.
1619+ """
1620+ cdef void * ptr
1621+ cdef DPCTLSyclEventRef ERef = NULL
1622+
1623+ if isinstance (mem, _Memory):
1624+ ptr = < void * > (< _Memory> mem).get_data_ptr()
1625+ else :
1626+ raise TypeError (" Parameter `mem` should have type _Memory" )
1627+
1628+ if (count <= 0 or count > mem.nbytes):
1629+ count = mem.nbytes
1630+
1631+ ERef = DPCTLQueue_Memset(self ._queue_ref, ptr, val, count)
1632+ if (ERef is NULL ):
1633+ raise RuntimeError (
1634+ " SyclQueue.memset operation encountered an error"
1635+ )
1636+ with nogil:
1637+ DPCTLEvent_Wait(ERef)
1638+ DPCTLEvent_Delete(ERef)
1639+
15971640 cpdef prefetch(self , mem, size_t count = 0 ):
15981641 cdef void * ptr
15991642 cdef DPCTLSyclEventRef ERef = NULL
0 commit comments