ClGenerators.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #ifndef MANDEL_CLGENERATORS_H
  2. #define MANDEL_CLGENERATORS_H
  3. #ifdef WITH_OPENCL
  4. #include "Generators.h"
  5. #include "OpenClCode.h"
  6. #include <optional>
  7. #include <vector>
  8. #ifdef __APPLE__
  9. #define CL_TARGET_OPENCL_VERSION 120
  10. #define CL_HPP_TARGET_OPENCL_VERSION 120
  11. #define CL_HPP_MINIMUM_OPENCL_VERSION 120
  12. #else
  13. #define CL_TARGET_OPENCL_VERSION 120
  14. #define CL_HPP_TARGET_OPENCL_VERSION 120
  15. #define CL_HPP_MINIMUM_OPENCL_VERSION 120
  16. #endif
  17. #ifdef WITH_OPENCL
  18. #ifdef __APPLE__
  19. #include <OpenCL/cl.hpp>
  20. #else
  21. #include <CL/cl2.hpp>
  22. #endif
  23. #endif
  24. namespace mnd
  25. {
  26. class MandelDevice;
  27. class ClGenerator;
  28. class ClGeneratorFloat;
  29. class ClGeneratorDoubleFloat;
  30. class ClGeneratorTripleFloat;
  31. class ClGeneratorDouble;
  32. class ClGeneratorDoubleDouble;
  33. class ClGeneratorTripleDouble;
  34. class ClGeneratorQuadDouble;
  35. class ClGeneratorHexDouble;
  36. class ClGeneratorOctaDouble;
  37. class ClGenerator128;
  38. class ClGenerator64;
  39. }
  40. class mnd::ClGenerator : public MandelGenerator
  41. {
  42. protected:
  43. MandelDevice& device;
  44. cl::Context& context;
  45. cl::Program program;
  46. cl::CommandQueue queue;
  47. cl::Kernel kernel;
  48. public:
  49. ClGenerator(MandelDevice& device, const std::string& source, mnd::Precision type);
  50. virtual ~ClGenerator(void);
  51. virtual void generate(const MandelInfo& info, float* data) = 0;
  52. virtual mnd::MandelDevice* getDevice(void);
  53. virtual std::optional<std::vector<char>> getBinary(void);
  54. };
  55. class mnd::ClGeneratorFloat : public ClGenerator
  56. {
  57. bool useVec;
  58. public:
  59. ClGeneratorFloat(MandelDevice& device, const std::string& code = getFloat_cl());
  60. virtual ~ClGeneratorFloat(void) = default;
  61. virtual void generate(const MandelInfo& info, float* data) override;
  62. protected:
  63. virtual std::string getKernelCode(bool smooth) const;
  64. };
  65. class mnd::ClGeneratorDoubleFloat : public ClGenerator
  66. {
  67. public:
  68. ClGeneratorDoubleFloat(MandelDevice& device);
  69. virtual ~ClGeneratorDoubleFloat(void) = default;
  70. virtual void generate(const MandelInfo& info, float* data) override;
  71. protected:
  72. virtual std::string getKernelCode(bool smooth) const;
  73. };
  74. class mnd::ClGeneratorTripleFloat : public ClGenerator
  75. {
  76. public:
  77. ClGeneratorTripleFloat(MandelDevice& device);
  78. virtual ~ClGeneratorTripleFloat(void) = default;
  79. virtual void generate(const MandelInfo& info, float* data) override;
  80. protected:
  81. virtual std::string getKernelCode(bool smooth) const;
  82. };
  83. class mnd::ClGeneratorDouble : public ClGenerator
  84. {
  85. public:
  86. ClGeneratorDouble(mnd::MandelDevice& device, const std::string& source = getDouble_cl());
  87. virtual ~ClGeneratorDouble(void) = default;
  88. virtual void generate(const MandelInfo& info, float* data) override;
  89. protected:
  90. virtual std::string getKernelCode(bool smooth) const;
  91. };
  92. class mnd::ClGeneratorDoubleDouble : public ClGenerator
  93. {
  94. bool smooth;
  95. public:
  96. ClGeneratorDoubleDouble(mnd::MandelDevice& device);
  97. virtual ~ClGeneratorDoubleDouble(void) = default;
  98. virtual void generate(const MandelInfo& info, float* data) override;
  99. protected:
  100. virtual std::string getKernelCode(bool smooth) const;
  101. };
  102. class mnd::ClGeneratorTripleDouble : public ClGenerator
  103. {
  104. bool smooth;
  105. public:
  106. ClGeneratorTripleDouble(mnd::MandelDevice& device);
  107. virtual ~ClGeneratorTripleDouble(void) = default;
  108. virtual void generate(const MandelInfo& info, float* data) override;
  109. protected:
  110. virtual std::string getKernelCode(bool smooth) const;
  111. };
  112. class mnd::ClGeneratorQuadDouble : public ClGenerator
  113. {
  114. bool smooth;
  115. public:
  116. ClGeneratorQuadDouble(mnd::MandelDevice& device);
  117. virtual ~ClGeneratorQuadDouble(void) = default;
  118. virtual void generate(const MandelInfo& info, float* data) override;
  119. protected:
  120. virtual std::string getKernelCode(bool smooth) const;
  121. };
  122. class mnd::ClGeneratorHexDouble : public ClGenerator
  123. {
  124. public:
  125. ClGeneratorHexDouble(mnd::MandelDevice& device);
  126. virtual ~ClGeneratorHexDouble(void) = default;
  127. virtual void generate(const MandelInfo& info, float* data) override;
  128. protected:
  129. virtual std::string getKernelCode(bool smooth) const;
  130. };
  131. class mnd::ClGeneratorOctaDouble : public ClGenerator
  132. {
  133. public:
  134. ClGeneratorOctaDouble(mnd::MandelDevice& device);
  135. virtual ~ClGeneratorOctaDouble(void) = default;
  136. virtual void generate(const MandelInfo& info, float* data) override;
  137. protected:
  138. virtual std::string getKernelCode(bool smooth) const;
  139. };
  140. class mnd::ClGenerator128 : public ClGenerator
  141. {
  142. public:
  143. ClGenerator128(mnd::MandelDevice& device);
  144. virtual ~ClGenerator128(void) = default;
  145. virtual void generate(const MandelInfo& info, float* data) override;
  146. protected:
  147. virtual std::string getKernelCode(bool smooth) const;
  148. };
  149. class mnd::ClGenerator64 : public ClGenerator
  150. {
  151. public:
  152. ClGenerator64(mnd::MandelDevice& device);
  153. virtual ~ClGenerator64(void) = default;
  154. virtual void generate(const MandelInfo& info, float* data) override;
  155. protected:
  156. virtual std::string getKernelCode(bool smooth) const;
  157. };
  158. #endif // WITH_OPENCL
  159. #endif // MANDEL_CLGENERATORS_H