All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils.hpp
Go to the documentation of this file.
#ifndef VIENNACL_OCL_UTILS_HPP_
#define VIENNACL_OCL_UTILS_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 <string>
#include "viennacl/ocl/backend.hpp"
#include "viennacl/ocl/device.hpp"
namespace viennacl
{
namespace ocl
{
template<typename ScalarType>
struct DOUBLE_PRECISION_CHECKER
{
static void apply(viennacl::ocl::context const &) {}
};
template<>
struct DOUBLE_PRECISION_CHECKER<double>
{
static void apply(viennacl::ocl::context const & ctx)
{
if (!ctx.current_device().double_support())
throw viennacl::ocl::double_precision_not_provided_error();
}
};
template<typename T>
struct type_to_string;
template<> struct type_to_string<char> { static std::string apply() { return "char"; } };
template<> struct type_to_string<short> { static std::string apply() { return "short"; } };
template<> struct type_to_string<int> { static std::string apply() { return "int"; } };
template<> struct type_to_string<long> { static std::string apply() { return "long"; } };
template<> struct type_to_string<unsigned char> { static std::string apply() { return "uchar"; } };
template<> struct type_to_string<unsigned short> { static std::string apply() { return "ushort"; } };
template<> struct type_to_string<unsigned int> { static std::string apply() { return "uint"; } };
template<> struct type_to_string<unsigned long> { static std::string apply() { return "ulong"; } };
template<> struct type_to_string<float> { static std::string apply() { return "float"; } };
template<> struct type_to_string<double> { static std::string apply() { return "double"; } };
template<typename T>
void append_double_precision_pragma(viennacl::ocl::context const & /*ctx*/, std::string & /*source*/) {}
template<>
inline void append_double_precision_pragma<double>(viennacl::ocl::context const & ctx, std::string & source)
{
source.append("#pragma OPENCL EXTENSION " + ctx.current_device().double_support_extension() + " : enable\n\n");
}
} //ocl
} //viennacl
#endif
viennacl::ocl::context::current_device
viennacl::ocl::device const & current_device() const
Returns the current device.
Definition: context.hpp:112
device.hpp
Represents an OpenCL device within ViennaCL.
viennacl::ocl::append_double_precision_pragma< double >
void append_double_precision_pragma< double >(viennacl::ocl::context const &ctx, std::string &source)
Definition: utils.hpp:78
viennacl::ocl::context
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
viennacl::ocl::append_double_precision_pragma
void append_double_precision_pragma(viennacl::ocl::context const &, std::string &)
Definition: utils.hpp:75
viennacl::ocl::DOUBLE_PRECISION_CHECKER::apply
static void apply(viennacl::ocl::context const &)
Definition: utils.hpp:40
viennacl::ocl::DOUBLE_PRECISION_CHECKER
Ensures that double precision types are only allocated if it is supported by the device. If double precision is requested for a device not capable of providing that, a double_precision_not_provided_error is thrown.
Definition: utils.hpp:38
viennacl::ocl::double_precision_not_provided_error
Exception thrown if the user wants to use double precision arithmetics, but the device does not suppo...
Definition: error.hpp:573
viennacl::ocl::device::double_support
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
Definition: device.hpp:956
backend.hpp
Implementations of the OpenCL backend, where all contexts are stored in.
viennacl::ocl::device::double_support_extension
std::string double_support_extension() const
ViennaCL convenience function: Returns the device extension which enables double precision (usually c...
Definition: device.hpp:967
viennacl::linalg::opencl::kernels::detail::type_to_string
std::string type_to_string(viennacl::row_major)
Definition: matrix.hpp:917
viennacl::ocl::type_to_string
Helper class for converting a type to its string representation.
Definition: utils.hpp:57