Skip to content

Commit 3e4dd67

Browse files
Refactor linear/tiled Images logic
Change-Id: I1deac70e95c6953645e9f52fb75f103b62927066 Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
1 parent d4571d6 commit 3e4dd67

File tree

14 files changed

+77
-89
lines changed

14 files changed

+77
-89
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!groovy
22
dependenciesRevision='2cb93cf2512d68900934c6aeccf1ddad5a927902-1308'
33
strategy='EQUAL'
4-
allowedCD=260
4+
allowedCD=259
55
allowedF=5

runtime/gmm_helper/gmm_helper.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ void GmmHelper::queryImgFromBufferParams(ImageInfo &imgInfo, GraphicsAllocation
8181
imgInfo.qPitch = 0;
8282
}
8383

84-
bool GmmHelper::allowTiling(const cl_image_desc &imageDesc) {
85-
auto imageType = imageDesc.image_type;
86-
auto buffer = castToObject<Buffer>(imageDesc.buffer);
87-
88-
return (!(DebugManager.flags.ForceLinearImages.get() || imageType == CL_MEM_OBJECT_IMAGE1D ||
89-
imageType == CL_MEM_OBJECT_IMAGE1D_ARRAY || imageType == CL_MEM_OBJECT_IMAGE1D_BUFFER || buffer));
90-
}
91-
9284
uint64_t GmmHelper::canonize(uint64_t address) {
9385
return ((int64_t)((address & 0xFFFFFFFFFFFF) << (64 - 48))) >> (64 - 48);
9486
}

