Skip to content

Commit 84c43fa

Browse files
committed
Merge remote-tracking branch 'origin/sycl-rel-6_3' into private/asachkov/cherry-pick-ur-patches
2 parents 42d06a9 + bacad63 commit 84c43fa

File tree

13 files changed

+122
-29
lines changed

13 files changed

+122
-29
lines changed

sycl/include/sycl/ext/intel/experimental/usm_properties.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,10 @@ class buffer_location
3939
uint64_t MLocation;
4040
};
4141

42+
// If new properties are added here, update `verifyUSMAllocatorProperties` to
43+
// include them!
44+
4245
} // namespace intel::experimental::property::usm
4346
} // namespace ext
44-
45-
template <>
46-
struct is_property<ext::oneapi::property::usm::device_read_only>
47-
: std::true_type {};
48-
49-
template <>
50-
struct is_property<ext::intel::experimental::property::usm::buffer_location>
51-
: std::true_type {};
52-
5347
} // namespace _V1
5448
} // namespace sycl

sycl/source/detail/device_global_map.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@ class DeviceGlobalMap {
2727
DeviceGlobalMap(bool OwnerControlledCleanup)
2828
: MOwnerControlledCleanup{OwnerControlledCleanup} {}
2929

30+
DeviceGlobalMap(const DeviceGlobalMap &) = delete;
31+
DeviceGlobalMap &operator=(const DeviceGlobalMap &) = delete;
32+
3033
~DeviceGlobalMap() {
31-
if (!MOwnerControlledCleanup)
32-
for (auto &DeviceGlobalIt : MDeviceGlobals)
33-
DeviceGlobalIt.second->cleanup();
34+
try {
35+
if (!MOwnerControlledCleanup)
36+
for (auto &DeviceGlobalIt : MDeviceGlobals)
37+
DeviceGlobalIt.second->cleanup();
38+
} catch (std::exception &e) {
39+
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~DeviceGlobalMap", e);
40+
}
3441
}
3542

3643
void initializeEntries(const RTDeviceBinaryImage *Img) {

sycl/source/detail/device_global_map_entry.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ struct DeviceGlobalMapEntry {
6767
// Constructor for only initializing ID and pointer. The other members will
6868
// be initialized later.
6969
DeviceGlobalMapEntry(std::string UniqueId, const void *DeviceGlobalPtr)
70-
: MUniqueId(UniqueId), MDeviceGlobalPtr(DeviceGlobalPtr) {}
70+
: MUniqueId(std::move(UniqueId)), MDeviceGlobalPtr(DeviceGlobalPtr) {}
7171

7272
// Constructor for only initializing ID, type size, and device image scope
7373
// flag. The pointer to the device global will be initialized later.
7474
DeviceGlobalMapEntry(std::string UniqueId, const RTDeviceBinaryImage *Img,
7575
std::uint32_t DeviceGlobalTSize,
7676
bool IsDeviceImageScopeDecorated)
77-
: MUniqueId(UniqueId), MImages{Img},
77+
: MUniqueId(std::move(UniqueId)), MImages{Img},
7878
MImageIdentifiers{reinterpret_cast<uintptr_t>(Img)},
7979
MDeviceGlobalTSize(DeviceGlobalTSize),
8080
MIsDeviceImageScopeDecorated(IsDeviceImageScopeDecorated) {}

sycl/source/detail/device_impl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ std::vector<device> device_impl::create_sub_devices(
258258
affinityDomainToString(AffinityDomain) + ".");
259259
}
260260

261-
ur_device_partition_property_t Prop;
261+
ur_device_partition_property_t Prop{};
262262
Prop.type = UR_DEVICE_PARTITION_BY_AFFINITY_DOMAIN;
263263
Prop.value.affinity_domain =
264264
static_cast<ur_device_affinity_domain_flags_t>(AffinityDomain);
@@ -285,9 +285,8 @@ std::vector<device> device_impl::create_sub_devices() const {
285285
"sycl::info::partition_property::ext_intel_partition_by_cslice.");
286286
}
287287

288-
ur_device_partition_property_t Prop;
288+
ur_device_partition_property_t Prop{};
289289
Prop.type = UR_DEVICE_PARTITION_BY_CSLICE;
290-
291290
ur_device_partition_properties_t Properties{};
292291
Properties.stype = UR_STRUCTURE_TYPE_DEVICE_PARTITION_PROPERTIES;
293292
Properties.pProperties = &Prop;

sycl/source/detail/property_set_io.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static IntT stringViewToInt(const std::string_view &SV) {
3030
if (SV.empty())
3131
return Result;
3232

33-
bool Negate = std::is_signed_v<IntT> && SV[0] == '-';
33+
const bool Negate = std::is_signed_v<IntT> && SV[0] == '-';
3434

3535
for (size_t I = static_cast<size_t>(Negate); I < SV.size(); ++I) {
3636
const char CurrentC = SV[I];

sycl/source/detail/usm/usm_impl.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,22 @@ void release_from_device_copy(const void *Ptr, const queue &Queue) {
644644
} // namespace ext::oneapi::experimental
645645

646646
__SYCL_EXPORT void verifyUSMAllocatorProperties(const property_list &PropList) {
647-
auto NoAllowedPropertiesCheck = [](int) { return false; };
648-
detail::PropertyValidator::checkPropsAndThrow(
649-
PropList, NoAllowedPropertiesCheck, NoAllowedPropertiesCheck);
647+
auto DataLessCheck = [](int Kind) {
648+
switch (Kind) {
649+
case detail::DeviceReadOnly:
650+
return true;
651+
}
652+
return false;
653+
};
654+
auto WithDataCheck = [](int Kind) {
655+
switch (Kind) {
656+
case detail::PropWithDataKind::AccPropBufferLocation:
657+
return true;
658+
}
659+
return false;
660+
};
661+
detail::PropertyValidator::checkPropsAndThrow(PropList, DataLessCheck,
662+
WithDataCheck);
650663
}
651664

652665
} // namespace _V1
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// REQUIRES: arch-intel_gpu_pvc, level_zero
2+
// UNSUPPORTED: gpu-intel-pvc-1T
3+
// UNSUPPORTED-TRACKER: GSD-9121
4+
5+
// DEFINE: %{setup_env} = env ZE_FLAT_DEVICE_HIERARCHY=COMPOSITE ZE_AFFINITY_MASK=0 ZEX_NUMBER_OF_CCS=0:4
6+
// RUN: %{build} -o %t.out
7+
// RUN: %{setup_env} %{run} %t.out
8+
9+
// Check that context can be created successfully when sub-sub-devices are
10+
// exposed.
11+
#include <iostream>
12+
#include <sycl/detail/core.hpp>
13+
#include <vector>
14+
15+
using namespace sycl;
16+
17+
int main() {
18+
std::cout << "[info] start context_create_sub_sub_device test" << std::endl;
19+
device d;
20+
std::vector<device> subsubdevices;
21+
22+
auto subdevices = d.create_sub_devices<
23+
info::partition_property::partition_by_affinity_domain>(
24+
info::partition_affinity_domain::next_partitionable);
25+
std::cout << "[info] sub device size = " << subdevices.size() << std::endl;
26+
27+
for (auto &subdev : subdevices) {
28+
subsubdevices = subdev.create_sub_devices<
29+
info::partition_property::ext_intel_partition_by_cslice>();
30+
31+
std::cout << "[info] sub-sub device size = " << subsubdevices.size()
32+
<< std::endl;
33+
}
34+
35+
// Create contexts
36+
context ctx1(d);
37+
context ctx2(subdevices);
38+
context ctx3(subsubdevices);
39+
40+
std::cout << "[info] contexts created successfully" << std::endl;
41+
return 0;
42+
}

sycl/test-e2e/Adapters/level_zero/usm_device_read_only.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <sycl/ext/oneapi/experimental/annotated_usm/alloc_shared.hpp>
1010

11+
#include <sycl/usm/usm_allocator.hpp>
12+
1113
using namespace std;
1214
using namespace sycl;
1315

@@ -24,7 +26,22 @@ int main(int argc, char *argv[]) {
2426
// CHECK: ---> urUSMSharedAlloc
2527
// CHECK-NOT: zeMemAllocShared
2628

27-
free(ptr1, Q);
29+
sycl::usm_allocator<int, sycl::usm::alloc::shared> allocator_no_prop{Q};
30+
31+
auto ptr3 = allocator_no_prop.allocate(1);
32+
// CHECK: ---> urUSMSharedAlloc
33+
// CHECK: zeMemAllocShared
34+
35+
sycl::usm_allocator<int, sycl::usm::alloc::shared> allocator_prop{
36+
Q, {sycl::ext::oneapi::property::usm::device_read_only{}}};
37+
38+
auto ptr4 = allocator_prop.allocate(1);
39+
// CHECK: ---> urUSMSharedAlloc
40+
// CHECK-NOT: zeMemAllocShared
41+
42+
allocator_prop.deallocate(ptr4, 1);
43+
allocator_no_prop.deallocate(ptr3, 1);
2844
free(ptr2, Q);
45+
free(ptr1, Q);
2946
return 0;
3047
}

sycl/test-e2e/USM/properties.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %{run} %t.out
3+
4+
#include <sycl/ext/intel/experimental/usm_properties.hpp>
5+
#include <sycl/usm/usm_allocator.hpp>
6+
7+
int main() {
8+
sycl::queue q;
9+
10+
// Ensure properties are supported when constructing the allocator:
11+
sycl::usm_allocator<int, sycl::usm::alloc::shared> allocator{
12+
q,
13+
{sycl::ext::oneapi::property::usm::device_read_only{},
14+
sycl::ext::intel::experimental::property::usm::buffer_location{1}}};
15+
}

unified-runtime/source/adapters/level_zero/device.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,20 @@ struct ur_device_handle_t_ : ur_object {
248248
ur::RefCount RefCount;
249249
};
250250

251-
inline std::vector<ur_device_handle_t>
252-
CollectDevicesAndSubDevices(const std::vector<ur_device_handle_t> &Devices) {
251+
// Collects a flat vector of unique devices for USM memory pool creation.
252+
// Traverses the input devices and their sub-devices, ensuring each Level Zero
253+
// device handle appears only once in the result.
254+
inline std::vector<ur_device_handle_t> CollectDevicesForUsmPoolCreation(
255+
const std::vector<ur_device_handle_t> &Devices) {
253256
std::vector<ur_device_handle_t> DevicesAndSubDevices;
254-
std::unordered_set<ur_device_handle_t> Seen;
257+
std::unordered_set<ze_device_handle_t> Seen;
258+
255259
std::function<void(const std::vector<ur_device_handle_t> &)>
256260
CollectDevicesAndSubDevicesRec =
257261
[&](const std::vector<ur_device_handle_t> &Devices) {
258262
for (auto &Device : Devices) {
259-
// Only add device if has not been seen before.
260-
if (Seen.insert(Device).second) {
263+
// Only add device if ZeDevice has not been seen before.
264+
if (Seen.insert(Device->ZeDevice).second) {
261265
DevicesAndSubDevices.push_back(Device);
262266
CollectDevicesAndSubDevicesRec(Device->SubDevices);
263267
}

0 commit comments

Comments
 (0)