From 79ba15ecd2255cc8cd60313833d5f88a05657a26 Mon Sep 17 00:00:00 2001 From: Avril Date: Tue, 24 Nov 2020 21:05:19 +0000 Subject: [PATCH] rust 'rs' target --- Makefile | 12 +++++++- fcmprs/Cargo.toml | 6 ++++ fcmprs/Makefile | 76 ++++++++++++++++++++++++++++++++++++++++++++++ fcmprs/src/main.rs | 2 +- 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 fcmprs/Makefile diff --git a/Makefile b/Makefile index 2b402fe..fc4dc51 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,10 @@ INCLUDE=include PROJECT=fcmp +OPT_FLAGS_RUST?= -C target-cpu=native OPT_FLAGS?= -march=native -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 +FEAT_RUST?= threads FEAT_CFLAGS?= -D_RUN_THREADED=0 FEAT_LDFLAGS?= -lpthread @@ -38,6 +40,9 @@ debug: | dirs $(PROJECT)-debug .PHONY: pgo pgo: | dirs $(PROJECT)-pgo +.PHONY: rs +rs: | $(PROJECT)-rs + dirs: @mkdir -p {obj,prof}/src @@ -58,6 +63,10 @@ $(PROJECT)-debug: LDFLAGS := $(DEBUG_LDFLAGS) $(LDFLAGS) $(PROJECT)-debug: $(OBJ) $(CC) $^ $(CFLAGS) -o $@ $(LDFLAGS) +$(PROJECT)-rs: + cd fcmprs && OPT_FLAGS="$(OPT_FLAGS_RUST)" CARGO_FEATURES="$(FEAT_RUST)" $(MAKE) + cp -f ./fcmprs/target/release/fcmprs $@ + pgo-generate: CFLAGS := $(RELEASE_CFLAGS) $(CFLAGS) pgo-generate: LDFLAGS := $(RELEASE_LDFLAGS) $(LDFLAGS) pgo-generate: $(PGO_OBJ) @@ -106,5 +115,6 @@ $(PROJECT)-pgo: pgo-profile strip $@ clean: + cd fcmprs && make clean rm -rf {obj,prof} - rm -f $(PROJECT)-{release,debug,pgo} + rm -f $(PROJECT)-{release,debug,pgo,rs} diff --git a/fcmprs/Cargo.toml b/fcmprs/Cargo.toml index 40d43fc..905a6bb 100644 --- a/fcmprs/Cargo.toml +++ b/fcmprs/Cargo.toml @@ -11,6 +11,12 @@ default = ["threads"] threads = ["rayon"] +[profile.release] +opt-level = 3 +lto = "fat" +codegen-units = 1 +panic = "abort" + [dependencies] cfg-if = "1.0.0" memmap = "0.7.0" diff --git a/fcmprs/Makefile b/fcmprs/Makefile new file mode 100644 index 0000000..f76588b --- /dev/null +++ b/fcmprs/Makefile @@ -0,0 +1,76 @@ + +PROJECT = fcmprs + +CARGO_FEATURES?= threads + +OPT_FLAGS?= -C target-cpu=native +RUSTFLAGS?= + +PROF_DIR=/tmp/fcmprs/prof +PROF_ITERATIONS?=100 +PROF_LOCATION?=/tmp/fcmprs-profiters + +PROF_LARGE_BOUND= $$(( 1024 * 1024 * 10 )) +PROF_SMALL_BOUND= $$(( 1024 * 10 )) + +.PHONY: release +release: target/release/$(PROJECT) + +.PHONY: debug +debug: target/debug/$(PROJECT) + +.PHONY: pgo +pgo: target/release/$(PROJECT)-pgo + # Currently broken. + + +target/release/$(PROJECT): RUSTFLAGS+= $(OPT_FLAGS) +target/release/$(PROJECT): + RUSTFLAGS="$(RUSTFLAGS)" cargo build --release --no-default-features $(addprefix --features ,$(CARGO_FEATURES)) + strip $@ + +target/debug/$(PROJECT): + RUSTFLAGS="$(RUSTFLAGS)" cargo build --no-default-features $(addprefix --features ,$(CARGO_FEATURES)) + +pgo-generate: RUSTFLAGS+= -Cprofile-generate=$(PROF_DIR) +pgo-generate: target/release/$(PROJECT) + +pgo-profile: pgo-generate + for i in {1..$(PROF_ITERATIONS)}; do \ + rm -rf $(PROF_LOCATION); \ + mkdir -p $(PROF_LOCATION)/{large,small}; \ + printf "Iteration $$i of $(PROF_ITERATIONS)\r"; \ + ../profile/gen $(PROF_LARGE_BOUND) "$(PROF_LOCATION)/large" >> /dev/null; \ + ../profile/gen $(PROF_SMALL_BOUND) "$(PROF_LOCATION)/small" >> /dev/null; \ + ./target/release/fcmprs $(PROF_LOCATION)/large/matching/* & > $(PROF_LOCATION)/stdout; \ + ./target/release/fcmprs $(PROF_LOCATION)/large/unmatching/* & > $(PROF_LOCATION)/stdout; \ + ./target/release/fcmprs $(PROF_LOCATION)/small/matching/* & > $(PROF_LOCATION)/stdout; \ + ./target/release/fcmprs $(PROF_LOCATION)/small/unmatching/* & > $(PROF_LOCATION)/stdout; \ + \ + ./target/release/fcmprs $(PROF_LOCATION)/small/matching/{1,2} & > $(PROF_LOCATION)/stdout; \ + ./target/release/fcmprs $(PROF_LOCATION)/large/matching/{1,2} & > $(PROF_LOCATION)/stdout; \ + ./target/release/fcmprs $(PROF_LOCATION)/small/unmatching/{1,2} & > $(PROF_LOCATION)/stdout; \ + ./target/release/fcmprs $(PROF_LOCATION)/large/unmatching/{1,2} & > $(PROF_LOCATION)/stdout; \ + wait; \ + rm -rf $(PROF_LOCATION)/{large,small}; \ + done + @echo "" + rm -rf $(PROF_LOCATION) + llvm-profdata merge -o $(PROF_DIR)/merged.profdata $(PROF_DIR) + +pgo-use: RUSTFLAGS+= -Cprofile-use=$(PROF_DIR)/merged.profdata -Cllvm-args=-pgo-warn-missing-function +pgo-use: target/release/$(PROJECT) + +pgo-reset: + rm -rf $(PROF_DIR) + mkdir -p $(PROF_DIR) + + +target/release/$(PROJECT)-pgo: | pgo-reset pgo-profile + #rm -rf target + CARGO_INCREMENTAL=0 $(MAKE) -B pgo-use + mv -f target/release/$(PROJECT) $@ + +clean: + rm -rf target + rm -rf $(PROF_LOCATION) $(PROF_DIR) diff --git a/fcmprs/src/main.rs b/fcmprs/src/main.rs index 9318d9b..3d04ead 100644 --- a/fcmprs/src/main.rs +++ b/fcmprs/src/main.rs @@ -31,7 +31,7 @@ fn main() { } }; - std::process::exit(dbg!{ + std::process::exit({ if let Some(map1) = map::map(&map1).discard_msg(format!("Failed to map file {}", map1)) { let slice = map1.as_slice(); let mut ok = true;