Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bragadeesh committed Aug 11, 2017
2 parents bbfeec7 + 27a8b2d commit b876219
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/library/lifetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ clfftStatus clfftSetup( const clfftSetupData* sData )
{
// Static data is not thread safe (to create), so we implement a lock to protect instantiation for the first call
// Implemented outside of FFTRepo::getInstance to minimize lock overhead; this is only necessary on first creation
scopedLock sLock( FFTRepo::lockRepo, _T( "FFTRepo::getInstance" ) );
scopedLock sLock( FFTRepo::lockRepo(), _T( "FFTRepo::getInstance" ) );

// First invocation of this function will allocate the FFTRepo singleton; thereafter the object always exists
FFTRepo& fftRepo = FFTRepo::getInstance( );
Expand Down
27 changes: 12 additions & 15 deletions src/library/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
using std::map;
using std::string;

// Static initialization of the repo lock variable
lockRAII FFTRepo::lockRepo( _T( "FFTRepo" ) );

// Static initialization of the plan count variable
size_t FFTRepo::planCount = 1;

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

clfftStatus FFTRepo::releaseResources( )
{
scopedLock sLock( lockRepo, _T( "releaseResources" ) );
scopedLock sLock( lockRepo(), _T( "releaseResources" ) );

// Release all handles to Kernels
//
Expand Down Expand Up @@ -110,7 +107,7 @@ clfftStatus FFTRepo::releaseResources( )

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

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

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

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

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

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

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

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

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

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

clfftStatus FFTRepo::setclProgram( const clfftGenerators gen, const FFTKernelSignatureHeader * data, const cl_program& prog, const cl_device_id &device, const cl_context& planContext )
{
scopedLock sLock( lockRepo, _T( "setclProgram" ) );
scopedLock sLock( lockRepo(), _T( "setclProgram" ) );

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

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

clfftStatus FFTRepo::getclProgram( const clfftGenerators gen, const FFTKernelSignatureHeader * data, cl_program& prog, const cl_device_id &device, const cl_context& planContext )
{
scopedLock sLock( lockRepo, _T( "getclProgram" ) );
scopedLock sLock( lockRepo(), _T( "getclProgram" ) );

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

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

clfftStatus FFTRepo::setclKernel( cl_program prog, clfftDirection dir, const cl_kernel& kernel )
{
scopedLock sLock( lockRepo, _T( "setclKernel" ) );
scopedLock sLock( lockRepo(), _T( "setclKernel" ) );

fftKernels & Kernels = mapKernels[ prog ];

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

clfftStatus FFTRepo::getclKernel( cl_program prog, clfftDirection dir, cl_kernel& kernel, lockRAII*& kernelLock)
{
scopedLock sLock( lockRepo, _T( "getclKernel" ) );
scopedLock sLock( lockRepo(), _T( "getclKernel" ) );

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

clfftStatus FFTRepo::createPlan( clfftPlanHandle* plHandle, FFTPlan*& fftPlan )
{
scopedLock sLock( lockRepo, _T( "insertPlan" ) );
scopedLock sLock( lockRepo(), _T( "insertPlan" ) );

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

clfftStatus FFTRepo::getPlan( clfftPlanHandle plHandle, FFTPlan*& fftPlan, lockRAII*& planLock )
{
scopedLock sLock( lockRepo, _T( "getPlan" ) );
scopedLock sLock( lockRepo(), _T( "getPlan" ) );

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

clfftStatus FFTRepo::deletePlan( clfftPlanHandle* plHandle )
{
scopedLock sLock( lockRepo, _T( "deletePlan" ) );
scopedLock sLock( lockRepo(), _T( "deletePlan" ) );

// First, check if we have already created a plan with this exact same FFTPlan
repoPlansType::iterator iter = repoPlans.find( *plHandle );
Expand Down
10 changes: 8 additions & 2 deletions src/library/repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,14 @@ class FFTRepo
// Used to make the FFTRepo struct thread safe; STL is not thread safe by default
// Optimally, we could use a lock object per STL struct, as two different STL structures
// can be modified at the same time, but a single lock object is easier and performance should
// still be good
static lockRAII lockRepo;
// still be good. This is implemented as a function returning a static local reference to
// assert that the lock must be instantiated before the result can be used.
static lockRAII& lockRepo()
{
// Static initialization of the repo lock variable
static lockRAII lock(_T("FFTRepo"));
return lock;
}

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

0 comments on commit b876219

Please sign in to comment.