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

@fastmath maximum #48153

Merged
merged 4 commits into from
Jan 22, 2023
Merged

@fastmath maximum #48153

merged 4 commits into from
Jan 22, 2023

Conversation

mcabbott
Copy link
Contributor

@mcabbott mcabbott commented Jan 6, 2023

This implements #48082.

julia> fast_maximum(x::AbstractArray{T}; dims=:) where T = @fastmath reduce(max, x; dims, init=typemin(T));

julia> let x = randn(Float32, 100, 1000)
           @btime maximum($x; dims=1)
           @btime fast_maximum($x; dims=1)
           @btime @fastmath maximum($x; dims=1)  # this PR
       end;
  min 708.375 μs, mean 713.129 μs (4 allocations, 4.17 KiB)
  min 12.375 μs, mean 13.942 μs (1 allocation, 4.06 KiB)
  min 14.791 μs, mean 15.820 μs (3 allocations, 4.12 KiB)

julia> let x = randn(Float32, 100, 1000)
           @btime maximum($x)
           @btime fast_maximum($x)
           @btime @fastmath maximum($x)  # this PR
       end;
  min 104.250 μs, mean 105.658 μs (0 allocations)
  min 12.708 μs, mean 13.205 μs (0 allocations)
  min 9.791 μs, mean 10.284 μs (0 allocations)

The need for this would be reduced if #45581 happened soon.

Currently fails because of an order of imports problem I think.

@oscardssmith oscardssmith added performance Must go faster maths Mathematical functions labels Jan 6, 2023
@N5N3
Copy link
Member

N5N3 commented Jan 6, 2023

We define Fastmath much later than reduce so perhaps it's easier to make reducedim_init(f, op_fast, A, region) fallback to reducedim_init(f, op, A, region)
And perhaps we also want to support @fastmath maximum!/minimum!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants