-
Notifications
You must be signed in to change notification settings - Fork 30
Subdevices work #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subdevices work #326
Conversation
2 notes being worked on
|
Yes, the pitfalls of our C API design. You can pass |
Resolved conflicts by keep changes on both sides
…SubDevicesEqually and others
Work on:
|
@diptorupd , @oleksandr-pavlyk could you please take a look and write what need to be changed? |
This kind of worked: In [8]: import numpy as np
In [9]: d.create_sub_devices_by_counts(np.array([2, 2, 2, 2, 2, 2], dtype=np.uint64), 6)
Out[9]:
[<dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz] at 0x7ffa9fa9a2f0>,
<dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz] at 0x7ffa9fa9a5f0>,
<dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz] at 0x7ffab44157b0>,
<dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz] at 0x7ffab4415770>,
<dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz] at 0x7ffab4415cb0>,
<dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz] at 0x7ffab4415830>] but it should be unnecessary to specify length 6 as the second argument. It also should not be needed to use numpy array for this. Using list should be supported, so I would have expected create by partition should raise an error here, rather than return an empty list In [12]: d.max_compute_units
Out[12]: 12
In [13]: d.create_sub_devices_equally(12)
Native API failed. Native API returns: -18 (CL_DEVICE_PARTITION_FAILED) -18 (CL_DEVICE_PARTITION_FAILED)
Out[13]: [] This worked fine.
I thought we discussed that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there. Looking good.
cdef DPCTLDeviceVectorRef DVRef = NULL | ||
DVRef = DPCTLDevice_CreateSubDevicesByAffinity(self._device_ref, domain) | ||
if DVRef is NULL: | ||
self._raise_sub_devices_creation_error("DPCTLSubDeviceCreationError", -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oleksandr-pavlyk Will Cython ever raise this exception? Should the cdef function have except +
added to the signature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1e-to can you check if Cython raises this exception? Would be good to have a negative test case to see if an exception is raised.
Refer Sasha's comments in #35 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it raises
>>> d = dpctl.SyclDevice("cpu")
>>> d.create_sub_devices("L2_cache")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dpctl/_sycl_device.pyx", line 268, in dpctl._sycl_device.SyclDevice.create_sub_devices
return self.create_sub_devices_by_affinity(domain_type)
File "dpctl/_sycl_device.pyx", line 241, in dpctl._sycl_device.SyclDevice.create_sub_devices_by_affinity
self._raise_sub_devices_creation_error("DPCTLSubDeviceCreationError", -1)
File "dpctl/_sycl_device.pyx", line 195, in dpctl._sycl_device.SyclDevice._raise_sub_devices_creation_error
raise e
dpctl._sycl_device.SubDeviceCreationError: Sub-devices were not created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1e-to Please add some negative test cases where we check if the exception is raised.
if DVRef is NULL: | ||
self._raise_sub_devices_creation_error("DPCTLSubDeviceCreationError", -1) | ||
cdef list devices = _get_devices(DVRef) | ||
free(counts_buff) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if memory was allocated, but DVRef
was NULL, the memory would never be freed.
I fixed this issue in #343
e = SubDeviceCreationError("Sub-devices were not created.") | ||
e.fname = fname | ||
e.code = errcode | ||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function serves no purpose. It is deleted in #343
Object e
derives from Exception
, which does not have attributes fname
or code
. Lines 193-194 dynamically add these attributes to the exception instance, but they go unused.
Calls self._raise_sub_devices_creation_error("DPCTLSubDeviceCreationError", -1)
have been replaced with raise SubDeviceCreationError("Sub-devices were not created.")
in #343
is created. | ||
""" | ||
cdef size_t ncounts = len(counts) | ||
cdef size_t *counts_buff = <size_t *> malloc(ncounts * sizeof(size_t)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must check that pointer counts_buff
is not NULL
, and raise MemoryError
if it is.
In any case, null pointer should not be dereferenced. Fixed in #343
def create_sub_devices(self, partition): | ||
if isinstance(partition, int) and partition > 0: | ||
return self.create_sub_devices_equally(partition) | ||
elif isinstance(partition, list) and all([i > 0 for i in partition]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all([i>0 for i in partition])
is redundant. It is being checked as part of conversion from element of partition to size_t on lines 223-224.
else: | ||
raise Exception('Unsupported type of domain') | ||
return self.create_sub_devices_by_affinity(domain_type) | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reworked this dispatch in #343 to require keyword partition
, so that device.create_sub_devices(4)
must become device.create_sub_devices(partition=4)
to work.
Changes allow allow for list/tuples/numpy arrays for specify partition by counts.
In [1]: import dpctl, numpy as np
In [2]: [di.max_compute_units for di in dpctl.SyclDevice("cpu").create_sub_devices(partition=np.array([2, 6])) ]
Out[2]: [2, 6]
In [1]: import dpctl, numpy as np
In [2]: [di.max_compute_units for di in dpctl.SyclDevice("cpu").create_sub_devices(partition=np.array([2, 6])) ]
Out[2]: [2, 6]
In [4]: [di.max_compute_units for di in dpctl.SyclDevice("cpu").create_sub_devices(partition = [2, 6, 4]) ]
Out[4]: [2, 6, 4]
In [5]: [di.max_compute_units for di in dpctl.SyclDevice("cpu").create_sub_devices(partition = (2, 6, 4)) ]
Out[5]: [2, 6, 4]
Also use of NumPy integral types is supported:
In [6]: dpctl.SyclDevice("cpu").create_sub_devices(partition=np.int32(4))
Out[6]:
[<dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz] at 0x7f1f698727b0>,
<dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz] at 0x7f1f69872c30>,
<dpctl.SyclDevice [backend_type.opencl, device_type.cpu, Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz] at 0x7f1f69872d30>]
Closing this PR, since the superseding PR #326 has been merged. |
Closes #290