2015-04-29 15:50:57 -04:00
|
|
|
#include <iostream>
|
2015-08-06 12:05:12 -07:00
|
|
|
|
2015-07-25 21:00:18 -07:00
|
|
|
#include "isaac/driver/context.h"
|
2015-07-31 00:41:03 -07:00
|
|
|
#include "isaac/driver/program.h"
|
2015-08-06 12:05:12 -07:00
|
|
|
|
|
|
|
#include "helpers/ocl/infos.hpp"
|
|
|
|
#include "getenv.hpp"
|
2015-08-05 11:13:49 -07:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
namespace isaac
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace driver
|
|
|
|
{
|
|
|
|
|
2015-08-05 11:13:49 -07:00
|
|
|
Context::Context(cl_context const & context, bool take_ownership) : backend_(OPENCL), device_(ocl::info<CL_CONTEXT_DEVICES>(context)[0], false), cache_path_(tools::getenv("ISAAC_CACHE_PATH")), h_(backend_, take_ownership)
|
2015-04-29 15:50:57 -04:00
|
|
|
{
|
2015-08-05 11:13:49 -07:00
|
|
|
h_.cl() = context;
|
|
|
|
}
|
2015-04-29 15:50:57 -04:00
|
|
|
|
2015-08-05 11:13:49 -07:00
|
|
|
Context::Context(Device const & device) : backend_(device.backend_), device_(device), cache_path_(tools::getenv("ISAAC_CACHE_PATH")), h_(backend_, true)
|
|
|
|
{
|
2015-04-29 15:50:57 -04:00
|
|
|
switch(backend_)
|
|
|
|
{
|
|
|
|
case CUDA:
|
2015-08-25 12:41:21 -04:00
|
|
|
cuda::check(dispatch::cuCtxCreate(&h_.cu(), CU_CTX_SCHED_AUTO, device.h_.cu()));
|
2015-04-29 15:50:57 -04:00
|
|
|
break;
|
|
|
|
case OPENCL:
|
2015-06-28 17:53:16 -07:00
|
|
|
cl_int err;
|
2015-08-25 12:41:21 -04:00
|
|
|
h_.cl() = dispatch::clCreateContext(NULL, 1, &device_.h_.cl(), NULL, NULL, &err);
|
2015-06-28 17:53:16 -07:00
|
|
|
ocl::check(err);
|
2015-04-29 15:50:57 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Context::operator==(Context const & other) const
|
2015-07-30 14:35:41 -07:00
|
|
|
{
|
|
|
|
return h_==other.h_;
|
|
|
|
}
|
2015-04-29 15:50:57 -04:00
|
|
|
|
|
|
|
bool Context::operator<(Context const & other) const
|
2015-07-30 14:35:41 -07:00
|
|
|
{
|
|
|
|
return h_<other.h_;
|
|
|
|
}
|
2015-04-29 15:50:57 -04:00
|
|
|
|
|
|
|
Device const & Context::device() const
|
|
|
|
{ return device_; }
|
|
|
|
|
|
|
|
backend_type Context::backend() const
|
|
|
|
{ return backend_; }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|