Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit f7a8cf0

Browse files
LewuatheNikhil Thorat
authored andcommitted
Comparison of max pool benchmark between CPU and GPU (#95)
* Comparison max pool benchmark between CPU and GPU
1 parent 7c3084b commit f7a8cf0

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

demos/benchmarks/math-benchmark-run-groups.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as conv_transpose_gpu_benchmark from './conv_transpose_gpu_benchmark';
1919
import * as logsumexp_cpu_benchmark from './logsumexp_cpu_benchmark';
2020
import * as logsumexp_gpu_benchmark from './logsumexp_gpu_benchmark';
2121
import * as max_pool_gpu_benchmark from './max_pool_gpu_benchmark';
22+
import * as max_pool_cpu_benchmark from './max_pool_cpu_benchmark';
2223
import * as mulmat_cpu_benchmark from './mulmat_cpu_benchmark';
2324
import * as mulmat_gpu_benchmark from './mulmat_gpu_benchmark';
2425

@@ -55,14 +56,17 @@ export const BENCHMARK_RUN_GROUPS: BenchmarkRunGroup[] = [
5556
'd1=1, d2=1, f=11, s=1', conv_transpose_gpu_benchmark.BENCHMARK_TEST)],
5657
},
5758
{
58-
name: 'Max pool (GPU)',
59+
name: 'Max pool (CPU vs GPU): d1=1, d2=1, f=11, s=1',
5960
min: 0,
6061
max: 1024,
6162
stepSize: 64,
6263
stepToSizeTransformation: (step: number) => Math.max(1, step),
63-
benchmarkRuns: [new BenchmarkRun(
64-
'd1=1, d2=1, f=11, s=1',
65-
max_pool_gpu_benchmark.MAX_POOL_BENCHMARK_TEST)],
64+
benchmarkRuns: [
65+
new BenchmarkRun('max_pool_gpu',
66+
max_pool_gpu_benchmark.MAX_POOL_BENCHMARK_TEST),
67+
new BenchmarkRun('max_pool_cpu',
68+
max_pool_cpu_benchmark.MAX_POOL_BENCHMARK_TEST)
69+
],
6670
},
6771
{
6872
name: 'LogSumExp (CPU vs GPU): input [size, size]',
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright 2017 Google Inc. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
import * as conv_util from '../../src/math/conv_util';
17+
import {NDArrayMathCPU} from '../../src/math/math_cpu';
18+
import {Array3D} from '../../src/math/ndarray';
19+
20+
import {BenchmarkTest} from './benchmark';
21+
22+
const OP_RUNS = 40;
23+
24+
export const MAX_POOL_BENCHMARK_TEST: BenchmarkTest = (size: number) => {
25+
if (size > 512) {
26+
return -1;
27+
}
28+
const positions = false;
29+
return testMaxPool(size, positions);
30+
};
31+
32+
function testMaxPool(size: number, positions: boolean): number {
33+
const math = new NDArrayMathCPU();
34+
const outputDepth = 1;
35+
const xShape: [number, number, number] = [size, size, outputDepth];
36+
const fieldSize = 11;
37+
const stride = 1;
38+
const zeroPad = conv_util.computeDefaultPad(xShape, fieldSize, stride);
39+
40+
const x = Array3D.randUniform(xShape, -1, 1);
41+
42+
const start = performance.now();
43+
for (let i = 0; i < OP_RUNS; i++) {
44+
math.maxPool(x as Array3D, fieldSize, stride, zeroPad);
45+
}
46+
const avgTime = (performance.now() - start) / OP_RUNS;
47+
48+
x.dispose();
49+
50+
return avgTime;
51+
}

0 commit comments

Comments
 (0)