-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
41 lines (35 loc) · 1.15 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
CC = clang
CFLAGS = -O3 -Ofast -std=c++20 -g -fsanitize=address
LDFLAGS =
LDLIBS = -lm -lc++
INCLUDES =
# Check if OpenMP is available
# This is done by attempting to compile an empty file with OpenMP flags
# OpenMP makes the code a lot faster so I advise installing it
# e.g. on MacOS: brew install libomp
# e.g. on Ubuntu: sudo apt-get install libomp-dev
# later, run the program by prepending the number of threads, e.g.: OMP_NUM_THREADS=8 ./gpt2
ifeq ($(shell echo | $(CC) -Xpreprocessor -fopenmp -x c -E - > /dev/null 2>&1; echo $$?), 0)
ifeq ($(shell uname), Darwin)
# macOS with Homebrew
CFLAGS += -Xclang -fopenmp
LDFLAGS += -L/opt/homebrew/opt/libomp/lib
LDLIBS += -lomp
INCLUDES += -I/opt/homebrew/opt/libomp/include
else
# Ubuntu or other Linux distributions
CFLAGS += -fopenmp
LDLIBS += -lgomp
endif
$(info NICE Compiling with OpenMP support)
else
$(warning OOPS Compiling without OpenMP support)
endif
# PHONY means these targets will always be executed
.PHONY: all example
# default target is all
all: example
example: tinytorch_example.cpp
$(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< $(LDLIBS) -o $@
clean:
rm example