add memalign 0 byte check

This commit is contained in:
Kunshang Ji 2023-09-04 00:43:23 +00:00
parent eeb20c083d
commit 7ba244b3e8

6
ggml.c
View file

@ -195,12 +195,12 @@ typedef void * thread_ret_t;
#define GGML_ALIGNED_FREE(ptr) _aligned_free(ptr) #define GGML_ALIGNED_FREE(ptr) _aligned_free(ptr)
#else #else
inline static void * ggml_aligned_malloc(size_t size) { inline static void * ggml_aligned_malloc(size_t size) {
void * aligned_memory = NULL;
#ifdef GGML_USE_CPU_HBM
if (size == 0) { if (size == 0) {
GGML_PRINT("WARNING: Behavior may be unexpected when allocate 0 byte for hbw_posix_memalign!"); GGML_PRINT("WARNING: Behavior may be unexpected when allocate 0 byte for ggml_aligned_malloc!");
return NULL; return NULL;
} }
void * aligned_memory = NULL;
#ifdef GGML_USE_CPU_HBM
int result = hbw_posix_memalign(&aligned_memory, 16, size); int result = hbw_posix_memalign(&aligned_memory, 16, size);
#elif GGML_USE_METAL #elif GGML_USE_METAL
int result = posix_memalign(&aligned_memory, sysconf(_SC_PAGESIZE), size); int result = posix_memalign(&aligned_memory, sysconf(_SC_PAGESIZE), size);