diff --git a/shared/source/memory_manager/graphics_allocation.cpp b/shared/source/memory_manager/graphics_allocation.cpp index 1739296557..4b0ffc04b3 100644 --- a/shared/source/memory_manager/graphics_allocation.cpp +++ b/shared/source/memory_manager/graphics_allocation.cpp @@ -16,12 +16,13 @@ #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/os_interface/os_context.h" #include "shared/source/utilities/logger.h" +#include "shared/source/utilities/logger_neo_only.h" namespace NEO { void GraphicsAllocation::setAllocationType(AllocationType allocationType) { if (this->allocationType != allocationType) { this->allocationType = allocationType; - fileLoggerInstance().logAllocation(this, nullptr); + logAllocation(fileLoggerInstance(), this, nullptr); } } @@ -70,7 +71,7 @@ std::string GraphicsAllocation::getAllocationInfoString() const { return ""; } -std::string GraphicsAllocation::getPatIndexInfoString() const { +std::string GraphicsAllocation::getPatIndexInfoString(const ProductHelper &) const { return ""; } diff --git a/shared/source/memory_manager/graphics_allocation.h b/shared/source/memory_manager/graphics_allocation.h index 50d3c16d7a..1436c9e74c 100644 --- a/shared/source/memory_manager/graphics_allocation.h +++ b/shared/source/memory_manager/graphics_allocation.h @@ -36,6 +36,7 @@ class Gmm; class MemoryManager; class CommandStreamReceiver; class GraphicsAllocation; +class ProductHelper; struct AllocationProperties; @@ -183,7 +184,7 @@ class GraphicsAllocation : public IDNode { bool isResidencyTaskCountBelow(TaskCountType taskCount, uint32_t contextId) const { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; } virtual std::string getAllocationInfoString() const; - virtual std::string getPatIndexInfoString() const; + virtual std::string getPatIndexInfoString(const ProductHelper &) const; virtual int createInternalHandle(MemoryManager *memoryManager, uint32_t handleId, uint64_t &handle) { return 0; } virtual int peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) { return 0; } virtual void clearInternalHandle(uint32_t handleId) { return; } diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index e41b4f070b..ceeaccbd5c 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -42,6 +42,7 @@ #include "shared/source/os_interface/os_interface.h" #include "shared/source/os_interface/product_helper.h" #include "shared/source/page_fault_manager/cpu_page_fault_manager.h" +#include "shared/source/utilities/logger_neo_only.h" #include #include @@ -671,7 +672,7 @@ GraphicsAllocation *MemoryManager::allocatePhysicalGraphicsMemory(const Allocati return nullptr; } - fileLoggerInstance().logAllocation(allocation, this); + logAllocation(fileLoggerInstance(), allocation, this); registerAllocationInOs(allocation); return allocation; } @@ -709,7 +710,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const A allocation->setAsReadOnly(); } - fileLoggerInstance().logAllocation(allocation, this); + logAllocation(fileLoggerInstance(), allocation, this); registerAllocationInOs(allocation); return allocation; } diff --git a/shared/source/os_interface/linux/drm_allocation.cpp b/shared/source/os_interface/linux/drm_allocation.cpp index 72912930f4..23cb6a46db 100644 --- a/shared/source/os_interface/linux/drm_allocation.cpp +++ b/shared/source/os_interface/linux/drm_allocation.cpp @@ -46,7 +46,7 @@ std::string DrmAllocation::getAllocationInfoString() const { return ss.str(); } -std::string DrmAllocation::getPatIndexInfoString() const { +std::string DrmAllocation::getPatIndexInfoString(const ProductHelper &productHelper) const { std::stringstream ss; auto bo = getBO(); diff --git a/shared/source/os_interface/linux/drm_allocation.h b/shared/source/os_interface/linux/drm_allocation.h index 0f3cf5e6ae..432062f94e 100644 --- a/shared/source/os_interface/linux/drm_allocation.h +++ b/shared/source/os_interface/linux/drm_allocation.h @@ -59,7 +59,7 @@ class DrmAllocation : public GraphicsAllocation { ~DrmAllocation() override; std::string getAllocationInfoString() const override; - std::string getPatIndexInfoString() const override; + std::string getPatIndexInfoString(const ProductHelper &productHelper) const override; BufferObject *getBO() const { if (fragmentsStorage.fragmentCount) { diff --git a/shared/source/os_interface/windows/wddm_allocation.cpp b/shared/source/os_interface/windows/wddm_allocation.cpp index b45c229650..d40a96fe2f 100644 --- a/shared/source/os_interface/windows/wddm_allocation.cpp +++ b/shared/source/os_interface/windows/wddm_allocation.cpp @@ -14,7 +14,7 @@ namespace NEO { std::string WddmAllocation::getAllocationInfoString() const { return getHandleInfoString(); } -std::string WddmAllocation::getPatIndexInfoString() const { +std::string WddmAllocation::getPatIndexInfoString(const ProductHelper &) const { return ""; } } // namespace NEO \ No newline at end of file diff --git a/shared/source/os_interface/windows/wddm_allocation.h b/shared/source/os_interface/windows/wddm_allocation.h index 513f6a65da..01412cc2e2 100644 --- a/shared/source/os_interface/windows/wddm_allocation.h +++ b/shared/source/os_interface/windows/wddm_allocation.h @@ -82,7 +82,7 @@ class WddmAllocation : public GraphicsAllocation { void setCpuAddress(void *cpuPtr) { this->cpuPtr = cpuPtr; } std::string getAllocationInfoString() const override; - std::string getPatIndexInfoString() const override; + std::string getPatIndexInfoString(const ProductHelper &productHelper) const override; uint64_t &getGpuAddressToModify() { return gpuAddress; } bool needsMakeResidentBeforeLock() const { return makeResidentBeforeLockRequired; } void setMakeResidentBeforeLockRequired(bool makeResidentBeforeLockRequired) { this->makeResidentBeforeLockRequired = makeResidentBeforeLockRequired; } diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index de5ef4ccd2..7cc1af3fc6 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -40,6 +40,7 @@ #include "shared/source/os_interface/windows/wddm_allocation.h" #include "shared/source/os_interface/windows/wddm_residency_allocations_container.h" #include "shared/source/os_interface/windows/wddm_residency_controller.h" +#include "shared/source/utilities/logger_neo_only.h" #include #include @@ -642,7 +643,7 @@ GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle( return nullptr; } - fileLoggerInstance().logAllocation(allocation.get(), this); + logAllocation(fileLoggerInstance(), allocation.get(), this); return allocation.release(); } diff --git a/shared/source/utilities/logger.cpp b/shared/source/utilities/logger.cpp index 4d23f21373..c43070d07f 100644 --- a/shared/source/utilities/logger.cpp +++ b/shared/source/utilities/logger.cpp @@ -8,6 +8,7 @@ #include "shared/source/utilities/logger.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/execution_environment/execution_environment.h" #include "shared/source/helpers/timestamp_packet.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/utilities/io_functions.h" @@ -93,48 +94,6 @@ void FileLogger::logApiCall(const char *function, bool enter, int32_ } } -template -void FileLogger::logAllocation(GraphicsAllocation const *graphicsAllocation, MemoryManager const *memoryManager) { - if (logAllocationType) { - printDebugString(true, stdout, "Created Graphics Allocation of type %s\n", getAllocationTypeString(graphicsAllocation)); - } - - if (false == enabled() && !logAllocationStdout) { - return; - } - - if (logAllocationMemoryPool || logAllocationType) { - std::stringstream ss; - std::thread::id thisThread = std::this_thread::get_id(); - - ss << " ThreadID: " << thisThread; - ss << " Type: " << getAllocationTypeString(graphicsAllocation); - ss << " Pool: " << getMemoryPoolString(graphicsAllocation); - ss << " Root index: " << graphicsAllocation->getRootDeviceIndex(); - ss << " Size: " << graphicsAllocation->getUnderlyingBufferSize(); - ss << " GPU VA: 0x" << std::hex << graphicsAllocation->getGpuAddress() << " - 0x" << std::hex << graphicsAllocation->getGpuAddress() + graphicsAllocation->getUnderlyingBufferSize() - 1; - - ss << graphicsAllocation->getAllocationInfoString(); - ss << graphicsAllocation->getPatIndexInfoString(); - - if (memoryManager) { - ss << " Total sys mem allocated: " << std::dec << memoryManager->getUsedSystemMemorySize(); - ss << " Total lmem allocated: " << std::dec << memoryManager->getUsedLocalMemorySize(graphicsAllocation->getRootDeviceIndex()); - } - - ss << std::endl; - auto str = ss.str(); - if (logAllocationStdout) { - printf("%s", str.c_str()); - return; - } - - if (enabled()) { - writeToFile(logFileName, str.c_str(), str.size(), std::ios::app); - } - } -} - template size_t FileLogger::getInput(const size_t *input, int32_t index) { if (enabled() == false) diff --git a/shared/source/utilities/logger.h b/shared/source/utilities/logger.h index 38419aae0e..7d6a3a5dc8 100644 --- a/shared/source/utilities/logger.h +++ b/shared/source/utilities/logger.h @@ -41,7 +41,6 @@ class FileLogger { void dumpKernel(const std::string &name, const std::string &src); void logApiCall(const char *function, bool enter, int32_t errorCode); - void logAllocation(GraphicsAllocation const *graphicsAllocation, MemoryManager const *memoryManager); size_t getInput(const size_t *input, int32_t index); MOCKABLE_VIRTUAL void writeToFile(std::string filename, const char *str, size_t length, std::ios_base::openmode mode); @@ -135,15 +134,15 @@ class FileLogger { void logDebugString(bool enableLog, std::string_view debugString); - const char *getLogFileName() { - return logFileName.c_str(); - } + const char *getLogFileName() { return logFileName.c_str(); } + std::string getLogFileNameString() { return logFileName; } - void setLogFileName(std::string filename) { - logFileName = std::move(filename); - } + void setLogFileName(std::string filename) { logFileName = std::move(filename); } bool peekLogApiCalls() { return logApiCalls; } + bool shouldLogAllocationType() { return logAllocationType; } + bool shouldLogAllocationToStdout() { return logAllocationStdout; } + bool shouldLogAllocationMemoryPool() { return logAllocationMemoryPool; } protected: std::mutex mutex; diff --git a/shared/source/utilities/logger_neo_only.h b/shared/source/utilities/logger_neo_only.h new file mode 100644 index 0000000000..d56beef514 --- /dev/null +++ b/shared/source/utilities/logger_neo_only.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/memory_manager/graphics_allocation.h" +#include "shared/source/memory_manager/memory_manager.h" +#include "shared/source/utilities/logger.h" + +#include + +/* Should not be used outside of NEO (e.g. with ocloc) because of dependencies towards other NEO structures */ +namespace NEO { + +template +void logAllocation(FileLogger &logger, GraphicsAllocation const *graphicsAllocation, MemoryManager const *memoryManager) { + if (logger.shouldLogAllocationType()) { + printDebugString(true, stdout, "Created Graphics Allocation of type %s\n", getAllocationTypeString(graphicsAllocation)); + } + + if (!logger.enabled() && !logger.shouldLogAllocationToStdout()) { + return; + } + + if (logger.shouldLogAllocationMemoryPool() || logger.shouldLogAllocationType()) { + std::stringstream ss; + std::thread::id thisThread = std::this_thread::get_id(); + + ss << " ThreadID: " << thisThread; + ss << " Type: " << getAllocationTypeString(graphicsAllocation); + ss << " Pool: " << getMemoryPoolString(graphicsAllocation); + ss << " Root index: " << graphicsAllocation->getRootDeviceIndex(); + ss << " Size: " << graphicsAllocation->getUnderlyingBufferSize(); + ss << " GPU VA: 0x" << std::hex << graphicsAllocation->getGpuAddress() << " - 0x" << std::hex << graphicsAllocation->getGpuAddress() + graphicsAllocation->getUnderlyingBufferSize() - 1; + + ss << graphicsAllocation->getAllocationInfoString(); + + if (memoryManager) { + auto *rootDeviceEnvironment{[graphicsAllocation, memoryManager]() { + auto &rootDeviceEnvironments{memoryManager->peekExecutionEnvironment().rootDeviceEnvironments}; + auto indexOfAllocation = graphicsAllocation->getRootDeviceIndex(); + return (indexOfAllocation < rootDeviceEnvironments.size()) ? rootDeviceEnvironments[indexOfAllocation].get() : nullptr; + }()}; + if (rootDeviceEnvironment) { + ss << graphicsAllocation->getPatIndexInfoString(rootDeviceEnvironment->getProductHelper()); + } + + ss << " Total sys mem allocated: " << std::dec << memoryManager->getUsedSystemMemorySize(); + ss << " Total lmem allocated: " << std::dec << memoryManager->getUsedLocalMemorySize(graphicsAllocation->getRootDeviceIndex()); + } + + ss << std::endl; + auto str = ss.str(); + if (logger.shouldLogAllocationToStdout()) { + printf("%s", str.c_str()); + return; + } + + if (logger.enabled()) { + logger.writeToFile(logger.getLogFileNameString(), str.c_str(), str.size(), std::ios::app); + } + } +} + +} // namespace NEO diff --git a/shared/test/common/utilities/logger_tests.h b/shared/test/common/utilities/logger_tests.h index bc3601d857..5e50fbec58 100644 --- a/shared/test/common/utilities/logger_tests.h +++ b/shared/test/common/utilities/logger_tests.h @@ -57,4 +57,4 @@ class TestFileLogger : public NEO::FileLogger { using FullyEnabledFileLogger = TestFileLogger; using FullyDisabledFileLogger = TestFileLogger; -using ReleaseInternalFileLogger = TestFileLogger; \ No newline at end of file +using ReleaseInternalFileLogger = TestFileLogger; diff --git a/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp b/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp index 2dc04caf68..836a3e128b 100644 --- a/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp +++ b/shared/test/unit_test/debug_settings/debug_settings_manager_tests.cpp @@ -15,6 +15,7 @@ #include "shared/test/common/helpers/gtest_helpers.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_io_functions.h" +#include "shared/test/common/mocks/mock_product_helper.h" #include "shared/test/common/test_macros/test.h" #include "shared/test/common/utilities/base_object_utils.h" @@ -337,7 +338,9 @@ TEST(AllocationInfoLogging, givenBaseGraphicsAllocationWhenGettingImplementation TEST(AllocationInfoLogging, givenBaseGraphicsAllocationWhenGettingImplementationSpecificPatIndexInfoThenReturnEmptyInfoString) { GraphicsAllocation graphicsAllocation(0, 1u /*num gmms*/, AllocationType::unknown, nullptr, 0, 0, MemoryPool::memoryNull, MemoryManager::maxOsContextCount, 0llu); - EXPECT_STREQ(graphicsAllocation.getPatIndexInfoString().c_str(), ""); + + MockProductHelper productHelper{}; + EXPECT_STREQ(graphicsAllocation.getPatIndexInfoString(productHelper).c_str(), ""); } TEST(DebugSettingsManager, givenDisabledDebugManagerWhenCreateThenOnlyReleaseVariablesAreRead) { diff --git a/shared/test/unit_test/os_interface/linux/file_logger_linux_tests.cpp b/shared/test/unit_test/os_interface/linux/file_logger_linux_tests.cpp index 5fc50714bb..8afb635c8f 100644 --- a/shared/test/unit_test/os_interface/linux/file_logger_linux_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/file_logger_linux_tests.cpp @@ -7,6 +7,7 @@ #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/utilities/logger_neo_only.h" #include "shared/test/common/libult/linux/drm_mock.h" #include "shared/test/common/mocks/linux/mock_drm_allocation.h" #include "shared/test/common/mocks/mock_execution_environment.h" @@ -47,7 +48,7 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) { allocation.bufferObjects[0] = &bo; - fileLogger.logAllocation(&allocation, executionEnvironment->memoryManager.get()); + logAllocation(fileLogger, &allocation, executionEnvironment->memoryManager.get()); std::thread::id thisThread = std::this_thread::get_id(); @@ -114,7 +115,7 @@ TEST(FileLogger, givenLogAllocationStdoutWhenLogAllocationThenLogToStdoutInstead allocation.bufferObjects[0] = &bo; testing::internal::CaptureStdout(); - fileLogger.logAllocation(&allocation, nullptr); + logAllocation(fileLogger, &allocation, nullptr); std::string output = testing::internal::GetCapturedStdout(); std::thread::id thisThread = std::this_thread::get_id(); @@ -161,7 +162,7 @@ TEST(FileLogger, GivenDrmAllocationWithoutBOThenNoHandleLogged) { allocation.getDefaultGmm()->resourceParams.Usage = GMM_RESOURCE_USAGE_TYPE_ENUM::GMM_RESOURCE_USAGE_OCL_BUFFER; allocation.getDefaultGmm()->resourceParams.Flags.Info.Cacheable = true; - fileLogger.logAllocation(&allocation, nullptr); + logAllocation(fileLogger, &allocation, nullptr); std::thread::id thisThread = std::this_thread::get_id(); std::stringstream threadIDCheck; @@ -190,7 +191,7 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagSetFalseThenAllocationIsNotLogg EXPECT_FALSE(logFileCreated); MockDrmAllocation allocation(0u, AllocationType::buffer, MemoryPool::system64KBPages); - fileLogger.logAllocation(&allocation, nullptr); + logAllocation(fileLogger, &allocation, nullptr); std::thread::id thisThread = std::this_thread::get_id(); diff --git a/shared/test/unit_test/os_interface/windows/file_logger_win_tests.cpp b/shared/test/unit_test/os_interface/windows/file_logger_win_tests.cpp index 468f89f015..066617da4c 100644 --- a/shared/test/unit_test/os_interface/windows/file_logger_win_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/file_logger_win_tests.cpp @@ -7,6 +7,7 @@ #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/gmm_helper/gmm.h" +#include "shared/source/utilities/logger_neo_only.h" #include "shared/test/common/fixtures/mock_execution_environment_gmm_fixture.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/windows/mock_wddm_allocation.h" @@ -38,7 +39,7 @@ TEST_F(FileLoggerTests, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) { allocation.setGpuAddress(0x12345); allocation.size = 777u; - fileLogger.logAllocation(&allocation, executionEnvironment->memoryManager.get()); + logAllocation(fileLogger, &allocation, executionEnvironment->memoryManager.get()); std::thread::id thisThread = std::this_thread::get_id(); @@ -93,7 +94,7 @@ TEST_F(FileLoggerTests, GivenLogAllocationMemoryPoolFlagSetFalseThenAllocationIs allocation.memoryPool = MemoryPool::system64KBPages; allocation.getDefaultGmm()->resourceParams.Flags.Info.NonLocalOnly = 0; - fileLogger.logAllocation(&allocation, nullptr); + logAllocation(fileLogger, &allocation, nullptr); std::thread::id thisThread = std::this_thread::get_id(); diff --git a/shared/test/unit_test/utilities/logger_tests.cpp b/shared/test/unit_test/utilities/logger_tests.cpp index 013ec92c43..60da48c965 100644 --- a/shared/test/unit_test/utilities/logger_tests.cpp +++ b/shared/test/unit_test/utilities/logger_tests.cpp @@ -11,6 +11,7 @@ #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/memory_manager/memory_pool.h" #include "shared/source/utilities/logger.h" +#include "shared/source/utilities/logger_neo_only.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/gtest_helpers.h" #include "shared/test/common/utilities/base_object_utils.h" @@ -535,7 +536,7 @@ TEST(AllocationTypeLoggingSingle, givenDebugVariableToCaptureAllocationTypeWhenF GraphicsAllocation graphicsAllocation(0, 1u /*num gmms*/, AllocationType::commandBuffer, nullptr, 0, 0, MemoryPool::memoryNull, MemoryManager::maxOsContextCount, 0llu); testing::internal::CaptureStdout(); - fileLogger.logAllocation(&graphicsAllocation, nullptr); + logAllocation(fileLogger, &graphicsAllocation, nullptr); std::string output = testing::internal::GetCapturedStdout(); std::string expectedOutput = "Created Graphics Allocation of type COMMAND_BUFFER\n"; @@ -557,7 +558,7 @@ TEST(AllocationTypeLoggingSingle, givenLogAllocationTypeWhenLoggingAllocationThe EXPECT_FALSE(logFileCreated); testing::internal::CaptureStdout(); - fileLogger.logAllocation(&graphicsAllocation, nullptr); + logAllocation(fileLogger, &graphicsAllocation, nullptr); std::string output = testing::internal::GetCapturedStdout(); std::string expectedOutput = "Created Graphics Allocation of type COMMAND_BUFFER\n";