inline cusparseHandle_t cusparse_handle(const command_queue &q) { typedef std::shared_ptr<std::remove_pointer<cusparseHandle_t>::type> smart_handle; typedef vex::detail::object_cache<vex::detail::index_by_context, smart_handle> cache_type; static cache_type cache; auto h = cache.find(q); if (h == cache.end()) { select_context(q); cusparseHandle_t handle; cuda_check( cusparseCreate(&handle) ); cuda_check( cusparseSetStream(handle, q.raw()) ); h = cache.insert(q, smart_handle(handle, detail::deleter())); } return h->second.get(); }
void select_context_dispatch( Stream & stream , ast::select_context const & templ , Context const & ctx , extension::associative_attribute) { auto iter = ctx.find(templ.tag); if(iter != ctx.end()) { // std::cout << "select_context ctx_parent " // << typeid(ctx).name() // << " ctx_child " // << typeid(iter->second).name() // << " category " // << typeid(typename extension::select_category<decltype(iter->second)>::type{}).name(); select_context( stream, templ.body, ctx, iter->second , typename extension::select_category<decltype(iter->second)>::type{}); } else { generate(stream, templ.body, ctx); } }
void operator()(T const & ctx_child) const { select_context( stream_, templ_, ctx_parent_, ctx_child , typename extension::select_category<T>::type{}); }