1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
--- a/runtime/hsa-ext-finalize/CMakeLists.txt
+++ b/runtime/hsa-ext-finalize/CMakeLists.txt
@@ -101,6 +101,18 @@ if( NOT DEFINED OPEN_SOURCE_DIR )
set ( OPEN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." )
endif()
+## Check for _GNU_SOURCE pthread extensions
+set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
+CHECK_SYMBOL_EXISTS ( "pthread_attr_setaffinity_np" "pthread.h" HAVE_PTHREAD_ATTR_SETAFFINITY_NP )
+CHECK_SYMBOL_EXISTS ( "pthread_rwlockattr_setkind_np" "pthread.h" HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP )
+unset(CMAKE_REQUIRED_DEFINITIONS)
+if ( HAVE_PTHREAD_ATTR_SETAFFINITY_NP )
+ target_compile_definitions(${CORE_RUNTIME_TARGET} PRIVATE HAVE_PTHREAD_ATTR_SETAFFINITY_NP )
+endif()
+if ( HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP )
+ target_compile_definitions(${CORE_RUNTIME_TARGET} PRIVATE HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP )
+endif()
+
## ------------------------- Linux Compiler and Linker options -------------------------
set ( CMAKE_CXX_FLAGS "-std=c++11 " )
--- a/runtime/hsa-runtime/CMakeLists.txt
+++ b/runtime/hsa-runtime/CMakeLists.txt
@@ -47,7 +47,7 @@ cmake_minimum_required ( VERSION 3.7 )
## Need an update to CMake 3.12 to remove this hack. See CMake policy change CMP0073.
unset ( hsa-runtime64_LIB_DEPENDS CACHE )
-set(CMAKE_VERBOSE_MAKEFILE ON)
+#_cmake_modify_IGNORE set(CMAKE_VERBOSE_MAKEFILE ON)
## Set core runtime module name and project name.
set ( CORE_RUNTIME_NAME "hsa-runtime64" )
@@ -109,6 +109,18 @@ if ( HAVE_MEMFD_CREATE )
target_compile_definitions(${CORE_RUNTIME_TARGET} PRIVATE HAVE_MEMFD_CREATE )
endif()
+## Check for _GNU_SOURCE pthread extensions
+set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
+CHECK_SYMBOL_EXISTS ( "pthread_attr_setaffinity_np" "pthread.h" HAVE_PTHREAD_ATTR_SETAFFINITY_NP )
+CHECK_SYMBOL_EXISTS ( "pthread_rwlockattr_setkind_np" "pthread.h" HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP )
+unset(CMAKE_REQUIRED_DEFINITIONS)
+if ( HAVE_PTHREAD_ATTR_SETAFFINITY_NP )
+ target_compile_definitions(${CORE_RUNTIME_TARGET} PRIVATE HAVE_PTHREAD_ATTR_SETAFFINITY_NP )
+endif()
+if ( HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP )
+ target_compile_definitions(${CORE_RUNTIME_TARGET} PRIVATE HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP )
+endif()
+
## Set include directories for ROCr runtime
target_include_directories( ${CORE_RUNTIME_TARGET}
PUBLIC
--- a/runtime/hsa-runtime/core/util/lnx/os_linux.cpp
+++ b/runtime/hsa-runtime/core/util/lnx/os_linux.cpp
@@ -137,12 +137,14 @@ class os_thread {
for (int i = 0; i < cores; i++) {
CPU_SET_S(i, CPU_ALLOC_SIZE(cores), cpuset);
}
+#ifdef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
err = pthread_attr_setaffinity_np(&attrib, CPU_ALLOC_SIZE(cores), cpuset);
CPU_FREE(cpuset);
if (err != 0) {
fprintf(stderr, "pthread_setaffinity_np failed: %s\n", strerror(err));
return;
}
+#endif
}
do {
@@ -165,6 +167,18 @@ class os_thread {
}
} while (stackSize < 20 * 1024 * 1024);
+#ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
+ if (cores && cpuset) {
+ err = pthread_setaffinity_np(thread, CPU_ALLOC_SIZE(cores), cpuset);
+ CPU_FREE(cpuset);
+ if (err != 0) {
+ fprintf(stderr, "pthread_setaffinity_np failed: %s\n", strerror(err));
+ thread = 0;
+ return;
+ }
+ }
+#endif
+
args.release();
}
@@ -655,18 +669,12 @@ SharedMutex CreateSharedMutex() {
return nullptr;
}
-#ifdef __GLIBC__
+#ifdef HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP
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;
|