2015-04-29 15:50:57 -04:00
|
|
|
#include <iostream>
|
2015-07-25 21:00:18 -07:00
|
|
|
#include "isaac/driver/buffer.h"
|
|
|
|
#include "helpers/ocl/infos.hpp"
|
2015-04-29 15:50:57 -04:00
|
|
|
|
|
|
|
namespace isaac
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace driver
|
|
|
|
{
|
|
|
|
|
2015-07-25 21:00:18 -07:00
|
|
|
Buffer::Buffer(cl_mem buffer) : backend_(OPENCL), context_(ocl::info<CL_MEM_CONTEXT>(buffer)), h_(backend_)
|
2015-06-23 09:38:34 -07:00
|
|
|
{
|
2015-07-23 09:39:13 -07:00
|
|
|
h_.cl() = buffer;
|
2015-06-23 09:38:34 -07:00
|
|
|
}
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
Buffer::Buffer(Context const & context, std::size_t size) : backend_(context.backend_), context_(context), h_(backend_)
|
2015-06-28 17:53:16 -07:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
{
|
|
|
|
switch(backend_)
|
|
|
|
{
|
|
|
|
#ifdef ISAAC_WITH_CUDA
|
2015-06-28 17:53:16 -07:00
|
|
|
case CUDA:
|
|
|
|
cuda::check(cuMemAlloc(h_.cu.get(), size));
|
|
|
|
break;
|
2015-04-29 15:50:57 -04:00
|
|
|
#endif
|
2015-06-28 17:53:16 -07:00
|
|
|
case OPENCL:
|
|
|
|
cl_int err;
|
2015-07-25 21:00:18 -07:00
|
|
|
h_.cl() = clCreateBuffer(context.h_.cl(), CL_MEM_READ_WRITE, size, NULL, &err);
|
2015-06-28 17:53:16 -07:00
|
|
|
ocl::check(err);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw;
|
2015-04-29 15:50:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context const & Buffer::context() const
|
|
|
|
{ return context_; }
|
|
|
|
|
|
|
|
bool Buffer::operator==(Buffer const & other) const
|
|
|
|
{ return h_==other.h_; }
|
|
|
|
|
|
|
|
bool Buffer::operator<(Buffer const & other) const
|
|
|
|
{ return h_<other.h_; }
|
|
|
|
|
2015-07-25 21:00:18 -07:00
|
|
|
HANDLE_TYPE(cl_mem, CUdeviceptr) & Buffer::handle()
|
2015-04-29 15:50:57 -04:00
|
|
|
{ return h_; }
|
|
|
|
|
2015-07-25 21:00:18 -07:00
|
|
|
HANDLE_TYPE(cl_mem, CUdeviceptr) const & Buffer::handle() const
|
2015-06-26 08:08:22 -07:00
|
|
|
{ return h_; }
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|