Git Product home page Git Product logo

taichi-dev / taichi Goto Github PK

View Code? Open in Web Editor NEW
24.8K 390.0 2.2K 58.03 MB

Productive, portable, and performant GPU programming in Python.

Home Page: https://taichi-lang.org

License: Apache License 2.0

CMake 1.32% Python 34.86% C++ 56.52% C 5.33% Cuda 0.28% Makefile 0.01% Shell 0.13% GLSL 0.16% PowerShell 0.07% Jupyter Notebook 0.02% Objective-C++ 0.88% Objective-C 0.27% Dockerfile 0.13%
taichi differentiable-programming gpu-programming sparse-computation gpu computer-graphics

taichi's Introduction


Latest Release downloads CI Nightly Release discord invitation link

pip install taichi  # Install Taichi Lang
ti gallery          # Launch demo gallery

What is Taichi Lang?

Taichi Lang is an open-source, imperative, parallel programming language for high-performance numerical computation. It is embedded in Python and uses just-in-time (JIT) compiler frameworks, for example LLVM, to offload the compute-intensive Python code to the native GPU or CPU instructions.

The language has broad applications spanning real-time physical simulation, numerical computation, augmented reality, artificial intelligence, vision and robotics, visual effects in films and games, general-purpose computing, and much more.

...More

Why Taichi Lang?

  • Built around Python: Taichi Lang shares almost the same syntax with Python, allowing you to write algorithms with minimal language barrier. It is also well integrated into the Python ecosystem, including NumPy and PyTorch.
  • Flexibility: Taichi Lang provides a set of generic data containers known as SNode (/ˈsnoʊd/), an effective mechanism for composing hierarchical, multi-dimensional fields. This can cover many use patterns in numerical simulation (e.g. spatially sparse computing).
  • Performance: With the @ti.kernel decorator, Taichi Lang's JIT compiler automatically compiles your Python functions into efficient GPU or CPU machine code for parallel execution.
  • Portability: Write your code once and run it everywhere. Currently, Taichi Lang supports most mainstream GPU APIs, such as CUDA and Vulkan.
  • ... and many more features! A cross-platform, Vulkan-based 3D visualizer, differentiable programming, quantized computation (experimental), etc.

Getting Started

Installation

Prerequisites
  • Operating systems
    • Windows
    • Linux
    • macOS
  • Python: 3.6 ~ 3.10 (64-bit only)
  • Compute backends
    • x64/ARM CPUs
    • CUDA
    • Vulkan
    • OpenGL (4.3+)
    • Apple Metal
    • WebAssembly (experiemental)

Use Python's package installer pip to install Taichi Lang:

pip install --upgrade taichi

We also provide a nightly package. Note that nightly packages may crash because they are not fully tested. We cannot guarantee their validity, and you are at your own risk trying out our latest, untested features. The nightly packages can be installed from our self-hosted PyPI (Using self-hosted PyPI allows us to provide more frequent releases over a longer period of time)

pip install -i https://pypi.taichi.graphics/simple/ taichi-nightly

Run your "Hello, world!"

Here is how you can program a 2D fractal in Taichi:

# python/taichi/examples/simulation/fractal.py

import taichi as ti

ti.init(arch=ti.gpu)

n = 320
pixels = ti.field(dtype=float, shape=(n * 2, n))


@ti.func
def complex_sqr(z):
    return ti.Vector([z[0]**2 - z[1]**2, z[1] * z[0] * 2])


@ti.kernel
def paint(t: float):
    for i, j in pixels:  # Parallelized over all pixels
        c = ti.Vector([-0.8, ti.cos(t) * 0.2])
        z = ti.Vector([i / n - 1, j / n - 0.5]) * 2
        iterations = 0
        while z.norm() < 20 and iterations < 50:
            z = complex_sqr(z) + c
            iterations += 1
        pixels[i, j] = 1 - iterations * 0.02


gui = ti.GUI("Julia Set", res=(n * 2, n))

for i in range(1000000):
    paint(i * 0.03)
    gui.set_image(pixels)
    gui.show()

If Taichi Lang is properly installed, you should get the animation below 🎉:

See Get started for more information.

Build from source

If you wish to try our our experimental features or build Taichi Lang for your own environments, see Developer installation.

Documentation

Community activity Time period

Timeline graph Issue status graph Pull request status graph Trending topics

Contributing

Kudos to all of our amazing contributors! Taichi Lang thrives through open-source. In that spirit, we welcome all kinds of contributions from the community. If you would like to participate, check out the Contribution Guidelines first.

Contributor avatars are randomly shuffled.

License

Taichi Lang is distributed under the terms of Apache License (Version 2.0).

See Apache License for details.

Community

