mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 23:03:02 +08:00
Initial commit
Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
173
runtime/mem_obj/buffer.h
Normal file
173
runtime/mem_obj/buffer.h
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "runtime/memory_manager/memory_constants.h"
|
||||
#include "runtime/mem_obj/mem_obj.h"
|
||||
#include "runtime/helpers/basic_math.h"
|
||||
#include "igfxfmid.h"
|
||||
|
||||
namespace OCLRT {
|
||||
class Buffer;
|
||||
|
||||
typedef Buffer *(*BufferCreatFunc)(Context *context,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *memoryStorage,
|
||||
void *hostPtr,
|
||||
GraphicsAllocation *gfxAllocation,
|
||||
bool zeroCopy,
|
||||
bool isHostPtrSVM,
|
||||
bool isImageRedescribed);
|
||||
|
||||
typedef struct {
|
||||
BufferCreatFunc createBufferFunction;
|
||||
} BufferFuncs;
|
||||
|
||||
extern BufferFuncs bufferFactory[IGFX_MAX_CORE];
|
||||
|
||||
class Buffer : public MemObj {
|
||||
public:
|
||||
const static size_t maxBufferSizeForReadWriteOnCpu = 10 * MB;
|
||||
const static cl_ulong maskMagic = 0xFFFFFFFFFFFFFFFFLL;
|
||||
static const cl_ulong objectMagic = MemObj::objectMagic | 0x02;
|
||||
bool forceDisallowCPUCopy = false;
|
||||
|
||||
~Buffer() override;
|
||||
static Buffer *create(Context *context,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &errcodeRet);
|
||||
|
||||
static Buffer *createSharedBuffer(Context *context,
|
||||
cl_mem_flags flags,
|
||||
SharingHandler *sharingHandler,
|
||||
GraphicsAllocation *graphicsAllocation);
|
||||
|
||||
static Buffer *createBufferHw(Context *context,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *memoryStorage,
|
||||
void *hostPtr,
|
||||
GraphicsAllocation *gfxAllocation,
|
||||
bool zeroCopy,
|
||||
bool isHostPtrSVM,
|
||||
bool isImageRedescribed);
|
||||
|
||||
Buffer *createSubBuffer(cl_mem_flags flags,
|
||||
const cl_buffer_region *region,
|
||||
cl_int &errcodeRet);
|
||||
|
||||
static void setSurfaceState(Context *context,
|
||||
void *surfaceState,
|
||||
size_t svmSize,
|
||||
void *svmPtr,
|
||||
GraphicsAllocation *gfxAlloc = nullptr,
|
||||
cl_mem_flags flags = 0);
|
||||
|
||||
BufferCreatFunc createFunction = nullptr;
|
||||
bool isSubBuffer();
|
||||
bool isValidSubBufferOffset(size_t offset);
|
||||
void setArgStateless(void *memory, uint32_t patchSize, bool set32BitAddressing = false);
|
||||
virtual void setArgStateful(void *memory) = 0;
|
||||
bool bufferRectPitchSet(const size_t *bufferOrigin,
|
||||
const size_t *region,
|
||||
size_t &bufferRowPitch,
|
||||
size_t &bufferSlicePitch,
|
||||
size_t &hostRowPitch,
|
||||
size_t &hostSlicePitch);
|
||||
|
||||
static size_t calculateHostPtrSize(const size_t *origin, const size_t *region, size_t rowPitch, size_t slicePitch);
|
||||
|
||||
void *transferDataToHostPtr() override;
|
||||
|
||||
bool isReadWriteOnCpuAllowed(cl_bool blocking, cl_uint numEventsInWaitList, void *ptr, size_t size);
|
||||
|
||||
cl_int unmapObj(CommandQueue *cmdQ, void *ptr, cl_uint numEventsInWaitList,
|
||||
const cl_event *eventWaitList, cl_event *event) override;
|
||||
|
||||
protected:
|
||||
Buffer(Context *context,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *memoryStorage,
|
||||
void *hostPtr,
|
||||
GraphicsAllocation *gfxAllocation,
|
||||
bool zeroCopy,
|
||||
bool isHostPtrSVM,
|
||||
bool isObjectRedescribed);
|
||||
|
||||
Buffer();
|
||||
|
||||
static void checkMemory(cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &errcodeRet,
|
||||
bool &isZeroCopy,
|
||||
bool &allocateMemory,
|
||||
bool ©MemoryFromHostPtr);
|
||||
};
|
||||
|
||||
template <typename GfxFamily>
|
||||
class BufferHw : public Buffer {
|
||||
public:
|
||||
BufferHw(Context *context,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *memoryStorage,
|
||||
void *hostPtr,
|
||||
GraphicsAllocation *gfxAllocation,
|
||||
bool zeroCopy,
|
||||
bool isHostPtrSVM,
|
||||
bool isObjectRedescribed)
|
||||
: Buffer(context, flags, size, memoryStorage, hostPtr, gfxAllocation,
|
||||
zeroCopy, isHostPtrSVM, isObjectRedescribed) {}
|
||||
|
||||
void setArgStateful(void *memory) override;
|
||||
|
||||
static Buffer *create(Context *context,
|
||||
cl_mem_flags flags,
|
||||
size_t size,
|
||||
void *memoryStorage,
|
||||
void *hostPtr,
|
||||
GraphicsAllocation *gfxAllocation,
|
||||
bool zeroCopy,
|
||||
bool isHostPtrSVM,
|
||||
bool isObjectRedescribed) {
|
||||
auto buffer = new BufferHw<GfxFamily>(context,
|
||||
flags,
|
||||
size,
|
||||
memoryStorage,
|
||||
hostPtr,
|
||||
gfxAllocation,
|
||||
zeroCopy,
|
||||
isHostPtrSVM,
|
||||
isObjectRedescribed);
|
||||
buffer->surfaceType = SURFACE_STATE::SURFACE_TYPE_SURFTYPE_1D;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
typedef typename GfxFamily::RENDER_SURFACE_STATE SURFACE_STATE;
|
||||
typename SURFACE_STATE::SURFACE_TYPE surfaceType;
|
||||
};
|
||||
} // namespace OCLRT
|
||||
Reference in New Issue
Block a user