Add implementation of new OpenCL 3.0 API functions

Additionally unify implementation of API functions related to creating buffers
and images.

Related-To: NEO-4368

Change-Id: Icfafc32f15e667e249fb318072194b6f76bd6481
Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2020-05-12 13:47:44 +02:00
committed by sys_ocldev
parent 37a6a900a8
commit 0a6da52bd4
18 changed files with 450 additions and 189 deletions

View File

@@ -13,6 +13,7 @@
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/get_info.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/ptr_math.h"
@@ -32,7 +33,11 @@
namespace NEO {
BufferFuncs bufferFactory[IGFX_MAX_CORE] = {};
BufferFactoryFuncs bufferFactory[IGFX_MAX_CORE] = {};
namespace BufferFunctions {
ValidateInputAndCreateBufferFunc validateInputAndCreateBuffer = Buffer::validateInputAndCreateBuffer;
} // namespace BufferFunctions
Buffer::Buffer(Context *context,
MemoryProperties memoryProperties,
@@ -85,38 +90,57 @@ bool Buffer::isValidSubBufferOffset(size_t offset) {
return false;
}
void Buffer::validateInputAndCreateBuffer(Context &context,
MemoryProperties memoryProperties,
cl_mem_flags flags,
cl_mem_flags_intel flagsIntel,
size_t size,
void *hostPtr,
cl_int &retVal,
cl_mem &buffer) {
cl_mem Buffer::validateInputAndCreateBuffer(cl_context context,
const cl_mem_properties *properties,
cl_mem_flags flags,
cl_mem_flags_intel flagsIntel,
size_t size,
void *hostPtr,
cl_int &retVal) {
if (!MemObjHelper::validateMemoryPropertiesForBuffer(memoryProperties, flags, flagsIntel, context)) {
retVal = CL_INVALID_VALUE;
return;
Context *pContext = nullptr;
retVal = validateObjects(WithCastToInternal(context, &pContext));
if (retVal != CL_SUCCESS) {
return nullptr;
}
auto pDevice = context.getDevice(0);
MemoryProperties memoryProperties{};
if ((false == isFieldValid(flags, MemObjHelper::validFlagsForBuffer)) ||
(false == MemObjHelper::validateMemoryPropertiesForBuffer(memoryProperties, flags, flagsIntel, *pContext))) {
retVal = CL_INVALID_VALUE;
return nullptr;
}
cl_mem_alloc_flags_intel allocflags = 0;
if (false == MemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
MemoryPropertiesHelper::ObjType::BUFFER, *pContext)) {
retVal = CL_INVALID_PROPERTY;
return nullptr;
}
if (!MemObjHelper::validateMemoryPropertiesForBuffer(memoryProperties, flags, flagsIntel, *pContext)) {
retVal = CL_INVALID_PROPERTY;
return nullptr;
}
auto pDevice = pContext->getDevice(0);
bool allowCreateBuffersWithUnrestrictedSize = isValueSet(flags, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL) ||
isValueSet(flagsIntel, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL);
if (size == 0 || (size > pDevice->getHardwareCapabilities().maxMemAllocSize && !allowCreateBuffersWithUnrestrictedSize)) {
retVal = CL_INVALID_BUFFER_SIZE;
return;
return nullptr;
}
/* Check the host ptr and data */
bool expectHostPtr = (flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) != 0;
if ((hostPtr == nullptr) == expectHostPtr) {
retVal = CL_INVALID_HOST_PTR;
return;
return nullptr;
}
// create the buffer
buffer = create(&context, memoryProperties, flags, flagsIntel, size, hostPtr, retVal);
return create(pContext, memoryProperties, flags, flagsIntel, size, hostPtr, retVal);
}
Buffer *Buffer::create(Context *context,

View File

@@ -16,29 +16,42 @@
#include "igfxfmid.h"
#include "memory_properties_flags.h"
#include <functional>
namespace NEO {
class Device;
class Buffer;
class ClDevice;
class MemoryManager;
typedef Buffer *(*BufferCreatFunc)(Context *context,
MemoryProperties memoryProperties,
cl_mem_flags flags,
cl_mem_flags_intel flagsIntel,
size_t size,
void *memoryStorage,
void *hostPtr,
GraphicsAllocation *gfxAllocation,
bool zeroCopy,
bool isHostPtrSVM,
bool isImageRedescribed);
using BufferCreatFunc = Buffer *(*)(Context *context,
MemoryProperties memoryProperties,
cl_mem_flags flags,
cl_mem_flags_intel flagsIntel,
size_t size,
void *memoryStorage,
void *hostPtr,
GraphicsAllocation *gfxAllocation,
bool zeroCopy,
bool isHostPtrSVM,
bool isImageRedescribed);
typedef struct {
struct BufferFactoryFuncs {
BufferCreatFunc createBufferFunction;
} BufferFuncs;
};
extern BufferFuncs bufferFactory[IGFX_MAX_CORE];
extern BufferFactoryFuncs bufferFactory[IGFX_MAX_CORE];
namespace BufferFunctions {
using ValidateInputAndCreateBufferFunc = std::function<cl_mem(cl_context context,
const uint64_t *properties,
uint64_t flags,
uint64_t flagsIntel,
size_t size,
void *hostPtr,
int32_t &retVal)>;
extern ValidateInputAndCreateBufferFunc validateInputAndCreateBuffer;
} // namespace BufferFunctions
class Buffer : public MemObj {
public:
@@ -49,14 +62,13 @@ class Buffer : public MemObj {
~Buffer() override;
static void validateInputAndCreateBuffer(Context &context,
MemoryProperties memoryProperties,
cl_mem_flags flags,
cl_mem_flags_intel flagsIntel,
size_t size,
void *hostPtr,
cl_int &retVal,
cl_mem &buffer);
static cl_mem validateInputAndCreateBuffer(cl_context context,
const cl_mem_properties *properties,
cl_mem_flags flags,
cl_mem_flags_intel flagsIntel,
size_t size,
void *hostPtr,
cl_int &retVal);
static Buffer *create(Context *context,
cl_mem_flags flags,
@@ -224,4 +236,5 @@ class BufferHw : public Buffer {
typedef typename GfxFamily::RENDER_SURFACE_STATE SURFACE_STATE;
typename SURFACE_STATE::SURFACE_TYPE surfaceType;
};
} // namespace NEO

View File

@@ -7,6 +7,6 @@
template <>
void populateFactoryTable<BufferHw<Family>>() {
extern BufferFuncs bufferFactory[IGFX_MAX_CORE];
extern BufferFactoryFuncs bufferFactory[IGFX_MAX_CORE];
bufferFactory[gfxCore].createBufferFunction = BufferHw<Family>::create;
}

View File

@@ -39,7 +39,11 @@
namespace NEO {
ImageFuncs imageFactory[IGFX_MAX_CORE] = {};
ImageFactoryFuncs imageFactory[IGFX_MAX_CORE] = {};
namespace ImageFunctions {
ValidateAndCreateImageFunc validateAndCreateImage = Image::validateAndCreateImage;
} // namespace ImageFunctions
Image::Image(Context *context,
const MemoryProperties &memoryProperties,
@@ -1110,8 +1114,8 @@ bool Image::isDepthFormat(const cl_image_format &imageFormat) {
return imageFormat.image_channel_order == CL_DEPTH || imageFormat.image_channel_order == CL_DEPTH_STENCIL;
}
Image *Image::validateAndCreateImage(Context *context,
const MemoryProperties &memoryProperties,
cl_mem Image::validateAndCreateImage(cl_context context,
const cl_mem_properties *properties,
cl_mem_flags flags,
cl_mem_flags_intel flagsIntel,
const cl_image_format *imageFormat,
@@ -1119,11 +1123,31 @@ Image *Image::validateAndCreateImage(Context *context,
const void *hostPtr,
cl_int &errcodeRet) {
if (!MemObjHelper::validateMemoryPropertiesForImage(memoryProperties, flags, flagsIntel, imageDesc->mem_object, *context)) {
Context *pContext = nullptr;
errcodeRet = validateObjects(WithCastToInternal(context, &pContext));
if (errcodeRet != CL_SUCCESS) {
return nullptr;
}
cl_mem_alloc_flags_intel allocflags = 0;
MemoryProperties memoryProperties = MemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, allocflags);
if ((false == isFieldValid(flags, MemObjHelper::validFlagsForImage)) ||
(false == MemObjHelper::validateMemoryPropertiesForImage(memoryProperties, flags, flagsIntel, imageDesc->mem_object, *pContext))) {
errcodeRet = CL_INVALID_VALUE;
return nullptr;
}
if (false == MemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
MemoryPropertiesHelper::ObjType::IMAGE, *pContext)) {
errcodeRet = CL_INVALID_PROPERTY;
return nullptr;
}
if (!MemObjHelper::validateMemoryPropertiesForImage(memoryProperties, flags, flagsIntel, imageDesc->mem_object, *pContext)) {
errcodeRet = CL_INVALID_PROPERTY;
return nullptr;
}
bool isHostPtrUsed = (hostPtr != nullptr);
bool areHostPtrFlagsUsed = memoryProperties.flags.copyHostPtr || memoryProperties.flags.useHostPtr;
if (isHostPtrUsed != areHostPtrFlagsUsed) {
@@ -1136,14 +1160,14 @@ Image *Image::validateAndCreateImage(Context *context,
return nullptr;
}
const auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
const auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, imageFormat, pContext->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
errcodeRet = Image::validate(context, memoryProperties, surfaceFormat, imageDesc, hostPtr);
errcodeRet = Image::validate(pContext, memoryProperties, surfaceFormat, imageDesc, hostPtr);
if (errcodeRet != CL_SUCCESS) {
return nullptr;
}
return Image::create(context, memoryProperties, flags, flagsIntel, surfaceFormat, imageDesc, hostPtr, errcodeRet);
return Image::create(pContext, memoryProperties, flags, flagsIntel, surfaceFormat, imageDesc, hostPtr, errcodeRet);
}
bool Image::isValidSingleChannelFormat(const cl_image_format *imageFormat) {

View File

@@ -19,25 +19,37 @@ class Image;
struct KernelInfo;
struct SurfaceFormatInfo;
typedef Image *(*ImageCreatFunc)(Context *context,
const MemoryProperties &memoryProperties,
uint64_t flags,
uint64_t flagsIntel,
size_t size,
void *hostPtr,
const cl_image_format &imageFormat,
const cl_image_desc &imageDesc,
bool zeroCopy,
GraphicsAllocation *graphicsAllocation,
bool isImageRedescribed,
uint32_t baseMipLevel,
uint32_t mipCount,
const ClSurfaceFormatInfo *surfaceFormatInfo,
const SurfaceOffsets *surfaceOffsets);
using ImageCreatFunc = Image *(*)(Context *context,
const MemoryProperties &memoryProperties,
uint64_t flags,
uint64_t flagsIntel,
size_t size,
void *hostPtr,
const cl_image_format &imageFormat,
const cl_image_desc &imageDesc,
bool zeroCopy,
GraphicsAllocation *graphicsAllocation,
bool isImageRedescribed,
uint32_t baseMipLevel,
uint32_t mipCount,
const ClSurfaceFormatInfo *surfaceFormatInfo,
const SurfaceOffsets *surfaceOffsets);
typedef struct {
struct ImageFactoryFuncs {
ImageCreatFunc createImageFunction;
} ImageFuncs;
};
namespace ImageFunctions {
using ValidateAndCreateImageFunc = std::function<cl_mem(cl_context context,
const uint64_t *properties,
uint64_t flags,
uint64_t flagsIntel,
const cl_image_format *imageFormat,
const cl_image_desc *imageDesc,
const void *hostPtr,
int32_t &errcodeRet)>;
extern ValidateAndCreateImageFunc validateAndCreateImage;
} // namespace ImageFunctions
class Image : public MemObj {
public:
@@ -55,8 +67,8 @@ class Image : public MemObj {
const void *hostPtr,
cl_int &errcodeRet);
static Image *validateAndCreateImage(Context *context,
const MemoryProperties &memoryProperties,
static cl_mem validateAndCreateImage(cl_context context,
const cl_mem_properties *properties,
cl_mem_flags flags,
cl_mem_flags_intel flagsIntel,
const cl_image_format *imageFormat,
@@ -352,4 +364,5 @@ class ImageHw : public Image {
}
typename RENDER_SURFACE_STATE::SURFACE_TYPE surfaceType;
};
} // namespace NEO

View File

@@ -8,6 +8,6 @@
template class ImageHw<Family>;
template <>
void populateFactoryTable<ImageHw<Family>>() {
extern ImageFuncs imageFactory[IGFX_MAX_CORE];
extern ImageFactoryFuncs imageFactory[IGFX_MAX_CORE];
imageFactory[gfxCore].createImageFunction = ImageHw<Family>::create;
}