ViennaCL - The Vienna Computing Library  1.5.2
viennacl/traits/context.hpp
Go to the documentation of this file.
00001 #ifndef VIENNACL_TRAITS_CONTEXT_HPP_
00002 #define VIENNACL_TRAITS_CONTEXT_HPP_
00003 
00004 /* =========================================================================
00005    Copyright (c) 2010-2014, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008    Portions of this software are copyright by UChicago Argonne, LLC.
00009 
00010                             -----------------
00011                   ViennaCL - The Vienna Computing Library
00012                             -----------------
00013 
00014    Project Head:    Karl Rupp                   rupp@iue.tuwien.ac.at
00015 
00016    (A list of authors and contributors can be found in the PDF manual)
00017 
00018    License:         MIT (X11), see file LICENSE in the base directory
00019 ============================================================================= */
00020 
00025 #include <string>
00026 #include <fstream>
00027 #include <sstream>
00028 #include "viennacl/forwards.h"
00029 #include "viennacl/context.hpp"
00030 #include "viennacl/traits/handle.hpp"
00031 
00032 namespace viennacl
00033 {
00034   namespace traits
00035   {
00036     //
00037     // Context
00038     //
00040     template <typename T>
00041     viennacl::context context(T const & t)
00042     {
00043 #ifdef VIENNACL_WITH_OPENCL
00044       if (traits::active_handle_id(t) == OPENCL_MEMORY)
00045         return viennacl::context(traits::opencl_handle(t).context());
00046 #endif
00047 
00048       return viennacl::context(traits::active_handle_id(t));
00049     }
00050 
00052     inline viennacl::context context(viennacl::backend::mem_handle const & h)
00053     {
00054 #ifdef VIENNACL_WITH_OPENCL
00055       if (h.get_active_handle_id() == OPENCL_MEMORY)
00056         return viennacl::context(h.opencl_handle().context());
00057 #endif
00058 
00059       return viennacl::context(h.get_active_handle_id());
00060     }
00061 
00062   } //namespace traits
00063 } //namespace viennacl
00064 
00065 
00066 #endif