1111 STDLIB := -stdlib=libc++
1212endif
1313
14+ EMFLAGS=-std =c++17 -I$(GPUCPP ) -I$(GPUCPP ) /third_party/headers/wasm -I. -Iunittest_llmc -Illm.c -s USE_WEBGPU=1 -s ASYNCIFY=1 -s STACK_SIZE=100000 -s MEMORY64=1 -s ALLOW_MEMORY_GROWTH=1
1415CXXFLAGS=-std =c++17 -I$(GPUCPP ) -I$(GPUCPP ) /third_party/headers -I. -Iunittest_llmc
1516CFLAGS =-Ofast -march=native -I. -Iunittest_llmc
1617
@@ -87,6 +88,47 @@ build/train_gpt2: llm.c build/unittest_kernels.o gpt2_124M.bin
8788 grep -q " ^#include \" unittest_kernels.h\" " llm.c/train_gpt2.c || sed -i ' 1i#include \"unittest_kernels.h\"' llm.c/train_gpt2.c
8889 $(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ llm.c/train_gpt2.c build/unittest_kernels.o
8990
91+ build/test_gpt2.html : check-emsdk run.cpp term.html build/test_gpt2
92+ em++ llm.c/test_gpt2.c unittest_llmc/unittest_kernels.cpp \
93+ --preload-file gpt2_tokenizer.bin@/gpt2_tokenizer.bin \
94+ --preload-file gpt2_124M.bin@/gpt2_124M.bin \
95+ --preload-file gpt2_124M_debug_state.bin@/gpt2_124M_debug_state.bin \
96+ --preload-file llm.c/dev/data/tinyshakespeare/tiny_shakespeare_train.bin@dev/data/tinyshakespeare/tiny_shakespeare_train.bin \
97+ --preload-file llm.c/dev/data/tinyshakespeare/tiny_shakespeare_val.bin@dev/data/tinyshakespeare/tiny_shakespeare_val.bin \
98+ -o build/test_gpt2.html \
99+ $(EMFLAGS ) \
100+ --shell-file term.html \
101+
102+ build/train_gpt2.html : check-emsdk run.cpp term.html build/train_gpt2
103+ em++ llm.c/train_gpt2.c unittest_llmc/unittest_kernels.cpp \
104+ --preload-file gpt2_tokenizer.bin@/gpt2_tokenizer.bin \
105+ --preload-file gpt2_124M.bin@/gpt2_124M.bin \
106+ --preload-file gpt2_124M_debug_state.bin@/gpt2_124M_debug_state.bin \
107+ --preload-file llm.c/dev/data/tinyshakespeare/tiny_shakespeare_train.bin@dev/data/tinyshakespeare/tiny_shakespeare_train.bin \
108+ --preload-file llm.c/dev/data/tinyshakespeare/tiny_shakespeare_val.bin@dev/data/tinyshakespeare/tiny_shakespeare_val.bin \
109+ -o build/train_gpt2.html \
110+ $(EMFLAGS ) \
111+ --shell-file term.html \
112+
113+ build/gpt2_gpucpp.html : check-emsdk run.cpp term.html build/train_gpt2
114+ em++ gpt2_wasm.c unittest_llmc/unittest_kernels.cpp \
115+ --preload-file gpt2_tokenizer.bin@/gpt2_tokenizer.bin \
116+ --preload-file gpt2_124M.bin@/gpt2_124M.bin \
117+ --preload-file gpt2_124M_debug_state.bin@/gpt2_124M_debug_state.bin \
118+ --preload-file llm.c/dev/data/tinyshakespeare/tiny_shakespeare_train.bin@dev/data/tinyshakespeare/tiny_shakespeare_train.bin \
119+ --preload-file llm.c/dev/data/tinyshakespeare/tiny_shakespeare_val.bin@dev/data/tinyshakespeare/tiny_shakespeare_val.bin \
120+ -o build/gpt2_gpucpp.html \
121+ $(EMFLAGS ) \
122+ --shell-file term.html \
123+
124+ server : build/train_gpt2.html build/test_gpt2.html
125+ @echo " \n┌───────────────────────────────────────────────────────────────────────────────────┐"
126+ @echo " │ Open http://localhost:8000/build/run.html in your browser to see the output. │"
127+ @echo " │ │"
128+ @echo " │ Press Ctrl+C to stop the server. │"
129+ @echo " └───────────────────────────────────────────────────────────────────────────────────┘\n\n"
130+ python3 -m http.server --directory .
131+
90132build/unittest_kernels.o : unittest_llmc/unittest_kernels.cpp unittest_llmc/unittest_kernels.h kernels.h
91133 mkdir -p build && $(CXX ) $(CXXFLAGS ) -DNDEBUG -c -o $@ $<
92134
@@ -106,3 +148,6 @@ clean:
106148
107149check-python :
108150 @command -v python3 > /dev/null 2>&1 || { echo >&2 " Python needs to be installed and in your path." ; exit 1; }
151+
152+ check-emsdk :
153+ @which em++ > /dev/null || (echo " emsdk not found. Please install emsdk and run 'source emsdk_env.sh' in the emsdk directory." && exit 1)
0 commit comments