File: device_binary_format_patchtokens.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 (64 lines) | stat: -rw-r--r-- 2,676 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
/*
 * Copyright (C) 2020 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/device_binary_format/device_binary_formats.h"
#include "shared/source/device_binary_format/patchtokens_decoder.h"
#include "shared/source/device_binary_format/patchtokens_dumper.h"
#include "shared/source/device_binary_format/patchtokens_validator.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/program/program_info_from_patchtokens.h"

#include "opencl/source/utilities/logger.h"

namespace NEO {

template <>
bool isDeviceBinaryFormat<NEO::DeviceBinaryFormat::Patchtokens>(const ArrayRef<const uint8_t> binary) {
    return NEO::PatchTokenBinary::isValidPatchTokenBinary(binary);
}

template <>
SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Patchtokens>(const ArrayRef<const uint8_t> archive, const ConstStringRef requestedProductAbbreviation, const TargetDevice &requestedTargetDevice,
                                                                                  std::string &outErrReason, std::string &outWarning) {
    auto programHeader = NEO::PatchTokenBinary::decodeProgramHeader(archive);
    if (nullptr == programHeader) {
        outErrReason = "Invalid program header";
        return {};
    }
    bool validForTarget = (requestedTargetDevice.coreFamily == static_cast<GFXCORE_FAMILY>(programHeader->Device));
    validForTarget &= (requestedTargetDevice.maxPointerSizeInBytes >= programHeader->GPUPointerSizeInBytes);
    validForTarget &= (iOpenCL::CURRENT_ICBE_VERSION == programHeader->Version);
    if (false == validForTarget) {
        outErrReason = "Unhandled target device";
        return {};
    }
    SingleDeviceBinary ret = {};
    ret.targetDevice = requestedTargetDevice;
    ret.format = NEO::DeviceBinaryFormat::Patchtokens;
    ret.deviceBinary = archive;
    return ret;
}

template <>
DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Patchtokens>(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) {
    NEO::PatchTokenBinary::ProgramFromPatchtokens decodedProgram = {};
    NEO::PatchTokenBinary::decodeProgramFromPatchtokensBlob(src.deviceBinary, decodedProgram);
    DBG_LOG(LogPatchTokens, NEO::PatchTokenBinary::asString(decodedProgram).c_str());

    std::string validatorWarnings;
    std::string validatorErrMessage;
    auto validatorErr = PatchTokenBinary::validate(decodedProgram, outErrReason, outWarning);
    if (DecodeError::Success != validatorErr) {
        return validatorErr;
    }

    NEO::populateProgramInfo(dst, decodedProgram);

    return DecodeError::Success;
}

} // namespace NEO