ClGenerators.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 ClGenerator128;
  35. class ClGenerator64;
  36. }
  37. class mnd::ClGenerator : public MandelGenerator
  38. {
  39. protected:
  40. MandelDevice& device;
  41. cl::Context& context;
  42. cl::Program program;
  43. cl::CommandQueue queue;
  44. cl::Kernel kernel;
  45. public:
  46. ClGenerator(MandelDevice& device, const std::string& source, mnd::Precision type);
  47. virtual ~ClGenerator(void);
  48. virtual void generate(const MandelInfo& info, float* data) = 0;
  49. virtual mnd::MandelDevice* getDevice(void);
  50. };
  51. class mnd::ClGeneratorFloat : public ClGenerator
  52. {
  53. bool useVec;
  54. public:
  55. ClGeneratorFloat(MandelDevice& device, const std::string& code = getFloat_cl());
  56. virtual ~ClGeneratorFloat(void) = default;
  57. virtual void generate(const MandelInfo& info, float* data) override;
  58. protected:
  59. virtual std::string getKernelCode(bool smooth) const;
  60. };
  61. class mnd::ClGeneratorDoubleFloat : public ClGenerator
  62. {
  63. public:
  64. ClGeneratorDoubleFloat(MandelDevice& device);
  65. virtual ~ClGeneratorDoubleFloat(void) = default;
  66. virtual void generate(const MandelInfo& info, float* data) override;
  67. protected:
  68. virtual std::string getKernelCode(bool smooth) const;
  69. };
  70. class mnd::ClGeneratorTripleFloat : public ClGenerator
  71. {
  72. public:
  73. ClGeneratorTripleFloat(MandelDevice& device);
  74. virtual ~ClGeneratorTripleFloat(void) = default;
  75. virtual void generate(const MandelInfo& info, float* data) override;
  76. protected:
  77. virtual std::string getKernelCode(bool smooth) const;
  78. };
  79. class mnd::ClGeneratorDouble : public ClGenerator
  80. {
  81. public:
  82. ClGeneratorDouble(mnd::MandelDevice& device, const std::string& source = getDouble_cl());
  83. virtual ~ClGeneratorDouble(void) = default;
  84. virtual void generate(const MandelInfo& info, float* data) override;
  85. protected:
  86. virtual std::string getKernelCode(bool smooth) const;
  87. };
  88. class mnd::ClGeneratorDoubleDouble : public ClGenerator
  89. {
  90. bool smooth;
  91. public:
  92. ClGeneratorDoubleDouble(mnd::MandelDevice& device);
  93. virtual ~ClGeneratorDoubleDouble(void) = default;
  94. virtual void generate(const MandelInfo& info, float* data) override;
  95. protected:
  96. virtual std::string getKernelCode(bool smooth) const;
  97. };
  98. class mnd::ClGeneratorTripleDouble : public ClGenerator
  99. {
  100. bool smooth;
  101. public:
  102. ClGeneratorTripleDouble(mnd::MandelDevice& device);
  103. virtual ~ClGeneratorTripleDouble(void) = default;
  104. virtual void generate(const MandelInfo& info, float* data) override;
  105. protected:
  106. virtual std::string getKernelCode(bool smooth) const;
  107. };
  108. class mnd::ClGeneratorQuadDouble : public ClGenerator
  109. {
  110. bool smooth;
  111. public:
  112. ClGeneratorQuadDouble(mnd::MandelDevice& device);
  113. virtual ~ClGeneratorQuadDouble(void) = default;
  114. virtual void generate(const MandelInfo& info, float* data) override;
  115. protected:
  116. virtual std::string getKernelCode(bool smooth) const;
  117. };
  118. class mnd::ClGeneratorHexDouble : public ClGenerator
  119. {
  120. bool smooth;
  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::ClGenerator128 : public ClGenerator
  129. {
  130. public:
  131. ClGenerator128(mnd::MandelDevice& device);
  132. virtual ~ClGenerator128(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::ClGenerator64 : public ClGenerator
  138. {
  139. public:
  140. ClGenerator64(mnd::MandelDevice& device);
  141. virtual ~ClGenerator64(void) = default;
  142. virtual void generate(const MandelInfo& info, float* data) override;
  143. protected:
  144. virtual std::string getKernelCode(bool smooth) const;
  145. };
  146. #endif // WITH_OPENCL
  147. #endif // MANDEL_CLGENERATORS_H