ViennaCL - The Vienna Computing Library: viennacl/context.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
context.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_CONTEXT_HPP_
2 #define VIENNACL_CONTEXT_HPP_
3
4 /* =========================================================================
5 Copyright (c) 2010-2016, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8 Portions of this software are copyright by UChicago Argonne, LLC.
9
10 -----------------
11 ViennaCL - The Vienna Computing Library
12 -----------------
13
14 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15
16 (A list of authors and contributors can be found in the manual)
17
18 License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20
25 #include <vector>
26 #include <stddef.h>
27 #include <assert.h>
28 #include "viennacl/forwards.h"
29 #include "viennacl/ocl/forwards.h"
30 #include "viennacl/backend/mem_handle.hpp"
31
32 namespace viennacl
33 {
39 class context
40 {
41 public:
42 context() : mem_type_(viennacl::backend::default_memory_type())
43 {
44 #ifdef VIENNACL_WITH_OPENCL
45 if (mem_type_ == OPENCL_MEMORY)
46 ocl_context_ptr_ = &viennacl::ocl::current_context();
47 else
48 ocl_context_ptr_ = NULL;
49 #endif
50 }
51
52 explicit context(viennacl::memory_types mtype) : mem_type_(mtype)
53 {
54 if (mem_type_ == MEMORY_NOT_INITIALIZED)
55 mem_type_ = viennacl::backend::default_memory_type();
56 #ifdef VIENNACL_WITH_OPENCL
57 if (mem_type_ == OPENCL_MEMORY)
58 ocl_context_ptr_ = &viennacl::ocl::current_context();
59 else
60 ocl_context_ptr_ = NULL;
61 #endif
62 }
63
64 #ifdef VIENNACL_WITH_OPENCL
65 context(viennacl::ocl::context const & ctx) : mem_type_(OPENCL_MEMORY), ocl_context_ptr_(&ctx) {}
66
67 viennacl::ocl::context const & opencl_context() const
68 {
69 assert(mem_type_ == OPENCL_MEMORY && bool("Context type is not OpenCL"));
70 return *ocl_context_ptr_;
71 }
72 #endif
73
74 // TODO: Add CUDA and OpenMP contexts
75
76 viennacl::memory_types memory_type() const { return mem_type_; }
77
78 private:
79 viennacl::memory_types mem_type_;
80 #ifdef VIENNACL_WITH_OPENCL
81 viennacl::ocl::context const * ocl_context_ptr_;
82 #endif
83 };
84
85
86 }
87
88 #endif
forwards.h
This file provides the forward declarations for the OpenCL layer of ViennaCL.
viennacl::context::context
context(viennacl::memory_types mtype)
Definition: context.hpp:52
viennacl::ocl::context
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
viennacl::ocl::current_context
viennacl::ocl::context & current_context()
Convenience function for returning the current context.
Definition: backend.hpp:213
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::context
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
viennacl::MEMORY_NOT_INITIALIZED
Definition: forwards.h:347
mem_handle.hpp
Implements the multi-memory-domain handle.
viennacl::backend::default_memory_type
memory_types default_memory_type()
Returns the default memory type for the given configuration.
Definition: mem_handle.hpp:73
viennacl::context::memory_type
viennacl::memory_types memory_type() const
Definition: context.hpp:76
viennacl::context::context
context()
Definition: context.hpp:42
viennacl::memory_types
memory_types
Definition: forwards.h:345