Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions dpctl/_sycl_context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ cdef class SyclContext(_SyclContext):
)
elif (ret == -6):
raise TypeError(
"Input capsule {} contains a null pointer or could not be"
" renamed".format(arg)
f"Input capsule {arg} contains a null pointer or could not "
"be renamed"
)
raise ValueError(
"Unrecognized error code ({}) encountered.".format(ret)
f"Unrecognized error code ({ret}) encountered."
)

cdef bool equals(self, SyclContext ctxt):
Expand Down Expand Up @@ -471,12 +471,10 @@ cdef class SyclContext(_SyclContext):
"""
cdef size_t n = self.device_count
if n == 1:
return ("<dpctl." + self.__name__ + " at {}>".format(hex(id(self))))
return f"<dpctl.{self.__name__} at {hex(id(self))}>"
else:
return (
"<dpctl."
+ self.__name__
+ " for {} devices at {}>".format(n, hex(id(self)))
f"<dpctl.{self.__name__} for {n} devices at {hex(id(self))}>"
)

def _get_capsule(self):
Expand Down
16 changes: 6 additions & 10 deletions dpctl/_sycl_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ cdef class SyclDevice(_SyclDevice):
if ret == -1:
raise SyclDeviceCreationError(
"Could not create a SyclDevice with the selector string "
"'{selector_string}'".format(selector_string=arg)
f"'{arg}'"
)
elif isinstance(arg, _SyclDevice):
ret = self._init_from__SyclDevice(arg)
Expand Down Expand Up @@ -1577,7 +1577,7 @@ cdef class SyclDevice(_SyclDevice):
+ ", "
+ " "
+ self.name
+ "] at {}>".format(hex(id(self)))
+ f"] at {hex(id(self))}>"
)

def __hash__(self):
Expand Down Expand Up @@ -1651,7 +1651,7 @@ cdef class SyclDevice(_SyclDevice):
counts_buff = <size_t *> malloc((<size_t> ncounts) * sizeof(size_t))
if counts_buff is NULL:
raise MemoryError(
"Allocation of counts array of size {} failed.".format(ncounts)
f"Allocation of counts array of size {ncounts} failed."
)
for i in range(ncounts):
counts_buff[i] = counts[i]
Expand Down Expand Up @@ -1714,10 +1714,8 @@ cdef class SyclDevice(_SyclDevice):
try:
sd = cpu_d.create_sub_devices(partition="numa")
print(
"{0} sub-devices were created with respective "
"#EUs being {1}".format(
len(sd), [d.max_compute_units for d in sd]
)
f"{len(sd)} sub-devices were created with respective "
f"#EUs being {[d.max_compute_units for d in sd]}"
)
except Exception:
print("Device partitioning by affinity was not successful.")
Expand Down Expand Up @@ -1785,9 +1783,7 @@ cdef class SyclDevice(_SyclDevice):
)
else:
raise ValueError(
"Partition affinity domain {} is not understood.".format(
partition
)
f"Partition affinity domain {partition} is not understood."
)
return self.create_sub_devices_by_affinity(domain_type)
elif isinstance(partition, collections.abc.Sized) and isinstance(
Expand Down
6 changes: 3 additions & 3 deletions dpctl/_sycl_event.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ cdef class SyclEvent(_SyclEvent):
raise ValueError("Event failed to be created.")
elif (ret == -2):
raise TypeError(
"Input capsule {} contains a null pointer or could not be"
" renamed".format(arg)
f"Input capsule {arg} contains a null pointer or could not "
"be renamed"
)
elif (ret == -3):
raise ValueError(
"Internal Error: Could not create a copy of a sycl event."
)
raise ValueError(
"Unrecognized error code ({}) encountered.".format(ret)
f"Unrecognized error code ({ret}) encountered."
)

cdef DPCTLSyclEventRef get_event_ref(self):
Expand Down
2 changes: 1 addition & 1 deletion dpctl/_sycl_platform.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ cdef class SyclPlatform(_SyclPlatform):
+ ", "
+ self.vendor
+ ", "
+ self.version + "] at {}>".format(hex(id(self)))
+ self.version + f"] at {hex(id(self))}>"
)

def __cinit__(self, arg=None):
Expand Down
41 changes: 18 additions & 23 deletions dpctl/_sycl_queue.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,12 @@ cdef int _parse_queue_properties(object prop) except *:
res = res | _queue_property_type._DEFAULT_PROPERTY
else:
raise ValueError(
(
"queue property '{}' is not understood, "
"expecting 'in_order', 'enable_profiling', or 'default'"
).format(prop)
f"queue property '{prop}' is not understood, expecting "
"'in_order', 'enable_profiling', or 'default'"
)
else:
raise ValueError(
"queue property '{}' is not understood.".format(prop)
f"queue property '{prop}' is not understood."
)
return res

Expand Down Expand Up @@ -648,7 +646,7 @@ cdef class SyclQueue(_SyclQueue):
if len(args) > 2:
raise TypeError(
"SyclQueue constructor takes 0, 1, or 2 positinal arguments, "
"but {} were given.".format(len(args))
f"but {len(args)} were given."
)
props = _parse_queue_properties(
kwargs.pop("property", _queue_property_type._DEFAULT_PROPERTY)
Expand Down Expand Up @@ -676,56 +674,55 @@ cdef class SyclQueue(_SyclQueue):
status = self._init_queue_from_capsule(arg)
else:
raise TypeError(
"Positional argument {} is not a filter string or a "
"SyclDevice".format(arg)
f"Positional argument {arg} is not a filter string or a "
"SyclDevice"
)
else:
ctx, dev = args
if not isinstance(ctx, SyclContext):
raise TypeError(
"SyclQueue constructor with two positional arguments "
"expected SyclContext as its first argument, but got {}."
.format(type(ctx))
"expected SyclContext as its first argument, but got "
f"{type(ctx)}."
)
if not isinstance(dev, SyclDevice):
raise TypeError(
"SyclQueue constructor with two positional arguments "
"expected SyclDevice as its second argument, but got {}."
.format(type(dev))
"expected SyclDevice as its second argument, but got "
f"{type(dev)}."
)
status = self._init_queue_from_context_and_device(
<SyclContext>ctx, <SyclDevice>dev, props
)
if status < 0:
if status == -1:
raise SyclQueueCreationError(
"Device filter selector string '{}' is not understood."
.format(arg)
f"Device filter selector string '{arg}' is not understood."
)
elif status == -2 or status == -8:
default_dev_error = (
"Default SYCL Device could not be created."
)
raise SyclQueueCreationError(
default_dev_error if (len_args == 0) else
"SYCL Device '{}' could not be created.".format(arg)
f"SYCL Device '{arg}' could not be created."
)
elif status == -3 or status == -7:
raise SyclQueueCreationError(
"SYCL Context could not be created " +
"by default constructor" if len_args == 0 else
"from '{}'.".format(arg)
f"from '{arg}'."
)
elif status == -4 or status == -6:
if len_args == 2:
arg = args
raise SyclQueueCreationError(
"SYCL Queue failed to be created from '{}'.".format(arg)
f"SYCL Queue failed to be created from '{arg}'."
)
elif status == -5:
raise TypeError(
"Input capsule {} contains a null pointer or could not "
"be renamed".format(arg)
f"Input capsule {arg} contains a null pointer or could not "
"be renamed"
)

cdef int _init_queue_from__SyclQueue(self, _SyclQueue other):
Expand Down Expand Up @@ -1546,12 +1543,10 @@ cdef class SyclQueue(_SyclQueue):
if en_prof:
prop.append("enable_profiling")
return (
"<dpctl."
+ self.__name__
+ " at {}, property={}>".format(hex(id(self)), prop)
f"<dpctl.{self.__name__} at {hex(id(self))}, property={prop}>"
)
else:
return "<dpctl." + self.__name__ + " at {}>".format(hex(id(self)))
return f"<dpctl.{self.__name__} at {hex(id(self))}>"

def __hash__(self):
"""
Expand Down
51 changes: 20 additions & 31 deletions dpctl/memory/_memory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def _to_memory(unsigned char[::1] b, str usm_kind):
res = MemoryUSMHost(len(b))
else:
raise ValueError(
"Unrecognized usm_kind={} stored in the "
"pickle".format(usm_kind)
f"Unrecognized usm_kind={usm_kind} stored in the pickle"
)
res.copy_from_host(b)

