8383#include < cstdlib>
8484#include < string>
8585#include < vector>
86- #include < unordered_set>
8786
8887static_assert (sizeof (half) == sizeof (ggml_fp16_t ), " wrong fp16 size" );
8988
@@ -2973,74 +2972,6 @@ static bool ggml_cuda_graph_check_compability(ggml_cgraph * cgraph) {
29732972 return use_cuda_graph;
29742973}
29752974
2976- static void ggml_cuda_graph_node_set_properties (ggml_cuda_graph_node_properties * props, ggml_tensor * node) {
2977- memset (props, 0 , sizeof (ggml_cuda_graph_node_properties));
2978- props->node_data = node->data ;
2979- props->node_op = node->op ;
2980- props->node_type = node->type ;
2981- props->flags = node->flags ;
2982- for (int i = 0 ; i < GGML_MAX_DIMS ; i++) {
2983- props->ne [i] = node->ne [i];
2984- props->nb [i] = node->nb [i];
2985- }
2986- for (int i = 0 ; i < GGML_MAX_SRC ; i++) {
2987- if (!node->src [i]) {
2988- continue ;
2989- }
2990-
2991- props->src_data [i] = node->src [i]->data ;
2992- }
2993- memcpy (props->op_params , node->op_params , GGML_MAX_OP_PARAMS );
2994- }
2995-
2996- static bool ggml_cuda_graph_node_properties_match (ggml_tensor * node, ggml_cuda_graph_node_properties * props) {
2997- if (node->data != props->node_data && node->op != GGML_OP_VIEW ) {
2998- return false ;
2999- }
3000-
3001- if (node->op != props->node_op ) {
3002- return false ;
3003- }
3004-
3005- if (node->type != props->node_type ) {
3006- return false ;
3007- }
3008-
3009- for (int i = 0 ; i < GGML_MAX_DIMS ; i++) {
3010- if (node->ne [i] != props->ne [i]) {
3011- return false ;
3012- }
3013- if (node->nb [i] != props->nb [i]) {
3014- return false ;
3015- }
3016- }
3017-
3018- if (node->op != GGML_OP_VIEW ) {
3019- for (int i = 0 ; i < GGML_MAX_SRC ; i++) {
3020- if (!node->src [i]) {
3021- if (props->src_data [i] != nullptr ) {
3022- return false ;
3023- }
3024- continue ;
3025- }
3026-
3027- if (node->src [i]->data != props->src_data [i]) {
3028- return false ;
3029- }
3030- }
3031- }
3032-
3033- if (memcmp (props->op_params , node->op_params , GGML_MAX_OP_PARAMS ) != 0 ) {
3034- return false ;
3035- }
3036-
3037- if ((node->flags & GGML_TENSOR_FLAG_COMPUTE ) != (props->flags & GGML_TENSOR_FLAG_COMPUTE )) {
3038- return false ;
3039- }
3040-
3041- return true ;
3042- }
3043-
30442975static const void * ggml_cuda_graph_get_key (ggml_cgraph * cgraph) {
30452976 return cgraph->nodes [0 ];
30462977}
@@ -3052,52 +2983,18 @@ static bool ggml_cuda_graph_update_required(ggml_backend_cuda_context * cuda_ctx
30522983 ggml_cuda_graph * graph = cuda_ctx->cuda_graph (graph_key);
30532984
30542985 // Check if the graph size has changed
3055- if (graph->props .size () != ( size_t ) cgraph->n_nodes ) {
2986+ if (( int ) graph->nodes_copy .size () != cgraph->n_nodes ) {
30562987 res = true ;
3057- graph->props .resize (cgraph->n_nodes );
2988+ graph->nodes_copy .resize (cgraph->n_nodes );
30582989 }
30592990
3060- // Loop over nodes in GGML graph to determine if CUDA graph update is required
3061- // and store properties to allow this comparison for the next token
3062- std::unordered_set<ggml_tensor *> seen_node;
3063- std::vector<ggml_tensor *> srcs_extra;
30642991 for (int i = 0 ; i < cgraph->n_nodes ; i++) {
3065- bool props_match = true ;
3066-
3067- seen_node.insert (cgraph->nodes [i]);
3068-
30692992 if (!res) {
3070- props_match = ggml_cuda_graph_node_properties_match (cgraph->nodes [i], &graph->props [i]);
3071- }
3072- if (!props_match) {
3073- res = true ;
3074- }
3075- ggml_cuda_graph_node_set_properties (&graph->props [i], cgraph->nodes [i]);
3076-
3077- for (int src_idx = 0 ; src_idx < GGML_MAX_SRC ; ++src_idx) {
3078- ggml_tensor * src = cgraph->nodes [i]->src [src_idx];
3079- if (src && seen_node.find (src) == seen_node.end ()) {
3080- srcs_extra.push_back (src);
2993+ if (memcmp (&graph->nodes_copy [i], cgraph->nodes [i], sizeof (ggml_tensor)) != 0 ) {
2994+ res = true ;
30812995 }
30822996 }
3083- }
3084-
3085- if (graph->extra .size () != (size_t ) srcs_extra.size ()) {
3086- res = true ;
3087- graph->extra .resize (srcs_extra.size ());
3088- }
3089-
3090- for (size_t i = 0 ; i < srcs_extra.size (); ++i) {
3091- bool props_match = true ;
3092-
3093- if (!res) {
3094- props_match = ggml_cuda_graph_node_properties_match (srcs_extra[i], &graph->extra [i]);
3095- }
3096-
3097- if (!props_match) {
3098- res = true ;
3099- }
3100- ggml_cuda_graph_node_set_properties (&graph->extra [i], srcs_extra[i]);
2997+ memcpy (&graph->nodes_copy [i], cgraph->nodes [i], sizeof (ggml_tensor));
31012998 }
31022999
31033000 return res;
0 commit comments