@@ -3494,7 +3494,7 @@ static bool GGML_IS_QUANTIZED[GGML_TYPE_COUNT] = {
3494
3494
};
3495
3495
static_assert (GGML_TYPE_COUNT == 13 , "GGML_IS_QUANTIZED is outdated" );
3496
3496
3497
- static const char * GGML_OP_LABEL [GGML_OP_COUNT ] = {
3497
+ static const char * GGML_OP_NAME [GGML_OP_COUNT ] = {
3498
3498
"NONE" ,
3499
3499
3500
3500
"DUP" ,
@@ -3749,6 +3749,9 @@ const char * ggml_type_name(enum ggml_type type) {
3749
3749
return GGML_TYPE_NAME [type ];
3750
3750
}
3751
3751
3752
+ const char * ggml_op_name (enum ggml_op op ) {
3753
+ return GGML_OP_NAME [op ];
3754
+ }
3752
3755
3753
3756
size_t ggml_element_size (const struct ggml_tensor * tensor ) {
3754
3757
return GGML_TYPE_SIZE [tensor -> type ];
@@ -4017,6 +4020,10 @@ size_t ggml_set_scratch(struct ggml_context * ctx, struct ggml_scratch scratch)
4017
4020
return result ;
4018
4021
}
4019
4022
4023
+ void ggml_set_no_alloc (struct ggml_context * ctx , bool no_alloc ) {
4024
+ ctx -> no_alloc = no_alloc ;
4025
+ }
4026
+
4020
4027
// IMPORTANT:
4021
4028
// when creating "opt" tensors, always save and load the scratch buffer
4022
4029
// this is an error prone process, but it is necessary to support inplace
@@ -4061,7 +4068,7 @@ struct ggml_tensor * ggml_new_tensor_impl(
4061
4068
struct ggml_object * const obj_new = (struct ggml_object * )(mem_buffer + cur_end );
4062
4069
4063
4070
if (ctx -> scratch .data == NULL || data != NULL ) {
4064
- size_needed += sizeof ( struct ggml_tensor ) ;
4071
+ size_needed += GGML_TENSOR_SIZE ;
4065
4072
4066
4073
if (cur_end + size_needed + GGML_OBJECT_SIZE > ctx -> mem_size ) {
4067
4074
GGML_PRINT ("%s: not enough space in the context's memory pool (needed %zu, available %zu)\n" ,
@@ -4077,14 +4084,15 @@ struct ggml_tensor * ggml_new_tensor_impl(
4077
4084
};
4078
4085
} else {
4079
4086
if (ctx -> scratch .offs + size_needed > ctx -> scratch .size ) {
4080
- GGML_PRINT ("%s: not enough space in the scratch memory\n" , __func__ );
4087
+ GGML_PRINT ("%s: not enough space in the scratch memory pool (needed %zu, available %zu)\n" ,
4088
+ __func__ , ctx -> scratch .offs + size_needed , ctx -> scratch .size );
4081
4089
assert (false);
4082
4090
return NULL ;
4083
4091
}
4084
4092
4085
- if (cur_end + sizeof ( struct ggml_tensor ) + GGML_OBJECT_SIZE > ctx -> mem_size ) {
4093
+ if (cur_end + GGML_TENSOR_SIZE + GGML_OBJECT_SIZE > ctx -> mem_size ) {
4086
4094
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 );
4095
+ __func__ , cur_end + GGML_TENSOR_SIZE + GGML_OBJECT_SIZE , ctx -> mem_size );
4088
4096
assert (false);
4089
4097
return NULL ;
4090
4098
}
@@ -4093,7 +4101,7 @@ struct ggml_tensor * ggml_new_tensor_impl(
4093
4101
4094
4102
* obj_new = (struct ggml_object ) {
4095
4103
.offs = cur_end + GGML_OBJECT_SIZE ,
4096
- .size = sizeof ( struct ggml_tensor ) ,
4104
+ .size = GGML_TENSOR_SIZE ,
4097
4105
.next = NULL ,
4098
4106
};
4099
4107
@@ -13792,11 +13800,19 @@ static void ggml_visit_parents(struct ggml_cgraph * cgraph, struct ggml_tensor *
13792
13800
// reached a leaf node, not part of the gradient graph (e.g. a constant)
13793
13801
GGML_ASSERT (cgraph -> n_leafs < GGML_MAX_NODES );
13794
13802
13803
+ if (strlen (node -> name ) == 0 ) {
13804
+ snprintf (node -> name , sizeof (node -> name ), "leaf_%d" , cgraph -> n_leafs );
13805
+ }
13806
+
13795
13807
cgraph -> leafs [cgraph -> n_leafs ] = node ;
13796
13808
cgraph -> n_leafs ++ ;
13797
13809
} else {
13798
13810
GGML_ASSERT (cgraph -> n_nodes < GGML_MAX_NODES );
13799
13811
13812
+ if (strlen (node -> name ) == 0 ) {
13813
+ snprintf (node -> name , sizeof (node -> name ), "node_%d" , cgraph -> n_nodes );
13814
+ }
13815
+
13800
13816
cgraph -> nodes [cgraph -> n_nodes ] = node ;
13801
13817
cgraph -> grads [cgraph -> n_nodes ] = node -> grad ;
13802
13818
cgraph -> n_nodes ++ ;
@@ -14510,6 +14526,18 @@ void ggml_graph_reset(struct ggml_cgraph * cgraph) {
14510
14526
}
14511
14527
}
14512
14528
14529
+ struct ggml_tensor * ggml_get_tensor_by_name (struct ggml_cgraph * cgraph , const char * name ) {
14530
+ for (int i = 0 ; i < cgraph -> n_nodes ; i ++ ) {
14531
+ struct ggml_tensor * node = cgraph -> nodes [i ];
14532
+
14533
+ if (strcmp (node -> name , name ) == 0 ) {
14534
+ return node ;
14535
+ }
14536
+ }
14537
+
14538
+ return NULL ;
14539
+ }
14540
+
14513
14541
void ggml_graph_print (const struct ggml_cgraph * cgraph ) {
14514
14542
int64_t perf_total_per_op_us [GGML_OP_COUNT ] = {0 };
14515
14543
@@ -14527,7 +14555,7 @@ void ggml_graph_print(const struct ggml_cgraph * cgraph) {
14527
14555
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" ,
14528
14556
i ,
14529
14557
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 ,
14558
+ GGML_OP_NAME [node -> op ], node -> is_param ? "x" : node -> grad ? "g" : " " , node -> perf_runs ,
14531
14559
(double ) node -> perf_cycles / (double ) ggml_cycles_per_ms (),
14532
14560
(double ) node -> perf_cycles / (double ) ggml_cycles_per_ms () / (double ) node -> perf_runs ,
14533
14561
(double ) node -> perf_time_us / 1000.0 ,
@@ -14541,15 +14569,15 @@ void ggml_graph_print(const struct ggml_cgraph * cgraph) {
14541
14569
GGML_PRINT (" - %3d: [ %5" PRId64 ", %5" PRId64 "] %8s\n" ,
14542
14570
i ,
14543
14571
node -> ne [0 ], node -> ne [1 ],
14544
- GGML_OP_LABEL [node -> op ]);
14572
+ GGML_OP_NAME [node -> op ]);
14545
14573
}
14546
14574
14547
14575
for (int i = 0 ; i < GGML_OP_COUNT ; i ++ ) {
14548
14576
if (perf_total_per_op_us [i ] == 0 ) {
14549
14577
continue ;
14550
14578
}
14551
14579
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 );
14580
+ 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 );
14553
14581
}
14554
14582
14555
14583
GGML_PRINT ("========================================\n" );
0 commit comments