Skip to content

Commit aa485ce

Browse files
committed
ggml : use posix_memalign on non-Windows env
1 parent c12b14b commit aa485ce

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

ggml.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,16 @@ typedef void* thread_ret_t;
118118
#define GGML_ALIGNED_MALLOC(size) _aligned_malloc(size, GGML_MEM_ALIGN)
119119
#define GGML_ALIGNED_FREE(ptr) _aligned_free(ptr)
120120
#else
121-
#define GGML_ALIGNED_MALLOC(size) aligned_alloc(GGML_MEM_ALIGN, size)
121+
inline static void* ggml_aligned_malloc(size_t size) {
122+
void* aligned_memory = NULL;
123+
int result = posix_memalign(&aligned_memory, GGML_MEM_ALIGN, size);
124+
if (result != 0) {
125+
// Handle allocation failure
126+
return NULL;
127+
}
128+
return aligned_memory;
129+
}
130+
#define GGML_ALIGNED_MALLOC(size) ggml_aligned_malloc(size)
122131
#define GGML_ALIGNED_FREE(ptr) free(ptr)
123132
#endif
124133

@@ -531,31 +540,31 @@ inline static float vaddvq_f32(float32x4_t v) {
531540
return vgetq_lane_f32(v, 0) + vgetq_lane_f32(v, 1) + vgetq_lane_f32(v, 2) + vgetq_lane_f32(v, 3);
532541
}
533542

534-
inline float vminvq_f32(float32x4_t v) {
543+
float vminvq_f32(float32x4_t v) {
535544
return
536545
MIN(MIN(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)),
537546
MIN(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3)));
538547
}
539548

540-
inline float vmaxvq_f32(float32x4_t v) {
549+
float vmaxvq_f32(float32x4_t v) {
541550
return
542551
MAX(MAX(vgetq_lane_f32(v, 0), vgetq_lane_f32(v, 1)),
543552
MAX(vgetq_lane_f32(v, 2), vgetq_lane_f32(v, 3)));
544553
}
545554

546-
inline int8x8_t vzip1_s8(int8x8_t a, int8x8_t b) {
555+
int8x8_t vzip1_s8(int8x8_t a, int8x8_t b) {
547556
return vget_low_s8(vcombine_s8(a, b));
548557
}
549558

550-
inline int8x8_t vzip2_s8(int8x8_t a, int8x8_t b) {
559+
int8x8_t vzip2_s8(int8x8_t a, int8x8_t b) {
551560
return vget_high_s8(vcombine_s8(a, b));
552561
}
553562

554-
inline uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b) {
563+
uint8x8_t vzip1_u8(uint8x8_t a, uint8x8_t b) {
555564
return vget_low_u8(vcombine_u8(a, b));
556565
}
557566

558-
inline uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b) {
567+
uint8x8_t vzip2_u8(uint8x8_t a, uint8x8_t b) {
559568
return vget_high_u8(vcombine_u8(a, b));
560569
}
561570

0 commit comments

Comments
 (0)