Skip to content

Commit 293bebe

Browse files
rgerganovslaren
andauthored
rpc : fix segfault with nkvo (ggml-org#9389)
* rpc : fix nkvo * rpc : buf_size must not be static ref: ggml-org#9337 --------- Co-authored-by: slaren <[email protected]>
1 parent 5fac4d5 commit 293bebe

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

ggml/src/ggml-cuda.cu

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,11 @@ GGML_CALL static enum ggml_status ggml_backend_cuda_graph_compute(ggml_backend_t
25522552
for (int i = 0; i < cgraph->n_nodes; i++) {
25532553
ggml_tensor * node = cgraph->nodes[i];
25542554

2555-
if (node->src[0] && ggml_backend_buffer_is_cuda_split(node->src[0]->buffer)) {
2555+
if (ggml_is_empty(node) || node->op == GGML_OP_RESHAPE || node->op == GGML_OP_TRANSPOSE || node->op == GGML_OP_VIEW || node->op == GGML_OP_PERMUTE || node->op == GGML_OP_NONE) {
2556+
continue;
2557+
}
2558+
2559+
if (node->src[0] && node->src[0]->buffer && ggml_backend_buffer_is_cuda_split(node->src[0]->buffer)) {
25562560
use_cuda_graph = false; // Split buffers are not supported by CUDA graph capture
25572561
#ifndef NDEBUG
25582562
GGML_CUDA_LOG_WARN("%s: disabling CUDA graphs due to split buffer\n", __func__);

ggml/src/ggml-rpc.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -883,15 +883,17 @@ ggml_tensor * rpc_server::deserialize_tensor(struct ggml_context * ctx, const rp
883883
}
884884
result->buffer = reinterpret_cast<ggml_backend_buffer_t>(tensor->buffer);
885885
if (result->buffer && buffers.find(result->buffer) == buffers.end()) {
886-
return nullptr;
886+
result->buffer = nullptr;
887887
}
888888

889-
// require that the tensor data does not go beyond the buffer end
890-
uint64_t tensor_size = (uint64_t) ggml_nbytes(result);
891-
uint64_t buffer_start = (uint64_t) ggml_backend_buffer_get_base(result->buffer);
892-
uint64_t buffer_size = (uint64_t) ggml_backend_buffer_get_size(result->buffer);
893-
GGML_ASSERT(tensor->data + tensor_size >= tensor->data); // check for overflow
894-
GGML_ASSERT(tensor->data >= buffer_start && tensor->data + tensor_size <= buffer_start + buffer_size);
889+
if (result->buffer) {
890+
// require that the tensor data does not go beyond the buffer end
891+
uint64_t tensor_size = (uint64_t) ggml_nbytes(result);
892+
uint64_t buffer_start = (uint64_t) ggml_backend_buffer_get_base(result->buffer);
893+
uint64_t buffer_size = (uint64_t) ggml_backend_buffer_get_size(result->buffer);
894+
GGML_ASSERT(tensor->data + tensor_size >= tensor->data); // check for overflow
895+
GGML_ASSERT(tensor->data >= buffer_start && tensor->data + tensor_size <= buffer_start + buffer_size);
896+
}
895897

896898
result->op = (ggml_op) tensor->op;
897899
for (uint32_t i = 0; i < GGML_MAX_OP_PARAMS / sizeof(int32_t); i++) {
@@ -1060,7 +1062,7 @@ bool rpc_server::graph_compute(const std::vector<uint8_t> & input, std::vector<u
10601062
const rpc_tensor * tensors = (const rpc_tensor *)(input.data() + sizeof(n_nodes) + n_nodes*sizeof(uint64_t) + sizeof(n_tensors));
10611063
GGML_PRINT_DEBUG("[%s] n_nodes: %u, n_tensors: %u\n", __func__, n_nodes, n_tensors);
10621064

1063-
static size_t buf_size = ggml_tensor_overhead()*(n_nodes + n_tensors) + ggml_graph_overhead_custom(n_nodes, false);
1065+
size_t buf_size = ggml_tensor_overhead()*(n_nodes + n_tensors) + ggml_graph_overhead_custom(n_nodes, false);
10641066
struct ggml_init_params params = {
10651067
/*.mem_size =*/ buf_size,
10661068
/*.mem_buffer =*/ NULL,

ggml/src/ggml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3847,7 +3847,7 @@ static struct ggml_object * ggml_new_object(struct ggml_context * ctx, enum ggml
38473847

38483848
if (cur_end + size_needed + GGML_OBJECT_SIZE > ctx->mem_size) {
38493849
GGML_PRINT("%s: not enough space in the context's memory pool (needed %zu, available %zu)\n",
3850-
__func__, cur_end + size_needed, ctx->mem_size);
3850+
__func__, cur_end + size_needed + GGML_OBJECT_SIZE, ctx->mem_size);
38513851
assert(false);
38523852
return NULL;
38533853
}

0 commit comments

Comments
 (0)