Skip to content

Commit a9a293b

Browse files
author
Pavel Chupin
authored
Revert "[SYCL] Guard access to the cache of device lib programs (#6094)"
This reverts commit 92cfd53.
1 parent 6244efe commit a9a293b

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

sycl/source/detail/context_impl.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ class context_impl {
140140
/// reference.
141141
const std::vector<device> &getDevices() const { return MDevices; }
142142

143-
using CachedLibProgramsT =
144-
std::map<std::pair<DeviceLibExt, RT::PiDevice>, RT::PiProgram>;
145-
146143
/// In contrast to user programs, which are compiled from user code, library
147144
/// programs come from the SYCL runtime. They are identified by the
148145
/// corresponding extension:
@@ -154,10 +151,10 @@ class context_impl {
154151
/// See `doc/design/DeviceLibExtensions.rst' for
155152
/// more details.
156153
///
157-
/// \returns an instance of sycl::detail::Locked which wraps a map with device
158-
/// library programs and the corresponding lock for synchronized access.
159-
Locked<CachedLibProgramsT> acquireCachedLibPrograms() {
160-
return {MCachedLibPrograms, MCachedLibProgramsMutex};
154+
/// \returns a map with device library programs.
155+
std::map<std::pair<DeviceLibExt, RT::PiDevice>, RT::PiProgram> &
156+
getCachedLibPrograms() {
157+
return MCachedLibPrograms;
161158
}
162159

163160
KernelProgramCache &getKernelProgramCache() const;
@@ -182,8 +179,8 @@ class context_impl {
182179
PlatformImplPtr MPlatform;
183180
property_list MPropList;
184181
bool MHostContext;
185-
CachedLibProgramsT MCachedLibPrograms;
186-
std::mutex MCachedLibProgramsMutex;
182+
std::map<std::pair<DeviceLibExt, RT::PiDevice>, RT::PiProgram>
183+
MCachedLibPrograms;
187184
mutable KernelProgramCache MKernelProgramCache;
188185
mutable PropertySupport MSupportBufferLocationByDevices;
189186
};

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(
567567

568568
ProgramPtr BuiltProgram =
569569
build(std::move(ProgramManaged), ContextImpl, CompileOpts, LinkOpts,
570-
getRawSyclObjImpl(Device)->getHandleRef(), DeviceLibReqMask);
570+
getRawSyclObjImpl(Device)->getHandleRef(),
571+
ContextImpl->getCachedLibPrograms(), DeviceLibReqMask);
571572

572573
emitBuiltProgramInfo(BuiltProgram.get(), ContextImpl);
573574

@@ -778,14 +779,13 @@ static const char *getDeviceLibExtensionStr(DeviceLibExt Extension) {
778779
PI_INVALID_OPERATION);
779780
}
780781

781-
static RT::PiProgram loadDeviceLibFallback(const ContextImplPtr Context,
782-
DeviceLibExt Extension,
783-
const RT::PiDevice &Device) {
782+
static RT::PiProgram loadDeviceLibFallback(
783+
const ContextImplPtr Context, DeviceLibExt Extension,
784+
const RT::PiDevice &Device,
785+
std::map<std::pair<DeviceLibExt, RT::PiDevice>, RT::PiProgram>
786+
&CachedLibPrograms) {
784787

785788
const char *LibFileName = getDeviceLibFilename(Extension);
786-
787-
auto LockedCache = Context->acquireCachedLibPrograms();
788-
auto CachedLibPrograms = LockedCache.get();
789789
auto CacheResult = CachedLibPrograms.emplace(
790790
std::make_pair(std::make_pair(Extension, Device), nullptr));
791791
bool Cached = !CacheResult.second;
@@ -923,9 +923,11 @@ static bool isDeviceLibRequired(DeviceLibExt Ext, uint32_t DeviceLibReqMask) {
923923
return ((DeviceLibReqMask & Mask) == Mask);
924924
}
925925

926-
static std::vector<RT::PiProgram>
927-
getDeviceLibPrograms(const ContextImplPtr Context, const RT::PiDevice &Device,
928-
uint32_t DeviceLibReqMask) {
926+
static std::vector<RT::PiProgram> getDeviceLibPrograms(
927+
const ContextImplPtr Context, const RT::PiDevice &Device,
928+
std::map<std::pair<DeviceLibExt, RT::PiDevice>, RT::PiProgram>
929+
&CachedLibPrograms,
930+
uint32_t DeviceLibReqMask) {
929931
std::vector<RT::PiProgram> Programs;
930932

931933
std::pair<DeviceLibExt, bool> RequiredDeviceLibExt[] = {
@@ -973,18 +975,21 @@ getDeviceLibPrograms(const ContextImplPtr Context, const RT::PiDevice &Device,
973975
bool DeviceSupports = DevExtList.npos != DevExtList.find(ExtStr);
974976

975977
if (!DeviceSupports || InhibitNativeImpl) {
976-
Programs.push_back(loadDeviceLibFallback(Context, Ext, Device));
978+
Programs.push_back(
979+
loadDeviceLibFallback(Context, Ext, Device, CachedLibPrograms));
977980
FallbackIsLoaded = true;
978981
}
979982
}
980983
return Programs;
981984
}
982985

983-
ProgramManager::ProgramPtr
984-
ProgramManager::build(ProgramPtr Program, const ContextImplPtr Context,
985-
const std::string &CompileOptions,
986-
const std::string &LinkOptions,
987-
const RT::PiDevice &Device, uint32_t DeviceLibReqMask) {
986+
ProgramManager::ProgramPtr ProgramManager::build(
987+
ProgramPtr Program, const ContextImplPtr Context,
988+
const std::string &CompileOptions, const std::string &LinkOptions,
989+
const RT::PiDevice &Device,
990+
std::map<std::pair<DeviceLibExt, RT::PiDevice>, RT::PiProgram>
991+
&CachedLibPrograms,
992+
uint32_t DeviceLibReqMask) {
988993

989994
if (DbgProgMgr > 0) {
990995
std::cerr << ">>> ProgramManager::build(" << Program.get() << ", "
@@ -1003,7 +1008,8 @@ ProgramManager::build(ProgramPtr Program, const ContextImplPtr Context,
10031008

10041009
std::vector<RT::PiProgram> LinkPrograms;
10051010
if (LinkDeviceLibs) {
1006-
LinkPrograms = getDeviceLibPrograms(Context, Device, DeviceLibReqMask);
1011+
LinkPrograms = getDeviceLibPrograms(Context, Device, CachedLibPrograms,
1012+
DeviceLibReqMask);
10071013
}
10081014

10091015
static const char *ForceLinkEnv = std::getenv("SYCL_FORCE_LINK");
@@ -1893,7 +1899,8 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
18931899

18941900
ProgramPtr BuiltProgram =
18951901
build(std::move(ProgramManaged), ContextImpl, CompileOpts, LinkOpts,
1896-
getRawSyclObjImpl(Devs[0])->getHandleRef(), DeviceLibReqMask);
1902+
getRawSyclObjImpl(Devs[0])->getHandleRef(),
1903+
ContextImpl->getCachedLibPrograms(), DeviceLibReqMask);
18971904

18981905
emitBuiltProgramInfo(BuiltProgram.get(), ContextImpl);
18991906

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ class ProgramManager {
261261
ProgramPtr build(ProgramPtr Program, const ContextImplPtr Context,
262262
const std::string &CompileOptions,
263263
const std::string &LinkOptions, const RT::PiDevice &Device,
264+
std::map<std::pair<DeviceLibExt, RT::PiDevice>,
265+
RT::PiProgram> &CachedLibPrograms,
264266
uint32_t DeviceLibReqMask);
265267
/// Provides a new kernel set id for grouping kernel names together
266268
KernelSetId getNextKernelSetId() const;

0 commit comments

Comments
 (0)