make compiler tunable in Makefile, i think potentially nice and useful

This commit is contained in:
Andrej Karpathy
2023-07-26 16:40:40 +00:00
parent 7059d7dba9
commit 2711ae8c32
+7 -4
View File
@@ -1,13 +1,16 @@
# choose your compiler, e.g. gcc/clang
# example override to clang: make run CC=clang
CC = gcc
# the most basic way of building that is most likely to work on most systems # the most basic way of building that is most likely to work on most systems
.PHONY: run .PHONY: run
run: run.c run: run.c
gcc -O3 -o run run.c -lm $(CC) -O3 -o run run.c -lm
# useful for a debug build, can then e.g. analyze with valgrind, example: # useful for a debug build, can then e.g. analyze with valgrind, example:
# $ valgrind --leak-check=full ./run out/model.bin 1.0 3 # $ valgrind --leak-check=full ./run out/model.bin 1.0 3
rundebug: run.c rundebug: run.c
gcc -g -o run run.c -lm $(CC) -g -o run run.c -lm
# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html # https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
# https://simonbyrne.github.io/notes/fastmath/ # https://simonbyrne.github.io/notes/fastmath/
@@ -20,14 +23,14 @@ rundebug: run.c
# In our specific application this is *probably* okay to use # In our specific application this is *probably* okay to use
.PHONY: runfast .PHONY: runfast
runfast: run.c runfast: run.c
gcc -Ofast -o run run.c -lm $(CC) -Ofast -o run run.c -lm
# additionally compiles with OpenMP, allowing multithreaded runs # additionally compiles with OpenMP, allowing multithreaded runs
# make sure to also enable multiple threads when running, e.g.: # make sure to also enable multiple threads when running, e.g.:
# OMP_NUM_THREADS=4 ./run out/model.bin # OMP_NUM_THREADS=4 ./run out/model.bin
.PHONY: runomp .PHONY: runomp
runomp: run.c runomp: run.c
gcc -Ofast -fopenmp -march=native run.c -lm -o run $(CC) -Ofast -fopenmp -march=native run.c -lm -o run
.PHONY: clean .PHONY: clean
clean: clean: