File: assert_handler.cpp

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (59 lines) | stat: -rw-r--r-- 1,988 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (C) 2023 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/assert_handler/assert_handler.h"

#include "shared/source/device/device.h"
#include "shared/source/helpers/abort.h"
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/program/print_formatter.h"

namespace NEO {
AssertHandler::AssertHandler(Device *device) : device(device) {
    auto rootDeviceIndex = device->getRootDeviceIndex();
    assertBuffer = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, assertBufferSize, AllocationType::assertBuffer, device->getDeviceBitfield()});

    AssertBufferHeader initialHeader = {};
    initialHeader.size = assertBufferSize;
    initialHeader.flags = 0;
    initialHeader.begin = sizeof(AssertBufferHeader);
    *reinterpret_cast<AssertBufferHeader *>(assertBuffer->getUnderlyingBuffer()) = initialHeader;
}

AssertHandler::~AssertHandler() {
    device->getMemoryManager()->freeGraphicsMemory(assertBuffer);
}

bool AssertHandler::checkAssert() const {
    return reinterpret_cast<AssertBufferHeader *>(assertBuffer->getUnderlyingBuffer())->flags != 0;
}

void AssertHandler::printMessage() const {

    auto messageBuffer = static_cast<uint8_t *>(assertBuffer->getUnderlyingBuffer());
    auto messageBufferSize = static_cast<uint32_t>(assertBuffer->getUnderlyingBufferSize());

    NEO::PrintFormatter printfFormatter{
        messageBuffer,
        messageBufferSize,
        false,
        nullptr};
    printfFormatter.setInitialOffset(offsetof(AssertBufferHeader, begin));

    printToStderr("AssertHandler::printMessage\n");
    printfFormatter.printKernelOutput([](char *str) { printToStderr(str); });
}

void AssertHandler::printAssertAndAbort() {
    std::lock_guard<std::mutex> lock(this->mtx);
    if (checkAssert()) {
        printMessage();
        abortExecution();
    }
}
} // namespace NEO