diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index 782e2eb08e..5293b8fa75 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -20,8 +20,6 @@ """ This file declares the SyclDevice extension type. """ -from libcpp cimport bool -from libc.stdint cimport uint32_t from ._backend cimport ( DPCTLSyclDeviceRef, DPCTLSyclDeviceSelectorRef, @@ -32,18 +30,10 @@ cdef class _SyclDevice: ''' Wrapper class for a Sycl Device ''' cdef DPCTLSyclDeviceRef _device_ref - cdef bool _accelerator_device - cdef bool _cpu_device - cdef bool _gpu_device - cdef bool _host_device cdef const char *_vendor_name cdef const char *_device_name cdef const char *_driver_version - cdef uint32_t _max_compute_units - cdef uint32_t _max_work_item_dims cdef size_t *_max_work_item_sizes - cdef size_t _max_work_group_size - cdef uint32_t _max_num_sub_groups cdef class SyclDevice(_SyclDevice): @@ -54,17 +44,3 @@ cdef class SyclDevice(_SyclDevice): cdef int _init_from__SyclDevice(self, _SyclDevice other) cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef) cdef DPCTLSyclDeviceRef get_device_ref(self) - cpdef get_backend(self) - cpdef get_device_name(self) - cpdef get_device_type(self) - cpdef get_vendor_name(self) - cpdef get_driver_version(self) - cpdef get_max_compute_units(self) - cpdef get_max_work_item_dims(self) - cpdef get_max_work_item_sizes(self) - cpdef get_max_work_group_size(self) - cpdef get_max_num_sub_groups(self) - cpdef is_accelerator(self) - cpdef is_cpu(self) - cpdef is_gpu(self) - cpdef is_host(self) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 016f249aa5..cdfcfca4dc 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -55,6 +55,7 @@ from ._backend cimport ( DPCTLSyclDeviceType, ) from . import backend_type, device_type +from libc.stdint cimport uint32_t import warnings __all__ = [ @@ -91,7 +92,7 @@ cdef class SyclDevice(_SyclDevice): # Create a SyclDevice with an explicit filter string, in # this case the first level_zero gpu device. level_zero_gpu = dpctl.SyclDevice("level_zero:gpu:0"): - level_zero_gpu.dump_device_info() + level_zero_gpu.print_device_info() - by calling one of the device selector helper functions: @@ -110,7 +111,7 @@ cdef class SyclDevice(_SyclDevice): # Create a SyclDevice of type GPU based on whatever is returned # by the SYCL `gpu_selector` device selector class. gpu = dpctl.select_gpu_device(): - gpu.dump_device_info() + gpu.print_device_info() """ @staticmethod @@ -119,17 +120,6 @@ cdef class SyclDevice(_SyclDevice): device._device_name = DPCTLDevice_GetName(DRef) device._driver_version = DPCTLDevice_GetDriverInfo(DRef) device._vendor_name = DPCTLDevice_GetVendorName(DRef) - device._accelerator_device = DPCTLDevice_IsAccelerator(DRef) - device._cpu_device = DPCTLDevice_IsCPU(DRef) - device._gpu_device = DPCTLDevice_IsGPU(DRef) - device._host_device = DPCTLDevice_IsHost(DRef) - device._max_compute_units = DPCTLDevice_GetMaxComputeUnits(DRef) - if (device._host_device): - device._max_num_sub_groups = -1 - else: - device._max_num_sub_groups = DPCTLDevice_GetMaxNumSubGroups(DRef) - device._max_work_group_size = DPCTLDevice_GetMaxWorkGroupSize(DRef) - device._max_work_item_dims = DPCTLDevice_GetMaxWorkItemDims(DRef) device._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes(DRef) @staticmethod @@ -145,18 +135,10 @@ cdef class SyclDevice(_SyclDevice): return -1 self._device_name = DPCTLDevice_GetName(self._device_ref) self._driver_version = DPCTLDevice_GetDriverInfo(self._device_ref) - self._max_compute_units = other._max_compute_units - self._max_num_sub_groups = other._max_num_sub_groups - self._max_work_group_size = other._max_work_group_size - self._max_work_item_dims = other._max_work_item_dims self._max_work_item_sizes = ( DPCTLDevice_GetMaxWorkItemSizes(self._device_ref) ) self._vendor_name = DPCTLDevice_GetVendorName(self._device_ref) - self._accelerator_device = other._accelerator_device - self._cpu_device = other._cpu_device - self._gpu_device = other._gpu_device - self._host_device = other._host_device cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef): # Initialize the attributes of the SyclDevice object @@ -169,7 +151,6 @@ cdef class SyclDevice(_SyclDevice): def __cinit__(self, arg=None): cdef DPCTLSyclDeviceSelectorRef DSRef = NULL - cdef DPCTLSyclDeviceRef DRef = NULL cdef const char *filter_c_str = NULL cdef int ret = 0 @@ -179,7 +160,9 @@ cdef class SyclDevice(_SyclDevice): DSRef = DPCTLFilterSelector_Create(filter_c_str) ret = self._init_from_selector(DSRef) if ret == -1: - raise ValueError("Could not create a Device with the selector") + raise ValueError( + "Could not create a SyclDevice with the selector string" + ) # Free up the device selector DPCTLDeviceSelector_Delete(DSRef) elif isinstance(arg, unicode): @@ -188,40 +171,52 @@ cdef class SyclDevice(_SyclDevice): DSRef = DPCTLFilterSelector_Create(filter_c_str) ret = self._init_from_selector(DSRef) if ret == -1: - raise ValueError("Could not create a Device with the selector") + raise ValueError( + "Could not create a SyclDevice with the selector string" + ) # Free up the device selector DPCTLDeviceSelector_Delete(DSRef) elif isinstance(arg, _SyclDevice): ret = self._init_from__SyclDevice(arg) if ret == -1: - raise ValueError("Could not create a Device from _SyclDevice instance") + raise ValueError( + "Could not create a SyclDevice from _SyclDevice instance" + ) elif arg is None: DSRef = DPCTLDefaultSelector_Create() ret = self._init_from_selector(DSRef) if ret == -1: - raise ValueError("Could not create a Device from default selector") + raise ValueError( + "Could not create a SyclDevice from default selector" + ) else: raise ValueError( "Invalid argument. Argument should be a str object specifying " "a SYCL filter selector string." ) - def dump_device_info(self): + def print_device_info(self): """ Print information about the SYCL device. """ - warnings.warn( - "WARNING: dump_device_info is deprecated and will be removed in " - "a future release of dpctl. Use print_device_info instead." - ) DPCTLDeviceMgr_PrintDeviceInfo(self._device_ref) + cdef DPCTLSyclDeviceRef get_device_ref (self): + """ Returns the DPCTLSyclDeviceRef pointer for this class. + """ + return self._device_ref - def print_device_info(self): - """ Print information about the SYCL device. + def addressof_ref(self): """ - DPCTLDeviceMgr_PrintDeviceInfo(self._device_ref) + Returns the address of the DPCTLSyclDeviceRef pointer as a size_t. - cpdef get_backend(self): + Returns: + int: The address of the DPCTLSyclDeviceRef object used to create + this SyclDevice cast to a size_t. + """ + return int(self._device_ref) + + @property + def backend(self): """Returns the backend_type enum value for this device Returns: @@ -241,12 +236,8 @@ cdef class SyclDevice(_SyclDevice): else: raise ValueError("Unknown backend type.") - cpdef get_device_name(self): - """ Returns the name of the device as a string - """ - return self._device_name.decode() - - cpdef get_device_type(self): + @property + def device_type(self): """ Returns the type of the device as a `device_type` enum. Returns: @@ -270,110 +261,6 @@ cdef class SyclDevice(_SyclDevice): else: raise ValueError("Unknown device type.") - cpdef get_vendor_name(self): - """ Returns the device vendor name as a string - """ - return self._vendor_name.decode() - - cpdef get_driver_version(self): - """ Returns the OpenCL software driver version as a string - in the form: major number.minor number, if this SYCL - device is an OpenCL device. Returns a string class - with the value "1.2" if this SYCL device is a host device. - """ - return self._driver_version.decode() - - cpdef get_max_compute_units(self): - """ Returns the number of parallel compute units - available to the device. The minimum value is 1. - """ - return self._max_compute_units - - cpdef get_max_work_item_dims(self): - """ Returns the maximum dimensions that specify - the global and local work-item IDs used by the - data parallel execution model. The minimum - value is 3 if this SYCL device is not of device - type ``info::device_type::custom``. - """ - return self._max_work_item_dims - - cpdef get_max_work_item_sizes(self): - """ Returns the maximum number of work-items - that are permitted in each dimension of the - work-group of the nd_range. The minimum - value is (1; 1; 1) for devices that are not of - device type ``info::device_type::custom``. - """ - max_work_item_sizes = [] - for n in range(3): - max_work_item_sizes.append(self._max_work_item_sizes[n]) - return tuple(max_work_item_sizes) - - cpdef get_max_work_group_size(self): - """ Returns the maximum number of work-items - that are permitted in a work-group executing a - kernel on a single compute unit. The minimum - value is 1. - """ - return self._max_work_group_size - - cpdef get_max_num_sub_groups(self): - """ Returns the maximum number of sub-groups - in a work-group for any kernel executed on the - device. The minimum value is 1. - """ - return self._max_num_sub_groups - - cpdef is_accelerator(self): - """ Returns True if the SyclDevice instance is a SYCL accelerator - device. - - Returns: - bool: True if the SyclDevice is a SYCL accelerator device, - else False. - """ - return self._accelerator_device - - cpdef is_cpu(self): - """ Returns True if the SyclDevice instance is a SYCL CPU device. - - Returns: - bool: True if the SyclDevice is a SYCL CPU device, else False. - """ - return self._cpu_device - - cpdef is_gpu(self): - """ Returns True if the SyclDevice instance is a SYCL GPU device. - - Returns: - bool: True if the SyclDevice is a SYCL GPU device, else False. - """ - return self._gpu_device - - cpdef is_host(self): - """ Returns True if the SyclDevice instance is a SYCL host device. - - Returns: - bool: True if the SyclDevice is a SYCL host device, else False. - """ - return self._host_device - - cdef DPCTLSyclDeviceRef get_device_ref (self): - """ Returns the DPCTLSyclDeviceRef pointer for this class. - """ - return self._device_ref - - def addressof_ref(self): - """ - Returns the address of the DPCTLSyclDeviceRef pointer as a size_t. - - Returns: - int: The address of the DPCTLSyclDeviceRef object used to create - this SyclDevice cast to a size_t. - """ - return int(self._device_ref) - @property def has_aspect_host(self): cdef _aspect_type AT = _aspect_type._host @@ -473,11 +360,126 @@ cdef class SyclDevice(_SyclDevice): DPCTLDeviceSelector_Delete(DSRef) return score + @property + def is_accelerator(self): + """ Returns True if the SyclDevice instance is a SYCL accelerator + device. + + Returns: + bool: True if the SyclDevice is a SYCL accelerator device, + else False. + """ + return DPCTLDevice_IsAccelerator(self._device_ref) + + @property + def is_cpu(self): + """ Returns True if the SyclDevice instance is a SYCL CPU device. + + Returns: + bool: True if the SyclDevice is a SYCL CPU device, else False. + """ + return DPCTLDevice_IsCPU(self._device_ref) + + @property + def is_gpu(self): + """ Returns True if the SyclDevice instance is a SYCL GPU device. + + Returns: + bool: True if the SyclDevice is a SYCL GPU device, else False. + """ + return DPCTLDevice_IsGPU(self._device_ref) + + @property + def is_host(self): + """ Returns True if the SyclDevice instance is a SYCL host device. + + Returns: + bool: True if the SyclDevice is a SYCL host device, else False. + """ + return DPCTLDevice_IsHost(self._device_ref) + + @property + def max_work_item_dims(self): + """ Returns the maximum dimensions that specify + the global and local work-item IDs used by the + data parallel execution model. The cb + value is 3 if this SYCL device is not of device + type ``info::device_type::custom``. + """ + cdef uint32_t max_work_item_dims = 0 + max_work_item_dims = DPCTLDevice_GetMaxWorkItemDims(self._device_ref) + return max_work_item_dims + + @property + def max_work_item_sizes(self): + """ Returns the maximum number of work-items + that are permitted in each dimension of the + work-group of the nd_range. The minimum + value is (1; 1; 1) for devices that are not of + device type ``info::device_type::custom``. + """ + return ( + self._max_work_item_sizes[0], + self._max_work_item_sizes[1], + self._max_work_item_sizes[2], + ) + + @property + def max_compute_units(self): + """ Returns the number of parallel compute units + available to the device. The minimum value is 1. + """ + cdef uint32_t max_compute_units = 0 + max_compute_units = DPCTLDevice_GetMaxComputeUnits(self._device_ref) + return max_compute_units + + @property + def max_work_group_size(self): + """ Returns the maximum number of work-items + that are permitted in a work-group executing a + kernel on a single compute unit. The minimum + value is 1. + """ + cdef uint32_t max_work_group_size = 0 + max_work_group_size = DPCTLDevice_GetMaxWorkGroupSize(self._device_ref) + return max_work_group_size + + @property + def max_num_sub_groups(self): + """ Returns the maximum number of sub-groups + in a work-group for any kernel executed on the + device. The minimum value is 1. + """ + cdef uint32_t max_num_sub_groups = 0 + if (not self.is_host): + max_num_sub_groups = ( + DPCTLDevice_GetMaxNumSubGroups(self._device_ref) + ) + return max_num_sub_groups + + @property + def vendor_name(self): + """ Returns the device vendor name as a string. + """ + return self._vendor_name.decode() + + @property + def driver_version(self): + """ Returns a backend-defined driver version as a string. + """ + return self._driver_version.decode() + + @property + def device_name(self): + """ Returns the name of the device as a string + """ + return self._device_name.decode() + @property def __name__(self): return "SyclDevice" def __repr__(self): return ("".format(hex(id(self))) ) + str(self.backend) + ", " + str(self.device_type) +", " + + " " + self.device_name + "] at {}>".format(hex(id(self))) ) diff --git a/dpctl/_sycl_queue_manager.pyx b/dpctl/_sycl_queue_manager.pyx index 848456cac8..e9e2ac78c5 100644 --- a/dpctl/_sycl_queue_manager.pyx +++ b/dpctl/_sycl_queue_manager.pyx @@ -144,7 +144,7 @@ cdef class _SyclQueueManager: device_type: The SYCL device type for the currently selected queue. Possible values can be gpu, cpu, accelerator, or host. """ - return self.get_current_queue().get_sycl_device().get_device_type() + return self.get_current_queue().get_sycl_device().device_type cpdef SyclQueue get_current_queue(self): """ diff --git a/dpctl/tests/test_dump_functions.py b/dpctl/tests/test_dump_functions.py index 2c6b924c7c..63b8a95886 100644 --- a/dpctl/tests/test_dump_functions.py +++ b/dpctl/tests/test_dump_functions.py @@ -32,12 +32,12 @@ def test_dpctl_dump(self): @unittest.skipUnless( dpctl.has_sycl_platforms(), "No SYCL devices except the default host device." ) - def test_dpctl_dump_device_info(self): + def test_dpctl_print_device_info(self): q = dpctl.get_current_queue() try: - q.get_sycl_device().dump_device_info() + q.get_sycl_device().print_device_info() except Exception: - self.fail("Encountered an exception inside dump_device_info().") + self.fail("Encountered an exception inside print_device_info().") if __name__ == "__main__": diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index 130e5cd82e..22fa118277 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -53,34 +53,34 @@ # Unit test cases that will be run for every device def check_get_max_compute_units(device): - max_compute_units = device.get_max_compute_units() + max_compute_units = device.max_compute_units assert max_compute_units > 0 def check_get_max_work_item_dims(device): - max_work_item_dims = device.get_max_work_item_dims() + max_work_item_dims = device.max_work_item_dims assert max_work_item_dims > 0 def check_get_max_work_item_sizes(device): - max_work_item_sizes = device.get_max_work_item_sizes() + max_work_item_sizes = device.max_work_item_sizes for size in max_work_item_sizes: assert size is not None def check_get_max_work_group_size(device): - max_work_group_size = device.get_max_work_group_size() + max_work_group_size = device.max_work_group_size # Special case for FPGA simulator - if device.is_accelerator(): + if device.is_accelerator: assert max_work_group_size >= 0 else: assert max_work_group_size > 0 def check_get_max_num_sub_groups(device): - max_num_sub_groups = device.get_max_num_sub_groups() + max_num_sub_groups = device.max_num_sub_groups # Special case for FPGA simulator - if device.is_accelerator() or device.is_host(): + if device.is_accelerator or device.is_host: assert max_num_sub_groups >= 0 else: assert max_num_sub_groups > 0 @@ -214,28 +214,28 @@ def check_has_aspect_usm_system_allocator(device): def check_is_accelerator(device): try: - device.is_accelerator() + device.is_accelerator except Exception: pytest.fail("is_accelerator call failed") def check_is_cpu(device): try: - device.is_cpu() + device.is_cpu except Exception: pytest.fail("is_cpu call failed") def check_is_gpu(device): try: - device.is_gpu() + device.is_gpu except Exception: pytest.fail("is_gpu call failed") def check_is_host(device): try: - device.is_host() + device.is_host except Exception: pytest.fail("is_hostcall failed") diff --git a/dpctl/tests/test_sycl_device_factory.py b/dpctl/tests/test_sycl_device_factory.py index ee718e9d39..0271f1d0fd 100644 --- a/dpctl/tests/test_sycl_device_factory.py +++ b/dpctl/tests/test_sycl_device_factory.py @@ -102,22 +102,22 @@ def device_type_str(request): def check_if_device_type_is_valid(devices): for d in devices: - assert d.get_device_type() in set(item for item in dty) + assert d.device_type in set(item for item in dty) def check_if_backend_is_valid(devices): for d in devices: - assert d.get_backend() in set(item for item in bty) + assert d.backend in set(item for item in bty) def check_if_backend_matches(devices, backend): for d in devices: - assert d.get_backend() == backend + assert d.backend == backend def check_if_device_type_matches(devices, device_type): for d in devices: - assert d.get_device_type() == device_type + assert d.device_type == device_type def test_get_devices_with_string_args(str_args): diff --git a/dpctl/tests/test_sycl_queue.py b/dpctl/tests/test_sycl_queue.py index cc0e342d12..9c1ac858a4 100644 --- a/dpctl/tests/test_sycl_queue.py +++ b/dpctl/tests/test_sycl_queue.py @@ -53,34 +53,34 @@ # Unit test cases that will be run for every device def check_get_max_compute_units(device): - max_compute_units = device.get_max_compute_units() + max_compute_units = device.max_compute_units assert max_compute_units > 0 def check_get_max_work_item_dims(device): - max_work_item_dims = device.get_max_work_item_dims() + max_work_item_dims = device.max_work_item_dims assert max_work_item_dims > 0 def check_get_max_work_item_sizes(device): - max_work_item_sizes = device.get_max_work_item_sizes() + max_work_item_sizes = device.max_work_item_sizes for size in max_work_item_sizes: assert size is not None def check_get_max_work_group_size(device): - max_work_group_size = device.get_max_work_group_size() + max_work_group_size = device.max_work_group_size # Special case for FPGA simulator - if device.is_accelerator(): + if device.is_accelerator: assert max_work_group_size >= 0 else: assert max_work_group_size > 0 def check_get_max_num_sub_groups(device): - max_num_sub_groups = device.get_max_num_sub_groups() + max_num_sub_groups = device.max_num_sub_groups # Special case for FPGA simulator - if device.is_accelerator() or device.is_host(): + if device.is_accelerator or device.is_host: assert max_num_sub_groups >= 0 else: assert max_num_sub_groups > 0 @@ -214,28 +214,28 @@ def check_has_aspect_usm_system_allocator(device): def check_is_accelerator(device): try: - device.is_accelerator() + device.is_accelerator except Exception: pytest.fail("is_accelerator call failed") def check_is_cpu(device): try: - device.is_cpu() + device.is_cpu except Exception: pytest.fail("is_cpu call failed") def check_is_gpu(device): try: - device.is_gpu() + device.is_gpu except Exception: pytest.fail("is_gpu call failed") def check_is_host(device): try: - device.is_host() + device.is_host except Exception: pytest.fail("is_hostcall failed") diff --git a/dpctl/tests/test_sycl_queue_manager.py b/dpctl/tests/test_sycl_queue_manager.py index 84d10ac015..a61d9c96d4 100644 --- a/dpctl/tests/test_sycl_queue_manager.py +++ b/dpctl/tests/test_sycl_queue_manager.py @@ -36,12 +36,12 @@ def test_dpctl_dump(self): except Exception: self.fail("Encountered an exception inside dump().") - def test_dpctl_dump_device_info(self): + def test_dpctl_print_device_info(self): q = dpctl.get_current_queue() try: - q.get_sycl_device().dump_device_info() + q.get_sycl_device().print_device_info() except Exception: - self.fail("Encountered an exception inside dump_device_info().") + self.fail("Encountered an exception inside print_device_info().") @unittest.skipIf(not dpctl.has_sycl_platforms(), "No SYCL platforms available") diff --git a/examples/python/create_sycl_queues.py b/examples/python/create_sycl_queues.py index c43e07b5b5..d3587081eb 100644 --- a/examples/python/create_sycl_queues.py +++ b/examples/python/create_sycl_queues.py @@ -43,7 +43,7 @@ print("========================================") print("Current context inside with scope") print("========================================") - cpu_queue.get_sycl_device().dump_device_info() + cpu_queue.get_sycl_device().print_device_info() # Note the current context can be either directly accessed by using # the "cpu_queue" object, or it can be accessed via the runtime's @@ -51,10 +51,10 @@ print("========================================") print("Looking up current context using runtime") print("========================================") - rt.get_current_queue().get_sycl_device().dump_device_info() + rt.get_current_queue().get_sycl_device().print_device_info() print("========================================") print("Current context after exiting with scope") print("========================================") -rt.get_current_queue().get_sycl_device().dump_device_info() +rt.get_current_queue().get_sycl_device().print_device_info() diff --git a/examples/python/usm_memory_allocation.py b/examples/python/usm_memory_allocation.py index d242a1bd9d..7fbb817e21 100644 --- a/examples/python/usm_memory_allocation.py +++ b/examples/python/usm_memory_allocation.py @@ -38,4 +38,4 @@ # information about device associate with USM buffer print("Allocation performed on device:") -mda._queue.get_sycl_device().dump_device_info() +mda._queue.get_sycl_device().print_device_info()