Generators.h 5.0 KB

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