Generators.h 4.7 KB

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