Created
February 12, 2019 08:49
-
-
Save astojilj/e2388f8a376b1f436597337c2efda389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/integration_tests/benchmarks/benchmark_test.ts b/integration_tests/benchmarks/benchmark_test.ts | |
| index 8148ea2..72b74f7 100644 | |
| --- a/integration_tests/benchmarks/benchmark_test.ts | |
| +++ b/integration_tests/benchmarks/benchmark_test.ts | |
| @@ -15,10 +15,15 @@ | |
| * ============================================================================= | |
| */ | |
| +import * as tf from '@tensorflow/tfjs-core'; | |
| + | |
| import {ConvGPUBenchmark, RegularConvParams} from './conv_benchmarks'; | |
| import {MatmulGPUBenchmark} from './matmul_benchmarks'; | |
| import {MobileNetV1GPUBenchmark} from './mobilenet_benchmarks'; | |
| +import {ReductionOpsGPUBenchmark} from './reduction_ops_benchmark'; | |
| import * as test_util from './test_util'; | |
| +import {BenchmarkTest} from './types'; | |
| +import * as util from './util'; | |
| const BENCHMARK_RUNS = 100; | |
| @@ -39,6 +44,54 @@ describe('benchmarks', () => { | |
| done(); | |
| }); | |
| + it('reduction', async done => { | |
| + const sizes = [263169]; | |
| + | |
| + const benchmark = new ReductionOpsGPUBenchmark(); | |
| + | |
| + await test_util.benchmarkAndLog( | |
| + 'reduction', size => benchmark.run(size, 'argMax'), sizes, | |
| + size => `N=${size}`, BENCHMARK_RUNS); | |
| + | |
| + done(); | |
| + }); | |
| + | |
| + it('avgPool', async done => { | |
| + const sizes = [33, 65]; | |
| + | |
| + const benchmark = new AvgPoolGPUBenchmark(); | |
| + | |
| + await test_util.benchmarkAndLog( | |
| + 'avgPool', size => benchmark.run(size), sizes, size => `N=${size}`, | |
| + BENCHMARK_RUNS); | |
| + | |
| + done(); | |
| + }); | |
| + | |
| + it('concat', async done => { | |
| + const sizes = [33, 65]; | |
| + | |
| + const benchmark = new ConcatGPUBenchmark(); | |
| + | |
| + await test_util.benchmarkAndLog( | |
| + 'concat', size => benchmark.run(size), sizes, size => `N=${size}`, | |
| + BENCHMARK_RUNS); | |
| + | |
| + done(); | |
| + }); | |
| + | |
| + it('resizeBilinear', async done => { | |
| + const sizes = [33, 65]; | |
| + | |
| + const benchmark = new ResizeBilinearBenchmark(); | |
| + | |
| + await test_util.benchmarkAndLog( | |
| + 'resizeBilinear', size => benchmark.run(size), sizes, | |
| + size => `N=${size}`, BENCHMARK_RUNS); | |
| + | |
| + done(); | |
| + }); | |
| + | |
| it('conv2d', async done => { | |
| const sizes = [10, 100, 227]; | |
| const convParams: RegularConvParams = | |
| @@ -64,3 +117,53 @@ describe('benchmarks', () => { | |
| done(); | |
| }); | |
| }); | |
| + | |
| +export class AvgPoolGPUBenchmark implements BenchmarkTest { | |
| + async run(size: number) { | |
| + tf.setBackend('webgl'); | |
| + | |
| + const x: tf.Tensor4D = tf.randomUniform([1, size, size, 320], -1, 1); | |
| + | |
| + const benchmark = () => tf.avgPool(x, [size, size], [size, size], 'valid'); | |
| + | |
| + const time = await util.warmupAndBenchmarkGPU(benchmark); | |
| + | |
| + x.dispose(); | |
| + | |
| + return time; | |
| + } | |
| +} | |
| + | |
| +export class ConcatGPUBenchmark implements BenchmarkTest { | |
| + async run(size: number) { | |
| + tf.setBackend('webgl'); | |
| + | |
| + const x: tf.Tensor4D = tf.randomUniform([1, size, size, 256], -1, 1); | |
| + const y: tf.Tensor4D = tf.randomUniform([1, size, size, 256], -1, 1); | |
| + | |
| + const benchmark = () => tf.concat([x, y], 3); | |
| + | |
| + const time = await util.warmupAndBenchmarkGPU(benchmark); | |
| + | |
| + x.dispose(); | |
| + y.dispose(); | |
| + | |
| + return time; | |
| + } | |
| +} | |
| + | |
| +export class ResizeBilinearBenchmark implements BenchmarkTest { | |
| + async run(size: number) { | |
| + tf.setBackend('webgl'); | |
| + | |
| + const x: tf.Tensor4D = tf.randomUniform([1, size, size, 21], -1, 1); | |
| + | |
| + const toSize = (size - 1) * 8 + 1; | |
| + const benchmark = () => tf.image.resizeBilinear(x, [toSize, toSize], true); | |
| + | |
| + const time = await util.warmupAndBenchmarkGPU(benchmark); | |
| + | |
| + x.dispose(); | |
| + return time; | |
| + } | |
| +} | |
| \ No newline at end of file | |
| diff --git a/integration_tests/benchmarks/reduction_ops_benchmark.ts b/integration_tests/benchmarks/reduction_ops_benchmark.ts | |
| index 6df9342..715cc0e 100644 | |
| --- a/integration_tests/benchmarks/reduction_ops_benchmark.ts | |
| +++ b/integration_tests/benchmarks/reduction_ops_benchmark.ts | |
| @@ -49,7 +49,7 @@ export class ReductionOpsCPUBenchmark implements BenchmarkTest { | |
| const start = performance.now(); | |
| tf.tidy(() => { | |
| - op(input).get(); | |
| + op(input).arraySync(); | |
| }); | |
| const end = performance.now(); | |
| @@ -61,9 +61,7 @@ export class ReductionOpsGPUBenchmark implements BenchmarkTest { | |
| async run(size: number, option: string) { | |
| tf.setBackend('webgl'); | |
| - // Square the provided size to make these 1D benchmarks comparable to the | |
| - // other 2D ones. | |
| - const input: tf.Tensor1D = tf.randomUniform([size * size], -1, 1); | |
| + const input: tf.Tensor2D = tf.randomUniform([size, 21], -1, 1); | |
| const op = getReductionOp(option); | |
| const benchmark = () => op(input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment