2019-12-10 23:26:35 +08:00
|
|
|
/*
|
2024-01-23 19:23:06 +08:00
|
|
|
* Copyright (C) 2019-2024 Intel Corporation
|
2019-12-10 23:26:35 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-09-25 00:40:29 +08:00
|
|
|
#include "shared/source/utilities/logger.h"
|
2019-12-10 23:26:35 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2024-10-23 01:22:46 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2024-12-12 23:55:13 +08:00
|
|
|
#include "shared/source/helpers/file_io.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/timestamp_packet.h"
|
2024-09-12 04:46:36 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2022-11-24 22:52:53 +08:00
|
|
|
#include "shared/source/utilities/io_functions.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2022-12-02 03:42:57 +08:00
|
|
|
#include <fstream>
|
2019-12-10 23:26:35 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
2022-05-16 22:06:56 +08:00
|
|
|
FileLogger<globalDebugFunctionalityLevel> &fileLoggerInstance() {
|
2023-11-30 16:32:25 +08:00
|
|
|
static FileLogger<globalDebugFunctionalityLevel> fileLoggerInstance(std::string("igdrcl.log"), debugManager.flags);
|
2019-12-10 23:26:35 +08:00
|
|
|
return fileLoggerInstance;
|
|
|
|
}
|
|
|
|
|
2023-11-24 01:09:04 +08:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
FileLogger<debugLevel>::FileLogger(std::string filename, const DebugVariables &flags) {
|
2022-08-16 21:24:22 +08:00
|
|
|
logFileName = std::move(filename);
|
2023-04-21 01:44:47 +08:00
|
|
|
if (enabled()) {
|
|
|
|
std::remove(logFileName.c_str());
|
|
|
|
}
|
2019-12-10 23:26:35 +08:00
|
|
|
|
|
|
|
dumpKernels = flags.DumpKernels.get();
|
|
|
|
logApiCalls = flags.LogApiCalls.get();
|
|
|
|
logAllocationMemoryPool = flags.LogAllocationMemoryPool.get();
|
2021-08-18 19:48:14 +08:00
|
|
|
logAllocationType = flags.LogAllocationType.get();
|
2021-12-22 16:43:41 +08:00
|
|
|
logAllocationStdout = flags.LogAllocationStdout.get();
|
2019-12-10 23:26:35 +08:00
|
|
|
}
|
|
|
|
|
2023-11-24 01:09:04 +08:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
FileLogger<debugLevel>::~FileLogger() = default;
|
2019-12-10 23:26:35 +08:00
|
|
|
|
2023-11-24 01:09:04 +08:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
void FileLogger<debugLevel>::writeToFile(std::string filename, const char *str, size_t length, std::ios_base::openmode mode) {
|
2022-08-16 21:24:22 +08:00
|
|
|
std::lock_guard theLock(mutex);
|
2024-12-19 00:26:44 +08:00
|
|
|
std::ofstream outFile(filename, mode);
|
|
|
|
if (outFile.is_open()) {
|
|
|
|
outFile.write(str, length);
|
|
|
|
outFile.close();
|
|
|
|
}
|
2019-12-10 23:26:35 +08:00
|
|
|
}
|
|
|
|
|
2023-11-24 01:09:04 +08:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
void FileLogger<debugLevel>::logDebugString(bool enableLog, std::string_view debugString) {
|
2022-11-24 22:52:53 +08:00
|
|
|
if (enabled()) {
|
|
|
|
if (enableLog) {
|
|
|
|
writeToFile(logFileName, debugString.data(), debugString.size(), std::ios::app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-24 01:09:04 +08:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
void FileLogger<debugLevel>::dumpKernel(const std::string &name, const std::string &src) {
|
2019-12-10 23:26:35 +08:00
|
|
|
if (false == enabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dumpKernels) {
|
|
|
|
DBG_LOG(LogApiCalls, "Kernel size", src.size(), src.c_str());
|
|
|
|
writeToFile(name + ".txt", src.c_str(), src.size(), std::ios::trunc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-24 01:09:04 +08:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
void FileLogger<debugLevel>::logApiCall(const char *function, bool enter, int32_t errorCode) {
|
2019-12-10 23:26:35 +08:00
|
|
|
if (false == enabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logApiCalls) {
|
|
|
|
std::thread::id thisThread = std::this_thread::get_id();
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "ThreadID: " << thisThread << " ";
|
|
|
|
if (enter)
|
|
|
|
ss << "Function Enter: ";
|
|
|
|
else
|
|
|
|
ss << "Function Leave (" << errorCode << "): ";
|
|
|
|
ss << function << std::endl;
|
|
|
|
|
|
|
|
auto str = ss.str();
|
|
|
|
writeToFile(logFileName, str.c_str(), str.size(), std::ios::app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-24 01:09:04 +08:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
size_t FileLogger<debugLevel>::getInput(const size_t *input, int32_t index) {
|
2019-12-10 23:26:35 +08:00
|
|
|
if (enabled() == false)
|
|
|
|
return 0;
|
|
|
|
return input != nullptr ? input[index] : 0;
|
|
|
|
}
|
|
|
|
|
2023-11-24 01:09:04 +08:00
|
|
|
template <DebugFunctionalityLevel debugLevel>
|
|
|
|
void FileLogger<debugLevel>::dumpBinaryProgram(int32_t numDevices, const size_t *lengths, const unsigned char **binaries) {
|
2019-12-10 23:26:35 +08:00
|
|
|
if (false == enabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dumpKernels) {
|
|
|
|
if (lengths != nullptr && binaries != nullptr &&
|
|
|
|
lengths[0] != 0 && binaries[0] != nullptr) {
|
|
|
|
writeToFile("programBinary.bin", reinterpret_cast<const char *>(binaries[0]), lengths[0], std::ios::trunc | std::ios::binary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 19:48:14 +08:00
|
|
|
const char *getAllocationTypeString(GraphicsAllocation const *graphicsAllocation) {
|
2019-12-10 23:26:35 +08:00
|
|
|
auto type = graphicsAllocation->getAllocationType();
|
|
|
|
|
|
|
|
switch (type) {
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::buffer:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::bufferHostMemory:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "BUFFER_HOST_MEMORY";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::commandBuffer:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "COMMAND_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::constantSurface:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "CONSTANT_SURFACE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::externalHostPtr:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "EXTERNAL_HOST_PTR";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::fillPattern:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "FILL_PATTERN";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::globalSurface:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "GLOBAL_SURFACE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::image:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "IMAGE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::indirectObjectHeap:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "INDIRECT_OBJECT_HEAP";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::instructionHeap:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "INSTRUCTION_HEAP";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::internalHeap:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "INTERNAL_HEAP";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::internalHostMemory:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "INTERNAL_HOST_MEMORY";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::kernelArgsBuffer:
|
2022-08-03 19:54:08 +08:00
|
|
|
return "KERNEL_ARGS_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::kernelIsa:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "KERNEL_ISA";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::kernelIsaInternal:
|
2020-11-13 02:53:30 +08:00
|
|
|
return "KERNEL_ISA_INTERNAL";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::linearStream:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "LINEAR_STREAM";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::mapAllocation:
|
2020-01-13 21:45:30 +08:00
|
|
|
return "MAP_ALLOCATION";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::mcs:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "MCS";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::pipe:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "PIPE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::preemption:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "PREEMPTION";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::printfSurface:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "PRINTF_SURFACE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::privateSurface:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "PRIVATE_SURFACE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::profilingTagBuffer:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "PROFILING_TAG_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::scratchSurface:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "SCRATCH_SURFACE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::sharedBuffer:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "SHARED_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::sharedImage:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "SHARED_IMAGE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::sharedResourceCopy:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "SHARED_RESOURCE_COPY";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::surfaceStateHeap:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "SURFACE_STATE_HEAP";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::svmCpu:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "SVM_CPU";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::svmGpu:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "SVM_GPU";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::svmZeroCopy:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "SVM_ZERO_COPY";
|
2024-09-06 03:37:52 +08:00
|
|
|
case AllocationType::syncBuffer:
|
|
|
|
return "SYNC_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::tagBuffer:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "TAG_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::globalFence:
|
2020-02-06 03:00:08 +08:00
|
|
|
return "GLOBAL_FENCE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::timestampPacketTagBuffer:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "TIMESTAMP_PACKET_TAG_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::unknown:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "UNKNOWN";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::writeCombined:
|
2019-12-10 23:26:35 +08:00
|
|
|
return "WRITE_COMBINED";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::debugContextSaveArea:
|
2020-06-24 18:54:30 +08:00
|
|
|
return "DEBUG_CONTEXT_SAVE_AREA";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::debugSbaTrackingBuffer:
|
2020-06-29 22:30:34 +08:00
|
|
|
return "DEBUG_SBA_TRACKING_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::debugModuleArea:
|
2020-10-14 22:46:11 +08:00
|
|
|
return "DEBUG_MODULE_AREA";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::workPartitionSurface:
|
2021-02-17 01:04:00 +08:00
|
|
|
return "WORK_PARTITION_SURFACE";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::gpuTimestampDeviceBuffer:
|
2021-07-16 22:10:17 +08:00
|
|
|
return "GPU_TIMESTAMP_DEVICE_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::ringBuffer:
|
2021-07-16 22:10:17 +08:00
|
|
|
return "RING_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::semaphoreBuffer:
|
2021-07-16 22:10:17 +08:00
|
|
|
return "SEMAPHORE_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::unifiedSharedMemory:
|
2021-07-16 22:10:17 +08:00
|
|
|
return "UNIFIED_SHARED_MEMORY";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::swTagBuffer:
|
2021-04-03 01:53:59 +08:00
|
|
|
return "SW_TAG_BUFFER";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::deferredTasksList:
|
2022-11-17 01:24:04 +08:00
|
|
|
return "DEFERRED_TASKS_LIST";
|
2023-12-11 22:24:36 +08:00
|
|
|
case AllocationType::assertBuffer:
|
2023-03-08 00:39:25 +08:00
|
|
|
return "ASSERT_BUFFER";
|
2024-03-26 18:02:52 +08:00
|
|
|
case AllocationType::syncDispatchToken:
|
|
|
|
return "SYNC_DISPATCH_TOKEN";
|
2019-12-10 23:26:35 +08:00
|
|
|
default:
|
|
|
|
return "ILLEGAL_VALUE";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-02 05:13:52 +08:00
|
|
|
const char *getMemoryPoolString(GraphicsAllocation const *graphicsAllocation) {
|
|
|
|
auto pool = graphicsAllocation->getMemoryPool();
|
|
|
|
|
|
|
|
switch (pool) {
|
2023-12-12 17:11:27 +08:00
|
|
|
case MemoryPool::memoryNull:
|
2022-06-02 05:13:52 +08:00
|
|
|
return "MemoryNull";
|
2023-12-12 17:11:27 +08:00
|
|
|
case MemoryPool::system4KBPages:
|
2022-06-02 05:13:52 +08:00
|
|
|
return "System4KBPages";
|
2023-12-12 17:11:27 +08:00
|
|
|
case MemoryPool::system64KBPages:
|
2022-06-02 05:13:52 +08:00
|
|
|
return "System64KBPages";
|
2023-12-12 17:11:27 +08:00
|
|
|
case MemoryPool::system4KBPagesWith32BitGpuAddressing:
|
2022-06-02 05:13:52 +08:00
|
|
|
return "System4KBPagesWith32BitGpuAddressing";
|
2023-12-12 17:11:27 +08:00
|
|
|
case MemoryPool::system64KBPagesWith32BitGpuAddressing:
|
2022-06-02 05:13:52 +08:00
|
|
|
return "System64KBPagesWith32BitGpuAddressing";
|
2023-12-12 17:11:27 +08:00
|
|
|
case MemoryPool::systemCpuInaccessible:
|
2022-06-02 05:13:52 +08:00
|
|
|
return "SystemCpuInaccessible";
|
2023-12-12 17:11:27 +08:00
|
|
|
case MemoryPool::localMemory:
|
2022-06-02 05:13:52 +08:00
|
|
|
return "LocalMemory";
|
|
|
|
}
|
|
|
|
|
|
|
|
UNRECOVERABLE_IF(true);
|
|
|
|
return "ILLEGAL_VALUE";
|
|
|
|
}
|
|
|
|
|
2023-12-05 20:06:54 +08:00
|
|
|
template class FileLogger<DebugFunctionalityLevel::none>;
|
|
|
|
template class FileLogger<DebugFunctionalityLevel::regKeys>;
|
|
|
|
template class FileLogger<DebugFunctionalityLevel::full>;
|
2019-12-10 23:26:35 +08:00
|
|
|
|
|
|
|
} // namespace NEO
|