Skip to content

Commit

Permalink
Pass all parfor kernel array arg types as USMNdArray.
Browse files Browse the repository at this point in the history
   - 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.
  • Loading branch information
Diptorup Deb committed Jun 17, 2023
1 parent 2b5bbe9 commit b109496
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion numba_dpex/core/parfors/kernel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b109496

Please sign in to comment.