ViennaCL - The Vienna Computing Library
1.5.0
|
00001 #ifndef VIENNACL_CONTEXT_HPP_ 00002 #define VIENNACL_CONTEXT_HPP_ 00003 00004 /* ========================================================================= 00005 Copyright (c) 2010-2013, 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 <vector> 00026 #include <stddef.h> 00027 #include <assert.h> 00028 #include "viennacl/forwards.h" 00029 #include "viennacl/ocl/forwards.h" 00030 #include "viennacl/backend/mem_handle.hpp" 00031 00032 namespace viennacl 00033 { 00039 class context 00040 { 00041 public: 00042 context() : mem_type_(viennacl::backend::default_memory_type()) 00043 { 00044 #ifdef VIENNACL_WITH_OPENCL 00045 if (mem_type_ == OPENCL_MEMORY) 00046 ocl_context_ptr_ = &viennacl::ocl::current_context(); 00047 else 00048 ocl_context_ptr_ = NULL; 00049 #endif 00050 } 00051 00052 explicit context(viennacl::memory_types mtype) : mem_type_(mtype) 00053 { 00054 if (mem_type_ == MEMORY_NOT_INITIALIZED) 00055 mem_type_ = viennacl::backend::default_memory_type(); 00056 #ifdef VIENNACL_WITH_OPENCL 00057 if (mem_type_ == OPENCL_MEMORY) 00058 ocl_context_ptr_ = &viennacl::ocl::current_context(); 00059 else 00060 ocl_context_ptr_ = NULL; 00061 #endif 00062 } 00063 00064 #ifdef VIENNACL_WITH_OPENCL 00065 context(viennacl::ocl::context const & ctx) : mem_type_(OPENCL_MEMORY), ocl_context_ptr_(&ctx) {} 00066 00067 viennacl::ocl::context const & opencl_context() const 00068 { 00069 assert(mem_type_ == OPENCL_MEMORY && bool("Context type is not OpenCL")); 00070 return *ocl_context_ptr_; 00071 } 00072 #endif 00073 00074 // TODO: Add CUDA and OpenMP contexts 00075 00076 viennacl::memory_types memory_type() const { return mem_type_; } 00077 00078 private: 00079 viennacl::memory_types mem_type_; 00080 #ifdef VIENNACL_WITH_OPENCL 00081 viennacl::ocl::context const * ocl_context_ptr_; 00082 #endif 00083 }; 00084 00085 00086 } 00087 00088 #endif