Skip to content

Commit 7fdc693

Browse files
authored
fix bench on macos and add ci (#209)
* fix bench on macos * no rpath * fix * fix * dbg * ci * fix
1 parent 32e7406 commit 7fdc693

4 files changed

Lines changed: 79 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,41 @@ jobs:
170170
run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools
171171
- name: Install Link deps
172172
run: sudo apt-get install libc-dev build-essential
173+
- name: Run bench
174+
run: ./bench/bench.sh | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' >> bench.md
175+
176+
- name: Find Bench Comment
177+
continue-on-error: true
178+
uses: peter-evans/find-comment@v3
179+
id: fc
180+
with:
181+
issue-number: ${{ github.event.pull_request.number }}
182+
comment-author: 'github-actions[bot]'
183+
body-includes: Benchmarking (Linux)
184+
- name: Create or update bench comment
185+
continue-on-error: true
186+
uses: peter-evans/create-or-update-comment@v4
187+
with:
188+
comment-id: ${{ steps.fc.outputs.comment-id }}
189+
issue-number: ${{ github.event.pull_request.number }}
190+
body-path: bench.md
191+
edit-mode: replace
192+
bench-macos:
193+
name: Bench macOS
194+
runs-on: macos-14
195+
env:
196+
CARGO_TERM_COLOR: always
197+
LIBRARY_PATH: /opt/homebrew/lib
198+
MLIR_SYS_190_PREFIX: /opt/homebrew/opt/llvm@19
199+
LLVM_SYS_191_PREFIX: /opt/homebrew/opt/llvm@19
200+
TABLEGEN_190_PREFIX: /opt/homebrew/opt/llvm@19
201+
steps:
202+
- uses: actions/checkout@v4
203+
- name: Rustup toolchain install
204+
uses: dtolnay/rust-toolchain@1.85.0
205+
- uses: homebrew/actions/setup-homebrew@master
206+
- name: install llvm
207+
run: brew install llvm@19
173208
- name: Run bench
174209
run: ./bench/bench.sh | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' > bench.md
175210

@@ -180,7 +215,7 @@ jobs:
180215
with:
181216
issue-number: ${{ github.event.pull_request.number }}
182217
comment-author: 'github-actions[bot]'
183-
body-includes: Benchmarking
218+
body-includes: Benchmarking (macOS)
184219
- name: Create or update bench comment
185220
continue-on-error: true
186221
uses: peter-evans/create-or-update-comment@v4

bench/bench.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <stdio.h>
44
#include <stdlib.h>
55
#include <time.h>
6+
#include <inttypes.h>
67

78
extern uint64_t Bench_concrete_function_0(uint64_t n);
89

@@ -53,7 +54,7 @@ int main(int argc, const char **argv) {
5354
result_concrete = Bench_concrete_function_0(input);
5455
}
5556
long time_elapsed_nanos = timer_end(vartime);
56-
printf("Concrete Result =\t%lu\t\tTime taken : %.2Lf ms\n", result_concrete,
57+
printf("Concrete Result =\t %" PRIu64 "\t\tTime taken : %.2Lf ms\n", result_concrete,
5758
(long double)time_elapsed_nanos / 1000000.0L);
5859
}
5960

@@ -63,7 +64,7 @@ int main(int argc, const char **argv) {
6364
result_rust = rust_function(input);
6465
}
6566
long time_elapsed_nanos = timer_end(vartime);
66-
printf("Rust Result =\t\t%lu\t\tTime taken : %.2Lf ms\n", result_rust,
67+
printf("Rust Result =\t\t %" PRIu64 "\t\tTime taken : %.2Lf ms\n", result_rust,
6768
(long double)time_elapsed_nanos / 1000000.0L);
6869
}
6970

bench/bench.sh

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,55 @@ cd "$(dirname "$0")"
77
RED='\033[0;31m'
88
NC='\033[0m' # No Color
99

10-
# name without extension, num_iters, input number
10+
unameOut="$(uname -s)"
11+
12+
case "${unameOut}" in
13+
Linux*) libext=so;;
14+
Darwin*) libext=dylib;;
15+
CYGWIN*) libext=dll;;
16+
MINGW*) libext=dll;;
17+
MSYS_NT*) libext=dll;;
18+
*) libext="so"
19+
esac
20+
1121
function bench_program() {
22+
case "${unameOut}" in
23+
Linux*) bench_program_linux "$@";;
24+
Darwin*) bench_program_macos "$@";;
25+
*) ;;
26+
esac
27+
}
28+
29+
# name without extension, num_iters, input number
30+
function bench_program_linux() {
1231
local name=$1
1332
local num_iters=$2
1433
local input=$3
1534

16-
echo -e "### ${RED}Benchmarking $name ${NC}"
35+
echo -e "### ${RED}Benchmarking (Linux) $name ${NC}"
1736

1837
rustc --crate-type=cdylib "$name.rs" -C target-cpu=native -C opt-level=3 -o "${name}_rs.so" > /dev/null 2>&1
1938
cargo r -- build "$name.con" --lib --release
2039
cp "$name.so" "${name}_con.so"
2140

22-
cc -march=native -mtune=native bench.c -L . -l:./"${name}"_rs.so -l:./"${name}"_con.so -Wl,-rpath -o bench_"${name}"
41+
cc -march=native -mtune=native bench.c -L . -l:./"${name}"_rs.so -l:./"${name}"_con.so -o bench_"${name}"
42+
43+
./bench_"${name}" "$num_iters" "$input"
44+
}
45+
46+
function bench_program_macos() {
47+
local name=$1
48+
local num_iters=$2
49+
local input=$3
50+
51+
echo -e "### ${RED}Benchmarking (macOS) $name ${NC}"
52+
53+
rustc --crate-type=cdylib "$name.rs" -C target-cpu=native -C opt-level=3 -o "${name}_rs.${libext}" > /dev/null 2>&1
54+
cargo r -- build "$name.con" --lib --release
55+
cp "$name.${libext}" "lib${name}_con.${libext}"
56+
cp "${name}_rs.${libext}" "lib${name}_rs.${libext}"
57+
58+
cc -march=native -mtune=native bench.c -L . -l"${name}_con" -l"${name}"_rs -rpath . -o bench_"${name}"
2359

2460
./bench_"${name}" "$num_iters" "$input"
2561
}
@@ -45,4 +81,4 @@ bench_program "factorial" 5000000 20
4581
bench_program "fib" 5000 20
4682

4783
# Cleanup
48-
rm ./*.so
84+
rm -rf ./*.{so,dylib}

src/driver/linker.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub fn link_shared_lib(objects: &[PathBuf], output_filename: &Path) -> std::io::
1212
output_filename =
1313
output_filename.with_extension(CompileUnitInfo::get_platform_library_ext());
1414
}
15-
1615
let output_filename = output_filename.to_string_lossy().to_string();
1716

1817
let args: Vec<_> = {
@@ -21,13 +20,11 @@ pub fn link_shared_lib(objects: &[PathBuf], output_filename: &Path) -> std::io::
2120
let mut args = vec![
2221
"-dynamic",
2322
"-dylib",
24-
"-mllvm",
2523
"-L/usr/local/lib",
2624
"-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib",
2725
];
2826

2927
args.extend(objects.iter().map(|x| x.as_str()));
30-
3128
args.extend(&["-o", &output_filename, "-lSystem"]);
3229

3330
args

0 commit comments

Comments
 (0)