Skip to content

Commit 3059ed3

Browse files
committed
format
1 parent 90ca7d2 commit 3059ed3

File tree

3 files changed

+46
-57
lines changed

3 files changed

+46
-57
lines changed

ggml/src/ggml-cuda/ggml-cuda.cu

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,9 +2821,9 @@ static bool ggml_cuda_can_fuse(const struct ggml_cgraph * cgraph, int node_idx,
28212821
std::initializer_list<enum ggml_op> topk_moe_ops = ggml_cuda_topk_moe_ops(false);
28222822
std::initializer_list<enum ggml_op> topk_moe_ops_with_norm = ggml_cuda_topk_moe_ops(true);
28232823

2824-
if (ops.size() == topk_moe_ops_with_norm.size() &&
2825-
ggml_can_fuse_subgraph(cgraph, node_idx, topk_moe_ops_with_norm, {node_idx}, {node_idx + 3, node_idx + 8})
2826-
) {
2824+
if (ops.size() == topk_moe_ops_with_norm.size() &&
2825+
ggml_can_fuse_subgraph(cgraph, node_idx, topk_moe_ops_with_norm, { node_idx },
2826+
{ node_idx + 3, node_idx + 8 })) {
28272827
ggml_tensor * softmax = cgraph->nodes[node_idx];
28282828
ggml_tensor * weights = cgraph->nodes[node_idx+8];
28292829

@@ -2832,8 +2832,8 @@ static bool ggml_cuda_can_fuse(const struct ggml_cgraph * cgraph, int node_idx,
28322832
}
28332833
}
28342834

2835-
if (ops.size() == topk_moe_ops.size() && ggml_can_fuse_subgraph(cgraph, node_idx, topk_moe_ops, {node_idx}, {node_idx+3, node_idx+4})) {
2836-
2835+
if (ops.size() == topk_moe_ops.size() &&
2836+
ggml_can_fuse_subgraph(cgraph, node_idx, topk_moe_ops, { node_idx }, { node_idx + 3, node_idx + 4 })) {
28372837
ggml_tensor * softmax = cgraph->nodes[node_idx];
28382838
ggml_tensor * weights = cgraph->nodes[node_idx+4];
28392839
if (ggml_cuda_should_use_topk_moe(softmax, weights)) {

ggml/src/ggml-impl.h

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -647,29 +647,26 @@ static inline bool ggml_can_fuse(const struct ggml_cgraph * cgraph, int node_idx
647647
return ggml_can_fuse_ext(cgraph, idxs, ops, num_ops);
648648
}
649649

650-
GGML_API bool ggml_can_fuse_subgraph_ext(
651-
const struct ggml_cgraph * cgraph,
652-
const int * node_idxs,
653-
int count,
654-
const enum ggml_op * ops,
655-
const int * inputs,
656-
int num_inputs,
657-
const int * outputs,
658-
int num_outputs);
650+
GGML_API bool ggml_can_fuse_subgraph_ext(const struct ggml_cgraph * cgraph,
651+
const int * node_idxs,
652+
int count,
653+
const enum ggml_op * ops,
654+
const int * inputs,
655+
int num_inputs,
656+
const int * outputs,
657+
int num_outputs);
659658

660659
// Returns true if the subgraph formed by {node_idxs} can be fused
661660
// checks whethers all nodes which are not part of inputs/outputs can be elided
662661
// by checking if their num_uses are confined to the subgraph
663-
static inline bool ggml_can_fuse_subgraph(
664-
const struct ggml_cgraph * cgraph,
665-
int node_idx,
666-
int count,
667-
const enum ggml_op * ops,
668-
const int * inputs,
669-
int num_inputs,
670-
const int * outputs,
671-
int num_outputs) {
672-
662+
static inline bool ggml_can_fuse_subgraph(const struct ggml_cgraph * cgraph,
663+
int node_idx,
664+
int count,
665+
const enum ggml_op * ops,
666+
const int * inputs,
667+
int num_inputs,
668+
const int * outputs,
669+
int num_outputs) {
673670
if (node_idx + count > cgraph->n_nodes) {
674671
return false;
675672
}
@@ -696,21 +693,13 @@ inline bool ggml_can_fuse(const struct ggml_cgraph * cgraph, int node_idx, std::
696693
return ggml_can_fuse(cgraph, node_idx, ops.begin(), (int)ops.size());
697694
}
698695

699-
inline bool ggml_can_fuse_subgraph(
700-
const struct ggml_cgraph * cgraph,
701-
int start_idx,
702-
std::initializer_list<enum ggml_op> ops,
703-
std::initializer_list<int> inputs = {},
704-
std::initializer_list<int> outputs = {}) {
705-
return ggml_can_fuse_subgraph(
706-
cgraph,
707-
start_idx,
708-
ops.size(),
709-
ops.begin(),
710-
inputs.begin(),
711-
inputs.size(),
712-
outputs.begin(),
713-
outputs.size());
696+
inline bool ggml_can_fuse_subgraph(const struct ggml_cgraph * cgraph,
697+
int start_idx,
698+
std::initializer_list<enum ggml_op> ops,
699+
std::initializer_list<int> inputs = {},
700+
std::initializer_list<int> outputs = {}) {
701+
return ggml_can_fuse_subgraph(cgraph, start_idx, ops.size(), ops.begin(), inputs.begin(), inputs.size(),
702+
outputs.begin(), outputs.size());
714703
}
715704

716705
// expose GGUF internals for test code

ggml/src/ggml.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6964,13 +6964,16 @@ void ggml_graph_print(const struct ggml_cgraph * cgraph) {
69646964
GGML_LOG_INFO("========================================\n");
69656965
}
69666966

6967-
static int ggml_find_tensor_node_list(const struct ggml_cgraph * cgraph, const int * idxs, int count, const struct ggml_tensor * tensor) {
6967+
static int ggml_find_tensor_node_list(const struct ggml_cgraph * cgraph,
6968+
const int * idxs,
6969+
int count,
6970+
const struct ggml_tensor * tensor) {
69686971
if (idxs == NULL || cgraph == NULL) {
69696972
return -1;
69706973
}
69716974

6972-
for(int i = 0; i < count; ++i) {
6973-
const int node_idx = idxs[count];
6975+
for (int i = 0; i < count; ++i) {
6976+
const int node_idx = idxs[i];
69746977

69756978
if (node_idx >= cgraph->n_nodes) {
69766979
return -1;
@@ -6982,21 +6985,19 @@ static int ggml_find_tensor_node_list(const struct ggml_cgraph * cgraph, const i
69826985
return -1;
69836986
}
69846987

6985-
bool ggml_can_fuse_subgraph_ext(
6986-
const struct ggml_cgraph * cgraph,
6987-
const int * node_idxs,
6988-
int count,
6989-
const enum ggml_op * ops,
6990-
const int * inputs,
6991-
int num_inputs,
6992-
const int * outputs,
6993-
int num_outputs) {
6994-
6988+
bool ggml_can_fuse_subgraph_ext(const struct ggml_cgraph * cgraph,
6989+
const int * node_idxs,
6990+
int count,
6991+
const enum ggml_op * ops,
6992+
const int * inputs,
6993+
int num_inputs,
6994+
const int * outputs,
6995+
int num_outputs) {
69956996
GGML_ASSERT(count < 32 && num_inputs > 0 && num_outputs > 0);
69966997
int interior_nodes_count = 0;
69976998
int interior_nodes[32];
69986999

6999-
for(int i = 0 ; i < count; ++i) {
7000+
for (int i = 0; i < count; ++i) {
70007001
if (node_idxs[i] >= cgraph->n_nodes || cgraph->nodes[node_idxs[i]]->op != ops[i]) {
70017002
return false;
70027003
}
@@ -7019,17 +7020,16 @@ bool ggml_can_fuse_subgraph_ext(
70197020
}
70207021

70217022
// if interior-node has n-uses, ensure that all of them lie within in this subgraph
7022-
for(int i = 0 ; i < interior_nodes_count; ++i) {
7023-
7023+
for (int i = 0; i < interior_nodes_count; ++i) {
70247024
const int num_uses = ggml_node_get_use_count(cgraph, interior_nodes[i]);
70257025

70267026
const struct ggml_tensor * node = cgraph->nodes[interior_nodes[i]];
70277027

70287028
int subgraph_uses = 0;
70297029
//check if all uses are within the graph
7030-
for(int j = 0; j < count; ++j) {
7030+
for (int j = 0; j < count; ++j) {
70317031
const struct ggml_tensor * other_node = cgraph->nodes[node_idxs[j]];
7032-
for(int src_idx = 0 ; src_idx < GGML_MAX_SRC; src_idx++) {
7032+
for (int src_idx = 0; src_idx < GGML_MAX_SRC; src_idx++) {
70337033
if (other_node->src[src_idx] && other_node->src[src_idx] == node) {
70347034
subgraph_uses++;
70357035
}

0 commit comments

Comments
 (0)