question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JIT: illegal Python function (with undefined variable) gives correct kernel by accident

See original GitHub issue

On the current master, the following code compiles and runs:

import cupy as cp
from cupyx import jit

@jit.rawkernel()
def f(b):
    laneId = jit.threadIdx.x & 0x1f
    if laneId == 0:
        value = cp.int64(100)
    b[laneId] = value


b = cp.empty((32,), dtype=cp.int64)
f[1, 32](b)
print(b)
print(f.cached_code)

However, a compilation error (better be NameError or UnboundLocalError) should be raised by the JIT compiler, because the variable value is not well defined for all code paths.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
leofangcommented, Jun 30, 2021

Thanks, @asi1024!

Current CuPy JIT already supports y = numpy.float32(12.) to specify the dtype of a local variable. We can support more additional styles like y = x.dtype.type(1.) or y: numpy.float32 = 1.

Sorry for my slow action…(still on vacation) I just opened an issue to track this feature request (#5417).

For example, do we pass a CuPy array or a NumPy array to the kernel under the simulation mode? Are we able to not generate any CUDA context initialization request when using JIT?

This feature is still in the planning stage, but it will probably not rely on any CUDA context.

Sounds cool! Not that I am a big fan of such simulators, but I am definitely interested in learning how it’s implemented.

1reaction
asi1024commented, Jun 29, 2021

@leofang Sorry for my late response.

Having the ability of accessing array types (ex: b.dtype) in a kernel has additional benefits, such as supporting C++ template-like kernels and allowing user-managed explicit casting. For example, Numba supports statements like y = x.dtype.type(1.) and y = numba.float32(12.) in a kernel. I think it’s best to be discussed separately. Let me open a new issue.

Current CuPy JIT already supports y = numpy.float32(12.) to specify the dtype of a local variable. We can support more additional styles like y = x.dtype.type(1.) or y: numpy.float32 = 1.

For example, do we pass a CuPy array or a NumPy array to the kernel under the simulation mode? Are we able to not generate any CUDA context initialization request when using JIT?

This feature is still in the planning stage, but it will probably not rely on any CUDA context.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting and tips — Numba 0.50.1 documentation
The most common reason for slowness of a compiled JIT function is that compiling in nopython mode has failed and the Numba compiler...
Read more >
python - numba nopython mode "Undefined variable '$313.3'"
I tend to profile in a Jupyter notebook using the %timeit magic. When profiling Numba code especially you need to throw out the...
Read more >
Release Notes - Numba documentation - Read the Docs
Version 0.52.0 (30 November, 2020)¶. This release focuses on performance improvements, but also adds some new features and contains numerous bug fixes and ......
Read more >
Intel®oneAPI ProgrammingGuide
Intel oneAPI Math Kernel Library (oneMKL) . ... Undefined (the SETVARS_CONFIG environment variable does not exist).
Read more >
Tree - rpms/kernel - CentOS Git server
This macro does requires, provides, conflicts, obsoletes for a kernel package. ... x86/crash: Correct the address boundary of function parameters (Lianbo ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found