Skip to content

Commit 3891e88

Browse files
feature: use heapless builtins for images
Related-To: NEO-12744 Signed-off-by: Kamil Kopryk <[email protected]>
1 parent bbdf1ac commit 3891e88

File tree

18 files changed

+654
-101
lines changed

18 files changed

+654
-101
lines changed

level_zero/core/source/builtin/builtin_functions_lib.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,27 @@ enum class Builtin : uint32_t {
5252

5353
enum class ImageBuiltin : uint32_t {
5454
copyBufferToImage3d16Bytes = 0u,
55+
copyBufferToImage3d16BytesHeapless,
5556
copyBufferToImage3d2Bytes,
57+
copyBufferToImage3d2BytesHeapless,
5658
copyBufferToImage3d4Bytes,
59+
copyBufferToImage3d4BytesHeapless,
5760
copyBufferToImage3d8Bytes,
61+
copyBufferToImage3d8BytesHeapless,
5862
copyBufferToImage3dBytes,
63+
copyBufferToImage3dBytesHeapless,
5964
copyImage3dToBuffer16Bytes,
65+
copyImage3dToBuffer16BytesHeapless,
6066
copyImage3dToBuffer2Bytes,
67+
copyImage3dToBuffer2BytesHeapless,
6168
copyImage3dToBuffer4Bytes,
69+
copyImage3dToBuffer4BytesHeapless,
6270
copyImage3dToBuffer8Bytes,
71+
copyImage3dToBuffer8BytesHeapless,
6372
copyImage3dToBufferBytes,
73+
copyImage3dToBufferBytesHeapless,
6474
copyImageRegion,
75+
copyImageRegionHeapless,
6576
count
6677
};
6778

@@ -170,6 +181,30 @@ constexpr Builtin adjustBuiltinType<Builtin::fillBufferRightLeftover>(const bool
170181
}
171182
return Builtin::fillBufferRightLeftover;
172183
}
184+
185+
template <ImageBuiltin type>
186+
constexpr ImageBuiltin adjustImageBuiltinType(const bool isHeapless) {
187+
return type;
188+
}
189+
190+
#define DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(type) \
191+
template <> \
192+
constexpr ImageBuiltin adjustImageBuiltinType<type>(const bool isHeapless) { \
193+
return isHeapless ? type##Heapless : type; \
194+
}
195+
196+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyBufferToImage3d16Bytes);
197+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyBufferToImage3d2Bytes);
198+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyBufferToImage3d4Bytes);
199+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyBufferToImage3d8Bytes);
200+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyBufferToImage3dBytes);
201+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyImage3dToBuffer16Bytes);
202+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyImage3dToBuffer2Bytes);
203+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyImage3dToBuffer4Bytes);
204+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyImage3dToBuffer8Bytes);
205+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyImage3dToBufferBytes);
206+
DEFINE_ADJUST_IMAGE_BUILTIN_TYPE(ImageBuiltin::copyImageRegion);
207+
173208
} // namespace BuiltinTypeHelper
174209

175210
} // namespace L0

