| 3157 | } |
| 3158 | |
| 3159 | static void llm_load_sparse_model_tensors( |
| 3160 | llama_model_loader & ml, |
| 3161 | llama_model & model, |
| 3162 | const llama_context_params * cparams, |
| 3163 | int main_gpu, |
| 3164 | long int vram_budget_bytes, |
| 3165 | bool reset_gpu_index, |
| 3166 | bool disable_ffn_split, |
| 3167 | bool use_mlock, |
| 3168 | llama_progress_callback progress_callback, |
| 3169 | void * progress_callback_user_data) { |
| 3170 | model.t_start_us = ggml_time_us(); |
| 3171 | auto & ctx = model.ctx; |
| 3172 | auto & hparams = model.hparams; |
| 3173 | |
| 3174 | size_t ctx_size; |
| 3175 | size_t mmapped_size; |
| 3176 | ml.calc_sizes(ctx_size, mmapped_size); |
| 3177 | LLAMA_LOG_INFO("%s: ggml ctx size = %7.2f MB\n", __func__, ctx_size/1024.0/1024.0); |
| 3178 | |
| 3179 | // create the ggml context |
| 3180 | { |
| 3181 | model.buf.resize(ctx_size); |
| 3182 | if (use_mlock) { |
| 3183 | model.mlock_buf.init (model.buf.data); |
| 3184 | model.mlock_buf.grow_to(model.buf.size); |
| 3185 | } |
| 3186 | |
| 3187 | struct ggml_init_params params = { |
| 3188 | /*.mem_size =*/ model.buf.size, |
| 3189 | /*.mem_buffer =*/ model.buf.data, |
| 3190 | /*.no_alloc =*/ ml.use_mmap, |
| 3191 | }; |
| 3192 | |
| 3193 | model.ctx = ggml_init(params); |
| 3194 | if (!model.ctx) { |
| 3195 | throw std::runtime_error(format("ggml_init() failed")); |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | (void) main_gpu; |
| 3200 | |
| 3201 | enum ggml_backend_type llama_backend_offload = GGML_BACKEND_CPU; |
| 3202 | enum ggml_backend_type llama_backend_offload_split = GGML_BACKEND_CPU; |
| 3203 | |
| 3204 | #ifdef GGML_USE_CUBLAS |
| 3205 | if (ggml_cublas_loaded()) { |
| 3206 | LLAMA_LOG_INFO("%s: using " GGML_CUDA_NAME " for GPU acceleration\n", __func__); |
| 3207 | ggml_cuda_set_main_device(main_gpu); |
| 3208 | |
| 3209 | llama_backend_offload = GGML_BACKEND_GPU; |
| 3210 | llama_backend_offload_split = GGML_BACKEND_GPU_SPLIT; |
| 3211 | } |
| 3212 | #elif defined(GGML_USE_CLBLAST) |
| 3213 | LLAMA_LOG_INFO("%s: using OpenCL for GPU acceleration\n", __func__); |
| 3214 | llama_backend_offload = GGML_BACKEND_GPU; |
| 3215 | llama_backend_offload_split = GGML_BACKEND_GPU; |
| 3216 | #endif |
no test coverage detected