Skip to content

Commit 614b69a

Browse files
jchodorCompute-Runtime-Automation
authored andcommitted
Adding support for get_image_num_mip_levels
* patch token decoding * crossthread data patching * additionally, fixing nasty ODR violation in VA tests (note : ODR = One Definition Rule) Change-Id: I9803ed599826c97359349d2b8fa0d86e46cb33ea
1 parent f6a9e3f commit 614b69a

File tree

12 files changed

+283
-199
lines changed

12 files changed

+283
-199
lines changed

runtime/kernel/kernel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ cl_int Kernel::setArgImageWithMipLevel(uint32_t argIndex,
12351235
patch<uint32_t, cl_channel_type>(imageFormat.image_channel_data_type, crossThreadData, kernelArgInfo.offsetChannelDataType);
12361236
patch<uint32_t, cl_channel_order>(imageFormat.image_channel_order, crossThreadData, kernelArgInfo.offsetChannelOrder);
12371237
patch<uint32_t, uint32_t>(kernelArgInfo.offsetHeap, crossThreadData, kernelArgInfo.offsetObjectId);
1238+
patch<uint32_t, cl_uint>(imageDesc.num_mip_levels, crossThreadData, kernelArgInfo.offsetNumMipLevels);
12381239

12391240
retVal = CL_SUCCESS;
12401241
}

