Nicolas Winkler il y a 5 ans
Parent
commit
896e35089e

+ 5 - 3
libmandel/include/ClGenerators.h

@@ -13,6 +13,8 @@
 
 namespace mnd
 {
+    class MandelDevice;
+
     class ClGenerator;
     class ClGeneratorFloat;
     class ClGeneratorDoubleFloat;
@@ -27,13 +29,13 @@ namespace mnd
 class mnd::ClGenerator : public MandelGenerator
 {
 protected:
-    cl::Device device;
-    cl::Context context;
+    const MandelDevice& device;
+    cl::Context& context;
     cl::Program program;
     cl::CommandQueue queue;
     cl::Kernel kernel;
 public:
-    ClGenerator(cl::Device device, const std::string& source, const mnd::Real& precision);
+    ClGenerator(const MandelDevice& device, const std::string& source, const mnd::Real& precision);
     virtual ~ClGenerator(void);
 
     virtual void generate(const MandelInfo& info, float* data) = 0;

+ 10 - 4
libmandel/include/IterationGenerator.h

@@ -14,6 +14,8 @@ namespace mnd
     class IterationGenerator;
 
     class NaiveGenerator;
+
+    template<typename T>
     class NaiveIRGenerator;
     class CompiledGenerator;
     class CompiledClGenerator;
@@ -47,6 +49,7 @@ private:
 };
 
 
+template<typename T>
 class mnd::NaiveIRGenerator : public mnd::MandelGenerator
 {
     const ir::Formula& form;
@@ -80,12 +83,15 @@ class mnd::CompiledClGenerator : public mnd::ClGeneratorFloat
 public:
     CompiledClGenerator(const MandelDevice& device, const std::string& code);
     CompiledClGenerator(CompiledClGenerator&&) = default;
-    //virtual ~CompiledGenerator(void);
-    //virtual void generate(const MandelInfo& info, float* data);
-    virtual std::string getKernelCode(bool smooth) const override;
     virtual void generate(const MandelInfo& info, float* data);
+};
 
-    //std::string dump(void) const;
+class mnd::CompiledClGeneratorDouble : public mnd::ClGeneratorDouble
+{
+public:
+    CompiledClGeneratorDouble(const MandelDevice& device, const std::string& code);
+    CompiledClGenerator(CompiledClGenerator&&) = default;
+    virtual void generate(const MandelInfo& info, float* data);
 };
 #endif // WITH_OPENCL
 

+ 1 - 0
libmandel/include/OpenClInternal.h

@@ -14,6 +14,7 @@ namespace mnd
     {
 #ifdef WITH_OPENCL
         cl::Device device;
+        cl::Context context;
 #endif
     };
 }

+ 5 - 3
libmandel/src/ClGenerators.cpp

@@ -1,4 +1,6 @@
 #include "ClGenerators.h"
+#include "Mandel.h"
+#include "OpenClInternal.h"
 #include "OpenClCode.h"
 
 #ifdef WITH_OPENCL
@@ -59,11 +61,11 @@ Device getDevice(Platform& platform, int i, bool display = false) {
 }
 
 
-ClGenerator::ClGenerator(cl::Device device, const std::string& source, const mnd::Real& precision) :
+ClGenerator::ClGenerator(const MandelDevice& device, const std::string& source, const mnd::Real& precision) :
     MandelGenerator{ precision },
-    device{ device }
+    device{ device },
+    context{ device.getClDevice().context }
 {
-    context = Context{ device };
     Program::Sources sources;
 
     sources.push_back({ source.c_str(), source.length() });

+ 15 - 8
libmandel/src/IterationGenerator.cpp

@@ -13,6 +13,15 @@ using mnd::NaiveIRGenerator;
 using mnd::IterationFormula;
 
 
+namespace mnd
+{
+    template class NaiveIRGenerator<float>;
+    template class NaiveIRGenerator<double>;
+    template class NaiveIRGenerator<mnd::DoubleDouble>;
+    template class NaiveIRGenerator<mnd::QuadDouble>;
+}
+
+
 IterationGenerator::IterationGenerator(IterationFormula z0, IterationFormula zi,
                                    const mnd::Real& prec) :
     mnd::MandelGenerator{ prec },
@@ -125,7 +134,8 @@ std::complex<double> NaiveGenerator::calc(mnd::Expression& expr, std::complex<do
 }
 
 
-NaiveIRGenerator::NaiveIRGenerator(const mnd::ir::Formula& irf,
+template<typename T>
+NaiveIRGenerator<T>::NaiveIRGenerator(const mnd::ir::Formula& irf,
                                    const mnd::Real& prec) :
     mnd::MandelGenerator{ prec },
     form{ irf }
@@ -133,7 +143,8 @@ NaiveIRGenerator::NaiveIRGenerator(const mnd::ir::Formula& irf,
 }
 
 
-void NaiveIRGenerator::generate(const mnd::MandelInfo& info, float* data)
+template<typename T>
+void NaiveIRGenerator<T>::generate(const mnd::MandelInfo& info, float* data)
 {
     const MandelViewport& view = info.view;
 
@@ -171,7 +182,8 @@ void NaiveIRGenerator::generate(const mnd::MandelInfo& info, float* data)
 }
 
 
-double NaiveIRGenerator::calc(mnd::ir::Node* expr, double a, double b, double x, double y)
+template<typename T>
+double NaiveIRGenerator<T>::calc(mnd::ir::Node* expr, double a, double b, double x, double y)
 {
     struct DoubleVisitor
     {
@@ -322,11 +334,6 @@ CompiledClGenerator::CompiledClGenerator(const mnd::MandelDevice& device, const
 }
 
 
-std::string CompiledClGenerator::getKernelCode(bool smooth) const
-{
-    return "";
-}
-
 void CompiledClGenerator::generate(const mnd::MandelInfo& info, float* data)
 {
     ::size_t bufferSize = info.bWidth * info.bHeight * sizeof(float);