| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Benchmark is a simple benchmarking tool for GPU.js. This tool works both in JavaScript and CLI.
This tool runs three benchmarks:
NOTE: The package gpu.js needs to be installed separately. Benchmark is available on npm under the name @gpujs/benchmark.
yarn add @gpujs/benchmarknpm install @gpujs/benchmarkThe npm module ships prebuilt dist/benchmark.js and dist/benchmark.min.js, so skip this step unless you are building a modified script locally.
npm install
npm run buildInclude the benchmark dist file in the HTML file.
<script src="path/to/dist/gpu.min.js"></script> <!--gpu.js has tp be included separately-->
<script src="path/to/dist/benchmark.min.js"></script>or, from the npm module
<script src="path/to/dist/gpu.min.js"></script> <!--gpu.js has tp be included separately-->
<script src="path/to/node_modules/@gpujs/benchmark/dist/benchmark.min.js"></script>The bundle exposes a gpujsBenchmark global:
const out = gpujsBenchmark.benchmark(options);
// gpujsBenchmark.multipleBenchmark(options) is also availableconst benchmark = require('@gpujs/benchmark')import benchmark from '@gpujs/benchmark'const benchmarks = benchmark.benchmark(options)OR run Multiple Benchmarks
const benchmarks = benchmark.multipleBenchmark(options)This returns the benchmarks in an Object. See this.
git clone https://github.com/gpujs/benchmark
cd benchmarknpm install -g yarnyarn setupyarn startnode ./index.jsThis will prompt you to enter the optional [options]
yarn start optionsoptions is a stringified JSON object passed as an argument.
node ./index.js optionsHere, options is a stringified JSON object.
yarn start '{"num_iterations": 4}'The following options can be passed on to the benchmark or multipleBenchmark method.
cpu(Object) *: A custom GPU({mode: 'cpu'}) Object to benchmark specific versions of GPU.js(>= v2.0.0). Mandatory in everything except CLI.
gpu(Object) *: A custom GPU() Object to benchmark specific versions of GPU.js(>= v2.0.0). (default: The version shipped with benchmark). Mandatory in everything except CLI.
matrix_size(Integer): The size of the uniform matrix used for benchmarking. (default: 512)
num_iterations(Integer): The number of iterations of run time calculation. (default: 1)
logs(Boolean): Toggles console logs by the library.
cpu_benchmark(Boolean): Toggles the benchmarking of CPU. False is recommended to big matrix sizes. (default: true)
{
common_options: { // options common to all but can be overridden in range or in full_options, preference given to range
cpu_benchmark: false,
cpu: new CPU({mode: 'cpu'}),
gpu: new GPU()
},
range: { // only one of this and full_options works
option_name: 'matrix_size',
interval: [128, 1024],
step: 100 //(default 10)(A.P.: 128, 138, 148, 158) one of step or common_ratio can be used, preference given to step
// common_ratio: 2 (G.P.: 128, 256, 512, 1024)
},
full_options: [
{
// array of options objects for each benchmark(only one of this and range works, preference given to range)
}
]
}yarn start --multiple [options?]options to the CLI are stored in a stringified JSON object passed as an argument. More about Multiple Benchmarks.
yarn start --multiple --returnPlotlyJSONThis will log to the console, plotly.js style JSON which stores the graph data for GPU score v/s matrix size of each benchmark.
yarn start --multiple --savePlotlyJSONToFile=path/to/file.jsonThis saves the plotly.js style JSON data for:
yarn start --multiple --returnChartistJSONThis will log to the console, chartist.js style JSON which stores the graph data for GPU score v/s matrix size of each benchmark.
yarn start --multiple --saveChartistJSONToFile=path/to/file.jsonThis saves the chartist.js style JSON data for:
Benchmark allows you to run a sequence of benchmarks each with different custom options or each having number options like matrix size changed by a fixed amount.
benchmark.multipleBenchmark(options);Where options is an object with the following properties:
benchmark.multipleBenchmark({
common_options: {
cpu_benchmark: false,
logs: false
},
range: {
option_name: 'matrix_size',
interval: [128, 2048],
common_ratio: 2
}
})The above code runs a separate benchmark for the matrix sizes 128, 256, 512, 1024, 2048 which are in GP.
benchmark.multipleBenchmark({
common_options: {
logs: false,
cpu_benchmark: false
},
full_options: [
{
logs: true, // override
matrix_size: 2048
},
{
cpu_benchmark: true, //override
matrix_size: 128
}
]
})The output of any benchmark(multiple or single) is a BenchmarkOut Object.
The output contains a stats property which shows the overall stats of the benchmark:
run_time: The run time stats
build_time: The build time stats
overall: The overall stats mat_mult, mat_conv: Overall stats for each benchmark
score: The score object is a property of the main output object.
TECHNICAL: The score is floor of one-hundredth of the ratio of the total number of operations in matrix multiplication to the time taken for the operations.
This object stores the output of Benchmark.
Default value of compare_fields argument for getPlotlyJSON and getChartistJSON methods:
[
{
x: 'matrix_size',
y: 'gpu_run_time_mat_mult'
},
{
x: 'matrix_size',
y: 'pipe_run_time'
},
{
x: 'matrix_size',
y: 'gpu_score'
}
]This benchmark multiplies two randomly generated uniform-sized matrices and benchmarks the GPU and CPU against the time taken by each.
GPU.js Kernel:
function(a, b) {
let sum = 0;
for (let i = 0; i < this.output.x; i++) {
sum += a[this.thread.y][i] * b[i][this.thread.x];
}
return sum;
}This benchmark convolves a 3x3 kernel over a randomly generated uniform sized matrix. The convolution kernel is
1 2 1 2 1 2 1 2 1
GPU.js Kernel:
function (array, kernel) {
let sum = 0;
for (let i = 0; i < ${kernelX}; i++){
for (let j = 0; j < ${kernelY}; j++){
sum += kernel[j][i] * array[this.thread.y + j][this.thread.x + i];
}
}
return sum;
}Where kernelX and kernelY are the dimensions of the kernel.
GPU.js supports a feature called Pipelining and this benchmark benchmarks this feature. It runs four matrix multiplication benchmarks in a sequence while pipelining the output of the earlier benchmark to be used as an input to the next one. The benchmark is run both on the GPU and the CPU(without pipelining) and the time taken is compared. When it is run on the GPU, the output of the previous multiplication is passed on to the next call as a texture (a storage unit on the GPU) on the GPU itself which drastically reduces the time taken because the output need not be converted and transferred to the CPU and back.
GPU.js can be run on Android and iOS devices using expo-gl which is a simple package developed by the GPU.js community.
| Back | FazBrowse Home | New Git URL |