diff --git a/runtime/dll/CMakeLists.txt b/runtime/dll/CMakeLists.txt index c4cd73217a..89ddc82fea 100644 --- a/runtime/dll/CMakeLists.txt +++ b/runtime/dll/CMakeLists.txt @@ -45,8 +45,9 @@ set(RUNTIME_SRCS_DLL_BASE ) set(RUNTIME_SRCS_DLL_LINUX - ${CMAKE_CURRENT_SOURCE_DIR}/linux/options.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linux/allocator_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux/drm_neo_create.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linux/options.cpp ) set(RUNTIME_SRCS_DLL_WINDOWS diff --git a/runtime/dll/linux/allocator_helper.cpp b/runtime/dll/linux/allocator_helper.cpp new file mode 100644 index 0000000000..d263d29d6d --- /dev/null +++ b/runtime/dll/linux/allocator_helper.cpp @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "runtime/helpers/aligned_memory.h" +#include "runtime/helpers/basic_math.h" +#include "runtime/os_interface/linux/allocator_helper.h" + +namespace OCLRT { +size_t getSizeToMap() { + return static_cast(alignUp(4 * GB - 8096, 4096)); +} +} // namespace OCLRT diff --git a/runtime/os_interface/linux/CMakeLists.txt b/runtime/os_interface/linux/CMakeLists.txt index d055e818aa..c7bea97438 100644 --- a/runtime/os_interface/linux/CMakeLists.txt +++ b/runtime/os_interface/linux/CMakeLists.txt @@ -20,6 +20,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/allocator_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/api.cpp ${CMAKE_CURRENT_SOURCE_DIR}/d3d_sharing_functions.h ${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.cpp diff --git a/runtime/os_interface/linux/allocator_helper.h b/runtime/os_interface/linux/allocator_helper.h new file mode 100644 index 0000000000..1519075af0 --- /dev/null +++ b/runtime/os_interface/linux/allocator_helper.h @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#pragma once +#include + +namespace OCLRT { +size_t getSizeToMap(); +} // namespace OCLRT \ No newline at end of file diff --git a/runtime/os_interface/linux/drm_32bit_memory.cpp b/runtime/os_interface/linux/drm_32bit_memory.cpp index 3f26211d32..4a088b493f 100644 --- a/runtime/os_interface/linux/drm_32bit_memory.cpp +++ b/runtime/os_interface/linux/drm_32bit_memory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -22,6 +22,7 @@ #include #include "runtime/os_interface/32bit_memory.h" +#include "runtime/os_interface/linux/allocator_helper.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/ptr_math.h" #include "runtime/helpers/basic_math.h" @@ -105,7 +106,7 @@ OCLRT::Allocator32bit::Allocator32bit() : Allocator32bit(new OsInternals) { OCLRT::Allocator32bit::Allocator32bit(Allocator32bit::OsInternals *osInternalsIn) : osInternals(osInternalsIn) { if (DebugManager.flags.UseNewHeapAllocator.get()) { - size_t sizeToMap = alignUp(4 * GB - 8096, 4096); + size_t sizeToMap = getSizeToMap(); void *ptr = MAP_FAILED; ptr = this->osInternals->mmapFunction(nullptr, sizeToMap, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); diff --git a/unit_tests/command_queue/enqueue_kernel_tests.cpp b/unit_tests/command_queue/enqueue_kernel_tests.cpp index 707234e7f5..eac294d449 100644 --- a/unit_tests/command_queue/enqueue_kernel_tests.cpp +++ b/unit_tests/command_queue/enqueue_kernel_tests.cpp @@ -1042,7 +1042,7 @@ HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeWhenEnqueueK auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - MockKernelWithInternals mockKernel(*pDevice); + MockKernelWithInternals mockKernel(*pDevice, context); size_t gws[3] = {1, 0, 0}; auto ret = pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, ret); @@ -1106,7 +1106,6 @@ HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeAndBatchedKe EXPECT_TRUE(mockedSubmissionsAggregator->peekCmdBufferList().peekIsEmpty()); EXPECT_EQ(1, mockCsrmockCsr->flushCalledCount); } - HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeWhenKernelIsEnqueuedTwiceThenTwoSubmissionsAreRecorded) { auto mockCsrmockCsr = new MockCsrHw2(pDevice->getHardwareInfo()); mockCsrmockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); @@ -1115,7 +1114,7 @@ HWTEST_F(EnqueueKernelTest, givenCommandStreamReceiverInBatchingModeWhenKernelIs auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsrmockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - MockKernelWithInternals mockKernel(*pDevice); + MockKernelWithInternals mockKernel(*pDevice, context); size_t gws[3] = {1, 0, 0}; //make sure csr emits something mockCsrmockCsr->overrideMediaVFEStateDirty(true); @@ -1357,7 +1356,7 @@ HWTEST_F(EnqueueKernelTest, givenOutOfOrderCommandQueueWhenEnqueueKernelIsMadeTh auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - MockKernelWithInternals mockKernel(*pDevice); + MockKernelWithInternals mockKernel(*pDevice, context); size_t gws[3] = {1, 0, 0}; clEnqueueNDRangeKernel(ooq, mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); @@ -1379,7 +1378,7 @@ HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelIsMadeThenP auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - MockKernelWithInternals mockKernel(*pDevice); + MockKernelWithInternals mockKernel(*pDevice, context); size_t gws[3] = {1, 0, 0}; clEnqueueNDRangeKernel(inOrderQueue, mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); @@ -1401,7 +1400,7 @@ HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelThatHasShar auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - MockKernelWithInternals mockKernel(*pDevice); + MockKernelWithInternals mockKernel(*pDevice, context); size_t gws[3] = {1, 0, 0}; mockKernel.mockKernel->setUsingSharedArgs(true); clEnqueueNDRangeKernel(inOrderQueue, mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); @@ -1419,7 +1418,7 @@ HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelThatHasShar mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); pDevice->resetCommandStreamReceiver(mockCsr); - MockKernelWithInternals mockKernel(*pDevice); + MockKernelWithInternals mockKernel(*pDevice, context); size_t gws[3] = {1, 0, 0}; mockKernel.mockKernel->setUsingSharedArgs(true); clEnqueueNDRangeKernel(this->pCmdQ, mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); @@ -1438,7 +1437,7 @@ HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelReturningEv auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - MockKernelWithInternals mockKernel(*pDevice); + MockKernelWithInternals mockKernel(*pDevice, context); size_t gws[3] = {1, 0, 0}; cl_event event; @@ -1465,7 +1464,7 @@ HWTEST_F(EnqueueKernelTest, givenInOrderCommandQueueWhenEnqueueKernelReturningEv auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - MockKernelWithInternals mockKernel(*pDevice); + MockKernelWithInternals mockKernel(*pDevice, context); size_t gws[3] = {1, 0, 0}; cl_event event; @@ -1491,7 +1490,7 @@ HWTEST_F(EnqueueKernelTest, givenOutOfOrderCommandQueueWhenEnqueueKernelReturnin const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, 0}; auto inOrderQueue = clCreateCommandQueueWithProperties(context, pDevice, props, nullptr); - MockKernelWithInternals mockKernel(*pDevice); + MockKernelWithInternals mockKernel(*pDevice, context); size_t gws[3] = {1, 0, 0}; cl_event event; @@ -1575,6 +1574,7 @@ TEST_F(EnqueueKernelTest, givenKernelWhenAllArgsAreNotAndEventExistSetThenClEnqu retVal = clEnqueueNDRangeKernel(pCmdQ2, kernel.get(), 1, nullptr, globalWorkSize, localWorkSize, 0, nullptr, &event); EXPECT_EQ(CL_INVALID_KERNEL_ARGS, retVal); + clFlush(pCmdQ2); clReleaseCommandQueue(pCmdQ2); } diff --git a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp index 9553eb6b9c..8c98d23083 100644 --- a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp @@ -57,8 +57,8 @@ using namespace OCLRT; -using ::testing::_; using ::testing::Invoke; +using ::testing::_; HWTEST_F(UltCommandStreamReceiverTest, givenThreadArbitrationPolicyNotChangedWhenEstimatingPreambleCmdSizeThenReturnItsValue) { auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); @@ -1817,6 +1817,10 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenEnabledPreemptionWhenFlushTas HWTEST_F(CommandStreamReceiverFlushTaskTests, flushTaskWithPCWhenPreambleSentAndL3ConfigChanged) { typedef typename FamilyType::PIPE_CONTROL PIPE_CONTROL; + typedef typename FamilyType::STATE_BASE_ADDRESS STATE_BASE_ADDRESS; + typedef typename FamilyType::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; + typedef typename FamilyType::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM; + typedef typename FamilyType::MEDIA_VFE_STATE MEDIA_VFE_STATE; CsrSizeRequestFlags csrSizeRequest = {}; commandStream.getSpace(sizeof(PIPE_CONTROL)); @@ -1829,13 +1833,18 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, flushTaskWithPCWhenPreambleSentAnd commandStreamReceiver.isPreambleSent = true; commandStreamReceiver.lastPreemptionMode = pDevice->getPreemptionMode(); commandStreamReceiver.lastMediaSamplerConfig = 0; + commandStreamReceiver.lastSentCoherencyRequest = false; commandStreamReceiver.lastSentThreadArbitrationPolicy = commandStreamReceiver.requiredThreadArbitrationPolicy; csrSizeRequest.l3ConfigChanged = true; commandStreamReceiver.overrideCsrSizeReqFlags(csrSizeRequest); auto &csrCS = commandStreamReceiver.getCS(); - size_t sizeNeeded = commandStreamReceiver.getRequiredCmdStreamSizeAligned(flushTaskFlags); + size_t sizeNeeded = 2 * sizeof(PIPE_CONTROL) + sizeof(MI_LOAD_REGISTER_IMM) + sizeof(MEDIA_VFE_STATE) + + sizeof(MI_BATCH_BUFFER_START) + sizeof(STATE_BASE_ADDRESS) + sizeof(PIPE_CONTROL) + + commandStreamReceiver.getRequiredPipeControlSize(); + auto expectedUsed = csrCS.getUsed() + sizeNeeded; + expectedUsed = alignUp(expectedUsed, MemoryConstants::cacheLineSize); commandStreamReceiver.flushTask(commandStream, 0, dsh, ioh, ssh, taskLevel, flushTaskFlags); diff --git a/unit_tests/compiler_interface/compiler_interface_tests.cpp b/unit_tests/compiler_interface/compiler_interface_tests.cpp index e241b2b6e7..46640f97cb 100644 --- a/unit_tests/compiler_interface/compiler_interface_tests.cpp +++ b/unit_tests/compiler_interface/compiler_interface_tests.cpp @@ -201,6 +201,7 @@ TEST_F(CompilerInterfaceTest, BuildWithDebugData) { retVal = pProgram->getInfo(CL_PROGRAM_DEBUG_INFO_INTEL, debugDataSize, nullptr, &retData); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ(numDevices * sizeof(debugData), retData); + cip->shutdown(); delete[] debugData; delete cip; diff --git a/unit_tests/helpers/built_ins_helper.cpp b/unit_tests/helpers/built_ins_helper.cpp index 6d6439af9d..2f1c5a21ab 100644 --- a/unit_tests/helpers/built_ins_helper.cpp +++ b/unit_tests/helpers/built_ins_helper.cpp @@ -25,7 +25,6 @@ namespace OCLRT { const SipKernel &initSipKernel(SipKernelType type, Device &device) { - CompilerInterface::getInstance(); std::unique_ptr mockCompilerInterface(new MockCompilerInterface()); mockCompilerInterface->overrideGlobalCompilerInterface(); mockCompilerInterface->sipKernelBinaryOverride = mockCompilerInterface->getDummyGenBinary(); diff --git a/unit_tests/libult/CMakeLists.txt b/unit_tests/libult/CMakeLists.txt index 213b730e3d..e3dd43432f 100644 --- a/unit_tests/libult/CMakeLists.txt +++ b/unit_tests/libult/CMakeLists.txt @@ -120,6 +120,7 @@ set(IGDRCL_SRCS_LIB_ULT_ENV_WINDOWS set(IGDRCL_SRCS_LIB_ULT_ENV_LINUX ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/options.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/allocator_helper.cpp ) if(WIN32) diff --git a/unit_tests/linux/CMakeLists.txt b/unit_tests/linux/CMakeLists.txt index cb6d9dfbf4..6a3bae6cc9 100644 --- a/unit_tests/linux/CMakeLists.txt +++ b/unit_tests/linux/CMakeLists.txt @@ -21,6 +21,7 @@ set(IGDRCL_SRCS_linux_tests ${CMAKE_CURRENT_SOURCE_DIR}/main_linux.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/allocator_helper.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/options.cpp ) @@ -30,6 +31,7 @@ set(IGDRCL_SRCS_linux_dll_tests ${CMAKE_CURRENT_SOURCE_DIR}/mock_os_layer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_os_layer.h ${IGDRCL_SOURCE_DIR}/runtime/os_interface/debug_settings_manager.cpp + ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/allocator_helper.cpp ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/drm_neo_create.cpp ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/options.cpp ) diff --git a/unit_tests/linux/main_linux_dll.cpp b/unit_tests/linux/main_linux_dll.cpp index 51c34244ed..2812c4ee34 100644 --- a/unit_tests/linux/main_linux_dll.cpp +++ b/unit_tests/linux/main_linux_dll.cpp @@ -22,6 +22,9 @@ #include "mock_os_layer.h" #include "runtime/gmm_helper/gmm_helper.h" +#include "runtime/helpers/aligned_memory.h" +#include "runtime/helpers/basic_math.h" +#include "runtime/os_interface/linux/allocator_helper.h" #include "unit_tests/custom_event_listener.h" #include "test.h" @@ -289,6 +292,10 @@ TEST_F(DrmTests, failOnInvalidDeviceName) { EXPECT_EQ(ptr, nullptr); } +TEST(AllocatorHelper, givenExpectedSizeToMapWhenGetSizetoMapCalledThenExpectedValueReturned) { + EXPECT_EQ((alignUp(4 * GB - 8096, 4096)), OCLRT::getSizeToMap()); +} + int main(int argc, char **argv) { bool useDefaultListener = false; diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index 0c5ca84b13..2d1ce42525 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -170,9 +170,6 @@ std::string getRunPath(char *argv0) { return res; } -extern int preemptionModeFromDebugManager; -int preemptionModeFromDebugManager = -2; - int main(int argc, char **argv) { int retVal = 0; bool useDefaultListener = false; @@ -365,10 +362,6 @@ int main(int argc, char **argv) { gEnvironment->setMockFileNames(fclDebugVars.fileName, igcDebugVars.fileName); gEnvironment->setDefaultDebugVars(fclDebugVars, igcDebugVars, device); - // globally override-disable preemption to speed-up test execution - preemptionModeFromDebugManager = OCLRT::DebugManager.flags.ForcePreemptionMode.get(); - OCLRT::DebugManager.flags.ForcePreemptionMode.set(static_cast(PreemptionMode::Disabled)); - #if defined(__linux__) //ULTs timeout if (enable_alarm) { diff --git a/unit_tests/mocks/mock_compilers.h b/unit_tests/mocks/mock_compilers.h index 0a5191fe04..f8e07439b3 100644 --- a/unit_tests/mocks/mock_compilers.h +++ b/unit_tests/mocks/mock_compilers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -191,9 +191,7 @@ struct MockFclOclDeviceCtx : MockCIF { class MockCompilerInterface : public CompilerInterface { public: ~MockCompilerInterface() { - if (originalGlobalCompilerInterface != nullptr) { - CompilerInterface::pInstance = originalGlobalCompilerInterface; - } + CompilerInterface::pInstance = originalGlobalCompilerInterface; } bool isCompilerAvailable() const { @@ -318,4 +316,4 @@ template <> inline std::map &MockCompilerInterface::getDeviceContexts() { return getFclDeviceContexts(); } -} +} // namespace OCLRT diff --git a/unit_tests/mocks/mock_context.cpp b/unit_tests/mocks/mock_context.cpp index c9b9b4546d..0733a39794 100644 --- a/unit_tests/mocks/mock_context.cpp +++ b/unit_tests/mocks/mock_context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -63,8 +63,6 @@ MockContext::~MockContext() { delete specialQueue; specialQueue = nullptr; } - CompilerInterface::shutdown(); - BuiltIns::shutDown(); if (memoryManager->isAsyncDeleterEnabled()) { memoryManager->getDeferredDeleter()->removeClient(); } diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index f4576d6e26..a59f5ec4fc 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -97,6 +97,20 @@ class MockDevice : public Device { void setSourceLevelDebuggerActive(bool active) { this->deviceInfo.sourceLevelDebuggerActive = active; } + template + static T *createWithMemoryManager(const HardwareInfo *pHwInfo, + MemoryManager *memManager) { + pHwInfo = getDeviceInitHwInfo(pHwInfo); + T *device = new T(*pHwInfo); + if (memManager) { + device->setMemoryManager(memManager); + } + if (false == createDeviceImpl(pHwInfo, true, *device)) { + delete device; + return nullptr; + } + return device; + } private: bool forceWhitelistedRegs = false; diff --git a/unit_tests/os_interface/linux/CMakeLists.txt b/unit_tests/os_interface/linux/CMakeLists.txt index 100b8d5a33..c9f0c0fabc 100644 --- a/unit_tests/os_interface/linux/CMakeLists.txt +++ b/unit_tests/os_interface/linux/CMakeLists.txt @@ -20,6 +20,7 @@ set(IGDRCL_SRCS_tests_os_interface_linux ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/allocator_helper_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/device_factory_tests.cpp diff --git a/unit_tests/os_interface/linux/allocator_helper.cpp b/unit_tests/os_interface/linux/allocator_helper.cpp new file mode 100644 index 0000000000..73f15b3659 --- /dev/null +++ b/unit_tests/os_interface/linux/allocator_helper.cpp @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "runtime/os_interface/linux/allocator_helper.h" + +namespace OCLRT { +size_t getSizeToMap() { + return static_cast(1 * 1024 * 1024u); +} +} // namespace OCLRT diff --git a/unit_tests/os_interface/linux/allocator_helper_tests.cpp b/unit_tests/os_interface/linux/allocator_helper_tests.cpp new file mode 100644 index 0000000000..a21183a631 --- /dev/null +++ b/unit_tests/os_interface/linux/allocator_helper_tests.cpp @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "gtest/gtest.h" +#include "runtime/os_interface/linux/allocator_helper.h" + +TEST(AllocatorHelper, givenExpectedSizeToMapWhenGetSizetoMapCalledThenExpectedValueReturned) { + EXPECT_EQ(1 * 1024 * 1024u, OCLRT::getSizeToMap()); +} diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index d4e3ce8310..d8424edb04 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -705,6 +705,7 @@ class DrmCommandStreamEnhancedFixture DrmMockCustom *mock; DeviceCommandStreamReceiver *csr = nullptr; DrmMemoryManager *mm = nullptr; + MockDevice *device = nullptr; DebugManagerStateRestore *dbgState; void SetUp() { @@ -719,12 +720,15 @@ class DrmCommandStreamEnhancedFixture ASSERT_NE(nullptr, csr); mm = reinterpret_cast(csr->createMemoryManager(false)); ASSERT_NE(nullptr, mm); + device = MockDevice::createWithMemoryManager(platformDevices[0], mm); + ASSERT_NE(nullptr, device); + mm->device = device; } void TearDown() { //And close at destruction delete csr; - delete mm; + delete device; delete mock; delete dbgState; } @@ -942,19 +946,13 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenDrmCsrCreatedWithInactiveGemCloseWor class DrmCommandStreamBatchingTests : public Test { public: DrmAllocation *tagAllocation; - DrmAllocation *preemptionAllocation = nullptr; + DrmAllocation *preemptionAllocation; void SetUp() override { DrmCommandStreamEnhancedFixture::SetUp(); - tagAllocation = mm->allocateGraphicsMemory(1024, 4096); - if (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) { - preemptionAllocation = mm->allocateGraphicsMemory(1024, 4096); - } + tagAllocation = static_cast(device->getTagAllocation()); + preemptionAllocation = static_cast(device->getPreemptionAllocation()); } void TearDown() override { - if (preemptionAllocation) { - mm->freeGraphicsMemory(preemptionAllocation); - } - mm->freeGraphicsMemory(tagAllocation); DrmCommandStreamEnhancedFixture::TearDown(); } }; @@ -974,10 +972,10 @@ TEST_F(DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsAr BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; csr->flush(batchBuffer, EngineType::ENGINE_RCS, nullptr); - //preemption allocation in Mid Thread preemption mode - int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 1 : 0; + //preemption allocation + Sip Kernel + int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 2 : 0; - EXPECT_EQ(5 + ioctlExtraCnt, this->mock->ioctl_cnt.total); + EXPECT_EQ(6 + ioctlExtraCnt, this->mock->ioctl_cnt.total); uint64_t flags = I915_EXEC_RENDER | I915_EXEC_NO_RELOC; EXPECT_EQ(flags, this->mock->execBuffer.flags); @@ -1007,6 +1005,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT tCsr->setTagAllocation(tagAllocation); tCsr->setPreemptionCsrAllocation(preemptionAllocation); DispatchFlags dispatchFlags; + dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(device->getHardwareInfo()); tCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags); //make sure command buffer is recorded @@ -1015,10 +1014,10 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT EXPECT_NE(nullptr, cmdBuffers.peekHead()); //preemption allocation - size_t csrSurfaceCount = (tCsr->getMemoryManager()->device->getPreemptionMode() == PreemptionMode::MidThread) ? 1 : 0; + size_t csrSurfaceCount = (tCsr->getMemoryManager()->device->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0; - //preemption allocation in Mid Thread preemption mode - int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 1 : 0; + //preemption allocation + sipKernel + int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 2 : 0; auto recordedCmdBuffer = cmdBuffers.peekHead(); EXPECT_EQ(3u + csrSurfaceCount, recordedCmdBuffer->surfaces.size()); @@ -1035,7 +1034,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT EXPECT_EQ(tCsr->commandStream.getGraphicsAllocation(), recordedCmdBuffer->batchBuffer.commandBufferAllocation); - EXPECT_EQ(5 + ioctlExtraCnt, this->mock->ioctl_cnt.total); + EXPECT_EQ(6 + ioctlExtraCnt, this->mock->ioctl_cnt.total); EXPECT_EQ(0u, this->mock->execBuffer.flags); @@ -1066,6 +1065,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte DispatchFlags dispatchFlags; dispatchFlags.guardCommandBufferWithPipeControl = true; + dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(device->getHardwareInfo()); tCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags); auto &cmdBuffers = mockedSubmissionsAggregator->peekCommandBuffers(); @@ -1082,10 +1082,10 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte EXPECT_FALSE(commandBufferGraphicsAllocation->isResident()); //preemption allocation - size_t csrSurfaceCount = (tCsr->getMemoryManager()->device->getPreemptionMode() == PreemptionMode::MidThread) ? 1 : 0; + size_t csrSurfaceCount = (tCsr->getMemoryManager()->device->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0; - //preemption allocation in Mid Thread preemption mode - int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 1 : 0; + //preemption allocation +sip Kernel + int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 2 : 0; //validate that submited command buffer has what we want EXPECT_EQ(3u + csrSurfaceCount, this->mock->execBuffer.buffer_count); @@ -1107,7 +1107,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte EXPECT_TRUE(handleFound); } - EXPECT_EQ(6 + ioctlExtraCnt, this->mock->ioctl_cnt.total); + EXPECT_EQ(7 + ioctlExtraCnt, this->mock->ioctl_cnt.total); mm->freeGraphicsMemory(dummyAllocation); mm->freeGraphicsMemory(commandBuffer); diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index 0e54a5274d..cfbd6cb5d4 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -28,6 +28,7 @@ #include "runtime/helpers/ptr_math.h" #include "runtime/mem_obj/buffer.h" #include "runtime/mem_obj/image.h" +#include "runtime/os_interface/linux/allocator_helper.h" #include "runtime/os_interface/linux/drm_allocation.h" #include "runtime/os_interface/linux/drm_buffer_object.h" #include "runtime/os_interface/linux/drm_command_stream.h" @@ -1129,7 +1130,7 @@ TEST_F(DrmMemoryManagerTest, Given32BitDeviceWithMemoryManagerWhenInternalHeapIs memoryManager->device = pDevice.get(); auto allocator = memoryManager->getDrmInternal32BitAllocator(); - size_t size = 4 * GB - 4096; + size_t size = getSizeToMap(); auto alloc = allocator->allocate(size); EXPECT_NE(0llu, alloc); diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index c1074bae20..b059fc627e 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -26,6 +26,7 @@ #include "runtime/command_stream/device_command_stream.h" #include "runtime/command_stream/linear_stream.h" #include "runtime/command_stream/preemption.h" +#include "runtime/helpers/built_ins_helper.h" #include "runtime/gen_common/hw_cmds.h" #include "runtime/helpers/options.h" #include "runtime/helpers/translationtable_callbacks.h" @@ -35,6 +36,7 @@ #include "runtime/os_interface/windows/wddm_memory_manager.h" #include "unit_tests/fixtures/memory_management_fixture.h" +#include "unit_tests/mocks/mock_builtins.h" #include "unit_tests/mocks/mock_buffer.h" #include "unit_tests/mocks/mock_device.h" #include "unit_tests/mocks/mock_graphics_allocation.h" @@ -109,10 +111,9 @@ class WddmCommandStreamWithMockGdiFixture { memManager = csr->createMemoryManager(false); ASSERT_NE(nullptr, memManager); - device = MockDevice::create(platformDevices[0]); + device = MockDevice::createWithMemoryManager(platformDevices[0], memManager); ASSERT_NE(nullptr, device); memManager->device = device; - tagAllocation = memManager->allocateGraphicsMemory(1024, 4096); if (device->getPreemptionMode() == PreemptionMode::MidThread) { preemptionAllocation = memManager->allocateGraphicsMemory(1024, 4096); @@ -128,7 +129,6 @@ class WddmCommandStreamWithMockGdiFixture { } delete csr->getTagAddress(); delete csr; - delete memManager; wddm = nullptr; delete device; } @@ -687,6 +687,7 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt DispatchFlags dispatchFlags; dispatchFlags.guardCommandBufferWithPipeControl = true; dispatchFlags.requiresCoherency = true; + dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(device->getHardwareInfo()); mockCsr->flushTask(cs, 0u, dsh, ioh, ssh, 0u, dispatchFlags); auto &cmdBuffers = mockedSubmissionsAggregator->peekCommandBuffers(); @@ -699,8 +700,8 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt EXPECT_TRUE(cmdBuffers.peekIsEmpty()); - //preemption allocation - size_t csrSurfaceCount = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 1 : 0; + //preemption allocation + sip Kernel + size_t csrSurfaceCount = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0; EXPECT_EQ(1u, wddm->submitResult.called); auto csrCommandStream = mockCsr->commandStream.getGraphicsAllocation(); diff --git a/unit_tests/preemption/preemption_tests.cpp b/unit_tests/preemption/preemption_tests.cpp index 7e45c0a58c..af687bd0fc 100644 --- a/unit_tests/preemption/preemption_tests.cpp +++ b/unit_tests/preemption/preemption_tests.cpp @@ -35,8 +35,6 @@ using namespace OCLRT; -extern int preemptionModeFromDebugManager; - class ThreadGroupPreemptionTests : public DevicePreemptionTests { void SetUp() override { dbgRestore.reset(new DebugManagerStateRestore()); @@ -309,10 +307,6 @@ TEST_F(DevicePreemptionTests, setDefaultDisabledPreemptionNoMidBatchSupport) { EXPECT_EQ(PreemptionMode::Disabled, devCapabilities.defaultPreemptionMode); } -TEST(PreemptionTest, defaultMode) { - EXPECT_EQ(-1, preemptionModeFromDebugManager); -} - struct PreemptionHwTest : ::testing::Test, ::testing::WithParamInterface { }; diff --git a/unit_tests/tbx/CMakeLists.txt b/unit_tests/tbx/CMakeLists.txt index a9d6de12cf..cb775abed2 100644 --- a/unit_tests/tbx/CMakeLists.txt +++ b/unit_tests/tbx/CMakeLists.txt @@ -40,6 +40,7 @@ if(WIN32) ) else() target_sources(igdrcl_tbx_tests PRIVATE + ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/allocator_helper.cpp ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/options.cpp ) endif()