File: ocloc_validator.cpp

package info (click to toggle)
intel-compute-runtime 20.44.18297-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,780 kB
  • sloc: cpp: 379,729; lisp: 4,931; python: 299; sh: 196; makefile: 8
file content (95 lines) | stat: -rw-r--r-- 3,769 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright (C) 2020 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/offline_compiler/source/ocloc_validator.h"

#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/source/device_binary_format/device_binary_formats.h"
#include "shared/source/program/program_info.h"

#include "opencl/source/program/kernel_info.h"

namespace NEO {
ProgramInfo::~ProgramInfo() {
    for (auto &kernelInfo : kernelInfos) {
        delete kernelInfo;
    }
    kernelInfos.clear();
}

KernelInfo::~KernelInfo() {
    kernelArgInfo.clear();

    patchInfo.stringDataMap.clear();
    delete[] crossThreadData;
}

namespace Ocloc {

int validate(const std::vector<std::string> &args, OclocArgHelper *argHelper) {
    NEO::ProgramInfo programInfo;
    NEO::SingleDeviceBinary deviceBinary;
    std::string errors;
    std::string warnings;
    UNRECOVERABLE_IF(nullptr == argHelper)
    std::string fileName;
    for (uint32_t i = 0; i < args.size(); ++i) {
        if (args.size() > (i + 1) && (ConstStringRef("-file") == args[i])) {
            fileName = args[i + 1];
        }
    }
    if (fileName.empty()) {
        argHelper->printf("Error : Mandatory argument -file is missing.\n");
        return -1;
    }

    if (false == argHelper->fileExists(fileName)) {
        argHelper->printf("Error : Input file missing : %s\n", fileName.c_str());
        return -1;
    }

    auto fileData = argHelper->readBinaryFile(fileName);
    argHelper->printf("Validating : %s (%d bytes).\n", fileName.c_str(), fileData.size());

    deviceBinary.deviceBinary = deviceBinary.deviceBinary.fromAny(fileData.data(), fileData.size());
    if (false == NEO::isDeviceBinaryFormat<DeviceBinaryFormat::Zebin>(deviceBinary.deviceBinary)) {
        argHelper->printf("Input is not a Zebin file (not elf or wrong elf object file type)\n", errors.c_str());
        return -2;
    }
    auto decodeResult = NEO::decodeSingleDeviceBinary<DeviceBinaryFormat::Zebin>(programInfo, deviceBinary, errors, warnings);
    if (false == warnings.empty()) {
        argHelper->printf("Validator detected potential problems :\n%s\n", warnings.c_str());
    }
    if (false == errors.empty()) {
        argHelper->printf("Validator detected errors :\n%s\n", errors.c_str());
    }

    argHelper->printf("Binary is %s (%s).\n", ((NEO::DecodeError::Success == decodeResult) ? "VALID" : "INVALID"), NEO::asString(decodeResult));
    if (NEO::DecodeError::Success == decodeResult) {
        argHelper->printf("Statistics : \n");
        if (0 != programInfo.globalVariables.size) {
            argHelper->printf("Binary contains global variables section of size :  %d.\n", programInfo.globalVariables.size);
        }
        if (0 != programInfo.globalConstants.size) {
            argHelper->printf("Binary contains global constants section of size :  %d.\n", programInfo.globalConstants.size);
        }
        argHelper->printf("Binary contains %d kernels.\n", programInfo.kernelInfos.size());
        for (size_t i = 0U; i < programInfo.kernelInfos.size(); ++i) {
            const auto &kernelDescriptor = programInfo.kernelInfos[i]->kernelDescriptor;
            argHelper->printf("\nKernel #%d named %s:\n", static_cast<int>(i), kernelDescriptor.kernelMetadata.kernelName.c_str());
            argHelper->printf(" * Number of binding table entries %d:\n", kernelDescriptor.payloadMappings.bindingTable.numEntries);
            argHelper->printf(" * Cross-thread data size %d:\n", kernelDescriptor.kernelAttributes.crossThreadDataSize);
            argHelper->printf(" * Per-thread data size %d:\n", kernelDescriptor.kernelAttributes.perThreadDataSize);
        }
    }

    return static_cast<int>(decodeResult);
}

} // namespace Ocloc

} // namespace NEO