SkelCL
SkelCL is a high level multi GPU skeleton library developed at the university of Münster, Germany.
 All Classes Namespaces Files Functions Variables Typedefs Groups
Source.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2011-2012 The SkelCL Team as listed in CREDITS.txt *
3  * http://skelcl.uni-muenster.de *
4  * *
5  * This file is part of SkelCL. *
6  * SkelCL is available under multiple licenses. *
7  * The different licenses are subject to terms and condition as provided *
8  * in the files specifying the license. See "LICENSE.txt" for details *
9  * *
10  *****************************************************************************
11  * *
12  * SkelCL is free software: you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation, either version 3 of the License, or *
15  * (at your option) any later version. See "LICENSE-gpl.txt" for details. *
16  * *
17  * SkelCL is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  *****************************************************************************
23  * *
24  * For non-commercial academic use see the license specified in the file *
25  * "LICENSE-academic.txt". *
26  * *
27  *****************************************************************************
28  * *
29  * If you are interested in other licensing models, including a commercial- *
30  * license, please contact the author at michel.steuwer@uni-muenster.de *
31  * *
32  *****************************************************************************/
33 
39 
40 #include <iostream>
41 
42 #include <istream>
43 #include <string>
44 
45 #include <pvsutil/Assert.h>
46 
47 #include "SkelCL/Source.h"
48 
49 namespace skelcl {
50 
51 Source::Source()
52  : _source()
53 {
54 }
55 
56 Source::Source(const char* source)
57  : _source(source)
58 {
59  ASSERT_MESSAGE(!_source.empty(),
60  "Tried to create source object with empty user source.");
61 }
62 
63 Source::Source(const std::string& source)
64  : _source(source)
65 {
66  ASSERT_MESSAGE(!_source.empty(),
67  "Tried to create source object with empty user source.");
68 }
69 
70 Source::Source(std::istream& is)
71  : _source( (std::istreambuf_iterator<char>(is)),
72  std::istreambuf_iterator<char>() )
73 {
74  ASSERT_MESSAGE(!_source.empty(),
75  "Tried to create source object with empty user source.");
76 }
77 
78 Source::Source(std::istream&& is)
79  : _source( (std::istreambuf_iterator<char>(is)),
80  std::istreambuf_iterator<char>() )
81 {
82  ASSERT_MESSAGE(!_source.empty(),
83  "Tried to create source object with empty user source.");
84 }
85 
87 {
88 }
89 
90 Source::operator std::string() const
91 {
92  return _source;
93 }
94 
95 void Source::append(const std::string& source)
96 {
97  _source.append("\n" + source);
98 }
99 
100 namespace detail {
101 
102 CommonDefinitions::CommonDefinitions()
103  : _sources(Level::SIZE)
104 {
105 }
106 
107 CommonDefinitions& CommonDefinitions::instance()
108 {
109  static CommonDefinitions instance;
110  return instance;
111 }
112 
113 void CommonDefinitions::append(const std::string& source, Level level)
114 {
115  CommonDefinitions::instance()._sources[level].append(source);
116 }
117 
118 Source CommonDefinitions::getSource()
119 {
120  auto& instance = CommonDefinitions::instance();
121  auto s = instance._sources[0];
122  for (unsigned int i = 1; i < Level::SIZE; ++i) {
123  s.append(instance._sources[i]);
124  }
125  return s;
126 }
127 
128 RegisterCommonDefinition::RegisterCommonDefinition(const char* definition,
129  CommonDefinitions::Level l)
130 {
131  // if definition contains the string "double" enable double
132  if (std::string(definition).find("double") != std::string::npos) {
133  CommonDefinitions::append(
134  "#if defined(cl_khr_fp64)\n"
135  "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n"
136  "#elif defined(cl_amd_fp64)\n"
137  "#pragma OPENCL EXTENSION cl_amd_fp64 : enable\n"
138  "#endif\n",
139  CommonDefinitions::PRAGMA);
140  }
141  CommonDefinitions::append(definition, l);
142 }
143 
144 } // namespace detail
145 
146 } // namespace skelcl
147 
void append(const std::string &source)
Append the given string to the source code.
Definition: Source.cpp:95
~Source()
Default destructor.
Definition: Source.cpp:86