Nicolas Winkler 5 tahun lalu
induk
melakukan
d340bc93b1

+ 10 - 4
choosegenerators.cpp

@@ -199,7 +199,7 @@ ChooseGenerators::ChooseGenerators(mnd::MandelContext& mndCtxt, QWidget *parent)
                 comboBox->setCurrentText(n);
             }
         }
-        le->setText(QString::number(static_cast<double>(prec)));
+        le->setText(QString::fromStdString(mnd::toLegibleString(prec)));
         comboBox->adjustSize();
         le->adjustSize();
     }
@@ -210,8 +210,11 @@ ChooseGenerators::ChooseGenerators(mnd::MandelContext& mndCtxt, QWidget *parent)
         int rowCount = ui->generatorTable->rowCount();
         ui->generatorTable->insertRow(rowCount);
         ui->generatorTable->setItem(rowCount, 0, new QTableWidgetItem);
+        ui->generatorTable->setItem(rowCount, 1, new QTableWidgetItem);
         const std::string& genName = mnd::getGeneratorName(generatorTypes[i]);
+        const mnd::Real& prec = mndCtxt.getCpuGenerator(generatorTypes[i])->getPrecision();
         ui->generatorTable->item(rowCount, 0)->setText(QString::fromStdString(genName));
+        ui->generatorTable->item(rowCount, 1)->setText(QString::fromStdString(mnd::toLegibleString(prec)));
         actualGenerators.push_back(mndCtxt.getCpuGenerator(generatorTypes[i]));
     }
 
@@ -221,8 +224,11 @@ ChooseGenerators::ChooseGenerators(mnd::MandelContext& mndCtxt, QWidget *parent)
             int rowCount = ui->generatorTable->rowCount();
             ui->generatorTable->insertRow(rowCount);
             ui->generatorTable->setItem(rowCount, 0, new QTableWidgetItem);
+            ui->generatorTable->setItem(rowCount, 1, new QTableWidgetItem);
             const std::string& genName = mnd::getGeneratorName(generatorTypes[i]) + " [" + device.getName() + "]";
+            const mnd::Real& prec = device.getGenerator(generatorTypes[i])->getPrecision();
             ui->generatorTable->item(rowCount, 0)->setText(QString::fromStdString(genName));
+            ui->generatorTable->item(rowCount, 1)->setText(QString::fromStdString(mnd::toLegibleString(prec)));
             actualGenerators.push_back(device.getGenerator(generatorTypes[i]));
         }
     }
@@ -260,8 +266,8 @@ QLineEdit* ChooseGenerators::createFloatText(void)
 
 void ChooseGenerators::setBenchmarkResult(int row, float percentage, double result)
 {
-    this->ui->generatorTable->setItem(row, 1, new QTableWidgetItem);
-    this->ui->generatorTable->item(row, 1)->setText(QString::number(result));
+    this->ui->generatorTable->setItem(row, 2, new QTableWidgetItem);
+    this->ui->generatorTable->item(row, 2)->setText(QString::number(result));
     ui->progressBar->setValue(int(percentage * 10.0f));
 }
 
