Skip to content

Commit

Permalink
Merge pull request #2 from xinyangli/ci-test
Browse files Browse the repository at this point in the history
ci: build and test all on native and riscv32-nemu
  • Loading branch information
xinyangli authored Nov 11, 2024
2 parents 64ecf78 + f31dfb2 commit 26435c3
Show file tree
Hide file tree
Showing 243 changed files with 60,580 additions and 62,477 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Test openperf

on:
push:
workflow_dispatch:

env:
AM_HOME: "${{ github.workspace }}/abstract-machine"
NEMU_HOME: "${{ github.workspace }}/nemu"

jobs:
test:
runs-on: ubuntu-latest

continue-on-error: true
strategy:
max-parallel: 4
matrix:
test_size: ["test", "ref"]
arch: ["native", "riscv32-nemu"]
steps:

- uses: nixbuild/nix-quick-install-action@v27

- uses: cachix/cachix-action@v14
with:
name: ysyx
authToken: '${{ secrets.CACHIX_SIGNING_KEY }}'

- name: Checkout Main Repo (openperf)
id: checkout-openperf
uses: actions/checkout@v4
with:
path: openperf

- name: Checkout Nemu Repo
id: checkout-nemu
if: ${{ contains(matrix.arch, 'nemu') }}
uses: actions/checkout@v4
with:
token: '${{ secrets.DEPLOY_KEY }}'
repository: xinyangli/openperf-nemu
path: nemu

- name: Checkout Abstract Machine Repo
id: checkout-am
uses: actions/checkout@v4
with:
token: '${{ secrets.DEPLOY_KEY }}'
repository: xinyangli/openperf-abstract-machine
path: abstract-machine

- name: Prepare devshell
run: |
mkdir -p /tmp/env
nix develop --no-use-registries --profile /tmp/env/openperf-env-${{ matrix.arch }} ./openperf#${{ matrix.arch }}
- name: Cache common libraries
uses: actions/cache@v4
with:
key: openperf-common-${{ matrix.arch }}-${{ hashFiles('**/*.nix') }}-${{ steps.checkout-openperf.outputs.commit }}-${{ steps.checkout-am.outputs.commit }}
path: openperf/src/common

- name: Generate config if target platform is nemu
if: ${{ contains(matrix.arch, 'nemu') }}
run: |
nix develop --no-use-registries /tmp/env/openperf-env-${{ matrix.arch }} --impure --command make -C $NEMU_HOME ARCH=riscv32-nemu openperf_${{ matrix.arch }}_defconfig
- name: Build common libraries
run: |
nix develop --no-use-registries /tmp/env/openperf-env-${{ matrix.arch }} --impure --command make -C openperf ARCH=${{ matrix.arch }} ALL=dummy run
- name: Run openperf benchmark
working-directory: openperf
run: |
nix develop --no-use-registries /tmp/env/openperf-env-${{ matrix.arch }} --impure --command make ARCH=${{ matrix.arch }} mainargs=${{ matrix.test_size }} run
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ _*
build/
!.gitignore
.vscode
!mersenne-riscv32e.bin
abstract-machine/
!.gitea
!.github
73 changes: 58 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

BENCH_LIBS := bench openlibm soft-fp

$(BENCH_LIBS): %: latest
$(BENCH_LIBS): %:
$(MAKE) -s -C ./src/common/$* archive

