Skip to content

Commit fa10954

Browse files
authored
Merge pull request #3230 from PaulBoersma/master
-
2 parents d389ced + a092eec commit fa10954

6 files changed

Lines changed: 150 additions & 77 deletions

File tree

external/portaudio/pa_endianness.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ extern "C"
7070
#if defined(NDEBUG)
7171
#define PA_VALIDATE_ENDIANNESS
7272
#else
73-
#if defined(PA_LITTLE_ENDIAN)
73+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
7474
#define PA_VALIDATE_ENDIANNESS \
7575
{ \
7676
const long nativeOne = 1; \
7777
assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 1 ); \
7878
}
79-
#elif defined(PA_BIG_ENDIAN)
79+
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
8080
#define PA_VALIDATE_ENDIANNESS \
8181
{ \
8282
const long nativeOne = 1; \

external/whispercpp/READ_ME.TXT

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,82 @@ with
338338
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
339339
```
340340

341-
4. Models
341+
4. General compatibility with C++
342+
---------------------------------
343+
4.1. Assigning from `void *`
344+
----------------------------
345+
This is ruled out in C++, so we cast according to the following examples:
346+
```
347+
galloc->node_allocs = ggml_calloc(graph->n_nodes, sizeof(struct node_alloc)); // C
348+
galloc->node_allocs = (struct node_alloc *) ggml_calloc(graph->n_nodes, sizeof(struct node_alloc)); // C++
349+
350+
result->vals = GGML_CALLOC(result->set.size, sizeof(struct ggml_tensor *)); // C
351+
result->vals = (struct ggml_tensor **) GGML_CALLOC(result->set.size, sizeof(struct ggml_tensor *)); // C++
352+
353+
char * const data = tensor->data; // C
354+
char * const data = (char *) tensor->data; // C++
355+
356+
const float * l = left; // C
357+
const float * l = (const float *) left; // C++
358+
359+
quantize_row_q2_K_ref(src, dst, (int64_t)nrow*n_per_row); // C
360+
quantize_row_q2_K_ref(src, (block_q2_K *) dst, (int64_t)nrow*n_per_row); // C++
361+
362+
char (*atomic_current_chunk)[CACHE_LINE_SIZE] = blabla // C
363+
char (*atomic_current_chunk)[CACHE_LINE_SIZE] = (char (*)[CACHE_LINE_SIZE]) blabla // C++
364+
```
365+
366+
4.2. Assigning int to enum
367+
--------------------------
368+
This is also ruled out in C++, so we cast according to the following examples:
369+
```
370+
const enum ggml_op_pool op = ggml_get_op_params_i32(tensor, 0);
371+
const enum ggml_op_pool op = (enum ggml_op_pool) ggml_get_op_params_i32(tensor, 0);
372+
373+
p->prio = 0; // C
374+
p->prio = (enum ggml_sched_priority) 0; // C++
375+
376+
static struct ggml_state g_state = {0}; // C
377+
static struct ggml_state g_state {}; // C++
378+
```
379+
380+
4.3. Assignments in initializer lists
381+
-------------------------------------
382+
Types have to match more closely in C++, so we cast according to the following examples:
383+
```
384+
*cgraph = (struct ggml_cgraph) { size, ... // C
385+
*cgraph = (struct ggml_cgraph) { (int) size, ... // C++
386+
387+
int32_t params[] = { nb1, nb2, nb3, offset, inplace ? 1 : 0 }; // C
388+
int32_t params[] = { (int32_t) nb1, (int32_t) nb2, (int32_t) nb3, (int32_t) offset, inplace ? 1 : 0 }; // C++
389+
390+
MMID_MATRIX_ROW(i02, matrix_row_counts[i02]) = (struct mmid_row_mapping) {id, iid1}; // C
391+
MMID_MATRIX_ROW(i02, matrix_row_counts[i02]) = (struct mmid_row_mapping) {id, (int32_t) iid1}; // C++
392+
393+
union { uint16_t u16; ggml_fp16_t fp16; } u = {i}; // C
394+
union { uint16_t u16; ggml_fp16_t fp16; } u = { (uint16_t) i }; // C++
395+
396+
struct ggml_compute_params params = {
397+
/*.ith =*/ state->ith,
398+
/*.nth =*/ atomic_load_explicit(&tp->n_graph, memory_order_relaxed) & GGML_THREADPOOL_N_THREADS_MASK,
399+
/*.wsize =*/ cplan->work_size,
400+
/*.wdata =*/ cplan->work_data,
401+
/*.threadpool =*/ tp,
402+
/*.use_ref =*/ cplan->use_ref,
403+
}; // C
404+
struct ggml_compute_params params = {
405+
/*.ith =*/ state->ith,
406+
/*.nth =*/ (int) (atomic_load_explicit(&tp->n_graph, memory_order_relaxed) & GGML_THREADPOOL_N_THREADS_MASK),
407+
/*.wsize =*/ cplan->work_size,
408+
/*.wdata =*/ cplan->work_data,
409+
/*.threadpool =*/ tp,
410+
/*.use_ref =*/ cplan->use_ref,
411+
}; // C++
412+
```
413+
414+
5. Models
342415
---------
343-
4.1. Bringing Silero-VAD model to Praat source code
416+
5.1. Bringing Silero-VAD model to Praat source code
344417
---------------------------------------------------
345418
First, we download the ggml Silero model from the original whisper.cpp repository:
346419
```
@@ -353,10 +426,10 @@ We then convert this binary to a C header using `xxd` and copy it to external/wh
353426
xxd -i -n ggml_silero_bin -n whisper.cpp/models/ggml-silero-v6.2.0.bin > praat/external/whispercpp/ggml-silero-vad-model-data.h
354427
```
355428

356-
4.2. Segmentation
429+
5.2. Segmentation
357430
-----------------
358431
todo
359432

360-
4.3. Embedding
433+
5.3. Embedding
361434
--------------
362-
todo
435+
todo

external/whispercpp/ggml-alloc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int ggml_dyn_tallocr_new_chunk(struct ggml_dyn_tallocr * alloc, size_t mi
159159
if (alloc->n_chunks >= GGML_VBUFFER_MAX_CHUNKS) {
160160
return -1;
161161
}
162-
struct tallocr_chunk * chunk = ggml_calloc(1, sizeof(struct tallocr_chunk));
162+
struct tallocr_chunk * chunk = (struct tallocr_chunk *) ggml_calloc(1, sizeof(struct tallocr_chunk));
163163
chunk->n_free_blocks = 1;
164164
chunk->free_blocks[0].offset = 0;
165165
// available space in a chunk is limited to max_chunk_size, but can be higher if:
@@ -497,13 +497,13 @@ ggml_gallocr_t ggml_gallocr_new_n(ggml_backend_buffer_type_t * bufts, int n_bufs
497497
ggml_gallocr_t galloc = (ggml_gallocr_t)ggml_calloc(1, sizeof(struct ggml_gallocr));
498498
GGML_ASSERT(galloc != NULL);
499499

500-
galloc->bufts = ggml_calloc(n_bufs, sizeof(ggml_backend_buffer_type_t));
500+
galloc->bufts = (ggml_backend_buffer_type_t *) ggml_calloc(n_bufs, sizeof(ggml_backend_buffer_type_t));
501501
GGML_ASSERT(galloc->bufts != NULL);
502502

503-
galloc->buffers = ggml_calloc(n_bufs, sizeof(struct vbuffer *));
503+
galloc->buffers = (struct vbuffer **) ggml_calloc(n_bufs, sizeof(struct vbuffer *));
504504
GGML_ASSERT(galloc->buffers != NULL);
505505

506-
galloc->buf_tallocs = ggml_calloc(n_bufs, sizeof(struct ggml_dyn_tallocr *));
506+
galloc->buf_tallocs = (struct ggml_dyn_tallocr **) ggml_calloc(n_bufs, sizeof(struct ggml_dyn_tallocr *));
507507
GGML_ASSERT(galloc->buf_tallocs != NULL);
508508

509509
for (int i = 0; i < n_bufs; i++) {
@@ -833,7 +833,7 @@ static bool ggml_gallocr_reserve_n_impl(
833833
GGML_ASSERT(galloc->hash_set.keys != NULL);
834834

835835
ggml_raw_free(galloc->hash_values);
836-
galloc->hash_values = ggml_malloc(sizeof(struct hash_node) * galloc->hash_set.size);
836+
galloc->hash_values = (struct hash_node *) ggml_malloc(sizeof(struct hash_node) * galloc->hash_set.size);
837837
GGML_ASSERT(galloc->hash_values != NULL);
838838
}
839839

@@ -848,7 +848,7 @@ static bool ggml_gallocr_reserve_n_impl(
848848
// set the node_allocs from the hash table
849849
if (galloc->n_nodes < graph->n_nodes) {
850850
ggml_raw_free(galloc->node_allocs);
851-
galloc->node_allocs = ggml_calloc(graph->n_nodes, sizeof(struct node_alloc));
851+
galloc->node_allocs = (struct node_alloc *) ggml_calloc(graph->n_nodes, sizeof(struct node_alloc));
852852
GGML_ASSERT(galloc->node_allocs != NULL);
853853
}
854854
galloc->n_nodes = graph->n_nodes;
@@ -881,7 +881,7 @@ static bool ggml_gallocr_reserve_n_impl(
881881
}
882882
if (galloc->n_leafs < graph->n_leafs) {
883883
ggml_raw_free(galloc->leaf_allocs);
884-
galloc->leaf_allocs = ggml_calloc(graph->n_leafs, sizeof(galloc->leaf_allocs[0]));
884+
galloc->leaf_allocs = (struct leaf_alloc *) ggml_calloc(graph->n_leafs, sizeof(galloc->leaf_allocs[0]));
885885
GGML_ASSERT(galloc->leaf_allocs != NULL);
886886
}
887887
galloc->n_leafs = graph->n_leafs;
@@ -1134,7 +1134,7 @@ static bool alloc_tensor_range(struct ggml_context * ctx,
11341134
return false;
11351135
}
11361136

1137-
*buffers = ggml_realloc(*buffers, sizeof(ggml_backend_buffer_t) * (*n_buffers + 1));
1137+
*buffers = (ggml_backend_buffer_t *) ggml_realloc(*buffers, sizeof(ggml_backend_buffer_t) * (*n_buffers + 1));
11381138
(*buffers)[(*n_buffers)++] = buffer;
11391139

11401140
struct ggml_tallocr tallocr = ggml_tallocr_new(buffer);

external/whispercpp/ggml-cpu.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ struct ggml_state {
372372
struct ggml_numa_nodes numa;
373373
};
374374

375-
static struct ggml_state g_state = {0};
375+
static struct ggml_state g_state {};
376376

377377
void ggml_barrier(struct ggml_threadpool * tp) {
378378
int n_threads = atomic_load_explicit(&tp->n_graph, memory_order_relaxed) & GGML_THREADPOOL_N_THREADS_MASK;
@@ -572,7 +572,7 @@ struct ggml_tensor * ggml_set_i32 (struct ggml_tensor * tensor, int32_t value) {
572572
const int nc = tensor->ne[0];
573573
const size_t n1 = tensor->nb[1];
574574

575-
char * const data = tensor->data;
575+
char * const data = (char *) tensor->data;
576576

577577
switch (tensor->type) {
578578
case GGML_TYPE_I8:
@@ -631,7 +631,7 @@ struct ggml_tensor * ggml_set_f32(struct ggml_tensor * tensor, float value) {
631631
const int nc = tensor->ne[0];
632632
const size_t n1 = tensor->nb[1];
633633

634-
char * const data = tensor->data;
634+
char * const data = (char *) tensor->data;
635635

636636
switch (tensor->type) {
637637
case GGML_TYPE_I8:
@@ -1116,7 +1116,7 @@ UseGgmlGemm1:;
11161116
#endif
11171117

11181118
if (src1->type != vec_dot_type) {
1119-
char * wdata = params->wdata;
1119+
char * wdata = (char *) params->wdata;
11201120

11211121
const size_t nbw0 = ggml_type_size(vec_dot_type);
11221122
const size_t nbw1 = ggml_row_size(vec_dot_type, ne10);
@@ -1368,18 +1368,18 @@ static void ggml_compute_forward_mul_mat_id(
13681368
}
13691369

13701370
int64_t * matrix_row_counts = // [n_as]
1371-
incr_ptr_aligned(&wdata_cur, n_as*sizeof(int64_t), sizeof(int64_t));
1371+
(int64_t *) incr_ptr_aligned(&wdata_cur, n_as*sizeof(int64_t), sizeof(int64_t));
13721372

13731373
struct mmid_row_mapping * matrix_rows = // [n_as][ids->ne[0]*ids->ne[1]]
1374-
incr_ptr_aligned(&wdata_cur, n_as*ids->ne[0]*ids->ne[1]*sizeof(struct mmid_row_mapping), sizeof(int64_t));
1374+
(struct mmid_row_mapping *) incr_ptr_aligned(&wdata_cur, n_as*ids->ne[0]*ids->ne[1]*sizeof(struct mmid_row_mapping), sizeof(int64_t));
13751375

13761376
char (*atomic_current_chunk)[CACHE_LINE_SIZE] = // [n_as]
1377-
incr_ptr_aligned(&wdata_cur, CACHE_LINE_SIZE * n_as, CACHE_LINE_SIZE);
1377+
(char (*)[CACHE_LINE_SIZE]) incr_ptr_aligned(&wdata_cur, CACHE_LINE_SIZE * n_as, CACHE_LINE_SIZE);
13781378

13791379
GGML_ASSERT(params->wsize >= (size_t)((char *) wdata_cur - (char *) params->wdata));
13801380

13811381
if (src1->type != vec_dot_type) {
1382-
char * wdata = params->wdata;
1382+
char * wdata = (char *) params->wdata;
13831383

13841384
const size_t nbw0 = ggml_type_size(vec_dot_type);
13851385
const size_t nbw1 = ggml_row_size(vec_dot_type, ne10);
@@ -1426,7 +1426,7 @@ static void ggml_compute_forward_mul_mat_id(
14261426

14271427
assert(i02 >= 0 && i02 < n_as);
14281428

1429-
MMID_MATRIX_ROW(i02, matrix_row_counts[i02]) = (struct mmid_row_mapping) {id, iid1};
1429+
MMID_MATRIX_ROW(i02, matrix_row_counts[i02]) = (struct mmid_row_mapping) {id, (int32_t) iid1};
14301430
matrix_row_counts[i02] += 1;
14311431
}
14321432
}
@@ -2767,7 +2767,7 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
27672767

27682768
struct ggml_compute_params params = {
27692769
/*.ith =*/ state->ith,
2770-
/*.nth =*/ atomic_load_explicit(&tp->n_graph, memory_order_relaxed) & GGML_THREADPOOL_N_THREADS_MASK,
2770+
/*.nth =*/ (int) (atomic_load_explicit(&tp->n_graph, memory_order_relaxed) & GGML_THREADPOOL_N_THREADS_MASK),
27712771
/*.wsize =*/ cplan->work_size,
27722772
/*.wdata =*/ cplan->work_data,
27732773
/*.threadpool =*/ tp,
@@ -2960,7 +2960,7 @@ static struct ggml_threadpool * ggml_threadpool_new_impl(
29602960
struct ggml_cplan * cplan) {
29612961

29622962
struct ggml_threadpool * threadpool =
2963-
ggml_aligned_malloc(sizeof(struct ggml_threadpool));
2963+
(struct ggml_threadpool *) ggml_aligned_malloc(sizeof(struct ggml_threadpool));
29642964
{
29652965
threadpool->cgraph = cgraph;
29662966
threadpool->cplan = cplan;
@@ -2980,7 +2980,7 @@ static struct ggml_threadpool * ggml_threadpool_new_impl(
29802980

29812981
// Allocate and init workers state
29822982
const size_t workers_size = sizeof(struct ggml_compute_state) * tpp->n_threads;
2983-
struct ggml_compute_state * workers = ggml_aligned_malloc(workers_size);
2983+
struct ggml_compute_state * workers = (struct ggml_compute_state *) ggml_aligned_malloc(workers_size);
29842984

29852985
memset(workers, 0, workers_size);
29862986
for (int j = 0; j < tpp->n_threads; j++) {
@@ -3512,7 +3512,7 @@ void ggml_cpu_init(void) {
35123512
union {
35133513
uint16_t u16;
35143514
ggml_fp16_t fp16;
3515-
} u = {i};
3515+
} u = { (uint16_t) i };
35163516
float f = GGML_COMPUTE_FP16_TO_FP32(u.fp16);
35173517
ggml_table_f32_f16[i] = f;
35183518
ggml_table_gelu_f16[i] = GGML_CPU_FP32_TO_FP16(ggml_gelu_f32(f));

0 commit comments

Comments
 (0)