@@ -719,53 +719,38 @@ Error olGetSymbol_impl(ol_program_handle_t Program, const char *Name,
719719
720720 std::lock_guard<std::mutex> Lock{Program->SymbolListMutex };
721721
722- // If it already exists, return an existing handle
723- auto CheckCache = [&](StringMap<std::unique_ptr<ol_symbol_impl_t >> &Map)
724- -> std::optional<ol_symbol_handle_t > {
725- if (Map.contains (Name))
726- return Map[Name].get ();
727- return std::nullopt ;
728- };
729-
730722 switch (Kind) {
731723 case OL_SYMBOL_KIND_KERNEL: {
732- if (auto Cache = CheckCache (Program->KernelSymbols )) {
733- *Symbol = *Cache;
734- return Plugin::success ();
735- }
724+ auto &Kernel = Program->KernelSymbols [Name];
725+ if (!Kernel) {
726+ auto KernelImpl = Device.constructKernel (Name);
727+ if (!KernelImpl)
728+ return KernelImpl.takeError ();
736729
737- auto KernelImpl = Device.constructKernel (Name);
738- if (!KernelImpl)
739- return KernelImpl.takeError ();
730+ if (auto Err = KernelImpl->init (Device, *Program->Image ))
731+ return Err;
740732
741- if (auto Err = KernelImpl->init (Device, *Program->Image ))
742- return Err;
733+ Kernel = std::make_unique<ol_symbol_impl_t >(KernelImpl->getName (),
734+ &*KernelImpl);
735+ }
743736
744- *Symbol = Program->KernelSymbols
745- .insert ({Name, std::make_unique<ol_symbol_impl_t >(
746- KernelImpl->getName (), &*KernelImpl)})
747- .first ->getValue ()
748- .get ();
737+ *Symbol = Kernel.get ();
749738 return Error::success ();
750739 }
751740 case OL_SYMBOL_KIND_GLOBAL_VARIABLE: {
752- if (auto Cache = CheckCache (Program->GlobalSymbols )) {
753- *Symbol = *Cache;
754- return Plugin::success ();
741+ auto &Global = Program->KernelSymbols [Name];
742+ if (!Global) {
743+ GlobalTy GlobalObj{Name};
744+ if (auto Res =
745+ Device.Plugin .getGlobalHandler ().getGlobalMetadataFromDevice (
746+ Device, *Program->Image , GlobalObj))
747+ return Res;
748+
749+ Global = std::make_unique<ol_symbol_impl_t >(GlobalObj.getName ().c_str (),
750+ std::move (GlobalObj));
755751 }
756752
757- GlobalTy GlobalObj{Name};
758- if (auto Res = Device.Plugin .getGlobalHandler ().getGlobalMetadataFromDevice (
759- Device, *Program->Image , GlobalObj))
760- return Res;
761-
762- *Symbol = Program->GlobalSymbols
763- .insert ({Name, std::make_unique<ol_symbol_impl_t >(
764- GlobalObj.getName ().c_str (),
765- std::move (GlobalObj))})
766- .first ->getValue ()
767- .get ();
768-
753+ *Symbol = Global.get ();
769754 return Error::success ();
770755 }
771756 default :
0 commit comments