From e43de7314996d8d7c5e4ea5c7939c2fd94787dcc Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 16 Sep 2015 12:32:46 -0400
Subject: [PATCH] P4 to Git Change 1191297 by jsjodin@alit_worker_lnx11_stg_ws
on 2015/09/16 12:24:49
EPR #425397 - Fix SIGFPE filtering to be set up in the CPU device.
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpudevice.cpp#275 edit
... //depot/stg/opencl/drivers/opencl/runtime/os/os.hpp#29 edit
... //depot/stg/opencl/drivers/opencl/runtime/os/os_posix.cpp#41 edit
... //depot/stg/opencl/drivers/opencl/runtime/os/os_win32.cpp#46 edit
[ROCm/clr commit: 972644abff09858a4ce30d66c431425882b92322]
---
.../rocclr/runtime/device/cpu/cpudevice.cpp | 6 +++-
projects/clr/rocclr/runtime/os/os.hpp | 6 ++++
projects/clr/rocclr/runtime/os/os_posix.cpp | 28 +++++++++++--------
projects/clr/rocclr/runtime/os/os_win32.cpp | 27 ++++++++++--------
4 files changed, 44 insertions(+), 23 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/cpu/cpudevice.cpp b/projects/clr/rocclr/runtime/device/cpu/cpudevice.cpp
index 2e4a575c13..3e5493b06e 100644
--- a/projects/clr/rocclr/runtime/device/cpu/cpudevice.cpp
+++ b/projects/clr/rocclr/runtime/device/cpu/cpudevice.cpp
@@ -51,7 +51,8 @@ Device::~Device()
void
Device::tearDown()
{
- aclCompilerFini(compiler_);
+ amd::Os::uninstallSigfpeHandler();
+ aclCompilerFini(compiler_);
}
bool
Device::init()
@@ -60,6 +61,9 @@ Device::init()
if (CPU_MAX_COMPUTE_UNITS == 0)
return false;
+ if(!amd::Os::installSigfpeHandler())
+ return false;
+
const char *library = getenv("COMPILER_LIBRARY");
aclCompilerOptions opts = {
sizeof(aclCompilerOptions_0_8),
diff --git a/projects/clr/rocclr/runtime/os/os.hpp b/projects/clr/rocclr/runtime/os/os.hpp
index e361a96f4f..5299162e18 100644
--- a/projects/clr/rocclr/runtime/os/os.hpp
+++ b/projects/clr/rocclr/runtime/os/os.hpp
@@ -259,6 +259,12 @@ public:
//! get Application file name
static std::string getAppFileName();
+
+ //! Install SIGFPE handler for CPU device
+ static bool installSigfpeHandler();
+
+ //! Uninstall SIGFPE handler for CPU device
+ static void uninstallSigfpeHandler();
};
/*@}*/
diff --git a/projects/clr/rocclr/runtime/os/os_posix.cpp b/projects/clr/rocclr/runtime/os/os_posix.cpp
index e7b6a9905f..26cde31c9c 100644
--- a/projects/clr/rocclr/runtime/os/os_posix.cpp
+++ b/projects/clr/rocclr/runtime/os/os_posix.cpp
@@ -124,6 +124,23 @@ static pthread_setaffinity_fn pthread_setaffinity_fptr;
static void init() __attribute__((constructor(101)));
static void init() { Os::init(); }
+bool Os::installSigfpeHandler() {
+ // Install a SIGFPE signal handler @todo: Chain the handlers
+ struct sigaction sa;
+ sigfillset(&sa.sa_mask);
+ sa.sa_handler = SIG_DFL;
+ sa.sa_sigaction = divisionErrorHandler;
+ sa.sa_flags = SA_SIGINFO | SA_RESTART;
+
+ if (sigaction(SIGFPE, &sa, &oldSigAction) != 0) {
+ return false;
+ }
+ return true;
+}
+
+void Os::uninstallSigfpeHandler() {
+}
+
bool
Os::init()
{
@@ -138,17 +155,6 @@ Os::init()
pageSize_ = (size_t) ::sysconf(_SC_PAGESIZE);
processorCount_ = ::sysconf(_SC_NPROCESSORS_CONF);
- // Install a SIGFPE signal handler @todo: Chain the handlers
- struct sigaction sa;
- sigfillset(&sa.sa_mask);
- sa.sa_handler = SIG_DFL;
- sa.sa_sigaction = divisionErrorHandler;
- sa.sa_flags = SA_SIGINFO | SA_RESTART;
-
- if (sigaction(SIGFPE, &sa, &oldSigAction) != 0) {
- return false;
- }
-
pthread_setaffinity_fptr = (pthread_setaffinity_fn)
dlsym(RTLD_NEXT, "pthread_setaffinity_np");
diff --git a/projects/clr/rocclr/runtime/os/os_win32.cpp b/projects/clr/rocclr/runtime/os/os_win32.cpp
index bea0efac62..0d66e09374 100644
--- a/projects/clr/rocclr/runtime/os/os_win32.cpp
+++ b/projects/clr/rocclr/runtime/os/os_win32.cpp
@@ -66,10 +66,6 @@ Os::init()
QueryPerformanceFrequency(&frequency);
PerformanceFrequency = (double) frequency.QuadPart;
-#ifdef _WIN64
- divExceptionHandler = AddVectoredExceptionHandler(1, divExceptionFilter);
-#endif // _WIN64
-
HMODULE handle = ::LoadLibrary("kernel32.dll");
if (handle != NULL) {
pfnSetThreadGroupAffinity = (SetThreadGroupAffinity_fn)
@@ -87,13 +83,6 @@ __declspec(allocate(".CRT$XTU")) void (*__exit)(void) = Os::tearDown;
void
Os::tearDown()
{
-#ifdef _WIN64
- if (divExceptionHandler != NULL) {
- RemoveVectoredExceptionHandler(divExceptionHandler);
- divExceptionHandler = NULL;
- }
-#endif // _WIN64
-
Thread::tearDown();
}
@@ -464,6 +453,22 @@ divExceptionFilter(struct _EXCEPTION_POINTERS* ep)
return EXCEPTION_CONTINUE_SEARCH;
}
+bool Os::installSigfpeHandler() {
+#ifdef _WIN64
+ divExceptionHandler = AddVectoredExceptionHandler(1, divExceptionFilter);
+#endif // _WIN64
+ return true;
+}
+
+void Os::uninstallSigfpeHandler() {
+#ifdef _WIN64
+ if (divExceptionHandler != NULL) {
+ RemoveVectoredExceptionHandler(divExceptionHandler);
+ divExceptionHandler = NULL;
+ }
+#endif // _WIN64
+}
+
void*
Thread::entry(Thread* thread)
{