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

[Doc] better documention #747

Merged
merged 55 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
26a7569
[skip ci] update doc Global Settings
archibate Apr 11, 2020
2e66e18
update linalg
archibate Apr 11, 2020
9e9265a
[skip ci] update type
archibate Apr 11, 2020
21df5e6
update global settings again
archibate Apr 11, 2020
65afc11
update gui&imgio to util
archibate Apr 11, 2020
5a45140
[skip ci] tmp work save
archibate Apr 11, 2020
0e699ff
add vector.rst
archibate Apr 11, 2020
0fab826
fix typoly
archibate Apr 11, 2020
b11cdf8
add atomic
archibate Apr 11, 2020
4bf9a7b
[skip ci] tmp work on tensor of scalars
archibate Apr 11, 2020
d5a2c3b
[skip ci] applying reviews by @k-ye
archibate Apr 11, 2020
1427d5a
[skip ci] add table
archibate Apr 11, 2020
ac92ead
[skip ci] apply reviews by @yuanming-hu
archibate Apr 11, 2020
342eec7
[skip ci] typo
archibate Apr 11, 2020
bd39eb3
[skip ci] typo2
archibate Apr 11, 2020
34a1e02
[skip ci] update hello
archibate Apr 11, 2020
f7509ee
[skip ci] change tables
archibate Apr 12, 2020
af695ec
[skip ci] update vector.rst
archibate Apr 12, 2020
38904c7
[skip ci] update dev_install.rst
archibate Apr 12, 2020
ef5e54f
[skip ci] update
archibate Apr 12, 2020
99440a4
[skip ci] update again
archibate Apr 12, 2020
5c8fbba
[skip ci] upd
archibate Apr 12, 2020
5a9291d
[skip ci] u
archibate Apr 12, 2020
7762a54
[skip ci] update
archibate Apr 12, 2020
b6ddde0
[skip ci] update break usage
archibate Apr 12, 2020
9e7f737
[skip ci] upd
archibate Apr 12, 2020
7b1bcf3
[skip ci]
archibate Apr 12, 2020
4c66e29
[skip ci] a
archibate Apr 12, 2020
3e65f78
[skip ci] s
archibate Apr 12, 2020
340436f
[skip ci] Merge branch 'master' into doc
archibate Apr 12, 2020
f8c5c2a
[skip ci] !
archibate Apr 12, 2020
cecb3b6
[skip ci] overhaul
archibate Apr 12, 2020
c7b6095
[skip ci] update scalar_tensor
archibate Apr 12, 2020
0082022
[skip ci] misc
archibate Apr 12, 2020
8b72b0f
[skip ci] rename to References
archibate Apr 12, 2020
b7ec4ae
[skip ci] swap
archibate Apr 12, 2020
f19f228
[skip ci] gsm
archibate Apr 12, 2020
4669334
Merge branch 'master' into doc
archibate Apr 13, 2020
ada791a
[skip ci] gsm init recursive
archibate Apr 13, 2020
57fdd42
Merge branch 'doc' of github.com:archibate/taichi into doc
archibate Apr 13, 2020
71c41ae
[skip ci] enforce code format
taichi-gardener Apr 13, 2020
a344fd4
[skip ci] Merge branch 'master' into doc
archibate Apr 14, 2020
5d97289
[skip ci] Merge branch 'master' into doc
archibate Apr 14, 2020
5521c03
[skip ci] Merge branch 'doc' of github.com:archibate/taichi into doc
archibate Apr 14, 2020
a126e0e
update lists.py
archibate Apr 14, 2020
671142e
xxx
archibate Apr 14, 2020
82ea5d7
[skip ci] fix WARNING
archibate Apr 14, 2020
a85ef7e
[skip ci] fix contributor_guide
archibate Apr 14, 2020
61c9704
update atomic.rst
yuanming-hu Apr 14, 2020
94416d3
update syntax and contributor_guide
yuanming-hu Apr 14, 2020
543234a
[skip ci] reviews
archibate Apr 14, 2020
4350e32
[skip ci] Merge branch 'doc' of github.com:archibate/taichi into doc
archibate Apr 14, 2020
b1c4191
[skip ci] fix typo
archibate Apr 14, 2020
1fd7210
update dev-install
archibate Apr 14, 2020
443b6c3
[skip ci] finalize
yuanming-hu Apr 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions docs/atomic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.. _atomic:

Atomic operations
=================

In taichi, ``x[i] += 1`` is atomic but ``x[i] = x[i] + 1`` is not.

For example, to perform a reduction:
::
@ti.kernel
def sum():
for i in x:
result[None] += x[i]

Or use the function ``ti.atomic_add``, which is equivalent:
::
@ti.kernel
def sum():
for i in x:
ti.atomic_add(result[None], x[i])

See https://en.wikipedia.org/wiki/Fetch-and-add for more details.


.. note::
Support of atomic operation on each backends:

+------+-----------+-----------+---------+
| type | LLVM | OpenGL | Metal |
+======+===========+===========+=========+
| i32 | OK | OK | OK |
+------+-----------+-----------+---------+
| f32 | OK | OK | OK |
+------+-----------+-----------+---------+
| i64 | OK | EXT | MISS |
+------+-----------+-----------+---------+
| f64 | OK | EXT | MISS |
+------+-----------+-----------+---------+
archibate marked this conversation as resolved.
Show resolved Hide resolved

(OK=supported, EXT=require extension, MISS=not supported)


Functions
---------

.. function:: ti.atomic_add(x, y)

This is equivalent to ``x += y``.

:parameter x: (Expr, lvalue) the LHS of addition, also where the result is saved
:parameter y: (Expr) the RHS of addition
:return: (Expr) the original value stored in ``x``

e.g.:
::
x = 3
y = 4
z = ti.atomic_add(x, y)
# now x = 7, y = 4, z = 3


.. function:: ti.atomic_sub(x, y)

This is equivalent to ``x -= y``.


.. function:: ti.atomic_max(x, y)

e.g.:
::
x = 3
y = 4
z = ti.atomic_max(x, y)
# now x = 4, y = 4, z = 3


.. function:: ti.atomic_min(x, y)


.. function:: ti.atomic_or(x, y)

This is equivalent to ``x |= y``.


.. function:: ti.atomic_and(x, y)

This is equivalent to ``x &= y``.


.. function:: ti.atomic_xor(x, y)

This is equivalent to ``x ^= y``.
4 changes: 4 additions & 0 deletions docs/cpp_style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ Don'ts
- ``NULL``, use ``nullptr`` instead.
- ``using namespace std;`` in global scope.
- ``typedef``. Use ``using`` instead.

Automatic code formatting
--------------------------------------------------------------------------------
- Please run ``ti format``
5 changes: 4 additions & 1 deletion docs/global_settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ Global Settings

- Restart the Taichi runtime system (clear memory, destroy all variables and kernels): ``ti.reset()``
- Eliminate verbose outputs: ``ti.get_runtime().set_verbose(False)``
- To specify which GPU to use: ``export CUDA_VISIBLE_DEVICES=0``
- Not to trigger GDB when crashes: ``ti.misc.util.set_gdb_trigger(False)``
- Show more detailed log (TI_TRACE): ``ti.misc.util.set_logging_level(ti.TRACE)``
- To specify which GPU to use for CUDA: ``export CUDA_VISIBLE_DEVICES=0``
- To specify which Arch to use: ``export TI_ARCH=cuda``
17 changes: 17 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ The Taichi Programming Language

external


.. toctree::
:caption: Language
:maxdepth: 3

atomic


.. toctree::
:caption: Structures
:maxdepth: 3

scalar_tensor
vector


.. toctree::
:caption: Advanced Programming
:maxdepth: 3
Expand Down Expand Up @@ -52,6 +68,7 @@ The Taichi Programming Language
dev_install
contributor_guide
cpp_style
performance
internal
faq
acknowledgments
Expand Down
1 change: 1 addition & 0 deletions docs/internal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Vector type system

Intermediate representation
---------------------------------------
Use ``ti.init(print_ir=True)`` to print IR on the console.


Code generation
Expand Down
1 change: 1 addition & 0 deletions docs/linalg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Matrices
- ``ti.Matrix`` is for small matrices (e.g. `3x3`) only. If you have `64x64` matrices, you should consider using a 2D tensor of scalars.
- ``ti.Vector`` is the same as ``ti.Matrix``, except that it has only one column.
- Differentiate element-wise product ``*`` and matrix product ``@``.
- ``ti.Vector(n, dt=ti.f32)`` or ``ti.Matrix(n, m, dt=ti.f32)``.
archibate marked this conversation as resolved.
Show resolved Hide resolved
- ``ti.transposed(A)`` or simply ``A.T()``
- ``ti.inverse(A)``
- ``ti.Matrix.abs(A)``
Expand Down
58 changes: 58 additions & 0 deletions docs/scalar_tensor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. _scalar_tensor:

