All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
context.hpp
Go to the documentation of this file.
#ifndef VIENNACL_CONTEXT_HPP_
#define VIENNACL_CONTEXT_HPP_
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <vector>
#include <stddef.h>
#include <assert.h>
#include "viennacl/forwards.h"
#include "viennacl/ocl/forwards.h"
#include "viennacl/backend/mem_handle.hpp"
namespace viennacl
{
class context
{
public:
context() : mem_type_(viennacl::backend::default_memory_type())
{
#ifdef VIENNACL_WITH_OPENCL
if (mem_type_ == OPENCL_MEMORY)
ocl_context_ptr_ = &viennacl::ocl::current_context();
else
ocl_context_ptr_ = NULL;
#endif
}
explicit context(viennacl::memory_types mtype) : mem_type_(mtype)
{
if (mem_type_ == MEMORY_NOT_INITIALIZED)
mem_type_ = viennacl::backend::default_memory_type();
#ifdef VIENNACL_WITH_OPENCL
if (mem_type_ == OPENCL_MEMORY)
ocl_context_ptr_ = &viennacl::ocl::current_context();
else
ocl_context_ptr_ = NULL;
#endif
}
#ifdef VIENNACL_WITH_OPENCL
context(viennacl::ocl::context const & ctx) : mem_type_(OPENCL_MEMORY), ocl_context_ptr_(&ctx) {}
viennacl::ocl::context const & opencl_context() const
{
assert(mem_type_ == OPENCL_MEMORY && bool("Context type is not OpenCL"));
return *ocl_context_ptr_;
}
#endif
// TODO: Add CUDA and OpenMP contexts
viennacl::memory_types memory_type() const { return mem_type_; }
private:
viennacl::memory_types mem_type_;
#ifdef VIENNACL_WITH_OPENCL
viennacl::ocl::context const * ocl_context_ptr_;
#endif
};
}
#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