Mandel.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef MANDEL_MANDEL_H
  2. #define MANDEL_MANDEL_H
  3. // don't expose this library interface as it clashes with qt
  4. //#include <asmjit/asmjit.h>
  5. namespace asmjit { class JitRuntime; }
  6. #ifndef WITH_ASMJIT
  7. // if no asmjit, use dummy implementation
  8. namespace asmjit { class JitRuntime{}; }
  9. #endif // WITH_ASMJITH
  10. #include <vector>
  11. #include <map>
  12. #include <string>
  13. #include <memory>
  14. #include "MandelUtil.h"
  15. #include "Generators.h"
  16. #include "IterationGenerator.h"
  17. #include "CpuGenerators.h"
  18. #include "Hardware.h"
  19. #include "CalcPlugin.h"
  20. namespace mnd
  21. {
  22. class MandelContext;
  23. class MandelDevice;
  24. struct ClDeviceWrapper;
  25. extern MandelContext initializeContext(void);
  26. struct MandelContextCache;
  27. }
  28. class mnd::MandelDevice
  29. {
  30. private:
  31. friend class MandelContext;
  32. std::string platformName;
  33. std::string vendor;
  34. std::string name;
  35. std::string extensions;
  36. std::unique_ptr<ClDeviceWrapper> clDevice;
  37. std::map<Precision, std::unique_ptr<MandelGenerator>> mandelGenerators;
  38. public:
  39. MandelDevice(ClDeviceWrapper, const std::string& platformName);
  40. MandelDevice(const MandelDevice&) = delete;
  41. MandelDevice(MandelDevice&&) = default;
  42. MandelDevice& operator=(const MandelDevice&) = delete;
  43. MandelDevice& operator=(MandelDevice&&) = default;
  44. inline const std::string& getVendor(void) const { return vendor; }
  45. inline const std::string& getName(void) const { return name; }
  46. MandelGenerator* getGenerator(Precision type) const;
  47. inline ClDeviceWrapper& getClDevice(void) { return *clDevice; }
  48. inline const ClDeviceWrapper& getClDevice(void) const { return *clDevice; }
  49. std::vector<Precision> getSupportedTypes(void) const;
  50. bool supportsDouble(void) const;
  51. };
  52. class mnd::MandelContext
  53. {
  54. private:
  55. friend MandelContext mnd::initializeContext(void);
  56. using GeneratorType = std::pair<Precision, HardwareFeature>;
  57. CpuInfo cpuInfo;
  58. std::unique_ptr<asmjit::JitRuntime> jitRuntime;
  59. ///
  60. /// \brief list of standard mandel generators implemented in c++
  61. ///
  62. /// This is an owning list of Generators that can be used regardless of
  63. /// Cpu type as they are implemented in standard c++ and are integrated
  64. /// into libmandel.
  65. ///
  66. std::vector<std::unique_ptr<MandelGenerator>> defaultGenerators;
  67. std::vector<std::unique_ptr<CalcPlugin>> loadedPlugins;
  68. ///
  69. /// \brief all cpu generators currently available
  70. ///
  71. std::map<GeneratorType, MandelGenerator*> cpuGenerators;
  72. std::unique_ptr<AdaptiveGenerator> adaptiveGenerator;
  73. std::vector<std::unique_ptr<mnd::MandelDevice>> devices;
  74. MandelContext(void);
  75. std::unique_ptr<AdaptiveGenerator> createAdaptiveGenerator(void);
  76. std::vector<std::unique_ptr<mnd::MandelDevice>> createDevices(void);
  77. public:
  78. ~MandelContext(void);
  79. MandelContext(const MandelContext&) = delete;
  80. MandelContext(MandelContext&&) = default;
  81. MandelContext& operator=(const MandelContext&) = delete;
  82. MandelContext& operator=(MandelContext&&) = default;
  83. void loadPlugin(std::unique_ptr<CalcPlugin> cp);
  84. AdaptiveGenerator& getDefaultGenerator(void);
  85. std::vector<std::unique_ptr<mnd::MandelDevice>>& getDevices(void);
  86. asmjit::JitRuntime& getJitRuntime(void);
  87. MandelGenerator* getCpuGenerator(mnd::Precision type, mnd::HardwareFeature ex);
  88. std::vector<GeneratorType> getSupportedTypes(void) const;
  89. std::vector<MandelGenerator*> getCpuGenerators(mnd::Precision prec) const;
  90. const CpuInfo& getCpuInfo(void) const { return cpuInfo; }
  91. void saveCache(const std::string& path) const;
  92. static MandelContext initializeFromCache(const std::string& path);
  93. };
  94. struct mnd::MandelContextCache
  95. {
  96. };
  97. #endif // MANDEL_MANDEL_H