Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoDiff] [CC] Add ti.extension.adstack support to C backend #1748

Closed
archibate opened this issue Aug 22, 2020 · 1 comment · Fixed by #1752
Closed

[AutoDiff] [CC] Add ti.extension.adstack support to C backend #1748

archibate opened this issue Aug 22, 2020 · 1 comment · Fixed by #1752
Assignees
Labels
c++ C++ engineering related feature request Suggest an idea on this project

Comments

@archibate
Copy link
Collaborator

archibate commented Aug 22, 2020

Concisely describe the proposed feature
I'd like to add the support of adstack to the C backend.
Some of the advanced usage of autodiff seems depends on this feature very much, e.g., mass_spring.py in difftaichi, as @samuela reported in #1644 (comment).

Describe the solution you'd like (if any)
I'm not super clear about the autodiff system, so I feel #1257 hard for me to understand. @k-ye Would you mind provide me with more information?

  • StackPopStmt
  • StackPushStmt
  • StackLoadTopStmt
  • StackLoadTopAdjStmt
  • StackAccAdjointStmt

What does adjoint and primal mean and their difference? It seems we have two 32-bit float values per-stack push? Is Adj a shortcut for Adjoint, or simply adjust stack?

Additional comments
@samuela's idea is to call Taichi kernels directly from Julia, that's why we need C backend instead of the LLVM backend, which doesn't have an export option for now.

@archibate archibate added feature request Suggest an idea on this project c++ C++ engineering related labels Aug 22, 2020
@archibate archibate self-assigned this Aug 22, 2020
@k-ye
Copy link
Member

k-ye commented Aug 23, 2020

What does adjoint and primal mean and their difference?

adjoint just stores the gradient of the corresponding variable. Maybe this is a good read: https://rufflewind.com/2016-12-30/reverse-mode-automatic-differentiation ?

It seems we have two 32-bit float values per-stack push?

Yeah. One to store the variable itself (primal), the other to store its gradient (adjoint)

Is Adj a shortcut for Adjoint, or simply adjust stack?

It stands for Adjoint. IIRC, stack adjustments are explicitly named push and pop in this case.

TBH I only have a rough idea of Taichi's autodiff system, which was enough to implement AdStack. As you've pointed out, AdStack itself is just a list of float pairs. So long as we implement those IRs correctly, I think the AD system will just work for the backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ C++ engineering related feature request Suggest an idea on this project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants