Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions demos/benchmarks/math-benchmark-run-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as conv_transpose_gpu_benchmark from './conv_transpose_gpu_benchmark';
import * as logsumexp_cpu_benchmark from './logsumexp_cpu_benchmark';
import * as logsumexp_gpu_benchmark from './logsumexp_gpu_benchmark';
import * as max_pool_gpu_benchmark from './max_pool_gpu_benchmark';
import * as max_pool_cpu_benchmark from './max_pool_cpu_benchmark';
import * as mulmat_cpu_benchmark from './mulmat_cpu_benchmark';
import * as mulmat_gpu_benchmark from './mulmat_gpu_benchmark';

Expand Down Expand Up @@ -55,14 +56,17 @@ export const BENCHMARK_RUN_GROUPS: BenchmarkRunGroup[] = [
'd1=1, d2=1, f=11, s=1', conv_transpose_gpu_benchmark.BENCHMARK_TEST)],
},
{
name: 'Max pool (GPU)',
name: 'Max pool (CPU vs GPU): d1=1, d2=1, f=11, s=1',
min: 0,
max: 1024,
stepSize: 64,
stepToSizeTransformation: (step: number) => Math.max(1, step),
benchmarkRuns: [new BenchmarkRun(
'd1=1, d2=1, f=11, s=1',
max_pool_gpu_benchmark.MAX_POOL_BENCHMARK_TEST)],
benchmarkRuns: [
new BenchmarkRun('max_pool_gpu',
max_pool_gpu_benchmark.MAX_POOL_BENCHMARK_TEST),
new BenchmarkRun('max_pool_cpu',
max_pool_cpu_benchmark.MAX_POOL_BENCHMARK_TEST)
],
},
{
name: 'LogSumExp (CPU vs GPU): input [size, size]',
Expand Down
51 changes: 51 additions & 0 deletions demos/benchmarks/max_pool_cpu_benchmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Copyright 2017 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import * as conv_util from '../../src/math/conv_util';
import {NDArrayMathCPU} from '../../src/math/math_cpu';
import {Array3D} from '../../src/math/ndarray';

import {BenchmarkTest} from './benchmark';

const OP_RUNS = 40;

export const MAX_POOL_BENCHMARK_TEST: BenchmarkTest = (size: number) => {
if (size > 512) {
return -1;
}
const positions = false;
return testMaxPool(size, positions);
};

function testMaxPool(size: number, positions: boolean): number {
const math = new NDArrayMathCPU();
const outputDepth = 1;
const xShape: [number, number, number] = [size, size, outputDepth];
const fieldSize = 11;
const stride = 1;
const zeroPad = conv_util.computeDefaultPad(xShape, fieldSize, stride);

const x = Array3D.randUniform(xShape, -1, 1);

const start = performance.now();
for (let i = 0; i < OP_RUNS; i++) {
math.maxPool(x as Array3D, fieldSize, stride, zeroPad);
}
const avgTime = (performance.now() - start) / OP_RUNS;

x.dispose();

return avgTime;
}