diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index d7d30fb3faa4b..3fcbc5a0e9bc0 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -346,8 +346,7 @@ _pi_context::getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &ZePool, std::lock_guard NumEventsLiveInEventPoolGuard( NumEventsLiveInEventPoolMutex, std::adopt_lock); - ze_event_pool_desc_t ZeEventPoolDesc = {}; - ZeEventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC; + ZeStruct ZeEventPoolDesc; ZeEventPoolDesc.count = MaxNumEventsPerPool; // Make all events visible on the host. @@ -585,7 +584,7 @@ pi_result _pi_context::initialize() { // TODO: get rid of using Devices[0] for the context with multiple // root-devices. We should somehow make the data initialized on all devices. pi_device Device = SingleRootDevice ? SingleRootDevice : Devices[0]; - ze_command_queue_desc_t ZeCommandQueueDesc = {}; + ZeStruct ZeCommandQueueDesc; ZeCommandQueueDesc.ordinal = Device->ZeComputeQueueGroupIndex; ZeCommandQueueDesc.index = 0; ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS; @@ -733,10 +732,8 @@ pi_result _pi_context::getAvailableCommandList( // Each command list is paired with an associated fence to track when the // command list is available for reuse. _pi_result pi_result = PI_OUT_OF_RESOURCES; - ze_command_list_desc_t ZeCommandListDesc = {}; - ZeCommandListDesc.stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC; - ze_fence_desc_t ZeFenceDesc = {}; - ZeFenceDesc.stype = ZE_STRUCTURE_TYPE_FENCE_DESC; + ZeStruct ZeCommandListDesc; + ZeStruct ZeFenceDesc; ZeCommandListDesc.commandQueueGroupOrdinal = (UseCopyEngine) ? Queue->Device->ZeCopyQueueGroupIndex @@ -2219,7 +2216,9 @@ pi_result piContextCreate(const pi_context_properties *Properties, PI_ASSERT(RetContext, PI_INVALID_VALUE); pi_platform Platform = (*Devices)->Platform; - ze_context_desc_t ContextDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0}; + ZeStruct ContextDesc; + ContextDesc.flags = 0; + ze_context_handle_t ZeContext; ZE_CALL(zeContextCreate, (Platform->ZeDriver, &ContextDesc, &ZeContext)); try { @@ -2384,7 +2383,7 @@ pi_result piQueueCreate(pi_context Context, pi_device Device, PI_ASSERT(Device, PI_INVALID_DEVICE); ZeDevice = Device->ZeDevice; - ze_command_queue_desc_t ZeCommandQueueDesc = {}; + ZeStruct ZeCommandQueueDesc; ZeCommandQueueDesc.ordinal = Device->ZeComputeQueueGroupIndex; ZeCommandQueueDesc.index = 0; ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS; @@ -2835,7 +2834,7 @@ pi_result piMemImageCreate(pi_context Context, pi_mem_flags Flags, return PI_INVALID_VALUE; } - ze_image_desc_t ZeImageDesc = {}; + ZeStruct ZeImageDesc; ZeImageDesc.arraylevels = ZeImageDesc.flags = 0; ZeImageDesc.type = ZeImageType; ZeImageDesc.format = ZeFormatDesc; @@ -3335,7 +3334,7 @@ static pi_result compileOrBuild(pi_program Program, pi_uint32 NumDevices, } // Ask Level Zero to build and load the native code onto the device. - ze_module_desc_t ZeModuleDesc = {}; + ZeStruct ZeModuleDesc; ZeModuleDesc.format = (Program->State == _pi_program::IL) ? ZE_MODULE_FORMAT_IL_SPIRV : ZE_MODULE_FORMAT_NATIVE; @@ -3510,7 +3509,7 @@ static pi_result copyModule(ze_context_handle_t ZeContext, std::unique_ptr Code(new uint8_t[Length]); ZE_CALL(zeModuleGetNativeBinary, (SrcMod, &Length, Code.get())); - ze_module_desc_t ZeModuleDesc = {}; + ZeStruct ZeModuleDesc; ZeModuleDesc.format = ZE_MODULE_FORMAT_NATIVE; ZeModuleDesc.inputSize = Length; ZeModuleDesc.pInputModule = Code.get(); @@ -3597,7 +3596,7 @@ pi_result piKernelCreate(pi_program Program, const char *KernelName, return PI_INVALID_PROGRAM_EXECUTABLE; } - ze_kernel_desc_t ZeKernelDesc = {}; + ZeStruct ZeKernelDesc; ZeKernelDesc.flags = 0; ZeKernelDesc.pKernelName = KernelName; @@ -4062,7 +4061,7 @@ pi_result piEventCreate(pi_context Context, pi_event *RetEvent) { return Res; ze_event_handle_t ZeEvent; - ze_event_desc_t ZeEventDesc = {}; + ZeStruct ZeEventDesc; // We have to set the SIGNAL flag as HOST scope because the // Level-Zero plugin implementation waits for the events to complete // on the host. @@ -4465,7 +4464,7 @@ pi_result piSamplerCreate(pi_context Context, pi_device Device = Context->Devices[0]; ze_sampler_handle_t ZeSampler; - ze_sampler_desc_t ZeSamplerDesc = {}; + ZeStruct ZeSamplerDesc; // Set the default values for the ZeSamplerDesc. ZeSamplerDesc.isNormalized = PI_TRUE; @@ -5181,7 +5180,7 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer, // Use the version with reference counting PI_CALL(piextUSMHostAlloc(RetMap, Queue->Context, nullptr, Size, 1)); } else { - ze_host_mem_alloc_desc_t ZeDesc = {}; + ZeStruct ZeDesc; ZeDesc.flags = 0; ZE_CALL(zeMemAllocHost, @@ -5711,14 +5710,13 @@ static pi_result USMDeviceAllocImpl(void **ResultPtr, pi_context Context, PI_INVALID_VALUE); // TODO: translate PI properties to Level Zero flags - ze_device_mem_alloc_desc_t ZeDesc = {}; + ZeStruct ZeDesc; ZeDesc.flags = 0; ZeDesc.ordinal = 0; - ze_relaxed_allocation_limits_exp_desc_t RelaxedDesc = {}; + ZeStruct RelaxedDesc; if (Size > Device->ZeDeviceProperties.maxMemAllocSize) { // Tell Level-Zero to accept Size > maxMemAllocSize - RelaxedDesc.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC; RelaxedDesc.flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE; ZeDesc.pNext = &RelaxedDesc; } @@ -5745,16 +5743,15 @@ static pi_result USMSharedAllocImpl(void **ResultPtr, pi_context Context, PI_INVALID_VALUE); // TODO: translate PI properties to Level Zero flags - ze_host_mem_alloc_desc_t ZeHostDesc = {}; + ZeStruct ZeHostDesc; ZeHostDesc.flags = 0; - ze_device_mem_alloc_desc_t ZeDevDesc = {}; + ZeStruct ZeDevDesc; ZeDevDesc.flags = 0; ZeDevDesc.ordinal = 0; - ze_relaxed_allocation_limits_exp_desc_t RelaxedDesc = {}; + ZeStruct RelaxedDesc; if (Size > Device->ZeDeviceProperties.maxMemAllocSize) { // Tell Level-Zero to accept Size > maxMemAllocSize - RelaxedDesc.stype = ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC; RelaxedDesc.flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE; ZeDevDesc.pNext = &RelaxedDesc; } @@ -5779,7 +5776,7 @@ static pi_result USMHostAllocImpl(void **ResultPtr, pi_context Context, PI_INVALID_VALUE); // TODO: translate PI properties to Level Zero flags - ze_host_mem_alloc_desc_t ZeHostDesc = {}; + ZeStruct ZeHostDesc; ZeHostDesc.flags = 0; ZE_CALL(zeMemAllocHost, (Context->ZeContext, &ZeHostDesc, Size, Alignment, ResultPtr)); diff --git a/sycl/plugins/level_zero/pi_level_zero.hpp b/sycl/plugins/level_zero/pi_level_zero.hpp index d829240bb7420..4abf77f5214be 100644 --- a/sycl/plugins/level_zero/pi_level_zero.hpp +++ b/sycl/plugins/level_zero/pi_level_zero.hpp @@ -55,6 +55,62 @@ template <> uint32_t pi_cast(uint64_t Value) { std::terminate(); } +// Returns the ze_structure_type_t to use in .stype of a structured descriptor. +// Intentionally not defined; will give an error if no proper specialization +template ze_structure_type_t getZeStructureType(); + +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_EVENT_POOL_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_FENCE_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_CONTEXT_DESC; +} +template <> +ze_structure_type_t +getZeStructureType() { + return ZE_STRUCTURE_TYPE_RELAXED_ALLOCATION_LIMITS_EXP_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC; +} +template <> +ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_IMAGE_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_MODULE_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_KERNEL_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_EVENT_DESC; +} +template <> ze_structure_type_t getZeStructureType() { + return ZE_STRUCTURE_TYPE_SAMPLER_DESC; +} + +// The helper struct to properly default initialize Level-Zero descriptor +// structure. +template struct ZeStruct : public T { + ZeStruct() { + this->stype = getZeStructureType(); + this->pNext = nullptr; + } +}; + // Base class to store common data struct _pi_object { _pi_object() : RefCount{1} {} @@ -613,7 +669,7 @@ struct _pi_image final : _pi_mem { #ifndef NDEBUG // Keep the descriptor of the image (for debugging purposes) - ze_image_desc_t ZeImageDesc; + ZeStruct ZeImageDesc; #endif // !NDEBUG // Level Zero image handle.