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
utils.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_OCL_UTILS_HPP_
2 #define VIENNACL_OCL_UTILS_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 <string>
27 #include "viennacl/ocl/backend.hpp"
28 #include "viennacl/ocl/device.hpp"
29 
30 namespace viennacl
31 {
32 namespace ocl
33 {
34 
37 template<typename ScalarType>
39 {
40  static void apply(viennacl::ocl::context const &) {}
41 };
42 
44 template<>
45 struct DOUBLE_PRECISION_CHECKER<double>
46 {
47  static void apply(viennacl::ocl::context const & ctx)
48  {
49  if (!ctx.current_device().double_support())
51  }
52 };
56 template<typename T>
58 
60 template<> struct type_to_string<char> { static std::string apply() { return "char"; } };
61 template<> struct type_to_string<short> { static std::string apply() { return "short"; } };
62 template<> struct type_to_string<int> { static std::string apply() { return "int"; } };
63 template<> struct type_to_string<long> { static std::string apply() { return "long"; } };
64 
65 template<> struct type_to_string<unsigned char> { static std::string apply() { return "uchar"; } };
66 template<> struct type_to_string<unsigned short> { static std::string apply() { return "ushort"; } };
67 template<> struct type_to_string<unsigned int> { static std::string apply() { return "uint"; } };
68 template<> struct type_to_string<unsigned long> { static std::string apply() { return "ulong"; } };
69 
70 template<> struct type_to_string<float> { static std::string apply() { return "float"; } };
71 template<> struct type_to_string<double> { static std::string apply() { return "double"; } };
74 template<typename T>
75 void append_double_precision_pragma(viennacl::ocl::context const & /*ctx*/, std::string & /*source*/) {}
76 
77 template<>
78 inline void append_double_precision_pragma<double>(viennacl::ocl::context const & ctx, std::string & source)
79 {
80  source.append("#pragma OPENCL EXTENSION " + ctx.current_device().double_support_extension() + " : enable\n\n");
81 }
82 
83 } //ocl
84 } //viennacl
85 #endif
viennacl::ocl::device const & current_device() const
Returns the current device.
Definition: context.hpp:112
Represents an OpenCL device within ViennaCL.
void append_double_precision_pragma< double >(viennacl::ocl::context const &ctx, std::string &source)
Definition: utils.hpp:78
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Definition: context.hpp:55
void append_double_precision_pragma(viennacl::ocl::context const &, std::string &)
Definition: utils.hpp:75
static void apply(viennacl::ocl::context const &)
Definition: utils.hpp:40
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
Exception thrown if the user wants to use double precision arithmetics, but the device does not suppo...
Definition: error.hpp:573
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
Definition: device.hpp:956
Implementations of the OpenCL backend, where all contexts are stored in.
std::string double_support_extension() const
ViennaCL convenience function: Returns the device extension which enables double precision (usually c...
Definition: device.hpp:967
std::string type_to_string(viennacl::row_major)
Definition: matrix.hpp:917
Helper class for converting a type to its string representation.
Definition: utils.hpp:57