Permalink
Browse files

AIRA source code

  • Loading branch information...
rlyerly committed Jan 11, 2018
1 parent cce36ec commit 96a830480d1ed8317e0175a10d950d7991fb2bb7
Showing 454 changed files with 87,357 additions and 0 deletions.
@@ -0,0 +1,53 @@
###############################################################################
# Building
###############################################################################
# benchmarks
all: analysis opencl_runtime power_management load_balancer
analysis:
$(MAKE) -C ./analysis/regression
$(MAKE) -C ./analysis/machine_learning
opencl_runtime:
$(MAKE) -C ./opencl_runtime
power_management:
$(MAKE) -C ./power_management
load_balancer: analysis opencl_runtime
$(MAKE) -C ./load_balancer
#benchmarks: load_balancer power_management
# $(MAKE) -C ./benchmarks/SNU_NPB-1.0.3/NPB3.3-OCL suite dyn_adj=enable
###############################################################################
# Cleaning
###############################################################################
analysis_clean:
$(MAKE) -C ./analysis/regression clean
$(MAKE) -C ./analysis/machine_learning clean
opencl_runtime_clean:
$(MAKE) -C ./opencl_runtime clean
power_management_clean:
$(MAKE) -C ./power_management clean
load_balancer_clean:
$(MAKE) -C ./load_balancer clean
benchmarks_clean:
$(MAKE) -C ./benchmarks/SNU_NPB-1.0.3/NPB3.3-OCL veryclean
clean: analysis_clean \
opencl_runtime_clean \
power_management_clean \
load_balancer_clean \
benchmarks_clean
# benchmarks
.PHONY: analysis opencl_runtime power_management load_balancer all \
analysis_clean opencl_runtime_clean power_management_clean \
load_balancer_clean benchmarks_clean clean
@@ -0,0 +1,103 @@
NAME := aira-ml
TRAIN := train
UNITTEST := unittest
GENCSV := tests/gendata.py
BUILD := build
LIBRARY_SRC := $(shell ls lib/*.cc)
GENERAL_SRC := $(shell ls *.cc | grep -v "train.cc")
TEST_SRC := $(shell ls tests/*.cc)
TEST_CSV := tests/unittest_3x3_linear.csv tests/unittest_100x25_linear.csv \
tests/unittest_100x24_123.csv tests/unittest_100x23_123.csv \
tests/unittest_3x3_123.csv
MAIN_SRC := train.cc
LIB := ${BUILD}/lib${NAME}.so
LIBRARY_OBJ := $(addprefix ${BUILD}/, ${LIBRARY_SRC:.cc=.po})
GENERAL_OBJ := $(addprefix ${BUILD}/, ${GENERAL_SRC:.cc=.o})
TEST_OBJ := $(addprefix ${BUILD}/, ${TEST_SRC:.cc=.o})
MAIN_OBJ := $(addprefix ${BUILD}/, ${MAIN_SRC:.cc=.o})
HEAD := $(shell ls *.hh */*.hh)
CXX := g++
CXXFLAGS := -std=c++11 -Wall -Iinclude `pkg-config opencv --cflags` -pipe \
-march=native -O2 -g
LDFLAGS := `pkg-config opencv --libs` -lmpfr -L${BUILD}/ -l${NAME} -g
all: ${LIB} ${TRAIN} ${TEST}
${BUILD}/.keep:
@echo " MKDIR ${BUILD}"
@mkdir -p ${BUILD} # Use -p to not warn if directory already exists.
@touch ${BUILD}/.keep
${BUILD}/lib/.keep: ${BUILD}/.keep
@echo " MKDIR ${BUILD}/lib"
@mkdir -p ${BUILD}/lib
@touch ${BUILD}/lib/.keep
${BUILD}/tests/.keep: ${BUILD}/.keep
@echo " MKDIR ${BUILD}/tests"
@mkdir -p ${BUILD}/tests
@touch ${BUILD}/tests/.keep
${BUILD}/%.po: %.cc ${HEAD} ${BUILD}/lib/.keep
@echo " CXX $@ (-fpic)"
@${CXX} ${CXXFLAGS} -fpic -c $< -o $@
${BUILD}/%.o: %.cc ${HEAD} ${BUILD}/.keep ${BUILD}/tests/.keep
@echo " CXX $@"
@${CXX} ${CXXFLAGS} -c $< -o $@
%.csv: ${GENCSV}
@echo " CSV $@"
@${GENCSV} $@
${LIB}: ${LIBRARY_OBJ}
@echo " LD.so $@"
@${CXX} -shared $^ -o $@
${TRAIN}: ${LIB} ${GENERAL_OBJ} ${BUILD}/train.o
@echo " LD $@"
@${CXX} -Wl,-rpath,./build ${GENERAL_OBJ} ${BUILD}/train.o ${LDFLAGS} -o $@
${UNITTEST}: ${LIB} ${TEST_OBJ}
@echo " LD $@"
@${CXX} ${TEST_OBJ} ${LDFLAGS} -lgtest_main -o $@
runtest: ${UNITTEST} ${TEST_CSV}
@echo " RUNTEST"
@LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${BUILD}/" ./${UNITTEST}
rundemo: ${TRAIN}
@echo " RUNDEMO"
@LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${BUILD}/" ./${TRAIN} \
--data ../results/merge-static.csv
runsanitize: clean
@echo " CLANG SANITIZE"
@$(MAKE) rundemo \
CXX=clang++ \
CXXEXTRAFLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer \
-g -O1" \
LDEXTRAFLAGS="-fsanitize=address,undefined -g"
runanalysis_clang: clean
@echo " CLANG STATIC ANALYSIS"
@scan-build $(MAKE)
runanalysis_cppcheck:
@echo " CPPCHECK STATIC ANALYSIS"
@cppcheck --quiet --enable=all --std=c++11 \
${MAIN_SRC} ${GENERAL_SRC} ${LIBRARY_SRC} ${TEST_SRC}
clean:
@echo " CLEAN"
@rm -f ${TRAIN} ${TEST} ${UNITTEST} ${TEST_CSV}
@rm -f ${LIBRARY_OBJ} ${GENERAL_OBJ} ${TEST_OBJ} ${MAIN_OBJ} ${LIB}
@rm -rf ${BUILD}/tests/.keep ${BUILD}/lib/.keep ${BUILD}/.keep
@rm -rf ${BUILD}/lib # Harmless error if BUILD is ".".
@rm -rf ${BUILD}/
.PHONY: all clean runtest rundemo
.PHONY: runsanitize runanalysis_clang runanalysis_cppcheck
@@ -0,0 +1,157 @@
#include "common.hh"
#include <iostream>
#include <string>
static double percent(double amount, double total)
{
return (amount/total)*100;
}
static std::string format_ratio(int amount, int total)
{
std::ostringstream format;
format << amount << "/" << total << " (" << percent(amount,total) << "%)";
return format.str();
}
static std::string justify(const std::string msg, unsigned minlen)
{
std::string justified = msg;
while (justified.length() < minlen)
justified += " ";
return justified;
}
void standard_label_transform(DataManager &data, int knn_k,
bool speedup, bool prob,
std::set<int>& cut_labels)
{
// TODO: knn
bool scaleRanges = true; // TODO make command-line arg
if (scaleRanges) {
data.scale_labels();
}
// Convert performance data to relative speed-ups.
if (speedup) {
data.convert_labels_to_speedups();
data.describe(std::cout, "Convert labels to speedups");
}
// Convert performance data to "probabilities".
if (prob) {
data.convert_labels_to_probabilities();
data.describe(std::cout, "Convert labels to prob");
}
if (cut_labels.size() > 0) {
data.apply_label_cut(cut_labels);
data.describe(std::cout, "Cut labels"); //TODO list cut labels
}
}
void standard_feature_transform(DataManager &data, bool cut_empty,
bool scale_means, bool scale_ranges,
std::set<int>& cut_features)
{
#if 0 // TODO
// Cut some known to be bad features manually.
const Data clean_data = in_progress->cut_bad_features();
if (cut_bad) {
in_progress = &clean_data;
in_progress->describe(std::cout, "Cut bad features");
}
#endif
#if 0 // TODO
// Optionally, cut profile-dependent features.
const Data prof_data = in_progress->cut_profile_features();
if (cut_prof) {
in_progress = &prof_data;
in_progress->describe(std::cout, "Cut profile-dependent features");
}
#endif
// Cut all features that add nothing.
if (cut_empty) {
data.apply_empty_cut();
assert((data.num_features() > 0)
&& "cut empty removed ALL features, data is junk");
data.describe(std::cout, "Cut empty features");
}
// Scale all features to have zero-mean.
if (scale_means) {
data.apply_scale_means();
data.describe(std::cout, "Scale means");
}
// Scale all features to have similar ranges.
// TODO: Can also try scaling by stddev rather than range.
if (scale_ranges) {
data.apply_scale_ranges();
data.describe(std::cout, "Scale ranges");
}
if (cut_features.size() > 0) {
data.apply_feature_cut(cut_features);
data.describe(std::cout, "Cut features"); //TODO list cut features
}
}
void evaluation_report(const EvaluationManager &em)
{
std::cout << "# Average training time: " << em.training_times() << std::endl;
std::cout << "# Average prediction time: " << em.prediction_times()
<< std::endl << std::endl;
const Mat32D &confusion = em.confusion_matrix();
std::cout << confusion << std::endl << std::endl;
std::cout << "# Correct distibution: " << confusion.transpose().sums()
<< std::endl;
std::cout << "# Predicted distibution: " << confusion.sums() << std::endl;
int correct = em.correct_predictions();
int incorrect = em.incorrect_predictions();
int total = correct+incorrect;
std::cout << "# Correctly classified " << format_ratio(correct, total)
<< std::endl;
std::cout << "# Speed-up: " << em.average_predicted() << " (oracle: "
<< em.average_actual() << ")" << std::endl;
}
void header_single()
{
std::cout << "# --- " << justify("BENCHMARK", 20) << "ACCURACY,\t\tA --> P"
<< "\t\tMAX%" << std::endl;
}
void evaluation_single(const EvaluationManager &em, const std::string &name,
const bool perf_predict)
{
if(perf_predict) {
double err = em.average_prediction_error();
int total = em.num_predictions();
std::cout << "# --- " << justify(name, 20) << err << "\t\t" << total;
} else {
int correct = em.correct_predictions();
int incorrect = em.incorrect_predictions();
int total = correct+incorrect;
std::cout << "# --- " << justify(name, 20) << format_ratio(correct, total);
int predicted_best = em.confusion_matrix().sums().max_index();
int actual_best = em.confusion_matrix().transpose().sums().max_index();
if (predicted_best == actual_best)
std::cout << ",\t\t" << actual_best << " === " << predicted_best;
else
std::cout << ",\t\t" << actual_best << " --> " << predicted_best;
std::cout << "\t\t" << percent(em.average_predicted(), em.average_actual());
std::cout << "\t\t" << em.average_predicted();
std::cout << "\t\t" << em.average_actual();
}
std::cout << std::endl;
}
@@ -0,0 +1,17 @@
#ifndef _COMMON_HH
#define _COMMON_HH
#include "include/data.hh"
#include "include/eval.hh"
void standard_label_transform(DataManager &data, int knn_k,
bool speedup, bool prob,
std::set<int>& cut_labels);
void standard_feature_transform(DataManager &data, bool cut_empty,
bool scale_means, bool scale_ranges,
std::set<int>& cut_features);
void evaluation_report(const EvaluationManager &em);
void evaluation_single(const EvaluationManager &em, const std::string &name, const bool perf_predict);
void header_single();
#endif // _COMMON_HH
@@ -0,0 +1,10 @@
set term png
set output "visualise.png"
set datafile separator ","
set title "2D PCA"
set xlabel "Best eigenvalue"
set ylabel "Second-best eigenvalue"
set grid
plot 'arch0.txt', 'arch1.txt', 'arch2.txt', 'arch3.txt', 'arch4.txt'
quit
@@ -0,0 +1,16 @@
set term png
#set term wxt
set output "visualise_3d.png"
set datafile separator ","
set title "3D PCA"
set xlabel "Best eigenvalue"
set ylabel "Second-best eigenvalue"
set zlabel "Third-best eigenvalue"
set grid
splot 'arch0.txt', \
'arch1.txt', \
'arch2.txt', \
'arch3.txt', \
'arch4.txt'
quit
@@ -0,0 +1,16 @@
set term png
#set term wxt
set output "visualise_3ds.png"
set datafile separator ","
set title "2D PCA"
set xlabel "Best eigenvalue"
set ylabel "Second-best eigenvalue"
set zlabel "Speed-up"
set grid
splot 'arch0.txt', \
'arch1.txt', \
'arch2.txt', \
'arch3.txt', \
'arch4.txt'
quit
Oops, something went wrong.

0 comments on commit 96a8304

Please sign in to comment.