Skip to content

Commit

Permalink
Refs #478, #482. Fix segfault bug for gemv_t with MAX_ALLOC_STACK flag.
Browse files Browse the repository at this point in the history
For gemv_t, directly use malloc to create the buffer.
  • Loading branch information
xianyi committed Apr 14, 2015
1 parent 62231ab commit 9798481
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
2 changes: 2 additions & 0 deletions common.h
Expand Up @@ -499,6 +499,8 @@ void blas_set_parameter(void);
int blas_get_cpu_number(void);
void *blas_memory_alloc (int);
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);

Expand Down
10 changes: 10 additions & 0 deletions driver/others/memory.c
Expand Up @@ -1161,6 +1161,16 @@ void blas_memory_free(void *free_area){
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){

int pos;
Expand Down
28 changes: 20 additions & 8 deletions interface/gemv.c
Expand Up @@ -211,15 +211,24 @@ void CNAME(enum CBLAS_ORDER order,
#ifdef MAX_STACK_ALLOC
// make it volatile because some gemv implementation (ex: dgemv_n.S)
// do not restore all register
volatile int stack_alloc_size = m + n;
if(stack_alloc_size < 128)
volatile int stack_alloc_size = 0;
if (trans == 0) {
stack_alloc_size = m + n;
if(stack_alloc_size < 128)
//dgemv_n.S require a 128 bytes buffer
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;
FLOAT stack_buffer[stack_alloc_size];
buffer = stack_alloc_size ? stack_buffer : (FLOAT *)blas_memory_alloc(1);
FLOAT stack_buffer[stack_alloc_size];
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
//Original OpenBLAS/GotoBLAS codes.
buffer = (FLOAT *)blas_memory_alloc(1);
#endif

Expand Down Expand Up @@ -251,10 +260,13 @@ void CNAME(enum CBLAS_ORDER order,
#endif

#ifdef MAX_STACK_ALLOC
if(!stack_alloc_size)
#endif
if(!stack_alloc_size){
blas_memory_free_nolock(buffer);
}
#else
blas_memory_free(buffer);

#endif

FUNCTION_PROFILE_END(1, m * n + m + n, 2 * m * n);

IDEBUG_END;
Expand Down

0 comments on commit 9798481

Please sign in to comment.