@@ -305,7 +311,7 @@ void ChooseGenerators::on_run_clicked()
 
 void ChooseGenerators::on_generatorTable_cellDoubleClicked(int row, int column)
 {
-    if (column == 1) {
+    if (column == 2) {
         QMessageBox msgBox{ this };
         msgBox.setText("Would you like to benchmark this generator?");
         msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);

+ 11 - 3
choosegenerators.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>976</width>
-    <height>493</height>
+    <width>1167</width>
+    <height>663</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -35,11 +35,14 @@
             <bool>true</bool>
            </property>
            <attribute name="horizontalHeaderDefaultSectionSize">
-            <number>200</number>
+            <number>180</number>
            </attribute>
            <attribute name="horizontalHeaderMinimumSectionSize">
             <number>100</number>
            </attribute>
+           <attribute name="horizontalHeaderStretchLastSection">
+            <bool>false</bool>
+           </attribute>
            <attribute name="verticalHeaderVisible">
             <bool>false</bool>
            </attribute>
@@ -50,6 +53,11 @@
            </column>
            <column>
             <property name="text">
+             <string>Precision</string>
+            </property>
+           </column>
+           <column>
+            <property name="text">
              <string>Performance</string>
             </property>
            </column>

+ 3 - 3
libmandel/include/OpenClCode.h

@@ -3,9 +3,9 @@
 
 namespace mnd
 {
-    unsigned char* fixed64_cl;
-    unsigned char* fixed128_cl;
-    unsigned char* fixed512_cl;
+    const char* getFixed64_cl();
+    const char* getFixed128_cl();
+    const char* getFixed512_cl();
 }
 
 #endif // MANDEL_OPENCLCODE_H

+ 1 - 0
libmandel/include/Types.h

@@ -155,6 +155,7 @@ namespace mnd
 #endif
 
     std::string toString(const Real& num);
+    std::string toLegibleString(const Real& num);
 
 
 /*

+ 8 - 8
libmandel/src/ClGenerators.cpp

@@ -120,7 +120,7 @@ void ClGenerator::generate(const mnd::MandelInfo& info, float* data)
 
 
 ClGeneratorFloat::ClGeneratorFloat(cl::Device device) :
-    ClGenerator{ device, mnd::getPrecision(mnd::Precision::FLOAT) }
+    ClGenerator{ device, mnd::getPrecision<float>() }
 {
     context = Context{ device };
     Program::Sources sources;
@@ -344,7 +344,7 @@ std::string ClGeneratorDoubleFloat::getKernelCode(bool smooth) const
 
 
 ClGeneratorDouble::ClGeneratorDouble(cl::Device device) :
-    ClGenerator{ device, mnd::getPrecision(mnd::Precision::DOUBLE) }
+    ClGenerator{ device, mnd::getPrecision<double>() }
 {
     context = Context{ device };
     Program::Sources sources;
@@ -422,7 +422,7 @@ std::string ClGeneratorDouble::getKernelCode(bool smooth) const
 
 
 ClGeneratorDoubleDouble::ClGeneratorDoubleDouble(cl::Device device) :
-    ClGenerator{ device, mnd::getPrecision(mnd::Precision::DOUBLE_DOUBLE) }
+    ClGenerator{ device, mnd::getPrecision<DoubleDouble>() }
 {
     context = Context{ device };
     Program::Sources sources;
@@ -478,7 +478,7 @@ std::string ClGeneratorDoubleDouble::getKernelCode(bool smooth) const
 
 
 ClGeneratorQuadDouble::ClGeneratorQuadDouble(cl::Device device) :
-    ClGenerator{ device, mnd::getPrecision(mnd::Precision::QUAD_DOUBLE) }
+    ClGenerator{ device, mnd::getPrecision<QuadDouble>() }
 {
     context = Context{ device };
     Program::Sources sources;
@@ -535,7 +535,7 @@ std::string ClGeneratorQuadDouble::getKernelCode(bool smooth) const
 
 
 ClGenerator128::ClGenerator128(cl::Device device) :
-    ClGenerator{ device, mnd::getPrecision(mnd::Precision::FIXED128) }
+    ClGenerator{ device, mnd::getPrecision<Fixed128>() }
 {
     context = Context{ device };
     Program::Sources sources;
@@ -598,12 +598,12 @@ std::string ClGenerator128::getKernelCode(bool smooth) const
         std::istreambuf_iterator<char>());
     //fprintf(stderr, "%s\n", str);
     return str;*/
-    return (char*) fixed512_cl;
+    return getFixed512_cl();
 }
 
 
 ClGenerator64::ClGenerator64(cl::Device device) :
-    ClGenerator{ device, mnd::getPrecision(mnd::Precision::FIXED64) }
+    ClGenerator{ device, mnd::getPrecision<Fixed64>() }
 {
     context = Context{ device };
     Program::Sources sources;
@@ -663,7 +663,7 @@ std::string ClGenerator64::getKernelCode(bool smooth) const
     std::istreambuf_iterator<char>());
     //fprintf(stderr, "%s\n", str);
     return str;*/
-    return (char*) fixed64_cl;
+    return getFixed64_cl();
 }
 
 #endif // WITH_OPENCL

+ 1 - 0
libmandel/src/Generators.cpp

@@ -96,6 +96,7 @@ namespace mnd
     {
         static const std::map<Precision, Real> precs {
             { Precision::FLOAT, getPrecision<float>() },
+            { Precision::DOUBLE_FLOAT, Real("1.0e-13") },
             { Precision::DOUBLE, getPrecision<double>() },
             { Precision::DOUBLE_DOUBLE, Real("1.0e-29") },
             { Precision::QUAD_DOUBLE, Real("1.0e-56") },

+ 16 - 3
libmandel/src/OpenClCode.cpp

@@ -1,9 +1,22 @@
+#include "OpenClCode.h"
+
+#include "opencl/fixed64.h"
+#include "opencl/fixed128.h"
+#include "opencl/fixed512.h"
 
 namespace mnd
 {
-#   include "opencl/fixed64.h"
-#   include "opencl/fixed128.h"
-#   include "opencl/fixed512.h"
+    const char* getFixed64_cl() {
+        return (char*) fixed64_cl;
+    }
+
+    const char* getFixed128_cl() {
+        return (char*) fixed128_cl;
+    }
+
+    const char* getFixed512_cl() {
+        return (char*) fixed512_cl;
+    }
 }
 
 

+ 17 - 0
libmandel/src/Types.cpp

@@ -9,6 +9,23 @@ namespace mnd
     {
         return num.str();
     }
+
+    std::string toLegibleString(const Real& num)
+    {
+        if (num == Real(0.0)) {
+            return "0";
+        }
+        int exponent = std::floor(static_cast<float>(mnd::log(num)) / ::logf(10.0));
+        float fac = static_cast<float>(num / mnd::pow(Real(10), Real(exponent)));
+        std::stringstream ss;
+        ss.precision(3);
+        ss << std::fixed << fac << "e";
+        if (exponent < 0)
+            ss << "-" << -exponent;
+        else
+            ss << "+" << exponent;
+        return ss.str();
+    }
 #else // !WITH_BOOST
     std::string toString(const Real& num)
     {