DPC++ Runtime
Runtime libraries for oneAPI DPC++
sycl::_V1::detail::KernelProgramCache Class Reference

#include <detail/kernel_program_cache.hpp>

Classes

struct  BuildError
 Denotes build error data. More...
 
struct  BuildResult
 Denotes pointer to some entity with its general state and build error. More...
 
struct  KernelBuildResult
 
struct  ProgramBuildResult
 
struct  ProgramCache
 

Public Types

enum class  BuildState { BS_Initial , BS_InProgress , BS_Done , BS_Failed }
 Denotes the state of a build. More...
 
using ProgramBuildResultPtr = std::shared_ptr< ProgramBuildResult >
 
using ProgramCacheKeyT = std::pair< std::pair< SerializedObj, std::uintptr_t >, ur_device_handle_t >
 
using CommonProgramKeyT = std::pair< std::uintptr_t, ur_device_handle_t >
 
using ContextPtr = context_impl *
 
using KernelArgMaskPairT = std::pair< ur_kernel_handle_t, const KernelArgMask * >
 
using KernelBuildResultPtr = std::shared_ptr< KernelBuildResult >
 
using KernelByNameT = ::boost::unordered_map< std::string, KernelBuildResultPtr >
 
using KernelCacheT = ::boost::unordered_map< ur_program_handle_t, KernelByNameT >
 
using KernelFastCacheKeyT = std::tuple< SerializedObj, ur_device_handle_t, std::string, std::string >
 
using KernelFastCacheValT = std::tuple< ur_kernel_handle_t, std::mutex *, const KernelArgMask *, ur_program_handle_t >
 
using KernelFastCacheT = ::boost::unordered_flat_map< KernelFastCacheKeyT, KernelFastCacheValT >
 

Public Member Functions

 ~KernelProgramCache ()=default
 
void setContextPtr (const ContextPtr &AContext)
 
Locked< ProgramCacheacquireCachedPrograms ()
 
Locked< KernelCacheTacquireKernelsPerProgramCache ()
 
std::pair< ProgramBuildResultPtr, bool > getOrInsertProgram (const ProgramCacheKeyT &CacheKey)
 
bool insertBuiltProgram (const ProgramCacheKeyT &CacheKey, ur_program_handle_t Program)
 
std::pair< KernelBuildResultPtr, bool > getOrInsertKernel (ur_program_handle_t Program, const std::string &KernelName)
 
template<typename KeyT >
KernelFastCacheValT tryToGetKernelFast (KeyT &&CacheKey)
 
template<typename KeyT , typename ValT >
void saveKernel (KeyT &&CacheKey, ValT &&CacheVal)
 
void reset ()
 Clears cache state. More...
 
template<errc Errc, typename GetCachedBuildFT , typename BuildFT >
auto getOrBuild (GetCachedBuildFT &&GetCachedBuild, BuildFT &&Build)
 Try to fetch entity (kernel or program) from cache. More...
 

Friends

class ::MockKernelProgramCache
 

Detailed Description

Definition at line 35 of file kernel_program_cache.hpp.

Member Typedef Documentation

◆ CommonProgramKeyT

using sycl::_V1::detail::KernelProgramCache::CommonProgramKeyT = std::pair<std::uintptr_t, ur_device_handle_t>

Definition at line 117 of file kernel_program_cache.hpp.

◆ ContextPtr

◆ KernelArgMaskPairT

using sycl::_V1::detail::KernelProgramCache::KernelArgMaskPairT = std::pair<ur_kernel_handle_t, const KernelArgMask *>

Definition at line 128 of file kernel_program_cache.hpp.

◆ KernelBuildResultPtr

◆ KernelByNameT

using sycl::_V1::detail::KernelProgramCache::KernelByNameT = ::boost::unordered_map<std::string, KernelBuildResultPtr>

Definition at line 144 of file kernel_program_cache.hpp.

◆ KernelCacheT

using sycl::_V1::detail::KernelProgramCache::KernelCacheT = ::boost::unordered_map<ur_program_handle_t, KernelByNameT>

Definition at line 146 of file kernel_program_cache.hpp.

◆ KernelFastCacheKeyT

using sycl::_V1::detail::KernelProgramCache::KernelFastCacheKeyT = std::tuple<SerializedObj, ur_device_handle_t, std::string, std::string>

Definition at line 149 of file kernel_program_cache.hpp.

◆ KernelFastCacheT

◆ KernelFastCacheValT

using sycl::_V1::detail::KernelProgramCache::KernelFastCacheValT = std::tuple<ur_kernel_handle_t, std::mutex *, const KernelArgMask *, ur_program_handle_t>

Definition at line 151 of file kernel_program_cache.hpp.

◆ ProgramBuildResultPtr

◆ ProgramCacheKeyT

using sycl::_V1::detail::KernelProgramCache::ProgramCacheKeyT = std::pair<std::pair<SerializedObj, std::uintptr_t>, ur_device_handle_t>

