@@ -1846,6 +1846,30 @@ std::vector<device_image_plain> ProgramManager::getSYCLDeviceImages(
1846
1846
return DeviceImages;
1847
1847
}
1848
1848
1849
+ static void
1850
+ setSpecializationConstants (const std::shared_ptr<device_image_impl> &InputImpl,
1851
+ RT::PiProgram Prog, const plugin &Plugin) {
1852
+ // Set ITT annotation specialization constant if needed.
1853
+ enableITTAnnotationsIfNeeded (Prog, Plugin);
1854
+
1855
+ std::lock_guard<std::mutex> Lock{InputImpl->get_spec_const_data_lock ()};
1856
+ const std::map<std::string, std::vector<device_image_impl::SpecConstDescT>>
1857
+ &SpecConstData = InputImpl->get_spec_const_data_ref ();
1858
+ const SerializedObj &SpecConsts = InputImpl->get_spec_const_blob_ref ();
1859
+
1860
+ // Set all specialization IDs from descriptors in the input device image.
1861
+ for (const auto &[SpecConstNames, SpecConstDescs] : SpecConstData) {
1862
+ std::ignore = SpecConstNames;
1863
+ for (const device_image_impl::SpecConstDescT &SpecIDDesc : SpecConstDescs) {
1864
+ if (SpecIDDesc.IsSet ) {
1865
+ Plugin.call <PiApiKind::piextProgramSetSpecializationConstant>(
1866
+ Prog, SpecIDDesc.ID , SpecIDDesc.Size ,
1867
+ SpecConsts.data () + SpecIDDesc.BlobOffset );
1868
+ }
1869
+ }
1870
+ }
1871
+ }
1872
+
1849
1873
device_image_plain
1850
1874
ProgramManager::compile (const device_image_plain &DeviceImage,
1851
1875
const std::vector<device> &Devs,
@@ -1876,7 +1900,7 @@ ProgramManager::compile(const device_image_plain &DeviceImage,
1876
1900
InputImpl->get_context (), Devs[0 ]);
1877
1901
1878
1902
if (InputImpl->get_bin_image_ref ()->supportsSpecConstants ())
1879
- enableITTAnnotationsIfNeeded ( Prog, Plugin);
1903
+ setSpecializationConstants (InputImpl, Prog, Plugin);
1880
1904
1881
1905
DeviceImageImplPtr ObjectImpl = std::make_shared<detail::device_image_impl>(
1882
1906
InputImpl->get_bin_image_ref (), InputImpl->get_context (), Devs,
@@ -1889,8 +1913,6 @@ ProgramManager::compile(const device_image_plain &DeviceImage,
1889
1913
for (const device &Dev : Devs)
1890
1914
PIDevices.push_back (getSyclObjImpl (Dev)->getHandleRef ());
1891
1915
1892
- // TODO: Set spec constatns here.
1893
-
1894
1916
// TODO: Handle zero sized Device list.
1895
1917
std::string CompileOptions;
1896
1918
applyCompileOptionsFromEnvironment (CompileOptions);
@@ -2073,25 +2095,8 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
2073
2095
Img, Context, Devs[0 ], CompileOpts + LinkOpts, SpecConsts);
2074
2096
2075
2097
if (!DeviceCodeWasInCache &&
2076
- InputImpl->get_bin_image_ref ()->supportsSpecConstants ()) {
2077
- enableITTAnnotationsIfNeeded (NativePrg, Plugin);
2078
-
2079
- std::lock_guard<std::mutex> Lock{InputImpl->get_spec_const_data_lock ()};
2080
- const std::map<std::string,
2081
- std::vector<device_image_impl::SpecConstDescT>>
2082
- &SpecConstData = InputImpl->get_spec_const_data_ref ();
2083
-
2084
- for (const auto &DescPair : SpecConstData) {
2085
- for (const device_image_impl::SpecConstDescT &SpecIDDesc :
2086
- DescPair.second ) {
2087
- if (SpecIDDesc.IsSet ) {
2088
- Plugin.call <PiApiKind::piextProgramSetSpecializationConstant>(
2089
- NativePrg, SpecIDDesc.ID , SpecIDDesc.Size ,
2090
- SpecConsts.data () + SpecIDDesc.BlobOffset );
2091
- }
2092
- }
2093
- }
2094
- }
2098
+ InputImpl->get_bin_image_ref ()->supportsSpecConstants ())
2099
+ setSpecializationConstants (InputImpl, NativePrg, Plugin);
2095
2100
2096
2101
ProgramPtr ProgramManaged (
2097
2102
NativePrg, Plugin.getPiPlugin ().PiFunctionTable .piProgramRelease );
0 commit comments