@@ -73,6 +73,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73
73
74
74
#include "common.h"
75
75
76
+ #define NEW_BUFFERS 512
76
77
#ifndef likely
77
78
#ifdef __GNUC__
78
79
#define likely (x ) __builtin_expect(!!(x), 1)
@@ -2897,7 +2898,7 @@ void *blas_memory_alloc(int procpos){
2897
2898
#endif
2898
2899
position ++ ;
2899
2900
2900
- } while (position < 512 + NUM_BUFFERS );
2901
+ } while (position < NEW_BUFFERS + NUM_BUFFERS );
2901
2902
}
2902
2903
#if (defined(SMP ) || defined(USE_LOCKING )) && !defined(USE_OPENMP )
2903
2904
UNLOCK_COMMAND (& alloc_lock );
@@ -3014,9 +3015,10 @@ void *blas_memory_alloc(int procpos){
3014
3015
fprintf (stderr ,"To avoid this warning, please rebuild your copy of OpenBLAS with a larger NUM_THREADS setting\n" );
3015
3016
fprintf (stderr ,"or set the environment variable OPENBLAS_NUM_THREADS to %d or lower\n" , MAX_CPU_NUMBER );
3016
3017
memory_overflowed = 1 ;
3017
- new_release_info = (struct release_t * ) malloc (512 * sizeof (struct release_t ));
3018
- newmemory = (struct newmemstruct * ) malloc (512 * sizeof (struct newmemstruct ));
3019
- for (i = 0 ; i < 512 ; i ++ ) {
3018
+ MB ;
3019
+ new_release_info = (struct release_t * ) malloc (NEW_BUFFERS * sizeof (struct release_t ));
3020
+ newmemory = (struct newmemstruct * ) malloc (NEW_BUFFERS * sizeof (struct newmemstruct ));
3021
+ for (i = 0 ; i < NEW_BUFFERS ; i ++ ) {
3020
3022
newmemory [i ].addr = (void * )0 ;
3021
3023
#if defined(WHEREAMI ) && !defined(USE_OPENMP )
3022
3024
newmemory [i ].pos = -1 ;
@@ -3129,12 +3131,12 @@ void blas_memory_free(void *free_area){
3129
3131
printf (" Position : %d\n" , position );
3130
3132
#endif
3131
3133
if (unlikely (memory_overflowed && position >= NUM_BUFFERS )) {
3132
- while ((position < NUM_BUFFERS + 512 ) && (newmemory [position - NUM_BUFFERS ].addr != free_area ))
3134
+ while ((position < NUM_BUFFERS + NEW_BUFFERS ) && (newmemory [position - NUM_BUFFERS ].addr != free_area ))
3133
3135
position ++ ;
3134
3136
// arm: ensure all writes are finished before other thread takes this memory
3135
3137
WMB ;
3136
-
3137
- newmemory [position ].used = 0 ;
3138
+ if ( position - NUM_BUFFERS >= NEW_BUFFERS ) goto error ;
3139
+ newmemory [position - NUM_BUFFERS ].used = 0 ;
3138
3140
#if (defined(SMP ) || defined(USE_LOCKING )) && !defined(USE_OPENMP )
3139
3141
UNLOCK_COMMAND (& alloc_lock );
3140
3142
#endif
@@ -3213,7 +3215,7 @@ void blas_shutdown(void){
3213
3215
memory [pos ].lock = 0 ;
3214
3216
}
3215
3217
if (memory_overflowed )
3216
- for (pos = 0 ; pos < 512 ; pos ++ ){
3218
+ for (pos = 0 ; pos < NEW_BUFFERS ; pos ++ ){
3217
3219
newmemory [pos ].addr = (void * )0 ;
3218
3220
newmemory [pos ].used = 0 ;
3219
3221
#if defined(WHEREAMI ) && !defined(USE_OPENMP )
0 commit comments