#include "isaac/driver/handle.h" #include namespace isaac { namespace driver { #ifdef ISAAC_WITH_CUDA template void Handle::_delete(CUcontext x) { cuCtxDestroy(x); } template void Handle::_delete(CUdeviceptr x) { cuMemFree(x); } template void Handle::_delete(CUstream x) { cuStreamDestroy(x); } template void Handle::_delete(CUdevice) { } template void Handle::_delete(CUevent x) { cuEventDestroy(x); } template void Handle::_delete(CUfunction) { } template void Handle::_delete(CUmodule x) { cuModuleUnload(x); } template void Handle::_delete(std::pair x) { _delete(x.first); _delete(x.second); } #endif template void Handle::release(cl_context x) { ocl::check(clReleaseContext(x)); } template void Handle::release(cl_mem x) { ocl::check(clReleaseMemObject(x)); } template void Handle::release(cl_command_queue x) { ocl::check(clReleaseCommandQueue(x)); } template void Handle::release(cl_device_id x) { ocl::check(clReleaseDevice(x)); } template void Handle::release(cl_event x) { ocl::check(clReleaseEvent(x)); } template void Handle::release(cl_kernel x) { ocl::check(clReleaseKernel(x)); } template void Handle::release(cl_program x) { ocl::check(clReleaseProgram(x)); } template Handle::Handle(backend_type backend, bool take_ownership): backend_(backend), has_ownership_(take_ownership) { switch(backend_) { #ifdef ISAAC_WITH_CUDA case CUDA: cu_.reset(new CUType()); #endif case OPENCL: cl_.reset(new CLType()); } } template bool Handle::operator==(Handle const & other) const { #ifdef ISAAC_WITH_CUDA if(backend_==CUDA && other.backend_==CUDA) return cu()==other.cu(); #endif if(backend_==OPENCL && other.backend_==OPENCL) return cl()==other.cl(); return false; } template bool Handle::operator<(Handle const & other) const { #ifdef ISAAC_WITH_CUDA if(backend_==CUDA && other.backend_==CUDA) return (*cu_)<(*other.cu_); #endif if(backend_==OPENCL && other.backend_==OPENCL) return (*cl_)<(*other.cl_); #ifdef ISAAC_WITH_CUDA if(backend_==CUDA && other.backend_==OPENCL) return true; #endif return false; } template Handle::~Handle() { #ifdef ISAAC_WITH_CUDA if(has_ownership_ && cu_ && cu_.unique() && *cu_) _delete(*cu_); #endif if(has_ownership_ && cl_ && cl_.unique() && *cl_) release(*cl_); } template CLType & Handle::cl() { return *cl_; } template CLType const & Handle::cl() const { return *cl_; } #ifdef ISAAC_WITH_CUDA template CUType & Handle::cu() { return *cu_; } template class Handle; template class Handle; template class Handle; template class Handle; template class Handle >; template class Handle; template class Handle; #else template class Handle; template class Handle; template class Handle; template class Handle; template class Handle; template class Handle; template class Handle; #endif } }