Skip to content

Commit

Permalink
ggml : add GGML_TENSOR_LOCALS helper macros (#309)
Browse files Browse the repository at this point in the history
* [WIP] ref #292

* Further code reduction

* ggml : minor style fixes

* ggml : hide op locals in source file

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
  • Loading branch information
goerch and ggerganov committed Jul 2, 2023
1 parent dfef9c6 commit 66ea403
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 904 deletions.
26 changes: 26 additions & 0 deletions include/ggml/ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@
#define GGML_MAX_NAME 48
#define GGML_DEFAULT_N_THREADS 4

#define GGML_UNUSED(x) (void)(x)

#define GGML_ASSERT(x) \
do { \
if (!(x)) { \
Expand All @@ -209,6 +211,30 @@
} \
} while (0)

// used to copy the number of elements and stride in bytes of tensors into local variables.
// main purpose is to reduce code duplication and improve readability.
//
// example:
//
// GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne);
// GGML_TENSOR_LOCALS(size_t, nb1, src1, nb);
//
#define GGML_TENSOR_LOCALS_1(type, prefix, pointer, array) \
const type prefix##0 = (pointer)->array[0]; \
GGML_UNUSED(prefix##0);
#define GGML_TENSOR_LOCALS_2(type, prefix, pointer, array) \
GGML_TENSOR_LOCALS_1 (type, prefix, pointer, array) \
const type prefix##1 = (pointer)->array[1]; \
GGML_UNUSED(prefix##1);
#define GGML_TENSOR_LOCALS_3(type, prefix, pointer, array) \
GGML_TENSOR_LOCALS_2 (type, prefix, pointer, array) \
const type prefix##2 = (pointer)->array[2]; \
GGML_UNUSED(prefix##2);
#define GGML_TENSOR_LOCALS(type, prefix, pointer, array) \
GGML_TENSOR_LOCALS_3 (type, prefix, pointer, array) \
const type prefix##3 = (pointer)->array[3]; \
GGML_UNUSED(prefix##3);

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
Loading

0 comments on commit 66ea403

Please sign in to comment.