Skip to content

Commit 656c6f5

Browse files
committed
Merge remote-tracking branch 'origin/master' into sl/rpc-dl-backend
2 parents 07da432 + 86bd60d commit 656c6f5

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

ggml/src/ggml-cpu/ggml-cpu.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,18 @@ static const char * ggml_backend_cpu_device_get_description(ggml_backend_dev_t d
337337
}
338338

339339
static void ggml_backend_cpu_device_get_memory(ggml_backend_dev_t dev, size_t * free, size_t * total) {
340-
#ifdef _WIN32
341-
MEMORYSTATUSEX status;
342-
status.dwLength = sizeof(status);
343-
GlobalMemoryStatusEx(&status);
344-
*total = status.ullTotalPhys;
345-
*free = status.ullAvailPhys;
346-
#else
347-
long pages = sysconf(_SC_PHYS_PAGES);
348-
long page_size = sysconf(_SC_PAGE_SIZE);
349-
*total = pages * page_size;
350-
*free = *total;
351-
#endif
340+
#ifdef _WIN32
341+
MEMORYSTATUSEX status;
342+
status.dwLength = sizeof(status);
343+
GlobalMemoryStatusEx(&status);
344+
*total = status.ullTotalPhys;
345+
*free = status.ullAvailPhys;
346+
#else
347+
long pages = sysconf(_SC_PHYS_PAGES);
348+
long page_size = sysconf(_SC_PAGE_SIZE);
349+
*total = pages * page_size;
350+
*free = *total;
351+
#endif
352352

353353
GGML_UNUSED(dev);
354354
}

tools/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ else()
2727
add_subdirectory(run)
2828
add_subdirectory(tokenize)
2929
add_subdirectory(tts)
30+
add_subdirectory(llava)
3031
if (GGML_RPC)
3132
add_subdirectory(rpc)
3233
endif()
3334
if (NOT GGML_BACKEND_DL)
3435
# these examples use the backends directly and cannot be built with dynamic loading
3536
add_subdirectory(cvector-generator)
3637
add_subdirectory(export-lora)
37-
add_subdirectory(llava)
3838
endif()
3939
endif()

tools/llava/clip.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3382,7 +3382,15 @@ bool clip_image_batch_encode(clip_ctx * ctx, const int n_threads, const clip_ima
33823382
GGML_ABORT("Unknown projector type");
33833383
}
33843384

3385-
ggml_backend_cpu_set_n_threads(ctx->backend_cpu, n_threads);
3385+
// ggml_backend_cpu_set_n_threads(ctx->backend_cpu, n_threads);
3386+
ggml_backend_dev_t dev = ggml_backend_get_device(ctx->backend_cpu);
3387+
ggml_backend_reg_t reg = dev ? ggml_backend_dev_backend_reg(dev) : nullptr;
3388+
if (reg) {
3389+
auto ggml_backend_set_n_threads_fn = (ggml_backend_set_n_threads_t) ggml_backend_reg_get_proc_address(reg, "ggml_backend_set_n_threads");
3390+
if (ggml_backend_set_n_threads_fn) {
3391+
ggml_backend_set_n_threads_fn(ctx->backend_cpu, n_threads);
3392+
}
3393+
}
33863394

33873395
auto status = ggml_backend_sched_graph_compute(ctx->sched.get(), gf);
33883396
if (status != GGML_STATUS_SUCCESS) {

tools/llava/llava.cpp

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

44
#include "llama.h"
5+
#include "ggml-cpp.h"
56

67
#include <algorithm>
78
#include <cerrno>
@@ -209,7 +210,10 @@ static bool clip_llava_handle_patches(clip_ctx * ctx_clip, std::vector<float *>
209210
struct ggml_tensor *flatten = ggml_view_2d(model.ctx, permuted_cont, clip_n_mmproj_embd(ctx_clip), num_patches_height * num_patches_width * num_patches_per_side * num_patches_per_side, size_ele * clip_n_mmproj_embd(ctx_clip), 0);
210211
// ggml_tensor_printf(flatten,"flatten",__LINE__,false,false);
211212
ggml_build_forward_expand(gf, flatten);
212-
ggml_graph_compute_with_ctx(model.ctx, gf, 1);
213+
214+
ggml_backend_ptr backend { ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, nullptr) };
215+
ggml_backend_graph_compute(backend.get(), gf);
216+
213217
struct ggml_tensor* result = ggml_graph_node(gf, -1);
214218

215219
memcpy(image_embd_out, image_embd_v[0], clip_embd_nbytes(ctx_clip)); // main image as global context

0 commit comments

Comments
 (0)