Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S Super-SloMo
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 19
    • Issues 19
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 10
    • Merge requests 10
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Avinash Paliwal
  • Super-SloMo
  • Merge requests
  • !111

Replace the numpy.meshgrid() with more efficient torch.meshgrid()

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Cui Jinku requested to merge github/fork/CuiJinku/master into master Mar 09, 2023
  • Overview 0
  • Commits 1
  • Pipelines 1
  • Changes 1

What does this PR do?


This PR improves the performance of the backwarp class.

The backwarp class is used for creating backwarping objects. The class constructor calls numpy.meshgrid() and torch.tensor() to create a grid including two tensor objects.

According to my profiling script, the similar API provided by the torch module has far better performance. The torch.meshgrid() has 25X speedup on a single NVIDIA 3090 GPU.

Analysis


I compare the trace of the two different implementations of meshgrid() functions from torch and numpy modules. The reasons for the performance difference would be:

  1. The np.meshgrid() generates the numpy objects on CPU and then copy it to GPU. The copy process incurs extra function call to aten::to. The aten::to takes 0.115ms
  2. The torch.meshgrid() takes 0.037ms, however, the numpy.meshgrid() takes 0.099ms. It indicates about 3X time difference.
  3. The total time for generating the grid with torch.meshgrid() is 0.113ms. The total time for generating the grid with np.meshgrid() is 0.370ms ---- 3X speedup.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/CuiJinku/master