diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/checked.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/checked.h index 93793bcc78..56497d120a 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/checked.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/checked.h @@ -58,7 +58,7 @@ template class Check final { Check(const Check&) { object_ = uintptr_t(this) ^ uintptr_t(code); } Check(Check&&) { object_ = uintptr_t(this) ^ uintptr_t(code); } - ~Check() { object_ = NULL; } + ~Check() { object_ = uintptr_t(NULL); } const Check& operator=(Check&& rhs) { return *this; } const Check& operator=(const Check& rhs) { return *this; } diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/default_signal.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/default_signal.cpp index 820fc75cab..b3e5a23f28 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/default_signal.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/default_signal.cpp @@ -57,7 +57,7 @@ int BusyWaitSignal::rtti_id_ = 0; BusyWaitSignal::BusyWaitSignal(SharedSignal* abi_block, bool enableIPC) : Signal(abi_block, enableIPC) { signal_.kind = AMD_SIGNAL_KIND_USER; - signal_.event_mailbox_ptr = NULL; + signal_.event_mailbox_ptr = uint64_t(NULL); } hsa_signal_value_t BusyWaitSignal::LoadRelaxed() { diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp index 7850490e22..fb70b81171 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp @@ -108,31 +108,44 @@ class os_thread { err = pthread_attr_setstacksize(&attrib, stackSize); if (err != 0) { fprintf(stderr, "pthread_attr_setstacksize failed: %s\n", strerror(err)); + err = pthread_attr_destroy(&attrib); + if (err != 0) { + fprintf(stderr, "pthread_attr_destroy failed: %s\n", strerror(err)); + } return; } } -\ - err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get()); + + int create_err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get()); // Probably a stack size error since system limits can be different from PTHREAD_STACK_MIN // Attempt to grow the stack within reason. - if ((err == EINVAL) && stackSize != 0) { + if ((create_err == EINVAL) && stackSize != 0) { while (stackSize < 20 * 1024 * 1024) { stackSize *= 2; err = pthread_attr_setstacksize(&attrib, stackSize); if (err != 0) { fprintf(stderr, "pthread_attr_setstacksize failed: %s\n", strerror(err)); + err = pthread_attr_destroy(&attrib); + if (err != 0) { + fprintf(stderr, "pthread_attr_destroy failed: %s\n", strerror(err)); + } + return; } - err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get()); - if (err != EINVAL) break; + + create_err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get()); + if (create_err != EINVAL) break; debug_print("pthread_create returned EINVAL, doubling stack size\n"); } } + int cores = 0; + cpu_set_t* cpuset = nullptr; + if (core::Runtime::runtime_singleton_->flag().override_cpu_affinity()) { - int cores = get_nprocs_conf(); - cpu_set_t* cpuset = CPU_ALLOC(cores); + cores = get_nprocs_conf(); + cpuset = CPU_ALLOC(cores); if (cpuset == nullptr) { fprintf(stderr, "CPU_ALLOC failed: %s\n", strerror(errno)); return; @@ -144,12 +157,11 @@ class os_thread { err = pthread_setaffinity_np(thread, CPU_ALLOC_SIZE(cores), cpuset); CPU_FREE(cpuset); if (err != 0) { - fprintf(stderr, "pthread_attr_setaffinity_np failed: %s\n", strerror(err)); + fprintf(stderr, "pthread_setaffinity_np failed: %s\n", strerror(err)); return; } } - - if (err == 0) + if (create_err == 0) args.release(); else thread = 0; @@ -642,11 +654,20 @@ SharedMutex CreateSharedMutex() { fprintf(stderr, "rw lock attribute init failed: %s\n", strerror(err)); return nullptr; } + +#ifdef __GLIBC__ err = pthread_rwlockattr_setkind_np(&attrib, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); if (err != 0) { fprintf(stderr, "Set rw lock attribute failure: %s\n", strerror(err)); return nullptr; } +#else + err = pthread_rwlockattr_setkind(&attrib, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); + if (err != 0) { + fprintf(stderr, "Set rw lock attribute failure: %s\n", strerror(err)); + return nullptr; + } +#endif pthread_rwlock_t* lock = new pthread_rwlock_t; err = pthread_rwlock_init(lock, &attrib); diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/util/utils.h b/projects/rocr-runtime/runtime/hsa-runtime/core/util/utils.h index ab536ba796..1a454d7bd4 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/util/utils.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/util/utils.h @@ -74,8 +74,7 @@ static __forceinline void* _aligned_malloc(size_t size, size_t alignment) { return aligned_alloc(alignment, size); #else void *mem = NULL; - if (NULL != posix_memalign(&mem, alignment, size)) - return NULL; + if (0 != posix_memalign(&mem, alignment, size)) return NULL; return mem; #endif } diff --git a/projects/rocr-runtime/runtime/hsa-runtime/image/util.h b/projects/rocr-runtime/runtime/hsa-runtime/image/util.h index 8482e41a4b..88cdf4ccc9 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/image/util.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/image/util.h @@ -99,7 +99,7 @@ static __forceinline void* _aligned_malloc(size_t size, size_t alignment) { return aligned_alloc(alignment, size); #else void* mem = NULL; - if (NULL != posix_memalign(&mem, alignment, size)) return NULL; + if (0 != posix_memalign(&mem, alignment, size)) return NULL; return mem; #endif }