[opengtl-commits] [373] add a native reference implementation

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 373
Author:   cyrille
Date:     2008-09-07 10:33:18 +0200 (Sun, 07 Sep 2008)

Log Message:
-----------
add a native reference implementation

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/tools/benchmark/CtlBenchmark.cpp


Modified: trunk/OpenGTL/OpenCTL/tools/benchmark/CtlBenchmark.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/tools/benchmark/CtlBenchmark.cpp	2008-09-07 08:17:51 UTC (rev 372)
+++ trunk/OpenGTL/OpenCTL/tools/benchmark/CtlBenchmark.cpp	2008-09-07 08:33:18 UTC (rev 373)
@@ -84,6 +84,7 @@
           m0 * (s*s*s - 2 * s*s + s) +
           table[i+1].y() * (-2 * s*s*s + 3 * s*s) +
           m1 * (s*s*s - s*s);
+
     }
   }
   return 0.0;
@@ -107,7 +108,7 @@
 
 class Benchmark {
   public:
-    Benchmark(int runCount, GTLCore::Array* array ) : m_array(array), m_runCount(runCount)  {}
+    Benchmark(int runCount ) : m_runCount(runCount)  {}
     void start()
     {
       initialise();
@@ -150,26 +151,53 @@
   protected:
     virtual void initialise() = 0;
     virtual void run() = 0;
-    GTLCore::Array* array() { return m_array; }
   private:
-    GTLCore::Array* m_array;
     int m_runCount;
     int m_totalTime;
     int m_bestTime;
     int m_worseTime;
 };
 
+class NativeBenchmark : public Benchmark {
+  public:
+    NativeBenchmark( const std::vector< PointF >& _points, int runCount, GTLCore::Array* array ) : Benchmark( runCount), points(_points), m_array(array)
+    {
+      
+    }
+  protected:
+    virtual void initialise() {}
+    virtual void run();
+  private:
+     std::vector< PointF > points;
+    GTLCore::Array* m_array;
+};
+
+void NativeBenchmark::run()
+{
+  GTLCore::PixelDescription pd( GTLCore::Type::Float, 4);
+  float* arr = m_array->data<float>();
+  for( int i = 0; i < m_array->size(); i += pd.bitsSize())
+  {
+    arr[0] = interpolateCubic1D( points, arr[0] );
+    arr[1] = interpolateCubic1D( points, arr[1] );
+    arr[2] = interpolateCubic1D( points, arr[2] );
+    arr[3] = arr[3];
+  }
+}
+
 class CtlBenchmark : public Benchmark {
   protected:
-    CtlBenchmark(int _level, const std::vector< PointF >& _points, int runCount, GTLCore::Array* array ) : Benchmark(runCount, array ), points(_points), program(0) {}
+    CtlBenchmark(int _level, const std::vector< PointF >& _points, int runCount, GTLCore::Array* array ) : Benchmark(runCount ), points(_points), program(0), m_array(array) {}
     GTLCore::String sourceCode() const;
     void compile();
     void apply();
+    GTLCore::Array* array() { return m_array; }
   private:
      GTLCore::String valueListToCTL( const std::vector<PointF>& _points, double _scale ) const;
      std::vector< PointF > points;
      OpenCTL::Program* program;
      int m_level;
+    GTLCore::Array* m_array;
 };
 
 void CtlBenchmark::compile()
@@ -279,6 +307,13 @@
   GTLCore::PixelDescription pd( GTLCore::Type::Float, 4);
   GTLCore::Array array( 1000000 * pd.bitsSize() / 8 );
   
+  {
+    std::cout << "Native" << std::endl;
+    NativeBenchmark benchmark( points, 100, &array );
+    benchmark.start();
+    benchmark.dump();
+  }
+  
   for(int level = 0; level <= GTLCore::Optimiser::maximumRecommendedLevel(); ++level)
   {
     std::cout << "Compile once = " << level << std::endl;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/