[mlpack-svn] r15380 - in mlpack/conf/jenkins-conf/benchmark: . benchmark

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Jul 2 06:44:29 EDT 2013


Author: marcus
Date: Tue Jul  2 06:44:29 2013
New Revision: 15380

Log:
Add Makfile to run the different scripts and restructure files.

Added:
   mlpack/conf/jenkins-conf/benchmark/Makefile
   mlpack/conf/jenkins-conf/benchmark/benchmark/
   mlpack/conf/jenkins-conf/benchmark/benchmark/memory_benchmark.py
   mlpack/conf/jenkins-conf/benchmark/benchmark/run_benchmark.py
   mlpack/conf/jenkins-conf/benchmark/benchmark/test_config.py
Removed:
   mlpack/conf/jenkins-conf/benchmark/benchmark.py

Added: mlpack/conf/jenkins-conf/benchmark/Makefile
==============================================================================
--- (empty file)
+++ mlpack/conf/jenkins-conf/benchmark/Makefile	Tue Jul  2 06:44:29 2013
@@ -0,0 +1,33 @@
+PYTHON_BIN := $(shell which python)
+PYTHON_VERSION := $(shell expr `$(PYTHON_BIN) -c 'import sys; print sys.version[:3]'` \>= 2.7)
+
+CONFIG := config.yaml
+BENCHMARKDDIR := benchmark
+
+ifeq ($(PYTHON_VERSION), 0)
+  $(error Python version 2.7 required which was not found.)
+endif
+
+.PHONY: help test run memory
+
+help:
+	@echo "Usage: make [option] [CONFIG=..]"
+	@echo "options:"
+	@echo "  help               Show this info."
+	@echo "  test [CONFIG]      Test the configuration file. Check for correct"
+	@echo "                     syntax and then try to open files referred in the"
+	@echo "                     configuration. Default ''."
+	@echo "  run [CONFIG]       Perform the benchmark with the given config."
+	@echo "                     Default '$(CONFIG)'."
+	@echo "  memory [CONFIG]    Get memory profiling information with the given "
+	@echo "                     config. Default '$(CONFIG)'."
+
+test:
+	$(PYTHON_BIN) $(BENCHMARKDDIR)/test_config.py -c $(CONFIG)
+
+run:
+	$(PYTHON_BIN) $(BENCHMARKDDIR)/run_benchmark.py -c $(CONFIG)
+
+memory:
+	$(PYTHON_BIN) $(BENCHMARKDDIR)/memory_benchmark.py -c $(CONFIG)
+	
\ No newline at end of file

Added: mlpack/conf/jenkins-conf/benchmark/benchmark/memory_benchmark.py
==============================================================================
--- (empty file)
+++ mlpack/conf/jenkins-conf/benchmark/benchmark/memory_benchmark.py	Tue Jul  2 06:44:29 2013
@@ -0,0 +1,100 @@
+'''
+  @file memory_benchmark.py
+  @author Marcus Edel
+
+  Perform the memory benchmark.
+'''
+
+
+import os, sys, inspect
+
+# Import the util path, this method even works if the path contains
+# symlinks to modules.
+cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
+  os.path.split(inspect.getfile(inspect.currentframe()))[0], '../util')))
+if cmd_subfolder not in sys.path:
+  sys.path.insert(0, cmd_subfolder)
+
+from log import *
+from system import *
+from loader import * 
+from parser import *
+
+import argparse
+
+'''
+Show system informations. Are there no data available, the value is 'N/A'.
+'''
+def SystemInformation():
+  
+  Log.Info('CPU Model: ' + SystemInfo.GetCPUModel())
+  Log.Info('Distribution: ' + SystemInfo.GetDistribution())
+  Log.Info('Platform: ' + SystemInfo.GetPlatform())
+  Log.Info('Memory: ' + SystemInfo.GetMemory())
+  Log.Info('CPU Cores: ' + SystemInfo.GetCPUCores())
+
+'''
+Start the main benchmark routine. The method shows some DEBUG information and 
+prints a table with the runtime information.
+'''
+def Main(configfile):
+  # Read Config.
+  config = Parser(configfile, verbose=False)
+
+  # Iterate through all libraries.
+  libraryMapping = config.GetConfigLibraryMethods()
+  while libraryMapping: 
+
+    if libraryMapping.libraryName != "mlpack":
+      continue
+
+    # Iterate through all methods.
+    methodMapping = config.GetConfigMethod(libraryMapping.methods)      
+    while methodMapping and libraryMapping:
+
+      if methodMapping.run:
+
+        Log.Info('Method: ' + methodMapping.methodName)
+
+        # Load script.
+        module = Loader.ImportModuleFromPath(methodMapping.script)
+        methodCall = getattr(module, methodMapping.methodName)
+
+        for dataset in methodMapping.datasets:
+
+          Log.Info('Options: ' + (dataset["options"] if dataset["options"] != '' 
+            else 'None'))
+
+          for files in dataset["files"]:
+
+            # Get dataset name.
+            if  not isinstance(files, basestring):
+              name = os.path.splitext(os.path.basename(files[0]))[0]  
+            else:
+              name = os.path.splitext(os.path.basename(files))[0]
+
+            if name.count('_') != 0:
+              name = name.split("_")[0]
+
+            Log.Info('Dataset: ' + name)
+
+            instance = methodCall(files, verbose=True)
+            instance.RunMemoryProfiling(dataset["options"]);
+
+            # Call the destructor.
+            del instance
+
+      methodMapping = config.GetConfigMethod(libraryMapping.methods)
+    libraryMapping = config.GetConfigLibraryMethods()
+
+if __name__ == '__main__':
+  parser = argparse.ArgumentParser(description="""Perform the benchmark with the
+      given config.""")
+  parser.add_argument('-c','--config', help='Configuration file name.', 
+      required=True)
+
+  args = parser.parse_args()
+
+  if args:
+    SystemInformation()
+    Main(args.config)
\ No newline at end of file

