numba-dpex icon indicating copy to clipboard operation
numba-dpex copied to clipboard

numba-dpex doesn't allow range multiplications inside NdRange

Open rohan11235813 opened this issue 2 years ago • 3 comments

Below is a valid sycl code where we are allowed to multiply two sycl::range objects.

sycl::range<3> dimBlock(1, 1, BLOCK_SIZE);
sycl::range<3> dimGrid(1, 1, blockCols);
cgh.parallel_for(sycl::nd_range<3>(dimGrid * dimBlock, dimBlock), [=](sycl::nd_item<3> item_ct1) {}

dimBlock * dimGrid is expected to produce range object with dimensions (1, 1, blockCols* BLOCK_SIZE) in this case. However this isn't allowed in numba-dpex ndrange.

dimBlock = numba_dpex.Range(1,1,BLOCK_SIZE)
dimGrid = numba_dpex.Range(1,1,int(blockCols))
sample_kernel[numba_dpex.NdRange(dimGrid*dimBlock,dimBlock)]()

This throws an error: TypeError: can't multiply sequence by non-int of type 'Range'

rohan11235813 avatar Oct 05 '23 20:10 rohan11235813

dimGrid and dimBlock are a Range objects, a Range is basically a tuple of ints., therefore you can't multiply two Ranges.

The Range and NdRange classes are defined here:

https://github.com/IntelPython/numba-dpex/blob/main/numba_dpex/core/kernel_interface/indexers.py

and to see how to use Range and NdRange, you can refer to these examples:

https://github.com/IntelPython/numba-dpex/blob/a92e9b37de455c21e6a0bf24aa3e03f0a839da82/numba_dpex/examples/kernel/matmul.py#L39

https://github.com/IntelPython/numba-dpex/blob/a92e9b37de455c21e6a0bf24aa3e03f0a839da82/numba_dpex/examples/kernel/pairwise_distance.py#L59

https://github.com/IntelPython/numba-dpex/blob/a92e9b37de455c21e6a0bf24aa3e03f0a839da82/numba_dpex/examples/kernel/interpolation.py#L123

chudur-budur avatar Dec 11 '23 19:12 chudur-budur

In SYCL, two sycl::range objects can be multiplied. I think we can do something similar with Range/NdRange as well.

@roxx30198 could you please post a complete code? Also what does the structure look like when you multiply two sycl::range objects?

It's a new feature that needs to be implemented.

chudur-budur avatar Dec 19 '23 20:12 chudur-budur

In SYCL, two sycl::range objects can be multiplied. I think we can do something similar with Range/NdRange as well.

@roxx30198 could you please post a complete code? Also what does the structure look like when you multiply two sycl::range objects?

It's a new feature that needs to be implemented.

Added the expected output. I couldn't get to exactly print the dimensions of final range object but I have verified it is the multiplication of corresponding elements in the tuple.

rohan11235813 avatar Dec 20 '23 02:12 rohan11235813