From d3ed744c1be089d87bb7bdc8faeede0bc4031713 Mon Sep 17 00:00:00 2001 From: "Chodor, Jaroslaw" Date: Fri, 14 Jun 2019 06:26:39 +0200 Subject: [PATCH] Minimalistic kernel dump in ocloc Resolves: NEO-2118 Change-Id: I7358ad991621114e287b1851cfce6254c76b63c1 --- offline_compiler/decoder/binary_decoder.cpp | 56 +++++++++++++++---- .../decoder/decoder_tests.cpp | 8 +++ 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/offline_compiler/decoder/binary_decoder.cpp b/offline_compiler/decoder/binary_decoder.cpp index d8626951d2..c73ded64f2 100644 --- a/offline_compiler/decoder/binary_decoder.cpp +++ b/offline_compiler/decoder/binary_decoder.cpp @@ -120,15 +120,53 @@ uint8_t BinaryDecoder::getSize(const std::string &typeStr) { } void BinaryDecoder::parseTokens() { - //Reading neccesary files + //Creating patchlist definitions std::vector patchList; - readFileToVectorOfStrings(patchList, pathToPatch + "patch_list.h", true); - readFileToVectorOfStrings(patchList, pathToPatch + "patch_shared.h", true); - readFileToVectorOfStrings(patchList, pathToPatch + "patch_g7.h", true); - readFileToVectorOfStrings(patchList, pathToPatch + "patch_g8.h", true); - readFileToVectorOfStrings(patchList, pathToPatch + "patch_g9.h", true); - readFileToVectorOfStrings(patchList, pathToPatch + "patch_g10.h", true); + if (pathToPatch.empty()) { + messagePrinter.printf("Path to patch list not provided - using defaults, skipping patchokens as undefined.\n"); + patchList = { + "struct SProgramBinaryHeader", + "{", + " uint32_t Magic;", + " uint32_t Version;", + " uint32_t Device;", + " uint32_t GPUPointerSizeInBytes;", + " uint32_t NumberOfKernels;", + " uint32_t SteppingId;", + " uint32_t PatchListSize;", + "};", + "", + "struct SKernelBinaryHeader", + "{", + " uint32_t CheckSum;", + " uint64_t ShaderHashCode;", + " uint32_t KernelNameSize;", + " uint32_t PatchListSize;", + "};", + "", + "struct SKernelBinaryHeaderCommon :", + " SKernelBinaryHeader", + "{", + " uint32_t KernelHeapSize;", + " uint32_t GeneralStateHeapSize;", + " uint32_t DynamicStateHeapSize;", + " uint32_t SurfaceStateHeapSize;", + " uint32_t KernelUnpaddedSize;", + "};", + "", + "enum PATCH_TOKEN", + "{", + "};", + }; + } else { + readFileToVectorOfStrings(patchList, pathToPatch + "patch_list.h", true); + readFileToVectorOfStrings(patchList, pathToPatch + "patch_shared.h", true); + readFileToVectorOfStrings(patchList, pathToPatch + "patch_g7.h", true); + readFileToVectorOfStrings(patchList, pathToPatch + "patch_g8.h", true); + readFileToVectorOfStrings(patchList, pathToPatch + "patch_g9.h", true); + readFileToVectorOfStrings(patchList, pathToPatch + "patch_g10.h", true); + } size_t pos = findPos(patchList, "struct SProgramBinaryHeader"); if (pos == patchList.size()) { @@ -392,10 +430,6 @@ int BinaryDecoder::validateInput(uint32_t argc, const char **argv) { messagePrinter.printf(".bin extension is expected for binary file.\n"); printHelp(); return -1; - } else if (pathToPatch.empty()) { - messagePrinter.printf("Path to patch list folder can't be empty.\n"); - printHelp(); - return -1; } else if (pathToDump.empty()) { messagePrinter.printf("Path to dump folder can't be empty.\n"); printHelp(); diff --git a/unit_tests/offline_compiler/decoder/decoder_tests.cpp b/unit_tests/offline_compiler/decoder/decoder_tests.cpp index 3518da6626..3cbf0bda78 100644 --- a/unit_tests/offline_compiler/decoder/decoder_tests.cpp +++ b/unit_tests/offline_compiler/decoder/decoder_tests.cpp @@ -178,6 +178,14 @@ TEST(DecoderTests, GivenProperPatchListFileWhenParsingTokensThenFileIsParsedCorr EXPECT_EQ("InterfaceDescriptorDataOffset", (decoder.patchTokens[19]->fields[0].name)); } +TEST(DecoderTests, WhenPathToPatchTokensNotProvidedThenUseDefaults) { + MockDecoder decoder; + decoder.pathToPatch = ""; + decoder.parseTokens(); + EXPECT_NE(0U, decoder.programHeader.size); + EXPECT_NE(0U, decoder.kernelHeader.size); +} + TEST(DecoderTests, GivenValidBinaryWhenReadingPatchTokensFromBinaryThenBinaryIsReadCorrectly) { std::string binaryString; std::stringstream binarySS;