Skip to content

Commit

Permalink
Unikernel fixes
Browse files Browse the repository at this point in the history
Makefile and run.c fixes.
  • Loading branch information
trholding committed Aug 25, 2023
1 parent f2fee04 commit b508909
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
*~
out/model.bin
out/
run
run.com.dbg
run.com
a.out
strlit
tokenizer.h
model.h
.config.old
.config
UNIK/
build/
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ run_clang_static_strlit: run.c
# Unikraft Unikernel build
.PHONY: run_unik_qemu_x86_64
run_unik_qemu_x86_64: run.c
[ ! -d "UNIK" ] && echo "Cloning unikraft and musl sources..."
[ ! -d "UNIK/unikraft" ] && git clone https://github.com/unikraft/unikraft UNIK/unikraft
[ ! -d "UNIK/libs/musl" ] && git clone https://github.com/unikraft/lib-musl UNIK/libs/musl
make -f Makefile.unikernel

# run all tests
Expand All @@ -194,4 +197,6 @@ clean:
.PHONY: distclean
distclean:
rm -f run run.com model.h tokenizer.h strlit run.com.dbg *~
make -f Makefile.unikernel distclean
make -f Makefile.unikernel distclean
rm -rf UNIK

25 changes: 20 additions & 5 deletions run.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
/* Inference for Llama-2 Transformer model in pure C
The Llama 2 Everywhere @trholding (Vulcan) fork */


// ----------------------------------------------------------------------------
// Unikraft Unikernel Support Directives
//

#define LSTATUS 0

#ifdef UNIK
#define STRLIT
#define LLOOP
#define LSTATUS 1
#endif

// ----------------------------------------------------------------------------
// INCBIN Embedding Support Directives
Expand Down Expand Up @@ -887,21 +900,23 @@ int main(int argc, char *argv[]) {
#if defined(COSMO_ZIP) || defined(INC_BIN) || defined(STRLIT) // special case for embedded models
// we read the embedded checkpoint from within the executable
// 'checkpoint' is necessary arg
#ifdef UNIK
printf("\n*** GURU UNMEDITATION :: BOOT > LLAMA HAS AWAKENED ***\n\n");
#endif
#if defined(COSMO_ZIP)
checkpoint_path = "/zip/out/model.bin";
tokenizer_path = "/zip/tokenizer.bin";
#elif defined(INC_BIN) || defined(STRLIT)
checkpoint_path = emb_Model_data;
tokenizer_path = emb_Tokenizer_data;
#endif
buffertokens=16;
char promptbuffer[1024]; // Buffer for prompt
buffertokens=8;
#ifdef LLOOP
stats = 0;
stats = LSTATUS;
while(1) { // start of loop
#endif
prompt=(char*)malloc(1024);
printf("L2E $ ");
printf("\nL2E $ ");
fflush(stdout);
inprompt(prompt); // read prompt
#else
Expand Down Expand Up @@ -1005,7 +1020,7 @@ int main(int argc, char *argv[]) {
free_sampler(&sampler);
free_tokenizer(&tokenizer);
free_transformer(&transformer);
#if defined(COSMO_ZIP) || defined(INC_BIN) || defined(STRLIT)
#if defined(COSMO_ZIP) || defined(INC_BIN) || defined(STRLIT)
#ifdef LLOOP
printf("\n");
} // end of loop
Expand Down

0 comments on commit b508909

Please sign in to comment.