guvectorize in-place operations work only in some cases
See original GitHub issueThe 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:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Moving to 0.56 as I’ll not get the time to look into this for 0.55.