Generators.h 4.3 KB

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