ClGenerators.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 ClGeneratorDouble;
  29. class ClGeneratorDoubleDouble;
  30. class ClGeneratorTripleDouble;
  31. class ClGeneratorQuadDouble;
  32. class ClGeneratorHexDouble;
  33. class ClGenerator128;
  34. class ClGenerator64;
  35. }
  36. class mnd::ClGenerator : public MandelGenerator
  37. {
  38. protected:
  39. MandelDevice& device;
  40. cl::Context& context;
  41. cl::Program program;
  42. cl::CommandQueue queue;
  43. cl::Kernel kernel;
  44. public:
  45. ClGenerator(MandelDevice& device, const std::string& source, mnd::Precision type);
  46. virtual ~ClGenerator(void);
  47. virtual void generate(const MandelInfo& info, float* data) = 0;
  48. virtual mnd::MandelDevice* getDevice(void);
  49. };
  50. class mnd::ClGeneratorFloat : public ClGenerator
  51. {
  52. bool useVec;
  53. public:
  54. ClGeneratorFloat(MandelDevice& device, const std::string& code = getFloat_cl());
  55. virtual ~ClGeneratorFloat(void) = default;
  56. virtual void generate(const MandelInfo& info, float* data) override;
  57. protected:
  58. virtual std::string getKernelCode(bool smooth) const;
  59. };
  60. class mnd::ClGeneratorDoubleFloat : public ClGenerator
  61. {
  62. public:
  63. ClGeneratorDoubleFloat(MandelDevice& device);
  64. virtual ~ClGeneratorDoubleFloat(void) = default;
  65. virtual void generate(const MandelInfo& info, float* data) override;
  66. protected:
  67. virtual std::string getKernelCode(bool smooth) const;
  68. };
  69. class mnd::ClGeneratorDouble : public ClGenerator
  70. {
  71. public:
  72. ClGeneratorDouble(mnd::MandelDevice& device, const std::string& source = getDouble_cl());
  73. virtual ~ClGeneratorDouble(void) = default;
  74. virtual void generate(const MandelInfo& info, float* data) override;
  75. protected:
  76. virtual std::string getKernelCode(bool smooth) const;
  77. };
  78. class mnd::ClGeneratorDoubleDouble : public ClGenerator
  79. {
  80. bool smooth;
  81. public:
  82. ClGeneratorDoubleDouble(mnd::MandelDevice& device);
  83. virtual ~ClGeneratorDoubleDouble(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::ClGeneratorTripleDouble : public ClGenerator
  89. {
  90. bool smooth;
  91. public:
  92. ClGeneratorTripleDouble(mnd::MandelDevice& device);
  93. virtual ~ClGeneratorTripleDouble(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::ClGeneratorQuadDouble : public ClGenerator
  99. {
  100. bool smooth;
  101. public:
  102. ClGeneratorQuadDouble(mnd::MandelDevice& device);
  103. virtual ~ClGeneratorQuadDouble(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::ClGeneratorHexDouble : public ClGenerator
  109. {
  110. bool smooth;
  111. public:
  112. ClGeneratorHexDouble(mnd::MandelDevice& device);
  113. virtual ~ClGeneratorHexDouble(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::ClGenerator128 : public ClGenerator
  119. {
  120. public:
  121. ClGenerator128(mnd::MandelDevice& device);
  122. virtual ~ClGenerator128(void) = default;
  123. virtual void generate(const MandelInfo& info, float* data) override;
  124. protected:
  125. virtual std::string getKernelCode(bool smooth) const;
  126. };
  127. class mnd::ClGenerator64 : public ClGenerator
  128. {
  129. public:
  130. ClGenerator64(mnd::MandelDevice& device);
  131. virtual ~ClGenerator64(void) = default;
  132. virtual void generate(const MandelInfo& info, float* data) override;
  133. protected:
  134. virtual std::string getKernelCode(bool smooth) const;
  135. };
  136. #endif // WITH_OPENCL
  137. #endif // MANDEL_CLGENERATORS_H