[clblas] 66/67: Fix https://github.com/clMathLibraries/clBLAS/issues/159 , teardown/setup when using autogemm causes next call to gemm to fail (segfault)
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Oct 27 08:02:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository clblas.
commit c56c725a87d4f3d16a46aa5a78db341c34fad455
Author: Hugh Perkins <hughperkins at gmail.com>
Date: Sun Oct 25 22:46:56 2015 +0800
Fix https://github.com/clMathLibraries/clBLAS/issues/159 , teardown/setup when using autogemm causes next call to gemm to fail (segfault)
---
src/library/CMakeLists.txt | 19 ++++++++++--
src/library/blas/AutoGemm/Includes.py | 57 ++++++++++++++++++++++++++---------
src/library/blas/init.c | 7 +++++
3 files changed, 66 insertions(+), 17 deletions(-)
diff --git a/src/library/CMakeLists.txt b/src/library/CMakeLists.txt
index 377aa9d..f0ce742 100644
--- a/src/library/CMakeLists.txt
+++ b/src/library/CMakeLists.txt
@@ -839,8 +839,7 @@ else()
MESSAGE( STATUS "clBLAS will NOT depend on ${AUTOGEMM_PRECOMPILED_KERNELS}" )
endif()
-
-add_library(clBLAS
+set(CLBLAS_ALL_SOURCES
${CLBLAS_SOURCES}
${GLOBAL_HEADERS}
${SRC_BLAS_HEADERS}
@@ -851,9 +850,23 @@ add_library(clBLAS
${AUTOGEMM_PRECOMPILED_KERNELS_CONDITIONAL}
#${USERGEMM_SRC}
#${USERGEMM_HEADERS}
- )
+)
+add_library(clBLAS ${CLBLAS_ALL_SOURCES})
add_dependencies(clBLAS GENERATE_CLT)
+function (add_target_definitions target)
+ get_target_property(defs ${target} COMPILE_DEFINITIONS)
+ if (defs MATCHES "NOTFOUND")
+ set(defs "")
+ endif ()
+ foreach (def ${defs} ${ARGN})
+ list(APPEND deflist ${def})
+ endforeach ()
+ set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS "${deflist}")
+endfunction ()
+
+add_target_definitions(clBLAS BUILDING_CLBLAS)
+
if (PRECOMPILE_TRSM_DTRSM OR PRECOMPILE_TRSM_STRSM)
add_dependencies(clBLAS OCLBinaryGenerator_GEN)
endif()
diff --git a/src/library/blas/AutoGemm/Includes.py b/src/library/blas/AutoGemm/Includes.py
index bb1969c..d525f08 100644
--- a/src/library/blas/AutoGemm/Includes.py
+++ b/src/library/blas/AutoGemm/Includes.py
@@ -179,6 +179,14 @@ class ClKernelIncludes:
self.incStr += "#include <CL/cl.h>\n"
self.incStr += "#endif\n"
self.incStr += "\n"
+ self.incStr += "#ifdef __cplusplus\n"
+ self.incStr += "extern \"C\" {\n"
+ self.incStr += "#endif\n"
+ self.incStr += " void initAutoGemmClKernels(void);\n";
+ self.incStr += "#ifdef __cplusplus\n"
+ self.incStr += "}\n";
+ self.incStr += "#endif\n"
+ self.incStr += "\n";
self.cppName = Common.getIncludePath() + "AutoGemmClKernels.cpp"
self.cppFile = open(self.cppName, "w")
@@ -190,29 +198,50 @@ class ClKernelIncludes:
self.cppStr += "#endif\n"
self.cppStr += "\n"
+
+ self.initFunction = "";
+ self.initFunction += "extern \"C\" {\n";
+ self.initFunction += " void initAutoGemmClKernels(void);\n";
+ self.initFunction += "}\n";
+ self.initFunction += "\n";
+ self.initFunction += "void initAutoGemmClKernels(void) {\n";
+ self.defines = "";
+
def addKernel(self, kernel):
- kernelName = kernel.getName()
- self.incStr += "extern cl_kernel %s_clKernel;\n" % kernelName
- self.cppStr += "cl_kernel %s_clKernel = NULL;\n" % kernelName
- kernelName = kernel.getRowName()
- self.incStr += "extern cl_kernel %s_clKernel;\n" % kernelName
- self.cppStr += "cl_kernel %s_clKernel = NULL;\n" % kernelName
- kernelName = kernel.getColName()
- self.incStr += "extern cl_kernel %s_clKernel;\n" % kernelName
- self.cppStr += "cl_kernel %s_clKernel = NULL;\n" % kernelName
- kernelName = kernel.getCornerName()
- self.incStr += "extern cl_kernel %s_clKernel;\n" % kernelName
- self.cppStr += "cl_kernel %s_clKernel = NULL;\n" % kernelName
+ kernelNames = [
+ kernel.getName(),
+ kernel.getRowName(),
+ kernel.getColName(),
+ kernel.getCornerName()
+ ]
+ for kernelName in kernelNames:
+ self.incStr += "extern cl_kernel %s_clKernel;\n" % kernelName
+
+ self.defines += "cl_kernel %s_clKernel = NULL;\n" % kernelName
+
+ self.initFunction += " if(%s_clKernel != NULL) {\n" % kernelName
+ self.initFunction += " clReleaseKernel(%s_clKernel);\n" % kernelName
+ self.initFunction += " %s_clKernel = NULL;\n" % kernelName
+ self.initFunction += " }\n"
self.incFile.write( self.incStr )
self.incStr = ""
- self.cppFile.write( self.cppStr )
- self.cppStr = ""
+# self.cppFile.write( self.cppStr )
+# self.cppStr = ""
def writeToFile(self):
self.incFile.write( self.incStr )
self.incFile.write( "\n#endif\n" )
self.incFile.close()
+
+ self.initFunction += "}\n";
+ self.cppStr += self.defines + "\n";
+ self.defines = "";
+ self.cppStr += self.initFunction + "\n";
+ self.initFunction = "";
+
+# self.cppStr += "\n";
+# self.cppStr += "initAutoGemmClKernels();\n";
self.cppFile.write( self.cppStr )
self.cppFile.close()
diff --git a/src/library/blas/init.c b/src/library/blas/init.c
index 31cb3b0..66aee44 100644
--- a/src/library/blas/init.c
+++ b/src/library/blas/init.c
@@ -25,6 +25,9 @@
#include <events.h>
#include <stdlib.h>
#include <stdio.h>
+#ifdef BUILDING_CLBLAS
+#include "AutoGemmIncludes/AutoGemmClKernels.h"
+#endif
clblasStatus
clblasGetVersion(cl_uint* major, cl_uint* minor, cl_uint* patch)
@@ -250,5 +253,9 @@ clblasTeardown(void)
printMemLeaksInfo();
releaseMallocTrace();
+#ifdef BUILDING_CLBLAS
+ initAutoGemmClKernels();
+#endif
+
clblasInitialized = 0;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/clblas.git
More information about the debian-science-commits
mailing list