News for hackers. Stuff that matters.
Re:CuPy: NumPy and SciPy for GPU by johndough on Friday September 20, 2024 @11:22AM (#41602855)
> Why not Jax?

- JAX Windows support is lacking

- CuPy is much closer to CUDA than JAX, so you can get better performance

- CuPy is generally more mature than JAX (fewer bugs)

- CuPy is more flexible thanks to cp.RawKernel

- (For those familiar with NumPy) CuPy is closer to NumPy than jax.numpy

But CuPy does not support automatic gradient computation, so if you do deep learning, use JAX instead. Or PyTorch, if you do not trust Google to maintain a project for a prolonged period of time https://killedbygoogle.com/

Re:CuPy: NumPy and SciPy for GPU by gnulinux on Friday September 20, 2024 @12:20PM (#41603453)
What about CPU-only loads? If one wants to write code that'll eventually run in both CPU and GPU but in the short-to-mid term will only be used in CPU? Since JAX natively support CPU (with numpy backend), but CuPy doesn't, this seems like a potential problem for some.
Re:CuPy: NumPy and SciPy for GPU by nextaccountic on Friday September 20, 2024 @12:31PM (#41603551)
Isn't there a way to dynamically select between numpy and cupy, depending on whether you want cpu or gpu code?
Re:CuPy: NumPy and SciPy for GPU by johndough on Friday September 20, 2024 @03:34PM (#41604919)
> Isn't there a way to dynamically select between numpy and cupy, depending on whether you want cpu or gpu code?

CuPy is an (almost) drop-in replacement for NumPy, so the following works surprisingly often:

    if use_cpu:
        import numpy as np
    else:
       import cupy as np
Re:CuPy: NumPy and SciPy for GPU by gnulinux on Tuesday September 24, 2024 @09:49AM (#41636429)
> surprisingly

This is the problem with these kind of methods. It works, until it doesn't in an unknown way.

Re:CuPy: NumPy and SciPy for GPU by kmaehashi on Friday September 20, 2024 @01:13PM (#41603885)
NumPy has a mechanism to dispatch execution to CuPy: https://numpy.org/neps/nep-0018-array-function-protocol.html

Just prepare the input on NumPy or CuPy, and then you can just feed it to NumPy APIs. NumPy functions will handle itself if the input is NumPy ndarray, or dispatch the execution to CuPy if the input is CuPy ndarray.

Re:CuPy: NumPy and SciPy for GPU by gnulinux on Friday September 20, 2024 @12:41PM (#41603621)
There is but then you're using two separate libraries, that seems like a fragile point of failure compared to just using jax. But regardless since jax will use different backends anyway, it's arguably not any worse (but it ends up being your responsibility to ensure correctness as opposed to the jax team).
Re:CuPy: NumPy and SciPy for GPU by insane_dreamer on Friday September 20, 2024 @12:50PM (#41603690)
> CuPy does not support automatic gradient computation, so if you do deep learning, use JAX instead

DL is major use case; is CuPy planning on adding auto gradient comp?