Add clCreateBufferWithPropertiesIntel() API

Change-Id: Icfbbbc2479c1bc94008e0ccf90bcb25adddf0b61
Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2018-10-31 09:51:31 +01:00
committed by sys_ocldev
parent f583ceb5eb
commit ea2e634f7e
12 changed files with 287 additions and 109 deletions

View File

@@ -35,7 +35,7 @@ struct clCreateBufferValidFlagsTests : public clCreateBufferTemplateTests {
cl_uchar pHostPtr[64];
};
TEST_P(clCreateBufferValidFlagsTests, validFlags) {
TEST_P(clCreateBufferValidFlagsTests, GivenValidFlagsWhenCreatingBufferThenBufferIsCreated) {
cl_mem_flags flags = GetParam() | CL_MEM_USE_HOST_PTR;
auto buffer = clCreateBuffer(pContext, flags, 64, pHostPtr, &retVal);
@@ -45,6 +45,22 @@ TEST_P(clCreateBufferValidFlagsTests, validFlags) {
clReleaseMemObject(buffer);
};
struct clCreateBufferWithPropertiesINTELValidFlagsTests : public clCreateBufferTemplateTests {
cl_uchar pHostPtr[64];
};
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);
EXPECT_NE(nullptr, buffer);
EXPECT_EQ(CL_SUCCESS, retVal);
clReleaseMemObject(buffer);
};
static cl_mem_flags validFlags[] = {
CL_MEM_READ_WRITE | CL_MEM_HOST_READ_ONLY,
CL_MEM_WRITE_ONLY,
@@ -59,10 +75,15 @@ INSTANTIATE_TEST_CASE_P(
clCreateBufferValidFlagsTests,
testing::ValuesIn(validFlags));
struct clCreateBufferInValidFlagsTests : public clCreateBufferTemplateTests {
INSTANTIATE_TEST_CASE_P(
CreateBufferCheckFlags,
clCreateBufferWithPropertiesINTELValidFlagsTests,
testing::ValuesIn(validFlags));
struct clCreateBufferInvalidFlagsTests : public clCreateBufferTemplateTests {
};
TEST_P(clCreateBufferInValidFlagsTests, inValidFlags) {
TEST_P(clCreateBufferInvalidFlagsTests, GivenInvalidFlagsWhenCreatingBufferThenBufferIsNotCreated) {
cl_mem_flags flags = GetParam();
auto buffer = clCreateBuffer(pContext, flags, 64, nullptr, &retVal);
@@ -70,7 +91,19 @@ TEST_P(clCreateBufferInValidFlagsTests, inValidFlags) {
EXPECT_EQ(CL_INVALID_VALUE, retVal);
};
cl_mem_flags inValidFlags[] = {
struct clCreateBufferWithPropertiesINTELInvalidPropertiesTests : public clCreateBufferTemplateTests {
};
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);
EXPECT_EQ(nullptr, buffer);
EXPECT_EQ(CL_INVALID_VALUE, retVal);
};
cl_mem_flags invalidFlags[] = {
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY,
CL_MEM_READ_WRITE | CL_MEM_READ_ONLY,
CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY,
@@ -84,16 +117,20 @@ cl_mem_flags inValidFlags[] = {
INSTANTIATE_TEST_CASE_P(
CreateBufferCheckFlags,
clCreateBufferInValidFlagsTests,
testing::ValuesIn(inValidFlags));
clCreateBufferInvalidFlagsTests,
testing::ValuesIn(invalidFlags));
INSTANTIATE_TEST_CASE_P(
CreateBufferCheckFlags,
clCreateBufferWithPropertiesINTELInvalidPropertiesTests,
testing::ValuesIn(invalidFlags));
TEST_F(clCreateBufferTests, GivenValidParametersWhenCreatingBufferThenSuccessIsReturned) {
unsigned char *pHostMem = nullptr;
cl_mem_flags flags = CL_MEM_USE_HOST_PTR;
static const unsigned int bufferSize = 16;
cl_mem buffer = nullptr;
pHostMem = new unsigned char[bufferSize];
unsigned char pHostMem[bufferSize];
memset(pHostMem, 0xaa, bufferSize);
buffer = clCreateBuffer(pContext, flags, bufferSize, pHostMem, &retVal);
@@ -103,8 +140,6 @@ TEST_F(clCreateBufferTests, GivenValidParametersWhenCreatingBufferThenSuccessIsR
retVal = clReleaseMemObject(buffer);
EXPECT_EQ(CL_SUCCESS, retVal);
delete[] pHostMem;
}
TEST_F(clCreateBufferTests, GivenNullContextWhenCreatingBufferThenInvalidContextErrorIsReturned) {
@@ -148,12 +183,11 @@ TEST_F(clCreateBufferTests, GivenMemWriteOnlyFlagAndMemReadWriteFlagWhenCreating
}
TEST_F(clCreateBufferTests, GivenNullHostPointerAndMemCopyHostPtrFlagWhenCreatingBufferThenNullIsReturned) {
unsigned char *pHostMem = nullptr;
cl_mem_flags flags = CL_MEM_USE_HOST_PTR;
static const unsigned int bufferSize = 16;
cl_mem buffer = nullptr;
pHostMem = new unsigned char[bufferSize];
unsigned char pHostMem[bufferSize];
memset(pHostMem, 0xaa, bufferSize);
buffer = clCreateBuffer(pContext, flags, bufferSize, pHostMem, nullptr);
@@ -162,8 +196,6 @@ TEST_F(clCreateBufferTests, GivenNullHostPointerAndMemCopyHostPtrFlagWhenCreatin
retVal = clReleaseMemObject(buffer);
EXPECT_EQ(CL_SUCCESS, retVal);
delete[] pHostMem;
}
using clCreateBufferTestsWithRestrictions = api_test_using_aligned_memory_manager;

View File

@@ -141,17 +141,17 @@ TEST_P(clSVMAllocFtrFlagsTests, SVMAllocValidFlags) {
clSVMFree(pContext, SVMPtr);
};
struct clSVMAllocInValidFlagsTests : public clSVMAllocTemplateTests {
struct clSVMAllocInvalidFlagsTests : public clSVMAllocTemplateTests {
};
TEST_P(clSVMAllocInValidFlagsTests, SVMAllocInValidFlags) {
TEST_P(clSVMAllocInvalidFlagsTests, SVMAllocInvalidFlags) {
cl_mem_flags flags = GetParam();
auto SVMPtr = clSVMAlloc(pContext, flags, 4096 /* Size*/, 128 /* alignment */);
EXPECT_EQ(nullptr, SVMPtr);
};
cl_mem_flags SVMAllocInValidFlags[] = {
cl_mem_flags SVMAllocInvalidFlags[] = {
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY,
CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY,
CL_MEM_SVM_ATOMICS,
@@ -159,8 +159,8 @@ cl_mem_flags SVMAllocInValidFlags[] = {
INSTANTIATE_TEST_CASE_P(
SVMAllocCheckFlags,
clSVMAllocInValidFlagsTests,
testing::ValuesIn(SVMAllocInValidFlags));
clSVMAllocInvalidFlagsTests,
testing::ValuesIn(SVMAllocInvalidFlags));
TEST_F(clSVMAllocTests, nullContextReturnsNull) {
cl_mem_flags flags = CL_MEM_READ_WRITE;

View File

@@ -175,24 +175,21 @@ TEST_P(ComputeTotalElementsCount, givenVariousInputVectorsWhenComputeTotalElemen
}
TEST(isPow2Test, WhenArgZeroThenReturnFalse) {
bool ret = isPow2<uint32_t>(0u);
EXPECT_FALSE(ret);
EXPECT_FALSE(isPow2(0u));
}
TEST(isPow2Test, WhenArgNonPow2ThenReturnFalse) {
bool ret = true;
uint32_t args[5] = {3, 5, 6, 7, 10};
for (uint32_t i = 0; i < 5; i++) {
ret = isPow2<uint32_t>(args[i]);
EXPECT_FALSE(ret);
}
EXPECT_FALSE(isPow2(3u));
EXPECT_FALSE(isPow2(5u));
EXPECT_FALSE(isPow2(6u));
EXPECT_FALSE(isPow2(7u));
EXPECT_FALSE(isPow2(10u));
}
TEST(isPow2Test, WhenArgPow2ThenReturnTrue) {
bool ret = false;
size_t args[5] = {1, 4, 8, 128, 4096};
for (uint32_t i = 0; i < 5; i++) {
ret = isPow2<size_t>(args[i]);
EXPECT_TRUE(ret);
}
EXPECT_TRUE(isPow2(1u));
EXPECT_TRUE(isPow2(4u));
EXPECT_TRUE(isPow2(8u));
EXPECT_TRUE(isPow2(128u));
EXPECT_TRUE(isPow2(4096u));
}

View File

@@ -20,7 +20,6 @@ TEST(MemObjHelper, givenValidMemFlagsForBufferWhenFlagsAreCheckedThenTrueIsRetur
TEST(MemObjHelper, givenInvalidMemFlagsForBufferWhenFlagsAreCheckedThenFalseIsReturned) {
cl_mem_flags flags = (1 << 13) | (1 << 14) | (1 << 30) | (1 << 31);
EXPECT_FALSE(MemObjHelper::checkExtraMemFlagsForBuffer(flags));
EXPECT_FALSE(MemObjHelper::checkMemFlagsForBuffer(flags));
}
@@ -31,8 +30,42 @@ TEST(MemObjHelper, givenValidMemFlagsForSubBufferWhenFlagsAreCheckedThenTrueIsRe
EXPECT_TRUE(MemObjHelper::checkMemFlagsForSubBuffer(flags));
}
TEST(MemObjHelper, givenInValidMemFlagsForSubBufferWhenFlagsAreCheckedThenTrueIsReturned) {
TEST(MemObjHelper, givenInvalidMemFlagsForSubBufferWhenFlagsAreCheckedThenTrueIsReturned) {
cl_mem_flags flags = CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR;
EXPECT_FALSE(MemObjHelper::checkMemFlagsForSubBuffer(flags));
}
TEST(MemObjHelper, givenNullPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
MemoryProperties propertiesStruct;
EXPECT_TRUE(MemObjHelper::parseMemoryProperties(nullptr, propertiesStruct));
}
TEST(MemObjHelper, givenEmptyPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
cl_mem_properties_intel properties[] = {0};
MemoryProperties propertiesStruct;
EXPECT_TRUE(MemObjHelper::parseMemoryProperties(properties, propertiesStruct));
}
TEST(MemObjHelper, givenValidPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
cl_mem_properties_intel properties[] = {
CL_MEM_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,
CL_MEM_FLAGS_INTEL,
(1 << 30),
0};
MemoryProperties propertiesStruct;
EXPECT_TRUE(MemObjHelper::parseMemoryProperties(properties, propertiesStruct));
}
TEST(MemObjHelper, givenInvalidPropertiesWhenParsingMemoryPropertiesThenFalseIsReturned) {
cl_mem_properties_intel properties[] = {
(1 << 30), CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR,
0};
MemoryProperties propertiesStruct;
EXPECT_FALSE(MemObjHelper::parseMemoryProperties(properties, propertiesStruct));
}

View File

@@ -220,15 +220,15 @@ TEST(Context, givenMockSharingBuilderWhenContextWithInvalidPropertiesThenContext
cl_platform_id platformId[] = {platform()};
cl_context_properties validProperties[5] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platformId[0], clContextPropertyMock, mockContextPassFinalize, 0};
cl_context_properties inValidProperties[5] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platformId[0], clContextPropertyMock, 0, 0};
cl_context_properties inValidPropertiesFailFinalize[5] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platformId[0], clContextPropertyMock, mockContextFailFinalize, 0};
cl_context_properties invalidProperties[5] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platformId[0], clContextPropertyMock, 0, 0};
cl_context_properties invalidPropertiesFailFinalize[5] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platformId[0], clContextPropertyMock, mockContextFailFinalize, 0};
std::unique_ptr<Context> context;
context.reset(Context::create<Context>(inValidProperties, deviceVector, nullptr, nullptr, retVal));
context.reset(Context::create<Context>(invalidProperties, deviceVector, nullptr, nullptr, retVal));
EXPECT_EQ(nullptr, context.get());
context.reset(Context::create<Context>(inValidPropertiesFailFinalize, deviceVector, nullptr, nullptr, retVal));
context.reset(Context::create<Context>(invalidPropertiesFailFinalize, deviceVector, nullptr, nullptr, retVal));
EXPECT_EQ(nullptr, context.get());
context.reset(Context::create<Context>(validProperties, deviceVector, nullptr, nullptr, retVal));