Skip to content

Commit b2f1af8

Browse files
committed
wip
1 parent b1306c4 commit b2f1af8

File tree

7 files changed

+252
-370
lines changed

7 files changed

+252
-370
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test: $(TEST_TARGETS)
6565
./$$test_target; \
6666
fi; \
6767
if [ $$? -ne 0 ]; then \
68-
printf 'Test $$test_target FAILED!\n\n' $$test_target; \
68+
printf 'Test %s FAILED!\n\n' $$test_target; \
6969
failures=$$(( failures + 1 )); \
7070
else \
7171
printf 'Test %s passed.\n\n' $$test_target; \

ggml-alloc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,10 @@ void ggml_allocr_set_parse_seq(ggml_allocr_t alloc, const int * list, int n) {
736736
}
737737

738738
void ggml_allocr_free(ggml_allocr_t alloc) {
739+
if (alloc == NULL) {
740+
return;
741+
}
742+
739743
ggml_gallocr_free(alloc->galloc);
740744
ggml_tallocr_free(alloc->talloc);
741745
free(alloc);

ggml-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static ggml_backend_graph_plan_t ggml_backend_cpu_graph_plan_create(ggml_backend
505505
struct ggml_backend_plan_cpu * cpu_plan = malloc(sizeof(struct ggml_backend_plan_cpu));
506506

507507
cpu_plan->cplan = ggml_graph_plan(cgraph, cpu_ctx->n_threads);
508-
cpu_plan->cgraph = *cgraph;
508+
cpu_plan->cgraph = *cgraph; // FIXME: deep copy
509509

510510
if (cpu_plan->cplan.work_size > 0) {
511511
cpu_plan->cplan.work_data = malloc(cpu_plan->cplan.work_size);

ggml-cuda.cu

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7057,6 +7057,7 @@ inline void ggml_cuda_op_upscale(
70577057

70587058
(void) src1;
70597059
(void) dst;
7060+
(void) src1_dd;
70607061
}
70617062

70627063
inline void ggml_cuda_op_pad(
@@ -7073,6 +7074,7 @@ inline void ggml_cuda_op_pad(
70737074

70747075
(void) src1;
70757076
(void) dst;
7077+
(void) src1_dd;
70767078
}
70777079

70787080
inline void ggml_cuda_op_rms_norm(
@@ -8958,7 +8960,7 @@ void ggml_cuda_transform_tensor(void * data, struct ggml_tensor * tensor) {
89588960

89598961
char * buf;
89608962
CUDA_CHECK(cudaMalloc(&buf, size));
8961-
char * buf_host = (char*)data + offset_split;
8963+
char * buf_host = (char *)data + offset_split;
89628964

89638965
// set padding to 0 to avoid possible NaN values
89648966
if (size > original_size) {

ggml.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,20 +2383,8 @@ size_t ggml_get_mem_size(const struct ggml_context * ctx) {
23832383
size_t ggml_get_max_tensor_size(const struct ggml_context * ctx) {
23842384
size_t max_size = 0;
23852385

2386-
struct ggml_object * obj = ctx->objects_begin;
2387-
2388-
while (obj != NULL) {
2389-
if (obj->type == GGML_OBJECT_TENSOR) {
2390-
struct ggml_tensor * tensor = (struct ggml_tensor *) ((char *) ctx->mem_buffer + obj->offs);
2391-
2392-
const size_t size = ggml_nbytes(tensor);
2393-
2394-
if (max_size < size) {
2395-
max_size = size;
2396-
}
2397-
}
2398-
2399-
obj = obj->next;
2386+
for (struct ggml_tensor * tensor = ggml_get_first_tensor(ctx); tensor != NULL; tensor = ggml_get_next_tensor(ctx, tensor)) {
2387+
max_size = MAX(max_size, ggml_nbytes(tensor));
24002388
}
24012389

24022390
return max_size;
@@ -3093,7 +3081,7 @@ struct ggml_tensor * ggml_view_tensor(
30933081
return result;
30943082
}
30953083

3096-
struct ggml_tensor * ggml_get_first_tensor(struct ggml_context * ctx) {
3084+
struct ggml_tensor * ggml_get_first_tensor(const struct ggml_context * ctx) {
30973085
struct ggml_object * obj = ctx->objects_begin;
30983086

30993087
char * const mem_buffer = ctx->mem_buffer;
@@ -3109,7 +3097,7 @@ struct ggml_tensor * ggml_get_first_tensor(struct ggml_context * ctx) {
31093097
return NULL;
31103098
}
31113099

3112-
struct ggml_tensor * ggml_get_next_tensor(struct ggml_context * ctx, struct ggml_tensor * tensor) {
3100+
struct ggml_tensor * ggml_get_next_tensor(const struct ggml_context * ctx, struct ggml_tensor * tensor) {
31133101
struct ggml_object * obj = (struct ggml_object *) ((char *)tensor - GGML_OBJECT_SIZE);
31143102
obj = obj->next;
31153103

@@ -19179,6 +19167,10 @@ char * gguf_get_tensor_name(const struct gguf_context * ctx, int i) {
1917919167
return ctx->infos[i].name.data;
1918019168
}
1918119169

19170+
enum ggml_type gguf_get_tensor_type(const struct gguf_context * ctx, int i) {
19171+
return ctx->infos[i].type;
19172+
}
19173+
1918219174
// returns the index
1918319175
static int gguf_get_or_add_key(struct gguf_context * ctx, const char * key) {
1918419176
const int idx = gguf_find_key(ctx, key);

ggml.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ extern "C" {
729729
GGML_API struct ggml_tensor * ggml_view_tensor(struct ggml_context * ctx, struct ggml_tensor * src);
730730

731731
// Context tensor enumeration and lookup
732-
GGML_API struct ggml_tensor * ggml_get_first_tensor(struct ggml_context * ctx);
733-
GGML_API struct ggml_tensor * ggml_get_next_tensor (struct ggml_context * ctx, struct ggml_tensor * tensor);
732+
GGML_API struct ggml_tensor * ggml_get_first_tensor(const struct ggml_context * ctx);
733+
GGML_API struct ggml_tensor * ggml_get_next_tensor (const struct ggml_context * ctx, struct ggml_tensor * tensor);
734734
GGML_API struct ggml_tensor * ggml_get_tensor(struct ggml_context * ctx, const char * name);
735735

736736
GGML_API struct ggml_tensor * ggml_set_zero(struct ggml_tensor * tensor);
@@ -2123,10 +2123,11 @@ extern "C" {
21232123
GGML_API const void * gguf_get_arr_data(const struct gguf_context * ctx, int key_id);
21242124
GGML_API const char * gguf_get_arr_str (const struct gguf_context * ctx, int key_id, int i);
21252125

2126-
GGML_API int gguf_get_n_tensors (const struct gguf_context * ctx);
2127-
GGML_API int gguf_find_tensor (const struct gguf_context * ctx, const char * name);
2128-
GGML_API size_t gguf_get_tensor_offset(const struct gguf_context * ctx, int i);
2129-
GGML_API char * gguf_get_tensor_name (const struct gguf_context * ctx, int i);
2126+
GGML_API int gguf_get_n_tensors (const struct gguf_context * ctx);
2127+
GGML_API int gguf_find_tensor (const struct gguf_context * ctx, const char * name);
2128+
GGML_API size_t gguf_get_tensor_offset(const struct gguf_context * ctx, int i);
2129+
GGML_API char * gguf_get_tensor_name (const struct gguf_context * ctx, int i);
2130+
GGML_API enum ggml_type gguf_get_tensor_type (const struct gguf_context * ctx, int i);
21302131

21312132
// overrides existing values or adds a new one
21322133
GGML_API void gguf_set_val_u8 (struct gguf_context * ctx, const char * key, uint8_t val);

0 commit comments

Comments
 (0)