Skip to content

Commit 5f66623

Browse files
Formatting to stay under 80 characters lines
1 parent 465f2f2 commit 5f66623

File tree

2 files changed

+75
-46
lines changed

2 files changed

+75
-46
lines changed

dpctl/memory/_memory.pxd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,22 @@ cdef public class _Memory [object Py_MemoryObject, type Py_MemoryType]:
5151
cpdef bytes tobytes(self)
5252

5353
@staticmethod
54-
cdef public SyclDevice get_pointer_device(DPCTLSyclUSMRef p, SyclContext ctx)
54+
cdef public SyclDevice get_pointer_device(
55+
DPCTLSyclUSMRef p, SyclContext ctx)
5556
@staticmethod
5657
cdef public bytes get_pointer_type(DPCTLSyclUSMRef p, SyclContext ctx)
5758

5859

59-
cdef public class MemoryUSMShared(_Memory) [object PyMemoryUSMSharedObject, type PyMemoryUSMSharedType]:
60+
cdef public class MemoryUSMShared(_Memory) [object PyMemoryUSMSharedObject,
61+
type PyMemoryUSMSharedType]:
6062
pass
6163

6264

63-
cdef public class MemoryUSMHost(_Memory) [object PyMemoryUSMHostObject, type PyMemoryUSMHostType]:
65+
cdef public class MemoryUSMHost(_Memory) [object PyMemoryUSMHostObject,
66+
type PyMemoryUSMHostType]:
6467
pass
6568

6669

67-
cdef public class MemoryUSMDevice(_Memory) [object PyMemoryUSMDeviceObject, type PyMemoryUSMDeviceType]:
70+
cdef public class MemoryUSMDevice(_Memory) [object PyMemoryUSMDeviceObject,
71+
type PyMemoryUSMDeviceType]:
6872
pass

dpctl/memory/_memory.pyx

Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,16 @@ cdef class _Memory:
302302
return obj
303303

304304
cpdef copy_from_host(self, object obj):
305-
"""Copy content of Python buffer provided by `obj` to instance memory."""
305+
"""
306+
Copy content of Python buffer provided by `obj` to instance memory.
307+
"""
306308
cdef const unsigned char[::1] host_buf = obj
307309
cdef Py_ssize_t buf_len = len(host_buf)
308310

309311
if (buf_len > self.nbytes):
310312
raise ValueError("Source object is too large to be "
311-
"accommodated in {} bytes buffer".format(self.nbytes))
313+
"accommodated in {} bytes buffer".format(
314+
self.nbytes))
312315
# call kernel to copy from
313316
DPCTLQueue_Memcpy(
314317
self.queue.get_queue_ref(),
@@ -332,7 +335,8 @@ cdef class _Memory:
332335

333336
if (src_buf.nbytes > self.nbytes):
334337
raise ValueError("Source object is too large to "
335-
"be accommondated in {} bytes buffer".format(self.nbytes))
338+
"be accommondated in {} bytes buffer".format(
339+
self.nbytes))
336340
kind = DPCTLUSM_GetPointerType(
337341
src_buf.p, self.queue.get_sycl_context().get_context_ref())
338342
if (kind == b'unknown'):
@@ -364,107 +368,128 @@ cdef class _Memory:
364368

365369
@staticmethod
366370
cdef SyclDevice get_pointer_device(DPCTLSyclUSMRef p, SyclContext ctx):
367-
"""Returns sycl device used to allocate given pointer `p` in given sycl context `ctx`"""
368-
cdef DPCTLSyclDeviceRef dref = DPCTLUSM_GetPointerDevice(p, ctx.get_context_ref())
371+
"""
372+
Returns sycl device used to allocate given pointer `p` in
373+
given sycl context `ctx`
374+
"""
375+
cdef DPCTLSyclDeviceRef dref = DPCTLUSM_GetPointerDevice(
376+
p, ctx.get_context_ref())
369377

370378
return SyclDevice._create(dref)
371379

