2015-12-19 21:35:35 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, PHILIPPE TILLET. All rights reserved.
|
|
|
|
*
|
|
|
|
* This file is part of ISAAC.
|
|
|
|
*
|
|
|
|
* ISAAC is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
|
|
|
*/
|
2015-12-21 17:04:09 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#include <iostream>
|
2015-07-25 21:00:18 -07:00
|
|
|
#include "isaac/driver/buffer.h"
|
2015-07-31 00:41:03 -07:00
|
|
|
#include "isaac/driver/backend.h"
|
2015-07-25 21:00:18 -07:00
|
|
|
#include "helpers/ocl/infos.hpp"
|
2015-04-29 15:50:57 -04:00
|
|
|
|
|
|
|
namespace isaac
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace driver
|
|
|
|
{
|
|
|
|
|
2015-11-21 13:57:05 -05:00
|
|
|
Buffer::Buffer(CUdeviceptr h, bool take_ownership) : backend_(CUDA), context_(backend::contexts::import(Buffer::context(h))), h_(backend_, take_ownership)
|
2015-11-20 02:56:33 -05:00
|
|
|
{
|
|
|
|
h_.cu() = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer::Buffer(cl_mem buffer, bool take_ownership) : backend_(OPENCL), context_(backend::contexts::import(ocl::info<CL_MEM_CONTEXT>(buffer))), h_(backend_, take_ownership)
|
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-11-20 02:56:33 -05:00
|
|
|
Buffer::Buffer(Context const & context, size_t size) : backend_(context.backend_), context_(context), h_(backend_, true)
|
2015-04-29 15:50:57 -04:00
|
|
|
{
|
|
|
|
switch(backend_)
|
|
|
|
{
|
2015-06-28 17:53:16 -07:00
|
|
|
case CUDA:
|
2016-04-02 18:19:33 -04:00
|
|
|
check(dispatch::cuMemAlloc(&h_.cu(), size));
|
2015-06-28 17:53:16 -07:00
|
|
|
break;
|
|
|
|
case OPENCL:
|
|
|
|
cl_int err;
|
2015-08-25 12:41:21 -04:00
|
|
|
h_.cl() = dispatch::clCreateBuffer(context.h_.cl(), CL_MEM_READ_WRITE, size, NULL, &err);
|
2016-04-02 18:19:33 -04:00
|
|
|
check(err);
|
2015-06-28 17:53:16 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw;
|
2015-04-29 15:50:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context const & Buffer::context() const
|
|
|
|
{ return context_; }
|
|
|
|
|
2016-05-31 23:28:32 -04:00
|
|
|
Buffer::handle_type & Buffer::handle()
|
2015-04-29 15:50:57 -04:00
|
|
|
{ return h_; }
|
|
|
|
|
2016-05-31 23:28:32 -04:00
|
|
|
Buffer::handle_type const & Buffer::handle() const
|
2015-06-26 08:08:22 -07:00
|
|
|
{ return h_; }
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|