ViennaCL - The Vienna Computing Library
1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
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-2015, 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>
38
struct
DOUBLE_PRECISION_CHECKER
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
())
50
throw
viennacl::ocl::double_precision_not_provided_error
();
51
}
52
};
56
template
<
typename
T>
57
struct
type_to_string
;
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::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
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition:
cpu_ram.hpp:34
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::linalg::opencl::kernels::detail::type_to_string
std::string type_to_string(viennacl::row_major)
Definition:
matrix.hpp:481
viennacl::ocl::type_to_string
Helper class for converting a type to its string representation.
Definition:
utils.hpp:57
viennacl
ocl
utils.hpp
Generated on Fri Jul 31 2015 14:18:58 for ViennaCL - The Vienna Computing Library by
1.8.9.1