ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
common.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_DEVICE_SPECIFIC_BUILTIN_DATABASE_COMMON_HPP_
2 #define VIENNACL_DEVICE_SPECIFIC_BUILTIN_DATABASE_COMMON_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 
27 
29 
31 
32 namespace viennacl
33 {
34 namespace device_specific
35 {
36 namespace builtin_database
37 {
38 
41 using namespace viennacl::ocl;
42 
43 template<class ParamT>
45 {
46 public:
47 
48  //Because it would be too easy to use nested maps directly.
49  //THANKS, VISUAL STUDIO.
50  struct expression_t{ typedef std::map<scheduler::statement_node_numeric_type, ParamT> map_t; map_t d; };
51  struct device_name_t{ typedef std::map<device_name_type, expression_t> map_t; map_t d; };
52  struct device_architecture_t{ typedef std::map<ocl::device_architecture_family, device_name_t> map_t; map_t d; };
53  struct device_type_t{ typedef std::map<device_type, device_architecture_t> map_t; map_t d; };
54  struct type{ typedef std::map<vendor_id_type, device_type_t> map_t; map_t d; };
56 
58  {
59  map.d[p0].d[p1].d[p2].d[p3].d.insert(std::make_pair(p4, p5));
60  return *this;
61  }
62 
64  {
65  return (*this)(p0, p1, p2, p3, scheduler::CHAR_TYPE, p5)
66  (p0, p1, p2, p3, scheduler::UCHAR_TYPE, p5);
67  }
68 
70  {
71  return (*this)(p0, p1, p2, p3, scheduler::SHORT_TYPE, p5)
72  (p0, p1, p2, p3, scheduler::USHORT_TYPE, p5)
73  (p0, p1, p2, p3, scheduler::HALF_TYPE, p5);
74  }
75 
77  {
78  return (*this)(p0, p1, p2, p3, scheduler::INT_TYPE, p5)
79  (p0, p1, p2, p3, scheduler::UINT_TYPE, p5)
80  (p0, p1, p2, p3, scheduler::FLOAT_TYPE, p5);
81  }
82 
84  {
85  return (*this)(p0, p1, p2, p3, scheduler::LONG_TYPE, p5)
86  (p0, p1, p2, p3, scheduler::ULONG_TYPE, p5)
87  (p0, p1, p2, p3, scheduler::DOUBLE_TYPE, p5);
88  }
89 
91  {
97  p1).d,
98  p2).d,
99  p3).d,
100  p4);
101  }
102 
103 
104 };
105 
106 
111 template<class NumericT, class ParamT>
112 inline ParamT const & get_parameters(database_type<ParamT> const & database, viennacl::ocl::device const & device)
113 {
115 
116  device_type dev_type = device.type();
118  ocl::device_architecture_family device_architecture = device.architecture_family();
119  std::string const & device_name = device.name();
120 
121 
122  /*-Vendor ID-*/
123  // std::cout << "Looking up vendor ID..." << std::endl;
124  typename database_type<ParamT>::type::map_t::const_iterator vendor_it = database.map.d.find(vendor_id);
125  //Vendor not recognized => device type default
126  if (vendor_it==database.map.d.end())
127  return database.at(ocl::unknown_id, dev_type, ocl::unknown, "", numeric_type);
128 
129  /*-Device Type-*/
130  // std::cout << "Looking up device type..." << std::endl;
131  typename database_type<ParamT>::device_type_t::map_t::const_iterator device_type_it = vendor_it->second.d.find(dev_type);
132  //Device type not recognized for this vendor => device type default
133  if (device_type_it==vendor_it->second.d.end())
134  return database.at(ocl::unknown_id, dev_type, ocl::unknown, "", numeric_type);
135 
136  /*-Device Architecture-*/
137  // std::cout << "Looking up device architecture..." << std::endl;
138  typename database_type<ParamT>::device_architecture_t::map_t::const_iterator architecture_it = device_type_it->second.d.find(device_architecture);
139  //Architecture not found. We try to find the closest architecture available.
140  if (architecture_it==device_type_it->second.d.end())
141  {
142  typename database_type<ParamT>::device_architecture_t::map_t::const_iterator current_it = device_type_it->second.d.begin();
143  architecture_it = current_it;
144  int closest_arch = current_it->first - device_architecture;
145  while (current_it!=device_type_it->second.d.end())
146  {
147  int arch_diff = std::abs(static_cast<int>(current_it->first) - static_cast<int>(device_architecture));
148  if (arch_diff < closest_arch)
149  {
150  architecture_it = current_it;
151  closest_arch = arch_diff;
152  }
153  current_it++;
154  }
155  }
156 
157  /*-Device Name-*/
158  // std::cout << "Looking up device name..." << std::endl;
159  typename database_type<ParamT>::device_name_t::map_t::const_iterator device_name_it = architecture_it->second.d.find(device_name);
160  //Name not found. We just take the first device for the architecture
161  if (device_name_it==architecture_it->second.d.end())
162  {
163  device_name_it = architecture_it->second.d.begin();
164  }
165 
166  // std::cout << "Looking up expression name.." << std::endl;
167  /*-Expression-*/
168  typename database_type<ParamT>::expression_t::map_t::const_iterator expression_it = device_name_it->second.d.find(numeric_type);
169  //Expression not found => Vendor default
170  if (expression_it==device_name_it->second.d.end())
171  return database.at(ocl::unknown_id, dev_type, ocl::unknown, "", numeric_type);
172 
173  // std::cout << "Device found in the database! Getting profile..." << std::endl;
174  //Everything okay. Return specific profile//
175  return expression_it->second;
176 }
177 
178 
179 }
180 }
181 }
182 #endif
std::string device_name_type
Definition: forwards.h:214
std::map< device_type, device_architecture_t > map_t
Definition: common.hpp:53
A class representing a compute device (e.g. a GPU)
Definition: device.hpp:49
ParamT const & get_parameters(database_type< ParamT > const &database, viennacl::ocl::device const &device)
Get the profile for a device and a descriptor.
Definition: common.hpp:112
cl_device_type type() const
The OpenCL device type.
Definition: device.hpp:893
std::map< vendor_id_type, device_type_t > map_t
Definition: common.hpp:54
ParamT const & at(vendor_id_type p0, device_type p1, ocl::device_architecture_family p2, device_name_type p3, scheduler::statement_node_numeric_type p4) const
Definition: common.hpp:90
cl_uint vendor_id() const
A unique device vendor identifier. An example of a unique device identifier could be the PCIe ID...
Definition: device.hpp:917
statement_node_numeric_type
Encodes the type of a node in the statement tree.
Definition: forwards.h:286
std::map< ocl::device_architecture_family, device_name_t > map_t
Definition: common.hpp:52
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
database_type< ParamT > & add_8B(vendor_id_type p0, device_type p1, ocl::device_architecture_family p2, device_name_type p3, ParamT const &p5)
Definition: common.hpp:83
database_type< ParamT > & add_2B(vendor_id_type p0, device_type p1, ocl::device_architecture_family p2, device_name_type p3, ParamT const &p5)
Definition: common.hpp:69
database_type< ParamT > & add_4B(vendor_id_type p0, device_type p1, ocl::device_architecture_family p2, device_name_type p3, ParamT const &p5)
Definition: common.hpp:76
Various utility implementations for dispatching with respect to the different devices available on th...
Forwards declaration.
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
std::string name() const
Device name string.
Definition: device.hpp:566
device_architecture_family architecture_family() const
Device architecture family.
Definition: device.hpp:578
Helper metafunction for obtaining the runtime type ID for a numerical type.
Definition: forwards.h:310
database_type< ParamT > & add_1B(vendor_id_type p0, device_type p1, ocl::device_architecture_family p2, device_name_type p3, ParamT const &p5)
Definition: common.hpp:63
cl_device_type device_type
Definition: forwards.h:213
database_type< ParamT > & operator()(vendor_id_type p0, device_type p1, ocl::device_architecture_family p2, device_name_type p3, scheduler::statement_node_numeric_type p4, ParamT const &p5)
Definition: common.hpp:57
OpenCL backend. Manages platforms, contexts, buffers, kernels, etc.
Definition: forwards.h:1003
ValueT const & at(std::map< KeyT, ValueT > const &map, KeyT const &key)
Emulation of C++11's .at() member for std::map<>, const-version.
Definition: forwards.h:142
std::map< scheduler::statement_node_numeric_type, ParamT > map_t
Definition: common.hpp:50