level_zero/core/source/builtin/builtin_functions_lib_impl.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,50 +159,93 @@ void BuiltinFunctionsLibImpl::initBuiltinImageKernel(ImageBuiltin func) {
159159
builtinName = "CopyBufferToImage3d16Bytes";
160160
builtin = NEO::EBuiltInOps::copyBufferToImage3d;
161161
break;
162+
case ImageBuiltin::copyBufferToImage3d16BytesHeapless:
163+
builtinName = "CopyBufferToImage3d16Bytes";
164+
builtin = NEO::EBuiltInOps::copyBufferToImage3dHeapless;
165+
break;
162166
case ImageBuiltin::copyBufferToImage3d2Bytes:
163167
builtinName = "CopyBufferToImage3d2Bytes";
164168
builtin = NEO::EBuiltInOps::copyBufferToImage3d;
165169
break;
170+
case ImageBuiltin::copyBufferToImage3d2BytesHeapless:
171+
builtinName = "CopyBufferToImage3d2Bytes";
172+
builtin = NEO::EBuiltInOps::copyBufferToImage3dHeapless;
173+
break;
166174
case ImageBuiltin::copyBufferToImage3d4Bytes:
167175
builtinName = "CopyBufferToImage3d4Bytes";
168176
builtin = NEO::EBuiltInOps::copyBufferToImage3d;
169177
break;
178+
case ImageBuiltin::copyBufferToImage3d4BytesHeapless:
179+
builtinName = "CopyBufferToImage3d4Bytes";
180+
builtin = NEO::EBuiltInOps::copyBufferToImage3dHeapless;
181+
break;
170182
case ImageBuiltin::copyBufferToImage3d8Bytes:
171183
builtinName = "CopyBufferToImage3d8Bytes";
172184
builtin = NEO::EBuiltInOps::copyBufferToImage3d;
173185
break;
186+
case ImageBuiltin::copyBufferToImage3d8BytesHeapless:
187+
builtinName = "CopyBufferToImage3d8Bytes";
188+
builtin = NEO::EBuiltInOps::copyBufferToImage3dHeapless;
189+
break;
174190
case ImageBuiltin::copyBufferToImage3dBytes:
175191
builtinName = "CopyBufferToImage3dBytes";
176192
builtin = NEO::EBuiltInOps::copyBufferToImage3d;
177193
break;
194+
case ImageBuiltin::copyBufferToImage3dBytesHeapless:
195+
builtinName = "CopyBufferToImage3dBytes";
196+
builtin = NEO::EBuiltInOps::copyBufferToImage3dHeapless;
197+
break;
178198
case ImageBuiltin::copyImage3dToBuffer16Bytes:
179199
builtinName = "CopyImage3dToBuffer16Bytes";
180200
builtin = NEO::EBuiltInOps::copyImage3dToBuffer;
181201
break;
202+
case ImageBuiltin::copyImage3dToBuffer16BytesHeapless:
203+
builtinName = "CopyImage3dToBuffer16Bytes";
204+
builtin = NEO::EBuiltInOps::copyImage3dToBufferHeapless;
205+
break;
182206
case ImageBuiltin::copyImage3dToBuffer2Bytes:
183207
builtinName = "CopyImage3dToBuffer2Bytes";
184208
builtin = NEO::EBuiltInOps::copyImage3dToBuffer;
185209
break;
210+
case ImageBuiltin::copyImage3dToBuffer2BytesHeapless:
211+
builtinName = "CopyImage3dToBuffer2Bytes";
212+
builtin = NEO::EBuiltInOps::copyImage3dToBufferHeapless;
213+
break;
186214
case ImageBuiltin::copyImage3dToBuffer4Bytes:
187215
builtinName = "CopyImage3dToBuffer4Bytes";
188216
builtin = NEO::EBuiltInOps::copyImage3dToBuffer;
189217
break;
218+
case ImageBuiltin::copyImage3dToBuffer4BytesHeapless:
219+
builtinName = "CopyImage3dToBuffer4Bytes";
220+
builtin = NEO::EBuiltInOps::copyImage3dToBufferHeapless;
221+
break;
190222
case ImageBuiltin::copyImage3dToBuffer8Bytes:
191223
builtinName = "CopyImage3dToBuffer8Bytes";
192224
builtin = NEO::EBuiltInOps::copyImage3dToBuffer;
193225
break;
226+
case ImageBuiltin::copyImage3dToBuffer8BytesHeapless:
227+
builtinName = "CopyImage3dToBuffer8Bytes";
228+
builtin = NEO::EBuiltInOps::copyImage3dToBufferHeapless;
229+
break;
194230
case ImageBuiltin::copyImage3dToBufferBytes:
195231
builtinName = "CopyImage3dToBufferBytes";
196232
builtin = NEO::EBuiltInOps::copyImage3dToBuffer;
197233
break;
234+
case ImageBuiltin::copyImage3dToBufferBytesHeapless:
235+
builtinName = "CopyImage3dToBufferBytes";
236+
builtin = NEO::EBuiltInOps::copyImage3dToBufferHeapless;
237+
break;
198238
case ImageBuiltin::copyImageRegion:
199239
builtinName = "CopyImageToImage3d";
200240
builtin = NEO::EBuiltInOps::copyImageToImage3d;
201241
break;
242+
case ImageBuiltin::copyImageRegionHeapless:
243+
builtinName = "CopyImageToImage3d";
244+
builtin = NEO::EBuiltInOps::copyImageToImage3dHeapless;
245+
break;
202246
default:
203247
UNRECOVERABLE_IF(true);
204248
};
205-
206249
auto builtId = static_cast<uint32_t>(func);
207250
imageBuiltins[builtId] = loadBuiltIn(builtin, builtinName);
208251
}

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -743,31 +743,33 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendImageCopyFromMemoryExt(z
743743
return status;
744744
}
745745

746-
auto lock = device->getBuiltinFunctionsLib()->obtainUniqueOwnership();
747-
748-
Kernel *builtinKernel = nullptr;
746+
bool isHeaplessEnabled = this->heaplessModeEnabled;
747+
ImageBuiltin builtInType = ImageBuiltin::copyBufferToImage3dBytes;
749748