Tensor of scalars
=================


Creation
--------

.. function:: ti.var(dt, shape = None)

:parameter dt: (DataType) type of the tensor element
:parameter shape: (optional, scalar or tuple) the shape of tensor

This creates a 4x3 tensor called ``x`` with ``float32`` elements in GPU memory:
::
x = ti.var(ti.f32, shape=(4, 3))

If shape is ``()``, then a scalar is created:
::
x = ti.var(ti.f32, shape=())

If ``shape`` is not provided then you must *place* the variable later yourself:
::
x = ti.var(ti.f32)
ti.root.dense(ti.ij, (4, 3)).place(x)

The about two are equivalent.


.. note::

All variables should be created and *placed* before any kernel invocation or any of them accessed from python-scope

For example:

.. code-block:: python

x = ti.var(ti.f32)
x[None] = 233 # ERROR: x not placed!

.. code-block:: python

x = ti.var(ti.f32, shape=())
@ti.kernel
def func():
x[None] = 233

func()
y = ti.var(ti.f32, shape=())
# ERROR: cannot create tensor after kernel invocated!

.. code-block:: python

x = ti.var(ti.f32, shape=())
x[None] = 233
y = ti.var(ti.f32, shape=())
# ERROR: cannot create tensor after accessed from python-scope!
2 changes: 1 addition & 1 deletion docs/sparse.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. _sparse:

Sparse computation
Sparse computation (WIP)
===============================================

.. warning::
Expand Down
2 changes: 2 additions & 0 deletions docs/tensor_matrix.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _tensor:

Tensors and matrices
==========================

Expand Down
36 changes: 36 additions & 0 deletions docs/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,47 @@ Supported types
---------------------------------------
Currently, supported basic types in Taichi are

- int8 ``ti.i8``
- int16 ``ti.i16``
- int32 ``ti.i32``
- int64 ``ti.i64``
- uint8 ``ti.u8``
- uint16 ``ti.u16``
- uint32 ``ti.u32``
- uint64 ``ti.u64``
- float32 ``ti.f32``
- float64 ``ti.f64``

.. note::
Supported types on each backends:

+------+-----------+-----------+---------+
| type | LLVM | OpenGL | Metal |
+======+===========+===========+=========+
| i8 | OK | MISS | OK |
+------+-----------+-----------+---------+
| i16 | OK | MISS | OK |
+------+-----------+-----------+---------+
| i32 | OK | OK | OK |
+------+-----------+-----------+---------+
| i64 | OK | EXT | MISS |
+------+-----------+-----------+---------+
| u8 | OK | MISS | OK |
+------+-----------+-----------+---------+
| u16 | OK | MISS | OK |
+------+-----------+-----------+---------+
| u32 | OK | MISS | OK |
+------+-----------+-----------+---------+
| u64 | OK | MISS | MISS |
+------+-----------+-----------+---------+
| f32 | OK | OK | OK |
+------+-----------+-----------+---------+
| f64 | OK | EXT | MISS |
+------+-----------+-----------+---------+
archibate marked this conversation as resolved.
Show resolved Hide resolved

(OK=supported, EXT=require extension, MISS=not supported)


Boolean types are represented using ``ti.i32``.

Binary operations on different types will give you a promoted type, following the C programming language, e.g.
Expand Down
24 changes: 24 additions & 0 deletions docs/utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ Utilities

TODO: update

GUI system
----------

.. code-block:: python

gui = ti.GUI('Title', (640, 480))
while not gui.is_pressed(ti.GUI.ESCAPE):
gui.set_image(img)
gui.show()


Also checkout https://github.com/taichi-dev/taichi/blob/master/examples/keyboard.py for more advanced event processing.
yuanming-hu marked this conversation as resolved.
Show resolved Hide resolved


Image I/O
---------

.. code-block:: python

img = ti.imread('hello.png')
ti.imshow(img, 'Window Title')
ti.imwrite(img, 'hello2.png')


Logging
-------

Expand Down
Loading