Definition at line 115 of file kernel_program_cache.hpp.

Member Enumeration Documentation

◆ BuildState

Denotes the state of a build.

Enumerator
BS_Initial 
BS_InProgress 
BS_Done 
BS_Failed 

Definition at line 47 of file kernel_program_cache.hpp.

Constructor & Destructor Documentation

◆ ~KernelProgramCache()

sycl::_V1::detail::KernelProgramCache::~KernelProgramCache ( )
default

Member Function Documentation

◆ acquireCachedPrograms()

Locked<ProgramCache> sycl::_V1::detail::KernelProgramCache::acquireCachedPrograms ( )
inline

◆ acquireKernelsPerProgramCache()

Locked<KernelCacheT> sycl::_V1::detail::KernelProgramCache::acquireKernelsPerProgramCache ( )
inline

Definition at line 170 of file kernel_program_cache.hpp.

Referenced by getOrInsertKernel().

◆ getOrBuild()

template<errc Errc, typename GetCachedBuildFT , typename BuildFT >
auto sycl::_V1::detail::KernelProgramCache::getOrBuild ( GetCachedBuildFT &&  GetCachedBuild,
BuildFT &&  Build 
)
inline

Try to fetch entity (kernel or program) from cache.

If there is no such entity try to build it. Throw any exception build process may throw. This method eliminates unwanted builds by employing atomic variable with build state and waiting until the entity is built in another thread. If the building thread has failed the awaiting thread will fail either. Exception thrown by build procedure are rethrown.

Template Parameters
RetTtype of entity to get
Errcerror code of exception to throw on awaiting thread if the building thread fails build step.
KeyTkey (in cache) to fetch built entity with
AcquireFTtype of function which will acquire the locked version of the cache. Accept reference to KernelProgramCache.
GetCacheFTtype of function which will fetch proper cache from locked version. Accepts reference to locked version of cache.
BuildFTtype of function which will build the entity if it is not in cache. Accepts nothing. Return pointer to built entity.
Returns
a pointer to cached build result, return value must not be nullptr.

Definition at line 275 of file kernel_program_cache.hpp.

References BS_Done, BS_Failed, BS_Initial, BS_InProgress, sycl::_V1::exception::code(), sycl::_V1::detail::KernelProgramCache::BuildError::Code, sycl::_V1::detail::KernelProgramCache::BuildResult< T >::Error, sycl::_V1::detail::get_ur_error(), sycl::_V1::detail::KernelProgramCache::BuildError::isFilledIn(), sycl::_V1::make_error_code(), sycl::_V1::memory_allocation, sycl::_V1::detail::KernelProgramCache::BuildError::Msg, reset(), sycl::_V1::detail::set_ur_error(), sycl::_V1::detail::KernelProgramCache::BuildResult< T >::State, sycl::_V1::detail::KernelProgramCache::BuildResult< T >::updateAndNotify(), sycl::_V1::detail::KernelProgramCache::BuildResult< T >::Val, sycl::_V1::detail::KernelProgramCache::BuildResult< T >::waitUntilTransition(), and sycl::_V1::exception::what().

Referenced by sycl::_V1::detail::ProgramManager::build(), sycl::_V1::detail::ProgramManager::getBuiltURProgram(), and sycl::_V1::detail::ProgramManager::getOrCreateKernel().

◆ getOrInsertKernel()

std::pair<KernelBuildResultPtr, bool> sycl::_V1::detail::KernelProgramCache::getOrInsertKernel ( ur_program_handle_t  Program,
const std::string &  KernelName 
)
inline

◆ getOrInsertProgram()

std::pair<ProgramBuildResultPtr, bool> sycl::_V1::detail::KernelProgramCache::getOrInsertProgram ( const ProgramCacheKeyT CacheKey)
inline

◆ insertBuiltProgram()

bool sycl::_V1::detail::KernelProgramCache::insertBuiltProgram ( const ProgramCacheKeyT CacheKey,
ur_program_handle_t  Program 
)
inline

◆ reset()

void sycl::_V1::detail::KernelProgramCache::reset ( )
inline

Clears cache state.

This member function should only be used in unit tests.

Definition at line 243 of file kernel_program_cache.hpp.

Referenced by getOrBuild().

◆ saveKernel()

template<typename KeyT , typename ValT >
void sycl::_V1::detail::KernelProgramCache::saveKernel ( KeyT &&  CacheKey,
ValT &&  CacheVal 
)
inline

◆ setContextPtr()

void sycl::_V1::detail::KernelProgramCache::setContextPtr ( const ContextPtr AContext)
inline

◆ tryToGetKernelFast()

template<typename KeyT >
KernelFastCacheValT sycl::_V1::detail::KernelProgramCache::tryToGetKernelFast ( KeyT &&  CacheKey)
inline

Friends And Related Function Documentation

◆ ::MockKernelProgramCache

friend class ::MockKernelProgramCache
friend

Definition at line 346 of file kernel_program_cache.hpp.


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