Refs #478, #482. Fix segfault bug for gemv_t with MAX_ALLOC_STACK flag.

For gemv_t, directly use malloc to create the buffer.
This commit is contained in:
Zhang Xianyi 2015-04-13 19:45:27 -05:00
parent 62231ab337
commit 9798481979
3 changed files with 32 additions and 8 deletions

View File

@ -499,6 +499,8 @@ void blas_set_parameter(void);
int blas_get_cpu_number(void); int blas_get_cpu_number(void);
void *blas_memory_alloc (int); void *blas_memory_alloc (int);
void blas_memory_free (void *); void blas_memory_free (void *);
void *blas_memory_alloc_nolock (int); //use malloc without blas_lock
void blas_memory_free_nolock (void *);
int get_num_procs (void); int get_num_procs (void);

View File

@ -1161,6 +1161,16 @@ void blas_memory_free(void *free_area){
return; return;
} }
void *blas_memory_alloc_nolock(int unused) {
void *map_address;
map_address = (void *)malloc(BUFFER_SIZE + FIXED_PAGESIZE);
return map_address;
}
void blas_memory_free_nolock(void * map_address) {
free(map_address);
}
void blas_shutdown(void){ void blas_shutdown(void){
int pos; int pos;

View File

@ -211,15 +211,24 @@ void CNAME(enum CBLAS_ORDER order,
#ifdef MAX_STACK_ALLOC #ifdef MAX_STACK_ALLOC
// make it volatile because some gemv implementation (ex: dgemv_n.S) // make it volatile because some gemv implementation (ex: dgemv_n.S)
// do not restore all register // do not restore all register
volatile int stack_alloc_size = m + n; volatile int stack_alloc_size = 0;
if(stack_alloc_size < 128) if (trans == 0) {
stack_alloc_size = m + n;
if(stack_alloc_size < 128)
//dgemv_n.S require a 128 bytes buffer //dgemv_n.S require a 128 bytes buffer
stack_alloc_size = 128; stack_alloc_size = 128;
if(stack_alloc_size > MAX_STACK_ALLOC / sizeof(FLOAT))
if(stack_alloc_size > MAX_STACK_ALLOC / sizeof(FLOAT))
stack_alloc_size = 0; stack_alloc_size = 0;
FLOAT stack_buffer[stack_alloc_size]; FLOAT stack_buffer[stack_alloc_size];
buffer = stack_alloc_size ? stack_buffer : (FLOAT *)blas_memory_alloc(1); buffer = stack_alloc_size ? stack_buffer : (FLOAT *)blas_memory_alloc_nolock(1);
}else{
//for gemv_t, only malloc
buffer = (FLOAT *)blas_memory_alloc_nolock(1);
}
#else #else
//Original OpenBLAS/GotoBLAS codes.
buffer = (FLOAT *)blas_memory_alloc(1); buffer = (FLOAT *)blas_memory_alloc(1);
#endif #endif
@ -251,9 +260,12 @@ void CNAME(enum CBLAS_ORDER order,
#endif #endif
#ifdef MAX_STACK_ALLOC #ifdef MAX_STACK_ALLOC
if(!stack_alloc_size) if(!stack_alloc_size){
#endif blas_memory_free_nolock(buffer);
}
#else
blas_memory_free(buffer); blas_memory_free(buffer);
#endif
FUNCTION_PROFILE_END(1, m * n + m + n, 2 * m * n); FUNCTION_PROFILE_END(1, m * n + m + n, 2 * m * n);