750749
switch (bytesPerPixel) {
751-
default:
752-
UNRECOVERABLE_IF(true);
753-
break;
754750
case 1u:
755-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyBufferToImage3dBytes);
751+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyBufferToImage3dBytes>(isHeaplessEnabled);
756752
break;
757753
case 2u:
758-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyBufferToImage3d2Bytes);
754+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyBufferToImage3d2Bytes>(isHeaplessEnabled);
759755
break;
760756
case 4u:
761-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyBufferToImage3d4Bytes);
757+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyBufferToImage3d4Bytes>(isHeaplessEnabled);
762758
break;
763759
case 8u:
764-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyBufferToImage3d8Bytes);
760+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyBufferToImage3d8Bytes>(isHeaplessEnabled);
765761
break;
766762
case 16u:
767-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyBufferToImage3d16Bytes);
763+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyBufferToImage3d16Bytes>(isHeaplessEnabled);
764+
break;
765+
default:
766+
UNRECOVERABLE_IF(true);
768767
break;
769768
}
770769

770+
auto lock = device->getBuiltinFunctionsLib()->obtainUniqueOwnership();
771+
Kernel *builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(builtInType);
772+
771773
builtinKernel->setArgBufferWithAlloc(0u, allocationStruct.alignedAllocationPtr,
772774
allocationStruct.alloc,
773775
nullptr);
@@ -913,34 +915,36 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendImageCopyToMemoryExt(voi
913915
return status;
914916
}
915917

916-
auto lock = device->getBuiltinFunctionsLib()->obtainUniqueOwnership();
917-
918-
Kernel *builtinKernel = nullptr;
918+
bool isHeaplessEnabled = this->heaplessModeEnabled;
919+
ImageBuiltin builtInType = ImageBuiltin::copyBufferToImage3dBytes;
919920

920921
switch (bytesPerPixel) {
921-
default: {
922-
CREATE_DEBUG_STRING(str, "Invalid bytesPerPixel of size: %u\n", bytesPerPixel);
923-
driverHandle->setErrorDescription(std::string(str.get()));
924-
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "invalid bytesPerPixel of size: %u\n", bytesPerPixel);
925-
UNRECOVERABLE_IF(true);
926-
break;
927-
}
928922
case 1u:
929-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyImage3dToBufferBytes);
923+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyImage3dToBufferBytes>(isHeaplessEnabled);
930924
break;
931925
case 2u:
932-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyImage3dToBuffer2Bytes);
926+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyImage3dToBuffer2Bytes>(isHeaplessEnabled);
933927
break;
934928
case 4u:
935-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyImage3dToBuffer4Bytes);
929+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyImage3dToBuffer4Bytes>(isHeaplessEnabled);
936930
break;
937931
case 8u:
938-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyImage3dToBuffer8Bytes);
932+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyImage3dToBuffer8Bytes>(isHeaplessEnabled);
939933
break;
940934
case 16u:
941-
builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyImage3dToBuffer16Bytes);
935+
builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyImage3dToBuffer16Bytes>(isHeaplessEnabled);
936+
break;
937+
default: {
938+
CREATE_DEBUG_STRING(str, "Invalid bytesPerPixel of size: %u\n", bytesPerPixel);
939+
driverHandle->setErrorDescription(std::string(str.get()));
940+
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "invalid bytesPerPixel of size: %u\n", bytesPerPixel);
941+
UNRECOVERABLE_IF(true);
942942
break;
943943
}
944+
}
945+
946+
auto lock = device->getBuiltinFunctionsLib()->obtainUniqueOwnership();
947+
Kernel *builtinKernel = device->getBuiltinFunctionsLib()->getImageFunction(builtInType);
944948

