2018-09-05 10:10:26 +02:00
|
|
|
/*
|
2019-01-09 12:56:38 +01:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2018-09-05 10:10:26 +02:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-09-05 10:10:26 +02:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-22 09:35:09 +02:00
|
|
|
#include "runtime/helpers/memory_properties_flags_helpers.h"
|
2018-09-05 10:10:26 +02:00
|
|
|
#include "runtime/mem_obj/mem_obj_helper.h"
|
2019-03-14 18:26:50 +01:00
|
|
|
#include "unit_tests/fixtures/image_fixture.h"
|
|
|
|
|
#include "unit_tests/utilities/base_object_utils.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2018-09-05 10:10:26 +02:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
using namespace NEO;
|
2018-09-05 10:10:26 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::checkMemFlagsForSubBuffer(flags));
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 09:51:31 +01:00
|
|
|
TEST(MemObjHelper, givenInvalidMemFlagsForSubBufferWhenFlagsAreCheckedThenTrueIsReturned) {
|
2018-09-05 10:10:26 +02:00
|
|
|
cl_mem_flags flags = CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR;
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(MemObjHelper::checkMemFlagsForSubBuffer(flags));
|
|
|
|
|
}
|
2018-10-31 09:51:31 +01:00
|
|
|
|
2019-04-29 07:58:14 +02:00
|
|
|
TEST(MemObjHelper, givenClMemForceLinearStorageFlagWhenCheckForLinearStorageForceThenReturnProperValue) {
|
|
|
|
|
MemoryProperties properties;
|
2019-08-22 09:35:09 +02:00
|
|
|
MemoryPropertiesFlags memoryProperties;
|
2019-04-29 07:58:14 +02:00
|
|
|
|
|
|
|
|
properties.flags |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL;
|
|
|
|
|
properties.flags_intel = 0;
|
2019-08-22 09:35:09 +02:00
|
|
|
memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
|
2019-08-22 12:31:07 +02:00
|
|
|
EXPECT_TRUE(memoryProperties.flags.forceLinearStorage);
|
2019-04-29 07:58:14 +02:00
|
|
|
|
|
|
|
|
properties.flags = 0;
|
|
|
|
|
properties.flags_intel |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL;
|
2019-08-22 09:35:09 +02:00
|
|
|
memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
|
2019-08-22 12:31:07 +02:00
|
|
|
EXPECT_TRUE(memoryProperties.flags.forceLinearStorage);
|
2019-04-29 07:58:14 +02:00
|
|
|
|
|
|
|
|
properties.flags |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL;
|
|
|
|
|
properties.flags_intel |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL;
|
2019-08-22 09:35:09 +02:00
|
|
|
memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
|
2019-08-22 12:31:07 +02:00
|
|
|
EXPECT_TRUE(memoryProperties.flags.forceLinearStorage);
|
2019-04-29 07:58:14 +02:00
|
|
|
|
|
|
|
|
properties.flags = 0;
|
|
|
|
|
properties.flags_intel = 0;
|
2019-08-22 09:35:09 +02:00
|
|
|
memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
|
2019-08-22 12:31:07 +02:00
|
|
|
EXPECT_FALSE(memoryProperties.flags.forceLinearStorage);
|
2019-04-29 07:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-09 12:56:38 +01:00
|
|
|
TEST(MemObjHelper, givenValidPropertiesWhenValidatingMemoryPropertiesThenTrueIsReturned) {
|
|
|
|
|
MemoryProperties properties;
|
2019-03-12 14:19:01 +01:00
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
|
|
|
|
|
|
|
|
|
properties.flags = CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL | CL_MEM_NO_ACCESS_INTEL;
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
|
|
|
|
|
|
|
|
|
properties.flags = CL_MEM_NO_ACCESS_INTEL;
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
2019-01-09 12:56:38 +01:00
|
|
|
|
|
|
|
|
properties.flags = CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_HOST_NO_ACCESS;
|
2019-03-12 14:19:01 +01:00
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
2019-01-09 12:56:38 +01:00
|
|
|
|
|
|
|
|
properties.flags = CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_WRITE_ONLY;
|
2019-03-12 14:19:01 +01:00
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
2019-01-09 12:56:38 +01:00
|
|
|
|
|
|
|
|
properties.flags = CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_HOST_NO_ACCESS;
|
2019-03-12 14:19:01 +01:00
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
2019-01-09 12:56:38 +01:00
|
|
|
|
|
|
|
|
properties.flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE;
|
2019-03-12 14:19:01 +01:00
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
2019-01-09 12:56:38 +01:00
|
|
|
|
2019-08-30 08:18:34 +02:00
|
|
|
properties.flags_intel = CL_MEM_LOCALLY_UNCACHED_SURFACE_STATE_RESOURCE;
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
|
|
|
|
|
2019-01-09 12:56:38 +01:00
|
|
|
properties.flags = 0;
|
2019-03-12 14:19:01 +01:00
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
|
|
|
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
2019-01-09 12:56:38 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-18 10:31:08 +01:00
|
|
|
struct Image1dWithAccessFlagsUnrestricted : public Image1dDefaults {
|
|
|
|
|
enum { flags = CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL };
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-14 18:26:50 +01:00
|
|
|
TEST(MemObjHelper, givenParentMemObjAndHostPtrFlagsWhenValidatingMemoryPropertiesForImageThenFalseIsReturned) {
|
|
|
|
|
MemoryProperties properties;
|
|
|
|
|
MockContext context;
|
|
|
|
|
auto image = clUniquePtr(Image1dHelper<>::create(&context));
|
2019-03-18 10:31:08 +01:00
|
|
|
auto imageWithAccessFlagsUnrestricted = clUniquePtr(ImageHelper<Image1dWithAccessFlagsUnrestricted>::create(&context));
|
2019-03-14 18:26:50 +01:00
|
|
|
|
2019-03-18 10:31:08 +01:00
|
|
|
cl_mem_flags hostPtrFlags[] = {CL_MEM_USE_HOST_PTR, CL_MEM_ALLOC_HOST_PTR, CL_MEM_COPY_HOST_PTR};
|
2019-03-14 18:26:50 +01:00
|
|
|
|
2019-03-18 10:31:08 +01:00
|
|
|
for (auto hostPtrFlag : hostPtrFlags) {
|
|
|
|
|
properties.flags = hostPtrFlag;
|
|
|
|
|
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, image.get()));
|
|
|
|
|
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, imageWithAccessFlagsUnrestricted.get()));
|
2019-03-14 18:26:50 +01:00
|
|
|
|
2019-03-18 10:31:08 +01:00
|
|
|
properties.flags |= CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL;
|
|
|
|
|
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, image.get()));
|
|
|
|
|
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, imageWithAccessFlagsUnrestricted.get()));
|
|
|
|
|
}
|
2019-03-14 18:26:50 +01:00
|
|
|
}
|