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
CUDA: Numerical differences between CPython / CPU target and the CUDA target in math.pow
#8218
Comments
Similar occurs in CUDA C / C++: // Compile with:
// nvcc -gencode arch=compute_75,code=sm_75 -std c++17 mini.cu -o mini
//
// produces:
//
// 3
// 2
#include <iostream>
#include <cstdint>
template<typename T>
__global__ void kernel(T* r, T* x, T* y)
{
r[0] = std::pow(x[0], y[0]);
}
template <typename T>
T host(T x, T y)
{
return std::pow(x, y);
}
__managed__ uint32_t r_32;
__managed__ uint32_t x_32;
__managed__ uint32_t y_32;
int main(int argc, char **argv)
{
x_32 = 3;
y_32 = 1;
kernel<<<1, 1>>>(&r_32, &x_32, &y_32);
cudaDeviceSynchronize();
std::cout << host(x_32, y_32) << std::endl;
std::cout << r_32 << std::endl;
} |
The CUDA target doesn't end up using |
I think I'm going to label this as an actual bug because I think it should be fixable to be less surprising, even though the same occurs in CUDA C/C++. |
IIRC a similar issue affected cuDF: rapidsai/cudf#10178 |
If the result is expected to be integral, it is possible to solve this in the same way as CuPy with an exponentiation-by-squaring algorithm, as I noted in the cuDF issue you linked. I think that might be the best solution for Numba as well as cuDF. rapidsai/cudf#10178 (comment) |
Thanks @bdice - this is indeed what should be happening - it should be picking up this implementation: https://github.com/numba/numba/blob/main/numba/cpython/numbers.py#L206 but it isn't. There's a wider question of why CUDA even needs to redefine the typing / lowering of things that already have implementations, which also needs looking at, possibly at the same time as this - having unnecessary redefinitions increases the chances of issues like this occurring. |
Originally noticed on Discourse.
The following:
prints
This can cause some surprise.
The text was updated successfully, but these errors were encountered: