Skip to content

Commit b109496

Browse files
author
Diptorup Deb
committed
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.
1 parent 2b5bbe9 commit b109496

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

numba_dpex/core/parfors/kernel_builder.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from numba_dpex import config
2929

3030
from ..descriptor import dpex_kernel_target
31-
from ..types.dpnp_ndarray_type import DpnpNdArray
31+
from ..types import DpnpNdArray, USMNdArray
3232
from ..utils.kernel_templates import RangeKernelTemplate
3333

3434

@@ -70,6 +70,30 @@ def _compile_kernel_parfor(
7070
func_ir, kernel_name
7171
)
7272

73+
# A cast from DpnpNdArray type to USMNdArray is needed for all arguments of
74+
# DpnpNdArray type. Although, DpnpNdArray derives from USMNdArray the two
75+
# types use different data models. USMNdArray uses the
76+
# numba_dpex.core.datamodel.models.ArrayModel data model that defines all
77+
# CPointer type members in the GLOBAL address space. The DpnpNdArray uses
78+
# Numba's default ArrayModel that does not define pointers in any specific
79+
# address space. For OpenCL HD Graphics devices, defining a kernel function
80+
# (spir_kernel calling convention) with pointer arguments that have no
81+
# address space qualifier causes a run time crash. By casting the argument
82+
# type for parfor arguments from DpnpNdArray type to the USMNdArray type the
83+
# generated kernel always has an address space qualifier, avoiding the issue
84+
# on OpenCL HD graphics devices.
85+
86+
for i, argty in enumerate(argtypes):
87+
if isinstance(argty, DpnpNdArray):
88+
new_argty = USMNdArray(
89+
ndim=argty.ndim,
90+
layout=argty.layout,
91+
dtype=argty.dtype,
92+
usm_type=argty.usm_type,
93+
queue=argty.queue,
94+
)
95+
argtypes[i] = new_argty
96+
7397
# compile the kernel
7498
kernel.compile(
7599
args=argtypes,

0 commit comments

Comments
 (0)