[clfft] 36/109: fix bug when working multiple devices.

Jérôme Kieffer kieffer-guest at moszumanska.debian.org
Wed May 20 07:29:24 UTC 2015


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

kieffer-guest pushed a commit to branch debian
in repository clfft.

commit ed38aa4d92de9c63c5d1e34478715593457fb5e1
Author: BenjaminCoquelle <benjamin.coquelle at amd.com>
Date:   Wed Dec 4 18:33:18 2013 +0000

    fix bug when working multiple devices.
    
    The lib requires to work with multiple context for the moment in that
    case.
    Therefore we need to get one kernel object per context
---
 src/library/generator.copy.cpp      | 45 ++++++++++++++++++++-----------------
 src/library/generator.stockham.cpp  |  9 ++++++--
 src/library/generator.transpose.cpp | 10 +++++++--
 src/library/plan.cpp                | 14 ++++++------
 src/library/repo.cpp                | 45 +++++++++++++++++++++++++++----------
 src/library/repo.h                  | 19 ++++++++++------
 src/library/transform.cpp           |  2 +-
 7 files changed, 93 insertions(+), 51 deletions(-)

diff --git a/src/library/generator.copy.cpp b/src/library/generator.copy.cpp
index 5afe3cd..b88adae 100644
--- a/src/library/generator.copy.cpp
+++ b/src/library/generator.copy.cpp
@@ -447,28 +447,33 @@ using namespace CopyGenerator;
 template<>
 clfftStatus FFTPlan::GenerateKernelPvt<Copy>(FFTRepo& fftRepo, const cl_command_queue commQueueFFT ) const
 {
-    FFTKernelGenKeyParams params;
-    OPENCL_V( this->GetKernelGenKeyPvt<Copy> (params), _T("GetKernelGenKey() failed!") );
+  FFTKernelGenKeyParams params;
+  OPENCL_V( this->GetKernelGenKeyPvt<Copy> (params), _T("GetKernelGenKey() failed!") );
+
+  std::string programCode;
+  Precision pr = (params.fft_precision == CLFFT_SINGLE) ? P_SINGLE : P_DOUBLE;
+  switch(pr)
+  {
+  case P_SINGLE:
+    {
+      CopyKernel<P_SINGLE> kernel(params);
+      kernel.GenerateKernel(programCode);
+    } break;
+  case P_DOUBLE:
+    {
+      CopyKernel<P_DOUBLE> kernel(params);
+      kernel.GenerateKernel(programCode);
+    } break;
+  }
 
-	std::string programCode;
-	Precision pr = (params.fft_precision == CLFFT_SINGLE) ? P_SINGLE : P_DOUBLE;
-	switch(pr)
-	{
-	case P_SINGLE:
-		{
-			CopyKernel<P_SINGLE> kernel(params);
-			kernel.GenerateKernel(programCode);
-		} break;
-	case P_DOUBLE:
-		{
-			CopyKernel<P_DOUBLE> kernel(params);
-			kernel.GenerateKernel(programCode);
-		} break;
-	}
+  cl_int status = CL_SUCCESS;
+  cl_context QueueContext = NULL;
+  status = clGetCommandQueueInfo(commQueueFFT, CL_QUEUE_CONTEXT, sizeof(cl_context), &QueueContext, NULL);
 
+  OPENCL_V( status, _T( "clGetCommandQueueInfo failed" ) );
 
-    OPENCL_V( fftRepo.setProgramCode( Copy, params, programCode ), _T( "fftRepo.setclString() failed!" ) );
-    OPENCL_V( fftRepo.setProgramEntryPoints( Copy, params, "copy_c2h", "copy_h2c" ), _T( "fftRepo.setProgramEntryPoint() failed!" ) );
+  OPENCL_V( fftRepo.setProgramCode( Copy, params, programCode, QueueContext ), _T( "fftRepo.setclString() failed!" ) );
+  OPENCL_V( fftRepo.setProgramEntryPoints( Copy, params, "copy_c2h", "copy_h2c", QueueContext ), _T( "fftRepo.setProgramEntryPoint() failed!" ) );
 
-    return CLFFT_SUCCESS;
+  return CLFFT_SUCCESS;
 }
