Skip to content

Commit 4f0c3cb

Browse files
committed
another try at a fix
1 parent afbff14 commit 4f0c3cb

File tree

1 file changed

+19
-35
lines changed

1 file changed

+19
-35
lines changed

ggml/include/ggml.h

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,13 @@ extern "C" {
664664
)
665665
#else
666666
// C++ implementation using function overloading
667+
static inline void * tensor_data(struct ggml_tensor * tensor);
668+
static inline void * tensor_data(const struct ggml_tensor * tensor);
669+
static inline void * tensor_data(struct ggml_tensor & tensor);
670+
static inline void * tensor_data(const struct ggml_tensor & tensor);
671+
static inline void tensor_set_data(struct ggml_tensor * tensor, void * value);
672+
static inline void tensor_set_data(struct ggml_tensor & tensor, void * value);
673+
667674
static inline void * tensor_data(struct ggml_tensor * tensor) {
668675
#ifdef GGML_NUMA_MIRROR
669676
int n = ggml_current_numa_node == -1 ? 0 : ggml_current_numa_node;
@@ -681,20 +688,10 @@ static inline void * tensor_data(const struct ggml_tensor * tensor) {
681688
#endif
682689
}
683690
static inline void * tensor_data(struct ggml_tensor & tensor) {
684-
#ifdef GGML_NUMA_MIRROR
685-
int n = ggml_current_numa_node == -1 ? 0 : ggml_current_numa_node;
686-
return tensor.__data[n];
687-
#else
688-
return tensor.data;
689-
#endif
691+
return tensor_data(&tensor);
690692
}
691693
static inline void * tensor_data(const struct ggml_tensor & tensor) {
692-
#ifdef GGML_NUMA_MIRROR
693-
int n = ggml_current_numa_node == -1 ? 0 : ggml_current_numa_node;
694-
return tensor.__data[n];
695-
#else
696-
return tensor.data;
697-
#endif
694+
return tensor_data(&tensor);
698695
}
699696

700697
static inline void tensor_set_data(struct ggml_tensor * tensor, void * value) {
@@ -714,46 +711,33 @@ static inline void tensor_set_data(struct ggml_tensor * tensor, void * value) {
714711
#endif
715712
}
716713
static inline void tensor_set_data(struct ggml_tensor & tensor, void * value) {
717-
#ifdef GGML_NUMA_MIRROR
718-
void* data_ = value;
719-
if ((uint64_t)data_ >= GGML_MMAP_VIRTUAL_MEMORY_BASE_OFFSET + GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT && (uint64_t)data_ < GGML_MMAP_VIRTUAL_MEMORY_BASE_OFFSET + 2 * GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT) {
720-
data_ = (void*)((uint64_t)data_ - GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT);
721-
}
722-
tensor.__data[0] = data_;
723-
if ((uint64_t)data_ >= GGML_MMAP_VIRTUAL_MEMORY_BASE_OFFSET && (uint64_t)data_ < GGML_MMAP_VIRTUAL_MEMORY_BASE_OFFSET + GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT) {
724-
tensor.__data[1] = (void*)((uint64_t)data_ + GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT);
725-
} else {
726-
tensor.__data[1] = data_;
727-
}
728-
#else
729-
tensor.data = value;
730-
#endif
714+
tensor_set_data(&tensor, value);
731715
}
732716
#endif
733717

734718
#if !defined(__cplusplus)
735719
#ifdef GGML_NUMA_MIRROR
736-
#define _tensor_data_ptr(tensor) \
737-
(ggml_current_numa_node == -1 ? (tensor)->__data[0] : (tensor)->__data[ggml_current_numa_node])
720+
#define _tensor_data_ptr(p) \
721+
(ggml_current_numa_node == -1 ? (p)->__data[0] : (p)->__data[ggml_current_numa_node])
738722

739-
#define _tensor_set_data_ptr(tensor, data_ptr) \
723+
#define _tensor_set_data_ptr(p, d) \
740724
do { \
741-
void* data_ = (data_ptr); \
725+
void* data_ = (d); \
742726
if ((uint64_t)data_ >= GGML_MMAP_VIRTUAL_MEMORY_BASE_OFFSET + GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT && \
743727
(uint64_t)data_ < GGML_MMAP_VIRTUAL_MEMORY_BASE_OFFSET + 2 * GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT) { \
744728
data_ = (void*)((uint64_t)data_ - GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT); \
745729
} \
746-
(tensor)->__data[0] = data_; \
730+
(p)->__data[0] = data_; \
747731
if ((uint64_t)data_ >= GGML_MMAP_VIRTUAL_MEMORY_BASE_OFFSET && \
748732
(uint64_t)data_ < GGML_MMAP_VIRTUAL_MEMORY_BASE_OFFSET + GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT) { \
749-
(tensor)->__data[1] = (void*)((uint64_t)data_ + GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT); \
733+
(p)->__data[1] = (void*)((uint64_t)data_ + GGML_MMAP_VIRTUAL_MEMORY_NUMA_INCREMENT); \
750734
} else { \
751-
(tensor)->__data[1] = data_; \
735+
(p)->__data[1] = data_; \
752736
} \
753737
} while (0)
754738
#else
755-
#define _tensor_data_ptr(tensor) ((tensor)->data)
756-
#define _tensor_set_data_ptr(tensor, value) ((tensor)->data = (value))
739+
#define _tensor_data_ptr(p) ((p)->data)
740+
#define _tensor_set_data_ptr(p, d) ((p)->data = (d))
757741
#endif
758742
#endif
759743

0 commit comments

Comments
 (0)