945949
builtinKernel->setArgRedescribedImage(0u, image->toHandle());
946950
builtinKernel->setArgBufferWithAlloc(1u, allocationStruct.alignedAllocationPtr,
@@ -1109,9 +1113,10 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendImageCopyRegion(ze_image
11091113
return status;
11101114
}
11111115

1112-
auto lock = device->getBuiltinFunctionsLib()->obtainUniqueOwnership();
1116+
ImageBuiltin builtInType = BuiltinTypeHelper::adjustImageBuiltinType<ImageBuiltin::copyImageRegion>(this->heaplessModeEnabled);
11131117

1114-
auto kernel = device->getBuiltinFunctionsLib()->getImageFunction(ImageBuiltin::copyImageRegion);
1118+
auto lock = device->getBuiltinFunctionsLib()->obtainUniqueOwnership();
1119+
auto kernel = device->getBuiltinFunctionsLib()->getImageFunction(builtInType);
11151120

11161121
ze_result_t ret = kernel->suggestGroupSize(groupSizeX, groupSizeY, groupSizeZ, &groupSizeX,
11171122
&groupSizeY, &groupSizeZ);

level_zero/core/test/unit_tests/sources/builtin/builtin_functions_tests.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,47 @@ HWTEST_F(TestBuiltinFunctionsLibImpl, givenHeaplessBuiltinsWhenInitBuiltinKernel
192192
EXPECT_STREQ("FillBufferRightLeftoverStateless", lib.kernelNamePassed.c_str());
193193
}
194194

195+
HWTEST_F(TestBuiltinFunctionsLibImpl, givenHeaplessImageBuiltinsWhenInitBuiltinKernelThenCorrectArgumentsArePassed) {
196+
197+
MockCheckPassedArgumentsBuiltinFunctionsLibImpl lib(device, device->getNEODevice()->getBuiltIns());
198+
199+
lib.initBuiltinImageKernel(L0::ImageBuiltin::copyBufferToImage3d16BytesHeapless);
200+
EXPECT_EQ(NEO::EBuiltInOps::copyBufferToImage3dHeapless, lib.builtinPassed);
201+
EXPECT_STREQ("CopyBufferToImage3d16Bytes", lib.kernelNamePassed.c_str());
202+
203+
lib.initBuiltinImageKernel(L0::ImageBuiltin::copyBufferToImage3d2BytesHeapless);
204+
EXPECT_EQ(NEO::EBuiltInOps::copyBufferToImage3dHeapless, lib.builtinPassed);
205+
EXPECT_STREQ("CopyBufferToImage3d2Bytes", lib.kernelNamePassed.c_str());
206+
207+
lib.initBuiltinImageKernel(L0::ImageBuiltin::copyBufferToImage3d4BytesHeapless);
208+
EXPECT_EQ(NEO::EBuiltInOps::copyBufferToImage3dHeapless, lib.builtinPassed);
209+
EXPECT_STREQ("CopyBufferToImage3d4Bytes", lib.kernelNamePassed.c_str());
210+
211+
lib.initBuiltinImageKernel(L0::ImageBuiltin::copyBufferToImage3d8BytesHeapless);
212+
EXPECT_EQ(NEO::EBuiltInOps::copyBufferToImage3dHeapless, lib.builtinPassed);
213+
EXPECT_STREQ("CopyBufferToImage3d8Bytes", lib.kernelNamePassed.c_str());
214+
215+
lib.initBuiltinImageKernel(L0::ImageBuiltin::copyImage3dToBuffer16BytesHeapless);
216+
EXPECT_EQ(NEO::EBuiltInOps::copyImage3dToBufferHeapless, lib.builtinPassed);
217+
EXPECT_STREQ("CopyImage3dToBuffer16Bytes", lib.kernelNamePassed.c_str());
218+
219+
lib.initBuiltinImageKernel(L0::ImageBuiltin::copyImage3dToBuffer2BytesHeapless);
220+
EXPECT_EQ(NEO::EBuiltInOps::copyImage3dToBufferHeapless, lib.builtinPassed);
221+
EXPECT_STREQ("CopyImage3dToBuffer2Bytes", lib.kernelNamePassed.c_str());
222+
223+
lib.initBuiltinImageKernel(L0::ImageBuiltin::copyImage3dToBuffer4BytesHeapless);
224+
EXPECT_EQ(NEO::EBuiltInOps::copyImage3dToBufferHeapless, lib.builtinPassed);
225+
EXPECT_STREQ("CopyImage3dToBuffer4Bytes", lib.kernelNamePassed.c_str());
226+
227+
lib.initBuiltinImageKernel(L0::ImageBuiltin::copyImage3dToBufferBytesHeapless);
228+
EXPECT_EQ(NEO::EBuiltInOps::copyImage3dToBufferHeapless, lib.builtinPassed);
229+
EXPECT_STREQ("CopyImage3dToBufferBytes", lib.kernelNamePassed.c_str());
230+
231+
lib.initBuiltinImageKernel(L0::ImageBuiltin::copyImageRegionHeapless);
232+
EXPECT_EQ(NEO::EBuiltInOps::copyImageToImage3dHeapless, lib.builtinPassed);
233+
EXPECT_STREQ("CopyImageToImage3d", lib.kernelNamePassed.c_str());
234+
}
235+
195236
HWTEST_F(TestBuiltinFunctionsLibImpl, givenCompilerInterfaceWhenCreateDeviceAndImageSupportedThenBuiltinsImageFunctionsAreLoaded) {
196237
ze_result_t returnValue = ZE_RESULT_SUCCESS;
197238
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->compilerInterface.reset(new NEO::MockCompilerInterfaceSpirv());

0 commit comments

Comments
 (0)