Generators.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. FLOAT128,
  88. FLOAT256,
  89. FIXED64,
  90. FIXED128,
  91. FIXED512
  92. };
  93. class mnd::MandelGenerator
  94. {
  95. protected:
  96. Real precision;
  97. Precision type;
  98. CpuExtension extension;
  99. public:
  100. MandelGenerator();
  101. inline MandelGenerator(Precision type) :
  102. precision{ mnd::getPrecision(type) },
  103. type{ type },
  104. extension{ mnd::CpuExtension::NONE }
  105. {
  106. }
  107. inline MandelGenerator(Precision type, CpuExtension extension) :
  108. precision{ mnd::getPrecision(type) },
  109. type{ type },
  110. extension{ extension }
  111. {
  112. }
  113. inline MandelGenerator(Precision type, CpuExtension extension, const Real& precision) :
  114. precision{ precision },
  115. type{ type },
  116. extension{ extension }
  117. {
  118. }
  119. virtual ~MandelGenerator(void);
  120. MandelGenerator(const MandelGenerator&) = delete;
  121. MandelGenerator& operator=(const MandelGenerator&) = delete;
  122. MandelGenerator(MandelGenerator&&) = default;
  123. MandelGenerator& operator=(MandelGenerator&&) = default;
  124. virtual void generate(const MandelInfo& info, float* data) = 0;
  125. virtual mnd::MandelDevice* getDevice(void);
  126. virtual Real getPrecision(void) const;
  127. virtual Precision getType(void) const;
  128. virtual CpuExtension getExtension(void) const;
  129. };
  130. class mnd::AdaptiveGenerator : public MandelGenerator
  131. {
  132. std::map<Real, MandelGenerator*, std::greater<Real>> generators;
  133. public:
  134. AdaptiveGenerator(void);
  135. AdaptiveGenerator(AdaptiveGenerator&) = default;
  136. AdaptiveGenerator(AdaptiveGenerator&&) = default;
  137. AdaptiveGenerator(MandelGenerator* floatGen, MandelGenerator* doubleGen);
  138. virtual ~AdaptiveGenerator(void) = default;
  139. void addGenerator(const Real& precision, MandelGenerator& generator);
  140. void addGenerator(Precision p, MandelGenerator& generator);
  141. const std::map<Real, MandelGenerator*, std::greater<Real>>& getGenerators(void) const { return generators; }
  142. inline void clear(void) { generators.clear(); }
  143. virtual void generate(const MandelInfo& info, float* data) override;
  144. };
  145. #endif // MANDEL_GENERATORS_H