Przeglądaj źródła

improving commandline version

Nicolas Winkler 4 lat temu
rodzic
commit
52b1f250d0

+ 1 - 0
libmandel/CMakeLists.txt

@@ -47,6 +47,7 @@ SET(MandelSources
     src/IterationIR.cpp
     src/NaiveIRGenerator.cpp
     src/FloatLog.cpp
+    src/Benchmark.cpp
 )
 FILE(GLOB MandelHeaders include/*.h)
 

+ 15 - 0
mandelvid/include/Util.h

@@ -0,0 +1,15 @@
+#pragma once
+#ifndef MANDELVID_UTIL_H
+#define MANDELVID_UTIL_H
+
+#include <vector>
+#include <string>
+
+using Table = std::vector<std::vector<std::string>>;
+
+
+void printTable(const Table& t);
+
+
+#endif // MANDELVID_UTIL_H
+

+ 3 - 0
mandelvid/include/run.h

@@ -3,8 +3,11 @@
 #define MANDELVID_RUN_H
 
 #include <string>
+#include "Mandel.h"
 
 
+void listGenerators(mnd::MandelContext& context);
+void benchGenerators(mnd::MandelContext& context);
 void renderImage(const std::string& xmlPath, const std::string& outPath);
 
 

+ 25 - 0
mandelvid/src/Util.cpp

@@ -0,0 +1,25 @@
+#include "Util.h"
+
+#include <map>
+#include <iostream>
+#include <iomanip>
+
+
+void printTable(const Table& t)
+{
+    std::map<size_t, size_t> maxLenghts;
+
+    for (const auto& arr : t) {
+        for (int i = 0; i < arr.size(); i++) {
+            if (arr[i].size() > maxLenghts[i])
+                maxLenghts[i] = arr[i].size();
+        }
+    }
+
+    for (const auto& arr : t) {
+        for (int i = 0; i < arr.size(); i++) {
+            std::cout << std::setw(maxLenghts[i] + 3) << std::left << arr[i];
+        }
+        std::cout << std::endl;
+    }
+}

+ 12 - 1
mandelvid/src/main.cpp

@@ -15,6 +15,8 @@ int main(int argc, char** argv)
     boost::optional<std::string> outPath;
     desc.add_options()
         ("help", "display this help message")
+        ("list-generators", "list all available generators on this machine")
+        ("benchmark-generators", "benchmark all available generators on this machine")
         ("render-image,i", "render a mandelbrot view")
         ("file,f", progOpts::value(&inPath), "specifies a file to load")
         ("output,o", progOpts::value(&outPath), "file to output")
@@ -32,7 +34,16 @@ int main(int argc, char** argv)
         return 0;
     }
 
-    if (vm.count("render-image")) {
+
+    if (vm.count("list-generators")) {
+        mnd::MandelContext mndCtxt = mnd::initializeContext();
+        listGenerators(mndCtxt);
+    }
+    else if (vm.count("benchmark-generators")) {
+        mnd::MandelContext mndCtxt = mnd::initializeContext();
+        benchGenerators(mndCtxt);
+    }
+    else if (vm.count("render-image")) {
         if (!inPath) {
             std::cout << "Please specify a path" << std::endl;
             return 1;

+ 59 - 1
mandelvid/src/run.cpp

@@ -1,12 +1,70 @@
 #include "run.h"
 
-#include "Mandel.h"
+#include "Util.h"
 
 #include "Serialize.h"
 #include "ImageExport.h"
 
+#include "Benchmark.h"
+
 #include <fstream>
 #include <iostream>
+#include <map>
+
+
+
+void listGenerators(mnd::MandelContext& context)
+{
+    Table table;
+    for (const auto& [type, extension] : context.getSupportedTypes()) {
+        table.push_back({ context.getCpuInfo().getBrand(), mnd::toString(type), mnd::toString(extension), mnd::toLegibleString(mnd::getPrecision(type)) });
+    }
+
+    for (auto& device : context.getDevices()) {
+        for (const auto& type : device->getSupportedTypes()) {
+            table.push_back({ device->getName(), mnd::toString(type), "", mnd::toLegibleString(mnd::getPrecision(type)) });
+        }
+    }
+
+    printTable(table);
+}
+
+void benchGenerators(mnd::MandelContext& context)
+{
+    Table table;
+    std::map<size_t, mnd::MandelGenerator*> generators;
+    for (const auto& [type, extension] : context.getSupportedTypes()) {
+        generators[table.size()] = context.getCpuGenerator(type, extension);
+        table.push_back({ context.getCpuInfo().getBrand(), mnd::toString(type), mnd::toString(extension), mnd::toLegibleString(mnd::getPrecision(type)) });
+    }
+
+    for (auto& device : context.getDevices()) {
+        for (const auto& type : device->getSupportedTypes()) {
+            generators[table.size()] = device->getGenerator(type);
+            table.push_back({ device->getName(), mnd::toString(type), "", mnd::toLegibleString(mnd::getPrecision(type)) });
+        }
+    }
+
+    std::map<size_t, size_t> maxLenghts;
+
+    for (const auto& arr : table) {
+        for (int i = 0; i < arr.size(); i++) {
+            if (arr[i].size() > maxLenghts[i])
+                maxLenghts[i] = arr[i].size();
+        }
+    }
+
+    for (int i = 0; i < table.size(); i++) {
+        const auto& arr = table[i];
+        for (int i = 0; i < arr.size(); i++) {
+            std::cout << std::setw(maxLenghts[i] + 3) << std::left << arr[i];
+        }
+        double iterPerNanos = mnd::benchmark(*generators[i]);
+        std::cout << std::fixed << std::setprecision(2) << (iterPerNanos * 1000);
+        std::cout << std::endl;
+    }
+}
+
 
 std::string readFile(const std::string& path)
 {

+ 6 - 2
src/choosegenerators.cpp

@@ -1,6 +1,9 @@
 #include "choosegenerators.h"
 #include "ui_choosegenerators.h"
 
+
+#include "Benchmark.h"
+
 #include "Almond.h"
 
 #include <Hardware.h>
@@ -108,7 +111,8 @@ std::pair<long long, std::chrono::nanoseconds> Benchmarker::measureMips(
 
 double Benchmarker::benchmarkResult(mnd::MandelGenerator& mg) const
 {
-    size_t testIndex = 0;
+    return mnd::benchmark(mg) * 1000;
+    /*size_t testIndex = 0;
 
     for (size_t i = 0; i < benches.size(); i++) {
         const mnd::MandelInfo& mi = benches[i];
@@ -151,7 +155,7 @@ double Benchmarker::benchmarkResult(mnd::MandelGenerator& mg) const
     catch(...) {
         printf("error benchmarking\n");
     }
-    return 0;
+    return 0;*/
 }