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

#include <detail/kernel_program_cache.hpp>


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 >, sycl::detail::pi::PiDevice >
using CommonProgramKeyT = std::pair< std::uintptr_t, sycl::detail::pi::PiDevice >
using ContextPtr = context_impl *
using KernelArgMaskPairT = std::pair< sycl::detail::pi::PiKernel, const KernelArgMask * >
using KernelBuildResultPtr = std::shared_ptr< KernelBuildResult >
using KernelByNameT = ::boost::unordered_map< std::string, KernelBuildResultPtr >
using KernelCacheT = ::boost::unordered_map< sycl::detail::pi::PiProgram, KernelByNameT >
using KernelFastCacheKeyT = std::tuple< SerializedObj, sycl::detail::pi::PiDevice, std::string, std::string >
using KernelFastCacheValT = std::tuple< sycl::detail::pi::PiKernel, std::mutex *, const KernelArgMask *, sycl::detail::pi::PiProgram >
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)
std::pair< KernelBuildResultPtr, bool > getOrInsertKernel (sycl::detail::pi::PiProgram 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<typename ExceptionT , typename GetCachedBuildFT , typename BuildFT >
auto getOrBuild (GetCachedBuildFT &&GetCachedBuild, BuildFT &&Build)
 Try to fetch entity (kernel or program) from cache. More...


class ::MockKernelProgramCache

Detailed Description

Definition at line 34 of file kernel_program_cache.hpp.

Member Typedef Documentation

◆ CommonProgramKeyT

◆ ContextPtr

◆ KernelArgMaskPairT

◆ KernelBuildResultPtr

◆ KernelByNameT

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

Definition at line 141 of file kernel_program_cache.hpp.

◆ KernelCacheT

◆ KernelFastCacheKeyT

◆ KernelFastCacheT

◆ KernelFastCacheValT

◆ ProgramBuildResultPtr

◆ ProgramCacheKeyT

Definition at line 110 of file kernel_program_cache.hpp.

Member Enumeration Documentation

◆ BuildState

Denotes the state of a build.


Definition at line 46 of file kernel_program_cache.hpp.

Constructor & Destructor Documentation

◆ ~KernelProgramCache()

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

Member Function Documentation

◆ acquireCachedPrograms()

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

◆ acquireKernelsPerProgramCache()

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

Definition at line 168 of file kernel_program_cache.hpp.

Referenced by getOrInsertKernel().

◆ getOrBuild()

template<typename ExceptionT , typename GetCachedBuildFT , typename BuildFT >
auto sycl::_V1::detail::KernelProgramCache::getOrBuild ( GetCachedBuildFT &&  GetCachedBuild,
BuildFT &&  Build 

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
ExceptionTtype 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.
a pointer to cached build result, return value must not be nullptr.

Definition at line 251 of file kernel_program_cache.hpp.

References BS_Done, BS_Failed, BS_Initial, BS_InProgress, sycl::_V1::detail::KernelProgramCache::BuildError::Code, sycl::_V1::detail::KernelProgramCache::BuildResult< T >::Error, sycl::_V1::exception::get_cl_code(), sycl::_V1::detail::KernelProgramCache::BuildError::isFilledIn(), sycl::_V1::detail::KernelProgramCache::BuildError::Msg, reset(), 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::getBuiltPIProgram(), and sycl::_V1::detail::ProgramManager::getOrCreateKernel().

◆ getOrInsertKernel()

std::pair<KernelBuildResultPtr, bool> sycl::_V1::detail::KernelProgramCache::getOrInsertKernel ( sycl::detail::pi::PiProgram  Program,
const std::string &  KernelName 

◆ getOrInsertProgram()

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

◆ reset()

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

Clears cache state.

This member function should only be used in unit tests.

Definition at line 219 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 

◆ setContextPtr()

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

◆ tryToGetKernelFast()

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

Friends And Related Function Documentation

◆ ::MockKernelProgramCache

friend class ::MockKernelProgramCache

Definition at line 318 of file kernel_program_cache.hpp.

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