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.

guvectorize in-place operations work only in some cases

See original GitHub issue

The following works, which is good (numba 0.51.2, llvmlite 0.34.0):

guvectorized function writing to the output, on GPU

@guvectorize(["(f8[:], f8[:])"], "() -> ()", target='cuda')
def test(inp, out):
    out[0] = inp[0]

feeding in device arrays: ✔️

ones = np.ones(10, dtype=np.float64)
twos = np.ones_like(ones) * 2
ones_d = numba.cuda.to_device(ones)
twos_d = numba.cuda.to_device(twos)

test(ones_d, out=twos_d)
twos_d.copy_to_host()

>>> array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

feeding in host arrays: ✔️

ones = np.ones(10, dtype=np.float64)
twos = np.ones_like(ones) * 2

test(ones, out=twos)
twos

>>> array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

guvectorized function modifying the output, on GPU

@guvectorize(["(f8[:], f8[:])"], "() -> ()", target='cuda')
def inplace_test(inp, out):
    out[0] += inp[0]    

feeding in device arrays: ✔️

ones = np.ones(10, dtype=np.float64)
twos = np.ones_like(ones) * 2
ones_d = numba.cuda.to_device(ones)
twos_d = numba.cuda.to_device(twos)

inplace_test(ones_d, out=twos_d)
twos_d.copy_to_host()

>>> array([3., 3., 3., 3., 3., 3., 3., 3., 3., 3.])

But this does not work:

feeding in host arrays: ❌

ones = np.ones(10, dtype=np.float64)
twos = np.ones_like(ones) * 2

inplace_test(ones, out=twos)
twos

>>> array([2., 2., 2., 2., 2., 2., 2., 2., 2., 2.])

the output host array contains just something… 🤷‍♂️

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
philippellercommented, May 31, 2021

Still convinced that this is a bug. The outputs are not being assigned. If the outputs of a function cannot be relied upon, then in my universe this is considered a bug. What was references as the same issue by @gmarkall is talking about writing to the inputs.

0reactions
gmarkallcommented, Oct 21, 2021

Moving to 0.56 as I’ll not get the time to look into this for 0.55.

Read more comments on GitHub >

github_iconTop Results From Across the Web

weird behavior of numba guvectorize - python - Stack Overflow
Function g() receives an uninitialized array through the res parameter. Assigning a new value to it doesn't modify the original array passed ...
Read more >
2.2. Compilation — Numba 0.20.0 documentation
guvectorize () allows you to create a Numpy ufunc whose core function takes array arguments of various dimensions. The additional argument layout is...
Read more >
Just-in-Time compilation - Numba documentation
The GIL will only be released if Numba can compile the function in nopython ... and returns a scalar value, numba.guvectorize() allows you...
Read more >
Boost python with your GPU (numba+CUDA) - The Data Frog
GPUs are not only for games and neural networks. They have a ... Numpy universal functions or ufuncs are functions that operate on...
Read more >
Numba — Python notebooks
The code is generated on-the-fly for CPU (default) or GPU hardware. Python decorator#. A decorator is used to modify a function or a...
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