Skip to content
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

atomic min, max for Float32 and Float64 #2129

Closed
ArturPrzybysz opened this issue Oct 25, 2023 · 1 comment
Closed

atomic min, max for Float32 and Float64 #2129

ArturPrzybysz opened this issue Oct 25, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@ArturPrzybysz
Copy link

Is your feature request related to a problem? Please describe.
Not described to a specific problem. I just think that atomic min and max are very common operations and it would be convenient for developers to have it out of the box. Currently only integers are supported.

Describe the solution you'd like
Including atomic min, max for Float32 and Float64 in CUDA.jl interface.

@ArturPrzybysz ArturPrzybysz added the enhancement New feature or request label Oct 25, 2023
@maleadt
Copy link
Member

maleadt commented Nov 1, 2023

The low level atomic operations, i.e. those prefixed by atomic_, only provide what the hardware implements. For a wider set of operations, potentially falling back to a slow CAS loop, you can use the CUDA.@atomic macro, which supports min just fine:

julia> function kernel(a)
           CUDA.@atomic a[1] = min(a[1], 1)
           return
       end
kernel (generic function with 1 method)

julia> a = cu([42])
1-element CuArray{Int64, 1, CUDA.Mem.DeviceBuffer}:
 42

julia> @cuda kernel(a)
CUDA.HostKernel for kernel(CuDeviceVector{Int64, 1})

julia> a
1-element CuArray{Int64, 1, CUDA.Mem.DeviceBuffer}:
 1

@maleadt maleadt closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants