
Python嵌入式高性能并行编程语言
Taichi是一款嵌入Python的开源并行编程语言,专注高性能 数值计算。它利用LLVM等即时编译器将Python代码转译为GPU或CPU指令,支持CUDA、Vulkan等多种后端。Taichi以其灵活性、高性能和跨平台特性,广泛应用于物理模拟、数值分析、AR和AI等领域。
<a href="https://discord.gg/f25GRdXRfg"><img alt="Discord邀请链接" src="https://dcbadge.vercel.app/api/server/f25GRdXRfg?style=flat"></a>
pip install taichi # 安装太极编程语言 ti gallery # 启动演示画廊
太极是一种开源的、命令式的、并行编程语言,专为高性能数值计算而设计。它嵌入在Python中,使用即时编译(JIT)框架(如LLVM)将计算密集型的Python代码编译为原生的GPU或CPU指令。
<a href="https://github.com/taichi-dev/taichi/blob/master/python/taichi/examples/simulation/fractal.py#L1-L31"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/2f590456-3123-4b25-8060-8cbf64f81a81.png" height="270px"></a> <img src="https://yellow-cdn.veclightyear.com/835a84d5/3a364ebf-b671-4bc5-a365-6fdd1bb6369b.gif" height="270px">
该语言有广泛的应用,涵盖实时物理模拟、数值计算、增强现实、人工智能、视觉和机器人技术、电影和游戏中的视觉效果、通用计算等多个领域。
<a href="https://github.com/taichi-dev/taichi/blob/master/python/taichi/examples/simulation/mpm128.py"><img src="https://yellow-cdn.veclightyear.com/835a84d5/4115a3bb-16d9-4e92-b985-16f5c6e9740b.gif" height="192px"></a> <a href="https://github.com/taichi-dev/quantaichi"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/1934f4bc-cc10-4645-bed7-0d3b84c3c0c7.gif" height="192px"></a> <a href="https://github.com/taichi-dev/taichi/blob/master/python/taichi/examples/rendering/sdf_renderer.py"><img src="https://yellow-cdn.veclightyear.com/835a84d5/b89d757c-d8aa-4a1b-9070-e792268a5b3e.jpg" height="192px"></a> <a href="https://github.com/taichi-dev/taichi/blob/master/python/taichi/examples/simulation/euler.py"><img src="https://yellow-cdn.veclightyear.com/835a84d5/7fc6b7d3-e43d-4685-94e8-ae4013badd59.gif" height="192px"></a>
<a href="https://github.com/taichi-dev/quantaichi"><img src="https://yellow-cdn.veclightyear.com/835a84d5/bf31a59a-9bf6-4107-bf4d-0e96fcf81bf5.gif" height="213px"></a> <a href="https://github.com/taichi-dev/quantaichi"><img src="https://yellow-cdn.veclightyear.com/835a84d5/400ef398-b59a-48ad-87d1-1aa3b3905e01.gif" height="213px"></a>
@ti.kernel装饰器,太极编程语言的JIT编译器自动将你的Python函数编译成高效的GPU或CPU机器码,以实现并行执行。使用Python的包安装器pip来安装太极编程语言:
pip install --upgrade taichi
我们还提供每日构建版本。请注意,每日构建版本可能会崩溃,因为它们没有经过完全测试。我们不能保证它们的有效性,使用我们最新的、未经测试的功能需要你自担风险。每 日构建版本可以从我们的自托管PyPI安装(使用自托管PyPI允许我们在更长的时间内提供更频繁的发布)
pip install -i https://pypi.taichi.graphics/simple/ taichi-nightly
以下是你如何用太极编程语言编写一个2D分形:
# 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: # 对所有像素并行化 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()
如果太极编程语 言安装正确,你应该会看到下面的动画 🎉:
<a href="https://github.com/taichi-dev/taichi/blob/master/python/taichi/examples/simulation/fractal.py#L1-L31"> </a><img src="https://yellow-cdn.veclightyear.com/835a84d5/3a364ebf-b671-4bc5-a365-6fdd1bb6369b.gif" height="270px">
更多信息请参见入门指南。
如果你想尝试我们的实验性功能或为你自己的环境构建太极编程语言,请参阅开发者安装指南。
向所有杰出的贡献者致敬!太极语言通过开源蓬勃发展。本着这种精神,我们欢迎社区的各种贡献。如果您想参与,请先查看贡献指南。
<a href="https://github.com/taichi-dev/taichi/graphs/contributors"><img src="https://yellow-cdn.veclightyear.com/835a84d5/498385b6-840a-4b18-a21b-c3e5888c1827.png" width="800px"></a>
贡献者头像随机排列。
太极语言在Apache许可证(版本2.0)条款下分发。
详情请参阅Apache许可证。
有关活动或社区的更多信息,请参阅此页面
如果您在研究中使用太极语言,请引用相应的论文: