Giter VIP home page Giter VIP logo

quantaichi's Introduction

QuanTaichi: A Compiler for Quantized Simulations (SIGGRAPH 2021)

Yuanming Hu, Jiafeng Liu, Xuanda Yang, Mingkuan Xu, Ye Kuang, Weiwei Xu, Qiang Dai, William T. Freeman, Fredo Durand

[Paper] [Video]

The QuanTaichi framework is now officially part of Taichi. This repo only contains examples.

Updates: Examples are now compatible with Taichi v1.1.0. Please update Taichi if you are using an old version.

Simulate more with less memory, using a quantization compiler.

High-resolution simulations can deliver great visual quality, but they are often limited by available memory. We present a compiler for physical simulation that can achieve both high performance and significantly reduced memory costs, by enabling flexible and aggressive quantization.

To achieve that, we implemented an extension of the type system in Taichi. Now, programmers can define custom data types using the following code:

i8 = ti.types.quant.int(bits=8, signed=True)
qfixed12 = ti.types.quant.fixed(frac=12, signed=False, range=3.0)
qfloat16 = ti.types.quant.float(exp=5, frac=11, signed=True)

The compiler will automatically encode/decode numerical data to achieve an improved memory efficiency (storage & bandwidth). Since custom data types are not natively supported by hardware, we propose two useful types of bit adapters: Bit structs and Bit arrays to pack thses types into hardware supported types with bit width 8, 16, 32, 64. For example, The following code declears 2 fields with custom types, and materialized them into two 2D 4 x 2 arrays with Bit structs:

u4 = ti.types.quant.int(bits=4, signed=False)
i12 = ti.types.quant.int(bits=12, signed=True)
p = ti.field(dtype=u4)
q = ti.field(dtype=i12)
ti.root.dense(ti.ij, (4, 2)).bit_struct(num_bits=16).place(p, q)

The p and q fields are laid in an array of structure (AOS) order in memory. Note the containing bit struct of a (p[i, j], q[i, j]) tuple is 16-bit wide. For more details of the usage of our quantization type system, please refer to our paper or see the examples in this repo.

Under proper quantization, we achieve 8× higher memory efficiency on each Game of Life cell, 1.57× on each Eulerian fluid simulation voxel, and 1.7× on each material point method particle. To the best of our knowledge, this is the first time these high-resolution simulations can run on a single GPU. Our system achieves resolution, performance, accuracy, and visual quality simultaneously.

How to run

Install Taichi 1.6.0 first.

Install Taichi 1.6.0 by:

python3 -m pip install —U taichi==1.6.0

Game of Life (GoL)

gol_pic

To reproduce the GOL galaxy:

cd gol && python3 galaxy.py -a [cpu/cuda] -o output

We suggest you run the script using GPU (--arch cuda). Because to better observe the evolution of metapixels, we set the steps per frame to be 32768 which will take quite a while on CPUs.

To reproduce the super large scale GoL:

  1. Download the pattern quant_sim_meta.rle from our Google Drive and place it in the same folder with quant_sim.py

  2. Run the code

python3 quant_sim.py -a [cpu/cuda] -o output

For more details, please refer to this documentation.

MLS-MPM

mpm-pic

To test our system on hybrid Lagrangian-Eulerian methods where both particles and grids are used, we implemented the Moving Least Squares Material Point Method with G2P2G transfer. The latest version is now maintained at Taichi Elements.

Eulerian Fluid

smoke_simulation

We developed a sparse-grid-based advection-reflection fluid solver to evaluate our system on grid-based physical simulators.

To reproduce the large scale smoke simulation demo, please first change the directory into eulerain_fluid, and run:

python3 run.py --demo [0/1] -o outputs

Set the arg of demo to 0 for the bunny demo and 1 for the flow demo. -o outputs means the set the output folder to outputs.

For more comparisons of this quantized fluid simulation, please refer to the documentation of this demo.

Microbenchmarks

To reproduce the experiments of microbenchmarks, please run

cd microbenchmarks
chmod +x run_microbenchmarks.sh
./run_microbenchmarks.sh

Please refer to this Readme to get more details.

Bibtex

@article{hu2021quantaichi,
  title={QuanTaichi: A Compiler for Quantized Simulations},
  author={Hu, Yuanming and Liu, Jiafeng and Yang, Xuanda and Xu, Mingkuan and Kuang, Ye and Xu, Weiwei and Dai, Qiang and Freeman, William T. and Durand, Frédo},
  journal={ACM Transactions on Graphics (TOG)},
  volume={40},
  number={4},
  year={2021},
  publisher={ACM}
}

quantaichi's People

Contributors

feisuzhu avatar hanke98 avatar jim19930609 avatar lin-hitonami avatar strongoier avatar th3charlie 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

quantaichi's Issues

Field with dim 2 accessed with indices of dim 3 error in eulerian fluid demo

Reproduction:

Under eulerian_fluid, deflate the tarball under input and run demo.py, the compiler complains that a 2D field is accessed with a 3D index.

Traceback

[Taichi] version 1.3.0, llvm 15.0.4, commit 0f25b95e, linux, python 3.8.13
cmd args: Namespace(advect='mc', debug=False, demo_id=0, dim=2, dye_type=0, frames=10000, outdir=None, quant_all=False, quant_dye=False, quant_v=False, res=512, rk=3, visualize=False)
[Taichi] Starting on arch=cuda
Level 0
  coarsened_grid_size 1024
  coarsened_offset (-512, -512)

  sparse_grid_size 1040
  sparse_offset [-520, -520]
Level 1
  coarsened_grid_size 512
  coarsened_offset [-256, -256]

  sparse_grid_size 528
  sparse_offset [-264, -264]
Level 2
  coarsened_grid_size 256
  coarsened_offset [-128, -128]

  sparse_grid_size 272
  sparse_offset [-136, -136]
Level 3
  coarsened_grid_size 128
  coarsened_offset [-64, -64]

  sparse_grid_size 144
  sparse_offset [-72, -72]
Traceback (most recent call last):
  File "demo.py", line 99, in <module>
    solver = FluidSolver(
  File "/home/taichigraphics/work/taichi-repos/quantaichi/eulerian_fluid/solver.py", line 231, in __init__
    self.set_custom_source(res=640)
  File "/home/taichigraphics/work/taichi-repos/quantaichi/eulerian_fluid/solver.py", line 578, in set_custom_source
    self.set_custom_source_helper(self.dye[0].field, self.density_source[k],
  File "/home/taichigraphics/miniconda3/envs/taichi/lib/python3.8/site-packages/taichi/lang/kernel_impl.py", line 1008, in __call__
    raise type(e)('\n' + str(e)) from None
taichi.lang.exception.TaichiIndexError:
File "/home/taichigraphics/work/taichi-repos/quantaichi/eulerian_fluid/solver.py", line 573, in set_custom_source_helper:
                dyef[k - self.res // 2, i - self.res // 2,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     j - self.res // 2] = [0., 0.5, 1.0]
                     ^^^^^^^^^^^^^^^^^^
Field with dim 2 accessed with indices of dim 3

cannot run the demo successfully

some errors when I run the Eulerian fluid demo.

  1. KeyError: 'Unrecognized keyword argument(s) for ti.init: use_unified_memory' ---> delete this argument

  2. cft = ti.quant.fixed(frac=21, signed=True, range=2**5) TypeError: fixed() got an unexpected keyword argument 'range' ----> delete range argument

  3. AttributeError: 'MatrixField' object has no attribute 'get_field_members'

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.