Add option to disable caching for a resource
Introduce CL_MEM_LOCALLY_UNCACHED_RESOURCE flag that can be used with clCreateBufferWithPropertiesINTEL() Change-Id: I9f208f00952cdca7482371ec21cbc57c08435b52 Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
parent
3a11da8ec8
commit
2d321cb557
|
@ -48,6 +48,7 @@ using cl_mem_flags_intel = cl_mem_flags;
|
|||
******************************/
|
||||
|
||||
#define CL_MEM_FLAGS_INTEL 0x10001
|
||||
#define CL_MEM_LOCALLY_UNCACHED_RESOURCE (1 << 18)
|
||||
|
||||
// Used with clEnqueueVerifyMemory
|
||||
#define CL_MEM_COMPARE_EQUAL 0u
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -29,12 +29,10 @@ bool MemObjHelper::parseMemoryProperties(const cl_mem_properties_intel *properti
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MemObjHelper::validateExtraMemoryProperties(const MemoryProperties &properties) {
|
||||
return true;
|
||||
}
|
||||
|
||||
AllocationProperties MemObjHelper::getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType type) {
|
||||
return AllocationProperties(allocateMemory, size, type);
|
||||
AllocationProperties allocationProperties(allocateMemory, size, type);
|
||||
allocationProperties.flags.uncacheable = !!(flags & CL_MEM_LOCALLY_UNCACHED_RESOURCE);
|
||||
return allocationProperties;
|
||||
}
|
||||
|
||||
AllocationProperties MemObjHelper::getAllocationProperties(ImageInfo *imgInfo) {
|
||||
|
@ -45,4 +43,11 @@ DevicesBitfield MemObjHelper::getDevicesBitfield(const MemoryProperties &propert
|
|||
return DevicesBitfield(0);
|
||||
}
|
||||
|
||||
bool MemObjHelper::validateExtraMemoryProperties(const MemoryProperties &properties) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void MemObjHelper::addExtraMemoryProperties(MemoryProperties &properties) {
|
||||
}
|
||||
|
||||
} // namespace OCLRT
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -16,21 +16,12 @@ namespace OCLRT {
|
|||
|
||||
class MemObjHelper {
|
||||
public:
|
||||
static bool checkMemFlagsForBuffer(cl_mem_flags flags) {
|
||||
const cl_mem_flags allValidFlags =
|
||||
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
||||
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR |
|
||||
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS;
|
||||
|
||||
return (flags & (~allValidFlags)) == 0;
|
||||
}
|
||||
|
||||
static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct);
|
||||
|
||||
static bool validateMemoryProperties(const MemoryProperties &properties) {
|
||||
|
||||
/* Are there some invalid flag bits? */
|
||||
if (!MemObjHelper::checkMemFlagsForBuffer(properties.flags)) {
|
||||
if (!MemObjHelper::checkMemFlagsForBuffer(properties)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -48,8 +39,6 @@ class MemObjHelper {
|
|||
return validateExtraMemoryProperties(properties);
|
||||
}
|
||||
|
||||
static bool validateExtraMemoryProperties(const MemoryProperties &properties);
|
||||
|
||||
static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType type);
|
||||
static AllocationProperties getAllocationProperties(ImageInfo *imgInfo);
|
||||
|
||||
|
@ -65,5 +54,27 @@ class MemObjHelper {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
static bool checkMemFlagsForBuffer(const MemoryProperties &properties) {
|
||||
MemoryProperties additionalAcceptedProperties;
|
||||
addExtraMemoryProperties(additionalAcceptedProperties);
|
||||
|
||||
const cl_mem_flags allValidFlags =
|
||||
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
||||
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR |
|
||||
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS |
|
||||
additionalAcceptedProperties.flags;
|
||||
|
||||
const cl_mem_flags allValidFlagsIntel = CL_MEM_LOCALLY_UNCACHED_RESOURCE |
|
||||
additionalAcceptedProperties.flags_intel;
|
||||
|
||||
return ((properties.flags & (~allValidFlags)) == 0) &&
|
||||
((properties.flags_intel & (~allValidFlagsIntel)) == 0);
|
||||
}
|
||||
|
||||
static bool validateExtraMemoryProperties(const MemoryProperties &properties);
|
||||
|
||||
static void addExtraMemoryProperties(MemoryProperties &properties);
|
||||
};
|
||||
} // namespace OCLRT
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#pragma once
|
||||
#include "public/cl_ext_private.h"
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
#include "runtime/memory_manager/host_ptr_defines.h"
|
||||
|
@ -59,18 +60,16 @@ struct AllocationProperties {
|
|||
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::UNKNOWN;
|
||||
ImageInfo *imgInfo = nullptr;
|
||||
|
||||
AllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(true, size, allocationType) {}
|
||||
AllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType) : size(size), allocationType(allocationType) {
|
||||
AllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType)
|
||||
: AllocationProperties(true, size, allocationType) {}
|
||||
AllocationProperties(bool allocateMemory, size_t size, GraphicsAllocation::AllocationType allocationType)
|
||||
: size(size), allocationType(allocationType) {
|
||||
allFlags = 0;
|
||||
flags.flushL3RequiredForRead = 1;
|
||||
flags.flushL3RequiredForWrite = 1;
|
||||
flags.allocateMemory = allocateMemory;
|
||||
}
|
||||
AllocationProperties(ImageInfo *imgInfo) : allocationType(GraphicsAllocation::AllocationType::IMAGE) {
|
||||
allFlags = 0;
|
||||
flags.flushL3RequiredForRead = 1;
|
||||
flags.flushL3RequiredForWrite = 1;
|
||||
flags.allocateMemory = 1;
|
||||
AllocationProperties(ImageInfo *imgInfo) : AllocationProperties(true, 0, GraphicsAllocation::AllocationType::IMAGE) {
|
||||
this->imgInfo = imgInfo;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -92,6 +92,7 @@ set(IGDRCL_SRCS_tests_api
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/cl_intel_accelerator_tests.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_intel_motion_estimation.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_link_program_tests.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_mem_locally_uncached_resource_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_release_command_queue_tests.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_release_context_tests.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_release_event_tests.inl
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2017-2018 Intel Corporation
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -43,18 +43,10 @@ TEST_P(clCreateBufferValidFlagsTests, GivenValidFlagsWhenCreatingBufferThenBuffe
|
|||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
clReleaseMemObject(buffer);
|
||||
};
|
||||
|
||||
struct clCreateBufferWithPropertiesINTELValidFlagsTests : public clCreateBufferTemplateTests {
|
||||
cl_uchar pHostPtr[64];
|
||||
};
|
||||
cl_mem_properties_intel properties[] = {CL_MEM_FLAGS, flags, 0};
|
||||
|
||||
TEST_P(clCreateBufferWithPropertiesINTELValidFlagsTests, GivenValidPropertiesWhenCreatingBufferThenBufferIsCreated) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
CL_MEM_FLAGS, GetParam() | CL_MEM_USE_HOST_PTR,
|
||||
0};
|
||||
|
||||
auto buffer = clCreateBufferWithPropertiesINTEL(pContext, properties, 64, pHostPtr, &retVal);
|
||||
buffer = clCreateBufferWithPropertiesINTEL(pContext, properties, 64, pHostPtr, &retVal);
|
||||
EXPECT_NE(nullptr, buffer);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
|
@ -75,13 +67,7 @@ INSTANTIATE_TEST_CASE_P(
|
|||
clCreateBufferValidFlagsTests,
|
||||
testing::ValuesIn(validFlags));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
CreateBufferCheckFlags,
|
||||
clCreateBufferWithPropertiesINTELValidFlagsTests,
|
||||
testing::ValuesIn(validFlags));
|
||||
|
||||
struct clCreateBufferInvalidFlagsTests : public clCreateBufferTemplateTests {
|
||||
};
|
||||
using clCreateBufferInvalidFlagsTests = clCreateBufferTemplateTests;
|
||||
|
||||
TEST_P(clCreateBufferInvalidFlagsTests, GivenInvalidFlagsWhenCreatingBufferThenBufferIsNotCreated) {
|
||||
cl_mem_flags flags = GetParam();
|
||||
|
@ -89,16 +75,10 @@ TEST_P(clCreateBufferInvalidFlagsTests, GivenInvalidFlagsWhenCreatingBufferThenB
|
|||
auto buffer = clCreateBuffer(pContext, flags, 64, nullptr, &retVal);
|
||||
EXPECT_EQ(nullptr, buffer);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
};
|
||||
|
||||
struct clCreateBufferWithPropertiesINTELInvalidPropertiesTests : public clCreateBufferTemplateTests {
|
||||
};
|
||||
cl_mem_properties_intel properties[] = {CL_MEM_FLAGS, flags, 0};
|
||||
|
||||
TEST_P(clCreateBufferWithPropertiesINTELInvalidPropertiesTests, GivenInvalidPropertiesWhenCreatingBufferThenBufferIsNotCreated) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
(1 << 30), CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR};
|
||||
|
||||
auto buffer = clCreateBufferWithPropertiesINTEL(pContext, properties, 64, nullptr, &retVal);
|
||||
buffer = clCreateBufferWithPropertiesINTEL(pContext, properties, 64, nullptr, &retVal);
|
||||
EXPECT_EQ(nullptr, buffer);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
};
|
||||
|
@ -120,10 +100,55 @@ INSTANTIATE_TEST_CASE_P(
|
|||
clCreateBufferInvalidFlagsTests,
|
||||
testing::ValuesIn(invalidFlags));
|
||||
|
||||
using clCreateBufferValidFlagsIntelTests = clCreateBufferTemplateTests;
|
||||
|
||||
TEST_P(clCreateBufferValidFlagsIntelTests, GivenValidFlagsIntelWhenCreatingBufferThenBufferIsCreated) {
|
||||
cl_mem_properties_intel properties[] = {CL_MEM_FLAGS_INTEL, GetParam(), 0};
|
||||
|
||||
auto buffer = clCreateBufferWithPropertiesINTEL(pContext, properties, 64, nullptr, &retVal);
|
||||
EXPECT_NE(nullptr, buffer);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
clReleaseMemObject(buffer);
|
||||
};
|
||||
|
||||
static cl_mem_flags validFlagsIntel[] = {
|
||||
CL_MEM_LOCALLY_UNCACHED_RESOURCE,
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
CreateBufferCheckFlags,
|
||||
clCreateBufferWithPropertiesINTELInvalidPropertiesTests,
|
||||
testing::ValuesIn(invalidFlags));
|
||||
CreateBufferCheckFlagsIntel,
|
||||
clCreateBufferValidFlagsIntelTests,
|
||||
testing::ValuesIn(validFlagsIntel));
|
||||
|
||||
using clCreateBufferInvalidFlagsIntelTests = clCreateBufferTemplateTests;
|
||||
|
||||
TEST_P(clCreateBufferInvalidFlagsIntelTests, GivenInvalidFlagsIntelWhenCreatingBufferThenBufferIsNotCreated) {
|
||||
cl_mem_properties_intel properties[] = {CL_MEM_FLAGS_INTEL, GetParam(), 0};
|
||||
|
||||
auto buffer = clCreateBufferWithPropertiesINTEL(pContext, properties, 64, nullptr, &retVal);
|
||||
EXPECT_EQ(nullptr, buffer);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
};
|
||||
|
||||
cl_mem_flags invalidFlagsIntel[] = {
|
||||
0xffcc,
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
CreateBufferCheckFlagsIntel,
|
||||
clCreateBufferInvalidFlagsIntelTests,
|
||||
testing::ValuesIn(invalidFlagsIntel));
|
||||
|
||||
using clCreateBufferInvalidProperties = clCreateBufferTemplateTests;
|
||||
|
||||
TEST_F(clCreateBufferInvalidProperties, GivenInvalidPropertyKeyWhenCreatingBufferThenBufferIsNotCreated) {
|
||||
cl_mem_properties_intel properties[] = {(cl_mem_properties_intel(1) << 31), 0, 0};
|
||||
|
||||
auto buffer = clCreateBufferWithPropertiesINTEL(pContext, properties, 64, nullptr, &retVal);
|
||||
EXPECT_EQ(nullptr, buffer);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
};
|
||||
|
||||
TEST_F(clCreateBufferTests, GivenValidParametersWhenCreatingBufferThenSuccessIsReturned) {
|
||||
cl_mem_flags flags = CL_MEM_USE_HOST_PTR;
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "public/cl_ext_private.h"
|
||||
#include "runtime/api/api.h"
|
||||
#include "runtime/command_queue/command_queue_hw.h"
|
||||
#include "runtime/command_stream/command_stream_receiver.h"
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/gen_common/hw_cmds.h"
|
||||
#include "runtime/gmm_helper/gmm_helper.h"
|
||||
#include "runtime/helpers/state_base_address.h"
|
||||
#include "runtime/kernel/kernel.h"
|
||||
#include "test.h"
|
||||
#include "unit_tests/fixtures/hello_world_fixture.h"
|
||||
#include "unit_tests/helpers/hw_parse.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
namespace clMemLocallyUncachedResourceTests {
|
||||
|
||||
struct clMemLocallyUncachedResourceFixture : Test<HelloWorldFixture<HelloWorldFixtureFactory>>,
|
||||
::testing::WithParamInterface<bool> {};
|
||||
|
||||
HWTEST_P(clMemLocallyUncachedResourceFixture, GivenLocallyCachedOrUncachedBufferWhenItIsSetAndQueuedThenItIsCorrectlyCached) {
|
||||
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
|
||||
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
|
||||
|
||||
const size_t n = 512;
|
||||
size_t globalWorkSize[3] = {n, 1, 1};
|
||||
size_t localWorkSize[3] = {256, 1, 1};
|
||||
bool useUncachedFlag = GetParam();
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
std::unique_ptr<Kernel> kernel(Kernel::create(pProgram, *pProgram->getKernelInfo("CopyBuffer"), &retVal));
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
cl_mem_properties_intel propertiesUncached[] = {CL_MEM_FLAGS_INTEL, CL_MEM_LOCALLY_UNCACHED_RESOURCE, 0};
|
||||
cl_mem_properties_intel *properties = (useUncachedFlag ? propertiesUncached : nullptr);
|
||||
auto buffer1 = clCreateBufferWithPropertiesINTEL(context, properties, n * sizeof(float), nullptr, nullptr);
|
||||
auto buffer2 = clCreateBufferWithPropertiesINTEL(context, properties, n * sizeof(float), nullptr, nullptr);
|
||||
|
||||
retVal = clSetKernelArg(kernel.get(), 0, sizeof(cl_mem), &buffer1);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
auto surfaceStateHeapAddress = kernel.get()->getSurfaceStateHeap();
|
||||
auto surfaceStateHeapAddressOffset = kernel.get()->getKernelInfo().kernelArgInfo[0].offsetHeap;
|
||||
auto surfaceState = reinterpret_cast<RENDER_SURFACE_STATE *>(ptrOffset(surfaceStateHeapAddress, surfaceStateHeapAddressOffset));
|
||||
auto expectedMocs = pDevice->getGmmHelper()->getMOCS(useUncachedFlag ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED
|
||||
: GMM_RESOURCE_USAGE_OCL_BUFFER);
|
||||
EXPECT_EQ(expectedMocs, surfaceState->getMemoryObjectControlState());
|
||||
|
||||
retVal = clSetKernelArg(kernel.get(), 1, sizeof(cl_mem), &buffer2);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
surfaceStateHeapAddressOffset = kernel.get()->getKernelInfo().kernelArgInfo[1].offsetHeap;
|
||||
surfaceState = reinterpret_cast<RENDER_SURFACE_STATE *>(ptrOffset(surfaceStateHeapAddress, surfaceStateHeapAddressOffset));
|
||||
EXPECT_EQ(expectedMocs, surfaceState->getMemoryObjectControlState());
|
||||
|
||||
EXPECT_TRUE(kernel->isPatched());
|
||||
retVal = clEnqueueNDRangeKernel(pCmdQ, kernel.get(), 1, nullptr, globalWorkSize, localWorkSize, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
auto pCmdQHw = reinterpret_cast<CommandQueueHw<FamilyType> *>(pCmdQ);
|
||||
ASSERT_NE(nullptr, pCmdQHw);
|
||||
auto &csr = pCmdQHw->getCommandStreamReceiver();
|
||||
HardwareParse hwParse;
|
||||
hwParse.parseCommands<FamilyType>(csr.getCS(0), 0);
|
||||
auto itorCmd = find<STATE_BASE_ADDRESS *>(hwParse.cmdList.begin(), hwParse.cmdList.end());
|
||||
EXPECT_NE(hwParse.cmdList.end(), itorCmd);
|
||||
auto sba = genCmdCast<STATE_BASE_ADDRESS *>(*itorCmd);
|
||||
ASSERT_NE(nullptr, sba);
|
||||
|
||||
EXPECT_EQ(expectedMocs, sba->getStatelessDataPortAccessMemoryObjectControlState());
|
||||
|
||||
retVal = clReleaseMemObject(buffer1);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
retVal = clReleaseMemObject(buffer2);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(clMemLocallyUncachedResourceTest,
|
||||
clMemLocallyUncachedResourceFixture,
|
||||
::testing::Bool());
|
||||
|
||||
} // namespace clMemLocallyUncachedResourceTests
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2017-2018 Intel Corporation
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -10,19 +10,6 @@
|
|||
|
||||
using namespace OCLRT;
|
||||
|
||||
TEST(MemObjHelper, givenValidMemFlagsForBufferWhenFlagsAreCheckedThenTrueIsReturned) {
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
||||
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR |
|
||||
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS;
|
||||
|
||||
EXPECT_TRUE(MemObjHelper::checkMemFlagsForBuffer(flags));
|
||||
}
|
||||
|
||||
TEST(MemObjHelper, givenInvalidMemFlagsForBufferWhenFlagsAreCheckedThenFalseIsReturned) {
|
||||
cl_mem_flags flags = (1 << 13) | (1 << 14) | (1 << 30) | (1 << 31);
|
||||
EXPECT_FALSE(MemObjHelper::checkMemFlagsForBuffer(flags));
|
||||
}
|
||||
|
||||
TEST(MemObjHelper, givenValidMemFlagsForSubBufferWhenFlagsAreCheckedThenTrueIsReturned) {
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
||||
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS;
|
||||
|
@ -54,7 +41,7 @@ TEST(MemObjHelper, givenValidPropertiesWhenParsingMemoryPropertiesThenTrueIsRetu
|
|||
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR |
|
||||
CL_MEM_USE_HOST_PTR | CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS,
|
||||
CL_MEM_FLAGS_INTEL,
|
||||
(1 << 30),
|
||||
CL_MEM_LOCALLY_UNCACHED_RESOURCE,
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
|
@ -69,3 +56,35 @@ TEST(MemObjHelper, givenInvalidPropertiesWhenParsingMemoryPropertiesThenFalseIsR
|
|||
MemoryProperties propertiesStruct;
|
||||
EXPECT_FALSE(MemObjHelper::parseMemoryProperties(properties, propertiesStruct));
|
||||
}
|
||||
|
||||
TEST(MemObjHelper, givenValidPropertiesWhenValidatingMemoryPropertiesThenTrueIsReturned) {
|
||||
MemoryProperties properties;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties));
|
||||
|
||||
properties.flags = CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_HOST_NO_ACCESS;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties));
|
||||
|
||||
properties.flags = CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_WRITE_ONLY;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties));
|
||||
|
||||
properties.flags = CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_HOST_NO_ACCESS;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties));
|
||||
|
||||
properties.flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties));
|
||||
|
||||
properties.flags = 0;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties));
|
||||
}
|
||||
|
||||
TEST(MemObjHelper, givenInvalidPropertiesWhenValidatingMemoryPropertiesThenFalseIsReturned) {
|
||||
MemoryProperties properties;
|
||||
properties.flags = (1 << 31);
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryProperties(properties));
|
||||
|
||||
properties.flags_intel = (1 << 31);
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryProperties(properties));
|
||||
|
||||
properties.flags = 0;
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryProperties(properties));
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/mem_obj/mem_obj_helper.h"
|
||||
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
||||
#include "runtime/execution_environment/execution_environment.h"
|
||||
|
||||
|
@ -44,3 +45,19 @@ TEST(MemoryManagerTest, givenAllowed32BitAndFroce32BitWhenGraphicsAllocationInDe
|
|||
EXPECT_EQ(nullptr, allocation);
|
||||
EXPECT_EQ(MemoryManager::AllocationStatus::RetryInNonDevicePool, status);
|
||||
}
|
||||
|
||||
TEST(AllocationFlagsTest, givenAllocateMemoryFlagWhenGetAllocationFlagsIsCalledThenAllocateFlagIsCorrectlySet) {
|
||||
auto allocationProperties = MemObjHelper::getAllocationProperties(0, true, 0, GraphicsAllocation::AllocationType::BUFFER);
|
||||
EXPECT_TRUE(allocationProperties.flags.allocateMemory);
|
||||
|
||||
allocationProperties = MemObjHelper::getAllocationProperties(0, false, 0, GraphicsAllocation::AllocationType::BUFFER);
|
||||
EXPECT_FALSE(allocationProperties.flags.allocateMemory);
|
||||
}
|
||||
|
||||
TEST(UncacheableFlagsTest, givenUncachedResourceFlagWhenGetAllocationFlagsIsCalledThenUncacheableFlagIsCorrectlySet) {
|
||||
auto allocationFlags = MemObjHelper::getAllocationProperties(CL_MEM_LOCALLY_UNCACHED_RESOURCE, false, 0, GraphicsAllocation::AllocationType::BUFFER);
|
||||
EXPECT_TRUE(allocationFlags.flags.uncacheable);
|
||||
|
||||
allocationFlags = MemObjHelper::getAllocationProperties(0, false, 0, GraphicsAllocation::AllocationType::BUFFER);
|
||||
EXPECT_FALSE(allocationFlags.flags.uncacheable);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue