Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit a281b1a8 authored by schultezub's avatar schultezub
Browse files

* added OpenCL MemObject wrapper stubs

 * added CommandQueue::enqueueBarrier and Co., CommandQueue::enqueueRead/Write

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@240 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 37adcdbf
......@@ -6,6 +6,7 @@
#include "cllib/device.h"
#include "cllib/event.h"
#include "cllib/kernel.h"
#include "cllib/memory.h"
#include "cllib/platform.h"
namespace cllib {
......@@ -133,5 +134,42 @@ namespace cllib {
return Event(e);
}
void CommandQueue::enqueueBarrier() {
LCL_ERROR(clEnqueueBarrier(_id));
}
Event CommandQueue::enqueueMarker() {
cl_event e;
LCL_ERROR(clEnqueueMarker(_id, &e));
return Event(e);
}
void CommandQueue::enqueueWaitForEvents(const EventList& eventsToWaitFor /*= EventList()*/) {
LCL_ERROR(clEnqueueWaitForEvents(_id, eventsToWaitFor._size, eventsToWaitFor._events));
}
Event CommandQueue::enqueueRead(const Buffer* buffer, void* data, bool blocking /*= true*/, size_t offset /*= 0*/, size_t numBytes /*= 0*/, const EventList& eventsToWaitFor /*= EventList()*/) {
cl_event e;
if (numBytes == 0) {
LCL_ERROR(clEnqueueReadBuffer(_id, buffer->getId(), blocking, offset, buffer->getSize(), data, eventsToWaitFor._size, eventsToWaitFor._events, &e));
}
else {
LCL_ERROR(clEnqueueReadBuffer(_id, buffer->getId(), blocking, offset, numBytes, data, eventsToWaitFor._size, eventsToWaitFor._events, &e));
}
return Event(e);
}
Event CommandQueue::enqueueWrite(const Buffer* buffer, void* data, bool blocking /*= true*/, size_t offset /*= 0*/, size_t numBytes /*= 0*/, const EventList& eventsToWaitFor /*= EventList()*/) {
cl_event e;
if (numBytes == 0) {
LCL_ERROR(clEnqueueWriteBuffer(_id, buffer->getId(), blocking, offset, buffer->getSize(), data, eventsToWaitFor._size, eventsToWaitFor._events, &e));
}
else {
LCL_ERROR(clEnqueueWriteBuffer(_id, buffer->getId(), blocking, offset, numBytes, data, eventsToWaitFor._size, eventsToWaitFor._events, &e));
}
return Event(e);
}
}
......@@ -9,6 +9,7 @@
namespace cllib {
class Buffer;
class Context;
class Device;
class Kernel;
......@@ -110,6 +111,56 @@ namespace cllib {
Event enqueueKernel(const Kernel* kernel, tgt::svec3 globalWorkSize, tgt::svec3 localWorkSize = tgt::svec3::zero, tgt::svec3 offset = tgt::svec3::zero, const EventList& eventsToWaitFor = EventList());
/**
* Enqueue a synchronization point that ensures that all queued commands in this command queue have
* finished execution before the next batch of commands can begin execution.
*
* \todo This method is deprecated in OpenCL 1.2
*/
void enqueueBarrier();
/**
* Enqueues a marker to the command queue.
* You can use the returned event for waiting for the command queue reach the marker.
*
* \todo This method is deprecated in OpenCL 1.2
* \return OpenCL event for waiting for the command queue reach the marker.
*/
Event enqueueMarker();
/**
* Enqueues a wait for the given list of events to complete before any future commands of this command queue are executed.
*
* \todo This method is deprecated in OpenCL 1.2
* \param eventsToWaitFor List of Events to wait for, default is empty.
*/
void enqueueWaitForEvents(const EventList& eventsToWaitFor = EventList());
/**
* Enqueues to read from a buffer object to host memory.
* \param buffer Buffer object to read from.
* \param data The pointer to host memory where data is to be read into.
* \param blocking Flag whether this operation shall be blocking or not. Defaults to true.
* \param offset The offset in bytes in the buffer object to read from.
* \param numBytes The number of bytes to be read. If 0, buffer->getSize() bytes will be read (default).
* \param eventsToWaitFor List of Events to wait for, default is empty.
* \return Event object that identifies this particular kernel execution instance.
*/
Event enqueueRead(const Buffer* buffer, void* data, bool blocking = true, size_t offset = 0, size_t numBytes = 0, const EventList& eventsToWaitFor = EventList());
/**
* Enqueues to write into a buffer object from host memory.
* \param buffer Buffer object to write into.
* \param data The pointer to host memory where data is read from.
* \param blocking Flag whether this operation shall be blocking or not. Defaults to true.
* \param offset The offset in bytes in the buffer object to start writing.
* \param numBytes The number of bytes to be written. If 0, buffer->getSize() bytes will be written (default).
* \param eventsToWaitFor List of Events to wait for, default is empty.
* \return Event object that identifies this particular kernel execution instance.
*/
Event enqueueWrite(const Buffer* buffer, void* data, bool blocking = true, size_t offset = 0, size_t numBytes = 0, const EventList& eventsToWaitFor = EventList());
// TODO: buffers, images, etc.
private:
......
#include "memory.h"
#include "tgt/assert.h"
#include "tgt/logmanager.h"
#include "cllib/context.h"
namespace cllib {
MemoryObject::MemoryObject(const Context* context)
: CLWrapper<cl_mem>(0)
, _context(context)
{
}
MemoryObject::~MemoryObject() {
}
const Context* MemoryObject::getContext() const {
return _context;
}
// ================================================================================================
Buffer::Buffer(const Context* context, cl_mem_flags flags, size_t size, const void* hostPtr /*= 0*/)
: MemoryObject(context)
, _size(size)
{
tgtAssert(size > 0, "Buffer size must be greater than 0.");
cl_int err;
_id = clCreateBuffer(context->getId(), flags, size, const_cast<void*>(hostPtr), &err);
LCL_ERROR(err);
}
Buffer::~Buffer() {
}
size_t Buffer::getSize() const {
return _size;
}
}
#ifndef CLMEMORY_H__
#define CLMEMORY_H__
#include "cllib/cllib.h"
namespace cllib {
class Context;
/**
* Base class for all OpenCL memory objects.
*/
class MemoryObject : public CLWrapper<cl_mem> {
public:
/**
* Creates a new OpenCL memory object.
* \param context Context where this memory object resides.
*/
MemoryObject(const Context* context);
/**
* Destructor, just hanging around virtually...
*/
virtual ~MemoryObject();
/**
* Gets the context where this memory object resides.
* \return _context
*/
const Context* getContext() const;
protected:
const Context* _context; ///< Context where this memory object resides.
};
// ================================================================================================
class Buffer : public MemoryObject {
public:
/**
* Creates a new OpenCL buffer object.
* \param context Context where this buffer object resides.
* \param flags Flags specifying allocation and usage information for this buffer.
* \param size The size in bytes of the buffer memory object to be allocated.
* \param hostPtr A pointer to the buffer data for optional initialization of the buffer, defaults to 0.
*/
Buffer(const Context* context, cl_mem_flags flags, size_t size, const void* hostPtr = 0);
/**
* Destructor, just hanging around virtually...
*/
virtual ~Buffer();
/**
* Gets the size of this buffer
* \return _size
*/
size_t getSize() const;
protected:
size_t _size; ///< Size of this buffer.
};
// ================================================================================================
class Image {
// TODO: implement
};
}
#endif // CLMEMORY_H__
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment