Skip to content

Commit

Permalink
[cases] add perf.llama
Browse files Browse the repository at this point in the history
  • Loading branch information
SharzyL committed May 3, 2024
1 parent 83f3b32 commit 185bdde
Show file tree
Hide file tree
Showing 12 changed files with 1,274 additions and 3 deletions.
11 changes: 8 additions & 3 deletions nix/t1/testcases/make-intrinsic-case.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

{ caseName, xLen ? 32, vLen ? 1024, fp ? false, ... }@inputs:

stdenv.mkDerivation (rec {
name = "intrinsic.${caseName}";
stdenv.mkDerivation (self: rec {
casePrefix = "intrinsic";
name = "${self.casePrefix}.${caseName}";

unpackPhase = ''
runHook preUnpack
if [ -z "''${srcs:-}" ]; then
if [ -z "''${src:-}" ]; then
echo 'variable $src or $srcs should point to the source'
exit 1
fi
srcs="$src"
fi
runHook postUnpack
'';

NIX_CFLAGS_COMPILE = [
Expand Down Expand Up @@ -51,7 +54,7 @@ stdenv.mkDerivation (rec {
jq --null-input \
--arg name ${caseName} \
--arg type intrinsic \
--arg type ${self.casePrefix} \
--argjson xLen ${toString xLen} \
--argjson vLen ${toString vLen} \
--argjson fp ${lib.boolToString fp} \
Expand All @@ -62,5 +65,7 @@ stdenv.mkDerivation (rec {
runHook postInstall
'';

dontFixup = true;

meta.description = "Test case '${caseName}', written in C intrinsic.";
} // inputs)
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ let
mlir = searchAndCallPackage ./mlir;
intrinsic = searchAndCallPackage ./intrinsic;
asm = searchAndCallPackage ./asm;
perf = searchAndCallPackage ./perf;

# nix build .#t1.cases.codegen.vaadd-vv -L
# codegen case are using xLen=32,vLen=1024 by default
Expand Down
48 changes: 48 additions & 0 deletions tests/perf/llama/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ lib
, emurt
, fetchurl
, _caseBuilders
}:

let
checkpoint_bin = fetchurl {
url = "https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin";
sha256 = "sha256-zVkGRNljhnorbloRB/UfrWY8QdecFJ++y7sflfqB9Jo=";
};

tokenizer_bin = fetchurl {
url = "https://github.com/karpathy/llama2.c/raw/b3c4b6c3c4bbff42e5211293280307019368ccb5/tokenizer.bin";
sha256 = "sha256-UKUu+CLunoPeXOnQvgoCWnc9AZQ39Ytf+dyvsGPs42E=";
};
in

_caseBuilders.mkIntrinsicCase {
casePrefix = "perf";
caseName = "llama";

buildInputs = [ emurt ];

src = with lib.fileset; toSource {
root = ./.;
fileset = fileFilter (file: file.name != "default.nix") ./.;
};

unpackPhase = ''
cp $src -rT .
chmod -R +w .
'';

postPatch = ''
substituteInPlace extern_data.S \
--replace-fail '{{checkpoint_bin}}' ${checkpoint_bin} \
--replace-fail '{{tokenizer_bin}}' ${tokenizer_bin}
'';

srcs = [
"run.c"
"trap.c"
"utils.c"
"extern_data.S"
../../t1_main.S
];
}
25 changes: 25 additions & 0 deletions tests/perf/llama/extern_data.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.section .rodata
.global checkpoint_data
.type checkpoint_data, @object
.align 4
checkpoint_data:
.incbin "{{checkpoint_bin}}" # will be replaced on nix build
checkpoint_end:
.global checkpoint_size
.type checkpoint_size, @object
.align 4
checkpoint_size:
.int checkpoint_end - checkpoint_data

.section .rodata
.global tokenizer_data
.type tokenizer_data, @object
.align 4
tokenizer_data:
.incbin "{{tokenizer_bin}}" # will be replaced on nix build
tokenizer_end:
.global tokenizer_size
.type tokenizer_size, @object
.align 4
tokenizer_size:
.int tokenizer_end - tokenizer_data
5 changes: 5 additions & 0 deletions tests/perf/llama/extern_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern int checkpoint_size;
extern float checkpoint_data[];

extern int tokenizer_size;
extern float tokenizer_data[];
11 changes: 11 additions & 0 deletions tests/perf/llama/linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SECTIONS
{
. = 0x20000000;
.text : { *(.text) }
.rodata : { *(.rodata) }
.data : { *(.data) }
.bss : { *(.bss) }
.sbss : { *(.sbss) }
.sdata : { *(.sdata) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
}
Loading

0 comments on commit 185bdde

Please sign in to comment.