Generators.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 Precision : int
  12. {
  13. FLOAT,
  14. DOUBLE_FLOAT,
  15. TRIPLE_FLOAT,
  16. DOUBLE,
  17. DOUBLE_DOUBLE,
  18. TRIPLE_DOUBLE,
  19. QUAD_DOUBLE,
  20. HEX_DOUBLE,
  21. OCTA_DOUBLE,
  22. FLOAT128,
  23. FLOAT256,
  24. FLOAT512,
  25. FIXED64,
  26. FIXED128,
  27. FIXED512,
  28. INF_PREC,
  29. };
  30. enum HardwareFeature : 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(HardwareFeature);
  41. Real getPrecision(Precision p);
  42. template<typename T>
  43. Real getPrecision(void);
  44. template<typename T>
  45. Precision getType(void);
  46. class MandelDevice;
  47. }
  48. class mnd::MandelGenerator
  49. {
  50. protected:
  51. Real precision;
  52. Precision type;
  53. HardwareFeature extension;
  54. public:
  55. MandelGenerator(void);
  56. inline MandelGenerator(Precision type) :
  57. precision{ mnd::getPrecision(type) },
  58. type{ type },
  59. extension{ mnd::HardwareFeature::NONE }
  60. {
  61. }
  62. inline MandelGenerator(Precision type, HardwareFeature extension) :
  63. precision{ mnd::getPrecision(type) },
  64. type{ type },
  65. extension{ extension }
  66. {
  67. }
  68. inline MandelGenerator(Precision type, HardwareFeature extension, const Real& precision) :
  69. precision{ precision },
  70. type{ type },
  71. extension{ extension }
  72. {
  73. }
  74. virtual ~MandelGenerator(void);
  75. MandelGenerator(const MandelGenerator&) = default;
  76. MandelGenerator& operator=(const MandelGenerator&) = default;
  77. MandelGenerator(MandelGenerator&&) = default;
  78. MandelGenerator& operator=(MandelGenerator&&) = default;
  79. virtual void generate(const MandelInfo& info, float* data) = 0;
  80. virtual mnd::MandelDevice* getDevice(void);
  81. virtual Real getPrecision(void) const;
  82. virtual Precision getType(void) const;
  83. virtual HardwareFeature getExtension(void) const;
  84. };
  85. class mnd::AdaptiveGenerator : public MandelGenerator
  86. {
  87. std::map<Real, MandelGenerator*, std::greater<Real>> generators;
  88. public:
  89. AdaptiveGenerator(void);
  90. AdaptiveGenerator(AdaptiveGenerator&) = delete;
  91. AdaptiveGenerator(AdaptiveGenerator&&) = default;
  92. AdaptiveGenerator(MandelGenerator* floatGen, MandelGenerator* doubleGen);
  93. virtual ~AdaptiveGenerator(void) = default;
  94. void addGenerator(const Real& precision, MandelGenerator& generator);
  95. void addGenerator(Precision p, MandelGenerator& generator);
  96. void addGenerator(MandelGenerator& generator);
  97. const std::map<Real, MandelGenerator*, std::greater<Real>>& getGenerators(void) const { return generators; }
  98. inline void clear(void) { generators.clear(); }
  99. virtual void generate(const MandelInfo& info, float* data) override;
  100. };
  101. #endif // MANDEL_GENERATORS_H