From f6c1b0a3f883204465b3c4551278231af8cd647b Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Sun, 28 Jul 2024 02:59:13 -0700 Subject: [PATCH] [SYCL][NFC] Improve work with mock images in unittests Most of our unit-tests only care about getting a device image with certain kernels and certain properties regardless of how other fields are set. This patch introduces a new constructor to UrImage to simplify unit-tests code. Also it cleans up some includes and uses existing helpers where possible to generate device images for tests. --- sycl/unittests/Extensions/DeviceGlobal.cpp | 20 ++--------- sycl/unittests/Extensions/USMMemcpy2D.cpp | 26 ++------------ .../SYCL2020/DeviceGetInfoAspects.cpp | 1 - sycl/unittests/SYCL2020/IsCompatible.cpp | 14 ++------ sycl/unittests/SYCL2020/KernelID.cpp | 26 ++------------ .../SYCL2020/SpecializationConstant.cpp | 10 +----- .../accessor/AccessorPlaceholder.cpp | 1 - sycl/unittests/assert/assert.cpp | 20 ++--------- sycl/unittests/helpers/UrImage.hpp | 34 ++++++++++++------- sycl/unittests/kernel-and-program/Cache.cpp | 10 +----- .../pipes/host_pipe_registration.cpp | 10 +----- sycl/unittests/program_manager/BuildLog.cpp | 1 - sycl/unittests/program_manager/SubDevices.cpp | 1 - .../arg_mask/EliminatedArgMask.cpp | 33 ++---------------- .../program_manager/itt_annotations.cpp | 1 - .../scheduler/CommandsWaitForEvents.cpp | 10 +----- .../scheduler/InOrderQueueHostTaskDeps.cpp | 1 - sycl/unittests/scheduler/RequiredWGSize.cpp | 1 - sycl/unittests/stream/stream.cpp | 1 - sycl/unittests/windows/dllmain.cpp | 1 - 20 files changed, 42 insertions(+), 180 deletions(-) diff --git a/sycl/unittests/Extensions/DeviceGlobal.cpp b/sycl/unittests/Extensions/DeviceGlobal.cpp index ee59cb4dc2d84..0f40726eaee3d 100644 --- a/sycl/unittests/Extensions/DeviceGlobal.cpp +++ b/sycl/unittests/Extensions/DeviceGlobal.cpp @@ -67,18 +67,10 @@ static sycl::unittest::UrImage generateDeviceGlobalImage() { PropSet.insert(__SYCL_PROPERTY_SET_SYCL_DEVICE_GLOBALS, UrArray{std::move(DevGlobInfo)}); - std::vector Bin{10, 11, 12, 13, 14, 15}; // Random data - UrArray Entries = makeEmptyKernels({DeviceGlobalTestKernelName}); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } @@ -98,18 +90,10 @@ static sycl::unittest::UrImage generateDeviceGlobalImgScopeImage() { PropSet.insert(__SYCL_PROPERTY_SET_SYCL_DEVICE_GLOBALS, UrArray{std::move(DevGlobInfo)}); - std::vector Bin{10, 11, 12, 13, 14, 15}; // Random data - UrArray Entries = makeEmptyKernels({DeviceGlobalImgScopeTestKernelName}); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } diff --git a/sycl/unittests/Extensions/USMMemcpy2D.cpp b/sycl/unittests/Extensions/USMMemcpy2D.cpp index 18d45736e54cb..8264b7c27ed69 100644 --- a/sycl/unittests/Extensions/USMMemcpy2D.cpp +++ b/sycl/unittests/Extensions/USMMemcpy2D.cpp @@ -125,30 +125,10 @@ struct KernelInfo> } // namespace _V1 } // namespace sycl -static sycl::unittest::UrImage generateMemopsImage() { - using namespace sycl::unittest; - - UrPropertySet PropSet; - - std::vector Bin{10, 11, 12, 13, 14, 15}; // Random data - - UrArray Entries = makeEmptyKernels( - {USMFillHelperKernelNameLong, USMFillHelperKernelNameChar, - USMMemcpyHelperKernelNameLong, USMMemcpyHelperKernelNameChar}); - - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; - - return Img; -} - namespace { -sycl::unittest::UrImage Imgs[] = {generateMemopsImage()}; +sycl::unittest::UrImage Imgs[] = {sycl::unittest::generateDefaultImage( + {USMFillHelperKernelNameLong, USMFillHelperKernelNameChar, + USMMemcpyHelperKernelNameLong, USMMemcpyHelperKernelNameChar})}; sycl::unittest::UrImageArray<1> ImgArray{Imgs}; ur_context_info_t LastMemopsQuery = UR_CONTEXT_INFO_NUM_DEVICES; diff --git a/sycl/unittests/SYCL2020/DeviceGetInfoAspects.cpp b/sycl/unittests/SYCL2020/DeviceGetInfoAspects.cpp index 42ff1c6eceabf..d9660a3ed6dbc 100644 --- a/sycl/unittests/SYCL2020/DeviceGetInfoAspects.cpp +++ b/sycl/unittests/SYCL2020/DeviceGetInfoAspects.cpp @@ -8,7 +8,6 @@ #include -#include #include #include diff --git a/sycl/unittests/SYCL2020/IsCompatible.cpp b/sycl/unittests/SYCL2020/IsCompatible.cpp index aaa295bf77b2f..a2badeadb0fc4 100644 --- a/sycl/unittests/SYCL2020/IsCompatible.cpp +++ b/sycl/unittests/SYCL2020/IsCompatible.cpp @@ -24,23 +24,15 @@ MOCK_INTEGRATION_HEADER(TestKernelACC) static sycl::unittest::UrImage generateDefaultImage(std::initializer_list KernelNames, - const std::vector &Aspects, const std::vector &ReqdWGSize = {}) { + const std::vector &Aspects, + const std::vector &ReqdWGSize = {}) { using namespace sycl::unittest; UrPropertySet PropSet; addDeviceRequirementsProps(PropSet, Aspects, ReqdWGSize); - - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - UrArray Entries = makeEmptyKernels(KernelNames); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } diff --git a/sycl/unittests/SYCL2020/KernelID.cpp b/sycl/unittests/SYCL2020/KernelID.cpp index 21e458864549a..87f01caf2a878 100644 --- a/sycl/unittests/SYCL2020/KernelID.cpp +++ b/sycl/unittests/SYCL2020/KernelID.cpp @@ -47,30 +47,10 @@ struct KernelInfo : public unittest::MockKernelInfoBase { } // namespace _V1 } // namespace sycl -static sycl::unittest::UrImage -generateDefaultImage(std::initializer_list Kernels) { - using namespace sycl::unittest; - - UrPropertySet PropSet; - - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - - UrArray Entries = makeEmptyKernels(Kernels); - - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; - - return Img; -} - static sycl::unittest::UrImage Imgs[2] = { - generateDefaultImage({"KernelID_TestKernel1", "KernelID_TestKernel3"}), - generateDefaultImage( + sycl::unittest::generateDefaultImage( + {"KernelID_TestKernel1", "KernelID_TestKernel3"}), + sycl::unittest::generateDefaultImage( {"KernelID_TestKernel2", "_ZTSN2cl4sycl6detail23__sycl_service_kernel__14ServiceKernel1"})}; static sycl::unittest::UrImageArray<2> ImgArray{Imgs}; diff --git a/sycl/unittests/SYCL2020/SpecializationConstant.cpp b/sycl/unittests/SYCL2020/SpecializationConstant.cpp index 9875084a3ed92..45be68d35270f 100644 --- a/sycl/unittests/SYCL2020/SpecializationConstant.cpp +++ b/sycl/unittests/SYCL2020/SpecializationConstant.cpp @@ -47,17 +47,9 @@ static sycl::unittest::UrImage generateImageWithSpecConsts() { UrPropertySet PropSet; addSpecConstants({SC1, SC2}, std::move(SpecConstData), PropSet); - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - UrArray Entries = makeEmptyKernels({"SpecializationConstant_TestKernel"}); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } diff --git a/sycl/unittests/accessor/AccessorPlaceholder.cpp b/sycl/unittests/accessor/AccessorPlaceholder.cpp index 045ae6402d22e..45b078984c84a 100644 --- a/sycl/unittests/accessor/AccessorPlaceholder.cpp +++ b/sycl/unittests/accessor/AccessorPlaceholder.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include diff --git a/sycl/unittests/assert/assert.cpp b/sycl/unittests/assert/assert.cpp index 33048f3433932..cd1ab74458daf 100644 --- a/sycl/unittests/assert/assert.cpp +++ b/sycl/unittests/assert/assert.cpp @@ -84,17 +84,9 @@ static sycl::unittest::UrImage generateDefaultImage() { setKernelUsesAssert({KernelName}, PropSet); - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - UrArray Entries = makeEmptyKernels({KernelName}); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } @@ -107,17 +99,9 @@ static sycl::unittest::UrImage generateCopierKernelImage() { UrPropertySet PropSet; - std::vector Bin{10, 11, 12, 13, 14, 15}; // Random data - UrArray Entries = makeEmptyKernels({CopierKernelName}); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } diff --git a/sycl/unittests/helpers/UrImage.hpp b/sycl/unittests/helpers/UrImage.hpp index 566817d7ef375..cab2bd40a4e90 100644 --- a/sycl/unittests/helpers/UrImage.hpp +++ b/sycl/unittests/helpers/UrImage.hpp @@ -246,6 +246,27 @@ class UrImage { CompileOptions, LinkOptions, {}, std::move(Binary), std::move(OffloadEntries), std::move(PropertySet)) {} + /// Constructs a mock SYCL device image with: + /// - the latest version + /// - SPIR-V format + /// - empty compile and link options + /// - placeholder binary data + UrImage(UrArray OffloadEntries, UrPropertySet PropertySet) + : UrImage( + SYCL_DEVICE_BINARY_VERSION, SYCL_DEVICE_BINARY_OFFLOAD_KIND_SYCL, + SYCL_DEVICE_BINARY_TYPE_SPIRV, __SYCL_DEVICE_BINARY_TARGET_SPIRV64, + "", "", {}, std::move(std::vector{1, 2, 3, 4, 5}), + std::move(OffloadEntries), std::move(PropertySet)) {} + + /// Constructs a mock SYCL device image with: + /// - the latest version + /// - SPIR-V format + /// - empty compile and link options + /// - placeholder binary data + /// - no properties + UrImage(UrArray OffloadEntries) + : UrImage(std::move(OffloadEntries), {}) {} + sycl_device_binary_struct convertToNativeType() { return sycl_device_binary_struct{ MVersion, @@ -539,20 +560,9 @@ addDeviceRequirementsProps(UrPropertySet &Props, inline UrImage generateDefaultImage(std::initializer_list KernelNames) { - UrPropertySet PropSet; - - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - UrArray Entries = makeEmptyKernels(KernelNames); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; - + UrImage Img(std::move(Entries)); return Img; } diff --git a/sycl/unittests/kernel-and-program/Cache.cpp b/sycl/unittests/kernel-and-program/Cache.cpp index c2ddb46c3a17f..f2ff07f50d7b8 100644 --- a/sycl/unittests/kernel-and-program/Cache.cpp +++ b/sycl/unittests/kernel-and-program/Cache.cpp @@ -59,18 +59,10 @@ static sycl::unittest::UrImage generateDefaultImage() { UrPropertySet PropSet; addSpecConstants({SC1}, std::move(SpecConstData), PropSet); - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - UrArray Entries = makeEmptyKernels({"CacheTestKernel", "CacheTestKernel2"}); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index b625b9f5fc5cc..84ccbe04bd2fe 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -41,17 +41,9 @@ static sycl::unittest::UrImage generateDefaultImage() { PropSet.insert(__SYCL_PROPERTY_SET_SYCL_HOST_PIPES, UrArray{std::move(HostPipeInfo)}); - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - UrArray Entries = makeEmptyKernels({"TestKernel"}); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } diff --git a/sycl/unittests/program_manager/BuildLog.cpp b/sycl/unittests/program_manager/BuildLog.cpp index fc4ff8abbbde2..c204c603655a6 100644 --- a/sycl/unittests/program_manager/BuildLog.cpp +++ b/sycl/unittests/program_manager/BuildLog.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/sycl/unittests/program_manager/SubDevices.cpp b/sycl/unittests/program_manager/SubDevices.cpp index 26d5b4cf148a0..602c16c3a5441 100644 --- a/sycl/unittests/program_manager/SubDevices.cpp +++ b/sycl/unittests/program_manager/SubDevices.cpp @@ -8,7 +8,6 @@ #include -#include #include #include diff --git a/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp b/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp index 5eb6fdb7e8f4e..1e36012a427c4 100644 --- a/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp +++ b/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp @@ -55,43 +55,16 @@ static sycl::unittest::UrImage generateEAMTestKernelImage() { UrPropertySet PropSet; PropSet.insert(__SYCL_PROPERTY_SET_KERNEL_PARAM_OPT_INFO, std::move(ImgKPOI)); - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - UrArray Entries = makeEmptyKernels({EAMTestKernelName}); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; - - return Img; -} - -static sycl::unittest::UrImage generateEAMTestKernel2Image() { - using namespace sycl::unittest; - - UrPropertySet PropSet; - - std::vector Bin{6, 7, 8, 9, 10, 11}; // Random data - - UrArray Entries = makeEmptyKernels({EAMTestKernel2Name}); - - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } static sycl::unittest::UrImage EAMImg = generateEAMTestKernelImage(); -static sycl::unittest::UrImage EAM2Img = generateEAMTestKernel2Image(); +static sycl::unittest::UrImage EAM2Img = + sycl::unittest::generateDefaultImage({EAMTestKernel2Name}); static sycl::unittest::UrImageArray<1> EAMImgArray{&EAMImg}; static sycl::unittest::UrImageArray<1> EAM2ImgArray{&EAM2Img}; diff --git a/sycl/unittests/program_manager/itt_annotations.cpp b/sycl/unittests/program_manager/itt_annotations.cpp index edcb9a9baf88b..f7c70a996b0e7 100644 --- a/sycl/unittests/program_manager/itt_annotations.cpp +++ b/sycl/unittests/program_manager/itt_annotations.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include diff --git a/sycl/unittests/scheduler/CommandsWaitForEvents.cpp b/sycl/unittests/scheduler/CommandsWaitForEvents.cpp index fdada9b624714..5cf9970604405 100644 --- a/sycl/unittests/scheduler/CommandsWaitForEvents.cpp +++ b/sycl/unittests/scheduler/CommandsWaitForEvents.cpp @@ -107,18 +107,10 @@ static sycl::unittest::UrImage generateDefaultImage() { UrPropertySet PropSet; addESIMDFlag(PropSet); - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - UrArray Entries = makeEmptyKernels({"StreamAUXCmdsWait_TestKernel"}); - UrImage Img{SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; + UrImage Img(std::move(Entries), std::move(PropSet)); return Img; } diff --git a/sycl/unittests/scheduler/InOrderQueueHostTaskDeps.cpp b/sycl/unittests/scheduler/InOrderQueueHostTaskDeps.cpp index c37753735c658..cf0c91e1478c5 100644 --- a/sycl/unittests/scheduler/InOrderQueueHostTaskDeps.cpp +++ b/sycl/unittests/scheduler/InOrderQueueHostTaskDeps.cpp @@ -10,7 +10,6 @@ #include "SchedulerTestUtils.hpp" #include -#include #include #include diff --git a/sycl/unittests/scheduler/RequiredWGSize.cpp b/sycl/unittests/scheduler/RequiredWGSize.cpp index 3cfa1958ed524..576c73d630eb9 100644 --- a/sycl/unittests/scheduler/RequiredWGSize.cpp +++ b/sycl/unittests/scheduler/RequiredWGSize.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include diff --git a/sycl/unittests/stream/stream.cpp b/sycl/unittests/stream/stream.cpp index 0811abff8cf77..34002a49cef59 100644 --- a/sycl/unittests/stream/stream.cpp +++ b/sycl/unittests/stream/stream.cpp @@ -8,7 +8,6 @@ #include -#include #include #include diff --git a/sycl/unittests/windows/dllmain.cpp b/sycl/unittests/windows/dllmain.cpp index f99364fe11720..79c41981f426b 100644 --- a/sycl/unittests/windows/dllmain.cpp +++ b/sycl/unittests/windows/dllmain.cpp @@ -12,7 +12,6 @@ * distinct binary executable. */ -#include #include #include