ClGenerators.h 4.9 KB

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