Skip to content

Commit c64b6d4

Browse files
committed
Add NotImplemented copy_from/copy_to
Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
1 parent 0d294e6 commit c64b6d4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

cuda_core/cuda/core/experimental/_memoryview.pyx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from ._dlpack cimport *
66
from libc.stdint cimport uintptr_t
77
from cuda.core.experimental._layout cimport StridedLayout
8+
from cuda.core.experimental._stream import Stream
89

910
import functools
1011
from typing import Optional
@@ -196,6 +197,60 @@ cdef class StridedMemoryView:
196197
view_buffer_strided(view, self.get_buffer(), layout, dtype, self.readonly)
197198
return view
198199

200+
def copy_from(
201+
self, other : StridedMemoryView, stream : Stream,
202+
allocator : MemoryResource | None = None,
203+
blocking : bool | None = None,
204+
):
205+
"""
206+
Copies the data from the other view into this view.
207+
208+
The copy can be performed between following memory spaces:
209+
host-to-device, device-to-host, device-to-device (on the same device).
210+
211+
The following conditions must be met:
212+
* Both views must have compatible shapes, i.e. the shapes must be equal
213+
or the source view's shape must be broadcastable to the target view's shape
214+
(see :meth:`StridedLayout.broadcast_to`).
215+
* Both views must have the same :attr:`dtype` (or :attr:`StridedLayout.itemsize`
216+
if :attr:`dtype` is not specified).
217+
* The destination's layout must be unique (see :meth:`StridedLayout.is_unique`).
218+
219+
Parameters
220+
----------
221+
other : StridedMemoryView
222+
The view to copy data from.
223+
stream : Stream | None, optional
224+
The stream to schedule the copy on.
225+
allocator : MemoryResource | None, optional
226+
If temporary buffers are needed, the specifed memory resources
227+
will be used to allocate the memory. If not specified, default
228+
resources will be used.
229+
blocking : bool | None, optional
230+
Whether the call should block until the copy is complete.
231+
* ``True``: the ``stream`` is synchronized with the host at the end of the call,
232+
blocking until the copy is complete.
233+
* ``False``: if possible, the call returns immediately once the copy is scheduled.
234+
However, in some cases of host-to-device or device-to-host copies, the call may
235+
still synchronize with the host if necessary.
236+
* ``None`` (default):
237+
* for device-to-device, it defaults to ``False`` (non-blocking),
238+
* for host-to-device or device-to-host, it defaults to ``True`` (blocking).
239+
"""
240+
raise NotImplementedError("Sorry, not supported: copy_from")
241+
242+
def copy_to(
243+
self, other : StridedMemoryView, stream : Stream | None = None,
244+
allocator : MemoryResource | None = None,
245+
blocking : bool | None = None,
246+
):
247+
"""
248+
Copies the data from this view into the other view.
249+
250+
For details, see :meth:`copy_from`.
251+
"""
252+
raise NotImplementedError("Sorry, not supported: copy_to")
253+
199254
@property
200255
def layout(self) -> StridedLayout:
201256
"""

0 commit comments

Comments
 (0)