Added: mlpack/conf/jenkins-conf/benchmark/benchmark/run_benchmark.py
==============================================================================
--- (empty file)
+++ mlpack/conf/jenkins-conf/benchmark/benchmark/run_benchmark.py	Tue Jul  2 06:44:29 2013
@@ -0,0 +1,116 @@
+'''
+  @file run_benchmark.py
+  @author Marcus Edel
+
+  Perform the timing benchmark.
+'''
+
+
+import os, sys, inspect
+
+# Import the util path, this method even works if the path contains
+# symlinks to modules.
+cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
+  os.path.split(inspect.getfile(inspect.currentframe()))[0], '../util')))
+if cmd_subfolder not in sys.path:
+  sys.path.insert(0, cmd_subfolder)
+
+from log import *
+from system import *
+from loader import * 
+from parser import *
+
+import argparse
+
+'''
+Show system informations. Are there no data available, the value is 'N/A'.
+'''
+def SystemInformation():
+  
+  Log.Info('CPU Model: ' + SystemInfo.GetCPUModel())
+  Log.Info('Distribution: ' + SystemInfo.GetDistribution())
+  Log.Info('Platform: ' + SystemInfo.GetPlatform())
+  Log.Info('Memory: ' + SystemInfo.GetMemory())
+  Log.Info('CPU Cores: ' + SystemInfo.GetCPUCores())
+
+'''
+Start the main benchmark routine. The method shows some DEBUG information and 
+prints a table with the runtime information.
+'''
+def Main(configfile):
+  # Read Config.
+  config = Parser(configfile, verbose=False)
+
+  # Iterate through all libraries.
+  libraryMapping = config.GetConfigLibraryMethods()
+  while libraryMapping: 
+
+    # Iterate through all methods.
+    methodMapping = config.GetConfigMethod(libraryMapping.methods)      
+    while methodMapping and libraryMapping:
+
+      if methodMapping.run:
+
+        Log.Info('Method: ' + methodMapping.methodName)
+
+        # Load script.
+        module = Loader.ImportModuleFromPath(methodMapping.script)
+        methodCall = getattr(module, methodMapping.methodName)
+
+        for dataset in methodMapping.datasets:
+
+          #! TEMPORARY
+          # Create table.
+          table = []
+          # set table header.
+          header = ['', libraryMapping.libraryName, 'matlab', 'shougun']
+          table.append(header)    
+
+          Log.Info('Options: ' + (dataset["options"] if dataset["options"] != '' 
+            else 'None'))
+
+          for files in dataset["files"]:
+
+            row = ['-'] * 4;
+            # Get dataset name.
+            if  not isinstance(files, basestring):
+              row[0] = os.path.splitext(os.path.basename(files[0]))[0]  
+            else:
+              row[0] = os.path.splitext(os.path.basename(files))[0]
+
+            if row[0].count('_') != 0:
+              row[0] = row[0].split("_")[0]
+
+            Log.Info('Dataset: ' + row[0])
+
+            time = 0
+            for num in range(methodMapping.iteration):
+              instance = methodCall(files, verbose=False)
+              time += instance.RunMethod(dataset["options"]);
+
+              # Call the destructor.
+              del instance
+
+            # Set time.
+            row[1] = time / methodMapping.iteration
+            table.append(row)
+
+          # Show results in a table.
+          Log.Notice('')
+          Log.PrintTable(table)
+          Log.Notice('')
+
+      methodMapping = config.GetConfigMethod(libraryMapping.methods)
+    libraryMapping = config.GetConfigLibraryMethods()
+
+if __name__ == '__main__':
+  parser = argparse.ArgumentParser(description="""Perform the benchmark with the
+      given config.""")
+  parser.add_argument('-c','--config', help='Configuration file name.', 
+      required=True)
+
+  args = parser.parse_args()
+
+  if args:
+    SystemInformation()
+    Main(args.config)
\ No newline at end of file

Added: mlpack/conf/jenkins-conf/benchmark/benchmark/test_config.py
==============================================================================
--- (empty file)
+++ mlpack/conf/jenkins-conf/benchmark/benchmark/test_config.py	Tue Jul  2 06:44:29 2013
@@ -0,0 +1,35 @@
+'''
+  @file test_benchmark.py
+  @author Marcus Edel
+
+  Test the configuration file.
+'''
+
+
+import os
+import sys
+import inspect
+
+# Import the util path, this method even works if the path contains
+# symlinks to modules.
+cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(
+  os.path.split(inspect.getfile(inspect.currentframe()))[0], '../util')))
+if cmd_subfolder not in sys.path:
+  sys.path.insert(0, cmd_subfolder)
+
+from parser import *
+
+import argparse
+
+if __name__ == '__main__':
+  parser = argparse.ArgumentParser(description="""Test the configuration file.
+      Check for correct syntax and then try to open files referred in the 
+      configuration""")
+  parser.add_argument('-c','--config', help='Configuration file name.', 
+      required=True)
+
+  args = parser.parse_args()
+
+  if args:
+    config = Parser(args.config)
+    config.CheckConfig()
\ No newline at end of file



More information about the mlpack-svn mailing list