8000 Add git-based build information for better issue tracking (#1232) · LostRuins/koboldcpp@f4cef87 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4cef87

Browse files
Add git-based build information for better issue tracking (#1232)
* Add git-based build information for better issue tracking * macOS fix * "build (hash)" and "CMAKE_SOURCE_DIR" changes * Redo "CMAKE_CURRENT_SOURCE_DIR" and clearer build messages * Fix conditional dependency on missing target * Broke out build-info.cmake, added find_package fallback, and added build into to all examples, added dependencies to Makefile * 4 space indenting for cmake, attempt to clean up my mess in Makefile * Short hash, less fancy Makefile, and don't modify build-info.h if it wouldn't change it
1 parent 58b367c commit f4cef87

File tree

18 files changed

+185
-21
lines changed

18 files changed

+185
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ models/*
3232
/vdot
3333
/Pipfile
3434

35+
build-info.h
3536
arm_neon.h
3637
compile_commands.json
3738

CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,41 @@ option(LLAMA_CLBLAST "llama: use CLBlast"
7272
option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
7373
option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
7474

75+
#
76+
# Build info header
77+
#
78+
79+
# Write header template to binary dir to keep source directory clean
80+
file(WRITE "${CMAKE_BINARY_DIR}/BUILD_INFO.h.in" "\
81+
#ifndef BUILD_INFO_H\n\
82+
#define BUILD_INFO_H\n\
83+
\n\
84+
#define BUILD_NUMBER @BUILD_NUMBER@\n\
85+
#define BUILD_COMMIT \"@BUILD_COMMIT@\"\n\
86+
\n\
87+
#endif // BUILD_INFO_H\n\
88+
")
89+
90+
# Generate initial build-info.h
91+
include(${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake)
92+
93+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
94+
# Add a custom target for build-info.h
95+
add_custom_target(BUILD_INFO ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h")
96+
97+
# Add a custom command to rebuild build-info.h when .git/index changes
98+
add_custom_command(
99+
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h"
100+
COMMENT "Generating build details from Git"
101+
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake"
102+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
103+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/.git/index"
104+
VERBATIM
105+
)
106+
else()
107+
message(WARNING "Git repository not found; to enable automatic generation of build info, make sure Git is installed and the project is a Git repository.")
108+
endif()
109+
75110
#
76111
# Compile flags
77112
#

Makefile

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,41 +181,56 @@ llama.o: llama.cpp ggml.h ggml-cuda.h llama.h llama-util.h
181181
common.o: examples/common.cpp examples/common.h
182182
$(CXX) $(CXXFLAGS) -c $< -o $@
183183

184+
libllama.so: llama.o ggml.o $(OBJS)
185+
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
186+
184187
clean:
185-
rm -vf *.o main quantize quantize-stats perplexity embedding benchmark-matmult
188+
rm -vf *.o main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state build-info.h
186189

187-
main: examples/main/main.cpp ggml.o llama.o common.o $(OBJS)
188-
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
190+
#
191+
# Examples
192+
#
193+
194+
main: examples/main/main.cpp build-info.h ggml.o llama.o common.o $(OBJS)
195+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
189196
@echo
190197
@echo '==== Run ./main -h for help. ===='
191198
@echo
192199

193-
quantize: examples/quantize/quantize.cpp ggml.o llama.o $(OBJS)
194-
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
200+
quantize: examples/quantize/quantize.cpp build-info.h ggml.o llama.o $(OBJS)
201+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
195202

196-
quantize-stats: examples/quantize-stats/quantize-stats.cpp ggml.o llama.o $(OBJS)
197-
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
203+
quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o llama.o $(OBJS)
204+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
198205

199-
perplexity: examples/perplexity/perplexity.cpp ggml.o llama.o common.o $(OBJS)
200-
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
206+
perplexity: examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o common.o $(OBJS)
207+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
201208

202-
embedding: examples/embedding/embedding.cpp ggml.o llama.o common.o $(OBJS)
203-
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
209+
embedding: examples/embedding/embedding.cpp build-info.h ggml.o llama.o common.o $(OBJS)
210+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
204211

205-
vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS)
206-
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
212+
save-load-state: examples/save-load-state/save-load-state.cpp build-info.h ggml.o llama.o common.o $(OBJS)
213+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
207214

208-
libllama.so: llama.o ggml.o $(OBJS)
209-
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
215+
build-info.h: $(wildcard .git/index) scripts/build-info.sh
216+
@scripts/build-info.sh > $@.tmp
217+
@if ! cmp -s $@.tmp $@; then \
218+
mv $@.tmp $@; \
219+
else \
220+
rm $@.tmp; \
221+
fi
210222

211223
#
212224
# Tests
213225
#
214226

215-
benchmark-matmult: examples/benchmark/benchmark-matmult.cpp ggml.o $(OBJS)
216-
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
227+
benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o $(OBJS)
228+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
217229
./$@
218230

231+
vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS)
232+
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
233+
219234
.PHONY: tests
220235
tests:
221236
bash ./tests/run-tests.sh

examples/benchmark/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ set(TARGET benchmark)
22
add_executable(${TARGET} benchmark-matmult.cpp)
33
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
44
target_compile_features(${TARGET} PRIVATE cxx_std_11)
5+
if(TARGET BUILD_INFO)
6+
add_dependencies(${TARGET} BUILD_INFO)
7+
endif()

examples/benchmark/benchmark-matmult.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <locale.h>
22
#include "ggml.h"
3+
#include "build-info.h"
34
#include <assert.h>
45
#include <math.h>
56
#include <cstring>
@@ -90,9 +91,10 @@ int main(int argc, char ** argv) {
9091
}
9192
}
9293

93-
// create the ggml context
94+
fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT);
9495
printf("Starting Test\n");
9596

97+
// create the ggml context
9698
struct ggml_context * ctx;
9799
//const int sizex = 4096;
98100
//const int sizey = 11008;

examples/embedding/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ set(TARGET embedding)
22
add_executable(${TARGET} embedding.cpp)
33
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
44
target_compile_features(${TARGET} PRIVATE cxx_std_11)
5+
if(TARGET BUILD_INFO)
6+
add_dependencies(${TARGET} BUILD_INFO)
7+
endif()

examples/embedding/embedding.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "common.h"
22
#include "llama.h"
3+
#include "build-info.h"
34

45
#include <ctime>
56

@@ -18,11 +19,13 @@ int main(int argc, char ** argv) {
1819
"expect poor results\n", __func__, params.n_ctx);
1920
}
2021

22+
fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT);
23+
2124
if (params.seed <= 0) {
2225
params.seed = time(NULL);
2326
}
2427

25-
fprintf(stderr, "%s: seed = %d\n", __func__, params.seed);
28+
fprintf(stderr, "%s: seed = %d\n", __func__, params.seed);
2629

2730
std::mt19937 rng(params.seed);
2831
if (params.random_prompt) {

examples/main/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ set(TARGET main)
22
add_executable(${TARGET} main.cpp)
33
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
44
target_compile_features(${TARGET} PRIVATE cxx_std_11)
5+
if(TARGET BUILD_INFO)
6+
add_dependencies(${TARGET} BUILD_INFO)
7+
endif()

examples/main/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "common.h"
77
#include "llama.h"
8+
#include "build-info.h"
89

910
#include <cassert>
1011
#include <cinttypes>
@@ -81,11 +82,13 @@ int main(int argc, char ** argv) {
8182
"expect poor results\n", __func__, params.n_ctx);
8283
}
8384

85+
fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT);
86+
8487
if (params.seed <= 0) {
8588
params.seed = time(NULL);
8689
}
8790

88-
fprintf(stderr, "%s: seed = %d\n", __func__, params.seed);
91+
fprintf(stderr, "%s: seed = %d\n", __func__, params.seed);
8992

9093
std::mt19937 rng(params.seed);
9194
if (params.random_prompt) {

examples/perplexity/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ set(TARGET perplexity)
22
add_executable(${TARGET} perplexity.cpp)
33
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
44
target_compile_features(${TARGET} PRIVATE cxx_std_11)
5+
if(TARGET BUILD_INFO)
6+
add_dependencies(${TARGET} BUILD_INFO)
7+
endif()

0 commit comments

Comments
 (0)
0