Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_global_id does not work if function is directly exported #693

Closed
geexie opened this issue Feb 2, 2022 · 3 comments
Closed

get_global_id does not work if function is directly exported #693

geexie opened this issue Feb 2, 2022 · 3 comments
Assignees
Labels
kernel API About @numba_dpex.kernel decorator
Milestone

Comments

@geexie
Copy link

geexie commented Feb 2, 2022

If I try the following code

import dpctl
import base_l2_distance
import math

from numba_dppy import kernel, get_global_id, atomic, DEFAULT_LOCAL_SIZE
atomic_add = atomic.add

@kernel(access_types={"read_only": ["a", "b"], "write_only": ["c"]})
def l2_distance_kernel(a, b, c):
    i = get_global_id(0)
    j = get_global_id(1)
    sub = a[i, j] - b[i, j]
    sq = sub**2
    atomic_add(c, 0, sq)

def l2_distance(a, b, distance):
    with dpctl.device_context(base_l2_distance.get_device_selector()):
        l2_distance_kernel[(a.shape[0], a.shape[1]), DEFAULT_LOCAL_SIZE](a, b, distance)

    return math.sqrt(distance)

the following error is risen during typeinfer

  File "/nfs/site/home/mkolpako/code/miniconda3/envs/gpu_dev/lib/python3.7/site-packages/numba/core/typeinfer.py", line 1466, in resolve_value_type
    raise TypingError(msg, loc=inst.loc)
numba.core.errors.TypingError: Failed in dppy_nopython mode pipeline (step: nopython frontend)
Untyped global name 'get_global_id': Cannot determine Numba type of <class 'function'>

File "l2_distance_kernel.py", line 59:
def l2_distance_kernel(a, b, c):
    i = get_global_id(0)

Everything works if I use numba_dppy.get_global_id notation

@PokhodenkoSA
Copy link
Contributor

PokhodenkoSA commented Feb 2, 2022

Environment:
dpctl 0.11.1
numba 0.54.1
numba-dppy 0.15.0

All examples shows using this functions only via module.

@PokhodenkoSA
Copy link
Contributor

Addressed in #694.

@diptorupd diptorupd self-assigned this Oct 7, 2022
@diptorupd
Copy link
Contributor

Letting users write get_global_id instead of numba_dpex.get_global_id is a syntactic preference IMO. If we want to be more descriptive perhaps we can go the route of numba.cuda and introduce a sycl module and change all of these functions to sycl module.

from numba_dpex import sycl

@sycl.kernel
def vecadd(a,b,c):
i = sycl.get_global_id(0)
a[i] = b[i] + c[i]

Having the module qualifier is much better in terms of overall readability and letting users know that the code is specific to the numba_dpex kernel API and will not work outside of the kernel function or without the kernel decorator. I am opening a separate issue #795 to track that work.

Supporting these intrinsic functions directly without using the module name is not going to be added at this moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel API About @numba_dpex.kernel decorator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants