Generators.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #ifndef MANDEL_GENERATORS_H
  2. #define MANDEL_GENERATORS_H
  3. #include "MandelUtil.h"
  4. #include <vector>
  5. #include <map>
  6. #include <utility>
  7. namespace mnd
  8. {
  9. class MandelGenerator;
  10. class AdaptiveGenerator;
  11. enum class GeneratorType : int;
  12. enum class Precision : int
  13. {
  14. FLOAT,
  15. DOUBLE_FLOAT,
  16. TRIPLE_FLOAT,
  17. DOUBLE,
  18. DOUBLE_DOUBLE,
  19. TRIPLE_DOUBLE,
  20. QUAD_DOUBLE,
  21. HEX_DOUBLE,
  22. FLOAT128,
  23. FLOAT256,
  24. FLOAT512,
  25. FIXED64,
  26. FIXED128,
  27. FIXED512,
  28. INF_PREC,
  29. };
  30. enum CpuExtension : int
  31. {
  32. NONE,
  33. X86_SSE2,
  34. X86_AVX,
  35. X86_AVX_FMA,
  36. X86_AVX_512,
  37. ARM_NEON,
  38. };
  39. std::string toString(Precision);
  40. std::string toString(CpuExtension);
  41. Real getPrecision(Precision p);
  42. template<typename T>
  43. Real getPrecision(void);
  44. template<> Real getPrecision<float>();
  45. template<> Real getPrecision<double>();
  46. template<> Real getPrecision<DoubleDouble>();
  47. template<> Real getPrecision<TripleDouble>();
  48. template<> Real getPrecision<QuadDouble>();
  49. template<> Real getPrecision<HexDouble>();
  50. template<> Real getPrecision<Fixed64>();
  51. template<> Real getPrecision<Fixed128>();
  52. template<> Real getPrecision<Fixed512>();
  53. template<> Real getPrecision<Float128>();
  54. template<> Real getPrecision<Float256>();
  55. template<> Real getPrecision<Float512>();
  56. template<typename T>
  57. Precision getType(void);
  58. template<> inline Precision getType<float>() { return Precision::FLOAT; }
  59. template<> inline Precision getType<double>() { return Precision::DOUBLE; }
  60. template<> inline Precision getType<DoubleDouble>() { return Precision::DOUBLE_DOUBLE; }
  61. template<> inline Precision getType<TripleDouble>() { return Precision::TRIPLE_DOUBLE; }
  62. template<> inline Precision getType<QuadDouble>() { return Precision::QUAD_DOUBLE; }
  63. template<> inline Precision getType<HexDouble>() { return Precision::HEX_DOUBLE; }
  64. template<> inline Precision getType<Fixed64>() { return Precision::FIXED64; }
  65. template<> inline Precision getType<Fixed128>() { return Precision::FIXED128; }
  66. template<> inline Precision getType<Fixed512>() { return Precision::FIXED512; }
  67. template<> inline Precision getType<Float128>() { return Precision::FLOAT128; }
  68. template<> inline Precision getType<Float256>() { return Precision::FLOAT256; }
  69. template<> inline Precision getType<Float512>() { return Precision::FLOAT512; }
  70. class MandelDevice;
  71. }
  72. /*
  73. enum class mnd::GeneratorType : int
  74. {
  75. UNSPECIFIED,
  76. FLOAT,
  77. FLOAT_SSE2,
  78. FLOAT_AVX,
  79. FLOAT_AVX_FMA,
  80. FLOAT_AVX512,
  81. FLOAT_NEON,
  82. DOUBLE_FLOAT,
  83. DOUBLE,
  84. DOUBLE_SSE2,
  85. DOUBLE_AVX,
  86. DOUBLE_AVX_FMA,
  87. DOUBLE_AVX512,
  88. DOUBLE_NEON,
  89. DOUBLE_DOUBLE,
  90. DOUBLE_DOUBLE_AVX,
  91. DOUBLE_DOUBLE_AVX_FMA,
  92. DOUBLE_DOUBLE_NEON,
  93. TRIPLE_DOUBLE,
  94. TRIPLE_DOUBLE_AVX,
  95. QUAD_DOUBLE,
  96. QUAD_DOUBLE_AVX_FMA,
  97. FLOAT128,
  98. FLOAT256,
  99. FIXED64,
  100. FIXED128,
  101. FIXED512
  102. };
  103. */
  104. class mnd::MandelGenerator
  105. {
  106. protected:
  107. Real precision;
  108. Precision type;
  109. CpuExtension extension;
  110. public:
  111. MandelGenerator(void);
  112. inline MandelGenerator(Precision type) :
  113. precision{ mnd::getPrecision(type) },
  114. type{ type },
  115. extension{ mnd::CpuExtension::NONE }
  116. {
  117. }
  118. inline MandelGenerator(Precision type, CpuExtension extension) :
  119. precision{ mnd::getPrecision(type) },
  120. type{ type },
  121. extension{ extension }
  122. {
  123. }
  124. inline MandelGenerator(Precision type, CpuExtension extension, const Real& precision) :
  125. precision{ precision },
  126. type{ type },
  127. extension{ extension }
  128. {
  129. }
  130. virtual ~MandelGenerator(void);
  131. MandelGenerator(const MandelGenerator&) = default;
  132. MandelGenerator& operator=(const MandelGenerator&) = default;
  133. MandelGenerator(MandelGenerator&&) = default;
  134. MandelGenerator& operator=(MandelGenerator&&) = default;
  135. virtual void generate(const MandelInfo& info, float* data) = 0;
  136. virtual mnd::MandelDevice* getDevice(void);
  137. virtual Real getPrecision(void) const;
  138. virtual Precision getType(void) const;
  139. virtual CpuExtension getExtension(void) const;
  140. };
  141. class mnd::AdaptiveGenerator : public MandelGenerator
  142. {
  143. std::map<Real, MandelGenerator*, std::greater<Real>> generators;
  144. public:
  145. AdaptiveGenerator(void);
  146. AdaptiveGenerator(AdaptiveGenerator&) = delete;
  147. AdaptiveGenerator(AdaptiveGenerator&&) = default;
  148. AdaptiveGenerator(MandelGenerator* floatGen, MandelGenerator* doubleGen);
  149. virtual ~AdaptiveGenerator(void) = default;
  150. void addGenerator(const Real& precision, MandelGenerator& generator);
  151. void addGenerator(Precision p, MandelGenerator& generator);
  152. void addGenerator(MandelGenerator& generator);
  153. const std::map<Real, MandelGenerator*, std::greater<Real>>& getGenerators(void) const { return generators; }
  154. inline void clear(void) { generators.clear(); }
  155. virtual void generate(const MandelInfo& info, float* data) override;
  156. };
  157. #endif // MANDEL_GENERATORS_H