Nicolas Winkler 5 jaren geleden
bovenliggende
commit
80ee03a734
6 gewijzigde bestanden met toevoegingen van 40 en 261 verwijderingen
  1. 11 2
      benchmarkdialog.cpp
  2. 1 1
      libmandel/CMakeLists.txt
  3. 2 0
      libmandel/include/Mandel.h
  4. 21 3
      libmandel/include/Types.h
  5. 5 0
      libmandel/src/CpuGenerators.cpp
  6. 0 255
      libmandel/src/mandel.cpp

+ 11 - 2
benchmarkdialog.cpp

@@ -106,12 +106,16 @@ void Benchmarker::start(void)
     mnd::Generator& cpuf = mndContext.getCpuGeneratorFloat();
     mnd::Generator& cpud = mndContext.getCpuGeneratorDouble();
     mnd::Generator* cpu128 = mndContext.getCpuGeneratorQuad();
+    mnd::Generator* cpu256 = mndContext.getCpuGeneratorOct();
 
     double nTests = 2;
 
     if (cpu128)
         nTests++;
 
+    if (cpu256)
+        nTests++;
+
     auto& devices = mndContext.getDevices();
     for (size_t i = 0; i < devices.size(); i++) {
         if (mnd::Generator* gpuf; (gpuf = devices[i].getGeneratorFloat())) {
@@ -146,6 +150,11 @@ void Benchmarker::start(void)
         br.percentage += progress;
         emit update(br);
     }
+    if (cpu256) {
+        cpu.push_back(benchmarkResult(*cpu256));
+        br.percentage += progress;
+        emit update(br);
+    }
 
     for (size_t i = 0; i < devices.size(); i++) {
         br.values.push_back({});
@@ -181,9 +190,9 @@ BenchmarkDialog::BenchmarkDialog(mnd::MandelContext& mndContext, QWidget *parent
 
     auto& devices = mndContext.getDevices();
     int nDevices = devices.size() + 1;
-    ui.tableWidget->setColumnCount(3);
+    ui.tableWidget->setColumnCount(4);
     ui.tableWidget->setRowCount(nDevices);
-    ui.tableWidget->setHorizontalHeaderLabels({"Single Precision", "Double Precision", "Quad Precision"});
+    ui.tableWidget->setHorizontalHeaderLabels({"Single Precision", "Double Precision", "Quad Precision", "Oct Precision"});
 
     QString cpuDesc = ("CPU [" + mndContext.getCpuInfo().getBrand() + "]").c_str();
     ui.tableWidget->setVerticalHeaderItem(0, new QTableWidgetItem(cpuDesc));

+ 1 - 1
libmandel/CMakeLists.txt

@@ -31,7 +31,7 @@ SET(MandelSources
     src/ClGenerators.cpp
     src/CpuGenerators.cpp
     src/Generators.cpp
-    src/mandel.cpp
+    src/Mandel.cpp
     src/Hardware.cpp
     src/MandelUtil.cpp
 )

+ 2 - 0
libmandel/include/Mandel.h

@@ -61,6 +61,7 @@ private:
     std::unique_ptr<Generator> cpuGeneratorFloat;
     std::unique_ptr<Generator> cpuGeneratorDouble;
     std::unique_ptr<Generator> cpuGeneratorQuad;
+    std::unique_ptr<Generator> cpuGeneratorOct;
     //std::unique_ptr<Generator> cpuGenerator128;
     //std::unique_ptr<Generator> cpuGeneratorFixedp;
 
@@ -86,6 +87,7 @@ public:
     Generator& getCpuGeneratorFloat(void);
     Generator& getCpuGeneratorDouble(void); 
     Generator* getCpuGeneratorQuad(void); 
+    Generator* getCpuGeneratorOct(void); 
     //Generator& getCpuGenerator128(void); 
 
     const CpuInfo& getCpuInfo(void) const { return cpuInfo; }

+ 21 - 3
libmandel/include/Types.h

@@ -16,10 +16,14 @@ namespace mnd
 
 
 #ifdef WITH_BOOST
-#if defined(__GNUC__) || defined(__INTEL_COMPILER)
+#if 0//defined(__GNUC__) || defined(__INTEL_COMPILER)
     using Float128 = boost::multiprecision::float128;
 #else
-    using Float128 = boost::multiprecision::cpp_bin_float_quad;
+    //using Float128 = boost::multiprecision::cpp_bin_float_quad;
+    using Float128 = boost::multiprecision::number<
+        boost::multiprecision::backends::cpp_bin_float<
+            112, boost::multiprecision::backends::digit_base_2, void, boost::int16_t, -16382, 16383>,
+            boost::multiprecision::et_off>;
 #endif
     inline Float128 abs(const Float128& x) { return boost::multiprecision::abs(x); }
     inline Float128 floor(const Float128& x) { return boost::multiprecision::floor(x); }
@@ -27,8 +31,22 @@ namespace mnd
     inline Float128 log2(const Float128& x) { return boost::multiprecision::log2(x); }
     inline Float128 pow(const Float128& x, const Float128& y) { return boost::multiprecision::pow(x, y); }
 
+
+/*
+    using Float256 = boost::multiprecision::number<
+        boost::multiprecision::backends::cpp_bin_float<
+            240, boost::multiprecision::backends::digit_base_2, void, boost::int16_t, -16382, 16383>,
+            boost::multiprecision::et_off>;
+*/
+    using Float256 = long double;
+    /*inline Float256 abs(const Float256& x) { return boost::multiprecision::abs(x); }
+    inline Float256 floor(const Float256& x) { return boost::multiprecision::floor(x); }
+    inline Float256 log(const Float256& x) { return boost::multiprecision::log(x); }
+    inline Float256 log2(const Float256& x) { return boost::multiprecision::log2(x); }
+    inline Float256 pow(const Float256& x, const Float256& y) { return boost::multiprecision::pow(x, y); }
+*/
     using Real = Float128;
-    using Integer = boost::multiprecision::int128_t;
+    using Integer = boost::multiprecision::int256_t;
 #else
     using Real = double;
     using Integer = int64_t;

+ 5 - 0
libmandel/src/CpuGenerators.cpp

@@ -37,6 +37,11 @@ namespace mnd
     template class CpuGenerator<mnd::Float128, mnd::NONE, false, true>;
     template class CpuGenerator<mnd::Float128, mnd::NONE, true, false>;
     template class CpuGenerator<mnd::Float128, mnd::NONE, true, true>;
+
+    template class CpuGenerator<mnd::Float256, mnd::NONE, false, false>;
+    template class CpuGenerator<mnd::Float256, mnd::NONE, false, true>;
+    template class CpuGenerator<mnd::Float256, mnd::NONE, true, false>;
+    template class CpuGenerator<mnd::Float256, mnd::NONE, true, true>;
 #endif
 }
 

+ 0 - 255
libmandel/src/mandel.cpp

@@ -1,255 +0,0 @@
-#include "Mandel.h"
-#include "Fixed.h"
-
-#include "CpuGenerators.h"
-#include "ClGenerators.h"
-
-using mnd::MandelDevice;
-using mnd::MandelContext;
-using mnd::Generator;
-using mnd::AdaptiveGenerator;
-
-
-
-MandelContext mnd::initializeContext(void)
-{
-    MandelContext context = MandelContext();
-    return context;
-}
-
-
-MandelDevice::MandelDevice(void) :
-    floatGenerator{ nullptr },
-    doubleGenerator{ nullptr },
-    floatGeneratorSmooth{ nullptr },
-    doubleGeneratorSmooth{ nullptr }
-
-{
-}
-
-
-mnd::Generator* MandelDevice::getGeneratorFloat(bool smooth) const
-{
-    if (smooth)
-        return floatGeneratorSmooth.get();
-    else
-        return floatGenerator.get();
-}
-
-
-mnd::Generator* MandelDevice::getGeneratorDouble(bool smooth) const
-{
-    if (smooth)
-        return doubleGeneratorSmooth.get();
-    else
-        return doubleGenerator.get();
-}
-
-
-/*
-mnd::Generator* MandelDevice::getGeneratorQuad(bool smooth) const
-{
-    if (smooth)
-        return quadGeneratorSmooth.get();
-    else
-        return quadGenerator.get();
-}*/
-
-
-/*
-mnd::Generator* MandelDevice::getGenerator128(bool smooth) const
-{
-    if (smooth)
-        return generator128Smooth.get();
-    else
-        return generator128.get();
-}
-*/
-
-MandelContext::MandelContext(void) :
-    cpuGeneratorQuad{ nullptr },
-    cpuGeneratorQuadSmooth{ nullptr }
-{
-
-#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) 
-    if (cpuInfo.hasAvx()) {
-        cpuGeneratorFloat = std::make_unique<CpuGenerator<float, mnd::X86_AVX, true, false>>();
-        cpuGeneratorDouble = std::make_unique<CpuGenerator<double, mnd::X86_AVX, true, false>>();
-        cpuGeneratorFloatSmooth = std::make_unique<CpuGenerator<float, mnd::X86_AVX, true, true>>();
-        cpuGeneratorDoubleSmooth = std::make_unique<CpuGenerator<double, mnd::X86_AVX, true, true>>();
-    }
-    else if (cpuInfo.hasSse2()) {
-        cpuGeneratorFloat = std::make_unique<CpuGenerator<float, mnd::X86_SSE2, true, false>>();
-        cpuGeneratorDouble = std::make_unique<CpuGenerator<double, mnd::X86_SSE2, true, false>>();
-        cpuGeneratorFloatSmooth = std::make_unique<CpuGenerator<float, mnd::X86_SSE2, true, true>>();
-        cpuGeneratorDoubleSmooth = std::make_unique<CpuGenerator<double, mnd::X86_SSE2, true, true>>();
-    }
-    else
-#elif defined(__aarch64__)
-    if (true) {
-        cpuGeneratorFloat = std::make_unique<CpuGenerator<float, mnd::ARM_NEON, true, false>>();
-        cpuGeneratorDouble = std::make_unique<CpuGenerator<double, mnd::ARM_NEON, true, false>>();
-        cpuGeneratorFloatSmooth = std::make_unique<CpuGenerator<float, mnd::ARM_NEON>>();
-        cpuGeneratorDoubleSmooth = std::make_unique<CpuGenerator<double, mnd::ARM_NEON>>();
-    }
-    else
-#endif
-    {
-        cpuGeneratorFloat = std::make_unique<CpuGenerator<float, mnd::NONE, true, false>>();
-        cpuGeneratorDouble = std::make_unique<CpuGenerator<double, mnd::NONE, true, false>>();
-        cpuGeneratorFloatSmooth = std::make_unique<CpuGenerator<float, mnd::NONE, true, true>>();
-        cpuGeneratorDoubleSmooth = std::make_unique<CpuGenerator<double, mnd::NONE, true, true>>();
-    }
-
-    //cpuGenerator128 = std::make_unique<CpuGenerator<Fixed128, mnd::NONE, true, false>>();
-    //cpuGenerator128Smooth = std::make_unique<CpuGenerator<Fixed128>>();
-    //cpuGeneratorFixedp = std::make_unique<CpuGenerator<fixed<1, 3>>>();
-
-#ifdef WITH_BOOST
-    cpuGeneratorQuad = std::make_unique<CpuGenerator<Float128, mnd::NONE, true, false>>();
-    cpuGeneratorQuadSmooth = std::make_unique<CpuGenerator<Float128, mnd::NONE, true, true>>();
-#endif // WITH_BOOST
-
-    devices = createDevices();
-    if (devices.empty()) {
-#ifdef WITH_BOOST
-        adaptiveGenerator = std::make_unique<AdaptiveGenerator>(
-            cpuGeneratorFloat.get(), cpuGeneratorDouble.get(), cpuGeneratorQuad.get());
-        adaptiveGeneratorSmooth = std::make_unique<AdaptiveGenerator>(
-            cpuGeneratorFloatSmooth.get(), cpuGeneratorDoubleSmooth.get(),
-            cpuGeneratorQuadSmooth.get());
-#else
-        adaptiveGenerator = std::make_unique<AdaptiveGenerator>(
-            cpuGeneratorFloat.get(), cpuGeneratorDouble.get());
-        adaptiveGeneratorSmooth = std::make_unique<AdaptiveGenerator>(
-            cpuGeneratorFloatSmooth.get(), cpuGeneratorDoubleSmooth.get());
-#endif
-    }
-    else {
-        auto& device1 = devices[0];
-        Generator* floatGenerator = device1.getGeneratorFloat(false);
-        Generator* doubleGenerator = device1.getGeneratorDouble(false);
-        Generator* floatGeneratorSmooth = device1.getGeneratorFloat(true);
-        Generator* doubleGeneratorSmooth = device1.getGeneratorDouble(true);
-        if (floatGenerator == nullptr)
-            floatGenerator = cpuGeneratorFloat.get();
-        if (doubleGenerator == nullptr)
-            doubleGenerator = cpuGeneratorDouble.get();
-        if (floatGeneratorSmooth == nullptr)
-            floatGeneratorSmooth = cpuGeneratorFloatSmooth.get();
-        if (doubleGeneratorSmooth == nullptr)
-            doubleGeneratorSmooth = cpuGeneratorDoubleSmooth.get();
-#ifdef WITH_BOOST
-        adaptiveGeneratorSmooth = std::make_unique<AdaptiveGenerator>(floatGeneratorSmooth, doubleGeneratorSmooth, cpuGeneratorQuadSmooth.get());
-        adaptiveGenerator = std::make_unique<AdaptiveGenerator>(floatGenerator, doubleGenerator, cpuGeneratorQuad.get());
-#else
-        adaptiveGeneratorSmooth = std::make_unique<AdaptiveGenerator>(floatGeneratorSmooth, doubleGeneratorSmooth);
-        adaptiveGenerator = std::make_unique<AdaptiveGenerator>(floatGenerator, doubleGenerator);
-#endif
-    }
-}
-
-
-std::vector<MandelDevice> MandelContext::createDevices(void)
-{
-    std::vector<MandelDevice> mandelDevices;
-#ifdef WITH_OPENCL
-    std::vector<cl::Platform> platforms;
-    cl::Platform::get(&platforms);
-    //platforms.erase(platforms.begin() + 1);
-
-    for (auto& platform : platforms) {
-        std::string name = platform.getInfo<CL_PLATFORM_NAME>();
-        std::string profile = platform.getInfo<CL_PLATFORM_PROFILE>();
-
-        //std::string ext = platform.getInfo<CL_PLATFORM_EXTENSIONS>();
-        //printf("Platform extensions: %s\n", ext.c_str());
-        //printf("Platform: %s, %s\n", name.c_str(), profile.c_str());
-
-        std::vector<cl::Device> devices;
-        platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
-        for (auto& device : devices) {
-            //printf("Device: %s\n", device.getInfo<CL_DEVICE_NAME>().c_str());
-            //printf("preferred float width: %d\n", device.getInfo<CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT>());
-            //printf("vendor: %s\n", device.getInfo<CL_DEVICE_VENDOR>().c_str());
-
-            std::string extensions = device.getInfo<CL_DEVICE_EXTENSIONS>();
-            auto supportsDouble = extensions.find("cl_khr_fp64") != std::string::npos;
-
-            //printf("Device extensions: %s\n", ext.c_str());
-            MandelDevice md;
-
-            //printf("clock: %d", device.getInfo<CL_DEVICE_MAX_CLOCK_FREQUENCY>());
-
-            md.name = device.getInfo<CL_DEVICE_NAME>();
-            md.vendor = device.getInfo<CL_DEVICE_VENDOR>();
-            try {
-                md.floatGenerator = std::make_unique<ClGeneratorFloat>(device, false);
-                md.floatGeneratorSmooth = std::make_unique<ClGeneratorFloat>(device, true);
-            }
-            catch (const std::string& err) {
-                printf("err: %s", err.c_str());
-            }
-
-            if (supportsDouble) {
-                try {
-                    md.doubleGenerator = std::make_unique<ClGeneratorDouble>(device, false);
-                    md.doubleGeneratorSmooth = std::make_unique<ClGeneratorDouble>(device, true);
-                }
-                catch (const std::string& err) {
-                }
-            }
-
-            try {
-                //md.generator128 = std::make_unique<ClGenerator128>(device);
-            }
-            catch (const std::string& err) {
-                //fprintf(stderr, "error creating 128bit cl generator: %s\n", err.c_str());
-            }
-
-            mandelDevices.push_back(std::move(md));
-        }
-    }
-#endif // WITH_OPENCL
-    
-    return mandelDevices;
-}
-
-
-const std::string& MandelDevice::getName(void) const
-{
-    return name;
-}
-
-
-Generator& MandelContext::getDefaultGenerator(bool smooth)
-{
-    if (smooth)
-        return *adaptiveGeneratorSmooth;
-    else
-        return *adaptiveGenerator;
-}
-
-
-const std::vector<MandelDevice>& MandelContext::getDevices(void)
-{
-    return devices;
-}
-
-
-Generator& MandelContext::getCpuGeneratorFloat(void)
-{
-    return *cpuGeneratorFloat;
-}
-
-
-Generator& MandelContext::getCpuGeneratorDouble(void)
-{
-    return *cpuGeneratorDouble;
-}
-
-
-Generator* MandelContext::getCpuGeneratorQuad(void)
-{
-    return cpuGeneratorQuad.get();
-}