Expand Down Expand Up @@ -206,9 +205,8 @@ cdef class _Memory:
p = DPCTLmalloc_device(nbytes, QRef)
else:
raise RuntimeError(
"Pointer type '{}' is not recognized".format(
ptr_type.decode("UTF-8")
)
f"Pointer type '{ptr_type.decode('UTF-8')}' is not "
"recognized"
)

if (p):
Expand Down Expand Up @@ -250,13 +248,13 @@ cdef class _Memory:
self.refobj = other
else:
raise ValueError(
"Argument {} does not correctly expose"
"`__sycl_usm_array_interface__`.".format(other)
f"Argument {other} does not correctly expose"
"`__sycl_usm_array_interface__`."
)
else:
raise ValueError(
"Argument {} does not expose "
"`__sycl_usm_array_interface__`.".format(other)
f"Argument {other} does not expose "
"`__sycl_usm_array_interface__`."
)

def __dealloc__(self):
Expand Down Expand Up @@ -350,12 +348,8 @@ cdef class _Memory:

def __repr__(self):
return (
"<SYCL(TM) USM-{} allocation of {} bytes at {}>"
.format(
self.get_usm_type(),
self.nbytes,
hex(<object>(<size_t>self._memory_ptr))
)
f"<SYCL(TM) USM-{self.get_usm_type()} allocation of {self.nbytes} "
f"bytes at {hex(<object>(<size_t>self._memory_ptr))}>"
)

