Skip to content

Commit 98ab6d7

Browse files
[SYCL][L0] initialize properties struct .stype and .pNext (#4056)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 06e4ebc commit 98ab6d7

File tree

2 files changed

+70
-23
lines changed

2 files changed

+70
-23
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <thread>
2525
#include <utility>
2626

27-
#include <level_zero/zes_api.h>
2827
#include <level_zero/zet_api.h>
2928

3029
#include "usm_allocator.hpp"
@@ -524,7 +523,7 @@ pi_result _pi_device::initialize() {
524523
if (numQueueGroups == 0) {
525524
return PI_ERROR_UNKNOWN;
526525
}
527-
std::vector<ze_command_queue_group_properties_t> QueueProperties(
526+
std::vector<ZeStruct<ze_command_queue_group_properties_t>> QueueProperties(
528527
numQueueGroups);
529528
ZE_CALL(zeDeviceGetCommandQueueGroupProperties,
530529
(ZeDevice, &numQueueGroups, QueueProperties.data()));
@@ -1169,7 +1168,7 @@ static bool setEnvVar(const char *name, const char *value) {
11691168

11701169
pi_result _pi_platform::initialize() {
11711170
// Cache driver properties
1172-
ze_driver_properties_t ZeDriverProperties;
1171+
ZeStruct<ze_driver_properties_t> ZeDriverProperties;
11731172
ZE_CALL(zeDriverGetProperties, (ZeDriver, &ZeDriverProperties));
11741173
uint32_t DriverVersion = ZeDriverProperties.driverVersion;
11751174
// Intel Level-Zero GPU driver stores version as:
@@ -1611,16 +1610,16 @@ pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName,
16111610
ZE_CALL(zeDeviceGetMemoryProperties,
16121611
(ZeDevice, &ZeAvailMemCount, ZeDeviceMemoryProperties.data()));
16131612

1614-
ze_device_image_properties_t ZeDeviceImageProperties = {};
1613+
ZeStruct<ze_device_image_properties_t> ZeDeviceImageProperties;
16151614
ZE_CALL(zeDeviceGetImageProperties, (ZeDevice, &ZeDeviceImageProperties));
16161615

1617-
ze_device_module_properties_t ZeDeviceModuleProperties = {};
1616+
ZeStruct<ze_device_module_properties_t> ZeDeviceModuleProperties;
16181617
ZE_CALL(zeDeviceGetModuleProperties, (ZeDevice, &ZeDeviceModuleProperties));
16191618

16201619
// TODO[1.0]: there can be multiple cache properites now, adjust.
16211620
// For now remember the first one, if any.
16221621
uint32_t Count = 0;
1623-
ze_device_cache_properties_t ZeDeviceCacheProperties = {};
1622+
ZeStruct<ze_device_cache_properties_t> ZeDeviceCacheProperties;
16241623
ZE_CALL(zeDeviceGetCacheProperties, (ZeDevice, &Count, nullptr));
16251624
if (Count > 0) {
16261625
Count = 1;
@@ -2049,7 +2048,7 @@ pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName,
20492048
zePrint("Set SYCL_ENABLE_PCI=1 to obtain PCI data.\n");
20502049
return PI_INVALID_VALUE;
20512050
}
2052-
zes_pci_properties_t ZeDevicePciProperties = {};
2051+
ZesStruct<zes_pci_properties_t> ZeDevicePciProperties;
20532052
ZE_CALL(zesDevicePciGetProperties, (ZeDevice, &ZeDevicePciProperties));
20542053
std::stringstream ss;
20552054
ss << ZeDevicePciProperties.address.domain << ":"
@@ -3357,7 +3356,7 @@ static pi_result compileOrBuild(pi_program Program, pi_uint32 NumDevices,
33573356
// Check if this module imports any symbols, which we need to know if we
33583357
// end up linking this module later. See comments in piProgramLink() for
33593358
// details.
3360-
ze_module_properties_t ZeModuleProps;
3359+
ZeStruct<ze_module_properties_t> ZeModuleProps;
33613360
ZE_CALL(zeModuleGetPropertiesMock, (ZeModule, &ZeModuleProps));
33623361
Program->HasImports = (ZeModuleProps.flags & ZE_MODULE_PROPERTY_FLAG_IMPORTS);
33633362

@@ -3708,7 +3707,7 @@ pi_result piKernelGetInfo(pi_kernel Kernel, pi_kernel_info ParamName,
37083707
size_t *ParamValueSizeRet) {
37093708
PI_ASSERT(Kernel, PI_INVALID_KERNEL);
37103709

3711-
ze_kernel_properties_t ZeKernelProperties = {};
3710+
ZeStruct<ze_kernel_properties_t> ZeKernelProperties;
37123711
ZE_CALL(zeKernelGetProperties, (Kernel->ZeKernel, &ZeKernelProperties));
37133712

37143713
ReturnHelper ReturnValue(ParamValueSize, ParamValue, ParamValueSizeRet);
@@ -3767,10 +3766,10 @@ pi_result piKernelGetGroupInfo(pi_kernel Kernel, pi_device Device,
37673766
PI_ASSERT(Device, PI_INVALID_DEVICE);
37683767

37693768
ze_device_handle_t ZeDevice = Device->ZeDevice;
3770-
ze_device_compute_properties_t ZeDeviceComputeProperties = {};
3769+
ZeStruct<ze_device_compute_properties_t> ZeDeviceComputeProperties;
37713770
ZE_CALL(zeDeviceGetComputeProperties, (ZeDevice, &ZeDeviceComputeProperties));
37723771

3773-
ze_kernel_properties_t ZeKernelProperties = {};
3772+
ZeStruct<ze_kernel_properties_t> ZeKernelProperties;
37743773
ZE_CALL(zeKernelGetProperties, (Kernel->ZeKernel, &ZeKernelProperties));
37753774

37763775
ReturnHelper ReturnValue(ParamValueSize, ParamValue, ParamValueSizeRet);
@@ -3801,7 +3800,7 @@ pi_result piKernelGetGroupInfo(pi_kernel Kernel, pi_device Device,
38013800
case PI_KERNEL_GROUP_INFO_LOCAL_MEM_SIZE:
38023801
return ReturnValue(pi_uint32{ZeKernelProperties.localMemSize});
38033802
case PI_KERNEL_GROUP_INFO_PREFERRED_WORK_GROUP_SIZE_MULTIPLE: {
3804-
ze_device_properties_t ZeDeviceProperties = {};
3803+
ZeStruct<ze_device_properties_t> ZeDeviceProperties;
38053804
ZE_CALL(zeDeviceGetProperties, (ZeDevice, &ZeDeviceProperties));
38063805

38073806
return ReturnValue(size_t{ZeDeviceProperties.physicalEUSimdWidth});
@@ -3825,7 +3824,7 @@ pi_result piKernelGetSubGroupInfo(pi_kernel Kernel, pi_device Device,
38253824
(void)InputValueSize;
38263825
(void)InputValue;
38273826

3828-
ze_kernel_properties_t ZeKernelProperties;
3827+
ZeStruct<ze_kernel_properties_t> ZeKernelProperties;
38293828
ZE_CALL(zeKernelGetProperties, (Kernel->ZeKernel, &ZeKernelProperties));
38303829

38313830
ReturnHelper ReturnValue(ParamValueSize, ParamValue, ParamValueSizeRet);
@@ -6052,7 +6051,7 @@ static pi_result USMFreeHelper(pi_context Context, void *Ptr) {
60526051

60536052
// Query the device of the allocation to determine the right allocator context
60546053
ze_device_handle_t ZeDeviceHandle;
6055-
ze_memory_allocation_properties_t ZeMemoryAllocationProperties = {};
6054+
ZeStruct<ze_memory_allocation_properties_t> ZeMemoryAllocationProperties;
60566055

60576056
// Query memory type of the pointer we're freeing to determine the correct
60586057
// way to do it(directly or via an allocator)
@@ -6166,7 +6165,7 @@ pi_result piextUSMEnqueueMemset(pi_queue Queue, void *Ptr, pi_int32 Value,
61666165
// Helper function to check if a pointer is a device pointer.
61676166
static bool IsDevicePointer(pi_context Context, const void *Ptr) {
61686167
ze_device_handle_t ZeDeviceHandle;
6169-
ze_memory_allocation_properties_t ZeMemoryAllocationProperties = {};
6168+
ZeStruct<ze_memory_allocation_properties_t> ZeMemoryAllocationProperties;
61706169

61716170
// Query memory type of the pointer
61726171
ZE_CALL(zeMemGetAllocProperties,
@@ -6346,7 +6345,7 @@ pi_result piextUSMGetMemAllocInfo(pi_context Context, const void *Ptr,
63466345
PI_ASSERT(Context, PI_INVALID_CONTEXT);
63476346

63486347
ze_device_handle_t ZeDeviceHandle;
6349-
ze_memory_allocation_properties_t ZeMemoryAllocationProperties = {};
6348+
ZeStruct<ze_memory_allocation_properties_t> ZeMemoryAllocationProperties;
63506349

63516350
ZE_CALL(zeMemGetAllocProperties,
63526351
(Context->ZeContext, Ptr, &ZeMemoryAllocationProperties,

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <vector>
3333

3434
#include <level_zero/ze_api.h>
35+
#include <level_zero/zes_api.h>
3536

3637
#include "usm_allocator.hpp"
3738

@@ -58,6 +59,7 @@ template <> uint32_t pi_cast(uint64_t Value) {
5859
// Returns the ze_structure_type_t to use in .stype of a structured descriptor.
5960
// Intentionally not defined; will give an error if no proper specialization
6061
template <class T> ze_structure_type_t getZeStructureType();
62+
template <class T> zes_structure_type_t getZesStructureType();
6163

6264
template <> ze_structure_type_t getZeStructureType<ze_event_pool_desc_t>() {
6365
return ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;
@@ -101,15 +103,61 @@ template <> ze_structure_type_t getZeStructureType<ze_event_desc_t>() {
101103
template <> ze_structure_type_t getZeStructureType<ze_sampler_desc_t>() {
102104
return ZE_STRUCTURE_TYPE_SAMPLER_DESC;
103105
}
106+
template <> ze_structure_type_t getZeStructureType<ze_driver_properties_t>() {
107+
return ZE_STRUCTURE_TYPE_DRIVER_PROPERTIES;
108+
}
109+
template <> ze_structure_type_t getZeStructureType<ze_device_properties_t>() {
110+
return ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
111+
}
112+
template <>
113+
ze_structure_type_t getZeStructureType<ze_device_compute_properties_t>() {
114+
return ZE_STRUCTURE_TYPE_DEVICE_COMPUTE_PROPERTIES;
115+
}
116+
template <>
117+
ze_structure_type_t getZeStructureType<ze_command_queue_group_properties_t>() {
118+
return ZE_STRUCTURE_TYPE_COMMAND_QUEUE_GROUP_PROPERTIES;
119+
}
120+
template <>
121+
ze_structure_type_t getZeStructureType<ze_device_image_properties_t>() {
122+
return ZE_STRUCTURE_TYPE_DEVICE_IMAGE_PROPERTIES;
123+
}
124+
template <>
125+
ze_structure_type_t getZeStructureType<ze_device_module_properties_t>() {
126+
return ZE_STRUCTURE_TYPE_DEVICE_MODULE_PROPERTIES;
127+
}
128+
template <>
129+
ze_structure_type_t getZeStructureType<ze_device_cache_properties_t>() {
130+
return ZE_STRUCTURE_TYPE_DEVICE_CACHE_PROPERTIES;
131+
}
132+
template <> ze_structure_type_t getZeStructureType<ze_module_properties_t>() {
133+
return ZE_STRUCTURE_TYPE_MODULE_PROPERTIES;
134+
}
135+
template <> ze_structure_type_t getZeStructureType<ze_kernel_properties_t>() {
136+
return ZE_STRUCTURE_TYPE_KERNEL_PROPERTIES;
137+
}
138+
template <>
139+
ze_structure_type_t getZeStructureType<ze_memory_allocation_properties_t>() {
140+
return ZE_STRUCTURE_TYPE_MEMORY_ALLOCATION_PROPERTIES;
141+
}
104142

105-
// The helper struct to properly default initialize Level-Zero descriptor
106-
// structure.
143+
template <> zes_structure_type_t getZesStructureType<zes_pci_properties_t>() {
144+
return ZES_STRUCTURE_TYPE_PCI_PROPERTIES;
145+
}
146+
147+
// The helpers to properly default initialize Level-Zero descriptor and
148+
// properties structures.
107149
template <class T> struct ZeStruct : public T {
108-
ZeStruct() {
150+
ZeStruct() : T{} { // zero initializes base struct
109151
this->stype = getZeStructureType<T>();
110152
this->pNext = nullptr;
111153
}
112154
};
155+
template <class T> struct ZesStruct : public T {
156+
ZesStruct() : T{} { // zero initializes base struct
157+
this->stype = getZesStructureType<T>();
158+
this->pNext = nullptr;
159+
}
160+
};
113161

114162
// Base class to store common data
115163
struct _pi_object {
@@ -244,8 +292,8 @@ struct _pi_device : _pi_object {
244292
int32_t ZeCopyQueueGroupIndex;
245293

246294
// Cache the properties of the compute/copy queue groups.
247-
ze_command_queue_group_properties_t ZeComputeQueueGroupProperties = {};
248-
ze_command_queue_group_properties_t ZeCopyQueueGroupProperties = {};
295+
ZeStruct<ze_command_queue_group_properties_t> ZeComputeQueueGroupProperties;
296+
ZeStruct<ze_command_queue_group_properties_t> ZeCopyQueueGroupProperties;
249297

250298
// This returns "true" if a copy engine is available for use.
251299
bool hasCopyEngine() const { return ZeCopyQueueGroupIndex >= 0; }
@@ -270,8 +318,8 @@ struct _pi_device : _pi_object {
270318
bool isSubDevice() { return RootDevice != nullptr; }
271319

272320
// Cache of the immutable device properties.
273-
ze_device_properties_t ZeDeviceProperties;
274-
ze_device_compute_properties_t ZeDeviceComputeProperties;
321+
ZeStruct<ze_device_properties_t> ZeDeviceProperties;
322+
ZeStruct<ze_device_compute_properties_t> ZeDeviceComputeProperties;
275323
};
276324

277325
struct _pi_context : _pi_object {

0 commit comments

Comments
 (0)