diff --git a/src/library/generator.stockham.cpp b/src/library/generator.stockham.cpp
index a1b7969..f6f7241 100644
--- a/src/library/generator.stockham.cpp
+++ b/src/library/generator.stockham.cpp
@@ -3240,6 +3240,11 @@ clfftStatus FFTPlan::GenerateKernelPvt<Stockham>(FFTRepo& fftRepo, const cl_comm
 
     OPENCL_V( status, _T( "clGetCommandQueueInfo failed" ) );
 
+    cl_context QueueContext = NULL;
+    status = clGetCommandQueueInfo(commQueueFFT, CL_QUEUE_CONTEXT, sizeof(cl_context), &QueueContext, NULL);
+
+    OPENCL_V( status, _T( "clGetCommandQueueInfo failed" ) );
+
 	std::string programCode;
 	Precision pr = (params.fft_precision == CLFFT_SINGLE) ? P_SINGLE : P_DOUBLE;
 	switch(pr)
@@ -3260,8 +3265,8 @@ clfftStatus FFTPlan::GenerateKernelPvt<Stockham>(FFTRepo& fftRepo, const cl_comm
 	ReadKernelFromFile(programCode);
 #endif
 
-    OPENCL_V( fftRepo.setProgramCode( Stockham, params, programCode ), _T( "fftRepo.setclString() failed!" ) );
-    OPENCL_V( fftRepo.setProgramEntryPoints( Stockham, params, "fft_fwd", "fft_back" ), _T( "fftRepo.setProgramEntryPoint() failed!" ) );
+    OPENCL_V( fftRepo.setProgramCode( Stockham, params, programCode, QueueContext ), _T( "fftRepo.setclString() failed!" ) );
+    OPENCL_V( fftRepo.setProgramEntryPoints( Stockham, params, "fft_fwd", "fft_back", QueueContext ), _T( "fftRepo.setProgramEntryPoint() failed!" ) );
 
     return CLFFT_SUCCESS;
 }
diff --git a/src/library/generator.transpose.cpp b/src/library/generator.transpose.cpp
index 2c83b8a..0615b99 100644
--- a/src/library/generator.transpose.cpp
+++ b/src/library/generator.transpose.cpp
@@ -830,8 +830,14 @@ clfftStatus FFTPlan::GenerateKernelPvt<Transpose> ( FFTRepo& fftRepo, const cl_c
 	std::string programCode;
 	OPENCL_V( GenerateTransposeKernel( params, programCode ), _T( "GenerateTransposeKernel() failed!" ) );
 
-	OPENCL_V( fftRepo.setProgramCode( Transpose, params, programCode ), _T( "fftRepo.setclString() failed!" ) );
-	OPENCL_V( fftRepo.setProgramEntryPoints( Transpose, params, "fft_trans", "fft_trans" ), _T( "fftRepo.setProgramEntryPoint() failed!" ) );
+  cl_int status = CL_SUCCESS;
+  cl_context QueueContext = NULL;
+  status = clGetCommandQueueInfo(commQueueFFT, CL_QUEUE_CONTEXT, sizeof(cl_context), &QueueContext, NULL);
+
+  OPENCL_V( status, _T( "clGetCommandQueueInfo failed" ) );
+
+  OPENCL_V( fftRepo.setProgramCode( Transpose, params, programCode, QueueContext ), _T( "fftRepo.setclString() failed!" ) );
+	OPENCL_V( fftRepo.setProgramEntryPoints( Transpose, params, "fft_trans", "fft_trans",QueueContext ), _T( "fftRepo.setProgramEntryPoint() failed!" ) );
 
 	return CLFFT_SUCCESS;
 }
diff --git a/src/library/plan.cpp b/src/library/plan.cpp
index 61ae195..c4064e4 100644
--- a/src/library/plan.cpp
+++ b/src/library/plan.cpp
@@ -194,7 +194,7 @@ clfftStatus	clfftCreateDefaultPlan( clfftPlanHandle* plHandle, cl_context contex
 }
 
 //	Read the kernels that this plan uses from file, and store into the plan
-clfftStatus WriteKernel( const clfftPlanHandle plHandle, const clfftGenerators gen, const FFTKernelGenKeyParams& fftParams )
+clfftStatus WriteKernel( const clfftPlanHandle plHandle, const clfftGenerators gen, const FFTKernelGenKeyParams& fftParams, const cl_context& context )
 {
 	FFTRepo& fftRepo	= FFTRepo::getInstance( );
 
@@ -220,7 +220,7 @@ clfftStatus WriteKernel( const clfftPlanHandle plHandle, const clfftGenerators g
 	}
 
 	std::string kernel;
-	OPENCL_V( fftRepo.getProgramCode( gen, fftParams, kernel ), _T( "fftRepo.getProgramCode failed." ) );
+	OPENCL_V( fftRepo.getProgramCode( gen, fftParams, kernel, context ), _T( "fftRepo.getProgramCode failed." ) );
 
 	kernelFile.get( ) << kernel << std::endl;
 
@@ -250,16 +250,16 @@ clfftStatus CompileKernels( const cl_command_queue commQueueFFT, const clfftPlan
 	OPENCL_V( fftPlan->GetKernelGenKey( fftParams ), _T("GetKernelGenKey() failed!") );
 
 	cl_program program;
-	if( fftRepo.getclProgram( gen, fftParams, program ) == CLFFT_INVALID_PROGRAM )
+  if( fftRepo.getclProgram( gen, fftParams, program, fftPlan->context ) == CLFFT_INVALID_PROGRAM )
 	{
 		//	If the user wishes us to write the kernels out to disk, we do so
 		if( fftRepo.setupData.debugFlags & CLFFT_DUMP_PROGRAMS )
 		{
-			OPENCL_V( WriteKernel( plHandle, gen, fftParams ), _T( "WriteKernel failed." ) );
+			OPENCL_V( WriteKernel( plHandle, gen, fftParams, fftPlan->context ), _T( "WriteKernel failed." ) );
 		}
 
 		std::string programCode;
-		OPENCL_V( fftRepo.getProgramCode( gen, fftParams, programCode ), _T( "fftRepo.getProgramCode failed." ) );
+		OPENCL_V( fftRepo.getProgramCode( gen, fftParams, programCode, fftPlan->context  ), _T( "fftRepo.getProgramCode failed." ) );
 
 		const char* source = programCode.c_str();
 		program = clCreateProgramWithSource( fftPlan->context, 1, &source, NULL, &status );
@@ -317,7 +317,7 @@ clfftStatus CompileKernels( const cl_command_queue commQueueFFT, const clfftPlan
 			if( fftRepo.getclKernel( program, CLFFT_FORWARD, kernel ) == CLFFT_INVALID_KERNEL )
 			{
 				std::string entryPoint;
-				OPENCL_V( fftRepo.getProgramEntryPoint( gen, fftParams, CLFFT_FORWARD, entryPoint ), _T( "fftRepo.getProgramEntryPoint failed." ) );
+				OPENCL_V( fftRepo.getProgramEntryPoint( gen, fftParams, CLFFT_FORWARD, entryPoint, fftPlan->context ), _T( "fftRepo.getProgramEntryPoint failed." ) );
 
 				kernel = clCreateKernel( program, entryPoint.c_str( ), &status );
 				OPENCL_V( status, _T( "clCreateKernel failed" ) );
@@ -331,7 +331,7 @@ clfftStatus CompileKernels( const cl_command_queue commQueueFFT, const clfftPlan
 			if( fftRepo.getclKernel( program, CLFFT_BACKWARD, kernel ) == CLFFT_INVALID_KERNEL )
 			{
 				std::string entryPoint;
-				OPENCL_V( fftRepo.getProgramEntryPoint( gen, fftParams, CLFFT_BACKWARD, entryPoint ), _T( "fftRepo.getProgramEntryPoint failed." ) );
+				OPENCL_V( fftRepo.getProgramEntryPoint( gen, fftParams, CLFFT_BACKWARD, entryPoint, fftPlan->context ), _T( "fftRepo.getProgramEntryPoint failed." ) );
 
 				kernel = clCreateKernel( program, entryPoint.c_str( ), &status );
 				OPENCL_V( status, _T( "clCreateKernel failed" ) );
diff --git a/src/library/repo.cpp b/src/library/repo.cpp
index b41d657..0b6e532 100644
--- a/src/library/repo.cpp
+++ b/src/library/repo.cpp
@@ -34,6 +34,9 @@ size_t FFTRepo::planCount	= 1;
 void* FFTRepo::timerHandle	= NULL;
 GpuStatTimer* FFTRepo::pStatTimer	= NULL;
 
+
+
+
 clfftStatus FFTRepo::releaseResources( )
 {
 	scopedLock sLock( lockRepo, _T( "releaseResources" ) );
@@ -88,11 +91,13 @@ clfftStatus FFTRepo::releaseResources( )
 	return	CLFFT_SUCCESS;
 }
 
-clfftStatus FFTRepo::setProgramCode( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, const std::string& kernel )
+clfftStatus FFTRepo::setProgramCode( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, const std::string& kernel, const cl_context& context )
 {
 	scopedLock sLock( lockRepo, _T( "setProgramCode" ) );
 
-	std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair( gen, fftParam );
+  std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair(fftParam, context);
+	fftRepoKey key = std::make_pair( gen, Params );
+
 
 	// Prefix copyright statement at the top of generated kernels
 	std::stringstream ss;
@@ -121,26 +126,28 @@ clfftStatus FFTRepo::setProgramCode( const clfftGenerators gen, const FFTKernelG
 	return	CLFFT_SUCCESS;
 }
 
-clfftStatus FFTRepo::getProgramCode( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, std::string& kernel )
+clfftStatus FFTRepo::getProgramCode( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, std::string& kernel, const cl_context& context )
 {
 	scopedLock sLock( lockRepo, _T( "getProgramCode" ) );
 
-	std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair( gen, fftParam );
+  std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair(fftParam, context);
+	fftRepoKey key = std::make_pair( gen, Params );
 
 	fftRepo_iterator pos = mapFFTs.find( key);
 	if( pos == mapFFTs.end( ) )
 		return	CLFFT_FILE_NOT_FOUND;
 
-	kernel = pos->second.ProgramString;
+  kernel = pos->second.ProgramString;
 	return	CLFFT_SUCCESS;
 }
 
 clfftStatus FFTRepo::setProgramEntryPoints( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam,
-	const char * kernel_fwd, const char * kernel_back )
+	const char * kernel_fwd, const char * kernel_back, const cl_context& context  )
 {
 	scopedLock sLock( lockRepo, _T( "setProgramEntryPoints" ) );
 
-	std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair( gen, fftParam );
+  std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair(fftParam, context);
+	fftRepoKey key = std::make_pair( gen, Params );
 
 	fftRepoValue& fft  = mapFFTs[ key ];
 	fft.EntryPoint_fwd  = kernel_fwd;
@@ -150,11 +157,12 @@ clfftStatus FFTRepo::setProgramEntryPoints( const clfftGenerators gen, const FFT
 }
 
 clfftStatus FFTRepo::getProgramEntryPoint( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam,
-			clfftDirection dir, std::string& kernel )
+			clfftDirection dir, std::string& kernel, const cl_context& context )
 {
 	scopedLock sLock( lockRepo, _T( "getProgramEntryPoint" ) );
 
-	std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair( gen, fftParam );
+  std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair(fftParam, context);
+	fftRepoKey key = std::make_pair( gen, Params );
 
 	fftRepo_iterator pos = mapFFTs.find( key );
 	if( pos == mapFFTs.end( ) )
@@ -182,7 +190,14 @@ clfftStatus FFTRepo::setclProgram( const clfftGenerators gen, const FFTKernelGen
 {
 	scopedLock sLock( lockRepo, _T( "setclProgram" ) );
 
-	std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair( gen, fftParam );
+  cl_int status = CL_SUCCESS;
+  cl_context ProgramContext = NULL;
+  status = clGetProgramInfo(prog, CL_PROGRAM_CONTEXT, sizeof(cl_context), &ProgramContext, NULL);
+
+  OPENCL_V( status, _T( "clGetCommandQueueInfo failed" ) );
+
+  std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair(fftParam, ProgramContext);
+	fftRepoKey key = std::make_pair( gen, Params );
 
 	fftRepo_iterator pos = mapFFTs.find( key );
 	if( pos == mapFFTs.end( ) )
@@ -198,11 +213,12 @@ clfftStatus FFTRepo::setclProgram( const clfftGenerators gen, const FFTKernelGen
 	return	CLFFT_SUCCESS;
 }
 
-clfftStatus FFTRepo::getclProgram( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, cl_program& prog )
+clfftStatus FFTRepo::getclProgram( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, cl_program& prog, const cl_context& PlanContext  )
 {
 	scopedLock sLock( lockRepo, _T( "getclProgram" ) );
 
-	std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair( gen, fftParam );
+  std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair(fftParam, PlanContext);
+	fftRepoKey key = std::make_pair( gen, Params );
 
 	fftRepo_iterator pos = mapFFTs.find( key );
 	if( pos == mapFFTs.end( ) )
@@ -210,6 +226,11 @@ clfftStatus FFTRepo::getclProgram( const clfftGenerators gen, const FFTKernelGen
 	prog = pos->second.clProgram;
 	if (NULL == prog)
 		return	CLFFT_INVALID_PROGRAM;
+  
+  cl_context ProgContext;
+  clGetProgramInfo(prog, CL_PROGRAM_CONTEXT, sizeof(cl_context), &ProgContext, NULL);
+  if (PlanContext!=ProgContext)
+    return	CLFFT_INVALID_PROGRAM;
 
 	return	CLFFT_SUCCESS;
 }
diff --git a/src/library/repo.h b/src/library/repo.h
index f68242d..f2619e7 100644
--- a/src/library/repo.h
+++ b/src/library/repo.h
@@ -22,6 +22,7 @@
 #include "private.h"
 #include "plan.h"
 #include "lock.h"
+
 #include "../statTimer/statisticalTimer.GPU.h"
 
 
@@ -48,10 +49,14 @@ class	FFTRepo
 
 	//	Map structure to map parameters that a generator uses to a specific set of kernels that the generator
 	//	has created
-	typedef std::pair< clfftGenerators, FFTKernelGenKeyParams > fftRepoKey;
+	//typedef std::pair< clfftGenerators, FFTKernelGenKeyParams > fftRepoKey;
+
+  typedef std::pair< clfftGenerators, std::pair<FFTKernelGenKeyParams, cl_context> > fftRepoKey;
 	typedef std::map< fftRepoKey, fftRepoValue > fftRepoType;
 	typedef fftRepoType::iterator fftRepo_iterator;
 
+
+
 	fftRepoType	mapFFTs;
 
 	struct fftKernels {
@@ -134,15 +139,15 @@ public:
 
 	clfftStatus releaseResources( );
 
-	clfftStatus setProgramCode( const clfftGenerators gen, const FFTKernelGenKeyParams&, const std::string& kernel );
-	clfftStatus getProgramCode( const clfftGenerators gen, const FFTKernelGenKeyParams&, std::string& kernel );
+	clfftStatus setProgramCode( const clfftGenerators gen, const FFTKernelGenKeyParams&, const std::string& kernel, const cl_context& context);
+	clfftStatus getProgramCode( const clfftGenerators gen, const FFTKernelGenKeyParams&, std::string& kernel, const cl_context& context );
 
 	clfftStatus setProgramEntryPoints( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam,
-		const char * kernel_fwd, const char * kernel_back );
-	clfftStatus getProgramEntryPoint( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, clfftDirection dir, std::string& kernel );
+		const char * kernel_fwd, const char * kernel_back, const cl_context& context );
+	clfftStatus getProgramEntryPoint( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, clfftDirection dir, std::string& kernel , const cl_context& context);
 
 	clfftStatus setclProgram( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, const cl_program& kernel );
-	clfftStatus getclProgram( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, cl_program& kernel );
+	clfftStatus getclProgram( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, cl_program& kernel, 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 );
@@ -150,9 +155,9 @@ public:
 	clfftStatus createPlan( clfftPlanHandle* plHandle, FFTPlan*& fftPlan );
 	clfftStatus getPlan( clfftPlanHandle plHandle, FFTPlan*& fftPlan, lockRAII*& planLock );
 	clfftStatus deletePlan( clfftPlanHandle* plHandle );
+  
 
 };
 
-
 #endif
 
diff --git a/src/library/transform.cpp b/src/library/transform.cpp
index e53e830..b1546f0 100644
--- a/src/library/transform.cpp
+++ b/src/library/transform.cpp
@@ -1152,7 +1152,7 @@ clfftStatus clfftEnqueueTransform(
 
 	cl_program	prog;
 	cl_kernel	kern;
-	OPENCL_V( fftRepo.getclProgram( fftPlan->gen, fftParams, prog ), _T( "fftRepo.getclProgram failed" ) );
+	OPENCL_V( fftRepo.getclProgram( fftPlan->gen, fftParams, prog, fftPlan->context ), _T( "fftRepo.getclProgram failed" ) );
 	OPENCL_V( fftRepo.getclKernel( prog, dir, kern ), _T( "fftRepo.getclKernels failed" ) );
 
 

-- 
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