Skip to content

Commit 14cdb5a

Browse files
authored
[SYCL] [Tests] Do not copy device binary image mocks (#4023)
Simplified, the motivation behind this change is the following. Employing std::vector to store device binary images makes them be allocated in heap which can't belong to neither any of loaded shared objects nor to the executable itself. Moving allocation to in-place makes the images be allocated in the executable.
1 parent 807fdae commit 14cdb5a

File tree

5 files changed

+16
-33
lines changed

5 files changed

+16
-33
lines changed

sycl/unittests/SYCL2020/SpecConstDefaultValues.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static sycl::unittest::PiImage generateImageWithSpecConsts() {
8282
}
8383

8484
sycl::unittest::PiImage Img = generateImageWithSpecConsts();
85-
sycl::unittest::PiImageArray ImgArray{Img};
85+
sycl::unittest::PiImageArray<1> ImgArray{&Img};
8686

8787
TEST(SpecConstDefaultValues, DISABLED_DefaultValuesAreSet) {
8888
sycl::platform Plt{sycl::default_selector()};

sycl/unittests/helpers/PiImage.hpp

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -233,46 +233,29 @@ class PiImage {
233233

234234
/// Convenience wrapper around pi_device_binaries_struct, that manages mock
235235
/// device images' lifecycle.
236-
class PiImageArray {
236+
template <size_t __NumberOfImages> class PiImageArray {
237237
public:
238-
/// Constructs an array of device images from a single image and registers
239-
/// it with SYCL runtime.
240-
PiImageArray(PiImage Image) {
241-
MImages.push_back(std::move(Image));
242-
convertImages();
243-
MAllBinaries = pi_device_binaries_struct{
244-
PI_DEVICE_BINARIES_VERSION,
245-
1, // num binaries
246-
MNativeImages.data(),
247-
nullptr, // not used, for compatibility with OpenMP
248-
nullptr // not used, for compatibility with OpenMP
249-
};
250-
__sycl_register_lib(&MAllBinaries);
251-
}
238+
static constexpr size_t NumberOfImages = __NumberOfImages;
239+
240+
PiImageArray(const PiImage *Imgs) {
241+
for (size_t Idx = 0; Idx < NumberOfImages; ++Idx)
242+
MNativeImages[Idx] = Imgs[Idx].convertToNativeType();
252243

253-
/// Constructs an array of device images and registers it with SYCL runtime.
254-
PiImageArray(std::vector<PiImage> Images) : MImages(std::move(Images)) {
255-
convertImages();
256244
MAllBinaries = pi_device_binaries_struct{
257245
PI_DEVICE_BINARIES_VERSION,
258-
static_cast<uint16_t>(MNativeImages.size()), // num binaries
259-
MNativeImages.data(),
260-
nullptr, // not used, for compatibility with OpenMP
261-
nullptr // not used, for compatibility with OpenMP
246+
NumberOfImages,
247+
MNativeImages,
248+
nullptr, // not used, put here for compatibility with OpenMP
249+
nullptr, // not used, put here for compatibility with OpenMP
262250
};
251+
263252
__sycl_register_lib(&MAllBinaries);
264253
}
265254

266255
~PiImageArray() { __sycl_unregister_lib(&MAllBinaries); }
267256

268257
private:
269-
void convertImages() {
270-
std::transform(
271-
MImages.begin(), MImages.end(), std::back_inserter(MNativeImages),
272-
[](const PiImage &Img) { return Img.convertToNativeType(); });
273-
}
274-
std::vector<PiImage> MImages;
275-
std::vector<pi_device_binary_struct> MNativeImages;
258+
pi_device_binary_struct MNativeImages[NumberOfImages];
276259
pi_device_binaries_struct MAllBinaries;
277260
};
278261

sycl/unittests/misc/KernelBuildOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static sycl::unittest::PiImage generateDefaultImage() {
208208
}
209209

210210
sycl::unittest::PiImage Img = generateDefaultImage();
211-
sycl::unittest::PiImageArray ImgArray{Img};
211+
sycl::unittest::PiImageArray<1> ImgArray{&Img};
212212

213213
TEST(KernelBuildOptions, KernelBundleBasic) {
214214
sycl::platform Plt{sycl::default_selector()};

sycl/unittests/program_manager/itt_annotations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static sycl::unittest::PiImage generateDefaultImage() {
239239
}
240240

241241
sycl::unittest::PiImage Img = generateDefaultImage();
242-
sycl::unittest::PiImageArray ImgArray{Img};
242+
sycl::unittest::PiImageArray<1> ImgArray{&Img};
243243

244244
TEST(ITTNotify, UseKernelBundle) {
245245
set_env(ITTProfileEnvVarName, "1");

sycl/unittests/scheduler/RequiredWGSize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static sycl::unittest::PiImage generateDefaultImage() {
226226
}
227227

228228
sycl::unittest::PiImage Img = generateDefaultImage();
229-
sycl::unittest::PiImageArray ImgArray{Img};
229+
sycl::unittest::PiImageArray<1> ImgArray{&Img};
230230

231231
static void performChecks() {
232232
sycl::platform Plt{sycl::default_selector()};

0 commit comments

Comments
 (0)