-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
161 lines (124 loc) · 4.51 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
DEFCC := cc
DEFCXX := c++
# Use default compilers if CC or CXX are not explicitly set
ifeq ($(origin CC),default)
CC := $(DEFCC)
endif
ifeq ($(origin CXX),default)
CXX := $(DEFCXX)
endif
CFLAGS = -g -Wall -Iggml/include -Iggml/src/ -Wno-unused-variable -fPIC
CXXFLAGS += -g -Wall -Iggml/include -Iggml/src/ -Wno-unused-variable -std=c++11 -fPIC
LDFLAGS = -Lggml/build/src/
OS := $(shell uname -s)
ifeq ($(OS),Linux)
CMAKE_FLAGS = -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF
else ifeq ($(OS),Darwin)
CMAKE_FLAGS = -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DGGML_METAL=ON -DGGML_BLAS=OFF
endif
CUDA_DIR = /usr/local/cuda-12.6/lib64
CUDA_FLAGS :=
VULKAN_FLAGS :=
SRCDIR = src
BINDIR = bin
SOURCES_C := $(wildcard $(SRCDIR)/*.c)
SOURCES_CPP := $(wildcard $(SRCDIR)/*.cpp)
TARGETS_C := $(patsubst $(SRCDIR)/%.c, %, $(SOURCES_C))
TARGETS_CPP := $(patsubst $(SRCDIR)/%.cpp, %, $(SOURCES_CPP))
ifeq ($(OS),Linux)
CFLAGS += -fopenmp
CXXFLAGS += -fopenmp
WHOLE_ARCHIVE = -Wl,--whole-archive ggml/build/src/libggml.a -Wl,--no-whole-archive
WHOLE_ARCHIVE += -Wl,--whole-archive ggml/build/src/libggml-base.a -Wl,--no-whole-archive
WHOLE_ARCHIVE += -Wl,--whole-archive ggml/build/src/libggml-cpu.a -Wl,--no-whole-archive
#WHOLE_ARCHIVE += -Wl,--whole-archive ggml/build/src/ggml-cuda/libggml-cuda.a -Wl,--no-whole-archive
else ifeq ($(OS),Darwin)
CFLAGS += -framework Metal -framework Foundation -framework MetalKit -framework Accelerate
CXXFLAGS += -framework Metal -framework Foundation -framework MetalKit -framework Accelerate
WHOLE_ARCHIVE = -Wl,-force_load,ggml/build/src/libggml.a
WHOLE_ARCHIVE += -Wl,-force_load,ggml/build/src/libggml-base.a
WHOLE_ARCHIVE += -Wl,-force_load,ggml/build/src/libggml-cpu.a
#WHOLE_ARCHIVE += -Wl,-force_load,ggml/build/src/libggml-cuda.a
endif
.PHONY: all clean
all: $(TARGETS_C)
ggml-quants: CFLAGS += -Iggml/src -Iggml/include/ggml
$(TARGETS_C): % : $(SRCDIR)/%.c | bindir
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o ${BINDIR}/$@ $< \
$(WHOLE_ARCHIVE) \
-lm $(CUDA_FLAGS) $(VULKAN_FLAGS)
$(TARGETS_CPP): % : $(SRCDIR)/%.cpp | bindir
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o ${BINDIR}/$@ $< \
$(WHOLE_ARCHIVE) \
-lm $(CUDA_FLAGS) $(VULKAN_FLAGS)
.PHONY: pre-quants
pre-quants: CFLAGS += -Iggml/src -Iggml/include/ggml
pre-quants:
$(CXX) -E $(CFLAGS) $(LDFLAGS) -o ${BINDIR}/quants.pre $(SRCDIR)/quants.c
.PHONY: pre-ggml.c
pre-ggml.c: CFLAGS += -Iggml/src -Iggml/include/ggml
pre-ggml.c:
$(CXX) -E $(CFLAGS) $(LDFLAGS) -o ${BINDIR}/ggml.c.pre ggml/src/ggml.c
#.PHONY: backend-cuda
backend-cuda: CUDA_FLAGS := -L${CUDA_DIR} -lcuda -lcublas -lculibos -lcudart -lcublasLt
backend-cuda: CC = $(CXX)
backend-cuda: backend
backend-vulkan: VULKAN_FLAGS := -Wl,--whole-archive -lvulkan -Wl,--no-whole-archive
backend-vulkan: CC = $(CXX)
backend-vulkan: backend
#.PHONY: conv2d-sched-cuda
conv2d-sched-cuda: CUDA_FLAGS := -L${CUDA_DIR} -lcuda -lcublas -lculibos -lcudart -lcublasLt
conv2d-sched-cuda: CC = $(CXX)
conv2d-sched-cuda: conv2d-sched
#.PHONY: sched-issue-cuda
sched-issue-cuda: CUDA_FLAGS := -L${CUDA_DIR} -lcuda -lcublas -lculibos -lcudart -lcublasLt
sched-issue-cuda: CC = $(CXX)
sched-issue-cuda: sched-issue
#.PHONY: run-sched-issue
run-sched-issue: sched-issue-cuda
env GGML_SCHED_DEBUG=2 ./bin/sched-issue
#.PHONY: debug-sched-issue
debug-sched-issue: sched-issue-cuda
env GGML_SCHED_DEBUG=2 gdb --args ./bin/sched-issue
.PHONY: run-backend-vulkan
run-backend-vulkan: backend-vulkan
env GGML_VULKAN_DEVICE=1 ./bin/backend
bindir: bin
bin:
@mkdir -p $(BINDIR)
clean:
${RM} -rf $(BINDIR)
.PHONY: ggml-init
ggml-init:
cd ggml && \
rm -rf build && mkdir build && cd build && \
cmake ${CMAKE_FLAGS} .. && make -j8 ggml
.PHONY: ggml-init-cuda
ggml-init-cuda:
cd ggml && \
rm -rf build && mkdir build && cd build && \
cmake ${CMAKE_FLAGS} -DGGML_CUDA=ON .. && make -j8 ggml
# This target does not work at the moment but should once
# https://github.com/ggerganov/ggml/pull/730 is merged.
ggml-init-vulkan:
cd ggml && \
rm -rf build && mkdir build && cd build && \
cmake ${CMAKE_FLAGS} -DGGML_VULKAN=ON .. && make -j8 ggml
.PHONY: ggml-show-build-settings
ggml-show-build-settings:
cmake -L ggml/build
.PHONY: ggml
ggml:
cd ggml/build && make -j8
show-add-dot:
dot -Tpng add.dot -o add.dot.png && xdg-open add.dot.png
show-mul-dot:
dot -Tpng mul.dot -o mul.dot.png && xdg-open mul.dot.png
show-rows-dot:
dot -Tpng get-rows.dot -o get-rows.dot.png && xdg-open get-rows.dot.png
update-ggml:
git submodule update --remote --merge ggml
clean-ggml:
${RM} -rf ggml/build
.PHONY: arch-macro
arch-macro: CFLAGS += -march=native