diff --git a/sycl/source/detail/kernel_bundle_impl.hpp b/sycl/source/detail/kernel_bundle_impl.hpp index a8d0bf13f287d..78869cb38032c 100644 --- a/sycl/source/detail/kernel_bundle_impl.hpp +++ b/sycl/source/detail/kernel_bundle_impl.hpp @@ -353,16 +353,16 @@ class kernel_bundle_impl { kernel_bundle_impl(const context &Context, syclex::source_language Lang, const std::string &Src, include_pairs_t IncludePairsVec) : MContext(Context), MDevices(Context.get_devices()), - MState(bundle_state::ext_oneapi_source), Language(Lang), Source(Src), - IncludePairs(IncludePairsVec) {} + MState(bundle_state::ext_oneapi_source), MLanguage(Lang), MSource(Src), + MIncludePairs(IncludePairsVec) {} // oneapi_ext_kernel_compiler // construct from source bytes kernel_bundle_impl(const context &Context, syclex::source_language Lang, const std::vector &Bytes) : MContext(Context), MDevices(Context.get_devices()), - MState(bundle_state::ext_oneapi_source), Language(Lang), Source(Bytes) { - } + MState(bundle_state::ext_oneapi_source), MLanguage(Lang), + MSource(Bytes) {} // oneapi_ext_kernel_compiler // interop constructor @@ -372,8 +372,8 @@ class kernel_bundle_impl { syclex::source_language Lang) : kernel_bundle_impl(Ctx, Devs, DevImage) { MState = bundle_state::executable; - KernelNames = KNames; - Language = Lang; + MKernelNames = KNames; + MLanguage = Lang; } // oneapi_ext_kernel_compiler @@ -382,7 +382,8 @@ class kernel_bundle_impl { const std::vector &KernelIDs, std::vector KNames, std::string Pfx, syclex::source_language Lang) - : kernel_bundle_impl(Ctx, Devs, KernelIDs, bundle_state::executable) { + : kernel_bundle_impl(std::move(Ctx), std::move(Devs), KernelIDs, + bundle_state::executable) { assert(Lang == syclex::source_language::sycl_jit); // Mark this bundle explicitly as "interop" to ensure that its kernels are // enqueued with the info from the kernel object passed by the application, @@ -390,9 +391,9 @@ class kernel_bundle_impl { // loaded via the program manager have `kernel_id`s, they can't be looked up // from the (unprefixed) kernel name. MIsInterop = true; - KernelNames = KNames; - Prefix = Pfx; - Language = Lang; + MKernelNames = std::move(KNames); + MPrefix = std::move(Pfx); + MLanguage = Lang; } std::string trimXsFlags(std::string &str) { @@ -493,13 +494,14 @@ class kernel_bundle_impl { DeviceVec.push_back(Dev); } - if (Language == syclex::source_language::sycl_jit) { + if (MLanguage == syclex::source_language::sycl_jit) { // Build device images via the program manager. // TODO: Support persistent caching. - const std::string &SourceStr = std::get(this->Source); + const std::string &SourceStr = std::get(MSource); auto [Binaries, CompilationID] = syclex::detail::SYCL_JIT_to_SPIRV( - SourceStr, IncludePairs, BuildOptions, LogPtr, RegisteredKernelNames); + SourceStr, MIncludePairs, BuildOptions, LogPtr, + RegisteredKernelNames); auto &PM = detail::ProgramManager::getInstance(); PM.addImages(Binaries); @@ -511,20 +513,20 @@ class kernel_bundle_impl { std::string Prefix = CompilationID + '$'; for (const auto &KernelID : PM.getAllSYCLKernelIDs()) { std::string_view KernelName{KernelID.get_name()}; - if (KernelName.find(Prefix) == 0) { + if (KernelName.find(MPrefix) == 0) { KernelIDs.push_back(KernelID); - KernelName.remove_prefix(Prefix.length()); + KernelName.remove_prefix(MPrefix.length()); KernelNames.emplace_back(KernelName); } } return std::make_shared( - MContext, MDevices, KernelIDs, KernelNames, Prefix, Language); + MContext, MDevices, KernelIDs, KernelNames, MPrefix, MLanguage); } ur_program_handle_t UrProgram = nullptr; // SourceStrPtr will be null when source is Spir-V bytes. - const std::string *SourceStrPtr = std::get_if(&this->Source); + const std::string *SourceStrPtr = std::get_if(&MSource); bool FetchedFromCache = false; if (PersistentDeviceCodeCache::isEnabled() && SourceStrPtr) { FetchedFromCache = extKernelCompilerFetchFromCache( @@ -533,7 +535,7 @@ class kernel_bundle_impl { if (!FetchedFromCache) { const auto spirv = [&]() -> std::vector { - if (Language == syclex::source_language::opencl) { + if (MLanguage == syclex::source_language::opencl) { // if successful, the log is empty. if failed, throws an error with // the compilation log. std::vector IPVersionVec(Devices.size()); @@ -548,17 +550,16 @@ class kernel_bundle_impl { return syclex::detail::OpenCLC_to_SPIRV(*SourceStrPtr, IPVersionVec, BuildOptions, LogPtr); } - if (Language == syclex::source_language::spirv) { - const auto &SourceBytes = - std::get>(this->Source); + if (MLanguage == syclex::source_language::spirv) { + const auto &SourceBytes = std::get>(MSource); std::vector Result(SourceBytes.size()); std::transform(SourceBytes.cbegin(), SourceBytes.cend(), Result.begin(), [](std::byte B) { return static_cast(B); }); return Result; } - if (Language == syclex::source_language::sycl) { - return syclex::detail::SYCL_to_SPIRV(*SourceStrPtr, IncludePairs, + if (MLanguage == syclex::source_language::sycl) { + return syclex::detail::SYCL_to_SPIRV(*SourceStrPtr, MIncludePairs, BuildOptions, LogPtr, RegisteredKernelNames); } @@ -623,7 +624,7 @@ class kernel_bundle_impl { } return std::make_shared(MContext, MDevices, DevImg, - KernelNames, Language); + MKernelNames, MLanguage); } std::string adjust_kernel_name(const std::string &Name, @@ -638,29 +639,29 @@ class kernel_bundle_impl { } bool ext_oneapi_has_kernel(const std::string &Name) { - auto it = std::find(KernelNames.begin(), KernelNames.end(), - adjust_kernel_name(Name, Language)); - return it != KernelNames.end(); + auto it = std::find(MKernelNames.begin(), MKernelNames.end(), + adjust_kernel_name(Name, MLanguage)); + return it != MKernelNames.end(); } kernel ext_oneapi_get_kernel(const std::string &Name, const std::shared_ptr &Self) { - if (KernelNames.empty()) + if (MKernelNames.empty()) throw sycl::exception(make_error_code(errc::invalid), "'ext_oneapi_get_kernel' is only available in " "kernel_bundles successfully built from " "kernel_bundle."); - std::string AdjustedName = adjust_kernel_name(Name, Language); + std::string AdjustedName = adjust_kernel_name(Name, MLanguage); if (!ext_oneapi_has_kernel(Name)) throw sycl::exception(make_error_code(errc::invalid), "kernel '" + AdjustedName + "' not found in kernel_bundle"); - if (Language == syclex::source_language::sycl_jit) { + if (MLanguage == syclex::source_language::sycl_jit) { auto &PM = ProgramManager::getInstance(); - auto KID = PM.getSYCLKernelID(Prefix + AdjustedName); + auto KID = PM.getSYCLKernelID(MPrefix + AdjustedName); for (const auto &DevImgWithDeps : MDeviceImages) { const auto &DevImg = DevImgWithDeps.getMain(); @@ -954,12 +955,12 @@ class kernel_bundle_impl { // ext_oneapi_kernel_compiler : Source, Languauge, KernelNames, IncludePairs // Language is for both state::source and state::executable. - syclex::source_language Language = syclex::source_language::opencl; - const std::variant> Source; + syclex::source_language MLanguage = syclex::source_language::opencl; + const std::variant> MSource; // only kernel_bundles created from source have KernelNames member. - std::vector KernelNames; - std::string Prefix; - include_pairs_t IncludePairs; + std::vector MKernelNames; + std::string MPrefix; + include_pairs_t MIncludePairs; }; } // namespace detail diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 7e2265484d759..08ee16a1a76dc 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -786,7 +786,7 @@ ur_program_handle_t ProgramManager::getBuiltURProgram( // built for the root device DeviceImplPtr RootDevImpl = DeviceImpl; while (!RootDevImpl->isRootDevice()) { - auto ParentDev = detail::getSyclObjImpl( + const auto &ParentDev = detail::getSyclObjImpl( RootDevImpl->get_info()); // Sharing is allowed within a single context only if (!ContextImpl->hasDevice(ParentDev))