compute-runtime/opencl/test/unit_test/fixtures/kernel_data_fixture.cpp

130 lines
5.1 KiB
C++
Raw Normal View History

/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/test/unit_test/fixtures/kernel_data_fixture.h"
#include "shared/source/device_binary_format/patchtokens_decoder.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/string.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/program/program_info_from_patchtokens.h"
void KernelDataTest::buildAndDecode() {
cl_int error = CL_SUCCESS;
kernelBinaryHeader.CheckSum = checkSum;
kernelBinaryHeader.DynamicStateHeapSize = dshSize;
kernelBinaryHeader.GeneralStateHeapSize = gshSize;
kernelBinaryHeader.KernelHeapSize = kernelHeapSize;
kernelBinaryHeader.KernelNameSize = kernelNameSize;
kernelBinaryHeader.KernelUnpaddedSize = kernelUnpaddedSize;
kernelBinaryHeader.PatchListSize = patchListSize + sizeof(SPatchDataParameterStream);
kernelBinaryHeader.ShaderHashCode = shaderHashCode;
kernelBinaryHeader.SurfaceStateHeapSize = sshSize;
kernelDataSize = sizeof(SKernelBinaryHeaderCommon) +
kernelNameSize + sshSize + dshSize + gshSize + kernelHeapSize + patchListSize;
kernelDataSize += sizeof(SPatchDataParameterStream);
pKernelData = static_cast<char *>(alignedMalloc(kernelDataSize, MemoryConstants::cacheLineSize));
ASSERT_NE(nullptr, pKernelData);
// kernel blob
pCurPtr = pKernelData;
// kernel header
// first clear it because sizeof() > sum of sizeof(fields). this is due to packing
memset(pCurPtr, 0, sizeof(SKernelBinaryHeaderCommon));
*(SKernelBinaryHeaderCommon *)pCurPtr = kernelBinaryHeader;
pCurPtr += sizeof(SKernelBinaryHeaderCommon);
// kernel name
memset(pCurPtr, 0, kernelNameSize);
strcpy_s(pCurPtr, strlen(kernelName.c_str()) + 1, kernelName.c_str());
pCurPtr += kernelNameSize;
// kernel heap
memcpy_s(pCurPtr, kernelHeapSize, pKernelHeap, kernelHeapSize);
pCurPtr += kernelHeapSize;
// general state heap
memcpy_s(pCurPtr, gshSize, pGsh, gshSize);
pCurPtr += gshSize;
// dynamic state heap
memcpy_s(pCurPtr, dshSize, pDsh, dshSize);
pCurPtr += dshSize;
// surface state heap
memcpy_s(pCurPtr, sshSize, pSsh, sshSize);
pCurPtr += sshSize;
// patch list
memcpy_s(pCurPtr, patchListSize, pPatchList, patchListSize);
pCurPtr += patchListSize;
// add a data stream member
iOpenCL::SPatchDataParameterStream dataParameterStream;
dataParameterStream.Token = PATCH_TOKEN_DATA_PARAMETER_STREAM;
dataParameterStream.Size = sizeof(SPatchDataParameterStream);
dataParameterStream.DataParameterStreamSize = 0x40;
memcpy_s(pCurPtr, sizeof(SPatchDataParameterStream),
&dataParameterStream, sizeof(SPatchDataParameterStream));
pCurPtr += sizeof(SPatchDataParameterStream);
// now build a program with this kernel data
iOpenCL::SProgramBinaryHeader header = {};
NEO::PatchTokenBinary::ProgramFromPatchtokens programFromPatchtokens;
programFromPatchtokens.decodeStatus = DecodeError::Success;
programFromPatchtokens.header = &header;
programFromPatchtokens.kernels.resize(1);
auto &kernelFromPatchtokens = *programFromPatchtokens.kernels.rbegin();
auto kernelBlob = ArrayRef<const uint8_t>(reinterpret_cast<const uint8_t *>(pKernelData), kernelDataSize);
bool decodeSuccess = NEO::PatchTokenBinary::decodeKernelFromPatchtokensBlob(kernelBlob, kernelFromPatchtokens);
EXPECT_TRUE(decodeSuccess);
ProgramInfo programInfo;
NEO::populateProgramInfo(programInfo, programFromPatchtokens);
error = program->processProgramInfo(programInfo, *pContext->getDevice(0));
EXPECT_EQ(CL_SUCCESS, error);
// extract the kernel info
pKernelInfo = program->Program::getKernelInfo(kernelName.c_str(), rootDeviceIndex);
// validate name
EXPECT_STREQ(pKernelInfo->kernelDescriptor.kernelMetadata.kernelName.c_str(), kernelName.c_str());
// validate each heap
Add braces to avoid ambiguous 'else' For the new Linux/Fedora configuration with introduction of gcc 7.2, compilation of this file issues a new warning due to the correct diagnosis of an ambiguous 'else'. As warnings are being treated as errors, this aborts the build. The diagnostic: vpg-compute-neo/unit_tests/elflib/elflib_tests.cpp:123:12: error: suggest explicit braces to avoid ambiguous 'else' [-Werror=dangling-else] if (nonfailingAllocation == failureIndex) ^ Diagnosis: The diagnostic suggested that this: if (nonfailingAllocation == failureIndex) ASSERT_NE(nullptr, pWriter); should be changed to: if (nonfailingAllocation == failureIndex) { ASSERT_NE(nullptr, pWriter); } This is a valid suggestion. The same is true for EXPECT_EQ. Pick the files in repository ssh://gerrit-gfx.intel.com:29418/mirrors/github/google/googletest for tracing the definition. (There are many versions of gtest.h under the ufo tree). Starting in file include/gtest/gtest.h, the definition of ASSERT_NE can be traced back towards its origin as follows: ASSERT_NE include/gtest/gtest.h GTEST_ASSERT_NE include/gtest/gtest.h ASSERT_PRED_FORMAT2 include/gtest/gtest_pred_impl.h GTEST_PRED_FORMAT2_ include/gtest/gtest_pred_impl.h GTEST_ASSERT_ include/gtest/gtest_pred_impl.h where GTEST_ASSERT_ indeed *should* be enclosed in braces. GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const ::testing::AssertionResult gtest_ar = (expression)) \ ; \ else \ on_failure(gtest_ar.failure_message()) The correct fix would be to place the braces in the macro definition. However, as file gtest.h comes from Google, and as there are 37 different versions of it in the source tree, this workaround will address the macro invocations. Should it be desirable, it is left to others to correct gtest.h and friends. Change-Id: I870d38ba623fc7564f894c7b1ea7512b74244ee2 Signed-off-by: Dale Stimson <dale.b.stimson@intel.com>
2018-01-24 09:00:40 +08:00
if (pKernelHeap != nullptr) {
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pKernelHeap, pKernelHeap, kernelHeapSize));
Add braces to avoid ambiguous 'else' For the new Linux/Fedora configuration with introduction of gcc 7.2, compilation of this file issues a new warning due to the correct diagnosis of an ambiguous 'else'. As warnings are being treated as errors, this aborts the build. The diagnostic: vpg-compute-neo/unit_tests/elflib/elflib_tests.cpp:123:12: error: suggest explicit braces to avoid ambiguous 'else' [-Werror=dangling-else] if (nonfailingAllocation == failureIndex) ^ Diagnosis: The diagnostic suggested that this: if (nonfailingAllocation == failureIndex) ASSERT_NE(nullptr, pWriter); should be changed to: if (nonfailingAllocation == failureIndex) { ASSERT_NE(nullptr, pWriter); } This is a valid suggestion. The same is true for EXPECT_EQ. Pick the files in repository ssh://gerrit-gfx.intel.com:29418/mirrors/github/google/googletest for tracing the definition. (There are many versions of gtest.h under the ufo tree). Starting in file include/gtest/gtest.h, the definition of ASSERT_NE can be traced back towards its origin as follows: ASSERT_NE include/gtest/gtest.h GTEST_ASSERT_NE include/gtest/gtest.h ASSERT_PRED_FORMAT2 include/gtest/gtest_pred_impl.h GTEST_PRED_FORMAT2_ include/gtest/gtest_pred_impl.h GTEST_ASSERT_ include/gtest/gtest_pred_impl.h where GTEST_ASSERT_ indeed *should* be enclosed in braces. GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const ::testing::AssertionResult gtest_ar = (expression)) \ ; \ else \ on_failure(gtest_ar.failure_message()) The correct fix would be to place the braces in the macro definition. However, as file gtest.h comes from Google, and as there are 37 different versions of it in the source tree, this workaround will address the macro invocations. Should it be desirable, it is left to others to correct gtest.h and friends. Change-Id: I870d38ba623fc7564f894c7b1ea7512b74244ee2 Signed-off-by: Dale Stimson <dale.b.stimson@intel.com>
2018-01-24 09:00:40 +08:00
}
if (pGsh != nullptr) {
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pGsh, pGsh, gshSize));
Add braces to avoid ambiguous 'else' For the new Linux/Fedora configuration with introduction of gcc 7.2, compilation of this file issues a new warning due to the correct diagnosis of an ambiguous 'else'. As warnings are being treated as errors, this aborts the build. The diagnostic: vpg-compute-neo/unit_tests/elflib/elflib_tests.cpp:123:12: error: suggest explicit braces to avoid ambiguous 'else' [-Werror=dangling-else] if (nonfailingAllocation == failureIndex) ^ Diagnosis: The diagnostic suggested that this: if (nonfailingAllocation == failureIndex) ASSERT_NE(nullptr, pWriter); should be changed to: if (nonfailingAllocation == failureIndex) { ASSERT_NE(nullptr, pWriter); } This is a valid suggestion. The same is true for EXPECT_EQ. Pick the files in repository ssh://gerrit-gfx.intel.com:29418/mirrors/github/google/googletest for tracing the definition. (There are many versions of gtest.h under the ufo tree). Starting in file include/gtest/gtest.h, the definition of ASSERT_NE can be traced back towards its origin as follows: ASSERT_NE include/gtest/gtest.h GTEST_ASSERT_NE include/gtest/gtest.h ASSERT_PRED_FORMAT2 include/gtest/gtest_pred_impl.h GTEST_PRED_FORMAT2_ include/gtest/gtest_pred_impl.h GTEST_ASSERT_ include/gtest/gtest_pred_impl.h where GTEST_ASSERT_ indeed *should* be enclosed in braces. GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const ::testing::AssertionResult gtest_ar = (expression)) \ ; \ else \ on_failure(gtest_ar.failure_message()) The correct fix would be to place the braces in the macro definition. However, as file gtest.h comes from Google, and as there are 37 different versions of it in the source tree, this workaround will address the macro invocations. Should it be desirable, it is left to others to correct gtest.h and friends. Change-Id: I870d38ba623fc7564f894c7b1ea7512b74244ee2 Signed-off-by: Dale Stimson <dale.b.stimson@intel.com>
2018-01-24 09:00:40 +08:00
}
if (pDsh != nullptr) {
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pDsh, pDsh, dshSize));
Add braces to avoid ambiguous 'else' For the new Linux/Fedora configuration with introduction of gcc 7.2, compilation of this file issues a new warning due to the correct diagnosis of an ambiguous 'else'. As warnings are being treated as errors, this aborts the build. The diagnostic: vpg-compute-neo/unit_tests/elflib/elflib_tests.cpp:123:12: error: suggest explicit braces to avoid ambiguous 'else' [-Werror=dangling-else] if (nonfailingAllocation == failureIndex) ^ Diagnosis: The diagnostic suggested that this: if (nonfailingAllocation == failureIndex) ASSERT_NE(nullptr, pWriter); should be changed to: if (nonfailingAllocation == failureIndex) { ASSERT_NE(nullptr, pWriter); } This is a valid suggestion. The same is true for EXPECT_EQ. Pick the files in repository ssh://gerrit-gfx.intel.com:29418/mirrors/github/google/googletest for tracing the definition. (There are many versions of gtest.h under the ufo tree). Starting in file include/gtest/gtest.h, the definition of ASSERT_NE can be traced back towards its origin as follows: ASSERT_NE include/gtest/gtest.h GTEST_ASSERT_NE include/gtest/gtest.h ASSERT_PRED_FORMAT2 include/gtest/gtest_pred_impl.h GTEST_PRED_FORMAT2_ include/gtest/gtest_pred_impl.h GTEST_ASSERT_ include/gtest/gtest_pred_impl.h where GTEST_ASSERT_ indeed *should* be enclosed in braces. GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const ::testing::AssertionResult gtest_ar = (expression)) \ ; \ else \ on_failure(gtest_ar.failure_message()) The correct fix would be to place the braces in the macro definition. However, as file gtest.h comes from Google, and as there are 37 different versions of it in the source tree, this workaround will address the macro invocations. Should it be desirable, it is left to others to correct gtest.h and friends. Change-Id: I870d38ba623fc7564f894c7b1ea7512b74244ee2 Signed-off-by: Dale Stimson <dale.b.stimson@intel.com>
2018-01-24 09:00:40 +08:00
}
if (pSsh != nullptr) {
EXPECT_EQ(0, memcmp(pKernelInfo->heapInfo.pSsh, pSsh, sshSize));
Add braces to avoid ambiguous 'else' For the new Linux/Fedora configuration with introduction of gcc 7.2, compilation of this file issues a new warning due to the correct diagnosis of an ambiguous 'else'. As warnings are being treated as errors, this aborts the build. The diagnostic: vpg-compute-neo/unit_tests/elflib/elflib_tests.cpp:123:12: error: suggest explicit braces to avoid ambiguous 'else' [-Werror=dangling-else] if (nonfailingAllocation == failureIndex) ^ Diagnosis: The diagnostic suggested that this: if (nonfailingAllocation == failureIndex) ASSERT_NE(nullptr, pWriter); should be changed to: if (nonfailingAllocation == failureIndex) { ASSERT_NE(nullptr, pWriter); } This is a valid suggestion. The same is true for EXPECT_EQ. Pick the files in repository ssh://gerrit-gfx.intel.com:29418/mirrors/github/google/googletest for tracing the definition. (There are many versions of gtest.h under the ufo tree). Starting in file include/gtest/gtest.h, the definition of ASSERT_NE can be traced back towards its origin as follows: ASSERT_NE include/gtest/gtest.h GTEST_ASSERT_NE include/gtest/gtest.h ASSERT_PRED_FORMAT2 include/gtest/gtest_pred_impl.h GTEST_PRED_FORMAT2_ include/gtest/gtest_pred_impl.h GTEST_ASSERT_ include/gtest/gtest_pred_impl.h where GTEST_ASSERT_ indeed *should* be enclosed in braces. GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const ::testing::AssertionResult gtest_ar = (expression)) \ ; \ else \ on_failure(gtest_ar.failure_message()) The correct fix would be to place the braces in the macro definition. However, as file gtest.h comes from Google, and as there are 37 different versions of it in the source tree, this workaround will address the macro invocations. Should it be desirable, it is left to others to correct gtest.h and friends. Change-Id: I870d38ba623fc7564f894c7b1ea7512b74244ee2 Signed-off-by: Dale Stimson <dale.b.stimson@intel.com>
2018-01-24 09:00:40 +08:00
}
if (kernelHeapSize) {
auto kernelAllocation = pKernelInfo->getGraphicsAllocation();
UNRECOVERABLE_IF(kernelAllocation == nullptr);
auto &device = pContext->getDevice(0)->getDevice();
auto &helper = device.getRootDeviceEnvironment().getHelper<GfxCoreHelper>();
size_t isaPadding = helper.getPaddingForISAAllocation();
EXPECT_EQ(kernelAllocation->getUnderlyingBufferSize(), kernelHeapSize + isaPadding);
auto kernelIsa = kernelAllocation->getUnderlyingBuffer();
EXPECT_EQ(0, memcmp(kernelIsa, pKernelInfo->heapInfo.pKernelHeap, kernelHeapSize));
} else {
EXPECT_EQ(nullptr, pKernelInfo->getGraphicsAllocation());
}
}