CUDA: move the fusion code out of ggml-cuda.cu
Some checks are pending
Python Type-Check / python type-check (push) Waiting to run

Move the fusion matchers, ggml_cuda_can_fuse, ggml_cuda_try_fuse and the
fusion alloc deps of graph_optimize into fusion.cu, unchanged.
fusion.cuh exports ggml_cuda_try_fuse and ggml_cuda_fusion_add_alloc_deps.
The GGML_CUDA_DISABLE_FUSION check is done by the two callers, and
ggml_cuda_is_view_or_noop moves to common.cuh since the compute loop
also uses it.
This commit is contained in:
Aman Gupta 2026-11-26 18:53:53 +08:00
parent 09c1410642
commit 6b70118784
5 changed files with 2394 additions and 2368 deletions

View file

@ -412,6 +412,11 @@ static bool ggml_cuda_is_aligned(const ggml_tensor * tensor, const size_t alignm
tensor->nb[3] % alignment == 0;
}
static bool ggml_cuda_is_view_or_noop(const ggml_tensor * t) {
return ggml_is_empty(t) || t->op == GGML_OP_RESHAPE || t->op == GGML_OP_TRANSPOSE ||
t->op == GGML_OP_VIEW || t->op == GGML_OP_PERMUTE || t->op == GGML_OP_NONE;
}
static constexpr __device__ int ggml_cuda_get_physical_warp_size() {
#if defined(GGML_USE_HIP) && (defined(__GFX9__) || defined(__GFX8__))
return 64;

2374
ggml/src/ggml-cuda/fusion.cu Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,10 @@
#pragma once
#include "common.cuh"
#include "ggml-backend-impl.h"
// try and fuse nodes starting at node i and return the number of nodes to skip
int ggml_cuda_try_fuse(ggml_backend_cuda_context * cuda_ctx, ggml_cgraph * cgraph, int i);
// add alloc deps for the fusions that need their inputs to stay alive (called from graph_optimize)
void ggml_cuda_fusion_add_alloc_deps(ggml_backend_cuda_context * cuda_ctx, ggml_cgraph * cgraph, ggml_backend_graph_optimize_params * params);

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
#pragma once
// CUDA graph capture and concurrent stream state, only needed by ggml-cuda.cu
// CUDA graph capture and concurrent stream state, only needed by ggml-cuda.cu and fusion.cu
#include "common.cuh"