@@ -3494,7 +3494,7 @@ static bool GGML_IS_QUANTIZED[GGML_TYPE_COUNT] = {
34943494};
34953495static_assert (GGML_TYPE_COUNT == 13 , "GGML_IS_QUANTIZED is outdated" );
34963496
3497- static const char * GGML_OP_LABEL [GGML_OP_COUNT ] = {
3497+ static const char * GGML_OP_NAME [GGML_OP_COUNT ] = {
34983498 "NONE" ,
34993499
35003500 "DUP" ,
@@ -3749,6 +3749,9 @@ const char * ggml_type_name(enum ggml_type type) {
37493749 return GGML_TYPE_NAME [type ];
37503750}
37513751
3752+ const char * ggml_op_name (enum ggml_op op ) {
3753+ return GGML_OP_NAME [op ];
3754+ }
37523755
37533756size_t ggml_element_size (const struct ggml_tensor * tensor ) {
37543757 return GGML_TYPE_SIZE [tensor -> type ];
@@ -3805,6 +3808,10 @@ enum ggml_type ggml_ftype_to_ggml_type(enum ggml_ftype ftype) {
38053808 return wtype ;
38063809}
38073810
3811+ size_t ggml_tensor_overhead (void ) {
3812+ return GGML_OBJECT_SIZE + GGML_TENSOR_SIZE + 16 ;
3813+ }
3814+
38083815static inline bool ggml_is_transposed (const struct ggml_tensor * tensor ) {
38093816 return tensor -> nb [0 ] > tensor -> nb [1 ];
38103817}
@@ -4017,6 +4024,10 @@ size_t ggml_set_scratch(struct ggml_context * ctx, struct ggml_scratch scratch)
40174024 return result ;
40184025}
40194026
4027+ void ggml_set_no_alloc (struct ggml_context * ctx , bool no_alloc ) {
4028+ ctx -> no_alloc = no_alloc ;
4029+ }
4030+
40204031// IMPORTANT:
40214032// when creating "opt" tensors, always save and load the scratch buffer
40224033// this is an error prone process, but it is necessary to support inplace
@@ -4061,7 +4072,7 @@ struct ggml_tensor * ggml_new_tensor_impl(
40614072 struct ggml_object * const obj_new = (struct ggml_object * )(mem_buffer + cur_end );
40624073
40634074 if (ctx -> scratch .data == NULL || data != NULL ) {
4064- size_needed += sizeof ( struct ggml_tensor ) ;
4075+ size_needed += GGML_TENSOR_SIZE ;
40654076
40664077 if (cur_end + size_needed + GGML_OBJECT_SIZE > ctx -> mem_size ) {
40674078 GGML_PRINT ("%s: not enough space in the context's memory pool (needed %zu, available %zu)\n" ,
@@ -4077,14 +4088,15 @@ struct ggml_tensor * ggml_new_tensor_impl(
40774088 };
40784089 } else {
40794090 if (ctx -> scratch .offs + size_needed > ctx -> scratch .size ) {
4080- GGML_PRINT ("%s: not enough space in the scratch memory\n" , __func__ );
4091+ GGML_PRINT ("%s: not enough space in the scratch memory pool (needed %zu, available %zu)\n" ,
4092+ __func__ , ctx -> scratch .offs + size_needed , ctx -> scratch .size );
40814093 assert (false);
40824094 return NULL ;
40834095 }
40844096
4085- if (cur_end + sizeof ( struct ggml_tensor ) + GGML_OBJECT_SIZE > ctx -> mem_size ) {
4097+ if (cur_end + GGML_TENSOR_SIZE + GGML_OBJECT_SIZE > ctx -> mem_size ) {
40864098 GGML_PRINT ("%s: not enough space in the context's memory pool (needed %zu, available %zu)\n" ,
4087- __func__ , cur_end + sizeof ( struct ggml_tensor ) + GGML_OBJECT_SIZE , ctx -> mem_size );
4099+ __func__ , cur_end + GGML_TENSOR_SIZE + GGML_OBJECT_SIZE , ctx -> mem_size );
40884100 assert (false);
40894101 return NULL ;
40904102 }
@@ -4093,7 +4105,7 @@ struct ggml_tensor * ggml_new_tensor_impl(
40934105
40944106 * obj_new = (struct ggml_object ) {
40954107 .offs = cur_end + GGML_OBJECT_SIZE ,
4096- .size = sizeof ( struct ggml_tensor ) ,
4108+ .size = GGML_TENSOR_SIZE ,
40974109 .next = NULL ,
40984110 };
40994111
@@ -13792,11 +13804,19 @@ static void ggml_visit_parents(struct ggml_cgraph * cgraph, struct ggml_tensor *
1379213804 // reached a leaf node, not part of the gradient graph (e.g. a constant)
1379313805 GGML_ASSERT (cgraph -> n_leafs < GGML_MAX_NODES );
1379413806
13807+ if (strlen (node -> name ) == 0 ) {
13808+ snprintf (node -> name , sizeof (node -> name ), "leaf_%d" , cgraph -> n_leafs );
13809+ }
13810+
1379513811 cgraph -> leafs [cgraph -> n_leafs ] = node ;
1379613812 cgraph -> n_leafs ++ ;
1379713813 } else {
1379813814 GGML_ASSERT (cgraph -> n_nodes < GGML_MAX_NODES );
1379913815
13816+ if (strlen (node -> name ) == 0 ) {
13817+ snprintf (node -> name , sizeof (node -> name ), "node_%d" , cgraph -> n_nodes );
13818+ }
13819+
1380013820 cgraph -> nodes [cgraph -> n_nodes ] = node ;
1380113821 cgraph -> grads [cgraph -> n_nodes ] = node -> grad ;
1380213822 cgraph -> n_nodes ++ ;
@@ -14510,6 +14530,26 @@ void ggml_graph_reset(struct ggml_cgraph * cgraph) {
1451014530 }
1451114531}
1451214532
14533+ struct ggml_tensor * ggml_get_tensor_by_name (struct ggml_cgraph * cgraph , const char * name ) {
14534+ for (int i = 0 ; i < cgraph -> n_leafs ; i ++ ) {
14535+ struct ggml_tensor * leaf = cgraph -> leafs [i ];
14536+
14537+ if (strcmp (leaf -> name , name ) == 0 ) {
14538+ return leaf ;
14539+ }
14540+ }
14541+
14542+ for (int i = 0 ; i < cgraph -> n_nodes ; i ++ ) {
14543+ struct ggml_tensor * node = cgraph -> nodes [i ];
14544+
14545+ if (strcmp (node -> name , name ) == 0 ) {
14546+ return node ;
14547+ }
14548+ }
14549+
14550+ return NULL ;
14551+ }
14552+
1451314553void ggml_graph_print (const struct ggml_cgraph * cgraph ) {
1451414554 int64_t perf_total_per_op_us [GGML_OP_COUNT ] = {0 };
1451514555
@@ -14527,7 +14567,7 @@ void ggml_graph_print(const struct ggml_cgraph * cgraph) {
1452714567 GGML_PRINT (" - %3d: [ %5" PRId64 ", %5" PRId64 ", %5" PRId64 "] %16s %s (%3d) cpu = %7.3f / %7.3f ms, wall = %7.3f / %7.3f ms\n" ,
1452814568 i ,
1452914569 node -> ne [0 ], node -> ne [1 ], node -> ne [2 ],
14530- GGML_OP_LABEL [node -> op ], node -> is_param ? "x" : node -> grad ? "g" : " " , node -> perf_runs ,
14570+ GGML_OP_NAME [node -> op ], node -> is_param ? "x" : node -> grad ? "g" : " " , node -> perf_runs ,
1453114571 (double ) node -> perf_cycles / (double ) ggml_cycles_per_ms (),
1453214572 (double ) node -> perf_cycles / (double ) ggml_cycles_per_ms () / (double ) node -> perf_runs ,
1453314573 (double ) node -> perf_time_us / 1000.0 ,
@@ -14541,15 +14581,15 @@ void ggml_graph_print(const struct ggml_cgraph * cgraph) {
1454114581 GGML_PRINT (" - %3d: [ %5" PRId64 ", %5" PRId64 "] %8s\n" ,
1454214582 i ,
1454314583 node -> ne [0 ], node -> ne [1 ],
14544- GGML_OP_LABEL [node -> op ]);
14584+ GGML_OP_NAME [node -> op ]);
1454514585 }
1454614586
1454714587 for (int i = 0 ; i < GGML_OP_COUNT ; i ++ ) {
1454814588 if (perf_total_per_op_us [i ] == 0 ) {
1454914589 continue ;
1455014590 }
1455114591
14552- GGML_PRINT ("perf_total_per_op_us[%16s] = %7.3f ms\n" , GGML_OP_LABEL [i ], (double ) perf_total_per_op_us [i ] / 1000.0 );
14592+ GGML_PRINT ("perf_total_per_op_us[%16s] = %7.3f ms\n" , GGML_OP_NAME [i ], (double ) perf_total_per_op_us [i ] / 1000.0 );
1455314593 }
1455414594
1455514595 GGML_PRINT ("========================================\n" );
0 commit comments