runtime/gmm_helper/gmm_helper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class GmmHelper {
4646

4747
static void queryImgFromBufferParams(ImageInfo &imgInfo, GraphicsAllocation *gfxAlloc);
4848
static GMM_CUBE_FACE_ENUM getCubeFaceIndex(uint32_t target);
49-
static bool allowTiling(const cl_image_desc &imageDesc);
5049
static uint32_t getRenderMultisamplesCount(uint32_t numSamples);
5150
static GMM_YUV_PLANE convertPlane(OCLPlane oclPlane);
5251

runtime/helpers/hw_helper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class HwHelper {
6868
virtual uint32_t getMetricsLibraryGenId() const = 0;
6969
virtual uint32_t getMocsIndex(GmmHelper &gmmHelper, bool l3enabled, bool l1enabled) const = 0;
7070
virtual bool requiresAuxResolves() const = 0;
71+
virtual bool tilingAllowed(bool isSharedContext, const cl_image_desc &imgDesc, bool forceLinearStorage) = 0;
7172

7273
static constexpr uint32_t lowPriorityGpgpuEngineIndex = 1;
7374

@@ -167,6 +168,8 @@ class HwHelperHw : public HwHelper {
167168

168169
bool requiresAuxResolves() const override;
169170

171+
bool tilingAllowed(bool isSharedContext, const cl_image_desc &imgDesc, bool forceLinearStorage) override;
172+
170173
protected:
171174
HwHelperHw() = default;
172175
};

runtime/helpers/hw_helper_base.inl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,17 @@ template <typename GfxFamily>
220220
inline bool HwHelperHw<GfxFamily>::requiresAuxResolves() const {
221221
return true;
222222
}
223+
224+
template <typename GfxFamily>
225+
bool HwHelperHw<GfxFamily>::tilingAllowed(bool isSharedContext, const cl_image_desc &imgDesc, bool forceLinearStorage) {
226+
if (DebugManager.flags.ForceLinearImages.get() || forceLinearStorage || isSharedContext) {
227+
return false;
228+
}
229+
230+
auto imageType = imgDesc.image_type;
231+
auto buffer = castToObject<Buffer>(imgDesc.buffer);
232+
233+
return !(imageType == CL_MEM_OBJECT_IMAGE1D || imageType == CL_MEM_OBJECT_IMAGE1D_ARRAY ||
234+
imageType == CL_MEM_OBJECT_IMAGE1D_BUFFER || buffer);
235+
}
223236
} // namespace NEO

runtime/mem_obj/image.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Image *Image::create(Context *context,
119119
MemoryManager *memoryManager = context->getMemoryManager();
120120
Buffer *parentBuffer = castToObject<Buffer>(imageDesc->mem_object);
121121
Image *parentImage = castToObject<Image>(imageDesc->mem_object);
122+
auto &hwHelper = HwHelper::get(context->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily);
122123

123124
do {
124125
size_t imageWidth = imageDesc->image_width;
@@ -181,7 +182,7 @@ Image *Image::create(Context *context,
181182
auto hostPtrRowPitch = imageDesc->image_row_pitch ? imageDesc->image_row_pitch : imageWidth * surfaceFormat->ImageElementSizeInBytes;
182183
auto hostPtrSlicePitch = imageDesc->image_slice_pitch ? imageDesc->image_slice_pitch : hostPtrRowPitch * imageHeight;
183184
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
184-
imgInfo.linearStorage = context->isSharedContext || !GmmHelper::allowTiling(*imageDesc) || memoryProperties.flags.forceLinearStorage;
185+
imgInfo.linearStorage = !hwHelper.tilingAllowed(context->isSharedContext, *imageDesc, memoryProperties.flags.forceLinearStorage);
185186
imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(!imgInfo.linearStorage, memoryProperties,
186187
context->peekContextType(), true);
187188

@@ -215,7 +216,7 @@ Image *Image::create(Context *context,
215216
bool transferNeeded = false;
216217
if (((imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) || (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D)) && (parentBuffer != nullptr)) {
217218

218-
HwHelper::get(context->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily).checkResourceCompatibility(parentBuffer, errcodeRet);
219+
hwHelper.checkResourceCompatibility(parentBuffer, errcodeRet);
219220

220221
if (errcodeRet != CL_SUCCESS) {
221222
return nullptr;
@@ -710,7 +711,6 @@ bool Image::isCopyRequired(ImageInfo &imgInfo, const void *hostPtr) {
710711

711712
auto hostPtrRowPitch = imgInfo.imgDesc->image_row_pitch ? imgInfo.imgDesc->image_row_pitch : imageWidth * imgInfo.surfaceFormat->ImageElementSizeInBytes;
712713
auto hostPtrSlicePitch = imgInfo.imgDesc->image_slice_pitch ? imgInfo.imgDesc->image_slice_pitch : hostPtrRowPitch * imgInfo.imgDesc->image_height;
713-
auto isTilingAllowed = GmmHelper::allowTiling(*imgInfo.imgDesc) && !imgInfo.linearStorage;
714714

715715
size_t pointerPassedSize = hostPtrRowPitch * imageHeight * imageDepth * imageCount;
716716
auto alignedSizePassedPointer = alignSizeWholePage(const_cast<void *>(hostPtr), pointerPassedSize);
@@ -721,7 +721,7 @@ bool Image::isCopyRequired(ImageInfo &imgInfo, const void *hostPtr) {
721721
(imgInfo.rowPitch != hostPtrRowPitch) |
722722
(imgInfo.slicePitch != hostPtrSlicePitch) |
723723
((reinterpret_cast<uintptr_t>(hostPtr) & (MemoryConstants::cacheLineSize - 1)) != 0) |
724-
isTilingAllowed;
724+
!imgInfo.linearStorage;
725725

726726
return copyRequired;
727727
}

unit_tests/aub_tests/mem_obj/create_image_aub_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ INSTANTIATE_TEST_CASE_P(
8484
testing::ValuesIn(ImgArrayTypes));
8585

8686
HWTEST_P(AUBCreateImageArray, CheckArrayImages) {
87+
auto &hwHelper = HwHelper::get(pDevice->getExecutionEnvironment()->getHardwareInfo()->platform.eRenderCoreFamily);
8788
imageDesc.image_type = GetParam();
8889
if (imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) {
8990
imageDesc.image_height = 1;
9091
}
9192
cl_mem_flags flags = CL_MEM_COPY_HOST_PTR;
9293
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
9394
auto imgInfo = MockGmm::initImgInfo(imageDesc, 0, surfaceFormat);
94-
imgInfo.linearStorage = !GmmHelper::allowTiling(imageDesc);
95+
imgInfo.linearStorage = !hwHelper.tilingAllowed(false, imageDesc, false);
9596
auto queryGmm = MockGmm::queryImgParams(imgInfo);
9697

9798
//allocate host_ptr

unit_tests/gmm_helper/gmm_helper_tests.cpp

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -417,80 +417,8 @@ static const cl_mem_object_type imgTypes[6] = {
417417
CL_MEM_OBJECT_IMAGE2D,
418418
CL_MEM_OBJECT_IMAGE2D_ARRAY,
419419
CL_MEM_OBJECT_IMAGE3D};
420-
421-
static const cl_mem_object_type imgFromBufferTypes[2] = {
422-
CL_MEM_OBJECT_IMAGE1D_BUFFER,
423-
CL_MEM_OBJECT_IMAGE2D};
424420
} // namespace GmmTestConst
425421

426-
class GmmTiling : public GmmTests,
427-
public ::testing::WithParamInterface<uint32_t /*cl_mem_object_type*/> {
428-
public:
429-
void checkTiling(cl_image_desc &imgDesc, bool forceLinear) {
430-
bool allowTiling = GmmHelper::allowTiling(imgDesc);
431-
if (forceLinear) {
432-
EXPECT_FALSE(allowTiling);
433-
} else {
434-
if (imgDesc.image_type == CL_MEM_OBJECT_IMAGE1D ||
435-
imgDesc.image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ||
436-
imgDesc.image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER ||
437-
imgDesc.buffer != nullptr) {
438-
EXPECT_FALSE(allowTiling);
439-
} else {
440-
EXPECT_TRUE(allowTiling);
441-
}
442-
}
443-
};
444-
};
445-
446-
class GmmImgTilingTests : public GmmTiling {};
447-
448-
INSTANTIATE_TEST_CASE_P(
449-
GmmTiledTests,
450-
GmmImgTilingTests,
451-
testing::ValuesIn(GmmTestConst::imgTypes));
452-
453-
TEST_P(GmmImgTilingTests, allowTiling) {
454-
bool defaultTilingType = DebugManager.flags.ForceLinearImages.get();
455-
456-
cl_image_desc imgDesc = {};
457-
imgDesc.image_type = GetParam();
458-
459-
checkTiling(imgDesc, defaultTilingType);
460-
461-
DebugManager.flags.ForceLinearImages.set(!defaultTilingType);
462-
463-
checkTiling(imgDesc, !defaultTilingType);
464-
465-
DebugManager.flags.ForceLinearImages.set(defaultTilingType);
466-
}
467-
468-
class GmmImgFromBufferTilingTests : public GmmTiling {};
469-
INSTANTIATE_TEST_CASE_P(
470-
GmmTiledTests,
471-
GmmImgFromBufferTilingTests,
472-
testing::ValuesIn(GmmTestConst::imgFromBufferTypes));
473-
474-
TEST_P(GmmImgFromBufferTilingTests, disallowImgFromBufferTiling) {
475-
bool defaultTilingType = DebugManager.flags.ForceLinearImages.get();
476-
if (defaultTilingType) {
477-
DebugManager.flags.ForceLinearImages.set(false);
478-
}
479-
480-
cl_image_desc imgDesc = {};
481-
imgDesc.image_type = GetParam();
482-
483-
MockContext context;
484-
cl_int retVal = CL_SUCCESS;
485-
486-
auto buffer = std::unique_ptr<Buffer>(Buffer::create(&context, {}, 1, nullptr, retVal));
487-
imgDesc.buffer = buffer.get();
488-
489-
checkTiling(imgDesc, false);
490-
491-
DebugManager.flags.ForceLinearImages.set(defaultTilingType);
492-
}
493-
494422
TEST_F(GmmTests, converOclPlaneToGmmPlane) {
495423
std::vector<std::pair<OCLPlane, GMM_YUV_PLANE>> v = {{OCLPlane::NO_PLANE, GMM_YUV_PLANE::GMM_NO_PLANE},
496424
{OCLPlane::PLANE_Y, GMM_YUV_PLANE::GMM_PLANE_Y},
@@ -503,7 +431,8 @@ TEST_F(GmmTests, converOclPlaneToGmmPlane) {
503431
}
504432
}
505433

506-
class GmmImgTest : public GmmTiling {};
434+
class GmmImgTest : public GmmTests,
435+
public ::testing::WithParamInterface<uint32_t /*cl_mem_object_type*/> {};
507436

508437
INSTANTIATE_TEST_CASE_P(
509438
GmmImgTests,

unit_tests/helpers/hw_helper_tests.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "runtime/os_interface/os_interface.h"
2020
#include "unit_tests/helpers/unit_test_helper.h"
2121
#include "unit_tests/helpers/variable_backup.h"
22+
#include "unit_tests/mocks/mock_context.h"
2223

2324
#include <chrono>
2425
#include <iostream>
@@ -677,3 +678,42 @@ TEST_F(HwHelperTest, givenVariousCachesRequestProperMOCSIndexesAreBeingReturned)
677678
EXPECT_EQ(expectedMocsForL3andL1on, mocsIndex);
678679
}
679680
}
681+
682+
HWTEST_F(HwHelperTest, givenHwHelperWhenAskingForTilingSupportThenReturnValidValue) {
683+
bool tilingSupported = UnitTestHelper<FamilyType>::tiledImagesSupported;
684+
685+
const uint32_t numImageTypes = 6;
686+
const cl_mem_object_type imgTypes[numImageTypes] = {CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE1D_ARRAY, CL_MEM_OBJECT_IMAGE1D_BUFFER,
687+
CL_MEM_OBJECT_IMAGE2D, CL_MEM_OBJECT_IMAGE2D_ARRAY, CL_MEM_OBJECT_IMAGE3D};
688+
cl_image_desc imgDesc = {};
689+
MockContext context;
690+
cl_int retVal = CL_SUCCESS;
691+
auto buffer = std::unique_ptr<Buffer>(Buffer::create(&context, 0, 1, nullptr, retVal));
692+
693+
auto &helper = HwHelper::get(renderCoreFamily);
694+
695+
for (uint32_t i = 0; i < numImageTypes; i++) {
696+
imgDesc.image_type = imgTypes[i];
697+
imgDesc.buffer = nullptr;
698+
699+
bool allowedType = imgTypes[i] == (CL_MEM_OBJECT_IMAGE2D) || (imgTypes[i] == CL_MEM_OBJECT_IMAGE3D) ||
700+
(imgTypes[i] == CL_MEM_OBJECT_IMAGE2D_ARRAY);
701+
702+
// non shared context, dont force linear storage
703+
EXPECT_EQ((tilingSupported & allowedType), helper.tilingAllowed(false, imgDesc, false));
704+
{
705+
DebugManagerStateRestore restore;
706+
DebugManager.flags.ForceLinearImages.set(true);
707+
// non shared context, dont force linear storage + debug flag
708+
EXPECT_FALSE(helper.tilingAllowed(false, imgDesc, false));
709+
}
710+
// shared context, dont force linear storage
711+
EXPECT_FALSE(helper.tilingAllowed(true, imgDesc, false));
712+
// non shared context, force linear storage
713+
EXPECT_FALSE(helper.tilingAllowed(false, imgDesc, true));
714+
715+
// non shared context, dont force linear storage + create from buffer
716+
imgDesc.buffer = buffer.get();
717+
EXPECT_FALSE(helper.tilingAllowed(false, imgDesc, false));
718+
}
719+
}

unit_tests/helpers/unit_test_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ struct UnitTestHelper {
3333
static bool isPipeControlWArequired(const HardwareInfo &hwInfo);
3434

3535
static uint64_t getMemoryAddress(const typename GfxFamily::MI_ATOMIC &atomic);
36+
37+
static const bool tiledImagesSupported;
3638
};
3739
} // namespace NEO

0 commit comments

Comments
 (0)