def __len__(self):
Expand Down Expand Up @@ -488,8 +482,8 @@ cdef class _Memory:
host_buf = obj
elif (<Py_ssize_t>len(host_buf) < self.nbytes):
raise ValueError(
"Destination object is too small to accommodate {} bytes"
.format(self.nbytes)
f"Destination object is too small to accommodate {self.nbytes} "
"bytes"
)
# call kernel to copy from
ERef = DPCTLQueue_Memcpy(
Expand All @@ -514,8 +508,8 @@ cdef class _Memory:

if (buf_len > self.nbytes):
raise ValueError(
"Source object is too large to be accommodated in {} bytes "
"buffer".format(self.nbytes)
"Source object is too large to be accommodated in "
f"{self.nbytes} bytes buffer"
)
# call kernel to copy from
ERef = DPCTLQueue_Memcpy(
Expand Down Expand Up @@ -551,7 +545,7 @@ cdef class _Memory:
if (src_buf.nbytes > self.nbytes):
raise ValueError(
"Source object is too large to "
"be accommondated in {} bytes buffer".format(self.nbytes)
f"be accommondated in {self.nbytes} bytes buffer"
)

src_queue = src_buf.queue
Expand Down Expand Up @@ -788,13 +782,12 @@ cdef class MemoryUSMShared(_Memory):
self.copy_from_device(other)
else:
raise ValueError(
"USM pointer in the argument {} is not a "
f"USM pointer in the argument {other} is not a "
"USM shared pointer. "
"Zero-copy operation is not possible with "
"copy=False. "
"Either use copy=True, or use a constructor "
"appropriate for "
"type '{}'".format(other, self.get_usm_type())
f"appropriate for type '{self.get_usm_type()}'"
)

def __getbuffer__(self, Py_buffer *buffer, int flags):
Expand Down Expand Up @@ -840,13 +833,11 @@ cdef class MemoryUSMHost(_Memory):
self.copy_from_device(other)
else:
raise ValueError(
"USM pointer in the argument {} is "
f"USM pointer in the argument {other} is "
"not a USM host pointer. "
"Zero-copy operation is not possible with copy=False. "
"Either use copy=True, or use a constructor "
"appropriate for type '{}'".format(
other, self.get_usm_type()
)
f"appropriate for type '{self.get_usm_type()}'"
)

def __getbuffer__(self, Py_buffer *buffer, int flags):
Expand Down Expand Up @@ -892,13 +883,11 @@ cdef class MemoryUSMDevice(_Memory):
self.copy_from_device(other)
else:
raise ValueError(
"USM pointer in the argument {} is not "
f"USM pointer in the argument {other} is not "
"a USM device pointer. "
"Zero-copy operation is not possible with copy=False. "
"Either use copy=True, or use a constructor "
"appropriate for type '{}'".format(
other, self.get_usm_type()
)
f"appropriate for type '{self.get_usm_type()}'"
)


Expand Down
14 changes: 6 additions & 8 deletions dpctl/memory/_sycl_usm_array_interface_utils.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ cdef class _USMBufferData:

if ary_version != 1:
raise ValueError(("__sycl_usm_array_interface__ is malformed:"
" dict('version': {}) is unexpected."
" The only recognized version is 1.").format(
ary_version))
f" dict('version': {ary_version}) is unexpected."
" The only recognized version is 1."))
if not ary_data_tuple or len(ary_data_tuple) != 2:
raise ValueError("__sycl_usm_array_interface__ is malformed:"
" 'data' field is required, and must be a tuple"
Expand All @@ -181,10 +180,9 @@ cdef class _USMBufferData:
if (QRef is NULL):
raise ValueError("__sycl_usm_array_interface__ is malformed:"
" 'data' field is not consistent with 'syclobj'"
" field, the pointer {} is not bound to"
" SyclContext derived from"
" dict('syclobj': {}).".format(
hex(arr_data_ptr), ary_syclobj))
f" field, the pointer {hex(arr_data_ptr)} is not "
"bound to SyclContext derived from "
f"dict('syclobj': {ary_syclobj}).")
# shape must be present
if ary_shape is None or not (
isinstance(ary_shape, collections.abc.Sized) and
Expand All @@ -204,7 +202,7 @@ cdef class _USMBufferData:
except TypeError as e:
raise ValueError(
"__sycl_usm_array_interface__ is malformed:"
" dict('typestr': {}) is unexpected. ".format(ary_typestr)
f" dict('typestr': {ary_typestr}) is unexpected."
) from e

if (ary_strides is None or (
Expand Down
4 changes: 1 addition & 3 deletions dpctl/tests/test_sycl_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def test_filter_string(valid_filter):
dev_id = device.filter_string
assert (
dpctl.SyclDevice(dev_id) == device
), "Reconstructed device is different, ({}, {})".format(
valid_filter, dev_id
)
), f"Reconstructed device is different, ({valid_filter}, {dev_id})"


def test_filter_string_property():
Expand Down
Loading
Loading