ViennaCL - The Vienna Computing Library  1.6.2
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2014, 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 PDF 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  {
92  return map.d.at(p0).d.at(p1).d.at(p2).d.at(p3).d.at(p4);
93  }
94 
95 
96 };
97 
98 
103 template<class NumericT, class ParamT>
104 inline ParamT const & get_parameters(database_type<ParamT> const & database, viennacl::ocl::device const & device)
105 {
107 
108  device_type dev_type = device.type();
110  ocl::device_architecture_family device_architecture = device.architecture_family();
111  std::string const & device_name = device.name();
112 
113 
114  /*-Vendor ID-*/
115  // std::cout << "Looking up vendor ID..." << std::endl;
116  typename database_type<ParamT>::type::map_t::const_iterator vendor_it = database.map.d.find(vendor_id);
117  //Vendor not recognized => device type default
118  if (vendor_it==database.map.d.end())
119  return database.at(ocl::unknown_id, dev_type, ocl::unknown, "", numeric_type);
120 
121  /*-Device Type-*/
122  // std::cout << "Looking up device type..." << std::endl;
123  typename database_type<ParamT>::device_type_t::map_t::const_iterator device_type_it = vendor_it->second.d.find(dev_type);
124  //Device type not recognized for this vendor => device type default
125  if (device_type_it==vendor_it->second.d.end())
126  return database.at(ocl::unknown_id, dev_type, ocl::unknown, "", numeric_type);
127 
128  /*-Device Architecture-*/
129  // std::cout << "Looking up device architecture..." << std::endl;
130  typename database_type<ParamT>::device_architecture_t::map_t::const_iterator architecture_it = device_type_it->second.d.find(device_architecture);
131  //Architecture not found. We try to find the closest architecture available.
132  if (architecture_it==device_type_it->second.d.end())
133  {
134  typename database_type<ParamT>::device_architecture_t::map_t::const_iterator current_it = device_type_it->second.d.begin();
135  architecture_it = current_it;
136  int closest_arch = current_it->first - device_architecture;
137  while (current_it!=device_type_it->second.d.end())
138  {
139  int arch_diff = std::abs(static_cast<int>(current_it->first) - static_cast<int>(device_architecture));
140  if (arch_diff < closest_arch)
141  {
142  architecture_it = current_it;
143  closest_arch = arch_diff;
144  }
145  current_it++;
146  }
147  }
148 
149  /*-Device Name-*/
150  // std::cout << "Looking up device name..." << std::endl;
151  typename database_type<ParamT>::device_name_t::map_t::const_iterator device_name_it = architecture_it->second.d.find(device_name);
152  //Name not found. We just take the first device for the architecture
153  if (device_name_it==architecture_it->second.d.end())
154  {
155  device_name_it = architecture_it->second.d.begin();
156  }
157 
158  // std::cout << "Looking up expression name.." << std::endl;
159  /*-Expression-*/
160  typename database_type<ParamT>::expression_t::map_t::const_iterator expression_it = device_name_it->second.d.find(numeric_type);
161  //Expression not found => Vendor default
162  if (expression_it==device_name_it->second.d.end())
163  return database.at(ocl::unknown_id, dev_type, ocl::unknown, "", numeric_type);
164 
165  // std::cout << "Device found in the database! Getting profile..." << std::endl;
166  //Everything okay. Return specific profile//
167  return expression_it->second;
168 }
169 
170 
171 }
172 }
173 }
174 #endif
std::string device_name_type
Definition: forwards.h:203
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:104
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:288
std::map< ocl::device_architecture_family, device_name_t > map_t
Definition: common.hpp:52
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:312
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:202
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
std::map< scheduler::statement_node_numeric_type, ParamT > map_t
Definition: common.hpp:50