mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Add clCreateBufferWithPropertiesIntel() API
Change-Id: Icfbbbc2479c1bc94008e0ccf90bcb25adddf0b61 Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
f583ceb5eb
commit
ea2e634f7e
@ -6,18 +6,19 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "CL/cl.h"
|
||||
|
||||
/***************************************
|
||||
* * Internal only queue properties *
|
||||
* ****************************************/
|
||||
/**********************************
|
||||
* Internal only queue properties *
|
||||
**********************************/
|
||||
// Intel evaluation now. Remove it after approval for public release
|
||||
#define CL_DEVICE_DRIVER_VERSION_INTEL 0x10010
|
||||
|
||||
#define CL_DEVICE_DRIVER_VERSION_INTEL_NEO1 0x454E4831 // Driver version is ENH1
|
||||
|
||||
/***************************************
|
||||
* * cl_intel_debug_info extension *
|
||||
* ****************************************/
|
||||
/*********************************
|
||||
* cl_intel_debug_info extension *
|
||||
*********************************/
|
||||
#define cl_intel_debug_info 1
|
||||
|
||||
// New queries for clGetProgramInfo:
|
||||
@ -29,8 +30,26 @@
|
||||
#define CL_KERNEL_BINARIES_INTEL 0x4102
|
||||
#define CL_KERNEL_BINARY_SIZES_INTEL 0x4103
|
||||
|
||||
/***************************************
|
||||
* * event properties for performance counter *
|
||||
* ****************************************/
|
||||
/********************************************
|
||||
* event properties for performance counter *
|
||||
********************************************/
|
||||
/* performance counter */
|
||||
#define CL_PROFILING_COMMAND_PERFCOUNTERS_INTEL 0x407F
|
||||
|
||||
/**************************
|
||||
* Internal only cl types *
|
||||
**************************/
|
||||
|
||||
using cl_mem_properties_intel = cl_bitfield;
|
||||
using cl_mem_flags_intel = cl_mem_flags;
|
||||
|
||||
struct MemoryProperties {
|
||||
cl_mem_flags flags = 0;
|
||||
cl_mem_flags_intel flags_intel = 0;
|
||||
};
|
||||
|
||||
/******************************
|
||||
* Internal only cl_mem_flags *
|
||||
******************************/
|
||||
|
||||
#define CL_MEM_FLAGS_INTEL 0x10001
|
||||
|
@ -536,59 +536,49 @@ cl_mem CL_API_CALL clCreateBuffer(cl_context context,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int *errcodeRet) {
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
API_ENTER(&retVal);
|
||||
DBG_LOG_INPUTS("cl_context", context,
|
||||
"cl_mem_flags", flags,
|
||||
"size", size,
|
||||
"hostPtr", DebugManager.infoPointerToString(hostPtr, size));
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
API_ENTER(&retVal);
|
||||
cl_mem buffer = nullptr;
|
||||
ErrorCodeHelper err(errcodeRet, CL_SUCCESS);
|
||||
|
||||
do {
|
||||
if (size == 0) {
|
||||
retVal = CL_INVALID_BUFFER_SIZE;
|
||||
break;
|
||||
}
|
||||
MemoryProperties propertiesStruct;
|
||||
propertiesStruct.flags = flags;
|
||||
Buffer::validateInputAndCreateBuffer(context, propertiesStruct, size, hostPtr, retVal, buffer);
|
||||
|
||||
/* Are there some invalid flag bits? */
|
||||
if (!MemObjHelper::checkMemFlagsForBuffer(flags)) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
err.set(retVal);
|
||||
DBG_LOG_INPUTS("buffer", buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* Check all the invalid flags combination. */
|
||||
if (((flags & CL_MEM_READ_WRITE) && (flags & (CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY))) ||
|
||||
((flags & CL_MEM_READ_ONLY) && (flags & (CL_MEM_WRITE_ONLY))) ||
|
||||
((flags & CL_MEM_ALLOC_HOST_PTR) && (flags & CL_MEM_USE_HOST_PTR)) ||
|
||||
((flags & CL_MEM_COPY_HOST_PTR) && (flags & CL_MEM_USE_HOST_PTR)) ||
|
||||
((flags & CL_MEM_HOST_READ_ONLY) && (flags & CL_MEM_HOST_NO_ACCESS)) ||
|
||||
((flags & CL_MEM_HOST_READ_ONLY) && (flags & CL_MEM_HOST_WRITE_ONLY)) ||
|
||||
((flags & CL_MEM_HOST_WRITE_ONLY) && (flags & CL_MEM_HOST_NO_ACCESS))) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
cl_mem CL_API_CALL clCreateBufferWithPropertiesINTEL(cl_context context,
|
||||
const cl_mem_properties_intel *properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int *errcodeRet) {
|
||||
|
||||
/* Check the host ptr and data */
|
||||
if ((((flags & CL_MEM_COPY_HOST_PTR) || (flags & CL_MEM_USE_HOST_PTR)) && hostPtr == nullptr) ||
|
||||
(!(flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) && (hostPtr != nullptr))) {
|
||||
retVal = CL_INVALID_HOST_PTR;
|
||||
break;
|
||||
}
|
||||
DBG_LOG_INPUTS("cl_context", context,
|
||||
"cl_mem_properties_intel", properties,
|
||||
"size", size,
|
||||
"hostPtr", DebugManager.infoPointerToString(hostPtr, size));
|
||||
|
||||
Context *pContext = nullptr;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
API_ENTER(&retVal);
|
||||
cl_mem buffer = nullptr;
|
||||
ErrorCodeHelper err(errcodeRet, CL_SUCCESS);
|
||||
|
||||
retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
if (retVal != CL_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
// create the buffer
|
||||
buffer = Buffer::create(pContext, flags, size, hostPtr, retVal);
|
||||
} while (false);
|
||||
|
||||
if (errcodeRet) {
|
||||
*errcodeRet = retVal;
|
||||
MemoryProperties propertiesStruct;
|
||||
if (!MemObjHelper::parseMemoryProperties(properties, propertiesStruct)) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
} else {
|
||||
Buffer::validateInputAndCreateBuffer(context, propertiesStruct, size, hostPtr, retVal, buffer);
|
||||
}
|
||||
|
||||
err.set(retVal);
|
||||
DBG_LOG_INPUTS("buffer", buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "CL/cl.h"
|
||||
#include "CL/cl_gl.h"
|
||||
#include "public/cl_ext_private.h"
|
||||
#include "runtime/api/dispatch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -120,6 +121,13 @@ cl_mem CL_API_CALL clCreateBuffer(
|
||||
void *hostPtr,
|
||||
cl_int *errcodeRet);
|
||||
|
||||
cl_mem CL_API_CALL clCreateBufferWithPropertiesINTEL(
|
||||
cl_context context,
|
||||
const cl_mem_properties_intel *properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int *errcodeRet);
|
||||
|
||||
cl_mem CL_API_CALL clCreateSubBuffer(
|
||||
cl_mem buffer,
|
||||
cl_mem_flags flags,
|
||||
|
@ -68,11 +68,54 @@ bool Buffer::isValidSubBufferOffset(size_t offset) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Buffer::validateInputAndCreateBuffer(cl_context &context,
|
||||
MemoryProperties properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &retVal,
|
||||
cl_mem &buffer) {
|
||||
if (size == 0) {
|
||||
retVal = CL_INVALID_BUFFER_SIZE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MemObjHelper::validateMemoryProperties(properties)) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check the host ptr and data */
|
||||
bool expectHostPtr = (properties.flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) != 0;
|
||||
if ((hostPtr == nullptr) == expectHostPtr) {
|
||||
retVal = CL_INVALID_HOST_PTR;
|
||||
return;
|
||||
}
|
||||
|
||||
Context *pContext = nullptr;
|
||||
retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
if (retVal != CL_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// create the buffer
|
||||
buffer = create(pContext, properties, size, hostPtr, retVal);
|
||||
}
|
||||
|
||||
Buffer *Buffer::create(Context *context,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &errcodeRet) {
|
||||
MemoryProperties properties;
|
||||
properties.flags = flags;
|
||||
return create(context, properties, size, hostPtr, errcodeRet);
|
||||
}
|
||||
|
||||
Buffer *Buffer::create(Context *context,
|
||||
MemoryProperties properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &errcodeRet) {
|
||||
Buffer *pBuffer = nullptr;
|
||||
errcodeRet = CL_SUCCESS;
|
||||
|
||||
@ -84,14 +127,14 @@ Buffer *Buffer::create(Context *context,
|
||||
bool allocateMemory = true;
|
||||
bool copyMemoryFromHostPtr = false;
|
||||
GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType(
|
||||
flags,
|
||||
properties.flags,
|
||||
context->isSharedContext,
|
||||
context->getDevice(0)->getHardwareInfo().capabilityTable.ftrRenderCompressedBuffers);
|
||||
|
||||
MemoryManager *memoryManager = context->getMemoryManager();
|
||||
UNRECOVERABLE_IF(!memoryManager);
|
||||
|
||||
checkMemory(flags, size, hostPtr, errcodeRet, alignementSatisfied, copyMemoryFromHostPtr, memoryManager);
|
||||
checkMemory(properties.flags, size, hostPtr, errcodeRet, alignementSatisfied, copyMemoryFromHostPtr, memoryManager);
|
||||
|
||||
if (errcodeRet != CL_SUCCESS) {
|
||||
return nullptr;
|
||||
@ -100,16 +143,16 @@ Buffer *Buffer::create(Context *context,
|
||||
if (allocationType == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED) {
|
||||
zeroCopyAllowed = false;
|
||||
allocateMemory = true;
|
||||
if (flags & CL_MEM_USE_HOST_PTR) {
|
||||
if (properties.flags & CL_MEM_USE_HOST_PTR) {
|
||||
copyMemoryFromHostPtr = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (allocationType == GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY) {
|
||||
if (flags & CL_MEM_ALLOC_HOST_PTR) {
|
||||
if (properties.flags & CL_MEM_ALLOC_HOST_PTR) {
|
||||
zeroCopyAllowed = true;
|
||||
allocateMemory = true;
|
||||
} else if (flags & CL_MEM_USE_HOST_PTR) {
|
||||
} else if (properties.flags & CL_MEM_USE_HOST_PTR) {
|
||||
allocateMemory = false;
|
||||
if (!alignementSatisfied || DebugManager.flags.DisableZeroCopyForUseHostPtr.get()) {
|
||||
zeroCopyAllowed = false;
|
||||
@ -124,7 +167,7 @@ Buffer *Buffer::create(Context *context,
|
||||
allocateMemory = false;
|
||||
}
|
||||
|
||||
if (flags & CL_MEM_USE_HOST_PTR) {
|
||||
if (properties.flags & CL_MEM_USE_HOST_PTR) {
|
||||
memory = context->getSVMAllocsManager()->getSVMAlloc(hostPtr);
|
||||
if (memory) {
|
||||
allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
|
||||
@ -152,8 +195,8 @@ Buffer *Buffer::create(Context *context,
|
||||
}
|
||||
|
||||
if (!memory) {
|
||||
AllocationFlags allocFlags = MemObjHelper::getAllocationFlags(flags, allocateMemory);
|
||||
DevicesBitfield devices = MemObjHelper::getDevicesBitfield(flags);
|
||||
AllocationFlags allocFlags = MemObjHelper::getAllocationFlags(properties.flags, allocateMemory);
|
||||
DevicesBitfield devices = MemObjHelper::getDevicesBitfield(properties.flags_intel);
|
||||
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocFlags, devices, hostPtr, static_cast<size_t>(size), allocationType);
|
||||
}
|
||||
|
||||
@ -163,12 +206,12 @@ Buffer *Buffer::create(Context *context,
|
||||
|
||||
// if memory pointer should not be allcoated and graphics allocation is nullptr
|
||||
// and cl_mem flags allow, create non-zerocopy buffer
|
||||
if (!allocateMemory && !memory && Buffer::isReadOnlyMemoryPermittedByFlags(flags)) {
|
||||
if (!allocateMemory && !memory && Buffer::isReadOnlyMemoryPermittedByFlags(properties.flags)) {
|
||||
allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
|
||||
zeroCopyAllowed = false;
|
||||
copyMemoryFromHostPtr = true;
|
||||
AllocationFlags allocFlags = MemObjHelper::getAllocationFlags(flags, true);
|
||||
DevicesBitfield devices = MemObjHelper::getDevicesBitfield(flags);
|
||||
AllocationFlags allocFlags = MemObjHelper::getAllocationFlags(properties.flags, true);
|
||||
DevicesBitfield devices = MemObjHelper::getDevicesBitfield(properties.flags_intel);
|
||||
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(allocFlags, devices, nullptr, static_cast<size_t>(size), allocationType);
|
||||
}
|
||||
|
||||
@ -184,12 +227,12 @@ Buffer *Buffer::create(Context *context,
|
||||
}
|
||||
|
||||
memory->setAllocationType(allocationType);
|
||||
memory->setMemObjectsAllocationWithWritableFlags(!(flags & (CL_MEM_READ_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)));
|
||||
memory->setMemObjectsAllocationWithWritableFlags(!(properties.flags & (CL_MEM_READ_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)));
|
||||
|
||||
DBG_LOG(LogMemoryObject, __FUNCTION__, "hostPtr:", hostPtr, "size:", size, "memoryStorage:", memory->getUnderlyingBuffer(), "GPU address:", std::hex, memory->getGpuAddress());
|
||||
|
||||
pBuffer = createBufferHw(context,
|
||||
flags,
|
||||
properties.flags,
|
||||
size,
|
||||
memory->getUnderlyingBuffer(),
|
||||
const_cast<void *>(hostPtr),
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "runtime/memory_manager/memory_constants.h"
|
||||
#include "runtime/mem_obj/mem_obj.h"
|
||||
#include "runtime/helpers/basic_math.h"
|
||||
#include "public/cl_ext_private.h"
|
||||
#include "igfxfmid.h"
|
||||
|
||||
namespace OCLRT {
|
||||
@ -40,12 +41,26 @@ class Buffer : public MemObj {
|
||||
bool forceDisallowCPUCopy = false;
|
||||
|
||||
~Buffer() override;
|
||||
|
||||
static void validateInputAndCreateBuffer(cl_context &context,
|
||||
MemoryProperties properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &retVal,
|
||||
cl_mem &buffer);
|
||||
|
||||
static Buffer *create(Context *context,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &errcodeRet);
|
||||
|
||||
static Buffer *create(Context *context,
|
||||
MemoryProperties properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &errcodeRet);
|
||||
|
||||
static Buffer *createSharedBuffer(Context *context,
|
||||
cl_mem_flags flags,
|
||||
SharingHandler *sharingHandler,
|
||||
|
@ -9,8 +9,28 @@
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
bool MemObjHelper::checkExtraMemFlagsForBuffer(cl_mem_flags flags) {
|
||||
return false;
|
||||
bool MemObjHelper::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct) {
|
||||
if (properties == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; properties[i] != 0; i += 2) {
|
||||
switch (properties[i]) {
|
||||
case CL_MEM_FLAGS:
|
||||
propertiesStruct.flags |= static_cast<cl_mem_flags>(properties[i + 1]);
|
||||
break;
|
||||
case CL_MEM_FLAGS_INTEL:
|
||||
propertiesStruct.flags_intel |= static_cast<cl_mem_flags_intel>(properties[i + 1]);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemObjHelper::validateExtraMemoryProperties(const MemoryProperties &properties) {
|
||||
return true;
|
||||
}
|
||||
|
||||
AllocationFlags MemObjHelper::getAllocationFlags(cl_mem_flags flags, bool allocateMemory) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "CL/cl.h"
|
||||
#include "public/cl_ext_private.h"
|
||||
#include "runtime/mem_obj/mem_obj.h"
|
||||
#include "runtime/memory_manager/memory_manager.h"
|
||||
|
||||
@ -20,13 +21,33 @@ class MemObjHelper {
|
||||
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;
|
||||
|
||||
bool flagsValidated = (flags & (~allValidFlags)) == 0;
|
||||
flagsValidated |= checkExtraMemFlagsForBuffer(flags & (~allValidFlags));
|
||||
|
||||
return flagsValidated;
|
||||
return (flags & (~allValidFlags)) == 0;
|
||||
}
|
||||
|
||||
static bool checkExtraMemFlagsForBuffer(cl_mem_flags flags);
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check all the invalid flags combination. */
|
||||
if (((properties.flags & CL_MEM_READ_WRITE) && (properties.flags & (CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY))) ||
|
||||
((properties.flags & CL_MEM_READ_ONLY) && (properties.flags & (CL_MEM_WRITE_ONLY))) ||
|
||||
((properties.flags & CL_MEM_ALLOC_HOST_PTR) && (properties.flags & CL_MEM_USE_HOST_PTR)) ||
|
||||
((properties.flags & CL_MEM_COPY_HOST_PTR) && (properties.flags & CL_MEM_USE_HOST_PTR)) ||
|
||||
((properties.flags & CL_MEM_HOST_READ_ONLY) && (properties.flags & CL_MEM_HOST_NO_ACCESS)) ||
|
||||
((properties.flags & CL_MEM_HOST_READ_ONLY) && (properties.flags & CL_MEM_HOST_WRITE_ONLY)) ||
|
||||
((properties.flags & CL_MEM_HOST_WRITE_ONLY) && (properties.flags & CL_MEM_HOST_NO_ACCESS))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return validateExtraMemoryProperties(properties);
|
||||
}
|
||||
|
||||
static bool validateExtraMemoryProperties(const MemoryProperties &properties);
|
||||
|
||||
static AllocationFlags getAllocationFlags(cl_mem_flags flags, bool allocateMemory);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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));
|
||||
|
Reference in New Issue
Block a user