runtime/program/kernel_arg_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct KernelArgInfo {
6767
uint32_t offsetVmeSearchPathType = undefinedOffset;
6868
uint32_t offsetObjectId = undefinedOffset;
6969
uint32_t offsetBufferOffset = undefinedOffset;
70+
uint32_t offsetNumMipLevels = undefinedOffset;
7071

7172
bool needPatch = false;
7273
bool isTransformable = false;

runtime/program/process_gen_binary.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ cl_int Program::parsePatchList(KernelInfo &kernelInfo) {
430430
break;
431431

432432
case DATA_PARAMETER_IMAGE_NUM_MIP_LEVELS:
433+
DBG_LOG(LogPatchTokens, "\n .Type", "IMAGE_NUM_MIP_LEVELS");
434+
kernelInfo.resizeKernelArgInfoAndRegisterParameter(argNum);
435+
kernelInfo.kernelArgInfo[argNum].offsetNumMipLevels = pDataParameterBuffer->Offset;
436+
DEBUG_BREAK_IF(pDataParameterBuffer->DataSize != sizeof(uint32_t));
437+
break;
433438
case DATA_PARAMETER_IMAGE_SRGB_CHANNEL_ORDER:
434439
case DATA_PARAMETER_STAGE_IN_GRID_ORIGIN:
435440
case DATA_PARAMETER_STAGE_IN_GRID_SIZE:

unit_tests/fixtures/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ set(IGDRCL_SRCS_tests_fixtures
3232
${CMAKE_CURRENT_SOURCE_DIR}/hello_world_kernel_fixture.h
3333
${CMAKE_CURRENT_SOURCE_DIR}/image_fixture.cpp
3434
${CMAKE_CURRENT_SOURCE_DIR}/image_fixture.h
35+
${CMAKE_CURRENT_SOURCE_DIR}/kernel_arg_fixture.cpp
36+
${CMAKE_CURRENT_SOURCE_DIR}/kernel_arg_fixture.h
3537
${CMAKE_CURRENT_SOURCE_DIR}/kernel_data_fixture.cpp
3638
${CMAKE_CURRENT_SOURCE_DIR}/kernel_data_fixture.h
3739
${CMAKE_CURRENT_SOURCE_DIR}/media_kernel_fixture.h
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "unit_tests/fixtures/kernel_arg_fixture.h"
24+
25+
#include "unit_tests/fixtures/image_fixture.h"
26+
#include "unit_tests/mocks/mock_context.h"
27+
#include "unit_tests/mocks/mock_kernel.h"
28+
#include "unit_tests/mocks/mock_program.h"
29+
#include "unit_tests/mocks/mock_image.h"
30+
31+
KernelImageArgTest::~KernelImageArgTest() = default;
32+
33+
void KernelImageArgTest::SetUp() {
34+
pKernelInfo.reset(OCLRT::KernelInfo::create());
35+
KernelArgPatchInfo kernelArgPatchInfo;
36+
kernelHeader.reset(new iOpenCL::SKernelBinaryHeaderCommon{});
37+
38+
kernelHeader->SurfaceStateHeapSize = sizeof(surfaceStateHeap);
39+
pKernelInfo->heapInfo.pSsh = surfaceStateHeap;
40+
pKernelInfo->heapInfo.pKernelHeader = kernelHeader.get();
41+
pKernelInfo->usesSsh = true;
42+
43+
pKernelInfo->kernelArgInfo.resize(5);
44+
pKernelInfo->kernelArgInfo[4].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
45+
pKernelInfo->kernelArgInfo[3].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
46+
pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
47+
pKernelInfo->kernelArgInfo[1].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
48+
pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
49+
50+
pKernelInfo->kernelArgInfo[0].offsetImgWidth = 0x4;
51+
pKernelInfo->kernelArgInfo[0].offsetNumSamples = 0x3c;
52+
offsetNumMipLevelsImage0 = 0x40;
53+
pKernelInfo->kernelArgInfo[0].offsetNumMipLevels = offsetNumMipLevelsImage0;
54+
pKernelInfo->kernelArgInfo[1].offsetImgHeight = 0xc;
55+
pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector[0].crossthreadOffset = 0x20;
56+
pKernelInfo->kernelArgInfo[2].kernelArgPatchInfoVector[0].size = sizeof(void *);
57+
pKernelInfo->kernelArgInfo[3].offsetImgDepth = 0x30;
58+
pKernelInfo->kernelArgInfo[4].offsetHeap = 0x20;
59+
pKernelInfo->kernelArgInfo[4].offsetObjectId = 0x0;
60+
61+
pKernelInfo->kernelArgInfo[4].isImage = true;
62+
pKernelInfo->kernelArgInfo[3].isImage = true;
63+
pKernelInfo->kernelArgInfo[2].isImage = true;
64+
pKernelInfo->kernelArgInfo[1].isImage = true;
65+
pKernelInfo->kernelArgInfo[0].isImage = true;
66+
67+
DeviceFixture::SetUp();
68+
program.reset(new OCLRT::MockProgram);
69+
pKernel.reset(new OCLRT::MockKernel(program.get(), *pKernelInfo, *pDevice));
70+
ASSERT_EQ(CL_SUCCESS, pKernel->initialize());
71+
72+
pKernel->setKernelArgHandler(0, &OCLRT::Kernel::setArgImage);
73+
pKernel->setKernelArgHandler(1, &OCLRT::Kernel::setArgImage);
74+
pKernel->setKernelArgHandler(2, &OCLRT::Kernel::setArgImmediate);
75+
pKernel->setKernelArgHandler(3, &OCLRT::Kernel::setArgImage);
76+
pKernel->setKernelArgHandler(4, &OCLRT::Kernel::setArgImage);
77+
78+
uint32_t crossThreadData[0x44] = {};
79+
crossThreadData[0x20 / sizeof(uint32_t)] = 0x12344321;
80+
pKernel->setCrossThreadData(crossThreadData, sizeof(crossThreadData));
81+
82+
context.reset(new OCLRT::MockContext(pDevice));
83+
image.reset(Image2dHelper<>::create(context.get()));
84+
ASSERT_NE(nullptr, image);
85+
}
86+
87+
void KernelImageArgTest::TearDown() {
88+
image.reset();
89+
pKernel.reset();
90+
program.reset();
91+
context.reset();
92+
DeviceFixture::TearDown();
93+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#pragma once
24+
25+
#include "unit_tests/fixtures/device_fixture.h"
26+
#include "unit_tests/gen_common/test.h"
27+
28+
#include <cstdint>
29+
30+
namespace OCLRT {
31+
class MockContext;
32+
class MockKernel;
33+
class MockProgram;
34+
class Image;
35+
struct KernelInfo;
36+
}
37+
38+
namespace iOpenCL {
39+
struct SKernelBinaryHeaderCommon;
40+
}
41+
42+
class KernelImageArgTest : public Test<DeviceFixture> {
43+
public:
44+
KernelImageArgTest() {
45+
}
46+
47+
~KernelImageArgTest() override;
48+
49+
protected:
50+
void SetUp() override;
51+
52+
void TearDown() override;
53+
54+
cl_int retVal = 0;
55+
std::unique_ptr<iOpenCL::SKernelBinaryHeaderCommon> kernelHeader;
56+
std::unique_ptr<OCLRT::MockContext> context;
57+
std::unique_ptr<OCLRT::MockProgram> program;
58+
std::unique_ptr<OCLRT::KernelInfo> pKernelInfo;
59+
std::unique_ptr<OCLRT::MockKernel> pKernel;
60+
std::unique_ptr<OCLRT::Image> image;
61+
62+
char surfaceStateHeap[0x80];
63+
uint32_t offsetNumMipLevelsImage0 = -1;
64+
};

unit_tests/helpers/mipmap_tests.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "runtime/mem_obj/image.h"
2525
#include "unit_tests/mocks/mock_buffer.h"
2626
#include "unit_tests/mocks/mock_gmm.h"
27+
#include "unit_tests/mocks/mock_image.h"
2728

2829
#include "gtest/gtest.h"
2930

@@ -107,40 +108,17 @@ struct MockMipMapGmmResourceInfo : GmmResourceInfo {
107108
}
108109
};
109110

110-
struct MockImage : public OCLRT::Image {
111-
using Image::imageDesc;
112-
using Image::graphicsAllocation;
113-
111+
struct MockImage : MockImageBase {
114112
MockGmm mockGmm;
115113

116-
MockImage() : Image(nullptr, cl_mem_flags{}, 0, nullptr, cl_image_format{},
117-
cl_image_desc{}, false, new MockGraphicsAllocation(nullptr, 0), false, false,
118-
0, 0, SurfaceFormatInfo{}, nullptr) {
114+
MockImage() : MockImageBase() {
119115
graphicsAllocation->gmm = &mockGmm;
120116
mockGmm.gmmResourceInfo.reset(new MockMipMapGmmResourceInfo());
121117
}
122-
~MockImage() override {
123-
delete this->graphicsAllocation;
124-
}
125-
126-
MockGraphicsAllocation *getAllocation() {
127-
return static_cast<MockGraphicsAllocation *>(graphicsAllocation);
128-
}
129118

130119
MockMipMapGmmResourceInfo *getResourceInfo() {
131120
return static_cast<MockMipMapGmmResourceInfo *>(mockGmm.gmmResourceInfo.get());
132121
}
133-
134-
void setImageArg(void *memory, bool isMediaBlockImage, uint32_t mipLevel) override {
135-
}
136-
void setMediaImageArg(void *memory) override {
137-
}
138-
void setMediaSurfaceRotation(void *memory) override {
139-
}
140-
void setSurfaceMemoryObjectControlStateIndexToMocsTable(void *memory, uint32_t value) override {
141-
}
142-
void transformImage2dArrayTo3d(void *memory) override {}
143-
void transformImage3dTo2dArray(void *memory) override {}
144122
};
145123

146124
TEST(MipmapHelper, givenImageWithoutMipLevelsWhenIsMipMappedIsCalledThenFalseIsReturned) {

0 commit comments

Comments
 (0)