MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / llm_load_tensors

Function llm_load_tensors

llama.cpp:3423–4218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3421}
3422
3423static void llm_load_tensors(
3424 llama_model_loader & ml,
3425 llama_model & model,
3426 int n_gpu_layers,
3427 int main_gpu,
3428 const float * tensor_split,
3429 bool use_mlock,
3430 llama_progress_callback progress_callback,
3431 void * progress_callback_user_data) {
3432 model.t_start_us = ggml_time_us();
3433
3434 auto & ctx = model.ctx;
3435 auto & hparams = model.hparams;
3436
3437 model.n_gpu_layers = n_gpu_layers;
3438
3439 size_t ctx_size;
3440 size_t mmapped_size;
3441
3442 ml.calc_sizes(ctx_size, mmapped_size);
3443
3444 LLAMA_LOG_INFO("%s: ggml ctx size = %7.2f MB\n", __func__, ctx_size/1024.0/1024.0);
3445
3446 // create the ggml context
3447 {
3448 model.buf.resize(ctx_size);
3449 if (use_mlock) {
3450 model.mlock_buf.init (model.buf.data);
3451 model.mlock_buf.grow_to(model.buf.size);
3452 }
3453
3454 struct ggml_init_params params = {
3455 /*.mem_size =*/ model.buf.size,
3456 /*.mem_buffer =*/ model.buf.data,
3457 /*.no_alloc =*/ ml.use_mmap,
3458 };
3459
3460 model.ctx = ggml_init(params);
3461 if (!model.ctx) {
3462 throw std::runtime_error(format("ggml_init() failed"));
3463 }
3464 }
3465
3466 (void) main_gpu;
3467
3468 enum ggml_backend_type llama_backend_offload = GGML_BACKEND_CPU;
3469 enum ggml_backend_type llama_backend_offload_split = GGML_BACKEND_CPU;
3470
3471#ifdef GGML_USE_CUBLAS
3472 if (ggml_cublas_loaded()) {
3473 LLAMA_LOG_INFO("%s: using " GGML_CUDA_NAME " for GPU acceleration\n", __func__);
3474 ggml_cuda_set_main_device(main_gpu);
3475
3476 llama_backend_offload = GGML_BACKEND_GPU;
3477 llama_backend_offload_split = GGML_BACKEND_GPU_SPLIT;
3478 }
3479#elif defined(GGML_USE_CLBLAST)
3480 LLAMA_LOG_INFO("%s: using OpenCL for GPU acceleration\n", __func__);

Callers 1

llama_model_loadFunction · 0.85

Calls 15

minFunction · 0.85
calc_sizesMethod · 0.80
get_tensor_nameMethod · 0.80
ggml_time_usFunction · 0.70
ggml_initFunction · 0.70
formatFunction · 0.70
LLM_TNClass · 0.70
ggml_nbytesFunction · 0.70
gguf_find_tensorFunction · 0.70
ggml_get_tensorFunction · 0.70
ggml_get_nameFunction · 0.70
tnFunction · 0.50

Tested by

no test coverage detected