diff --git a/runtime/context/CMakeLists.txt b/runtime/context/CMakeLists.txt index 6c42f94fbb..eb06816f18 100644 --- a/runtime/context/CMakeLists.txt +++ b/runtime/context/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2018 Intel Corporation +# Copyright (C) 2018-2019 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -10,6 +10,7 @@ set(RUNTIME_SRCS_CONTEXT ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/context_extra.cpp ${CMAKE_CURRENT_SOURCE_DIR}/context.h ${CMAKE_CURRENT_SOURCE_DIR}/context.inl + ${CMAKE_CURRENT_SOURCE_DIR}/context_type.h ${CMAKE_CURRENT_SOURCE_DIR}/driver_diagnostics.cpp ${CMAKE_CURRENT_SOURCE_DIR}/driver_diagnostics.h ) diff --git a/runtime/context/context.h b/runtime/context/context.h index 637a30052c..cd6f9f54ae 100644 --- a/runtime/context/context.h +++ b/runtime/context/context.h @@ -1,11 +1,12 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once +#include "runtime/context/context_type.h" #include "runtime/device/device_vector.h" #include "runtime/context/driver_diagnostics.h" #include "runtime/helpers/base_object.h" @@ -26,12 +27,6 @@ struct OpenCLObjectMapper<_cl_context> { typedef class Context DerivedType; }; -enum class ContextType { - CONTEXT_TYPE_DEFAULT, - CONTEXT_TYPE_SPECIALIZED, - CONTEXT_TYPE_UNRESTRICTIVE -}; - class Context : public BaseObject<_cl_context> { public: static const cl_ulong objectMagic = 0xA4234321DC002130LL; diff --git a/runtime/context/context_type.h b/runtime/context/context_type.h new file mode 100644 index 0000000000..e943e9519f --- /dev/null +++ b/runtime/context/context_type.h @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +namespace OCLRT { + +enum class ContextType { + CONTEXT_TYPE_DEFAULT, + CONTEXT_TYPE_SPECIALIZED, + CONTEXT_TYPE_UNRESTRICTIVE +}; + +} // namespace OCLRT diff --git a/runtime/mem_obj/buffer.cpp b/runtime/mem_obj/buffer.cpp index be3e19d613..ffa2238407 100644 --- a/runtime/mem_obj/buffer.cpp +++ b/runtime/mem_obj/buffer.cpp @@ -132,8 +132,9 @@ Buffer *Buffer::create(Context *context, UNRECOVERABLE_IF(!memoryManager); GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType( - properties.flags, + properties, context->isSharedContext, + context->peekContextType(), HwHelper::renderCompressedBuffersSupported(context->getDevice(0)->getHardwareInfo()), memoryManager->isLocalMemorySupported()); @@ -333,26 +334,24 @@ void Buffer::checkMemory(cl_mem_flags flags, return; } -GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(cl_mem_flags flags, bool sharedContext, bool renderCompressedBuffers, bool isLocalMemoryEnabled) { - if (is32bit) { +GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const MemoryProperties &properties, bool sharedContext, + ContextType contextType, bool renderCompressedBuffers, + bool isLocalMemoryEnabled) { + if (is32bit || sharedContext) { return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; } - if (sharedContext) { - return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; - } - - GraphicsAllocation::AllocationType type = GraphicsAllocation::AllocationType::BUFFER; - - if (isValueSet(flags, CL_MEM_USE_HOST_PTR)) { - if (isValueSet(flags, CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL) || !isLocalMemoryEnabled) { - type = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; + if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR)) { + if (isValueSet(properties.flags, CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL) || !isLocalMemoryEnabled) { + return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; } - } else if (renderCompressedBuffers) { - type = GraphicsAllocation::AllocationType::BUFFER_COMPRESSED; + return GraphicsAllocation::AllocationType::BUFFER; } - return type; + if (MemObjHelper::isSuitableForRenderCompression(renderCompressedBuffers, properties, contextType)) { + return GraphicsAllocation::AllocationType::BUFFER_COMPRESSED; + } + return GraphicsAllocation::AllocationType::BUFFER; } bool Buffer::isReadOnlyMemoryPermittedByFlags(cl_mem_flags flags) { diff --git a/runtime/mem_obj/buffer.h b/runtime/mem_obj/buffer.h index 0cc5f404d9..a142edae45 100644 --- a/runtime/mem_obj/buffer.h +++ b/runtime/mem_obj/buffer.h @@ -6,6 +6,7 @@ */ #pragma once +#include "runtime/context/context_type.h" #include "runtime/memory_manager/memory_constants.h" #include "runtime/mem_obj/mem_obj.h" #include "runtime/helpers/basic_math.h" @@ -138,7 +139,9 @@ class Buffer : public MemObj { bool &isZeroCopy, bool ©MemoryFromHostPtr, MemoryManager *memMngr); - static GraphicsAllocation::AllocationType getGraphicsAllocationType(cl_mem_flags flags, bool sharedContext, bool renderCompressedBuffers, bool localMemoryEnabled); + static GraphicsAllocation::AllocationType getGraphicsAllocationType(const MemoryProperties &properties, bool sharedContext, + ContextType contextType, bool renderCompressedBuffers, + bool localMemoryEnabled); static bool isReadOnlyMemoryPermittedByFlags(cl_mem_flags flags); void transferData(void *dst, void *src, size_t copySize, size_t copyOffset); diff --git a/runtime/mem_obj/mem_obj_helper.cpp b/runtime/mem_obj/mem_obj_helper.cpp index fc3bf8f983..4afc4210e2 100644 --- a/runtime/mem_obj/mem_obj_helper.cpp +++ b/runtime/mem_obj/mem_obj_helper.cpp @@ -30,7 +30,8 @@ bool MemObjHelper::parseMemoryProperties(const cl_mem_properties_intel *properti return true; } -AllocationProperties MemObjHelper::getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType type) { +AllocationProperties MemObjHelper::getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, + size_t size, GraphicsAllocation::AllocationType type) { AllocationProperties allocationProperties(allocateMemory, size, type); allocationProperties.flags.uncacheable = isValueSet(flags, CL_MEM_LOCALLY_UNCACHED_RESOURCE); return allocationProperties; @@ -44,6 +45,10 @@ DevicesBitfield MemObjHelper::getDevicesBitfield(const MemoryProperties &propert return DevicesBitfield(0); } +bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressedBuffers, const MemoryProperties &properties, ContextType contextType) { + return renderCompressedBuffers; +} + bool MemObjHelper::validateExtraMemoryProperties(const MemoryProperties &properties) { return true; } diff --git a/runtime/mem_obj/mem_obj_helper.h b/runtime/mem_obj/mem_obj_helper.h index 42e56d1006..dd5ebd98bc 100644 --- a/runtime/mem_obj/mem_obj_helper.h +++ b/runtime/mem_obj/mem_obj_helper.h @@ -10,6 +10,7 @@ #include "common/helpers/bit_helpers.h" #include "mem_obj_types.h" #include "public/cl_ext_private.h" +#include "runtime/context/context_type.h" #include "runtime/mem_obj/mem_obj.h" #include "runtime/memory_manager/memory_manager.h" @@ -41,7 +42,8 @@ class MemObjHelper { return validateExtraMemoryProperties(properties); } - static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType type); + static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, + size_t size, GraphicsAllocation::AllocationType type); static AllocationProperties getAllocationProperties(ImageInfo *imgInfo, bool allocateMemory); static DevicesBitfield getDevicesBitfield(const MemoryProperties &properties); @@ -54,6 +56,8 @@ class MemObjHelper { return isFieldValid(flags, allValidFlags); } + static bool isSuitableForRenderCompression(bool renderCompressedBuffers, const MemoryProperties &properties, ContextType contextType); + protected: static bool checkMemFlagsForBuffer(const MemoryProperties &properties) { MemoryProperties additionalAcceptedProperties; diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index a513c33506..194c11eb1f 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -16,18 +16,19 @@ #include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/os_context.h" +#include "test.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/fixtures/execution_model_fixture.h" #include "unit_tests/fixtures/memory_management_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/gtest_helpers.h" -#include "test.h" #include "unit_tests/mocks/mock_graphics_allocation.h" #include "unit_tests/mocks/mock_kernel.h" #include "unit_tests/mocks/mock_program.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/program/program_from_binary.h" #include "unit_tests/program/program_tests.h" +#include "unit_tests/utilities/base_object_utils.h" #include @@ -1684,46 +1685,46 @@ HWTEST_F(KernelResidencyTest, givenKernelWhenMakeResidentIsCalledThenKernelIsaIs } TEST(KernelImageDetectionTests, givenKernelWithImagesOnlyWhenItIsAskedIfItHasImagesOnlyThenTrueIsReturned) { - auto device = std::make_unique(*platformDevices[0]); auto pKernelInfo = std::make_unique(); - pKernelInfo->kernelArgInfo.resize(3); pKernelInfo->kernelArgInfo[2].isImage = true; pKernelInfo->kernelArgInfo[1].isMediaBlockImage = true; pKernelInfo->kernelArgInfo[0].isMediaImage = true; - MockProgram program(*device->getExecutionEnvironment()); - std::unique_ptr kernel(new MockKernel(&program, *pKernelInfo, *device)); + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(platformDevices[0])); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *pKernelInfo, *device)); EXPECT_FALSE(kernel->usesOnlyImages()); kernel->initialize(); EXPECT_TRUE(kernel->usesOnlyImages()); } TEST(KernelImageDetectionTests, givenKernelWithImagesAndBuffersWhenItIsAskedIfItHasImagesOnlyThenFalseIsReturned) { - auto device = std::make_unique(*platformDevices[0]); auto pKernelInfo = std::make_unique(); - pKernelInfo->kernelArgInfo.resize(3); pKernelInfo->kernelArgInfo[2].isImage = true; pKernelInfo->kernelArgInfo[1].isBuffer = true; pKernelInfo->kernelArgInfo[0].isMediaImage = true; - MockProgram program(*device->getExecutionEnvironment()); - std::unique_ptr kernel(new MockKernel(&program, *pKernelInfo, *device)); + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(platformDevices[0])); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *pKernelInfo, *device)); EXPECT_FALSE(kernel->usesOnlyImages()); kernel->initialize(); EXPECT_FALSE(kernel->usesOnlyImages()); } TEST(KernelImageDetectionTests, givenKernelWithNoImagesWhenItIsAskedIfItHasImagesOnlyThenFalseIsReturned) { - auto device = std::make_unique(*platformDevices[0]); auto pKernelInfo = std::make_unique(); - pKernelInfo->kernelArgInfo.resize(1); pKernelInfo->kernelArgInfo[0].isBuffer = true; - MockProgram program(*device->getExecutionEnvironment()); - std::unique_ptr kernel(new MockKernel(&program, *pKernelInfo, *device)); + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(platformDevices[0])); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *pKernelInfo, *device)); EXPECT_FALSE(kernel->usesOnlyImages()); kernel->initialize(); EXPECT_FALSE(kernel->usesOnlyImages()); @@ -2319,8 +2320,10 @@ TEST(KernelTest, givenKernelWithKernelInfoWith64bitPointerSizeThenReport64bit) { TEST(KernelTest, givenFtrRenderCompressedBuffersWhenInitializingArgsWithNonStatefulAccessThenMarkKernelForAuxTranslation) { HardwareInfo localHwInfo = *platformDevices[0]; - auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(&localHwInfo)); - MockKernelWithInternals kernel(*device); + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(&localHwInfo)); + auto context = clUniquePtr(new MockContext(device.get())); + context->setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE); + MockKernelWithInternals kernel(*device, context.get()); kernel.kernelInfo.kernelArgInfo.resize(1); kernel.kernelInfo.kernelArgInfo.at(0).typeStr = "char *"; @@ -2340,12 +2343,13 @@ TEST(KernelTest, givenFtrRenderCompressedBuffersWhenInitializingArgsWithNonState TEST(KernelTest, givenDebugVariableSetWhenKernelHasStatefulBufferAccessThenMarkKernelForAuxTranslation) { DebugManagerStateRestore restore; - HardwareInfo localHwInfo = *platformDevices[0]; - DebugManager.flags.RenderCompressedBuffersEnabled.set(1); - auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(&localHwInfo)); - MockKernelWithInternals kernel(*device); + HardwareInfo localHwInfo = *platformDevices[0]; + + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(&localHwInfo)); + auto context = clUniquePtr(new MockContext(device.get())); + MockKernelWithInternals kernel(*device, context.get()); kernel.kernelInfo.kernelArgInfo.resize(1); kernel.kernelInfo.kernelArgInfo.at(0).typeStr = "char *"; diff --git a/unit_tests/mem_obj/buffer_tests.cpp b/unit_tests/mem_obj/buffer_tests.cpp index 7e28aef982..0ed669728e 100644 --- a/unit_tests/mem_obj/buffer_tests.cpp +++ b/unit_tests/mem_obj/buffer_tests.cpp @@ -289,8 +289,8 @@ TEST(Buffer, givenAllocHostPtrFlagPassedToBufferCreateWhenNoSharedContextOrRende } TEST(Buffer, givenRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferCompressedTypeIsReturnedIn64Bit) { - cl_mem_flags flags = 0; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, false, true, false); + MemoryProperties properties; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false); if (is32bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } else { @@ -299,26 +299,28 @@ TEST(Buffer, givenRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenB } TEST(Buffer, givenSharedContextWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) { - cl_mem_flags flags = 0; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, true, false, false); + MemoryProperties properties; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenSharedContextAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) { - cl_mem_flags flags = 0; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, true, true, false); + MemoryProperties properties; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) { - cl_mem_flags flags = CL_MEM_USE_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, false, false, false); + MemoryProperties properties; + properties.flags = CL_MEM_USE_HOST_PTR; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) { - cl_mem_flags flags = CL_MEM_USE_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, false, false, true); + MemoryProperties properties; + properties.flags = CL_MEM_USE_HOST_PTR; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true); if (is64bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type); } else { @@ -327,8 +329,9 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledWhenAllocationTypeIsQueried } TEST(Buffer, givenAllocHostPtrFlagWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) { - cl_mem_flags flags = CL_MEM_ALLOC_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, false, false, false); + MemoryProperties properties; + properties.flags = CL_MEM_ALLOC_HOST_PTR; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false); if (is64bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type); } else { @@ -337,14 +340,16 @@ TEST(Buffer, givenAllocHostPtrFlagWhenAllocationTypeIsQueriedThenBufferTypeIsRet } TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferMemoryTypeIsReturned) { - cl_mem_flags flags = CL_MEM_USE_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, false, true, false); + MemoryProperties properties; + properties.flags = CL_MEM_USE_HOST_PTR; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferMemoryTypeIsReturned) { - cl_mem_flags flags = CL_MEM_USE_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, false, true, true); + MemoryProperties properties; + properties.flags = CL_MEM_USE_HOST_PTR; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true); if (is64bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type); } else { @@ -353,14 +358,16 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledAndRenderCompressedBuffersE } TEST(Buffer, givenUseHostPointerFlagAndForceSharedPhysicalStorageWhenLocalMemoryIsEnabledThenBufferHostMemoryTypeIsReturned) { - cl_mem_flags flags = CL_MEM_USE_HOST_PTR | CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, false, true, true); + MemoryProperties properties; + properties.flags = CL_MEM_USE_HOST_PTR | CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenAllocHostPtrFlagAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferCompressedTypeIsReturned) { - cl_mem_flags flags = CL_MEM_ALLOC_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, false, true, false); + MemoryProperties properties; + properties.flags = CL_MEM_ALLOC_HOST_PTR; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false); if (is64bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type); } else { @@ -369,8 +376,8 @@ TEST(Buffer, givenAllocHostPtrFlagAndRenderCompressedBuffersEnabledWhenAllocatio } TEST(Buffer, givenZeroFlagsNoSharedContextAndRenderCompressedBuffersDisabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) { - cl_mem_flags flags = 0; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(flags, false, false, false); + MemoryProperties properties; + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false); if (is32bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } else { @@ -409,6 +416,7 @@ struct RenderCompressedBuffersTests : public ::testing::Test { localHwInfo = *platformDevices[0]; device.reset(Device::create(&localHwInfo, new ExecutionEnvironment(), 0u)); context = std::make_unique(device.get(), true); + context->setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE); } cl_int retVal = CL_SUCCESS; diff --git a/unit_tests/os_interface/debug_settings_manager_tests.cpp b/unit_tests/os_interface/debug_settings_manager_tests.cpp index f8d55e7dd5..2e82ec202c 100644 --- a/unit_tests/os_interface/debug_settings_manager_tests.cpp +++ b/unit_tests/os_interface/debug_settings_manager_tests.cpp @@ -15,6 +15,7 @@ #include "unit_tests/mocks/mock_mdi.h" #include "unit_tests/mocks/mock_program.h" #include "unit_tests/os_interface/debug_settings_manager_fixture.h" +#include "unit_tests/utilities/base_object_utils.h" #include #include @@ -451,11 +452,11 @@ TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsLocalBuffer) { } TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsBufferNotSet) { - auto kernelInfo = std::make_unique(); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); KernelArgPatchInfo kernelArgPatchInfo; @@ -479,14 +480,14 @@ TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsBufferNotSet) { } TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsBuffer) { - MockContext context; - auto buffer = BufferHelper<>::create(&context); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto buffer = BufferHelper<>::create(context.get()); cl_mem clObj = buffer; auto kernelInfo = std::make_unique(); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment(), &context, false); - auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); KernelArgPatchInfo kernelArgPatchInfo; @@ -517,11 +518,11 @@ TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsBuffer) { } TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsSampler) { - auto kernelInfo = std::make_unique(); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); KernelArgPatchInfo kernelArgPatchInfo; @@ -543,9 +544,10 @@ TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsSampler) { TEST(DebugSettingsManager, WithDebugFunctionalityDumpKernelArgsImageNotSet) { auto kernelInfo = std::make_unique(); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - auto kernel = unique_ptr(new MockKernel(&program, *kernelInfo, *device)); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + auto kernel = clUniquePtr(new MockKernel(program.get(), *kernelInfo, *device)); SKernelBinaryHeaderCommon kernelHeader; char surfaceStateHeap[0x80]; diff --git a/unit_tests/scheduler/scheduler_kernel_tests.cpp b/unit_tests/scheduler/scheduler_kernel_tests.cpp index a14afc846d..953fee7e8c 100644 --- a/unit_tests/scheduler/scheduler_kernel_tests.cpp +++ b/unit_tests/scheduler/scheduler_kernel_tests.cpp @@ -1,21 +1,23 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ -#include +#include "runtime/helpers/options.h" #include "runtime/scheduler/scheduler_kernel.h" +#include "test.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_program.h" #include "unit_tests/mocks/mock_device.h" #include "unit_tests/mocks/mock_graphics_allocation.h" #include "unit_tests/mocks/mock_ostime.h" -#include "runtime/helpers/options.h" +#include "unit_tests/utilities/base_object_utils.h" #include "gtest/gtest.h" -#include "test.h" +#include #include using namespace OCLRT; @@ -116,12 +118,13 @@ TEST(SchedulerKernelTest, getCurbeSize) { } TEST(SchedulerKernelTest, setArgsForSchedulerKernel) { - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - program.setDevice(device.get()); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + program->setDevice(device.get()); unique_ptr info(nullptr); KernelInfo *infoPtr = nullptr; - unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(program, *device.get(), infoPtr)); + unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(*program, *device, infoPtr)); info.reset(infoPtr); unique_ptr allocs[9]; @@ -145,13 +148,14 @@ TEST(SchedulerKernelTest, setArgsForSchedulerKernel) { } TEST(SchedulerKernelTest, setArgsForSchedulerKernelWithNullDebugQueue) { - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - program.setDevice(device.get()); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + program->setDevice(device.get()); unique_ptr info(nullptr); KernelInfo *infoPtr = nullptr; - unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(program, *device.get(), infoPtr)); + unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(*program, *device, infoPtr)); info.reset(infoPtr); unique_ptr allocs[9]; @@ -178,13 +182,14 @@ TEST(SchedulerKernelTest, createKernelReflectionForForcedSchedulerDispatch) { DebugManagerStateRestore dbgRestorer; DebugManager.flags.ForceDispatchScheduler.set(true); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - program.setDevice(device.get()); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + program->setDevice(device.get()); unique_ptr info(nullptr); KernelInfo *infoPtr = nullptr; - unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(program, *device.get(), infoPtr)); + unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(*program, *device, infoPtr)); info.reset(infoPtr); scheduler->createReflectionSurface(); @@ -196,13 +201,14 @@ TEST(SchedulerKernelTest, createKernelReflectionSecondTimeForForcedSchedulerDisp DebugManagerStateRestore dbgRestorer; DebugManager.flags.ForceDispatchScheduler.set(true); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - program.setDevice(device.get()); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + program->setDevice(device.get()); unique_ptr info(nullptr); KernelInfo *infoPtr = nullptr; - unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(program, *device.get(), infoPtr)); + unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(*program, *device, infoPtr)); info.reset(infoPtr); scheduler->createReflectionSurface(); @@ -218,13 +224,14 @@ TEST(SchedulerKernelTest, createKernelReflectionForSchedulerDoesNothing) { DebugManagerStateRestore dbgRestorer; DebugManager.flags.ForceDispatchScheduler.set(false); - auto device = unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockProgram program(*device->getExecutionEnvironment()); - program.setDevice(device.get()); + unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto context = clUniquePtr(new MockContext(device.get())); + auto program = clUniquePtr(new MockProgram(*device->getExecutionEnvironment(), context.get(), false)); + program->setDevice(device.get()); unique_ptr info(nullptr); KernelInfo *infoPtr = nullptr; - unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(program, *device.get(), infoPtr)); + unique_ptr scheduler = unique_ptr(MockSchedulerKernel::create(*program, *device, infoPtr)); info.reset(infoPtr); scheduler->createReflectionSurface();