Skip to content

Commit b876219

Browse files
committed
Merge branch 'master' into develop
2 parents bbfeec7 + 27a8b2d commit b876219

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/library/lifetime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ clfftStatus clfftSetup( const clfftSetupData* sData )
3939
{
4040
// Static data is not thread safe (to create), so we implement a lock to protect instantiation for the first call
4141
// Implemented outside of FFTRepo::getInstance to minimize lock overhead; this is only necessary on first creation
42-
scopedLock sLock( FFTRepo::lockRepo, _T( "FFTRepo::getInstance" ) );
42+
scopedLock sLock( FFTRepo::lockRepo(), _T( "FFTRepo::getInstance" ) );
4343

4444
// First invocation of this function will allocate the FFTRepo singleton; thereafter the object always exists
4545
FFTRepo& fftRepo = FFTRepo::getInstance( );

src/library/repo.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
using std::map;
2525
using std::string;
2626

27-
// Static initialization of the repo lock variable
28-
lockRAII FFTRepo::lockRepo( _T( "FFTRepo" ) );
29-
3027
// Static initialization of the plan count variable
3128
size_t FFTRepo::planCount = 1;
3229

@@ -39,7 +36,7 @@ GpuStatTimer* FFTRepo::pStatTimer = NULL;
3936

4037
clfftStatus FFTRepo::releaseResources( )
4138
{
42-
scopedLock sLock( lockRepo, _T( "releaseResources" ) );
39+
scopedLock sLock( lockRepo(), _T( "releaseResources" ) );
4340

4441
// Release all handles to Kernels
4542
//
@@ -110,7 +107,7 @@ clfftStatus FFTRepo::releaseResources( )
110107

111108
clfftStatus FFTRepo::setProgramCode( const clfftGenerators gen, const FFTKernelSignatureHeader * data, const std::string& kernel, const cl_device_id &device, const cl_context& planContext )
112109
{
113-
scopedLock sLock( lockRepo, _T( "setProgramCode" ) );
110+
scopedLock sLock( lockRepo(), _T( "setProgramCode" ) );
114111

115112
FFTRepoKey key(gen, data, planContext, device);
116113

@@ -149,7 +146,7 @@ clfftStatus FFTRepo::setProgramCode( const clfftGenerators gen, const FFTKernelS
149146

150147
clfftStatus FFTRepo::getProgramCode( const clfftGenerators gen, const FFTKernelSignatureHeader * data, std::string& kernel, const cl_device_id &device, const cl_context& planContext )
151148
{
152-
scopedLock sLock( lockRepo, _T( "getProgramCode" ) );
149+
scopedLock sLock( lockRepo(), _T( "getProgramCode" ) );
153150

154151
FFTRepoKey key(gen, data, planContext, device);
155152

@@ -164,7 +161,7 @@ clfftStatus FFTRepo::getProgramCode( const clfftGenerators gen, const FFTKernelS
164161
clfftStatus FFTRepo::setProgramEntryPoints( const clfftGenerators gen, const FFTKernelSignatureHeader * data,
165162
const char * kernel_fwd, const char * kernel_back, const cl_device_id &device, const cl_context& planContext )
166163
{
167-
scopedLock sLock( lockRepo, _T( "setProgramEntryPoints" ) );
164+
scopedLock sLock( lockRepo(), _T( "setProgramEntryPoints" ) );
168165

169166
FFTRepoKey key(gen, data, planContext, device);
170167

@@ -178,7 +175,7 @@ clfftStatus FFTRepo::setProgramEntryPoints( const clfftGenerators gen, const FFT
178175
clfftStatus FFTRepo::getProgramEntryPoint( const clfftGenerators gen, const FFTKernelSignatureHeader * data,
179176
clfftDirection dir, std::string& kernel, const cl_device_id &device, const cl_context& planContext )
180177
{
181-
scopedLock sLock( lockRepo, _T( "getProgramEntryPoint" ) );
178+
scopedLock sLock( lockRepo(), _T( "getProgramEntryPoint" ) );
182179

183180
FFTRepoKey key(gen, data, planContext, device);
184181

@@ -206,7 +203,7 @@ clfftStatus FFTRepo::getProgramEntryPoint( const clfftGenerators gen, const FFTK
206203

207204
clfftStatus FFTRepo::setclProgram( const clfftGenerators gen, const FFTKernelSignatureHeader * data, const cl_program& prog, const cl_device_id &device, const cl_context& planContext )
208205
{
209-
scopedLock sLock( lockRepo, _T( "setclProgram" ) );
206+
scopedLock sLock( lockRepo(), _T( "setclProgram" ) );
210207

211208
FFTRepoKey key(gen, data, planContext, device);
212209

@@ -229,7 +226,7 @@ clfftStatus FFTRepo::setclProgram( const clfftGenerators gen, const FFTKernelSig
229226

230227
clfftStatus FFTRepo::getclProgram( const clfftGenerators gen, const FFTKernelSignatureHeader * data, cl_program& prog, const cl_device_id &device, const cl_context& planContext )
231228
{
232-
scopedLock sLock( lockRepo, _T( "getclProgram" ) );
229+
scopedLock sLock( lockRepo(), _T( "getclProgram" ) );
233230

234231
FFTRepoKey key(gen, data, planContext, device);
235232

@@ -250,7 +247,7 @@ clfftStatus FFTRepo::getclProgram( const clfftGenerators gen, const FFTKernelSig
250247

251248
clfftStatus FFTRepo::setclKernel( cl_program prog, clfftDirection dir, const cl_kernel& kernel )
252249
{
253-
scopedLock sLock( lockRepo, _T( "setclKernel" ) );
250+
scopedLock sLock( lockRepo(), _T( "setclKernel" ) );
254251

255252
fftKernels & Kernels = mapKernels[ prog ];
256253

@@ -287,7 +284,7 @@ clfftStatus FFTRepo::setclKernel( cl_program prog, clfftDirection dir, const cl_
287284

288285
clfftStatus FFTRepo::getclKernel( cl_program prog, clfftDirection dir, cl_kernel& kernel, lockRAII*& kernelLock)
289286
{
290-
scopedLock sLock( lockRepo, _T( "getclKernel" ) );
287+
scopedLock sLock( lockRepo(), _T( "getclKernel" ) );
291288

292289
Kernel_iterator pos = mapKernels.find( prog );
293290
if (pos == mapKernels.end( ) )
@@ -315,7 +312,7 @@ clfftStatus FFTRepo::getclKernel( cl_program prog, clfftDirection dir, cl_kernel
315312

316313
clfftStatus FFTRepo::createPlan( clfftPlanHandle* plHandle, FFTPlan*& fftPlan )
317314
{
318-
scopedLock sLock( lockRepo, _T( "insertPlan" ) );
315+
scopedLock sLock( lockRepo(), _T( "insertPlan" ) );
319316

320317
// We keep track of this memory in our own collection class, to make sure it's freed in releaseResources
321318
// The lifetime of a plan is tracked by the client and is freed when the client calls ::clfftDestroyPlan()
@@ -336,7 +333,7 @@ clfftStatus FFTRepo::createPlan( clfftPlanHandle* plHandle, FFTPlan*& fftPlan )
336333

337334
clfftStatus FFTRepo::getPlan( clfftPlanHandle plHandle, FFTPlan*& fftPlan, lockRAII*& planLock )
338335
{
339-
scopedLock sLock( lockRepo, _T( "getPlan" ) );
336+
scopedLock sLock( lockRepo(), _T( "getPlan" ) );
340337

341338
// First, check if we have already created a plan with this exact same FFTPlan
342339
repoPlansType::iterator iter = repoPlans.find( plHandle );
@@ -352,7 +349,7 @@ clfftStatus FFTRepo::getPlan( clfftPlanHandle plHandle, FFTPlan*& fftPlan, lockR
352349

353350
clfftStatus FFTRepo::deletePlan( clfftPlanHandle* plHandle )
354351
{
355-
scopedLock sLock( lockRepo, _T( "deletePlan" ) );
352+
scopedLock sLock( lockRepo(), _T( "deletePlan" ) );
356353

357354
// First, check if we have already created a plan with this exact same FFTPlan
358355
repoPlansType::iterator iter = repoPlans.find( *plHandle );

src/library/repo.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,14 @@ class FFTRepo
183183
// Used to make the FFTRepo struct thread safe; STL is not thread safe by default
184184
// Optimally, we could use a lock object per STL struct, as two different STL structures
185185
// can be modified at the same time, but a single lock object is easier and performance should
186-
// still be good
187-
static lockRAII lockRepo;
186+
// still be good. This is implemented as a function returning a static local reference to
187+
// assert that the lock must be instantiated before the result can be used.
188+
static lockRAII& lockRepo()
189+
{
190+
// Static initialization of the repo lock variable
191+
static lockRAII lock(_T("FFTRepo"));
192+
return lock;
193+
}
188194

189195
// Our runtime library can instrument kernel timings with a GPU timer available in a shared module
190196
// Handle/Address of the dynamic module that contains timers

0 commit comments

Comments
 (0)