Skip to content

Commit

Permalink
#634 Don't eta-reduce by default for cuda (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
developedby authored Sep 4, 2024
1 parent 0945efc commit f3be26b
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl OptLevel {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CompilerTarget {
C,
Cuda,
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ pub enum OptArgs {
fn compile_opts_from_cli(args: &Vec<OptArgs>, compiler_target: CompilerTarget) -> CompileOpts {
use OptArgs::*;
let mut opts = CompileOpts { target_architecture: compiler_target, ..CompileOpts::default() };
if opts.target_architecture != CompilerTarget::C {
opts.eta = false;
}

for arg in args {
match arg {
Expand Down
2 changes: 2 additions & 0 deletions tests/golden_tests/cli/gen_hvm_no_eta_by_default.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gen-hvm
tests/golden_tests/cli/gen_hvm_no_eta_by_default.bend
21 changes: 21 additions & 0 deletions tests/golden_tests/cli/gen_hvm_no_eta_by_default.bend
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Eta-reduction of some recursive functions can mess the performance
# of programs targeting the CUDA runtime.

# So for now we've disabled it by default when the target architecture
# is not C (for which eta-reduction usually seems to not only decrease
# the total amount of interactions, but actually slightly increase
# performance a little bit is the tested cases).

# This test checks that the compiler doesn't eta-reduce when calling
# 'gen-hvm', which has an unknown target architecture.

# A recursive function
make_list n x = switch n {
0: @l l
_: @l (l x (make_list n-1 x))
}

# A non-recursive function
make_10 x = (make_list 10 x)

main = (make_10 1)
14 changes: 14 additions & 0 deletions tests/snapshots/cli__gen_hvm_no_eta_by_default.bend.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/cli/gen_hvm_no_eta_by_default.bend
---
@main = a
& @make_10 ~ (1 a)

@make_10 = (a b)
& @make_list ~ (10 (a b))

@make_list = (?(((* (a a)) @make_list__C0) (b c)) (b c))

@make_list__C0 = (b ({a c} ((a (d e)) e)))
& @make_list ~ (b (c d))
38 changes: 19 additions & 19 deletions tests/snapshots/cli__net_size_too_large.bend.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ input_file: tests/golden_tests/cli/net_size_too_large.bend
@Gen = (a b)
& @Gen.go ~ (a (0 b))

@Gen.go = (?((@Gen.go__C0 @Gen.go__C1) a) a)
@Gen.go = (?((@Gen.go__C0 @Gen.go__C1) (a b)) (a b))

@Gen.go__C0 = a
& @Arr/Leaf ~ a
@Gen.go__C0 = (a b)
& @Arr/Leaf ~ (a b)

@Gen.go__C1 = ({a d} ({$([*0x0000002] $([|0x0000001] e)) $([*0x0000002] b)} g))
& @Arr/Node ~ (c (f g))
Expand All @@ -39,10 +39,10 @@ input_file: tests/golden_tests/cli/net_size_too_large.bend

@Map_/Used/tag = 1

@Merge = ((@Merge__C13 a) a)
@Merge = ((@Merge__C13 (a b)) (a b))

@Merge__C0 = (* a)
& @Map_/Both ~ a
@Merge__C0 = (* (a (b c)))
& @Map_/Both ~ (a (b c))

@Merge__C1 = (?((@Map_/Used @Merge__C0) a) a)

Expand All @@ -56,7 +56,7 @@ input_file: tests/golden_tests/cli/net_size_too_large.bend

@Merge__C2 = (?((@Map_/Free @Merge__C1) a) a)

@Merge__C3 = (?((@Map_/Used *) a) a)
@Merge__C3 = (?((@Map_/Used (* (* (* *)))) a) a)

@Merge__C4 = (?((@Map_/Used @Merge__C3) a) a)

Expand All @@ -65,10 +65,10 @@ input_file: tests/golden_tests/cli/net_size_too_large.bend
&!@Merge ~ (a (b c))
&!@Merge ~ (d (e f))

@Merge__C6 = a
& @Map_/Both ~ a
@Merge__C6 = (a (b c))
& @Map_/Both ~ (a (b c))

@Merge__C7 = (?((* @Merge__C5) a) a)
@Merge__C7 = (?(((* (* *)) @Merge__C5) a) a)

@Merge__C8 = (?((@Merge__C6 @Merge__C7) a) a)

Expand Down Expand Up @@ -102,8 +102,8 @@ input_file: tests/golden_tests/cli/net_size_too_large.bend

@Reverse = ((@Reverse__C3 a) a)

@Reverse__C0 = a
& @Arr/Leaf ~ a
@Reverse__C0 = (a b)
& @Arr/Leaf ~ (a b)

@Reverse__C1 = (* (c (a e)))
& @Arr/Node ~ (b (d e))
Expand All @@ -128,18 +128,18 @@ input_file: tests/golden_tests/cli/net_size_too_large.bend

@Sum__C2 = (?((0 @Sum__C1) a) a)

@Swap = (?((@Swap__C0 @Swap__C1) a) a)
@Swap = (?((@Swap__C0 @Swap__C1) (a (b c))) (a (b c)))

@Swap__C0 = a
& @Map_/Both ~ a
@Swap__C0 = (a (b c))
& @Map_/Both ~ (a (b c))

@Swap__C1 = (* (b (a c)))
& @Map_/Both ~ (a (b c))

@ToArr = (a ((@ToArr__C3 (a b)) b))

@ToArr__C0 = a
& @Arr/Leaf ~ a
@ToArr__C0 = (a b)
& @Arr/Leaf ~ (a b)

@ToArr__C1 = (* (b (e ({$([*0x0000002] $([+0x0000001] d)) $([*0x0000002] $([+0x0000000] a))} g))))
& @Arr/Node ~ (c (f g))
Expand All @@ -152,8 +152,8 @@ input_file: tests/golden_tests/cli/net_size_too_large.bend

@ToMap = ((@ToMap__C3 a) a)

@ToMap__C0 = a
& @Radix ~ a
@ToMap__C0 = (a b)
& @Radix ~ (a b)

@ToMap__C1 = (* (a (c e)))
& @Merge ~ (b (d e))
Expand Down
38 changes: 19 additions & 19 deletions tests/snapshots/cli__no_check_net_size.bend.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ input_file: tests/golden_tests/cli/no_check_net_size.bend
@Gen = (a b)
& @Gen.go ~ (a (0 b))

@Gen.go = (?((@Gen.go__C0 @Gen.go__C1) a) a)
@Gen.go = (?((@Gen.go__C0 @Gen.go__C1) (a b)) (a b))

@Gen.go__C0 = a
& @Arr/Leaf ~ a
@Gen.go__C0 = (a b)
& @Arr/Leaf ~ (a b)

@Gen.go__C1 = ({a d} ({$([*0x0000002] $([|0x0000001] e)) $([*0x0000002] b)} g))
& @Arr/Node ~ (c (f g))
Expand All @@ -39,10 +39,10 @@ input_file: tests/golden_tests/cli/no_check_net_size.bend

@Map_/Used/tag = 1

@Merge = ((@Merge__C13 a) a)
@Merge = ((@Merge__C13 (a b)) (a b))

@Merge__C0 = (* a)
& @Map_/Both ~ a
@Merge__C0 = (* (a (b c)))
& @Map_/Both ~ (a (b c))

@Merge__C1 = (?((@Map_/Used @Merge__C0) a) a)

Expand All @@ -56,7 +56,7 @@ input_file: tests/golden_tests/cli/no_check_net_size.bend

@Merge__C2 = (?((@Map_/Free @Merge__C1) a) a)

@Merge__C3 = (?((@Map_/Used *) a) a)
@Merge__C3 = (?((@Map_/Used (* (* (* *)))) a) a)

@Merge__C4 = (?((@Map_/Used @Merge__C3) a) a)

Expand All @@ -65,10 +65,10 @@ input_file: tests/golden_tests/cli/no_check_net_size.bend
&!@Merge ~ (a (b c))
&!@Merge ~ (d (e f))

@Merge__C6 = a
& @Map_/Both ~ a
@Merge__C6 = (a (b c))
& @Map_/Both ~ (a (b c))

@Merge__C7 = (?((* @Merge__C5) a) a)
@Merge__C7 = (?(((* (* *)) @Merge__C5) a) a)

@Merge__C8 = (?((@Merge__C6 @Merge__C7) a) a)

Expand Down Expand Up @@ -102,8 +102,8 @@ input_file: tests/golden_tests/cli/no_check_net_size.bend

@Reverse = ((@Reverse__C3 a) a)

@Reverse__C0 = a
& @Arr/Leaf ~ a
@Reverse__C0 = (a b)
& @Arr/Leaf ~ (a b)

@Reverse__C1 = (* (c (a e)))
& @Arr/Node ~ (b (d e))
Expand All @@ -128,18 +128,18 @@ input_file: tests/golden_tests/cli/no_check_net_size.bend

@Sum__C2 = (?((0 @Sum__C1) a) a)

@Swap = (?((@Swap__C0 @Swap__C1) a) a)
@Swap = (?((@Swap__C0 @Swap__C1) (a (b c))) (a (b c)))

@Swap__C0 = a
& @Map_/Both ~ a
@Swap__C0 = (a (b c))
& @Map_/Both ~ (a (b c))

@Swap__C1 = (* (b (a c)))
& @Map_/Both ~ (a (b c))

@ToArr = (a ((@ToArr__C3 (a b)) b))

@ToArr__C0 = a
& @Arr/Leaf ~ a
@ToArr__C0 = (a b)
& @Arr/Leaf ~ (a b)

@ToArr__C1 = (* (b (e ({$([*0x0000002] $([+0x0000001] d)) $([*0x0000002] $([+0x0000000] a))} g))))
& @Arr/Node ~ (c (f g))
Expand All @@ -152,8 +152,8 @@ input_file: tests/golden_tests/cli/no_check_net_size.bend

@ToMap = ((@ToMap__C3 a) a)

@ToMap__C0 = a
& @Radix ~ a
@ToMap__C0 = (a b)
& @Radix ~ (a b)

@ToMap__C1 = (* (a (c e)))
& @Merge ~ (b (d e))
Expand Down

0 comments on commit f3be26b

Please sign in to comment.