@@ -34,6 +34,9 @@ size_t FFTRepo::planCount = 1;
3434void * FFTRepo::timerHandle = NULL ;
3535GpuStatTimer* FFTRepo::pStatTimer = NULL ;
3636
37+
38+
39+
3740clfftStatus FFTRepo::releaseResources ( )
3841{
3942 scopedLock sLock ( lockRepo, _T ( " releaseResources" ) );
@@ -88,11 +91,13 @@ clfftStatus FFTRepo::releaseResources( )
8891 return CLFFT_SUCCESS;
8992}
9093
91- clfftStatus FFTRepo::setProgramCode ( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, const std::string& kernel )
94+ clfftStatus FFTRepo::setProgramCode ( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, const std::string& kernel, const cl_context& context )
9295{
9396 scopedLock sLock ( lockRepo, _T ( " setProgramCode" ) );
9497
95- std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair ( gen, fftParam );
98+ std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair (fftParam, context);
99+ fftRepoKey key = std::make_pair ( gen, Params );
100+
96101
97102 // Prefix copyright statement at the top of generated kernels
98103 std::stringstream ss;
@@ -121,26 +126,28 @@ clfftStatus FFTRepo::setProgramCode( const clfftGenerators gen, const FFTKernelG
121126 return CLFFT_SUCCESS;
122127}
123128
124- clfftStatus FFTRepo::getProgramCode ( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, std::string& kernel )
129+ clfftStatus FFTRepo::getProgramCode ( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, std::string& kernel, const cl_context& context )
125130{
126131 scopedLock sLock ( lockRepo, _T ( " getProgramCode" ) );
127132
128- std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair ( gen, fftParam );
133+ std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair (fftParam, context);
134+ fftRepoKey key = std::make_pair ( gen, Params );
129135
130136 fftRepo_iterator pos = mapFFTs.find ( key);
131137 if ( pos == mapFFTs.end ( ) )
132138 return CLFFT_FILE_NOT_FOUND;
133139
134- kernel = pos->second .ProgramString ;
140+ kernel = pos->second .ProgramString ;
135141 return CLFFT_SUCCESS;
136142}
137143
138144clfftStatus FFTRepo::setProgramEntryPoints ( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam,
139- const char * kernel_fwd, const char * kernel_back )
145+ const char * kernel_fwd, const char * kernel_back, const cl_context& context )
140146{
141147 scopedLock sLock ( lockRepo, _T ( " setProgramEntryPoints" ) );
142148
143- std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair ( gen, fftParam );
149+ std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair (fftParam, context);
150+ fftRepoKey key = std::make_pair ( gen, Params );
144151
145152 fftRepoValue& fft = mapFFTs[ key ];
146153 fft.EntryPoint_fwd = kernel_fwd;
@@ -150,11 +157,12 @@ clfftStatus FFTRepo::setProgramEntryPoints( const clfftGenerators gen, const FFT
150157}
151158
152159clfftStatus FFTRepo::getProgramEntryPoint ( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam,
153- clfftDirection dir, std::string& kernel )
160+ clfftDirection dir, std::string& kernel, const cl_context& context )
154161{
155162 scopedLock sLock ( lockRepo, _T ( " getProgramEntryPoint" ) );
156163
157- std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair ( gen, fftParam );
164+ std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair (fftParam, context);
165+ fftRepoKey key = std::make_pair ( gen, Params );
158166
159167 fftRepo_iterator pos = mapFFTs.find ( key );
160168 if ( pos == mapFFTs.end ( ) )
@@ -182,7 +190,14 @@ clfftStatus FFTRepo::setclProgram( const clfftGenerators gen, const FFTKernelGen
182190{
183191 scopedLock sLock ( lockRepo, _T ( " setclProgram" ) );
184192
185- std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair ( gen, fftParam );
193+ cl_int status = CL_SUCCESS;
194+ cl_context ProgramContext = NULL ;
195+ status = clGetProgramInfo (prog, CL_PROGRAM_CONTEXT, sizeof (cl_context), &ProgramContext, NULL );
196+
197+ OPENCL_V ( status, _T ( " clGetCommandQueueInfo failed" ) );
198+
199+ std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair (fftParam, ProgramContext);
200+ fftRepoKey key = std::make_pair ( gen, Params );
186201
187202 fftRepo_iterator pos = mapFFTs.find ( key );
188203 if ( pos == mapFFTs.end ( ) )
@@ -198,18 +213,24 @@ clfftStatus FFTRepo::setclProgram( const clfftGenerators gen, const FFTKernelGen
198213 return CLFFT_SUCCESS;
199214}
200215
201- clfftStatus FFTRepo::getclProgram ( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, cl_program& prog )
216+ clfftStatus FFTRepo::getclProgram ( const clfftGenerators gen, const FFTKernelGenKeyParams& fftParam, cl_program& prog, const cl_context& PlanContext )
202217{
203218 scopedLock sLock ( lockRepo, _T ( " getclProgram" ) );
204219
205- std::pair< clfftGenerators, FFTKernelGenKeyParams > key = std::make_pair ( gen, fftParam );
220+ std::pair<FFTKernelGenKeyParams, cl_context> Params = std::make_pair (fftParam, PlanContext);
221+ fftRepoKey key = std::make_pair ( gen, Params );
206222
207223 fftRepo_iterator pos = mapFFTs.find ( key );
208224 if ( pos == mapFFTs.end ( ) )
209225 return CLFFT_INVALID_PROGRAM;
210226 prog = pos->second .clProgram ;
211227 if (NULL == prog)
212228 return CLFFT_INVALID_PROGRAM;
229+
230+ cl_context ProgContext;
231+ clGetProgramInfo (prog, CL_PROGRAM_CONTEXT, sizeof (cl_context), &ProgContext, NULL );
232+ if (PlanContext!=ProgContext)
233+ return CLFFT_INVALID_PROGRAM;
213234
214235 return CLFFT_SUCCESS;
215236}
0 commit comments