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

codegen: ensure Bool arithmetic is done in mod-2 #31503

Merged
merged 2 commits into from
Apr 3, 2019
Merged

codegen: ensure Bool arithmetic is done in mod-2 #31503

merged 2 commits into from
Apr 3, 2019

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Mar 27, 2019

As @stevengj found in #31486, we're doing boolean arithmetic wrong in codegen, and that's causing us to potentially give up lots of performance since we can't vectorize it, and in addition we get wrong answers.

setup:

julia> xor_(a, b) = Core.Intrinsics.xor_int(a, b);
julia> b = rand(Bool, 150); i = UInt8.(b);
julia> f(a) = reduce(xor, a); g(a) = reduce(!=, a); h(a) = reduce(xor_, a);
julia> using BenchmarkTools

before:

julia> @btime f(b)
  115.304 ns (0 allocations: 0 bytes)
true

julia> @btime f(i)
  34.677 ns (0 allocations: 0 bytes)
0x01

julia> @btime g(b)
  114.314 ns (0 allocations: 0 bytes)
true

julia> @btime g(i)
  119.157 ns (0 allocations: 0 bytes)
true

julia> @btime h(b)
  33.699 ns (0 allocations: 0 bytes)
true

julia> @btime h(i)
  35.412 ns (0 allocations: 0 bytes)
0x01

after:

julia> @btime f(b)
  38.064 ns (0 allocations: 0 bytes)
true

julia> @btime f(i)
  34.773 ns (0 allocations: 0 bytes)
0x01

julia> @btime g(b)
  35.565 ns (0 allocations: 0 bytes)
true

julia> @btime g(i)
  118.535 ns (0 allocations: 0 bytes)
true

julia> @btime h(b)
  39.737 ns (0 allocations: 0 bytes)
true

julia> @btime h(i)
  34.269 ns (0 allocations: 0 bytes)
0x01

julia> @btime h(i)
  34.299 ns (0 allocations: 0 bytes)
0x01

PS: ignore the first commit, it's just deleting dead code

vtjnash added 2 commits March 27, 2019 10:38
A Bool is represented as i8, but in Julia it is required to be
managed as an i1 with range [0,1] for correctness and performance.

fixes #31486
@vtjnash
Copy link
Member Author

vtjnash commented Mar 29, 2019

@nanosoldier runbenchmarks(ALL, ":master")

@vtjnash
Copy link
Member Author

vtjnash commented Apr 2, 2019

@nanosoldier runbenchmarks(ALL, vs=":master")

@nanosoldier
Copy link
Collaborator

Something went wrong when running your job:

NanosoldierError: failed to run benchmarks against primary commit: failed process: Process(`make -j3 USECCACHE=1`, ProcessExited(2)) [2]

Logs and partial data can be found here
cc @ararslan

@ararslan
Copy link
Member

ararslan commented Apr 2, 2019

Nanosoldier is currently broken due to the BinaryBuilder changes.

@ararslan
Copy link
Member

ararslan commented Apr 2, 2019

@nanosoldier runbenchmarks(ALL, vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@vtjnash
Copy link
Member Author

vtjnash commented Apr 3, 2019

Looks like it's probably a wash, so no major issues created by fixing this, but lets see if it is repeatable: @nanosoldier runbenchmarks(ALL, vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@vtjnash vtjnash merged commit 06b1867 into master Apr 3, 2019
@vtjnash vtjnash deleted the jn/31486 branch April 3, 2019 14:41
@rfourquet
Copy link
Member

"mod 2" instead of "mod 1" ?

@vtjnash vtjnash changed the title codegen: ensure Bool arithmetic is done in mod-1 codegen: ensure Bool arithmetic is done in mod-2 Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants