Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
frechet::app::ConcurrencyContext Class Reference

Detailed Description

a singleton class managing concurrency settings for the application.

It controls the number of parallel threads (for use by TBB functions).

It sets up OpenCL contexts for use by a GPU device.

Also acts as a factory for poly::Algorithm

Author
Peter Schäfer

Definition at line 22 of file concurrency.h.

#include <concurrency.h>

Public Member Functions

 ConcurrencyContext ()
 default constructor; does no initialisation More...
 
 ~ConcurrencyContext ()
 destructor; releases all OpenCL resources More...
 
void setup (int max_threads)
 set up TBB thread count More...
 
bool setupGpu (size2_t max_tile)
 set up OpenCL context More...
 
void close ()
 release all OpenCL resources. More...
 

Static Public Member Functions

static int countThreads ()
 
static int countCores ()
 
static tbb::tbb_thread::id currentThread ()
 
static bool hasGpuSupport ()
 
static std::string gpuName ()
 
static cl_uint countGpuUnits ()
 
static cl_context clContext ()
 
static cl_command_queue clQueue ()
 
static void maxMaxtrixTile (size2_t &)
 set tile size for cubic matrix multiplication. Tiles adapt to local memory and/or compute units. This is the upper limit; usually {4, 4..8}. More...
 
static int cacheSize (int level)
 size of CPU cache memory More...
 

Static Public Attributes

static ConcurrencyContext instance
 singleton instance More...
 

Private Member Functions

void findCacheSizes ()
 retrieve CPU cache sizes More...
 

Static Private Member Functions

static void cpuid (int leaf, unsigned int regs[4])
 retrieve CPU factory info More...
 
static void cpuid (int leaf, int level, unsigned int regs[4])
 retrieve CPU factory info More...
 
static const char * findKernelDirectory (const char *subdir)
 look up directory containing OpenCL source files ("kernels") More...
 

Private Attributes

tbb::task_scheduler_init * tbb_context
 controls the number of parallel threads that are used by TBB functions. More...
 
int num_cores
 number of physical cores (if known) More...
 
int num_threads
 number of logical threads (always known) More...
 
cl_platform_id platform = nullptr
 OpenCL platform identifier. More...
 
cl_context ctx
 OpenCL platform identifier. More...
 
cl_device_id device = nullptr
 OpenCL device. More...
 
cl_command_queue queue = nullptr
 OpenCL command queue. More...
 
cl_event event = nullptr
 last OpenCL event More...
 
cl_int clerr
 last OpenCL return code More...
 
std::string device_name
 name of OpenCL device More...
 
cl_uint gpu_units
 number of GPU units (if known) More...
 
size2_t max_tile
 maximum tile size for Boolean matrix multiplication More...
 

Constructor & Destructor Documentation

◆ ConcurrencyContext()

ConcurrencyContext::ConcurrencyContext ( )

default constructor; does no initialisation

Definition at line 25 of file concurrency.cpp.

◆ ~ConcurrencyContext()

ConcurrencyContext::~ConcurrencyContext ( )

destructor; releases all OpenCL resources

Definition at line 31 of file concurrency.cpp.

Member Function Documentation

◆ cacheSize()

int ConcurrencyContext::cacheSize ( int  level)
static

size of CPU cache memory

Parameters
levelcache level (L1,L2,L3)
Returns
size of cache memory in bytes

Definition at line 208 of file concurrency.cpp.

◆ clContext()

cl_context ConcurrencyContext::clContext ( )
static
Returns
the OpenCL context

Definition at line 71 of file concurrency.cpp.

◆ close()

void ConcurrencyContext::close ( )

release all OpenCL resources.

Definition at line 177 of file concurrency.cpp.

◆ clQueue()

cl_command_queue ConcurrencyContext::clQueue ( )
static
Returns
the OpenCL command queue

Definition at line 76 of file concurrency.cpp.

◆ countCores()

int ConcurrencyContext::countCores ( )
static
Returns
number of physical cores (not always accurate!)

Definition at line 51 of file concurrency.cpp.

◆ countGpuUnits()

cl_uint ConcurrencyContext::countGpuUnits ( )
static
Returns
number of GPU units (if available)

Definition at line 67 of file concurrency.cpp.

◆ countThreads()

int ConcurrencyContext::countThreads ( )
static
Returns
number of logical threads

Definition at line 47 of file concurrency.cpp.

◆ cpuid() [1/2]

void ConcurrencyContext::cpuid ( int  leaf,
unsigned int  regs[4] 
)
staticprivate

retrieve CPU factory info

Definition at line 198 of file concurrency.cpp.

◆ cpuid() [2/2]

void ConcurrencyContext::cpuid ( int  leaf,
int  level,
unsigned int  regs[4] 
)
staticprivate

retrieve CPU factory info

Definition at line 188 of file concurrency.cpp.

◆ currentThread()

tbb::tbb_thread::id ConcurrencyContext::currentThread ( )
static
Returns
identifier for current thread

Definition at line 55 of file concurrency.cpp.

◆ findCacheSizes()

void frechet::app::ConcurrencyContext::findCacheSizes ( )
private

retrieve CPU cache sizes

◆ findKernelDirectory()

const char * ConcurrencyContext::findKernelDirectory ( const char *  subdir)
staticprivate

look up directory containing OpenCL source files ("kernels")

Definition at line 158 of file concurrency.cpp.

◆ gpuName()

std::string ConcurrencyContext::gpuName ( )
static
Returns
name of the GPU device (if available)

Definition at line 63 of file concurrency.cpp.

◆ hasGpuSupport()

bool ConcurrencyContext::hasGpuSupport ( )
static
Returns
true if GPU support is available

Definition at line 59 of file concurrency.cpp.

◆ maxMaxtrixTile()

void ConcurrencyContext::maxMaxtrixTile ( size2_t result)
static

set tile size for cubic matrix multiplication. Tiles adapt to local memory and/or compute units. This is the upper limit; usually {4, 4..8}.

Definition at line 81 of file concurrency.cpp.

◆ setup()

void ConcurrencyContext::setup ( int  max_threads)

set up TBB thread count

Parameters
max_threadsmaximum number of thread

Definition at line 39 of file concurrency.cpp.

◆ setupGpu()

bool ConcurrencyContext::setupGpu ( size2_t  max_tile)

set up OpenCL context

Parameters
max_tilemaximum tile size for Boolean matrix multiplication
Returns
true, if OpenCL initialisation was succesfull. false, if OpenCL is not available.

Definition at line 87 of file concurrency.cpp.

Member Data Documentation

◆ clerr

cl_int frechet::app::ConcurrencyContext::clerr
private

last OpenCL return code

Definition at line 46 of file concurrency.h.

◆ ctx

cl_context frechet::app::ConcurrencyContext::ctx
private

OpenCL platform identifier.

Definition at line 38 of file concurrency.h.

◆ device

cl_device_id frechet::app::ConcurrencyContext::device = nullptr
private

OpenCL device.

Definition at line 40 of file concurrency.h.

◆ device_name

std::string frechet::app::ConcurrencyContext::device_name
private

name of OpenCL device

Definition at line 49 of file concurrency.h.

◆ event

cl_event frechet::app::ConcurrencyContext::event = nullptr
private

last OpenCL event

Definition at line 44 of file concurrency.h.

◆ gpu_units

cl_uint frechet::app::ConcurrencyContext::gpu_units
private

number of GPU units (if known)

Definition at line 51 of file concurrency.h.

◆ instance

ConcurrencyContext ConcurrencyContext::instance
static

singleton instance

Definition at line 61 of file concurrency.h.

◆ max_tile

size2_t frechet::app::ConcurrencyContext::max_tile
private

maximum tile size for Boolean matrix multiplication

Definition at line 53 of file concurrency.h.

◆ num_cores

int frechet::app::ConcurrencyContext::num_cores
private

number of physical cores (if known)

Definition at line 31 of file concurrency.h.

◆ num_threads

int frechet::app::ConcurrencyContext::num_threads
private

number of logical threads (always known)

Definition at line 33 of file concurrency.h.

◆ platform

cl_platform_id frechet::app::ConcurrencyContext::platform = nullptr
private

OpenCL platform identifier.

Definition at line 36 of file concurrency.h.

◆ queue

cl_command_queue frechet::app::ConcurrencyContext::queue = nullptr
private

OpenCL command queue.

Definition at line 42 of file concurrency.h.

◆ tbb_context

tbb::task_scheduler_init* frechet::app::ConcurrencyContext::tbb_context
private

controls the number of parallel threads that are used by TBB functions.

Definition at line 29 of file concurrency.h.


The documentation for this class was generated from the following files: