小白开启taichi源码研究

请问一下作为初次接触taichi源码的我该怎么去对源码进行研究尼?就比如atuo_diff.cpp那个文件,有些好的建议吗?我也看了一下,有点看不懂

1 Like

欢迎!

可以看看Taichi kernel的生命周期,这样对项目整体有个了解: https://taichi.readthedocs.io/en/stable/compilation.html

TaichiCon里面有很多面向开发者的信息:https://github.com/taichi-dev/taichicon

auto_diff.cpp可以看 https://arxiv.org/abs/1910.00935 现在auto_diff系统比这个文章里面的更复杂一些,但是总体思路差不多。

Let’s take an example piece in auto_diff.cpp:

    } else if (stmt->op_type == UnaryOpType::cos) {
      accumulate(stmt->operand, negate(mul(adjoint(stmt), sin(stmt->operand))));

stmt is statement, one kind of statement is unary operation statement, i.e. only have one operand like -x, cos(x).
The stmt->op_type tells you exactly which operator the statement is. It’s cos in this case.
The stmt->operand is the operand of this statement, it can be variable like x, or constant like 233.

accumulate(stmt->operand, negate(mul(adjoint(stmt), sin(stmt->operand))));

This is basically calculating the derivitive (dao shu) of cos(x). Recall that d cos(x) = -sin(x) dx, we use negate, mul, adjoint to represents the computation in C++ code.
If you take a close look,

negate(mul(adjoint(stmt), sin(stmt->operand)))

negate(mul(dx, sin(x)))

negate(sin(x) * dx)

-sin(x) * dx

You can easily reassemble the original mathematical expression.


} else if (stmt->op_type == UnaryOpType::tan) {
      TI_NOT_IMPLEMENTED

Here, we use the TI_NOT_IMPLEMENTED macro, it will raise an error when executed. That means the derivite calculation is not yet implemented for tan, would you complete this by using the method above to check if you’ve learnt it? (If you’re OK with calculas).

(Sorry about not typing in Chinese… my ShuRuFa gets broken and I have to talk English now)

1 Like

感谢巨佬 :grin:

感谢感谢,看懂了你的表述,说的很明白! :fist: