From f3be26b2c85a44486a78f0141b8b7f16b58e2f52 Mon Sep 17 00:00:00 2001 From: Nicolas Abril Date: Wed, 4 Sep 2024 20:26:46 +0000 Subject: [PATCH] #634 Don't eta-reduce by default for cuda (#705) --- Cargo.lock | 2 +- src/lib.rs | 2 +- src/main.rs | 3 ++ .../cli/gen_hvm_no_eta_by_default.args | 2 + .../cli/gen_hvm_no_eta_by_default.bend | 21 ++++++++++ .../cli__gen_hvm_no_eta_by_default.bend.snap | 14 +++++++ .../cli__net_size_too_large.bend.snap | 38 +++++++++---------- .../cli__no_check_net_size.bend.snap | 38 +++++++++---------- 8 files changed, 80 insertions(+), 40 deletions(-) create mode 100644 tests/golden_tests/cli/gen_hvm_no_eta_by_default.args create mode 100644 tests/golden_tests/cli/gen_hvm_no_eta_by_default.bend create mode 100644 tests/snapshots/cli__gen_hvm_no_eta_by_default.bend.snap diff --git a/Cargo.lock b/Cargo.lock index 890183d65..8556640f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,7 +62,7 @@ dependencies = [ [[package]] name = "bend-lang" -version = "0.2.36" +version = "0.2.37-alpha.1" dependencies = [ "TSPL", "clap", diff --git a/src/lib.rs b/src/lib.rs index 209d32bf2..88f189bf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -329,7 +329,7 @@ impl OptLevel { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum CompilerTarget { C, Cuda, diff --git a/src/main.rs b/src/main.rs index 02f5b2743..b69ea3196 100644 --- a/src/main.rs +++ b/src/main.rs @@ -193,6 +193,9 @@ pub enum OptArgs { fn compile_opts_from_cli(args: &Vec, 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 { diff --git a/tests/golden_tests/cli/gen_hvm_no_eta_by_default.args b/tests/golden_tests/cli/gen_hvm_no_eta_by_default.args new file mode 100644 index 000000000..9c23af410 --- /dev/null +++ b/tests/golden_tests/cli/gen_hvm_no_eta_by_default.args @@ -0,0 +1,2 @@ +gen-hvm +tests/golden_tests/cli/gen_hvm_no_eta_by_default.bend \ No newline at end of file diff --git a/tests/golden_tests/cli/gen_hvm_no_eta_by_default.bend b/tests/golden_tests/cli/gen_hvm_no_eta_by_default.bend new file mode 100644 index 000000000..3a7efdcf0 --- /dev/null +++ b/tests/golden_tests/cli/gen_hvm_no_eta_by_default.bend @@ -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) \ No newline at end of file diff --git a/tests/snapshots/cli__gen_hvm_no_eta_by_default.bend.snap b/tests/snapshots/cli__gen_hvm_no_eta_by_default.bend.snap new file mode 100644 index 000000000..6bf01e6eb --- /dev/null +++ b/tests/snapshots/cli__gen_hvm_no_eta_by_default.bend.snap @@ -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)) diff --git a/tests/snapshots/cli__net_size_too_large.bend.snap b/tests/snapshots/cli__net_size_too_large.bend.snap index 60d1eeacc..516b49d27 100644 --- a/tests/snapshots/cli__net_size_too_large.bend.snap +++ b/tests/snapshots/cli__net_size_too_large.bend.snap @@ -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)) @@ -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) @@ -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) @@ -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) @@ -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)) @@ -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)) @@ -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)) diff --git a/tests/snapshots/cli__no_check_net_size.bend.snap b/tests/snapshots/cli__no_check_net_size.bend.snap index 83acc1659..461e0f9c3 100644 --- a/tests/snapshots/cli__no_check_net_size.bend.snap +++ b/tests/snapshots/cli__no_check_net_size.bend.snap @@ -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)) @@ -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) @@ -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) @@ -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) @@ -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)) @@ -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)) @@ -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))