COLOR_RED = \033[1;31m
Expand All @@ -11,38 +11,81 @@ COLOR_NONE = \033[0m
RESULT = .result
$(shell > $(RESULT))

ALL = cpuemu mcf x264 tcc stream linpack gemm whetstone
KEEP_LOG_FAILED ?= true
KEEP_LOG_SUCCEED ?= false
TIME := $(shell date --iso=seconds)

ALL = mcf x264 tcc stream linpack gemm whetstone

all: $(BENCH_LIBS) $(ALL)
@echo "test list [$(words $(ALL)) item(s)]:" $(ALL)
@echo "OpenPerf [$(words $(ALL)) item(s)]:" $(ALL)
@if [ -z "$(mainargs)" ]; then \
echo "Empty mainargs, use \"ref\" by default"; \
echo "====== Running OpenPerf [input *ref*] ======"; \
else \
echo "====== Running OpenPerf [input *$${mainargs}*] ======"; \
fi

$(ALL): %: $(BENCH_LIBS) latest
$(ALL): %: $(BENCH_LIBS)
@{\
TMP=$*.tmp;\
make -C ./src/$* ARCH=$(ARCH) run 2>&1 | tee -a $$TMP;\
if [ $${PIPESTATUS[0]} -eq 0 ]; then \
$(MAKE) -C ./src/$* ARCH=$(ARCH) run 2>&1 | tee -a $$TMP;\
if [ $${PIPESTATUS[0]} -eq 0 ]; then \
printf "[%14s] $(COLOR_GREEN)PASS$(COLOR_NONE) " $* >> $(RESULT); \
cat $$TMP | grep -E -i -e "time: ([0-9]*\.)?[0-9]* ms" >> $(RESULT); \
rm $$TMP;\
cat $$TMP | grep -E -i -e "OpenPerf time: ([0-9]*\.)?[0-9]*" >> $(RESULT); \
if $(KEEP_LOG_SUCCEED); then \
mkdir -p "logs/$(TIME)/"; \
mv $$TMP "logs/$(TIME)/"; \
else \
rm $$TMP; \
fi \
else \
printf "[%14s] $(COLOR_RED)***FAIL***$(COLOR_NONE)\n" $* >> $(RESULT); \
rm $$TMP; \
if $(KEEP_LOG_FAILED); then \
mkdir -p "logs/$(TIME)/"; \
mv $$TMP "logs/$(TIME)/"; \
else \
rm $$TMP; \
fi \
fi \
}

run: $(BENCH_LIBS) all
@cat $(RESULT)
@cat $(RESULT) | grep -E -o "time: ([0-9]*\.[0-9]*) ms" | awk '{sum += $$2} END {print sum " ms"}'
@rm $(RESULT)

@echo "============================================="
@awk '\
{ \
h = min = s = ms = us = 0;\
if (match($$0, /([0-9]+) h/, arr)) h = arr[1]; \
if (match($$0, /([0-9]+) min/, arr)) min = arr[1]; \
if (match($$0, /([0-9]+) s/, arr)) s = arr[1]; \
if (match($$0, /([0-9]+)\.([0-9]*) ms/, arr)) {ms = arr[1]; us = arr[2]} \
total_ms += h * 3600000 + min * 60000 + s * 1000 + ms; \
} \
END { \
printf "Total time: %d h %d min %d s %d.%d ms\n", \
int(total_ms / 3600000), \
int((total_ms % 3600000) / 60000), \
int((total_ms % 60000) / 1000), \
total_ms % 1000, \
us; \
} \
' $(RESULT)
@if grep -q -i -e "fail" "$(RESULT)"; then \
echo "OpenPerf FAIL"; \
rm $(RESULT); \
exit 1; \
else \
echo "OpenPerf PASS"; \
rm $(RESULT); \
exit 0; \
fi

CLEAN_ALL = $(dir $(shell find . -mindepth 2 -name Makefile))
clean-all: $(CLEAN_ALL)

$(CLEAN_ALL):
-@$(MAKE) -s -C $@ clean

.PHONY: $(BENCH_LIBS) $(CLEAN_ALL) $(ALL) all run clean-all latest

latest:
.PHONY: $(BENCH_LIBS) $(CLEAN_ALL) $(ALL) all run clean-all

44 changes: 44 additions & 0 deletions fix-gcc-ice.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--- gcc-13.3.0/gcc/gimple-ssa-store-merging.cc 2024-05-21 15:47:38.000000000 +0800
+++ gimple-ssa-store-merging.cc 2024-11-11 11:54:49.366712830 +0800
@@ -3157,6 +3157,10 @@
unsigned int min_order = first_order;
unsigned first_nonmergeable_int_order = ~0U;
unsigned HOST_WIDE_INT this_end = end;
+ unsigned HOST_WIDE_INT this_bitregion_start
+ = new_bitregion_start;
+ unsigned HOST_WIDE_INT this_bitregion_end
+ = new_bitregion_end;
k = i;
first_nonmergeable_order = ~0U;
for (unsigned int j = i + 1; j < len; ++j)
@@ -3180,6 +3184,19 @@
k = 0;
break;
}
+ if (info2->bitregion_start
+ < this_bitregion_start)
+ this_bitregion_start = info2->bitregion_start;
+ if (info2->bitregion_end
+ > this_bitregion_end)
+ this_bitregion_end = info2->bitregion_end;
+ if (((this_bitregion_end - this_bitregion_start
+ + 1) / BITS_PER_UNIT)
+ > (unsigned) param_store_merging_max_size)
+ {
+ k = 0;
+ break;
+ }
k = j;
min_order = MIN (min_order, info2->order);
this_end = MAX (this_end,
@@ -5247,7 +5264,9 @@
|| !bitsize.is_constant (&const_bitsize)
|| !bitpos.is_constant (&const_bitpos)
|| !bitregion_start.is_constant (&const_bitregion_start)
- || !bitregion_end.is_constant (&const_bitregion_end))
+ || !bitregion_end.is_constant (&const_bitregion_end)
+ || ((const_bitregion_end - const_bitregion_start + 1) / BITS_PER_UNIT
+ > (unsigned) param_store_merging_max_size))
return terminate_all_aliasing_chains (NULL, stmt);

if (!ins_stmt)
27 changes: 27 additions & 0 deletions flake.lock

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

82 changes: 82 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};

outputs =
{ self, nixpkgs, ... }:
{
devShells.x86_64-linux =
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
patchGccStdenv =
pkgs: stdenv:
pkgs.overrideCC stdenv (
pkgs.wrapCC (
stdenv.cc.cc.overrideAttrs (final: prev: { patches = prev.patches ++ [ ./fix-gcc-ice.patch ]; })
)
);
crossSystem = {
config = "riscv32-none-none-elf";
gcc = {
abi = "ilp32";
arch = "rv32i";
};
};
localSystem = "x86_64-linux";
rv32CrossPkgs = import nixpkgs {
inherit localSystem crossSystem;
};
rv32LLVMCrossPkgs = import nixpkgs {
inherit localSystem;
crossSystem = crossSystem // {
useLLVM = true;
};
};
bareClangStdenv =
with rv32LLVMCrossPkgs;
overrideCC clangStdenv buildPackages.llvmPackages.clangNoLibc;

nemuDepsBuildBuild = with pkgs; [
gnumake
SDL2
pkg-config
bison
flex
ncurses
readline
libllvm
gcc
clang
];
in
rec {
nemu = rv32CrossPkgs.mkShell {
name = "openperf";
depsBuildBuild = nemuDepsBuildBuild;

CROSS_COMPILE = "riscv32-none-none-elf-";
};

nemu-clang = bareClangStdenv.mkDerivation {
name = "openperf";
depsBuildBuild = nemuDepsBuildBuild;
};

native =
pkgs.mkShell.override
{
stdenv = patchGccStdenv pkgs pkgs.stdenv;
}
{
name = "openperf";
buildInputs = with pkgs; [
gnumake
SDL2
];
};

riscv32-nemu = nemu;
};
};
}
Loading

0 comments on commit 26435c3

Please sign in to comment.