Skip to content

Commit

Permalink
Merge pull request #12 from gpujs/benchmark-v3
Browse files Browse the repository at this point in the history
Benchmark v3
  • Loading branch information
harshkhandeparkar authored Mar 18, 2020
2 parents c19757f + b7bfe9e commit ead5056
Show file tree
Hide file tree
Showing 46 changed files with 1,024 additions and 762 deletions.
242 changes: 142 additions & 100 deletions README.md

Large diffs are not rendered by default.

File renamed without changes.
5 changes: 5 additions & 0 deletions cli/default-options-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"matrix_size",
"num_iterations",
"cpu_benchmark"
]
File renamed without changes.
20 changes: 20 additions & 0 deletions cli/get-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const readlineSync = require('readline-sync'),
defaultInputs = require('./default-options-input.json'),
{ YELLOW_UNDER, GREEN_NO_UNDER, NC } = require('./colors'),
defaults = require('../src/util/defaults.json');

function getOptionsInput(options) {
console.log(`${GREEN_NO_UNDER}OPTIONS:${NC} (Press Enter to Select the Default Value)`);

defaultInputs.forEach(input => {
if (options.hasOwnProperty(input)) return;

options[input] = readlineSync.question(`${YELLOW_UNDER}${input}${NC} (${typeof defaults[input]})(default: ${defaults[input]}): `);

if (options[input] === '') options[input] = defaults[input];
})

return options;
}

module.exports = getOptionsInput;
18 changes: 18 additions & 0 deletions cli/graph-defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"x": "matrix_size",
"y": "gpu_score"
},
{
"x": "matrix_size",
"y": "gpu_run_time_mat_mult"
},
{
"x": "matrix_size",
"y": "cpu_score"
},
{
"x": "matrix_size",
"y": "cpu_run_time_mat_mult"
}
]
10 changes: 10 additions & 0 deletions cli/log-min-max.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { NC, YELLOW_UNDER } = require('./colors');

const getVal = val => val.avg == -1 ?
`${YELLOW_UNDER}Not Benchmarked${NC}` :
`${YELLOW_UNDER}${val.avg}${NC} ms +- ${YELLOW_UNDER}${val.deviation}${NC}%`

module.exports = minMax => {
console.log(`GPU average: ${getVal(minMax.gpu)}`);
console.log(`CPU average: ${getVal(minMax.cpu)}`);
}
70 changes: 70 additions & 0 deletions cli/log-stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const { NC, YELLOW_NO_UNDER, YELLOW_UNDER, GREEN_UNDER, GREEN_NO_UNDER, RED_NO_UNDER } = require('./colors'),
{ br } = require('./format');

const performerMap = {
gpu: 'GPU',
cpu: 'CPU',
pipe: 'GPU(pipeline mode)'
},
benchMap = {
mat_mult: 'Matrix Multiplication',
mat_conv: 'Matrix Convolution',
pipe: 'Pipelining'
}

const logRunTimeStats = ({run_time}, cpuBenched) => {
if (cpuBenched) {
for (const bench in run_time) {
console.log(`Benchmark: ${GREEN_UNDER}${benchMap[bench]}${NC}`);
br();
let performerNotBenched;

for (const diff in run_time[bench].diff) {
const performers = diff.split('_'),
{ avg } = run_time[bench].diff[diff],
percentage = {
avg: run_time[bench].diff[diff].avg.percentage
};

performerNotBenched = (performerNotBenched || percentage.min == -1 || percentage.max == -1 || percentage.avg == -1);

if (!performerNotBenched){
console.log(`Performance Comparison between ${YELLOW_NO_UNDER}${performerMap[performers[0]]}${NC} and ${YELLOW_NO_UNDER}${performerMap[performers[1]]}${NC}:`);
console.log(`Better Performer: ${YELLOW_NO_UNDER}${performerMap[avg.winner]}${NC} by ${YELLOW_UNDER}${percentage.avg}${NC}%`);
}
}
br(2);
}
}
else console.log('Nothing to Compare With \n')
}

const logBuildTimeStats = ({build_time}) => {
for (const bench in build_time) {
const performers = ['gpu', 'pipe'];
performers.splice(performers.indexOf(build_time[bench].diff.winner));
console.log(`Benchmark: ${GREEN_UNDER}${benchMap[bench]}${NC}`);
console.log(`${YELLOW_NO_UNDER}${performerMap[build_time[bench].diff.gpu_pipe.winner]}${NC} compiled ${YELLOW_UNDER}${build_time[bench].diff.gpu_pipe.percentage}${NC}% faster than ${YELLOW_NO_UNDER}${performerMap[performers[0]]}${NC}`);
br(2);
}
}

const logOverallStats = ({overall}, cpuBenched) => {
if (cpuBenched) {
for (const bench in overall) {
console.log(`Benchmark: ${GREEN_UNDER}${benchMap[bench]}${NC}`);
br();
if (overall[bench].diff.percentage != -1) console.log(`${YELLOW_NO_UNDER}${performerMap[overall[bench].best_performer]}${NC} was ${YELLOW_UNDER}${overall[bench].diff.percentage}${NC}% faster than ${YELLOW_NO_UNDER}${performerMap[overall[bench].worst_performer]}${NC}`);
br(2);
}
}
else console.log('Nothing to Compare With')
}

module.exports = {
logRunTimeStats,
logBuildTimeStats,
logOverallStats,
performerMap,
benchMap
}
11 changes: 11 additions & 0 deletions cli/multiple-defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"common_options": {
"cpu_benchmark": false,
"logs": true
},
"range": {
"option_name": "matrix_size",
"interval": [64, 512],
"common_ratio": 2
}
}
30 changes: 30 additions & 0 deletions cli/parse-args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @description Parses all the CLI arguments
* @param {Float32Array} args The user CLI arguments (Usually process.argv)
*/
function parseArgs(args) {
if (args[2] !== undefined) {
const multiple = args.includes('--multiple');
const options = args.find(opt => /^{.*}$/.test(opt)) || false;

const returnPlotlyJSON = args.includes('--returnPlotlyJSON');
const returnChartistJSON = args.includes('--returnChartistJSON');

const plotlySavePath = args.find(opt => /^--savePlotlyJSONToFile=/.test(opt)) || false;
const chartistSavePath = args.find(opt => /^--saveChartistJSONToFile=/.test(opt)) || false;

return {
multiple,
options,
returnPlotlyJSON,
returnChartistJSON,
plotlySavePath,
chartistSavePath
}
}
else {
return false;
}
}

module.exports = parseArgs;
30 changes: 30 additions & 0 deletions cli/write-file-recursive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require('fs'),
path = require('path');

/**
* @description Saves a file to a given path recursively, ie also creates the required directories.
* @param {String} path Path to the file including the name of the file with the extension
* @param {String} content Contents of the file
*/
function writeFileSyncRecursive(path, content) {
const folders = path.split(path.sep).slice(0, -1);
if (folders.length > 0) {

// create folder path if it doesn't exist
folders.reduce((last, folder) => {
if (!fs.existsSync(last)) {
fs.mkdirSync(last);
}
const folderPath = last + path.sep + folder;

if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
}

return folderPath;
})
}
fs.writeFileSync(path, content);
}

module.exports = writeFileSyncRecursive;
Loading

0 comments on commit ead5056

Please sign in to comment.