For more information about the events or community, please refer to this page

Join our discussions

Report an issue

Contact us

Reference

Demos

AOT deployment

Lectures & talks

Citations

If you use Taichi Lang in your research, please cite the corresponding papers:

taichi's People

Contributors

ailzhang avatar amesingflank avatar archibate avatar bobcao3 avatar dream189free avatar erizmr avatar fantasyvr avatar feisuzhu avatar frostming avatar g1n0st avatar galeselee avatar jim19930609 avatar k-ye avatar leonz5288 avatar lin-hitonami avatar listerily avatar morcki avatar neozhaoliang avatar penguinliong avatar pgzxb avatar qiao-bo avatar squarefk avatar strongoier avatar taichi-gardener avatar th3charlie avatar turbo0628 avatar writinwaters avatar xumingkuan avatar yolo2themoon avatar yuanming-hu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

taichi's Issues

Travis CI & AppVeyor Support

I'm getting tired testing the environment on all the 3 platforms and I think it's better to have CIs for Taichi. Please let me know it you have any suggestion on this topic or want to help realize it. Thank you. It looks that Travis CI for Linux and Mac OSX and AppVeyor for Windows are suitable choices.

MacOSX: problem report of nbody_3d.py

On MacOSX(10.11.6), some errors will happen when execute nbody_3d.py.
I fixed them in a not clever way, but it works for me.

Traceback (most recent call last):
 File "nbody_3d.py", line 1, in <module>
   from taichi.dynamics.nbody import NBody
 File "/Users/YJ-work/Desktop/taichi_root/taichi/python/taichi/dynamics/nbody.py", line 6, in <module>
   from taichi.tools.video import VideoManager
 File "/Users/YJ-work/Desktop/taichi_root/taichi/python/taichi/tools/video.py", line 1, in <module>
   from taichi import ndarray_to_array2d
ImportError: cannot import name ndarray_to_array2d

I replaced from taichi import ndarray_to_array2d with from taichi.misc.util import ndarray_to_array2d in taichi.tools.video.

[Errno 2] No such file or directory: '/Users/YJ-work/Desktop/taichi_root//taichi_outputs///task-2017-01-10-21-51-00-r07015'
Simulation time: 0.0
nbody.cpp[201]: node_end = 297117
Time: 0.0983819961548
Segmentation fault: 11

I replaced self.directory = taichi.get_output_path(get_unique_task_id()) with a full path self.directory = '/Users/YJ-work/Desktop/taichi_root/taichi/output/' in taichi.dynamics.nbody

Traceback (most recent call last):
  File "nbody_3d.py", line 6, in <module>
    nbody.step(0.01)
  File "/Users/YJ-work/Desktop/taichi_root/taichi/python/taichi/dynamics/nbody.py", line 49, in step
    img = LDRDisplay(exposure=1, adaptive_exposure=False).process(img)
NameError: global name 'LDRDisplay' is not defined

I added from taichi.visual.post_process import LDRDisplay in taichi.dynamics.nbody.

Traceback (most recent call last):
  File "nbody_3d.py", line 6, in <module>
    nbody.step(0.01)
  File "/Users/YJ-work/Desktop/taichi_root/taichi/python/taichi/dynamics/nbody.py", line 53, in step
    self.video_manager.write_frame(img)
  File "/Users/YJ-work/Desktop/taichi_root/taichi/python/taichi/tools/video.py", line 18, in write_frame
    ndarray_to_array2d(img).write(self.directory + '/%05d.png' % self.frame_counter)
AttributeError: 'NoneType' object has no attribute 'write'

I commented out self.video_manager.write_frame(img) in taichi.dynamics.nbody.

Maybe there is a clever way to fix this problem.

BTW, I got this output (one of those frames)
image
Is it correct?

Issue with building on ubuntu 14.04

Keep getting this issue when installing it with make -j 2

fatal error: taichi/dynamics/poisson_solver2D.h: No such file or directory
#include <taichi/dynamics/poisson_solver2D.h>
^
compilation terminated.
make[2]: *** [CMakeFiles/taichi_core.dir/src/simulation3d/poisson_solver2d.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/taichi_core.dir/all] Error 2
make: *** [all] Error 2

Documentation update for installing on Ubuntu 16.10

I followed the 16.04 instructions to install on a new Ubuntu 16.10 VM but the library ended up being linked with -lpython3.5m and would not work.

To link with python 2.7 I had to use this cmake command:

cmake \
  -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python2.7 \
  -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python2.7 \
  -DPYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython2.7.so \
  ..

taichi_core.so: undefined symbol: __cpu_model on Ubuntu 16.04

Taichi won't import:

/home/janvorac/wheel/packages/taichi/taichi/python/taichi/core/load_core.py in <module>()
     29         sys.path.append(bin_dir)
     30         shutil.copy('libtaichi_core.so', 'taichi_core.so')
---> 31         import taichi_core as tc_core
     32 
     33         os.chdir(tmp_cwd)

ImportError: ./taichi_core.so: undefined symbol: __cpu_model

Installed using your wiki guide on XUbuntu 16.04.02. I am using Python 2.7.12 in virtual environment downloaded via mkvirtualenv (not compiled on my PC).
My gcc/g++ version is 5.4.0, cmake version is 3.5.1. Any help would be welcome!

[macOS] some build errors

I'm using Xcode building the project, but caught these errors:

1. boost header including error:

fatal error: 'boost/foreach.hpp' file not found

Fixed by adding the boost including path to "search paths".

2. a link error:

clang: error: no such file or directory: '/Users/Iterator/homebrew/Cellar/python/2.7.8_1/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib'

It seems that I should change "/Users/Iterator/homebrew" to my own path(in Build Settings--Other Linker Flags).
For me, it is "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib"

Rename Mesh

They should be objects...Mesh should be used for triangle meshes.

Browser viewer

It would be good to have an additional browser viewer for rendering/simulation process visualization. Python itself has good HTTP server support and it will help in case people use Taichi for some task via ssh and do not want to enable X11 forwarding.

MacOSX: unsafe use of relative rpath libboost_system.dylib

After I built libtaichi_core.dylib and run the test code, I have this error

>>> import taichi as tc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/YJ-work/Desktop/taichi_root/taichi/python/taichi/__init__.py", line 1, in <module>
    from taichi.core import tc_core as core
  File "/Users/YJ-work/Desktop/taichi_root/taichi/python/taichi/core/__init__.py", line 2, in <module>
    from load_core import tc_core
  File "/Users/YJ-work/Desktop/taichi_root/taichi/python/taichi/core/load_core.py", line 18, in <module>
    import taichi_core as tc_core
ImportError: dlopen(./taichi_core.so, 2): Library not loaded: libboost_system.dylib
  Referenced from: /Users/YJ-work/Desktop/taichi_root/taichi/build/taichi_core.so
  Reason: unsafe use of relative rpath libboost_system.dylib in ./taichi_core.so with restricted binary

I googled and found the problem is in libtaichi_core.dylib:

aibm8:build YJ-work$ otool -L libtaichi_core.dylib 
libtaichi_core.dylib:
	/Users/YJ-work/Desktop/taichi_root/taichi/build/libtaichi_core.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
	/opt/local/lib/libembree.2.dylib (compatibility version 2.0.0, current version 2.13.0)
	/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
	/opt/local/lib/libboost_system-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
	/opt/local/lib/libboost_python-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
	libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)
	libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)

And I changed the path libboost_system.dylib, libboost_python.dylib to:

/opt/local/lib/libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/local/lib/libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0)

then the error is gone.
The problem is: every time I rebuild libtaichi_core.dylib, I have to repeat the above things again.
Is there any way to solve this problem?

/opt/local/lib is where I put libboost_system.dylib and libboost_python.dylib.

Documentation

I plan to first have the documentation on the Python part, so that people can use it. The doc for C++ part will be put lower priority.

Merge taichi-research

I'm sorry that this taichi hasn't been updated for a while. This is because I used it for my research and some part of code cannot be open source before the paper is published. However, I'll merge research-unrelated part into this repos.

test.py failed on MacOSX

The 13th line of test.py
show_image('img', img)
doesn't work. It never response.
taichi_test_1

When I comment out show_image('img', img), the program ends correctly.
taichi_test_2

Maybe there is something wrong with show_image?

vfx missing in 2d examples

/taichi/python/examples/2d   master ●  for fn in *.py; do echo $fn;python3 $fn;done
color_schemes.py
composer.py
fluid_simulator.py
Traceback (most recent call last):
  File "fluid_simulator.py", line 1, in <module>
    from .levelset import LevelSet2D
SystemError: Parent module '' not loaded, cannot perform relative import
__init__.py
levelset.py
mcmc.py
16 @9.9999%
^CTraceback (most recent call last):
  File "mcmc.py", line 150, in <module>
    mh()
  File "mcmc.py", line 27, in mh
    acceptance = min(eval(y) / eval(x), 1)
KeyboardInterrupt
mpm_simulator.py
Traceback (most recent call last):
  File "mpm_simulator.py", line 3, in <module>
    from .levelset import LevelSet2D
SystemError: Parent module '' not loaded, cannot perform relative import
polygons.py
run_fluid_fancy.py
Traceback (most recent call last):
  File "run_fluid_fancy.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_fluid.py
