Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ GlobalHandler &GlobalHandler::instance() {
}

template <typename T, typename... Types>
T &GlobalHandler::getOrCreate(InstWithLock<T> &IWL, Types... Args) {
T &GlobalHandler::getOrCreate(InstWithLock<T> &IWL, Types &&...Args) {
const LockGuard Lock{IWL.Lock};

if (!IWL.Inst)
IWL.Inst = std::make_unique<T>(Args...);
IWL.Inst = std::make_unique<T>(std::forward<Types>(Args)...);

return *IWL.Inst;
}
Expand Down Expand Up @@ -182,50 +182,67 @@ void GlobalHandler::registerSchedulerUsage(bool ModifyCounter) {
}

ProgramManager &GlobalHandler::getProgramManager() {
return getOrCreate(MProgramManager);
static ProgramManager &PM = getOrCreate(MProgramManager);
return PM;
}

std::unordered_map<PlatformImplPtr, ContextImplPtr> &
GlobalHandler::getPlatformToDefaultContextCache() {
// The optimization with static reference is not done because
// there are public methods of the GlobalHandler
// that can set the MPlatformToDefaultContextCache back to nullptr.
// So one time initialization is not possible and we need
// to call getOrCreate on every access.
return getOrCreate(MPlatformToDefaultContextCache);
}

std::mutex &GlobalHandler::getPlatformToDefaultContextCacheMutex() {
return getOrCreate(MPlatformToDefaultContextCacheMutex);
static std::mutex &PlatformToDefaultContextCacheMutex =
getOrCreate(MPlatformToDefaultContextCacheMutex);
return PlatformToDefaultContextCacheMutex;
}

Sync &GlobalHandler::getSync() { return getOrCreate(MSync); }
Sync &GlobalHandler::getSync() {
static Sync &sync = getOrCreate(MSync);
return sync;
}

std::vector<PlatformImplPtr> &GlobalHandler::getPlatformCache() {
return getOrCreate(MPlatformCache);
static std::vector<PlatformImplPtr> &PlatformCache =
getOrCreate(MPlatformCache);
return PlatformCache;
}

std::mutex &GlobalHandler::getPlatformMapMutex() {
return getOrCreate(MPlatformMapMutex);
static std::mutex &PlatformMapMutex = getOrCreate(MPlatformMapMutex);
return PlatformMapMutex;
}

std::mutex &GlobalHandler::getFilterMutex() {
return getOrCreate(MFilterMutex);
static std::mutex &FilterMutex = getOrCreate(MFilterMutex);
return FilterMutex;
}

std::vector<AdapterPtr> &GlobalHandler::getAdapters() {
static std::vector<AdapterPtr> &adapters = getOrCreate(MAdapters);
enableOnCrashStackPrinting();
return getOrCreate(MAdapters);
return adapters;
}

ods_target_list &
GlobalHandler::getOneapiDeviceSelectorTargets(const std::string &InitValue) {
return getOrCreate(MOneapiDeviceSelectorTargets, InitValue);
static ods_target_list &OneapiDeviceSelectorTargets =
getOrCreate(MOneapiDeviceSelectorTargets, InitValue);
return OneapiDeviceSelectorTargets;
}

XPTIRegistry &GlobalHandler::getXPTIRegistry() {
return getOrCreate(MXPTIRegistry);
}

ThreadPool &GlobalHandler::getHostTaskThreadPool() {
int Size = SYCLConfig<SYCL_QUEUE_THREAD_POOL_SIZE>::get();
ThreadPool &TP = getOrCreate(MHostTaskThreadPool, Size);

static ThreadPool &TP = getOrCreate(
MHostTaskThreadPool, SYCLConfig<SYCL_QUEUE_THREAD_POOL_SIZE>::get());
return TP;
}

Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class GlobalHandler {
};

template <typename T, typename... Types>
T &getOrCreate(InstWithLock<T> &IWL, Types... Args);
T &getOrCreate(InstWithLock<T> &IWL, Types &&...Args);

InstWithLock<Scheduler> MScheduler;
InstWithLock<ProgramManager> MProgramManager;
Expand Down