Skip to content

Commit

Permalink
Fix CI hangs on win32
Browse files Browse the repository at this point in the history
After much debugging, it turns out that OpenBlas is sometimes hanging
on exit due to bad assumptions in its thread management. The upstream
discussion is at OpenMathLib/OpenBLAS#2350, but this
should fix our frequent win32 CI failures in the meantime.
  • Loading branch information
Keno committed Dec 31, 2019
1 parent 4c58369 commit 79d55f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion deps/blas.mk
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-skylakexdgemm.patch-applied: $(BUILDDIR
patch -p1 -f < $(SRCDIR)/patches/openblas-skylakexdgemm.patch
echo 1 > $@

$(BUILDDIR)/$(OPENBLAS_SRC_DIR)/build-configured: $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-skylakexdgemm.patch-applied
$(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-winexit.patch-applied: $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/source-extracted
cd $(BUILDDIR)/$(OPENBLAS_SRC_DIR) && \
patch -p1 -f < $(SRCDIR)/patches/openblas-winexit.patch
echo 1 > $@

$(BUILDDIR)/$(OPENBLAS_SRC_DIR)/build-configured: $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-skylakexdgemm.patch-applied $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/openblas-winexit.patch-applied
echo 1 > $@

$(BUILDDIR)/$(OPENBLAS_SRC_DIR)/build-compiled: $(BUILDDIR)/$(OPENBLAS_SRC_DIR)/build-configured
Expand Down
34 changes: 34 additions & 0 deletions deps/patches/openblas-winexit.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
commit 67bdd1b07c8fe880b2813c96849444b3dea67860
Author: Keno Fischer <[email protected]>
Date: Sun Dec 29 15:08:13 2019 -0500

win32: Don't run cleanup if we're about to exit anyway

If the process is about to exit, there's no point trying to do
a bunch of work to clean up resources. The kernel will release
them much more efficiently when the process exits at the end
of this function.

diff --git a/exports/dllinit.c b/exports/dllinit.c
index 02ff092e..b65fe0c6 100644
--- a/exports/dllinit.c
+++ b/exports/dllinit.c
@@ -42,13 +42,17 @@ void gotoblas_init(void);
void gotoblas_quit(void);

BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) {
+<<<<<<< HEAD

if (reason == DLL_PROCESS_ATTACH) {
gotoblas_init();
}

if (reason == DLL_PROCESS_DETACH) {
- gotoblas_quit();
+ // If the process is about to exit, don't bother releasing any resources
+ // The kernel is much better at bulk releasing then.
+ if (!reserved)
+ gotoblas_quit();
}

return TRUE;

0 comments on commit 79d55f4

Please sign in to comment.