372380
@staticmethod
373381
cdef bytes get_pointer_type(DPCTLSyclUSMRef p, SyclContext ctx):
374382
"""Returns USM-type of given pointer `p` in given sycl context `ctx`"""
375-
cdef const char * usm_type = DPCTLUSM_GetPointerType(p, ctx.get_context_ref())
383+
cdef const char * usm_type = DPCTLUSM_GetPointerType(
384+
p, ctx.get_context_ref())
376385

377386
return <bytes>usm_type
378387

379388

380389
cdef class MemoryUSMShared(_Memory):
381390
"""
382-
MemoryUSMShared(nbytes, alignment=0, queue=None, copy=False) allocates nbytes of
383-
USM shared memory.
391+
MemoryUSMShared(nbytes, alignment=0, queue=None, copy=False)
392+
allocates nbytes of USM shared memory.
384393
385394
Non-positive alignments are not used (malloc_shared is used instead).
386395
For the queue=None cast the `dpctl.SyclQueue()` is used to allocate memory.
387396
388-
MemoryUSMShared(usm_obj) constructor create instance from `usm_obj` expected to
389-
implement `__sycl_usm_array_interface__` protocol and exposing a contiguous block of
390-
USM memory of USM shared type. Using copy=True to perform a copy if USM type is other
391-
than 'shared'.
397+
MemoryUSMShared(usm_obj) constructor create instance from `usm_obj`
398+
expected to implement `__sycl_usm_array_interface__` protocol and exposing
399+
a contiguous block of USM memory of USM shared type. Using copy=True to
400+
perform a copy if USM type is other than 'shared'.
392401
"""
393-
def __cinit__(self, other, *, Py_ssize_t alignment=0, SyclQueue queue=None, int copy=False):
402+
def __cinit__(self, other, *, Py_ssize_t alignment=0,
403+
SyclQueue queue=None, int copy=False):
394404
if (isinstance(other, numbers.Integral)):
395405
self._cinit_alloc(alignment, <Py_ssize_t>other, b"shared", queue)
396406
else:
397407
self._cinit_other(other)
398408
if (self.get_usm_type() != "shared"):
399409
if copy:
400-
self._cinit_alloc(0, <Py_ssize_t>self.nbytes, b"shared", queue)
410+
self._cinit_alloc(0, <Py_ssize_t>self.nbytes,
411+
b"shared", queue)
401412
self.copy_from_device(other)
402413
else:
403-
raise ValueError("USM pointer in the argument {} is not a USM shared pointer. "
404-
"Zero-copy operation is not possible with copy=False. "
405-
"Either use copy=True, or use a constructor appropriate for "
406-
"type '{}'".format(other, self.get_usm_type()))
414+
raise ValueError(
415+
"USM pointer in the argument {} is not a "
416+
"USM shared pointer. "
417+
"Zero-copy operation is not possible with "
418+
"copy=False. "
419+
"Either use copy=True, or use a constructor "
420+
"appropriate for "
421+
"type '{}'".format(other, self.get_usm_type()))
407422

408423
def __getbuffer__(self, Py_buffer *buffer, int flags):
409424
self._getbuffer(buffer, flags)
410425

411426

