Skip to content

Commit

Permalink
Workflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul1365972 committed Dec 15, 2023
1 parent a57884d commit 353831b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 7 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/gpo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: PGO optimization

on:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: write

jobs:
optimize:
name: Optimize
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
components: llvm-tools-preview

- name: Cache Rust artifacts
uses: Swatinem/rust-cache@v2

- name: First Benchmark
run: cargo bench -p mchprs_core --bench chungus_full

- name: Install cargo-pgo
run: cargo install cargo-pgo

- name: Build instrumented binary
run: cargo pgo bench -p mchprs_core --bench chungus_full

- name: Build optimized binary
run: cargo pgo optimize

- name: Upload release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./target/x86_64-unknown-linux-gnu/release/mchprs
asset_name: mchprs_linux_pgo
release_name: MCHPRS
tag: ${{ github.ref }}
overwrite: true

- name: Upload profiling data
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: release.profdata
asset_name: mchprs_linux_pgo_chungus_mandelbrot.profdata
release_name: MCHPRS
tag: ${{ github.ref }}
overwrite: true

- name: Second Benchmark
run: cargo pgo optimize bench -p mchprs_core --bench chungus_full
13 changes: 8 additions & 5 deletions crates/core/benches/chungus_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,27 @@ fn load_world(path: impl AsRef<Path>) -> PlotWorld {
}
}

fn init_compiler() -> Compiler {
let mut world = load_world("./benches/chungus_mandelbrot_plot");
fn init_compiler(world: &mut PlotWorld) -> Compiler {
let mut compiler: Compiler = Default::default();

let options = CompilerOptions::parse("-O");
let options = CompilerOptions::parse("-I -O");
let bounds = world.get_corners();
compiler.compile(&mut world, bounds, options, Vec::new());
compiler.compile(world, bounds, options, Vec::new());
compiler.on_use_block(START_BUTTON);
compiler
}

fn mandelbrot_full(_c: &mut Criterion) {
println!("Running full chungus mandelbrot, this can take a while!");
let mut compiler = init_compiler();
let mut world = load_world("./benches/chungus_mandelbrot_plot");
let mut compiler = init_compiler(&mut world);
let start = Instant::now();
for _ in 0..12411975 {
compiler.tick();
}
compiler.flush(&mut world);
let bounds = world.get_corners();
compiler.reset(&mut world, bounds);
println!("Mandelbrot benchmark completed in {:?}", start.elapsed());
}

Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use self::data::sleep_time_for_tps;
use self::scoreboard::Scoreboard;

/// The width of a plot (2^n)
pub const PLOT_SCALE: u32 = 5;
pub const PLOT_SCALE: u32 = 4;

/// The width of a plot counted in chunks
pub const PLOT_WIDTH: i32 = 2i32.pow(PLOT_SCALE);
Expand All @@ -50,7 +50,7 @@ pub const PLOT_BLOCK_WIDTH: i32 = PLOT_WIDTH * 16;
pub const NUM_CHUNKS: usize = PLOT_WIDTH.pow(2) as usize;

/// The height of the world in sections (Default: 16, Max: 127)
pub const PLOT_SECTIONS: usize = 32;
pub const PLOT_SECTIONS: usize = 16;
/// The plot height in blocks
pub const PLOT_BLOCK_HEIGHT: i32 = PLOT_SECTIONS as i32 * 16;

Expand Down

0 comments on commit 353831b

Please sign in to comment.