Backend: fixed ocl::info<> for CL_PROGRAM_BINARIES
This commit is contained in:
@@ -34,6 +34,14 @@ private:
|
||||
static void _delete(std::pair<CUevent, CUevent> x);
|
||||
#endif
|
||||
|
||||
static void release(cl_context x);
|
||||
static void release(cl_mem x);
|
||||
static void release(cl_command_queue x);
|
||||
static void release(cl_device_id x);
|
||||
static void release(cl_event x);
|
||||
static void release(cl_kernel x);
|
||||
static void release(cl_program x);
|
||||
|
||||
public:
|
||||
Handle(backend_type backend);
|
||||
bool operator==(Handle const & other) const;
|
||||
|
@@ -258,6 +258,8 @@ std::string dot::generate_impl(const char * suffix, expressions_tuple const & ex
|
||||
stream.dec_tab();
|
||||
stream << "}" << std::endl;
|
||||
|
||||
// std::cout << stream.str() << std::endl;
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,27 @@ void Handle<CLType, CUType>::_delete(std::pair<CUevent, CUevent> x) { _delete(x.
|
||||
|
||||
#endif
|
||||
|
||||
template<class CLType, class CUType>
|
||||
void Handle<CLType, CUType>::release(cl_context x) { ocl::check(clReleaseContext(x)); }
|
||||
|
||||
template<class CLType, class CUType>
|
||||
void Handle<CLType, CUType>::release(cl_mem x) { ocl::check(clReleaseMemObject(x)); }
|
||||
|
||||
template<class CLType, class CUType>
|
||||
void Handle<CLType, CUType>::release(cl_command_queue x) { ocl::check(clReleaseCommandQueue(x)); }
|
||||
|
||||
template<class CLType, class CUType>
|
||||
void Handle<CLType, CUType>::release(cl_device_id x) { ocl::check(clReleaseDevice(x)); }
|
||||
|
||||
template<class CLType, class CUType>
|
||||
void Handle<CLType, CUType>::release(cl_event x) { ocl::check(clReleaseEvent(x)); }
|
||||
|
||||
template<class CLType, class CUType>
|
||||
void Handle<CLType, CUType>::release(cl_kernel x) { ocl::check(clReleaseKernel(x)); }
|
||||
|
||||
template<class CLType, class CUType>
|
||||
void Handle<CLType, CUType>::release(cl_program x) { ocl::check(clReleaseProgram(x)); }
|
||||
|
||||
template<class CLType, class CUType>
|
||||
Handle<CLType, CUType>::Handle(backend_type backend): backend_(backend)
|
||||
{
|
||||
@@ -78,16 +99,12 @@ bool Handle<CLType, CUType>::operator<(Handle const & other) const
|
||||
template<class CLType, class CUType>
|
||||
Handle<CLType, CUType>::~Handle()
|
||||
{
|
||||
if(cu_ && cu_.unique())
|
||||
{
|
||||
switch(backend_)
|
||||
{
|
||||
#ifdef ISAAC_WITH_CUDA
|
||||
case CUDA: _delete(*cu_); break;
|
||||
if(cu_ && cu_.unique())
|
||||
_delete(*cu_);
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if(cl_ && cl_.unique())
|
||||
release(*cl_);
|
||||
}
|
||||
|
||||
template<class CLType, class CUType>
|
||||
|
@@ -336,6 +336,16 @@ typename detail::return_type<cl_program, param>::Result info(cl_program const &
|
||||
return detail::get_info_impl<res_t>()(handle,param);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline typename detail::return_type<cl_program, CL_PROGRAM_BINARIES>::Result info<CL_PROGRAM_BINARIES>(cl_program const & handle)
|
||||
{
|
||||
std::vector<unsigned char *> res;
|
||||
std::vector<size_t> sizes = info<CL_PROGRAM_BINARY_SIZES>(handle);
|
||||
for(unsigned int s: sizes)
|
||||
res.push_back(new unsigned char[s]);
|
||||
return res;
|
||||
}
|
||||
|
||||
template<cl_program_build_info param>
|
||||
typename detail::return_type<cl_program, param>::Result info(cl_program const & phandle, cl_device_id const & dhandle){
|
||||
typedef typename detail::return_type<cl_program, param>::Result res_t;
|
||||
@@ -388,6 +398,8 @@ typename detail::return_type<OCL_TYPE, param>::Result info(OCL_TYPE const & hand
|
||||
return info(handle.get());
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class OCL_TYPE, class OCL_TYPE_ARG, typename detail::info<OCL_TYPE>::type param>
|
||||
typename detail::return_type<OCL_TYPE, param>::Result info(OCL_TYPE const & handle, OCL_TYPE_ARG const & arg_handle){
|
||||
return info(handle.get(), arg_handle.get());
|
||||
|
@@ -107,23 +107,23 @@ Program::Program(Context const & context, std::string const & source) : backend_
|
||||
|
||||
//Load cached program
|
||||
const char * build_opt = "";
|
||||
if(cache_path.size())
|
||||
{
|
||||
std::ifstream cached(fname, std::ios::binary);
|
||||
if (cached)
|
||||
{
|
||||
std::size_t len;
|
||||
std::vector<unsigned char> buffer;
|
||||
cached.read((char*)&len, sizeof(std::size_t));
|
||||
buffer.resize(len);
|
||||
cached.read((char*)buffer.data(), std::streamsize(len));
|
||||
unsigned char* cbuffer = buffer.data();
|
||||
h_.cl() = clCreateProgramWithBinary(context_.h_.cl(), devices.size(), devices.data(), &len, (const unsigned char **)&cbuffer, NULL, &err);
|
||||
ocl::check(err);
|
||||
ocl::check(clBuildProgram(h_.cl(), devices.size(), devices.data(), build_opt, NULL, NULL));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if(cache_path.size())
|
||||
// {
|
||||
// std::ifstream cached(fname, std::ios::binary);
|
||||
// if (cached)
|
||||
// {
|
||||
// std::size_t len;
|
||||
// std::vector<char> buffer;
|
||||
// cached.read((char*)&len, sizeof(std::size_t));
|
||||
// buffer.resize(len);
|
||||
// cached.read((char*)buffer.data(), std::streamsize(len));
|
||||
// char* cbuffer = buffer.data();
|
||||
// h_.cl() = clCreateProgramWithBinary(context_.h_.cl(), devices.size(), devices.data(), &len, (const unsigned char **)&cbuffer, NULL, &err);
|
||||
// ocl::check(err);
|
||||
// ocl::check(clBuildProgram(h_.cl(), devices.size(), devices.data(), build_opt, NULL, NULL));
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
std::size_t srclen = source.size();
|
||||
const char * csrc = source.c_str();
|
||||
|
@@ -45,11 +45,11 @@ void test_reduction(T epsilon, simple_vector_base<T> & cx, simple_vector_base<T
|
||||
cout << endl;
|
||||
|
||||
#define PREFIX "[C]"
|
||||
RUN_TEST("DOT", cs+=cx[i]*cy[i], 0, cs, BLAS<T>::F(clblasSdot, clblasDdot)(N, CHANDLE(ds), 0, CHANDLE(x), x.start()[0], x.stride()[0],
|
||||
CHANDLE(y), y.start()[0], y.stride()[0],
|
||||
CHANDLE(scratch), 1, &clqueue, 0, NULL, NULL));
|
||||
RUN_TEST("ASUM", cs+=std::fabs(cx[i]), 0, cs, BLAS<T>::F(clblasSasum, clblasDasum)(N, CHANDLE(ds), 0, CHANDLE(x), x.start()[0], x.stride()[0],
|
||||
CHANDLE(scratch), 1, &clqueue, 0, NULL, NULL));
|
||||
// RUN_TEST("DOT", cs+=cx[i]*cy[i], 0, cs, BLAS<T>::F(clblasSdot, clblasDdot)(N, CHANDLE(ds), 0, CHANDLE(x), x.start()[0], x.stride()[0],
|
||||
// CHANDLE(y), y.start()[0], y.stride()[0],
|
||||
// CHANDLE(scratch), 1, &clqueue, 0, NULL, NULL));
|
||||
// RUN_TEST("ASUM", cs+=std::fabs(cx[i]), 0, cs, BLAS<T>::F(clblasSasum, clblasDasum)(N, CHANDLE(ds), 0, CHANDLE(x), x.start()[0], x.stride()[0],
|
||||
// CHANDLE(scratch), 1, &clqueue, 0, NULL, NULL));
|
||||
#undef PREFIX
|
||||
#define PREFIX "[C++]"
|
||||
|
||||
|
Reference in New Issue
Block a user