412427
cdef class MemoryUSMHost(_Memory):
413428
"""
414-
MemoryUSMHost(nbytes, alignment=0, queue=None, copy=False) allocates nbytes of
415-
USM host memory.
429+
MemoryUSMHost(nbytes, alignment=0, queue=None, copy=False)
430+
allocates nbytes of USM host memory.
416431
417432
Non-positive alignments are not used (malloc_host is used instead).
418433
For the queue=None case `dpctl.SyclQueue()` is used to allocate memory.
419434
420-
MemoryUSMDevice(usm_obj) constructor create instance from `usm_obj` expected to
421-
implement `__sycl_usm_array_interface__` protocol and exposing a contiguous block of
422-
USM memory of USM host type. Using copy=True to perform a copy if USM type is other
423-
than 'host'.
435+
MemoryUSMDevice(usm_obj) constructor create instance from `usm_obj`
436+
expected to implement `__sycl_usm_array_interface__` protocol and exposing
437+
a contiguous block of USM memory of USM host type. Using copy=True to
438+
perform a copy if USM type is other than 'host'.
424439
"""
425-
def __cinit__(self, other, *, Py_ssize_t alignment=0, SyclQueue queue=None, int copy=False):
440+
def __cinit__(self, other, *, Py_ssize_t alignment=0,
441+
SyclQueue queue=None, int copy=False):
426442
if (isinstance(other, numbers.Integral)):
427443
self._cinit_alloc(alignment, <Py_ssize_t>other, b"host", queue)
428444
else:
429445
self._cinit_other(other)
430446
if (self.get_usm_type() != "host"):
431447
if copy:
432-
self._cinit_alloc(0, <Py_ssize_t>self.nbytes, b"host", queue)
448+
self._cinit_alloc(0, <Py_ssize_t>self.nbytes,
449+
b"host", queue)
433450
self.copy_from_device(other)
434451
else:
435-
raise ValueError("USM pointer in the argument {} is not a USM host pointer. "
436-
"Zero-copy operation is not possible with copy=False. "
437-
"Either use copy=True, or use a constructor appropriate for "
438-
"type '{}'".format(other, self.get_usm_type()))
452+
raise ValueError(
453+
"USM pointer in the argument {} is "
454+
"not a USM host pointer. "
455+
"Zero-copy operation is not possible with copy=False. "
456+
"Either use copy=True, or use a constructor "
457+
"appropriate for type '{}'".format(
458+
other, self.get_usm_type()))
439459

440460
def __getbuffer__(self, Py_buffer *buffer, int flags):
441461
self._getbuffer(buffer, flags)
442462

443463

444464
cdef class MemoryUSMDevice(_Memory):
445465
"""
446-
MemoryUSMDevice(nbytes, alignment=0, queue=None, copy=False) allocates nbytes of
447-
USM device memory.
466+
MemoryUSMDevice(nbytes, alignment=0, queue=None, copy=False)
467+
allocates nbytes of USM device memory.
448468
449469
Non-positive alignments are not used (malloc_device is used instead).
450470
For the queue=None cast the `dpctl.SyclQueue()` is used to allocate memory.
451471
452-
MemoryUSMDevice(usm_obj) constructor create instance from `usm_obj` expected to
453-
implement `__sycl_usm_array_interface__` protocol and exposing a contiguous block of
454-
USM memory of USM device type. Using copy=True to perform a copy if USM type is other
455-
than 'device'.
472+
MemoryUSMDevice(usm_obj) constructor create instance from `usm_obj`
473+
expected to implement `__sycl_usm_array_interface__` protocol and exposing
474+
a contiguous block of USM memory of USM device type. Using copy=True to
475+
perform a copy if USM type is other than 'device'.
456476
"""
457-
def __cinit__(self, other, *, Py_ssize_t alignment=0, SyclQueue queue=None, int copy=False):
477+
def __cinit__(self, other, *, Py_ssize_t alignment=0,
478+
SyclQueue queue=None, int copy=False):
458479
if (isinstance(other, numbers.Integral)):
459480
self._cinit_alloc(alignment, <Py_ssize_t>other, b"device", queue)
460481
else:
461482
self._cinit_other(other)
462483
if (self.get_usm_type() != "device"):
463484
if copy:
464-
self._cinit_alloc(0, <Py_ssize_t>self.nbytes, b"device", queue)
485+
self._cinit_alloc(0, <Py_ssize_t>self.nbytes,
486+
b"device", queue)
465487
self.copy_from_device(other)
466488
else:
467-
raise ValueError("USM pointer in the argument {} is not a USM device pointer. "
468-
"Zero-copy operation is not possible with copy=False. "
469-
"Either use copy=True, or use a constructor appropriate for "
470-
"type '{}'".format(other, self.get_usm_type()))
489+
raise ValueError(
490+
"USM pointer in the argument {} is not "
491+
"a USM device pointer. "
492+
"Zero-copy operation is not possible with copy=False. "
493+
"Either use copy=True, or use a constructor "
494+
"appropriate for type '{}'".format(
495+
other, self.get_usm_type()))

0 commit comments

Comments
 (0)