@@ -2105,15 +2105,13 @@ ProgramManager::compile(const device_image_plain &DeviceImage,
2105
2105
}
2106
2106
2107
2107
std::vector<device_image_plain>
2108
- ProgramManager::link (const std::vector< device_image_plain> &DeviceImages ,
2108
+ ProgramManager::link (const device_image_plain &DeviceImage ,
2109
2109
const std::vector<device> &Devs,
2110
2110
const property_list &PropList) {
2111
2111
(void )PropList;
2112
2112
2113
2113
std::vector<pi_program> PIPrograms;
2114
- PIPrograms.reserve (DeviceImages.size ());
2115
- for (const device_image_plain &DeviceImage : DeviceImages)
2116
- PIPrograms.push_back (getSyclObjImpl (DeviceImage)->get_program_ref ());
2114
+ PIPrograms.push_back (getSyclObjImpl (DeviceImage)->get_program_ref ());
2117
2115
2118
2116
std::vector<pi_device> PIDevices;
2119
2117
PIDevices.reserve (Devs.size ());
@@ -2123,14 +2121,12 @@ ProgramManager::link(const std::vector<device_image_plain> &DeviceImages,
2123
2121
std::string LinkOptionsStr;
2124
2122
applyLinkOptionsFromEnvironment (LinkOptionsStr);
2125
2123
if (LinkOptionsStr.empty ()) {
2126
- for (const device_image_plain &DeviceImage : DeviceImages) {
2127
- const std::shared_ptr<device_image_impl> &InputImpl =
2128
- getSyclObjImpl (DeviceImage);
2129
- appendLinkOptionsFromImage (LinkOptionsStr,
2130
- *(InputImpl->get_bin_image_ref ()));
2131
- }
2124
+ const std::shared_ptr<device_image_impl> &InputImpl =
2125
+ getSyclObjImpl (DeviceImage);
2126
+ appendLinkOptionsFromImage (LinkOptionsStr,
2127
+ *(InputImpl->get_bin_image_ref ()));
2132
2128
}
2133
- const context &Context = getSyclObjImpl (DeviceImages[ 0 ] )->get_context ();
2129
+ const context &Context = getSyclObjImpl (DeviceImage )->get_context ();
2134
2130
const ContextImplPtr ContextImpl = getSyclObjImpl (Context);
2135
2131
const detail::plugin &Plugin = ContextImpl->getPlugin ();
2136
2132
@@ -2152,55 +2148,53 @@ ProgramManager::link(const std::vector<device_image_plain> &DeviceImages,
2152
2148
std::shared_ptr<std::vector<kernel_id>> KernelIDs{new std::vector<kernel_id>};
2153
2149
std::vector<unsigned char > NewSpecConstBlob;
2154
2150
device_image_impl::SpecConstMapT NewSpecConstMap;
2155
- for (const device_image_plain &DeviceImage : DeviceImages) {
2156
- std::shared_ptr<device_image_impl> DeviceImageImpl =
2157
- getSyclObjImpl (DeviceImage);
2158
2151
2159
- // Duplicates are not expected here, otherwise piProgramLink should fail
2160
- KernelIDs->insert (KernelIDs->end (),
2161
- DeviceImageImpl->get_kernel_ids_ptr ()->begin (),
2162
- DeviceImageImpl->get_kernel_ids_ptr ()->end ());
2152
+ std::shared_ptr<device_image_impl> DeviceImageImpl =
2153
+ getSyclObjImpl (DeviceImage);
2163
2154
2164
- // To be able to answer queries about specialziation constants, the new
2165
- // device image should have the specialization constants from all the linked
2166
- // images.
2167
- {
2168
- const std::lock_guard<std::mutex> SpecConstLock (
2169
- DeviceImageImpl->get_spec_const_data_lock ());
2170
-
2171
- // Copy all map entries to the new map. Since the blob will be copied to
2172
- // the end of the new blob we need to move the blob offset of each entry.
2173
- for (const auto &SpecConstIt :
2174
- DeviceImageImpl->get_spec_const_data_ref ()) {
2175
- std::vector<device_image_impl::SpecConstDescT> &NewDescEntries =
2176
- NewSpecConstMap[SpecConstIt.first ];
2177
- assert (NewDescEntries.empty () &&
2178
- " Specialization constant already exists in the map." );
2179
- NewDescEntries.reserve (SpecConstIt.second .size ());
2180
- for (const device_image_impl::SpecConstDescT &SpecConstDesc :
2181
- SpecConstIt.second ) {
2182
- device_image_impl::SpecConstDescT NewSpecConstDesc = SpecConstDesc;
2183
- NewSpecConstDesc.BlobOffset += NewSpecConstBlob.size ();
2184
- NewDescEntries.push_back (std::move (NewSpecConstDesc));
2185
- }
2186
- }
2155
+ // Duplicates are not expected here, otherwise piProgramLink should fail
2156
+ KernelIDs->insert (KernelIDs->end (),
2157
+ DeviceImageImpl->get_kernel_ids_ptr ()->begin (),
2158
+ DeviceImageImpl->get_kernel_ids_ptr ()->end ());
2187
2159
2188
- // Copy the blob from the device image into the new blob. This moves the
2189
- // offsets of the following blobs.
2190
- NewSpecConstBlob.insert (
2191
- NewSpecConstBlob.end (),
2192
- DeviceImageImpl->get_spec_const_blob_ref ().begin (),
2193
- DeviceImageImpl->get_spec_const_blob_ref ().end ());
2160
+ // To be able to answer queries about specialziation constants, the new
2161
+ // device image should have the specialization constants from all the linked
2162
+ // images.
2163
+ {
2164
+ const std::lock_guard<std::mutex> SpecConstLock (
2165
+ DeviceImageImpl->get_spec_const_data_lock ());
2166
+
2167
+ // Copy all map entries to the new map. Since the blob will be copied to
2168
+ // the end of the new blob we need to move the blob offset of each entry.
2169
+ for (const auto &SpecConstIt : DeviceImageImpl->get_spec_const_data_ref ()) {
2170
+ std::vector<device_image_impl::SpecConstDescT> &NewDescEntries =
2171
+ NewSpecConstMap[SpecConstIt.first ];
2172
+ assert (NewDescEntries.empty () &&
2173
+ " Specialization constant already exists in the map." );
2174
+ NewDescEntries.reserve (SpecConstIt.second .size ());
2175
+ for (const device_image_impl::SpecConstDescT &SpecConstDesc :
2176
+ SpecConstIt.second ) {
2177
+ device_image_impl::SpecConstDescT NewSpecConstDesc = SpecConstDesc;
2178
+ NewSpecConstDesc.BlobOffset += NewSpecConstBlob.size ();
2179
+ NewDescEntries.push_back (std::move (NewSpecConstDesc));
2180
+ }
2194
2181
}
2182
+
2183
+ // Copy the blob from the device image into the new blob. This moves the
2184
+ // offsets of the following blobs.
2185
+ NewSpecConstBlob.insert (NewSpecConstBlob.end (),
2186
+ DeviceImageImpl->get_spec_const_blob_ref ().begin (),
2187
+ DeviceImageImpl->get_spec_const_blob_ref ().end ());
2195
2188
}
2189
+
2196
2190
// device_image_impl expects kernel ids to be sorted for fast search
2197
2191
std::sort (KernelIDs->begin (), KernelIDs->end (), LessByHash<kernel_id>{});
2198
2192
2193
+ auto BinImg = getSyclObjImpl (DeviceImage)->get_bin_image_ref ();
2199
2194
DeviceImageImplPtr ExecutableImpl =
2200
2195
std::make_shared<detail::device_image_impl>(
2201
- /* BinImage=*/ nullptr , Context, Devs, bundle_state::executable,
2202
- std::move (KernelIDs), LinkedProg, std::move (NewSpecConstMap),
2203
- std::move (NewSpecConstBlob));
2196
+ BinImg, Context, Devs, bundle_state::executable, std::move (KernelIDs),
2197
+ LinkedProg, std::move (NewSpecConstMap), std::move (NewSpecConstBlob));
2204
2198
2205
2199
// TODO: Make multiple sets of device images organized by devices they are
2206
2200
// compiled for.
0 commit comments