[clfft] 01/16: fixing the thread saefty issue with contribution from #146

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Sep 1 07:42:41 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository clfft.

commit b43cc6157f7420d71ef63f8e8b7d90af08318f68
Author: bragadeesh <bragadeesh.natarajan at amd>
Date:   Thu Jul 28 16:15:42 2016 -0700

    fixing the thread saefty issue with contribution from #146
---
 src/library/enqueue.cpp           | 11 ++++++++---
 src/library/fft_binary_lookup.cpp |  2 +-
 src/library/repo.cpp              | 27 +++++++++++++++++++++++++--
 src/library/repo.h                |  6 +++++-
 4 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/src/library/enqueue.cpp b/src/library/enqueue.cpp
index befdf65..f5ee01b 100644
--- a/src/library/enqueue.cpp
+++ b/src/library/enqueue.cpp
@@ -562,8 +562,11 @@ clfftStatus FFTAction::enqueue(clfftPlanHandle plHandle,
 
     cl_program	prog;
     cl_kernel	kern;
+	lockRAII* kernelLock;
     OPENCL_V( fftRepo.getclProgram( this->getGenerator(), this->getSignatureData(), prog, this->plan->bakeDevice, this->plan->context ), _T( "fftRepo.getclProgram failed" ) );
-    OPENCL_V( fftRepo.getclKernel( prog, dir, kern ), _T( "fftRepo.getclKernels failed" ) );
+    OPENCL_V( fftRepo.getclKernel( prog, dir, kern, kernelLock), _T( "fftRepo.getclKernels failed" ) );
+
+	scopedLock sLock(*kernelLock, _T("FFTAction::enqueue"));
 
     cl_uint uarg = 0;
     if (!this->plan->transflag && !(this->plan->gen == Copy))
@@ -792,7 +795,8 @@ clfftStatus FFTAction::compileKernels( const cl_command_queue commQueueFFT, cons
         cl_kernel kernel;
         if( buildFwdKernel )
         {
-            if( fftRepo.getclKernel( program, CLFFT_FORWARD, kernel ) == CLFFT_INVALID_KERNEL )
+			lockRAII *kernelLock;
+            if( fftRepo.getclKernel( program, CLFFT_FORWARD, kernel, kernelLock) == CLFFT_INVALID_KERNEL )
             {
                 std::string entryPoint;
                 OPENCL_V( fftRepo.getProgramEntryPoint( this->getGenerator(), this->getSignatureData(), CLFFT_FORWARD, entryPoint, q_device, fftPlan->context ), _T( "fftRepo.getProgramEntryPoint failed." ) );
@@ -806,7 +810,8 @@ clfftStatus FFTAction::compileKernels( const cl_command_queue commQueueFFT, cons
 
         if( buildBwdKernel )
         {
-            if( fftRepo.getclKernel( program, CLFFT_BACKWARD, kernel ) == CLFFT_INVALID_KERNEL )
+			lockRAII *kernelLock;
+            if( fftRepo.getclKernel( program, CLFFT_BACKWARD, kernel, kernelLock ) == CLFFT_INVALID_KERNEL )
             {
                 std::string entryPoint;
                 OPENCL_V( fftRepo.getProgramEntryPoint( this->getGenerator(), this->getSignatureData(), CLFFT_BACKWARD, entryPoint, q_device, fftPlan->context ), _T( "fftRepo.getProgramEntryPoint failed." ) );
diff --git a/src/library/fft_binary_lookup.cpp b/src/library/fft_binary_lookup.cpp
index 9a80936..ff386e2 100644
--- a/src/library/fft_binary_lookup.cpp
+++ b/src/library/fft_binary_lookup.cpp
@@ -55,7 +55,7 @@ extern "C"
 
 static char * sep()
 {
-#ifdef __WIN32
+#ifdef _WIN32
     return (char*)"\\";
 #else
     return (char*)"/";
diff --git a/src/library/repo.cpp b/src/library/repo.cpp
index 9e2ab8d..4a66829 100644
--- a/src/library/repo.cpp
+++ b/src/library/repo.cpp
@@ -53,6 +53,18 @@ clfftStatus FFTRepo::releaseResources( )
 		iKern->second.kernel_back = NULL;
 		if (NULL != k)
 			clReleaseKernel( k );
+
+		if (NULL != iKern->second.kernel_fwd_lock)
+		{
+			delete iKern->second.kernel_fwd_lock;
+			iKern->second.kernel_fwd_lock = NULL;
+		}
+
+		if (NULL != iKern->second.kernel_back_lock)
+		{
+			delete iKern->second.kernel_back_lock;
+			iKern->second.kernel_back_lock = NULL;
+		}
 	}
 	mapKernels.clear( );
 
@@ -239,12 +251,16 @@ clfftStatus FFTRepo::setclKernel( cl_program prog, clfftDirection dir, const cl_
 	fftKernels & Kernels = mapKernels[ prog ];
 
 	cl_kernel * pk;
+	lockRAII ** kernelLock;
+
 	switch (dir) {
 	case CLFFT_FORWARD:
 		pk = & Kernels.kernel_fwd;
+		kernelLock = & Kernels.kernel_fwd_lock;
 		break;
 	case CLFFT_BACKWARD:
 		pk = & Kernels.kernel_back;
+		kernelLock = & Kernels.kernel_back_lock;
 		break;
 	default:
 		assert (false);
@@ -255,12 +271,17 @@ clfftStatus FFTRepo::setclKernel( cl_program prog, clfftDirection dir, const cl_
 	if (NULL != *pk)
 		clReleaseKernel( *pk );
 
-	 *pk = kernel;
+	*pk = kernel;
+
+	if (NULL != *kernelLock)
+		 delete kernelLock;
+
+	*kernelLock = new lockRAII;
 
 	return	CLFFT_SUCCESS;
 }
 
-clfftStatus FFTRepo::getclKernel( cl_program prog, clfftDirection dir, cl_kernel& kernel )
+clfftStatus FFTRepo::getclKernel( cl_program prog, clfftDirection dir, cl_kernel& kernel, lockRAII*& kernelLock)
 {
 	scopedLock sLock( lockRepo, _T( "getclKernel" ) );
 
@@ -271,9 +292,11 @@ clfftStatus FFTRepo::getclKernel( cl_program prog, clfftDirection dir, cl_kernel
 	switch (dir) {
 	case CLFFT_FORWARD:
 		kernel = pos->second.kernel_fwd;
+		kernelLock = pos->second.kernel_fwd_lock;
 		break;
 	case CLFFT_BACKWARD:
 		kernel = pos->second.kernel_back;
+		kernelLock = pos->second.kernel_back_lock;
 		break;
 	default:
 		assert (false);
diff --git a/src/library/repo.h b/src/library/repo.h
index df274ef..6b5acda 100644
--- a/src/library/repo.h
+++ b/src/library/repo.h
@@ -124,10 +124,14 @@ class	FFTRepo
 	struct fftKernels {
 		cl_kernel kernel_fwd;
 		cl_kernel kernel_back;
+		lockRAII* kernel_fwd_lock;
+		lockRAII* kernel_back_lock;
 
 		fftKernels ()
 		:	kernel_fwd (NULL)
 		,	kernel_back (NULL)
+		,	kernel_fwd_lock(NULL)
+		,	kernel_back_lock(NULL)
 		{}
 	};
 
@@ -211,7 +215,7 @@ public:
 	clfftStatus getclProgram( const clfftGenerators gen, const FFTKernelSignatureHeader * data, cl_program& prog, const cl_device_id &device, const cl_context& planContext );
 
 	clfftStatus setclKernel ( cl_program prog, clfftDirection dir, const cl_kernel& kernel );
-	clfftStatus getclKernel ( cl_program prog, clfftDirection dir, cl_kernel& kernel );
+	clfftStatus getclKernel ( cl_program prog, clfftDirection dir, cl_kernel& kernel, lockRAII*& kernelLock);
 
 	clfftStatus createPlan( clfftPlanHandle* plHandle, FFTPlan*& fftPlan );
 	clfftStatus getPlan( clfftPlanHandle plHandle, FFTPlan*& fftPlan, lockRAII*& planLock );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/clfft.git



More information about the debian-science-commits mailing list