OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
glfft_wisdom.hpp
Go to the documentation of this file.
1 /* Copyright (C) 2015 Hans-Kristian Arntzen <maister@archlinux.us>
2  *
3  * Permission is hereby granted, free of charge,
4  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
5  * to deal in the Software without restriction, including without limitation the rights to
6  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8  *
9  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
12  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17  */
18 
19 #ifndef GLFFT_WISDOM_HPP__
20 #define GLFFT_WISDOM_HPP__
21 
22 #include <unordered_map>
23 #include <utility>
24 #include <string>
25 #include "glfft_common.hpp"
26 
27 namespace GLFFT
28 {
29 
30 struct WisdomPass
31 {
32  struct
33  {
34  unsigned Nx;
35  unsigned Ny;
36  unsigned radix;
41  } pass;
42 
43  double cost;
44 
45  bool operator==(const WisdomPass &other) const
46  {
47  return std::memcmp(&pass, &other.pass, sizeof(pass)) == 0;
48  }
49 };
50 
51 }
52 
53 namespace std
54 {
55  template<>
56  struct hash<GLFFT::WisdomPass>
57  {
58  std::size_t operator()(const GLFFT::WisdomPass &params) const
59  {
60  std::size_t h = 0;
61  hash<uint8_t> hasher;
62  for (std::size_t i = 0; i < sizeof(params.pass); i++)
63  {
64  h ^= hasher(reinterpret_cast<const uint8_t*>(&params.pass)[i]);
65  }
66 
67  return h;
68  }
69  };
70 }
71 
72 namespace GLFFT
73 {
74 
75 // Adds information which depends on the GPU vendor.
76 // This can speed up learning process, since there will be fewer "obviously wrong" settings to test.
78 {
79  enum Tristate { True = 1, False = 0, DontCare = -1 };
80 
81  unsigned min_workgroup_size = 1;
83  unsigned max_workgroup_size = 128; // GLES 3.1 mandates support for this.
84  unsigned min_vector_size = 2;
85  unsigned max_vector_size = 4;
87 };
88 
89 class FFTWisdom
90 {
91  public:
92  const std::pair<double, FFTOptions::Performance> learn_optimal_options(unsigned Nx, unsigned Ny, unsigned radix,
93  Mode mode, Target input_target, Target output_target, const FFTOptions::Type &type);
94 
95  void learn_optimal_options_exhaustive(unsigned Nx, unsigned Ny,
96  Type type, Target input_target, Target output_target, const FFTOptions::Type &fft_type);
97 
98  const std::pair<const WisdomPass, FFTOptions::Performance>* find_optimal_options(unsigned Nx, unsigned Ny, unsigned radix,
99  Mode mode, Target input_target, Target output_target, const FFTOptions::Type &base_options) const;
100 
101  const FFTOptions::Performance& find_optimal_options_or_default(unsigned Nx, unsigned Ny, unsigned radix,
102  Mode mode, Target input_target, Target output_target, const FFTOptions &base_options) const;
103 
105  static FFTStaticWisdom get_static_wisdom_from_renderer(const char *renderer);
106 
107  void set_bench_params(unsigned warmup, unsigned iterations, unsigned dispatches,
108  double timeout)
109  {
110  params.warmup = warmup;
111  params.iterations = iterations;
112  params.dispatches = dispatches;
113  params.timeout = timeout;
114  }
115 
116  private:
117  std::unordered_map<WisdomPass, FFTOptions::Performance> library;
118 
119  std::pair<double, FFTOptions::Performance> study(const WisdomPass &pass, FFTOptions::Type options) const;
120 
121  double bench(GLuint output, GLuint input, const WisdomPass &pass, const FFTOptions &options,
122  const std::shared_ptr<ProgramCache> &cache) const;
123 
125 
126  struct
127  {
128  unsigned warmup = 2;
129  unsigned iterations = 20;
130  unsigned dispatches = 50;
131  double timeout = 1.0;
132  } params;
133 };
134 
135 }
136 
137 #endif
138 
void ** params
Definition: gl2ext.h:143
std::pair< double, FFTOptions::Performance > study(const WisdomPass &pass, FFTOptions::Type options) const
int pass
Definition: app.cpp:216
struct GLFFT::FFTWisdom::@4 params
GLenum mode
Definition: gl2ext.h:302
double bench(GLuint output, GLuint input, const WisdomPass &pass, const FFTOptions &options, const std::shared_ptr< ProgramCache > &cache) const
struct GLFFT::WisdomPass::@3 pass
std::unordered_map< WisdomPass, FFTOptions::Performance > library
FFTStaticWisdom static_wisdom
Options for FFT implementation. Defaults for performance as conservative.
const std::pair< const WisdomPass, FFTOptions::Performance > * find_optimal_options(unsigned Nx, unsigned Ny, unsigned radix, Mode mode, Target input_target, Target output_target, const FFTOptions::Type &base_options) const
static FFTStaticWisdom get_static_wisdom_from_renderer(const char *renderer)
GLfloat GLfloat GLfloat GLfloat h
Definition: gl2ext.h:2701
const std::pair< double, FFTOptions::Performance > learn_optimal_options(unsigned Nx, unsigned Ny, unsigned radix, Mode mode, Target input_target, Target output_target, const FFTOptions::Type &type)
GLenum type
Definition: gl2ext.h:133
GLbitfield GLuint64 timeout
Definition: gl2ext.h:954
bool operator==(const WisdomPass &other) const
const FFTOptions::Performance & find_optimal_options_or_default(unsigned Nx, unsigned Ny, unsigned radix, Mode mode, Target input_target, Target output_target, const FFTOptions &base_options) const
void learn_optimal_options_exhaustive(unsigned Nx, unsigned Ny, Type type, Target input_target, Target output_target, const FFTOptions::Type &fft_type)
void set_static_wisdom(FFTStaticWisdom static_wisdom)
FFTOptions::Type type
unsigned min_workgroup_size_shared
void set_bench_params(unsigned warmup, unsigned iterations, unsigned dispatches, double timeout)
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
std::size_t operator()(const GLFFT::WisdomPass &params) const