Skip to content

[MISC] Speed up solver via linesearch/update_constraint/func_init optimizations#2445

Draft
erizmr wants to merge 14 commits intoGenesis-Embodied-AI:mainfrom
erizmr:mingrui/260218/solver_opt_merge_to_main
Draft

[MISC] Speed up solver via linesearch/update_constraint/func_init optimizations#2445
erizmr wants to merge 14 commits intoGenesis-Embodied-AI:mainfrom
erizmr:mingrui/260218/solver_opt_merge_to_main

Conversation

@erizmr
Copy link
Contributor

@erizmr erizmr commented Feb 22, 2026

Description

Related Issue

Resolves Genesis-Embodied-AI/Genesis#

Motivation and Context

How Has This Been / Can This Be Tested?

Screenshots (if appropriate):

Checklist:

  • I read the CONTRIBUTING document.
  • I followed the Submitting Code Changes section of CONTRIBUTING document.
  • I tagged the title correctly (including BUG FIX/FEATURE/MISC/BREAKING)
  • I updated the documentation accordingly or no change is needed.
  • I tested my changes and added instructions on how to test it for reviewers.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@erizmr erizmr force-pushed the mingrui/260218/solver_opt_merge_to_main branch from b7969ff to 912fdf6 Compare March 2, 2026 18:38
@erizmr erizmr force-pushed the mingrui/260218/solver_opt_merge_to_main branch from 912fdf6 to 0d43c2b Compare March 2, 2026 18:44
@erizmr erizmr force-pushed the mingrui/260218/solver_opt_merge_to_main branch from 034c2e5 to e8422e9 Compare March 3, 2026 19:39
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

🔴 Benchmark Regression Detected ➡️ Report

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

🔴 Benchmark Regression Detected ➡️ Report

@erizmr erizmr marked this pull request as ready for review March 5, 2026 05:21
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

🔴 Benchmark Regression Detected ➡️ Report

Comment on lines +2265 to +2268
@qd.func
def _log_scale(min_value: gs.qd_float, max_value: gs.qd_float, num_values: qd.i32, i: qd.i32) -> gs.qd_float:
step = (qd.log(max_value) - qd.log(min_value)) / qd.max(1.0, gs.qd_float(num_values - 1))
return qd.exp(qd.log(min_value) + gs.qd_float(i) * step)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be moved in generic quadrants kernel utils

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only for linesearch use. I intend to add a note to state it can be moved in generic quadrants kernel utils and do follow up PRs on it. How do you think?

Copy link
Collaborator

@duburcqa duburcqa Mar 9, 2026

Choose a reason for hiding this comment

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

If think it should either be inlined or move in generic quadrants kernel utils. No good reason to wait.

n_entities: int = -1
n_links: int = -1
n_geoms: int = -1
iterations: int = -1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this. It is not the right place. We do consider dynamically changing variables as pre-compiled constant. Moreover, "iterations" is a terrible variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for removing the reading from field rigid_global_info.iterations[None] in python scope, i.e., removing the implicit cpu-gpu sync. I have two other solutions in mind: 1. Store as a Python attribute on rigid_global_info 2. add a new parameter such n_solver_iterations to func_solve_body, which one would you prefer? Or feel free to share a three

Copy link
Collaborator

Choose a reason for hiding this comment

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

I need to think about it. At this point none of them seems acceptable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you share more details regarding what this attribute is storing and how it is used? Is it changing at every simulation step or is it a constant? How does it works?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it is a constant, the usual approach is to store another Python native attribute with _ prefix in the solver and pass it as input argument of Python-native functions only. We are doing this for instance to skip kernel calls for specialized collision detection if useless, eg box-box.

from genesis.engine.solvers.rigid.constraint import solver

LS_PARALLEL_K = 16
LS_PARALLEL_MIN_STEP = 1e-6
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should depends on the desired precision. It should not be hard-coded this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add them to the rigid solver options. The LS_PARALLEL_K is similar to the BLOCK_DIM in func_hessian_direct_tiled impl, which determines the parallelism and shared memory pattern of the kernel, which is not runtime changing variable.

LS_PARALLEL_MIN_STEP is a starting low bound of the linesearch alpha search range. It is more reasonable to set it as a constant in my opinion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. Can you document them? I think it is weird to pick a constant that does not depends on genesis precision and/or linesearch tolerance. Does it make sense to use a threshold that is smaller than desired linesearch tolerance? You should document all of this.

Comment on lines +8 to +9
LS_PARALLEL_MIN_STEP = 1e-6
LS_PARALLEL_N_REFINE = 1 # number of successive refinement passes in parallel linesearch
Copy link
Collaborator

Choose a reason for hiding this comment

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

These 2 options should probably be added to the rigid solver options.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it does not make sense to make this parameters tunable then it is great, but you need to document why you think so.

@erizmr
Copy link
Contributor Author

erizmr commented Mar 9, 2026

@hughperkins hughperkins marked this pull request as draft March 19, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants