From 8f50e09218e113d054932508c2477420b558c473 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Fri, 16 Jun 2023 18:17:09 -0500 Subject: [PATCH 1/2] Add repr and str methods to DpnpNdarray and USMNdarray types. --- numba_dpex/core/types/dpnp_ndarray_type.py | 6 ++++++ numba_dpex/core/types/usm_ndarray_type.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/numba_dpex/core/types/dpnp_ndarray_type.py b/numba_dpex/core/types/dpnp_ndarray_type.py index 75d77141c4..04edec02b1 100644 --- a/numba_dpex/core/types/dpnp_ndarray_type.py +++ b/numba_dpex/core/types/dpnp_ndarray_type.py @@ -58,6 +58,12 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): else: return + def __str__(self): + return self.name.replace("USMNdArray", "DpnpNdarray") + + def __repr__(self): + return self.__str__() + def __allocate__( self, typingctx, diff --git a/numba_dpex/core/types/usm_ndarray_type.py b/numba_dpex/core/types/usm_ndarray_type.py index f6eb08564f..f5d83783b1 100644 --- a/numba_dpex/core/types/usm_ndarray_type.py +++ b/numba_dpex/core/types/usm_ndarray_type.py @@ -87,7 +87,7 @@ def __init__( self.dtype = dtype if name is None: - type_name = "usm_ndarray" + type_name = "USMNdArray" if readonly: type_name = "readonly " + type_name if not aligned: @@ -116,6 +116,9 @@ def __init__( aligned=aligned, ) + def __repr__(self): + return self.name + def copy( self, dtype=None, From 7832c835efee1736e7ed45f81722fb6a4bd117c8 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Fri, 16 Jun 2023 21:56:26 -0500 Subject: [PATCH 2/2] Pass all parfor kernel array arg types as USMNdArray. - Previously, any dpnp.ndarray objects used as an argument in a parfor was a numba_dpex.core.types.DpnpNdArray. The commit changes that and casts all dpnp.ndarray arguments of a parfor to numba_dpex.core.types.USMNdArray. The reason for the change is as follows: Although, DpnpNdArray derives from USMNdArray the two types use different data models. USMNdArray uses the numba_dpex.core.datamodel.models.ArrayModel data model that defines all CPointer type members in the GLOBAL address space. The DpnpNdArray uses Numba's default ArrayModel that does not define pointers in any specific address space. For OpenCL HD Graphics devices, defining a kernel function (spir_kernel calling convention) with pointer arguments that have no address space qualifier causes a run time crash. By casting the argument type for parfor arguments from DpnpNdArray type to the USMNdArray type the generated kernel always has an address space qualifier, avoiding the issue on OpenCL HD graphics devices. --- numba_dpex/core/parfors/kernel_builder.py | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/numba_dpex/core/parfors/kernel_builder.py b/numba_dpex/core/parfors/kernel_builder.py index 7200a6e62a..a941e03c10 100644 --- a/numba_dpex/core/parfors/kernel_builder.py +++ b/numba_dpex/core/parfors/kernel_builder.py @@ -28,7 +28,7 @@ from numba_dpex import config from ..descriptor import dpex_kernel_target -from ..types.dpnp_ndarray_type import DpnpNdArray +from ..types import DpnpNdArray, USMNdArray from ..utils.kernel_templates import RangeKernelTemplate @@ -70,6 +70,30 @@ def _compile_kernel_parfor( func_ir, kernel_name ) + # A cast from DpnpNdArray type to USMNdArray is needed for all arguments of + # DpnpNdArray type. Although, DpnpNdArray derives from USMNdArray the two + # types use different data models. USMNdArray uses the + # numba_dpex.core.datamodel.models.ArrayModel data model that defines all + # CPointer type members in the GLOBAL address space. The DpnpNdArray uses + # Numba's default ArrayModel that does not define pointers in any specific + # address space. For OpenCL HD Graphics devices, defining a kernel function + # (spir_kernel calling convention) with pointer arguments that have no + # address space qualifier causes a run time crash. By casting the argument + # type for parfor arguments from DpnpNdArray type to the USMNdArray type the + # generated kernel always has an address space qualifier, avoiding the issue + # on OpenCL HD graphics devices. + + for i, argty in enumerate(argtypes): + if isinstance(argty, DpnpNdArray): + new_argty = USMNdArray( + ndim=argty.ndim, + layout=argty.layout, + dtype=argty.dtype, + usm_type=argty.usm_type, + queue=argty.queue, + ) + argtypes[i] = new_argty + # compile the kernel kernel.compile( args=argtypes,