-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Allow overriding USE_COMPILER_TLS (formerly HAS_COMPILER_TLS). #1726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -471,26 +471,27 @@ struct alloc_t { | |
for an auxiliary tracking structure. */ | ||
static const int allocation_block_size = BUFFER_SIZE + sizeof(struct alloc_t); | ||
|
||
#if !defined(USE_COMPILER_TLS) | ||
/* Clang supports TLS from version 2.8 */ | ||
#if defined(__clang__) && __clang_major__ > 2 || \ | ||
(__clang_minor__ == 2 || __clang_minor__ == 8) | ||
#define HAS_COMPILER_TLS | ||
#define USE_COMPILER_TLS 1 | ||
#endif | ||
|
||
/* GCC supports TLS from version 4.1 */ | ||
#if !defined(__clang__) && defined(__GNUC__) && \ | ||
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) | ||
#define HAS_COMPILER_TLS | ||
#define USE_COMPILER_TLS 1 | ||
#endif | ||
|
||
/* MSVC supports TLS from version 2005 */ | ||
#if defined(_MSC_VER) && _MSC_VER >= 1400 | ||
#define HAS_COMPILER_TLS | ||
#define USE_COMPILER_TLS 1 | ||
#endif | ||
|
||
/* Versions of XCode before 8 did not properly support TLS */ | ||
#if defined(__apple_build_version__) && __apple_build_version__ < 8000042 | ||
#undef HAS_COMPILER_TLS | ||
#define USE_COMPILER_TLS 0 | ||
#endif | ||
|
||
/* Android NDK's before version 12b did not support TLS */ | ||
|
@@ -501,17 +502,18 @@ static const int allocation_block_size = BUFFER_SIZE + sizeof(struct alloc_t); | |
#if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \ | ||
defined(__NDK_MINOR__) && \ | ||
((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1))) | ||
#undef HAS_COMPILER_TLS | ||
#define USE_COMPILER_TLS 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: possible redefinition of |
||
#endif | ||
#endif | ||
#endif /* !USE_COMPILER_TLS */ | ||
|
||
/* Holds pointers to allocated memory */ | ||
#if defined(SMP) && !defined(USE_OPENMP_UNUSED) | ||
/* This is the number of threads than can be spawned by the server, which is the | ||
server plus the number of threads in the thread pool */ | ||
# define MAX_ALLOCATING_THREADS MAX_CPU_NUMBER * 2 * MAX_PARALLEL_NUMBER * 2 | ||
static int next_memory_table_pos = 0; | ||
# if defined(HAS_COMPILER_TLS) | ||
# if USE_COMPILER_TLS | ||
/* Use compiler generated thread-local-storage */ | ||
static int THREAD_LOCAL local_memory_table_pos = 0; | ||
# else | ||
|
@@ -521,7 +523,7 @@ static DWORD local_storage_key; | |
# else | ||
static pthread_key_t local_storage_key; | ||
# endif /* defined(OS_WINDOWS) */ | ||
# endif /* defined(HAS_COMPILER_TLS) */ | ||
# endif /* USE_COMPILER_TLS */ | ||
#else | ||
/* There is only one allocating thread when in single-threaded mode and when using OpenMP */ | ||
# define MAX_ALLOCATING_THREADS 1 | ||
|
@@ -545,26 +547,26 @@ static BLASULONG alloc_lock = 0UL; | |
/* Returns a pointer to the start of the per-thread memory allocation data */ | ||
static __inline struct alloc_t ** get_memory_table() { | ||
#if defined(SMP) && !defined(USE_OPENMP_UNUSED) | ||
# if !defined(HAS_COMPILER_TLS) | ||
# if !USE_COMPILER_TLS | ||
# if defined(OS_WINDOWS) | ||
int local_memory_table_pos = (int)::TlsGetValue(local_storage_key); | ||
# else | ||
int local_memory_table_pos = (int)pthread_getspecific(local_storage_key); | ||
# endif /* defined(OS_WINDOWS) */ | ||
# endif /* !defined(HAS_COMPILER_TLS) */ | ||
# endif /* !USE_COMPILER_TLS */ | ||
if (!local_memory_table_pos) { | ||
LOCK_COMMAND(&alloc_lock); | ||
local_memory_table_pos = next_memory_table_pos++; | ||
if (next_memory_table_pos > MAX_ALLOCATING_THREADS) | ||
printf("OpenBLAS : Program will terminate because you tried to start too many threads.\n"); | ||
UNLOCK_COMMAND(&alloc_lock); | ||
# if !defined(HAS_COMPILER_TLS) | ||
# if !USE_COMPILER_TLS | ||
# if defined(OS_WINDOWS) | ||
::TlsSetValue(local_storage_key, (void*)local_memory_table_pos); | ||
# else | ||
pthread_setspecific(local_storage_key, (void*)local_memory_table_pos); | ||
# endif /* defined(OS_WINDOWS) */ | ||
# endif /* !defined(HAS_COMPILER_TLS) */ | ||
# endif /* !USE_COMPILER_TLS */ | ||
} | ||
return local_memory_table[local_memory_table_pos]; | ||
#else | ||
|
@@ -1072,13 +1074,13 @@ static volatile int memory_initialized = 0; | |
static void blas_memory_init(){ | ||
#if defined(SMP) && !defined(USE_OPENMP_UNUSED) | ||
next_memory_table_pos = 0; | ||
# if !defined(HAS_COMPILER_TLS) | ||
# if !USE_COMPILER_TLS | ||
# if defined(OS_WINDOWS) | ||
local_storage_key = ::TlsAlloc(); | ||
# else | ||
pthread_key_create(&local_storage_key, NULL); | ||
# endif /* defined(OS_WINDOWS) */ | ||
# endif /* defined(HAS_COMPILER_TLS) */ | ||
# endif /* USE_COMPILER_TLS */ | ||
#endif /* defined(SMP) && !defined(USE_OPENMP) */ | ||
memset(local_memory_table, 0, sizeof(local_memory_table)); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to have this condition match while also have a previous one match ?
This would mean a previous line (like 478) does
#define USE_COMPILER_TLS 1
and then this one redefine it to 0 causing a compiler warning or error.Maybe just add a
#undef USE_COMPILER_TLS
before this line.