@@ -114,6 +114,14 @@ typedef void* thread_ret_t;
114
114
#define GGML_MEM_ALIGN 16
115
115
#endif
116
116
117
+ #if defined(_MSC_VER ) || defined(__MINGW32__ )
118
+ #define GGML_ALIGNED_MALLOC (size ) _aligned_malloc(size, GGML_MEM_ALIGN)
119
+ #define GGML_ALIGNED_FREE (ptr ) _aligned_free(ptr)
120
+ #else
121
+ #define GGML_ALIGNED_MALLOC (size ) aligned_alloc(GGML_MEM_ALIGN, size)
122
+ #define GGML_ALIGNED_FREE (ptr ) free(ptr)
123
+ #endif
124
+
117
125
#define UNUSED (x ) (void)(x)
118
126
#define SWAP (x , y , T ) do { T SWAP = x; x = y; y = SWAP; } while (0)
119
127
@@ -2966,7 +2974,7 @@ struct ggml_context * ggml_init(struct ggml_init_params params) {
2966
2974
2967
2975
* ctx = (struct ggml_context ) {
2968
2976
/*.mem_size =*/ params .mem_size ,
2969
- /*.mem_buffer =*/ params .mem_buffer ? params .mem_buffer : malloc (params .mem_size ),
2977
+ /*.mem_buffer =*/ params .mem_buffer ? params .mem_buffer : GGML_ALIGNED_MALLOC (params .mem_size ),
2970
2978
/*.mem_buffer_owned =*/ params .mem_buffer ? false : true,
2971
2979
/*.no_alloc =*/ params .no_alloc ,
2972
2980
/*.n_objects =*/ 0 ,
@@ -3001,7 +3009,7 @@ void ggml_free(struct ggml_context * ctx) {
3001
3009
__func__ , i , ctx -> n_objects , ctx -> objects_end -> offs + ctx -> objects_end -> size );
3002
3010
3003
3011
if (ctx -> mem_buffer_owned ) {
3004
- free (ctx -> mem_buffer );
3012
+ GGML_ALIGNED_FREE (ctx -> mem_buffer );
3005
3013
}
3006
3014
3007
3015
found = true;
1 commit comments
nnnn20430 commentedon Apr 15, 2023
This seems to have broken build in termux, because termux min sdk is 24 and bionic doesn't support aligned_alloc in that version