Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions external/ggml/src/ggml-cuda/ggml-cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5897,6 +5897,9 @@ static void * ggml_backend_cuda_reg_get_proc_address(ggml_backend_reg_t reg, con
if (strcmp(name, "ggml_backend_cuda_set_stream_priority") == 0) {
return (void *)ggml_backend_cuda_set_stream_priority;
}
if (strcmp(name, "ggml_backend_cuda_get_stream") == 0) {
return (void *)ggml_backend_cuda_get_stream;
}
return nullptr;
}

Expand Down
1 change: 1 addition & 0 deletions include/engine/framework/core/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void trim_backend_pools(ggml_backend_t backend);
// higher priority, 0 = default). No-op on non-CUDA backends and on builds
// whose CUDA backend does not export the hook.
void set_backend_stream_priority(ggml_backend_t backend, int priority);
void * backend_cuda_stream(ggml_backend_t backend);
// evict_cuda_graph_cache=false (the default) is the historical no-op;
// true drops the backend's cached compiled-graph state (CUDA/HIP graph
// cache) for this cgraph at destruction — opt in per family.
Expand Down
17 changes: 17 additions & 0 deletions src/framework/core/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,23 @@ void set_backend_stream_priority(ggml_backend_t backend, int priority) {
if (fn != nullptr) fn(backend, priority);
}

void * backend_cuda_stream(ggml_backend_t backend) {
if (backend == nullptr) return nullptr;
if (!is_cuda_backend_handle(backend) && !is_hip_backend_handle(backend)) return nullptr;
ggml_backend_dev_t device = ggml_backend_get_device(backend);
if (device == nullptr) {
throw std::runtime_error("CUDA backend stream lookup failed: backend has no device");
}
auto fn = (void * (*)(ggml_backend_t))
ggml_backend_reg_get_proc_address(
ggml_backend_dev_backend_reg(device),
"ggml_backend_cuda_get_stream");
if (fn == nullptr) {
throw std::runtime_error("CUDA backend stream lookup failed: backend does not export ggml_backend_cuda_get_stream");
}
return fn(backend);
}

// evict_cuda_graph_cache defaults to false, preserving historical behavior
// for existing call sites: before the CUDA backend exported
// ggml_backend_cuda_clear_graph the lookup resolved nothing, and families
Expand Down
8 changes: 2 additions & 6 deletions src/framework/sampling/torch_random.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#include "engine/framework/sampling/torch_random.h"

#include "engine/framework/core/backend.h"
#include "engine/framework/debug/trace.h"
#include "engine/framework/io/dynamic_library.h"
#ifdef ENGINE_HAS_CUDA_TORCH_RANDOM
#include "torch_random_cuda_runtime.h"

#ifdef ENGINE_HAS_CUDA_TORCH_RANDOM
#include "ggml-backend.h"
#include "ggml-cuda.h"
#endif
#endif

#include <algorithm>
Expand Down Expand Up @@ -488,7 +484,7 @@ void torch_cuda_sample_topk_exponential_pairs(

void * torch_cuda_backend_stream(void * ggml_backend) {
#ifdef ENGINE_HAS_CUDA_TORCH_RANDOM
return ggml_backend_cuda_get_stream(static_cast<ggml_backend_t>(ggml_backend));
return core::backend_cuda_stream(static_cast<ggml_backend_t>(ggml_backend));
#else
(void) ggml_backend;
return nullptr;
Expand Down
Loading