Skip to content

Commit

Permalink
org: move jemalloc from spec2006 to benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
xieby1 committed Dec 18, 2024
1 parent ea1c10c commit f50912a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
22 changes: 21 additions & 1 deletion benchmarks/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
{ lib
, callPackage
, riscv64-pkgs
}: lib.makeScope lib.callPackageWith (self: {
spec2006 = callPackage ./spec2006 {};
riscv64-jemalloc = riscv64-pkgs.jemalloc.overrideAttrs (oldAttrs: {
configureFlags = (oldAttrs.configureFlags or []) ++ [
"--enable-static"
"--disable-shared"
];
preBuild = ''
# Add weak attribute to C++ operators, same as jemalloc_cpp.patch
sed -i 's/void \*operator new(size_t)/void *operator new(size_t) __attribute__((weak))/g' src/jemalloc_cpp.cpp
sed -i 's/void operator delete(void \*)/void operator delete(void *) __attribute__((weak))/g' src/jemalloc_cpp.cpp
'';
# Ensure static libraries are installed
postInstall = ''
${oldAttrs.postInstall or ""}
cp -v lib/libjemalloc.a $out/lib/
'';
});
spec2006 = callPackage ./spec2006 {
inherit (self) riscv64-jemalloc;
};

openblas = callPackage ./openblas {};
})
28 changes: 6 additions & 22 deletions benchmarks/spec2006/build-all.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,18 @@
, lib
, fetchFromGitHub
, libxcrypt-legacy

, riscv64-pkgs
, riscv64-cc
, riscv64-fortran
, riscv64-libc-static

, riscv64-jemalloc
, src
, size
, enableVector # TODO: enable vector in libc and jemalloc
, optimize
, march
}:
let
customJemalloc = riscv64-pkgs.jemalloc.overrideAttrs (oldAttrs: {
configureFlags = (oldAttrs.configureFlags or []) ++ [
"--enable-static"
"--disable-shared"
];
preBuild = ''
# Add weak attribute to C++ operators, same as jemalloc_cpp.patch
sed -i 's/void \*operator new(size_t)/void *operator new(size_t) __attribute__((weak))/g' src/jemalloc_cpp.cpp
sed -i 's/void operator delete(void \*)/void operator delete(void *) __attribute__((weak))/g' src/jemalloc_cpp.cpp
'';
# Ensure static libraries are installed
postInstall = ''
${oldAttrs.postInstall or ""}
cp -v lib/libjemalloc.a $out/lib/
'';
});
CPU2006LiteWrapper = fetchFromGitHub {
owner = "OpenXiangShan";
repo = "CPU2006LiteWrapper";
Expand All @@ -50,7 +34,7 @@ in stdenv.mkDerivation {
riscv64-cc
riscv64-fortran
riscv64-libc-static
customJemalloc
riscv64-jemalloc
];

prePatch = ''
Expand Down Expand Up @@ -88,9 +72,9 @@ in stdenv.mkDerivation {
export OPTIMIZE="${optimize} -march=${march}"
export SUBPROCESS_NUM=5
export CFLAGS="$CFLAGS -static -Wno-format-security -I${customJemalloc}/include "
export CXXFLAGS="$CXXFLAGS -static -Wno-format-security -I${customJemalloc}/include"
export LDFLAGS="$LDFLAGS -static -ljemalloc -L${customJemalloc}/lib"
export CFLAGS="$CFLAGS -static -Wno-format-security -I${riscv64-jemalloc}/include "
export CXXFLAGS="$CXXFLAGS -static -Wno-format-security -I${riscv64-jemalloc}/include"
export LDFLAGS="$LDFLAGS -static -ljemalloc -L${riscv64-jemalloc}/lib"
pushd $SPEC && source shrc && popd
make copy-all-src
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/spec2006/build-one.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ runCommand

, callPackage

, riscv64-jemalloc
, src
, size
, enableVector
Expand All @@ -9,6 +10,7 @@
, testCase
}: let
build-all = callPackage ./build-all.nix {
inherit riscv64-jemalloc;
inherit src size enableVector optimize march;
};
in runCommand "${testCase}" {
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/spec2006/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ callPackage

, riscv64-jemalloc
, src
, size
, enableVector
Expand Down Expand Up @@ -42,6 +43,7 @@ in builtins.listToAttrs (
# change `.` to `_`, e.g. "403.gcc" to "403_gcc"
name = builtins.replaceStrings ["."] ["_"] testCase;
value = callPackage ./build-one.nix {
inherit riscv64-jemalloc;
inherit src size enableVector optimize march;
inherit testCase;
};
Expand Down

0 comments on commit f50912a

Please sign in to comment.