MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / main

Function main

subprojects/llama.cpp/tests/test-thread-safety.cpp:16–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include "sampling.h"
15
16int main(int argc, char ** argv) {
17 common_params params;
18
19 if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_COMMON)) {
20 return 1;
21 }
22
23 common_init();
24
25 llama_backend_init();
26 llama_numa_init(params.numa);
27
28 LOG_INF("%s\n", common_params_get_system_info(params).c_str());
29
30 //llama_log_set([](ggml_log_level level, const char * text, void * /*user_data*/) {
31 // if (level == GGML_LOG_LEVEL_ERROR) {
32 // common_log_add(common_log_main(), level, "%s", text);
33 // }
34 //}, NULL);
35
36 auto cparams = common_context_params_to_llama(params);
37
38 // each context has a single sequence
39 cparams.n_seq_max = 1;
40
41 int dev_count = ggml_backend_dev_count();
42 std::vector<std::array<ggml_backend_dev_t, 2>> gpus;
43 for (int i = 0; i < dev_count; ++i) {
44 auto * dev = ggml_backend_dev_get(i);
45 if (dev && ggml_backend_dev_type(dev) == GGML_BACKEND_DEVICE_TYPE_GPU) {
46 gpus.push_back({dev, nullptr});
47 }
48 }
49 const int gpu_dev_count = (int)gpus.size();
50 const int num_models = gpu_dev_count + 1 + 1; // GPUs + 1 CPU model + 1 layer split
51 //const int num_models = std::max(1, gpu_dev_count);
52 const int num_contexts = std::max(1, params.n_parallel);
53
54 std::vector<llama_model_ptr> models;
55 std::vector<std::thread> threads;
56 std::atomic<bool> failed = false;
57
58 for (int m = 0; m < num_models; ++m) {
59 auto mparams = common_model_params_to_llama(params);
60
61 if (m < gpu_dev_count) {
62 mparams.split_mode = LLAMA_SPLIT_MODE_NONE;
63 mparams.devices = gpus[m].data();
64 } else if (m == gpu_dev_count) {
65 mparams.split_mode = LLAMA_SPLIT_MODE_NONE;
66 mparams.main_gpu = -1; // CPU model
67 } else {
68 mparams.split_mode = LLAMA_SPLIT_MODE_LAYER;
69 }
70
71 llama_model * model = llama_model_load_from_file(params.model.path.c_str(), mparams);
72 if (model == NULL) {
73 LOG_ERR("%s: failed to load model '%s'\n", __func__, params.model.path.c_str());

Callers

nothing calls this directly

Calls 15

common_params_parseFunction · 0.85
common_initFunction · 0.85
llama_backend_initFunction · 0.85
llama_numa_initFunction · 0.85
ggml_backend_dev_countFunction · 0.85
ggml_backend_dev_getFunction · 0.85
maxFunction · 0.85
llama_init_from_modelFunction · 0.85

Tested by

no test coverage detected