Skip to content

Commit dac63e9

Browse files
committed
libs : add libllama-common-base
1 parent c4f5835 commit dac63e9

17 files changed

Lines changed: 108 additions & 51 deletions

common/CMakeLists.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# llama-common
2-
31
find_package(Threads REQUIRED)
42

53
llama_add_compile_flags()
64

5+
#
6+
# llama-common-base
7+
#
8+
79
# Build info header
810

911
if(EXISTS "${PROJECT_SOURCE_DIR}/.git")
@@ -33,15 +35,22 @@ endif()
3335

3436
set(TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/build-info.cpp.in")
3537
set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/build-info.cpp")
38+
3639
configure_file(${TEMPLATE_FILE} ${OUTPUT_FILE})
3740

38-
set(TARGET build_info)
39-
add_library(${TARGET} OBJECT ${OUTPUT_FILE})
41+
set(TARGET llama-common-base)
42+
add_library(${TARGET} STATIC ${OUTPUT_FILE})
43+
44+
target_include_directories(${TARGET} PUBLIC .)
45+
4046
if (BUILD_SHARED_LIBS)
4147
set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
42-
set_target_properties(${TARGET} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
4348
endif()
4449

50+
#
51+
# llama-common
52+
#
53+
4554
set(TARGET llama-common)
4655

4756
add_library(${TARGET}
@@ -123,7 +132,7 @@ if (BUILD_SHARED_LIBS)
123132
set_target_properties(${TARGET} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
124133
endif()
125134

126-
target_link_libraries(${TARGET} PUBLIC build_info)
135+
target_link_libraries(${TARGET} PUBLIC llama-common-base)
127136
target_link_libraries(${TARGET} PRIVATE cpp-httplib)
128137

129138
if (LLAMA_LLGUIDANCE)

common/arg.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "arg.h"
22

3+
#include "build-info.h"
34
#include "chat.h"
45
#include "common.h"
56
#include "download.h"
@@ -1041,8 +1042,8 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
10411042
{"--version"},
10421043
"show version and build info",
10431044
[](common_params &) {
1044-
fprintf(stderr, "version: %d (%s)\n", LLAMA_BUILD_NUMBER, LLAMA_COMMIT);
1045-
fprintf(stderr, "built with %s for %s\n", LLAMA_COMPILER, LLAMA_BUILD_TARGET);
1045+
fprintf(stderr, "version: %d (%s)\n", llama_build_number(), llama_commit());
1046+
fprintf(stderr, "built with %s for %s\n", llama_compiler(), llama_build_target());
10461047
exit(0);
10471048
}
10481049
));

common/build-info.cpp.in

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1+
#include "build-info.h"
2+
3+
#include <cstdio>
4+
#include <string>
5+
16
int LLAMA_BUILD_NUMBER = @LLAMA_BUILD_NUMBER@;
2-
char const *LLAMA_COMMIT = "@LLAMA_BUILD_COMMIT@";
3-
char const *LLAMA_COMPILER = "@BUILD_COMPILER@";
4-
char const *LLAMA_BUILD_TARGET = "@BUILD_TARGET@";
7+
char const * LLAMA_COMMIT = "@LLAMA_BUILD_COMMIT@";
8+
char const * LLAMA_COMPILER = "@BUILD_COMPILER@";
9+
char const * LLAMA_BUILD_TARGET = "@BUILD_TARGET@";
10+
11+
int llama_build_number(void) {
12+
return LLAMA_BUILD_NUMBER;
13+
}
14+
15+
const char * llama_commit(void) {
16+
return LLAMA_COMMIT;
17+
}
18+
19+
const char * llama_compiler(void) {
20+
return LLAMA_COMPILER;
21+
}
22+
23+
const char * llama_build_target(void) {
24+
return LLAMA_BUILD_TARGET;
25+
}
26+
27+
const char * llama_build_info(void) {
28+
static std::string s = "b" + std::to_string(LLAMA_BUILD_NUMBER) + "-" + LLAMA_COMMIT;
29+
return s.c_str();
30+
}
31+
32+
void llama_print_build_info(void) {
33+
fprintf(stderr, "%s: build = %d (%s)\n", __func__, llama_build_number(), llama_commit());
34+
fprintf(stderr, "%s: built with %s for %s\n", __func__, llama_compiler(), llama_build_target());
35+
}

common/build-info.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
int llama_build_number(void);
4+
5+
const char * llama_commit(void);
6+
const char * llama_compiler(void);
7+
8+
const char * llama_build_target(void);
9+
const char * llama_build_info(void);
10+
11+
void llama_print_build_info(void);

common/common.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ggml.h"
22
#include "gguf.h"
33

4+
#include "build-info.h"
45
#include "common.h"
56
#include "log.h"
67
#include "llama.h"
@@ -372,7 +373,7 @@ void common_init() {
372373
const char * build_type = " (debug)";
373374
#endif
374375

375-
LOG_DBG("build: %d (%s) with %s for %s%s\n", LLAMA_BUILD_NUMBER, LLAMA_COMMIT, LLAMA_COMPILER, LLAMA_BUILD_TARGET, build_type);
376+
LOG_DBG("build: %d (%s) with %s for %s%s\n", llama_build_number(), llama_commit(), llama_compiler(), llama_build_target(), build_type);
376377
}
377378

378379
std::string common_params_get_system_info(const common_params & params) {

common/common.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
#pragma once
44

5+
#include "llama-cpp.h"
6+
57
#include "ggml-opt.h"
68
#include "ggml.h"
7-
#include "llama-cpp.h"
89

910
#include <set>
1011
#include <sstream>
@@ -27,11 +28,6 @@
2728
#define die(msg) do { fputs("error: " msg "\n", stderr); exit(1); } while (0)
2829
#define die_fmt(fmt, ...) do { fprintf(stderr, "error: " fmt "\n", __VA_ARGS__); exit(1); } while (0)
2930

30-
#define print_build_info() do { \
31-
fprintf(stderr, "%s: build = %d (%s)\n", __func__, LLAMA_BUILD_NUMBER, LLAMA_COMMIT); \
32-
fprintf(stderr, "%s: built with %s for %s\n", __func__, LLAMA_COMPILER, LLAMA_BUILD_TARGET); \
33-
} while(0)
34-
3531
struct common_time_meas {
3632
common_time_meas(int64_t & t_acc, bool disable = false);
3733
~common_time_meas();
@@ -53,14 +49,6 @@ struct common_adapter_lora_info {
5349

5450
using llama_tokens = std::vector<llama_token>;
5551

56-
// build info
57-
extern int LLAMA_BUILD_NUMBER;
58-
extern const char * LLAMA_COMMIT;
59-
extern const char * LLAMA_COMPILER;
60-
extern const char * LLAMA_BUILD_TARGET;
61-
62-
const static std::string build_info("b" + std::to_string(LLAMA_BUILD_NUMBER) + "-" + LLAMA_COMMIT);
63-
6452
struct common_control_vector_load_info;
6553

6654
//

common/download.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "arg.h"
22

3+
#include "build-info.h"
34
#include "common.h"
45
#include "log.h"
56
#include "download.h"
@@ -290,7 +291,7 @@ static int common_download_file_single_online(const std::string & url,
290291
headers.emplace(h.first, h.second);
291292
}
292293
if (headers.find("User-Agent") == headers.end()) {
293-
headers.emplace("User-Agent", "llama-cpp/" + build_info);
294+
headers.emplace("User-Agent", "llama-cpp/" + std::string(llama_build_info()));
294295
}
295296
if (!bearer_token.empty()) {
296297
headers.emplace("Authorization", "Bearer " + bearer_token);
@@ -411,7 +412,7 @@ std::pair<long, std::vector<char>> common_remote_get_content(const std::string
411412
headers.emplace(h.first, h.second);
412413
}
413414
if (headers.find("User-Agent") == headers.end()) {
414-
headers.emplace("User-Agent", "llama-cpp/" + build_info);
415+
headers.emplace("User-Agent", "llama-cpp/" + std::string(llama_build_info()));
415416
}
416417

417418
if (params.timeout > 0) {

common/hf-cache.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "hf-cache.h"
22

3+
#include "build-info.h"
34
#include "common.h"
45
#include "log.h"
56
#include "http.h"
@@ -200,7 +201,7 @@ static nl::json api_get(const std::string & url,
200201
auto [cli, parts] = common_http_client(url);
201202

202203
httplib::Headers headers = {
203-
{"User-Agent", "llama-cpp/" + build_info},
204+
{"User-Agent", "llama-cpp/" + std::string(llama_build_info())},
204205
{"Accept", "application/json"}
205206
};
206207

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function(llama_build source)
1010
endif()
1111

1212
add_executable(${TEST_TARGET} ${TEST_SOURCES})
13-
target_link_libraries(${TEST_TARGET} PRIVATE llama-common)
13+
target_link_libraries(${TEST_TARGET} PRIVATE llama llama-common)
1414
if (LLAMA_TESTS_INSTALL)
1515
install(TARGETS ${TEST_TARGET} RUNTIME)
1616
endif()

tests/test-quantize-stats.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
#include "ggml.h"
2-
#include "ggml-cpu.h"
31
#include "llama.h"
2+
3+
#include "build-info.h"
44
#include "common.h"
55

66
#include "../src/llama-model.h"
77

8+
#include "ggml.h"
9+
#include "ggml-cpu.h"
10+
811
#include <algorithm>
912
#include <cassert>
1013
#include <cinttypes>
@@ -298,7 +301,7 @@ int main(int argc, char ** argv) {
298301
return 1;
299302
}
300303

301-
print_build_info();
304+
llama_print_build_info();
302305

303306
// load the model
304307
fprintf(stderr, "Loading model\n");

0 commit comments

Comments
 (0)