Skip to content

Commit 24fa45a

Browse files
committed
Fix sycl.cpp and use std::array to replace map for bf16 device images
Signed-off-by: jinge90 <[email protected]>
1 parent 640f679 commit 24fa45a

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,9 @@ void ProgramManager::addImages(sycl_device_binaries DeviceBinary) {
19451945
// library images will not be erased unless program manager is destroyed.
19461946
{
19471947
if (IsBfloat16DeviceLib) {
1948-
if (m_Bfloat16DeviceLibImages.count(Bfloat16DeviceLibVersion) > 0)
1948+
assert((Bfloat16DeviceLibVersion < 2) &&
1949+
"Invalid Bfloat16 Device Library Index.");
1950+
if (m_Bfloat16DeviceLibImages[Bfloat16DeviceLibVersion].get())
19491951
continue;
19501952
size_t ImgSize =
19511953
static_cast<size_t>(RawImg->BinaryEnd - RawImg->BinaryStart);
@@ -1960,8 +1962,8 @@ void ProgramManager::addImages(sycl_device_binaries DeviceBinary) {
19601962
m_ExportedSymbolImages.insert(
19611963
{ESProp->Name, DynBfloat16DeviceLibImg.get()});
19621964
}
1963-
m_Bfloat16DeviceLibImages.insert(
1964-
{Bfloat16DeviceLibVersion, std::move(DynBfloat16DeviceLibImg)});
1965+
m_Bfloat16DeviceLibImages[Bfloat16DeviceLibVersion] =
1966+
std::move(DynBfloat16DeviceLibImg);
19651967
continue;
19661968
}
19671969
}
@@ -2137,7 +2139,7 @@ void ProgramManager::removeImages(sycl_device_binaries DeviceBinary) {
21372139
continue;
21382140
const sycl_offload_entry EntriesB = RawImg->EntriesBegin;
21392141
const sycl_offload_entry EntriesE = RawImg->EntriesEnd;
2140-
if ((EntriesB == EntriesE))
2142+
if (EntriesB == EntriesE)
21412143
continue;
21422144

21432145
RTDeviceBinaryImage *Img = DevImgIt->second.get();

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <sycl/device.hpp>
2525
#include <sycl/kernel_bundle.hpp>
2626

27+
#include <array>
2728
#include <cstdint>
2829
#include <map>
2930
#include <memory>
@@ -502,12 +503,11 @@ class ProgramManager {
502503
std::map<std::vector<unsigned char>, ur_kernel_handle_t>;
503504
std::unordered_map<std::string, MaterializedEntries> m_MaterializedKernels;
504505

505-
// Holds bfloat16 device library images, the key is 0 for fallback version
506-
// and 1 for native version. These bfloat16 device library images are
507-
// provided by compiler long time ago, we expect no further update, so
508-
// keeping 1 copy should be OK.
509-
std::unordered_map<uint32_t, DynRTDeviceBinaryImageUPtr>
510-
m_Bfloat16DeviceLibImages;
506+
// Holds bfloat16 device library images, the 1st element is for fallback
507+
// version and 2nd is for native version. These bfloat16 device library
508+
// images are provided by compiler long time ago, we expect no further
509+
// update, so keeping 1 copy should be OK.
510+
std::array<DynRTDeviceBinaryImageUPtr, 2> m_Bfloat16DeviceLibImages;
511511

512512
friend class ::ProgramManagerTest;
513513
};

sycl/test-e2e/KernelCompiler/sycl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ int main() {
535535
}
536536
// Run test_device_libraries twice to verify bfloat16 device library.
537537
return test_build_and_run(q) || test_device_code_split(q) ||
538-
test_device_libraries(q) || test_device_libraries(q) ||
538+
test_device_libraries(q) || test_esimd(q) ||
539539
test_device_libraries(q) || test_unsupported_options(q) ||
540540
test_error(q) || test_no_visible_ids(q) || test_warning(q);
541541
#else

0 commit comments

Comments
 (0)