Add dpctl.SyclQueue.memset() method - #2361
Conversation
|
View rendered docs @ https://intelpython.github.io/dpctl/pulls/2361/index.html |
|
@ndgrigorian I implemented |
| host = bytearray(nbytes) | ||
| q.memcpy(host, mobj, nbytes) | ||
| return bytes(host) | ||
|
|
There was a problem hiding this comment.
The docstring promises val is interpreted as unsigned char (LSB only), but nothing verifies e.g. memset(mem, 0x1FF) fills 0xFF or -1 fills 0xFF. There is no error case to test here (values truncate, not reject).
There was a problem hiding this comment.
This case is already covered by test_memset_value_truncated_to_byte (negatives and overflow)
https://github.com/IntelPython/dpctl/pull/2361/changes#diff-8cf72656d339e0f446c2227869696dee611bdce0bc37434f62419482dc4cd075R192
| mobj = _create_memory(q, nbytes) | ||
|
|
||
| e1 = q.memset_async(mobj, 0x01) | ||
| e2 = q.memset_async(mobj, 0x02, nbytes, [e1]) |
There was a problem hiding this comment.
e2 overwrites the entire buffer with 0x02, the final state is 0x02 no matter what e1 did or whether e2 actually waited for it.
To actually prove the dependency you'd need the two ops to interact where order changes the value — e.g. e1 fills the whole buffer with 0x01, e2 (depending on e1) fills only the first half with 0x02, then assert first half 0x02 + second half 0x01.
| except dpctl.SyclQueueCreationError: | ||
| pytest.skip("Default constructor for SyclQueue failed") | ||
| nbytes = 256 | ||
| mobj = mem_cls(nbytes, queue=q) |
There was a problem hiding this comment.
Not every SYCL device supports every USM kind. Needs to check the aspect (or catch the allocation failure) and pytest.skip when unsupported.
Applicable to the memcpy tests also.
| ``mem``, the whole allocation is filled. Default: ``0``. | ||
|
|
||
| Raises: | ||
| TypeError: |
There was a problem hiding this comment.
Might raise OverflowError also:
import dpctl
import dpctl.memory as dpm
q = dpctl.SyclQueue()
m = dpm.MemoryUSMShared(16, queue=q)
# val too big for a C int (typically 32-bit here):
q.memset(m, 2**40)
# OverflowError: Python int too large to convert to C long
# negative count into an unsigned size_t:
q.memset(m, 0xAB, -1)
# OverflowError: can't convert negative value to size_t| return nullptr; | ||
| } | ||
|
|
||
| return wrap<event>(new event(ev)); |
There was a problem hiding this comment.
| return wrap<event>(new event(ev)); | |
| return wrap<event>(new event(std::move(ev))); |
This PR proposes adding
dpctl.SyclQueue.memsetanddpctl.SyclQueue.memset_asyncmethods as a Python wrapper oversycl::queue::memsetbacked by the existingDPCTLQueue_Memsetand a newDPCTLQueue_MemsetWithEventsC-API function and adding a newtest_sycl_queue_memset.py