Traceback (most recent call last):
  File "run_fluid.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_levelset.py
Traceback (most recent call last):
  File "run_levelset.py", line 1, in <module>
    import pyglet
ImportError: No module named 'pyglet'
run_mpm_balance.py
Traceback (most recent call last):
  File "run_mpm_balance.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_elastic.py
Traceback (most recent call last):
  File "run_mpm_elastic.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_sand_friction_angle.py
Traceback (most recent call last):
  File "run_mpm_sand_friction_angle.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_sand_hourglass.py
Traceback (most recent call last):
  File "run_mpm_sand_hourglass.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_sand.py
Traceback (most recent call last):
  File "run_mpm_sand.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_snow.py
Traceback (most recent call last):
  File "run_mpm_snow.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_snow_smash.py
Traceback (most recent call last):
  File "run_mpm_snow_smash.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_snow_sticky.py
Traceback (most recent call last):
  File "run_mpm_snow_sticky.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_title.py
Traceback (most recent call last):
  File "run_mpm_title.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_tree.py
Traceback (most recent call last):
  File "run_mpm_tree.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_words.py
Traceback (most recent call last):
  File "run_mpm_words.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_smoke_ball.py
Traceback (most recent call last):
  File "run_smoke_ball.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_smoke.py
Traceback (most recent call last):
  File "run_smoke.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
simulation_window.py
Traceback (most recent call last):
  File "simulation_window.py", line 4, in <module>
    import pyglet
ImportError: No module named 'pyglet'
simulator.py

go language binding / port

Hello. Will support this iterator for go language? I also have own path tracing, but for different purpose, so have no much functions. I know fogleman but I seen your iterator more advanced.

nbody example fails

~/taichi/taichi/python/examples/simulation$ python nbody_3d.py

[Errno 2] No such file or directory: '../output/frames/task-2017-01-05-20-58-23-r03610/'
Simulation time: 0.0
nbody.cpp[201]: node_end = 297117
Time: 0.139370918274
Segmentation fault (core dumped)

I think the error is nbody.py where this line:
self.directory = '../output/frames/' + get_uuid() + '/'

Maybe should be:
self.directory = tc.get_root_directory() + 'output/frames/' + get_uuid() + '/'

added this:
import taichi as tc

but then get this error:

python nbody_3d.py 
[Errno 2] No such file or directory: '/home/me/taichi/output/frames/task-2017-01-05-21-19-15-r07527/'
Simulation time: 0.0
nbody.cpp[201]: node_end = 297117
Time: 0.115436077118
Segmentation fault (core dumped)

as if it cannot os.mkdir(self.directory)

Switch to C++17 when it's time

Getting tired dealing with templates and if constexpr would be a great help. We should make the switch when all platforms have C++17 ready.

MacOSX ImportError: No module named taichi

Hi, I built libtaichi_core.dylib successfully, following the Mac OS X part of Wiki.
But when I run
$python2.7
>>> import taichi as tc
I got

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named taichi

What should I do?

CMakeList 中Boost大小写问题

include_directories(${BOOST_INCLUDE_DIRS})
中Boost是全大写,但是
find_package(Boost COMPONENTS system python REQUIRED)
中Boost是区分大小写,导致osx下无法寻找到正确的路径

PyPI support

It would be great if users can install Taichi just by

pip install taichi

Actually I had a try days ago but it's interesting that I can only package the *.py files in taichi/python/, even if I added the rest to MANIFEST.in.

If you have any idea on what's going on, please let me know.
Thanks!

Some examples fail on macOS

They all seem to fail with the same assertion:

$ python bubbles.py
asset_manager.h@(Ln 20): Assertion Failed. [Asset has been expired]

My taichi is compiled against Python 2.7.13, boost 1.6.13, embree 2.13.0, and tbb 4.4-20161128.

The examples that do work are:

  • geometry
  • scoping
  • trees

Better software architecture?

Maybe taichi could be split into several modules:

  1. (Module A) C++ graphics rendering engine: Given a 3D scene in a standard data format (e.g. the one in taichi/blender/exporter/__init__.py), the engine calculates a rasterised image. This rendering engine could be used interchangeably with other rendering engines.

  2. (Module B) Python library to procedurally generate a 3D scene. The output is given in a standard data format, and can be fed into any graphics rendering engine.

  3. (Module B) C++ physics simulation: given some parameters, calculates a series of scenes. This part could be integrated into Module B: this can be seen as a specific way to generate 3D scenes.

  4. (Module C) A seperate Python library to handle realtime preview and program hot reloading, for any Python program that generates a series of images. We don't need to have lovecat integrated into Module C.

  5. (Module D) A set of demos that is built upon Module B, Module C and lovecat. Binary asset files could go into Module D.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.