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

optimize resizeNearestNeighborBackprop CPU #1333

Merged
merged 2 commits into from
Oct 22, 2018

Conversation

jgartman
Copy link
Contributor

@jgartman jgartman commented Oct 20, 2018

Description

Optimizes the CPU implementation of resizeNearestNeighborBackprop

Benchmark code. To run, expose resizeNearestNeighborBackprop at top level:

tf.setBackend("cpu");
    const ns = [64, 128, 256, 512];
    const RUNS = 100;

    ns.forEach(n => {
      const dy = tf.randomUniform([8, n, n, 3]);
      const x = tf.randomUniform([8, n / 2, n / 2, 3])
      
	// Warmup.
      tf.image.resizeNearestNeighborBackprop(dy, x, false);

      let res = null;
      const start = performance.now();
      for (let i = 0; i < RUNS; i++) {
        res = tf.image.resizeNearestNeighborBackprop(dy, x, false);
      }
      res.dataSync();
      const elapsed = (performance.now() - start) / RUNS;
      console.log(`N: ${n}: ${elapsed.toFixed(2)} ms`);
});

results before optimization:

N: 64: 18.59 ms
N: 128: 78.92 ms
N: 256: 312.69 ms
N: 512: 1290.73 ms

results after optimization:

N: 64: 3.07 ms
N: 128: 11.20 ms
N: 256: 43.60 ms
N: 512: 175.77 ms

For repository owners only:

Please remember to apply all applicable tags to your pull request.
Tags: FEATURE, BREAKING, BUG, PERF, DEV, DOC, SECURITY

For more info see: /~https://github.com/tensorflow/tfjs/blob/master/DEVELOPMENT.md


This change is Reviewable

Copy link
Contributor

@nsthorat nsthorat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r1.
Reviewable status: 0 of 1 approvals obtained

@nsthorat
Copy link
Contributor

Thanks Josh! Just curious, what is motivating these changes?

@nsthorat nsthorat merged commit 2d415d6 into tensorflow:master Oct 22, 2018
@jgartman
Copy link
Contributor Author

Oh, I just assumed that optimizing performance was something we'd want to do in general, I didn't have any motivation beyond that. If you'd like I can hold off on opening any similar PR's until there's a specific use case for them.

@nsthorat
Copy link
Contributor

No need to wait! Optimizations are always welcome, was just curious :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants