├── .clang-format ├── .clang-tidy ├── .git-blame-ignore-revs ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ ├── document.md │ ├── feature_request.md │ └── question.md ├── actionlint.yaml ├── pull_request_template.md └── workflows │ ├── build.yaml │ ├── cache.yml │ ├── ghstack_land.yml │ ├── initiator.yaml │ ├── issue_comment.yml │ ├── issue_open.yml │ ├── notify_on_failure.yml │ ├── perf.yml │ ├── pull_request.yml │ ├── release.yml │ ├── scripts │ ├── aot-demo.sh │ ├── build.py │ ├── check_clang_tidy.sh │ ├── common-utils.ps1 │ ├── common-utils.sh │ ├── ghstack-perm-check.py │ ├── post-benchmark-to-github-pr.py │ ├── sync-cache.py │ ├── ti_build │ │ ├── __init__.py │ │ ├── alter.py │ │ ├── android.py │ │ ├── bootstrap.py │ │ ├── cmake.py │ │ ├── compiler.py │ │ ├── dep.py │ │ ├── entry.py │ │ ├── escapes.py │ │ ├── ios.py │ │ ├── llvm.py │ │ ├── misc.py │ │ ├── ospkg.py │ │ ├── python.py │ │ ├── sccache.py │ │ ├── tinysh.py │ │ └── vulkan.py │ ├── unix-perf-mon.sh │ ├── unix-test-docs.sh │ ├── unix_aot_compat_test.sh │ ├── unix_test.sh │ └── win_test.ps1 │ └── testing.yml ├── .gitignore ├── .gitmodules ├── .pre-commit-config.yaml ├── .pylintrc ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── benchmarks ├── README.md ├── deserialize.py ├── microbenchmarks │ ├── __init__.py │ ├── _items.py │ ├── _metric.py │ ├── _plan.py │ ├── _utils.py │ ├── atomic_ops.py │ ├── fill.py │ ├── math_opts.py │ ├── matrix_ops.py │ ├── memcpy.py │ ├── saxpy.py │ └── stencil2d.py ├── requirements.txt ├── run.py ├── suite_microbenchmarks.py └── utils.py ├── build.py ├── c_api ├── .gitignore ├── cmake │ └── FindTaichi.cmake ├── docs │ └── taichi │ │ ├── taichi_core.h.md │ │ └── taichi_vulkan.h.md ├── include │ └── taichi │ │ ├── cpp │ │ └── taichi.hpp │ │ ├── taichi.h │ │ ├── taichi_core.h │ │ ├── taichi_cpu.h │ │ ├── taichi_cuda.h │ │ ├── taichi_metal.h │ │ ├── taichi_opengl.h │ │ ├── taichi_platform.h │ │ ├── taichi_unity.h │ │ └── taichi_vulkan.h ├── src │ ├── c_api_test_utils.cpp │ ├── c_api_test_utils.h │ ├── taichi_core_impl.cpp │ ├── taichi_core_impl.h │ ├── taichi_gfx_impl.cpp │ ├── taichi_gfx_impl.h │ ├── taichi_llvm_impl.cpp │ ├── taichi_llvm_impl.h │ ├── taichi_metal_impl.h │ ├── taichi_metal_impl.mm │ ├── taichi_opengl_impl.cpp │ ├── taichi_opengl_impl.h │ ├── taichi_vulkan_impl.cpp │ └── taichi_vulkan_impl.h ├── taichi.json ├── tests │ ├── c_api_aot_test.cpp │ ├── c_api_behavior_test.cpp │ ├── c_api_cgraph_test.cpp │ ├── c_api_interface_test.cpp │ ├── c_api_interop_test.cpp │ ├── c_api_numerical_test.cpp │ ├── comet.cpp │ ├── gtest_fixture.h │ ├── mpm88_test.cpp │ ├── sph.cpp │ └── taichi_sparse_test.cpp ├── unity │ └── .gitkeep └── version_scripts │ ├── README.md │ ├── export_symbols_linux.lds │ └── export_symbols_mac.lds ├── ci ├── .gitignore ├── Dockerfile.tpl ├── assets │ └── mitm-ca.crt ├── build-images ├── fix-ci-image-version └── scripts │ └── release_test.sh ├── cmake ├── CMakeGraphVizOptions.cmake ├── Distributed.cmake ├── PythonNumpyPybind11.cmake ├── TaichiCAPI.cmake ├── TaichiCAPITests.cmake ├── TaichiCXXFlags.cmake ├── TaichiConfig.cmake.in ├── TaichiCore.cmake ├── TaichiExamples.cmake ├── TaichiTargets.cmake ├── TaichiTests.cmake └── utils.cmake ├── conda ├── README.md ├── conda_env.yaml ├── scripts │ └── activate_env_vars.sh └── update_env_vars.sh ├── cpp_examples ├── aot_save.cpp ├── autograd.cpp ├── rhi_examples │ ├── CMakeLists.txt │ ├── common_metal.h │ ├── common_metal.mm │ ├── common_vulkan.h │ ├── sample_1_window.cpp │ ├── sample_2_triangle.cpp │ ├── sample_3_textured_triangle.cpp │ └── shaders │ │ ├── 2_triangle.frag │ │ ├── 2_triangle.frag.spv.h │ │ ├── 2_triangle.vert │ │ ├── 2_triangle.vert.spv.h │ │ ├── 3_triangle.frag │ │ ├── 3_triangle.frag.spv.h │ │ ├── 3_triangle.vert │ │ └── 3_triangle.vert.spv.h └── run_snode.cpp ├── docs ├── conftest.py ├── cover-in-ci.lst ├── design │ └── llvm_sparse_runtime.md ├── fragments │ └── .gitkeep ├── lang │ └── articles │ │ ├── about │ │ ├── _category_.json │ │ └── overview.md │ │ ├── advanced │ │ ├── _category_.json │ │ ├── argument_pack.md │ │ ├── data_oriented_class.md │ │ ├── dataclass.md │ │ ├── meta.md │ │ ├── odop.md │ │ └── quant.md │ │ ├── basic │ │ ├── _category_.json │ │ ├── external.md │ │ ├── field.md │ │ ├── layout.md │ │ ├── ndarray.md │ │ ├── offset.md │ │ └── sparse.md │ │ ├── c-api │ │ ├── _category_.json │ │ ├── taichi_core.md │ │ └── taichi_vulkan.md │ │ ├── contribution │ │ ├── _category_.json │ │ ├── contributor_guide.md │ │ ├── dev_install.md │ │ ├── developer_utilities.md │ │ ├── development_tips.md │ │ ├── doc_writing.md │ │ ├── style_guide_en.md │ │ ├── windows_debug.md │ │ ├── write_test.md │ │ └── writing_cpp_tests.md │ │ ├── debug │ │ ├── _category_.json │ │ └── debugging.md │ │ ├── deployment │ │ ├── _category_.json │ │ └── tutorial.md │ │ ├── differentiable │ │ ├── _category_.json │ │ └── differentiable_programming.md │ │ ├── faqs │ │ ├── _category_.json │ │ ├── faq.md │ │ └── install.md │ │ ├── get-started │ │ ├── _category_.json │ │ ├── accelerate_python.md │ │ ├── accelerate_pytorch.md │ │ ├── cloth_simulation.md │ │ └── hello_world.md │ │ ├── glossary │ │ ├── _category_.json │ │ └── glossary.md │ │ ├── internals │ │ ├── _category_.json │ │ ├── compilation.md │ │ ├── internal.md │ │ └── life_of_kernel_lowres.jpg │ │ ├── kernels │ │ ├── _category_.json │ │ ├── kernel_function.md │ │ └── kernel_sync.md │ │ ├── math │ │ ├── _category_.json │ │ ├── linear_solver.md │ │ ├── math_module.md │ │ └── sparse_matrix.md │ │ ├── performance_tuning │ │ ├── _category_.json │ │ ├── performance.md │ │ └── profiler.md │ │ ├── reference │ │ ├── _category_.json │ │ ├── differences_between_taichi_and_python_programs.md │ │ ├── global_settings.md │ │ ├── language_reference.md │ │ ├── operator.md │ │ ├── simt.md │ │ └── syntax_sugars.md │ │ ├── static │ │ └── assets │ │ │ ├── aot_tutorial.png │ │ │ ├── arrow_field.png │ │ │ ├── arrows.png │ │ │ ├── bitpacked_fields_layout_example.png │ │ │ ├── bls_indices_mapping.png │ │ │ ├── circles.png │ │ │ ├── colored_circles.png │ │ │ ├── effect_of_offline_cache.png │ │ │ ├── floating-point_formats.png │ │ │ ├── fractal.png │ │ │ ├── lines.png │ │ │ ├── point_field.png │ │ │ ├── quant_array_layout_example.png │ │ │ ├── rect.png │ │ │ ├── runtime.png │ │ │ └── triangles.png │ │ ├── type_system │ │ ├── _category_.json │ │ └── type.md │ │ ├── utilities │ │ └── _category_.json │ │ └── visualization │ │ ├── _category_.json │ │ ├── export_results.md │ │ ├── ggui.md │ │ └── gui_system.md ├── rfcs │ ├── 20220410-rfc-process.md │ ├── 20220413-aot-for-all-snode.md │ ├── res │ │ └── .gitkeep │ └── yyyymmdd-rfc-template.md └── variable.json ├── external ├── amdgpu_libdevice │ ├── ockl.bc │ ├── oclc_abi_version_400.bc │ ├── oclc_correctly_rounded_sqrt_off.bc │ ├── oclc_daz_opt_off.bc │ ├── oclc_finite_only_off.bc │ ├── oclc_isa_version_1010.bc │ ├── oclc_isa_version_1011.bc │ ├── oclc_isa_version_1012.bc │ ├── oclc_isa_version_1013.bc │ ├── oclc_isa_version_1030.bc │ ├── oclc_isa_version_1031.bc │ ├── oclc_isa_version_1032.bc │ ├── oclc_isa_version_1033.bc │ ├── oclc_isa_version_1034.bc │ ├── oclc_isa_version_1035.bc │ ├── oclc_isa_version_600.bc │ ├── oclc_isa_version_601.bc │ ├── oclc_isa_version_602.bc │ ├── oclc_isa_version_700.bc │ ├── oclc_isa_version_701.bc │ ├── oclc_isa_version_702.bc │ ├── oclc_isa_version_703.bc │ ├── oclc_isa_version_704.bc │ ├── oclc_isa_version_705.bc │ ├── oclc_isa_version_801.bc │ ├── oclc_isa_version_802.bc │ ├── oclc_isa_version_803.bc │ ├── oclc_isa_version_805.bc │ ├── oclc_isa_version_810.bc │ ├── oclc_isa_version_900.bc │ ├── oclc_isa_version_902.bc │ ├── oclc_isa_version_904.bc │ ├── oclc_isa_version_906.bc │ ├── oclc_isa_version_908.bc │ ├── oclc_isa_version_909.bc │ ├── oclc_isa_version_90a.bc │ ├── oclc_isa_version_90c.bc │ ├── oclc_unsafe_math_off.bc │ ├── oclc_wavefrontsize64_off.bc │ ├── ocml.bc │ └── opencl.bc ├── cuda_libdevice │ └── slim_libdevice.10.bc └── include │ ├── catch.hpp │ ├── json.hpp │ ├── stb_image.h │ ├── stb_image_write.h │ └── stb_truetype.h ├── misc ├── Test-TaichiAotWorkflow.ps1 ├── appveyor_filter.py ├── baselines │ ├── .gitignore │ ├── Makefile │ ├── assert.cu │ ├── atomics.cpp │ ├── bandwidth.cu │ ├── containers.cpp │ ├── cpu_memory_bound.cpp │ ├── cuda_atomic_reduce.cu │ ├── deadlock.txt │ ├── fill.cu │ ├── get_time.h │ ├── gpu_memory_bound.cu │ ├── gpu_reduction.cu │ ├── kernel_malloc.cu │ ├── laplace.cu │ ├── ldg.cu │ ├── mutex.cu │ └── rand.cu ├── benchmark_bit_struct_stores.py ├── benchmark_bls.py ├── benchmark_compile.py ├── benchmark_parallel_compilation.py ├── benchmark_reduction.py ├── benchmark_reduction_tmps.py ├── benchmark_scatter_bls.py ├── benchmark_tensor_access.py ├── ci_check_pr_title.py ├── ci_create_pr_card.py ├── ci_setup.py ├── copyright.py ├── count_tags.py ├── demo_constant_fold.py ├── demo_launch_overhead.py ├── demo_listgen.py ├── demo_oob_ub.py ├── demo_trackback.py ├── difftaichi_bibtex.txt ├── examples.md ├── fetch_active_contributors.py ├── format_server.py ├── generate_c_api.py ├── generate_c_api_docs.py ├── generate_example_videos.py ├── generate_ir_design_doc.py ├── generate_unity_language_binding.py ├── idle_hello.py ├── links.md ├── logo.png ├── make_changelog.py ├── minimal_timed.py ├── prtags.json ├── quantaichi_bibtex.txt ├── save_new_version.py ├── spMv_linear_solve.py ├── sparse_matrix.py ├── tag_to_project.json ├── taichi_bibtex.txt ├── taichi_json.py ├── test_async_weaken_access.py ├── test_gpu_async.py ├── test_grid_stride_loop.py ├── test_gui.py ├── test_memory_pool.py ├── test_poly_timed.py ├── test_print.py ├── test_without_init.py └── upload_release.py ├── netlify.toml ├── pyproject.toml ├── python ├── .gitignore └── taichi │ ├── __init__.py │ ├── __main__.py │ ├── _funcs.py │ ├── _kernels.py │ ├── _lib │ ├── __init__.py │ └── utils.py │ ├── _logging.py │ ├── _main.py │ ├── _snode │ ├── __init__.py │ ├── fields_builder.py │ └── snode_tree.py │ ├── _ti_module │ ├── __init__.py │ ├── cppgen.py │ └── module.py │ ├── _version_check.py │ ├── ad │ ├── __init__.py │ └── _ad.py │ ├── algorithms │ ├── __init__.py │ └── _algorithms.py │ ├── aot │ ├── __init__.py │ ├── _export.py │ ├── conventions │ │ ├── __init__.py │ │ └── gfxruntime140 │ │ │ ├── README.md │ │ │ ├── __init__.py │ │ │ ├── dr.py │ │ │ └── sr.py │ ├── module.py │ └── utils.py │ ├── examples │ ├── algorithm │ │ ├── circle-packing │ │ │ ├── circle_packing_image.py │ │ │ └── taichi_logo.png │ │ ├── laplace.py │ │ ├── marching_squares.py │ │ ├── mciso_advanced.py │ │ ├── mgpcg.py │ │ ├── mgpcg_advanced.py │ │ ├── poisson_disk_sampling.py │ │ └── print_offset.py │ ├── autodiff │ │ ├── diff_sph │ │ │ ├── diff_sph.py │ │ │ ├── fc1_pretrained.pkl │ │ │ └── fc2_pretrained.pkl │ │ ├── jacobian.py │ │ ├── minimization.py │ │ ├── regression.py │ │ └── simple_derivative.py │ ├── features │ │ ├── gui │ │ │ ├── fullscreen.py │ │ │ ├── gui_image_io.py │ │ │ ├── gui_widgets.py │ │ │ └── keyboard.py │ │ ├── io │ │ │ ├── .gitignore │ │ │ ├── export_mesh.py │ │ │ ├── export_ply.py │ │ │ └── export_videos.py │ │ └── sparse │ │ │ ├── explicit_activation.py │ │ │ ├── taichi_bitmasked.py │ │ │ ├── taichi_dynamic.py │ │ │ ├── taichi_sparse.py │ │ │ └── tutorial.py │ ├── ggui_examples │ │ ├── fem128_ggui.py │ │ ├── fractal3d_ggui.py │ │ ├── mass_spring_3d_ggui.py │ │ ├── mass_spring_game_ggui.py │ │ ├── mpm128_ggui.py │ │ ├── mpm3d_ggui.py │ │ └── stable_fluid_ggui.py │ ├── graph │ │ ├── mpm88_graph.py │ │ ├── stable_fluid_graph.py │ │ └── texture_graph.py │ ├── machine_learning │ │ └── differential_evolution.py │ ├── minimal.py │ ├── patterns.py │ ├── real_func │ │ ├── algorithm │ │ │ ├── marching_squares.py │ │ │ └── poisson_disk_sampling.py │ │ ├── graph │ │ │ └── stable_fluid_graph.py │ │ └── rendering │ │ │ ├── cornell_box.py │ │ │ └── taichi_ngp.py │ ├── rendering │ │ ├── cornell_box.py │ │ ├── oit_renderer.py │ │ ├── rasterizer.py │ │ ├── sdf_renderer.py │ │ ├── simple_texture.py │ │ ├── simple_uv.py │ │ ├── taichi_logo.py │ │ └── taichi_ngp.py │ └── simulation │ │ ├── ad_gravity.py │ │ ├── comet.py │ │ ├── euler.py │ │ ├── eulerfluid2d.py │ │ ├── fem128.py │ │ ├── fem99.py │ │ ├── fractal.py │ │ ├── game_of_life.py │ │ ├── implicit_fem.py │ │ ├── implicit_mass_spring.py │ │ ├── initial_value_problem.py │ │ ├── karman_vortex_street.py │ │ ├── laplace_equation.py │ │ ├── mandelbrot_zoom.py │ │ ├── mass_spring_game.py │ │ ├── mpm128.py │ │ ├── mpm3d.py │ │ ├── mpm88.py │ │ ├── mpm99.py │ │ ├── mpm_lagrangian_forces.py │ │ ├── nbody.py │ │ ├── odop_solar.py │ │ ├── pbf2d.py │ │ ├── physarum.py │ │ ├── snow_phaseField.py │ │ ├── stable_fluid.py │ │ ├── two_stream_instability.py │ │ ├── vortex_rings.py │ │ └── waterwave.py │ ├── experimental.py │ ├── graph │ ├── __init__.py │ └── _graph.py │ ├── lang │ ├── README.md │ ├── __init__.py │ ├── _ndarray.py │ ├── _ndrange.py │ ├── _texture.py │ ├── _wrap_inspect.py │ ├── any_array.py │ ├── argpack.py │ ├── ast │ │ ├── __init__.py │ │ ├── ast_transformer.py │ │ ├── ast_transformer_utils.py │ │ ├── checkers.py │ │ ├── symbol_resolver.py │ │ └── transform.py │ ├── common_ops.py │ ├── enums.py │ ├── exception.py │ ├── expr.py │ ├── field.py │ ├── impl.py │ ├── kernel_arguments.py │ ├── kernel_impl.py │ ├── matrix.py │ ├── matrix_ops.py │ ├── matrix_ops_utils.py │ ├── mesh.py │ ├── misc.py │ ├── ops.py │ ├── runtime_ops.py │ ├── shell.py │ ├── simt │ │ ├── __init__.py │ │ ├── block.py │ │ ├── grid.py │ │ ├── subgroup.py │ │ └── warp.py │ ├── snode.py │ ├── source_builder.py │ ├── struct.py │ └── util.py │ ├── linalg │ ├── __init__.py │ ├── matrixfree_cg.py │ ├── sparse_cg.py │ ├── sparse_matrix.py │ └── sparse_solver.py │ ├── math │ ├── __init__.py │ ├── _complex.py │ └── mathimpl.py │ ├── profiler │ ├── __init__.py │ ├── kernel_metrics.py │ ├── kernel_profiler.py │ ├── memory_profiler.py │ └── scoped_profiler.py │ ├── shaders │ ├── Circles_vk.frag │ ├── Circles_vk.vert │ ├── Circles_vk_frag.spv │ ├── Circles_vk_vert.spv │ ├── Lines_vk.frag │ ├── Lines_vk.vert │ ├── Lines_vk_frag.spv │ ├── Lines_vk_vert.spv │ ├── Mesh_vk.frag │ ├── Mesh_vk.vert │ ├── Mesh_vk_frag.spv │ ├── Mesh_vk_vert.spv │ ├── Particles_vk.frag │ ├── Particles_vk.vert │ ├── Particles_vk_frag.spv │ ├── Particles_vk_vert.spv │ ├── SceneLines2quad_vk.comp │ ├── SceneLines2quad_vk_comp.spv │ ├── SceneLines_vk.frag │ ├── SceneLines_vk.vert │ ├── SceneLines_vk_frag.spv │ ├── SceneLines_vk_vert.spv │ ├── SetImage_vk.frag │ ├── SetImage_vk.vert │ ├── SetImage_vk_frag.spv │ ├── SetImage_vk_vert.spv │ ├── Triangles_vk.frag │ ├── Triangles_vk.vert │ ├── Triangles_vk_frag.spv │ ├── Triangles_vk_vert.spv │ ├── lines2quad_vk.comp │ └── lines2quad_vk_comp.spv │ ├── sparse │ ├── __init__.py │ └── _sparse_grid.py │ ├── tools │ ├── __init__.py │ ├── diagnose.py │ ├── image.py │ ├── np2ply.py │ ├── video.py │ └── vtk.py │ ├── types │ ├── __init__.py │ ├── annotations.py │ ├── compound_types.py │ ├── ndarray_type.py │ ├── primitive_types.py │ ├── quant.py │ ├── texture_type.py │ └── utils.py │ └── ui │ ├── __init__.py │ ├── camera.py │ ├── canvas.py │ ├── constants.py │ ├── gui.py │ ├── imgui.py │ ├── scene.py │ ├── staging_buffer.py │ ├── ui.py │ ├── utils.py │ └── window.py ├── requirements_dev.txt ├── requirements_test.txt ├── scripts ├── build-taichi-android.sh └── run_clang_tidy.py ├── setup.cfg ├── setup.py ├── taichi ├── analysis │ ├── alias_analysis.cpp │ ├── arithmetic_interpretor.cpp │ ├── arithmetic_interpretor.h │ ├── bls_analyzer.cpp │ ├── bls_analyzer.h │ ├── build_cfg.cpp │ ├── check_fields_registered.cpp │ ├── clone.cpp │ ├── constexpr_propagation.cpp │ ├── count_statements.cpp │ ├── data_source_analysis.cpp │ ├── detect_fors_with_break.cpp │ ├── gather_deactivations.cpp │ ├── gather_dynamically_indexed_pointers.cpp │ ├── gather_func_store_dests.cpp │ ├── gather_immutable_local_vars.cpp │ ├── gather_mesh_thread_local.cpp │ ├── gather_meshfor_relation_types.cpp │ ├── gather_snode_read_writes.cpp │ ├── gather_statement_usages.cpp │ ├── gather_statements.cpp │ ├── gather_uniquely_accessed_pointers.cpp │ ├── gather_uniquely_accessed_pointers.h │ ├── gather_used_atomics.cpp │ ├── gen_offline_cache_key.cpp │ ├── has_store_or_atomic.cpp │ ├── last_store_or_atomic.cpp │ ├── mesh_bls_analyzer.cpp │ ├── mesh_bls_analyzer.h │ ├── offline_cache_util.cpp │ ├── offline_cache_util.h │ ├── same_statements.cpp │ ├── value_diff.cpp │ └── verify.cpp ├── aot │ ├── graph_data.cpp │ ├── graph_data.h │ ├── module_builder.cpp │ ├── module_builder.h │ ├── module_data.h │ ├── module_loader.cpp │ └── module_loader.h ├── codegen │ ├── amdgpu │ │ ├── CMakeLists.txt │ │ ├── codegen_amdgpu.cpp │ │ └── codegen_amdgpu.h │ ├── codegen.cpp │ ├── codegen.h │ ├── codegen_utils.h │ ├── compiled_kernel_data.cpp │ ├── compiled_kernel_data.h │ ├── cpu │ │ ├── CMakeLists.txt │ │ ├── codegen_cpu.cpp │ │ └── codegen_cpu.h │ ├── cuda │ │ ├── CMakeLists.txt │ │ ├── codegen_cuda.cpp │ │ └── codegen_cuda.h │ ├── dx12 │ │ ├── CMakeLists.txt │ │ ├── codegen_dx12.cpp │ │ ├── codegen_dx12.h │ │ ├── dx12_global_optimize_module.cpp │ │ ├── dx12_llvm_passes.h │ │ ├── dx12_lower_intrinsic.cpp │ │ └── dx12_lower_runtime_context.cpp │ ├── kernel_compiler.h │ ├── llvm │ │ ├── CMakeLists.txt │ │ ├── codegen_llvm.cpp │ │ ├── codegen_llvm.h │ │ ├── codegen_llvm_quant.cpp │ │ ├── compiled_kernel_data.cpp │ │ ├── compiled_kernel_data.h │ │ ├── kernel_compiler.cpp │ │ ├── kernel_compiler.h │ │ ├── llvm_codegen_utils.cpp │ │ ├── llvm_codegen_utils.h │ │ ├── llvm_compiled_data.h │ │ ├── struct_llvm.cpp │ │ └── struct_llvm.h │ └── spirv │ │ ├── CMakeLists.txt │ │ ├── compiled_kernel_data.cpp │ │ ├── compiled_kernel_data.h │ │ ├── kernel_compiler.cpp │ │ ├── kernel_compiler.h │ │ ├── kernel_utils.cpp │ │ ├── kernel_utils.h │ │ ├── lib_tiny_ir.h │ │ ├── snode_struct_compiler.cpp │ │ ├── snode_struct_compiler.h │ │ ├── spirv_codegen.cpp │ │ ├── spirv_codegen.h │ │ ├── spirv_ir_builder.cpp │ │ ├── spirv_ir_builder.h │ │ ├── spirv_types.cpp │ │ └── spirv_types.h ├── common │ ├── CMakeLists.txt │ ├── cleanup.cpp │ ├── cleanup.h │ ├── commit_hash.h.in │ ├── core.cpp │ ├── core.h │ ├── dict.h │ ├── dynamic_loader.cpp │ ├── dynamic_loader.h │ ├── exceptions.h │ ├── filesystem.hpp │ ├── interface.h │ ├── json.cpp │ ├── json.h │ ├── json_serde.h │ ├── logging.cpp │ ├── logging.h │ ├── miniz.c │ ├── miniz.h │ ├── one_or_more.h │ ├── platform_macros.h │ ├── ref_counted_pool.h │ ├── serialization.h │ ├── symbol_version.cpp │ ├── task.h │ ├── trait.h │ ├── types.h │ ├── utils.h │ ├── version.h.in │ ├── virtual_dir.cpp │ ├── virtual_dir.h │ ├── zip.cpp │ └── zip.h ├── compilation_manager │ ├── CMakeLists.txt │ ├── kernel_compilation_manager.cpp │ └── kernel_compilation_manager.h ├── inc │ ├── address_mode.inc.h │ ├── archs.inc.h │ ├── binary_op.inc.h │ ├── constants.h │ ├── cuda_kernel_utils.inc.h │ ├── data_type.inc.h │ ├── data_type_with_c_type.inc.h │ ├── expressions.inc.h │ ├── extensions.inc.h │ ├── filter.inc.h │ ├── frontend_statements.inc.h │ ├── internal_ops.inc.h │ ├── offloaded_task_type.inc.h │ ├── opengl_extension.inc.h │ ├── rhi_constants.inc.h │ ├── snodes.inc.h │ ├── statements.inc.h │ ├── type_kind.inc.h │ └── unary_op.inc.h ├── ir │ ├── analysis.h │ ├── basic_stmt_visitor.cpp │ ├── control_flow_graph.cpp │ ├── control_flow_graph.h │ ├── expr.cpp │ ├── expr.h │ ├── expression.h │ ├── expression_ops.cpp │ ├── expression_ops.h │ ├── expression_printer.h │ ├── frontend_ir.cpp │ ├── frontend_ir.h │ ├── ir.cpp │ ├── ir.h │ ├── ir_builder.cpp │ ├── ir_builder.h │ ├── mesh.cpp │ ├── mesh.h │ ├── offloaded_task_type.cpp │ ├── offloaded_task_type.h │ ├── pass.cpp │ ├── pass.h │ ├── scratch_pad.cpp │ ├── scratch_pad.h │ ├── snode.cpp │ ├── snode.h │ ├── snode_types.cpp │ ├── snode_types.h │ ├── statements.cpp │ ├── statements.h │ ├── stmt_op_types.cpp │ ├── stmt_op_types.h │ ├── transforms.h │ ├── type.cpp │ ├── type.h │ ├── type_factory.cpp │ ├── type_factory.h │ ├── type_system.cpp │ ├── type_system.h │ ├── type_utils.cpp │ ├── type_utils.h │ └── visitors.h ├── jit │ ├── jit_module.h │ ├── jit_session.cpp │ └── jit_session.h ├── math │ ├── arithmetic.h │ ├── array.h │ ├── array_2d.h │ ├── array_fwd.h │ ├── geometry_util.h │ ├── linalg.h │ ├── math.h │ ├── scalar.h │ ├── sifakis_svd.h │ └── svd.h ├── platform │ ├── amdgpu │ │ ├── detect_amdgpu.cpp │ │ └── detect_amdgpu.h │ ├── cuda │ │ ├── detect_cuda.cpp │ │ └── detect_cuda.h │ ├── mac │ │ ├── objc_api.cpp │ │ └── objc_api.h │ └── windows │ │ └── windows.h ├── program │ ├── argpack.cpp │ ├── argpack.h │ ├── callable.cpp │ ├── callable.h │ ├── compile_config.cpp │ ├── compile_config.h │ ├── conjugate_gradient.cpp │ ├── conjugate_gradient.h │ ├── context.h │ ├── extension.cpp │ ├── extension.h │ ├── field_info.cpp │ ├── field_info.h │ ├── function.cpp │ ├── function.h │ ├── function_key.cpp │ ├── function_key.h │ ├── graph_builder.cpp │ ├── graph_builder.h │ ├── kernel.cpp │ ├── kernel.h │ ├── kernel_launcher.h │ ├── kernel_profiler.cpp │ ├── kernel_profiler.h │ ├── launch_context_builder.cpp │ ├── launch_context_builder.h │ ├── matrix.h │ ├── ndarray.cpp │ ├── ndarray.h │ ├── parallel_executor.cpp │ ├── parallel_executor.h │ ├── program.cpp │ ├── program.h │ ├── program_impl.cpp │ ├── program_impl.h │ ├── py_print_buffer.cpp │ ├── py_print_buffer.h │ ├── snode_expr_utils.cpp │ ├── snode_expr_utils.h │ ├── snode_rw_accessors_bank.cpp │ ├── snode_rw_accessors_bank.h │ ├── sparse_matrix.cpp │ ├── sparse_matrix.h │ ├── sparse_solver.cpp │ ├── sparse_solver.h │ ├── texture.cpp │ └── texture.h ├── python │ ├── exception.cpp │ ├── exception.h │ ├── export.cpp │ ├── export.h │ ├── export_ggui.cpp │ ├── export_lang.cpp │ ├── export_math.cpp │ ├── export_misc.cpp │ ├── export_visual.cpp │ ├── interfaces_registry.cpp │ ├── memory_usage_monitor.cpp │ ├── memory_usage_monitor.h │ ├── py_exception_translator.cpp │ ├── snode_registry.cpp │ └── snode_registry.h ├── rhi │ ├── CMakeLists.txt │ ├── amdgpu │ │ ├── CMakeLists.txt │ │ ├── amdgpu_context.cpp │ │ ├── amdgpu_context.h │ │ ├── amdgpu_device.cpp │ │ ├── amdgpu_device.h │ │ ├── amdgpu_driver.cpp │ │ ├── amdgpu_driver.h │ │ ├── amdgpu_driver_functions.inc.h │ │ ├── amdgpu_profiler.cpp │ │ ├── amdgpu_profiler.h │ │ └── amdgpu_types.h │ ├── arch.cpp │ ├── arch.h │ ├── common │ │ ├── CMakeLists.txt │ │ ├── host_memory_pool.cpp │ │ ├── host_memory_pool.h │ │ ├── unified_allocator.cpp │ │ ├── unified_allocator.h │ │ ├── window_system.cpp │ │ └── window_system.h │ ├── cpu │ │ ├── CMakeLists.txt │ │ ├── cpu_device.cpp │ │ └── cpu_device.h │ ├── cuda │ │ ├── CMakeLists.txt │ │ ├── cublas_functions.inc.h │ │ ├── cuda_context.cpp │ │ ├── cuda_context.h │ │ ├── cuda_device.cpp │ │ ├── cuda_device.h │ │ ├── cuda_driver.cpp │ │ ├── cuda_driver.h │ │ ├── cuda_driver_functions.inc.h │ │ ├── cuda_profiler.cpp │ │ ├── cuda_profiler.h │ │ ├── cuda_types.h │ │ ├── cupti_toolkit.cpp │ │ ├── cupti_toolkit.h │ │ ├── cusolver_functions.inc.h │ │ └── cusparse_functions.inc.h │ ├── device.cpp │ ├── device.h │ ├── device_capability.cpp │ ├── device_capability.h │ ├── dummy.cpp │ ├── dx │ │ ├── CMakeLists.txt │ │ ├── dx_api.cpp │ │ ├── dx_api.h │ │ ├── dx_device.cpp │ │ ├── dx_device.h │ │ ├── dx_info_queue.cpp │ │ └── dx_info_queue.h │ ├── dx12 │ │ ├── CMakeLists.txt │ │ ├── dx12_api.cpp │ │ └── dx12_api.h │ ├── impl_support.h │ ├── interop │ │ ├── CMakeLists.txt │ │ ├── vulkan_cpu_interop.cpp │ │ ├── vulkan_cpu_interop.h │ │ ├── vulkan_cuda_interop.cpp │ │ └── vulkan_cuda_interop.h │ ├── llvm │ │ ├── CMakeLists.txt │ │ ├── allocator.cpp │ │ ├── allocator.h │ │ ├── device_memory_pool.cpp │ │ ├── device_memory_pool.h │ │ └── llvm_device.h │ ├── metal │ │ ├── CMakeLists.txt │ │ ├── metal_api.cpp │ │ ├── metal_api.h │ │ ├── metal_device.h │ │ ├── metal_device.mm │ │ └── metal_rhi_enum_mappings.h │ ├── opengl │ │ ├── CMakeLists.txt │ │ ├── opengl_api.cpp │ │ ├── opengl_api.h │ │ ├── opengl_device.cpp │ │ └── opengl_device.h │ ├── public_device.h │ └── vulkan │ │ ├── CMakeLists.txt │ │ ├── vulkan_api.cpp │ │ ├── vulkan_api.h │ │ ├── vulkan_common.h │ │ ├── vulkan_device.cpp │ │ ├── vulkan_device.h │ │ ├── vulkan_device_creator.cpp │ │ ├── vulkan_device_creator.h │ │ ├── vulkan_loader.cpp │ │ ├── vulkan_loader.h │ │ ├── vulkan_memory_allocator.cpp │ │ └── vulkan_utils.h ├── runtime │ ├── .gitignore │ ├── amdgpu │ │ ├── CMakeLists.txt │ │ ├── jit_amdgpu.cpp │ │ ├── jit_amdgpu.h │ │ ├── kernel_launcher.cpp │ │ └── kernel_launcher.h │ ├── cpu │ │ ├── CMakeLists.txt │ │ ├── jit_cpu.cpp │ │ ├── kernel_launcher.cpp │ │ └── kernel_launcher.h │ ├── cuda │ │ ├── CMakeLists.txt │ │ ├── jit_cuda.cpp │ │ ├── jit_cuda.h │ │ ├── kernel_launcher.cpp │ │ └── kernel_launcher.h │ ├── dx12 │ │ ├── CMakeLists.txt │ │ ├── aot_graph_data.h │ │ ├── aot_module_builder_impl.cpp │ │ ├── aot_module_builder_impl.h │ │ ├── aot_module_loader_impl.cpp │ │ └── aot_module_loader_impl.h │ ├── gfx │ │ ├── CMakeLists.txt │ │ ├── aot_graph_data.h │ │ ├── aot_module_builder_impl.cpp │ │ ├── aot_module_builder_impl.h │ │ ├── aot_module_loader_impl.cpp │ │ ├── aot_module_loader_impl.h │ │ ├── aot_utils.h │ │ ├── kernel_launcher.cpp │ │ ├── kernel_launcher.h │ │ ├── runtime.cpp │ │ ├── runtime.h │ │ ├── snode_tree_manager.cpp │ │ └── snode_tree_manager.h │ ├── llvm │ │ ├── CMakeLists.txt │ │ ├── aot_graph_data.h │ │ ├── kernel_launcher.cpp │ │ ├── kernel_launcher.h │ │ ├── llvm_aot_module_builder.cpp │ │ ├── llvm_aot_module_builder.h │ │ ├── llvm_aot_module_loader.cpp │ │ ├── llvm_aot_module_loader.h │ │ ├── llvm_context.cpp │ │ ├── llvm_context.h │ │ ├── llvm_context_pass.h │ │ ├── llvm_fwd.h │ │ ├── llvm_offline_cache.cpp │ │ ├── llvm_offline_cache.h │ │ ├── llvm_runtime_executor.cpp │ │ ├── llvm_runtime_executor.h │ │ ├── runtime_module │ │ │ ├── CMakeLists.txt │ │ │ ├── atomic.h │ │ │ ├── cuda_runtime-cuda-nvptx64-nvidia-cuda-sm_60.bc │ │ │ ├── cuda_runtime.cu │ │ │ ├── internal_functions.h │ │ │ ├── locked_task.h │ │ │ ├── node_bitmasked.h │ │ │ ├── node_dense.h │ │ │ ├── node_dynamic.h │ │ │ ├── node_pointer.h │ │ │ ├── node_root.h │ │ │ └── runtime.cpp │ │ ├── snode_tree_buffer_manager.cpp │ │ └── snode_tree_buffer_manager.h │ └── program_impls │ │ ├── dx │ │ ├── CMakeLists.txt │ │ ├── dx_program.cpp │ │ └── dx_program.h │ │ ├── dx12 │ │ ├── CMakeLists.txt │ │ ├── dx12_program.cpp │ │ └── dx12_program.h │ │ ├── gfx │ │ ├── CMakeLists.txt │ │ ├── gfx_program.cpp │ │ └── gfx_program.h │ │ ├── llvm │ │ ├── CMakeLists.txt │ │ ├── llvm_program.cpp │ │ └── llvm_program.h │ │ ├── metal │ │ ├── CMakeLists.txt │ │ ├── metal_program.cpp │ │ └── metal_program.h │ │ ├── opengl │ │ ├── CMakeLists.txt │ │ ├── opengl_program.cpp │ │ └── opengl_program.h │ │ └── vulkan │ │ ├── CMakeLists.txt │ │ ├── vulkan_program.cpp │ │ └── vulkan_program.h ├── struct │ ├── snode_tree.cpp │ ├── snode_tree.h │ ├── struct.cpp │ └── struct.h ├── system │ ├── benchmark.h │ ├── demangling.cpp │ ├── dynamic_loader.h │ ├── hacked_signal_handler.cpp │ ├── hacked_signal_handler.h │ ├── interface_registry.cpp │ ├── loader.cpp │ ├── profiler.cpp │ ├── profiler.h │ ├── run_tests.cpp │ ├── threading.cpp │ ├── threading.h │ ├── timeline.cpp │ ├── timeline.h │ ├── timer.cpp │ ├── timer.h │ ├── traceback.cpp │ └── traceback.h ├── transforms │ ├── alg_simp.cpp │ ├── auto_diff.cpp │ ├── binary_op_simplify.cpp │ ├── bit_loop_vectorize.cpp │ ├── cache_loop_invariant_global_vars.cpp │ ├── cfg_optimization.cpp │ ├── check_out_of_bound.cpp │ ├── check_out_of_bound.h │ ├── compile_taichi_functions.cpp │ ├── compile_to_offloads.cpp │ ├── constant_fold.cpp │ ├── constant_fold.h │ ├── demote_atomics.cpp │ ├── demote_dense_struct_fors.cpp │ ├── demote_mesh_statements.cpp │ ├── demote_mesh_statements.h │ ├── demote_no_access_mesh_fors.cpp │ ├── demote_operations.cpp │ ├── detect_read_only.cpp │ ├── determine_ad_stack_size.cpp │ ├── die.cpp │ ├── eliminate_immutable_local_vars.cpp │ ├── extract_constant.cpp │ ├── flag_access.cpp │ ├── frontend_type_check.cpp │ ├── handle_external_ptr_boundary.cpp │ ├── inlining.cpp │ ├── inlining.h │ ├── insert_scratch_pad.cpp │ ├── ir_printer.cpp │ ├── loop_invariant_code_motion.cpp │ ├── loop_invariant_detector.h │ ├── lower_access.cpp │ ├── lower_access.h │ ├── lower_ast.cpp │ ├── lower_matrix_ptr.cpp │ ├── make_block_local.cpp │ ├── make_block_local.h │ ├── make_cpu_multithreaded_range_for.cpp │ ├── make_mesh_block_local.cpp │ ├── make_mesh_block_local.h │ ├── make_mesh_thread_local.cpp │ ├── make_mesh_thread_local.h │ ├── make_thread_local.cpp │ ├── offload.cpp │ ├── optimize_bit_struct_stores.cpp │ ├── re_id.cpp │ ├── remove_assume_in_range.cpp │ ├── remove_loop_unique.cpp │ ├── replace_statements.cpp │ ├── reverse_segments.cpp │ ├── scalar_pointer_lowerer.cpp │ ├── scalar_pointer_lowerer.h │ ├── scalarize.cpp │ ├── simplify.cpp │ ├── simplify.h │ ├── statement_usage_replace.cpp │ ├── transform_statements.cpp │ ├── type_check.cpp │ ├── unreachable_code_elimination.cpp │ ├── utils.cpp │ ├── utils.h │ └── whole_kernel_cse.cpp ├── ui │ ├── CMakeLists.txt │ ├── common │ │ ├── app_config.h │ │ ├── camera.h │ │ ├── canvas_base.h │ │ ├── event.h │ │ ├── gui_base.h │ │ ├── input_handler.h │ │ ├── renderable_info.h │ │ ├── scene_base.h │ │ ├── window_base.cpp │ │ └── window_base.h │ ├── ggui │ │ ├── CMakeLists.txt │ │ ├── app_context.cpp │ │ ├── app_context.h │ │ ├── canvas.cpp │ │ ├── canvas.h │ │ ├── gui.cpp │ │ ├── gui.h │ │ ├── gui_metal.h │ │ ├── gui_metal.mm │ │ ├── nswindow_adapter.h │ │ ├── nswindow_adapter.mm │ │ ├── renderable.cpp │ │ ├── renderable.h │ │ ├── renderables │ │ │ ├── circles.cpp │ │ │ ├── circles.h │ │ │ ├── lines.cpp │ │ │ ├── lines.h │ │ │ ├── mesh.cpp │ │ │ ├── mesh.h │ │ │ ├── particles.cpp │ │ │ ├── particles.h │ │ │ ├── scene_lines.cpp │ │ │ ├── scene_lines.h │ │ │ ├── set_image.cpp │ │ │ ├── set_image.h │ │ │ ├── triangles.cpp │ │ │ └── triangles.h │ │ ├── renderer.cpp │ │ ├── renderer.h │ │ ├── scene.cpp │ │ ├── scene.h │ │ ├── sceneV2.cpp │ │ ├── sceneV2.h │ │ ├── swap_chain.cpp │ │ ├── swap_chain.h │ │ ├── vertex.h │ │ ├── window.cpp │ │ └── window.h │ ├── gui │ │ ├── android.cpp │ │ ├── cocoa.cpp │ │ ├── gui.cpp │ │ ├── gui.h │ │ ├── win32.cpp │ │ └── x11.cpp │ └── utils │ │ └── utils.h └── util │ ├── CMakeLists.txt │ ├── base64.h │ ├── bit.cpp │ ├── bit.h │ ├── environ_config.h │ ├── file_sequence_writer.cpp │ ├── file_sequence_writer.h │ ├── hash.h │ ├── image_buffer.cpp │ ├── image_io.cpp │ ├── image_io.h │ ├── io.h │ ├── lang_util.cpp │ ├── lang_util.h │ ├── line_appender.h │ ├── lock.h │ ├── macros.h │ ├── meta.h │ ├── offline_cache.cpp │ ├── offline_cache.h │ ├── short_name.cpp │ ├── short_name.h │ ├── str.cpp │ ├── str.h │ ├── testing.cpp │ ├── testing.h │ └── zip.cpp ├── tests ├── __init__.py ├── cpp │ ├── AOT_TEST_README.md │ ├── analysis │ │ ├── alias_analysis_test.cpp │ │ ├── bls_analyzer_test.cpp │ │ ├── same_statements_test.cpp │ │ └── value_diff_test.cpp │ ├── aot │ │ ├── dx12 │ │ │ └── aot_save_load_test.cpp │ │ ├── gfx_utils.cpp │ │ ├── gfx_utils.h │ │ ├── llvm │ │ │ ├── bitmasked_aot_test.cpp │ │ │ ├── dynamic_aot_test.cpp │ │ │ ├── field_aot_test.cpp │ │ │ ├── field_cgraph_test.cpp │ │ │ ├── graph_aot_test.cpp │ │ │ ├── kernel_aot_test.cpp │ │ │ ├── kernel_return_aot_test.cpp │ │ │ └── mpm88_graph_aot_test.cpp │ │ ├── opengl │ │ │ ├── device_test.cpp │ │ │ ├── graph_aot_test.cpp │ │ │ └── kernel_aot_test.cpp │ │ ├── python_scripts │ │ │ ├── aot_module_test_.py │ │ │ ├── bitmasked_aot_test_.py │ │ │ ├── comet_aot.py │ │ │ ├── dense_field_aot_test_.py │ │ │ ├── dynamic_aot_test_.py │ │ │ ├── field_aot_test_.py │ │ │ ├── graph_aot_test_.py │ │ │ ├── kernel_aot_test1.py │ │ │ ├── kernel_aot_test2.py │ │ │ ├── kernel_return_aot_test_.py │ │ │ ├── matrix_aot_test_.py │ │ │ ├── mpm88_graph_aot.py │ │ │ ├── numerical_aot_test_.py │ │ │ ├── shared_array_aot_test_.py │ │ │ ├── sph_aot.py │ │ │ ├── taichi_sparse_test_.py │ │ │ ├── tcm_test_.py │ │ │ └── texture_aot_test_.py │ │ └── vulkan │ │ │ ├── device_test.cpp │ │ │ ├── graph_aot_test.cpp │ │ │ └── kernel_aot_test.cpp │ ├── backends │ │ ├── amdgpu_device_test.cpp │ │ └── dx11_device_test.cpp │ ├── codegen │ │ ├── compiled_kernel_data_test.cpp │ │ └── refine_coordinates_test.cpp │ ├── common │ │ ├── core_test.cpp │ │ ├── dict_test.cpp │ │ └── serialization_test.cpp │ ├── conftest.py │ ├── cpptests.yaml │ ├── ir │ │ ├── frontend_type_inference_test.cpp │ │ ├── ir_builder_test.cpp │ │ ├── ir_test.cpp │ │ ├── ir_type_promotion_test.cpp │ │ ├── ndarray_kernel.cpp │ │ ├── ndarray_kernel.h │ │ ├── stmt_field_manager_test.cpp │ │ └── type_test.cpp │ ├── llvm │ │ ├── is_same_type_test.cpp │ │ └── llvm_offline_cache_test.cpp │ ├── offline_cache │ │ └── load_metadata_test.cpp │ ├── program │ │ ├── graph_test.cpp │ │ ├── test_program.cpp │ │ └── test_program.h │ ├── rhi │ │ └── common │ │ │ └── host_memory_pool_test.cpp │ ├── struct │ │ ├── fake_struct_compiler.h │ │ └── snode_tree_test.cpp │ ├── task │ │ ├── test_exception_handling.cpp │ │ └── test_gui.cpp │ └── transforms │ │ ├── alg_simp_test.cpp │ │ ├── binary_op_simplify_test.cpp │ │ ├── constant_fold_test.cpp │ │ ├── determine_ad_stack_size_test.cpp │ │ ├── eliminate_immutable_local_vars_test.cpp │ │ ├── extract_constant_test.cpp │ │ ├── half2_vectorization_test.cpp │ │ ├── inlining_test.cpp │ │ ├── make_block_local_test.cpp │ │ ├── scalar_pointer_lowerer_test.cpp │ │ ├── scalarize_test.cpp │ │ └── simplify_test.cpp ├── generate_compat_test_modules.py ├── pytest.ini ├── pytest_hardtle.py ├── python │ ├── __init__.py │ ├── bls_test_template.py │ ├── conftest.py │ ├── ell.json │ ├── expected │ │ ├── test_depth.png │ │ ├── test_draw_3d_lines.png │ │ ├── test_draw_lines.mac.png │ │ ├── test_draw_lines.png │ │ ├── test_draw_mesh_instances.png │ │ ├── test_draw_part_of_lines.mac.png │ │ ├── test_draw_part_of_lines.png │ │ ├── test_draw_part_of_mesh.png │ │ ├── test_draw_part_of_mesh_instances.png │ │ ├── test_draw_part_of_particles.png │ │ ├── test_draw_part_of_particles_per_vertex_rad_and_col.png │ │ ├── test_geometry_2d.png │ │ ├── test_geometry_3d.png │ │ ├── test_imgui.png │ │ ├── test_set_image.png │ │ └── test_wireframe_mode.png │ ├── fuse_test_template.py │ ├── py38_only.py │ ├── test_abs.py │ ├── test_ad_atomic.py │ ├── test_ad_atomic_fwd.py │ ├── test_ad_basics.py │ ├── test_ad_basics_fwd.py │ ├── test_ad_demote_dense.py │ ├── test_ad_dynamic_index.py │ ├── test_ad_for.py │ ├── test_ad_for_fwd.py │ ├── test_ad_gdar_diffmpm.py │ ├── test_ad_global_data_access_rule_checker.py │ ├── test_ad_grad_check.py │ ├── test_ad_if.py │ ├── test_ad_if_fwd.py │ ├── test_ad_math_func.py │ ├── test_ad_ndarray.py │ ├── test_ad_offload.py │ ├── test_ad_snode_grad_type.py │ ├── test_ad_tensor.py │ ├── test_aot.py │ ├── test_api.py │ ├── test_arg_alignment.py │ ├── test_arg_check.py │ ├── test_arg_load.py │ ├── test_argpack.py │ ├── test_argument.py │ ├── test_assert.py │ ├── test_assign.py │ ├── test_ast_refactor.py │ ├── test_ast_resolver.py │ ├── test_atomic.py │ ├── test_basics.py │ ├── test_binding.py │ ├── test_bit_operations.py │ ├── test_bitmasked.py │ ├── test_bitpacked_fields.py │ ├── test_bls.py │ ├── test_bls_assume_in_range.py │ ├── test_bool_op.py │ ├── test_bool_type.py │ ├── test_cache_loop_invariant.py │ ├── test_callable_template_mapper.py │ ├── test_cast.py │ ├── test_cfg_continue.py │ ├── test_classfunc.py │ ├── test_clear_all_gradients.py │ ├── test_cli.py │ ├── test_compare.py │ ├── test_complex_struct.py │ ├── test_continue.py │ ├── test_copy_from.py │ ├── test_cuda_internals.py │ ├── test_custom_struct.py │ ├── test_customized_grad.py │ ├── test_debug.py │ ├── test_delay_modify.py │ ├── test_deprecation.py │ ├── test_div.py │ ├── test_dynamic.py │ ├── test_dynamic_append_length.py │ ├── test_dynamic_attributes.py │ ├── test_eig.py │ ├── test_element_wise.py │ ├── test_empty.py │ ├── test_exception.py │ ├── test_expr_dict.py │ ├── test_expr_list.py │ ├── test_external_func.py │ ├── test_f16.py │ ├── test_field.py │ ├── test_fields_builder.py │ ├── test_fill.py │ ├── test_floor_dtype_argument.py │ ├── test_for_break.py │ ├── test_for_group_mismatch.py │ ├── test_fp_flush_to_zero.py │ ├── test_function.py │ ├── test_function_parameter_by_value.py │ ├── test_gc.py │ ├── test_get_external_tensor_shape.py │ ├── test_ggui.py │ ├── test_global_buffer_misalined.py │ ├── test_global_store_grad.py │ ├── test_global_thread_idx.py │ ├── test_graph.py │ ├── test_grouped.py │ ├── test_gui.py │ ├── test_if.py │ ├── test_image_io.py │ ├── test_immediate_layout.py │ ├── test_implicit_fem.py │ ├── test_indices.py │ ├── test_internal_func.py │ ├── test_ipython.ipynb │ ├── test_kernel_arg_errors.py │ ├── test_kernel_templates.py │ ├── test_lang.py │ ├── test_lexical_scope.py │ ├── test_linalg.py │ ├── test_listgen.py │ ├── test_literal.py │ ├── test_local_atomic_opt.py │ ├── test_local_atomics.py │ ├── test_logical_op.py │ ├── test_loop_grad.py │ ├── test_loop_unique.py │ ├── test_loops.py │ ├── test_materialize_check.py │ ├── test_math_module.py │ ├── test_matrix.py │ ├── test_matrix_arg.py │ ├── test_matrix_different_type.py │ ├── test_matrix_return.py │ ├── test_matrix_slice.py │ ├── test_matrix_solve.py │ ├── test_matrixfree_bicgstab.py │ ├── test_matrixfree_cg.py │ ├── test_memory.py │ ├── test_mesh.py │ ├── test_mod.py │ ├── test_module_import.py │ ├── test_mpm88.py │ ├── test_mpm_particle_list.py │ ├── test_name_error.py │ ├── test_native_functions.py │ ├── test_ndarray.py │ ├── test_ndrange.py │ ├── test_nested_kernel_error.py │ ├── test_new_allocator.py │ ├── test_no_activate.py │ ├── test_no_grad.py │ ├── test_non_taichi_types_in_kernel.py │ ├── test_numpy.py │ ├── test_numpy_io.py │ ├── test_offline_cache.py │ ├── test_offload.py │ ├── test_offload_cross.py │ ├── test_offset.py │ ├── test_oop.py │ ├── test_optimization.py │ ├── test_order.py │ ├── test_overflow.py │ ├── test_packed_size.py │ ├── test_paddle_io.py │ ├── test_parallel_range_for.py │ ├── test_pow.py │ ├── test_print.py │ ├── test_ptr_assign.py │ ├── test_quant_array.py │ ├── test_quant_array_vectorization.py │ ├── test_quant_atomics.py │ ├── test_quant_fixed.py │ ├── test_quant_float.py │ ├── test_quant_float_shared_exp.py │ ├── test_quant_int.py │ ├── test_quant_time_integration.py │ ├── test_random.py │ ├── test_reduction.py │ ├── test_rescale.py │ ├── test_return.py │ ├── test_runtime.py │ ├── test_scalar_op.py │ ├── test_scan.py │ ├── test_scope_errors.py │ ├── test_serial_execution.py │ ├── test_shared_array.py │ ├── test_simt.py │ ├── test_snode.py │ ├── test_snode_layout_inspection.py │ ├── test_sort.py │ ├── test_sparse_activate.py │ ├── test_sparse_basics.py │ ├── test_sparse_cg.py │ ├── test_sparse_deactivate.py │ ├── test_sparse_grid.py │ ├── test_sparse_linear_solver.py │ ├── test_sparse_matrix.py │ ├── test_sparse_multi_tree.py │ ├── test_sparse_parallel.py │ ├── test_spmv.py │ ├── test_ssa.py │ ├── test_static.py │ ├── test_stencils.py │ ├── test_stop_grad.py │ ├── test_struct.py │ ├── test_struct_for.py │ ├── test_struct_for_dynamic.py │ ├── test_struct_for_intermediate.py │ ├── test_struct_for_non_pot.py │ ├── test_svd.py │ ├── test_sync.py │ ├── test_syntax_errors.py │ ├── test_tensor_dimensionality.py │ ├── test_tensor_reflection.py │ ├── test_test.py │ ├── test_texture.py │ ├── test_threading.py │ ├── test_torch_ad.py │ ├── test_torch_io.py │ ├── test_tuple_assign.py │ ├── test_type_check.py │ ├── test_type_promotion.py │ ├── test_type_system.py │ ├── test_types.py │ ├── test_unary_ops.py │ ├── test_vector_swizzle.py │ └── test_while.py ├── run_c_api_compat_test.py ├── run_tests.py └── test_utils.py ├── version.txt └── vs-chromium-project.txt /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Reformat everything (#617) 2 | 02a4048b547e0c00c65856f47351c4ecf0163268 3 | 4 | # [misc] Relax Black formatter line length limit to 120 (#7824) 5 | 4fe7f150790012e6d9298614a040bb0053acd0fb 6 | 7 | # [misc] Switch code formatter from `yapf` to `black` (#7785) 8 | e0aa905991a01dfd68b7bcf1ad20f5132408febc 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | # Ref: https://github.com/pypa/pypi-support/blob/master/.github/ISSUE_TEMPLATE/config.yml 2 | blank_issues_enabled: true 3 | contact_links: 4 | - name: Contributor Guideline 5 | url: https://docs.taichi-lang.org/docs/contributor_guide 6 | about: Please check this out if you'd like to contribute by opening a PR :) 7 | - name: Taichi Forum 8 | url: https://forum.taichi.graphics 9 | about: GitHub issues too formal? Questions about Taichi? Feel free to chat on our forum! 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/document.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Doc 3 | about: Have doubts or suggestions about Taichi Docs 4 | title: '' 5 | labels: doc 6 | assignees: '' 7 | 8 | --- 9 | 10 | 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: feature request 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Concisely describe the proposed feature** 11 | A clear and concise description of what you want. For example, 12 | > I would like to add an Apple Metal backend to the compiler so that my Macbook GPU can be utilized. 13 | 14 | **Describe the solution you'd like (if any)** 15 | A clear and concise description of what you want to achieve and implement. 16 | 17 | **Additional comments** 18 | Add any other context or screenshots about the feature request here. 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Ask a Question 3 | about: Ask anything about Taichi 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | 18 | -------------------------------------------------------------------------------- /.github/actionlint.yaml: -------------------------------------------------------------------------------- 1 | self-hosted-runner: 2 | labels: 3 | - cn 4 | - cuda 5 | - OpenGL 6 | - vulkan 7 | - m1 8 | - driver550 9 | - benchmark 10 | - release 11 | - build 12 | - sm70 13 | - sm86 14 | - amdgpu 15 | - online 16 | 17 | # config-variables: 18 | # - ENVIRONMENT_STAGE 19 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Issue: # 2 | 3 | ### Brief Summary 4 | 5 | copilot:summary 6 | 7 | ### Walkthrough 8 | 9 | copilot:walkthrough 10 | -------------------------------------------------------------------------------- /.github/workflows/cache.yml: -------------------------------------------------------------------------------- 1 | name: Sync Near Cache 2 | on: 3 | workflow_dispatch: 4 | 5 | env: 6 | TI_CI: "1" 7 | 8 | jobs: 9 | sync_cache: 10 | name: Sync cache 11 | runs-on: 12 | - self-hosted 13 | - Linux 14 | steps: 15 | - name: Sync Cache 16 | run: | 17 | .github/workflows/scripts/sync-cache.py 18 | env: 19 | BOT_MINIO_ACCESS_KEY: ${{ secrets.BOT_MINIO_ACCESS_KEY }} 20 | BOT_MINIO_SECRET_KEY: ${{ secrets.BOT_MINIO_SECRET_KEY }} 21 | BOT_OSS_ACCESS_KEY: ${{ secrets.BOT_OSS_ACCESS_KEY }} 22 | BOT_OSS_SECRET_KEY: ${{ secrets.BOT_OSS_SECRET_KEY }} 23 | -------------------------------------------------------------------------------- /.github/workflows/issue_open.yml: -------------------------------------------------------------------------------- 1 | name: Add issues to Taichi project 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | 8 | jobs: 9 | add-to-project: 10 | name: Add issue to project 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/add-to-project@main 14 | with: 15 | project-url: https://github.com/orgs/taichi-dev/projects/1 16 | github-token: ${{ secrets.ORG_PROJECT_PAT }} 17 | -------------------------------------------------------------------------------- /.github/workflows/scripts/build.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import sys 5 | 6 | import ti_build.entry 7 | 8 | if __name__ == "__main__": 9 | sys.exit(ti_build.entry.main()) 10 | -------------------------------------------------------------------------------- /.github/workflows/scripts/check_clang_tidy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # TODO: move inside docker 4 | wget https://github.com/taichi-dev/taichi_assets/releases/download/llvm15/taichi-llvm-15-linux.zip 5 | unzip taichi-llvm-15-linux.zip && rm taichi-llvm-15-linux.zip 6 | export LLVM_DIR="$PWD/taichi-llvm-15" 7 | 8 | pushd taichi 9 | python3 -m pip install -r requirements_dev.txt 10 | 11 | CI_SETUP_CMAKE_ARGS=$1 12 | export CI_SETUP_CMAKE_ARGS 13 | python3 ./scripts/run_clang_tidy.py $PWD/taichi -clang-tidy-binary clang-tidy-10 -header-filter=$PWD/taichi -j2 14 | popd 15 | -------------------------------------------------------------------------------- /.github/workflows/scripts/ti_build/__init__.py: -------------------------------------------------------------------------------- 1 | from .bootstrap import early_init 2 | 3 | early_init() 4 | -------------------------------------------------------------------------------- /.github/workflows/scripts/unix-test-docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ex 3 | 4 | . $(dirname $0)/common-utils.sh 5 | 6 | export PYTHONUNBUFFERED=1 7 | 8 | export TI_CI=1 9 | export LD_LIBRARY_PATH=$PWD/build/:$LD_LIBRARY_PATH 10 | export TI_OFFLINE_CACHE_FILE_PATH=$PWD/.cache/taichi 11 | 12 | [[ "$IN_DOCKER" == "true" ]] && cd taichi 13 | 14 | python3 .github/workflows/scripts/build.py --permissive --write-env=/tmp/ti-env.sh 15 | . /tmp/ti-env.sh 16 | 17 | python3 -m pip uninstall -y taichi taichi-nightly || true 18 | python3 -m pip install dist/*.whl 19 | 20 | export PATH=$PATH:$HOME/.local/bin 21 | python3 -m pip install -r requirements_test.txt 22 | python3 -m pip install torch 23 | 24 | cat docs/cover-in-ci.lst | xargs pytest -v -n 4 25 | -------------------------------------------------------------------------------- /.github/workflows/scripts/unix_aot_compat_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ex 3 | 4 | . $(dirname $0)/common-utils.sh 5 | 6 | export PYTHONUNBUFFERED=1 7 | 8 | export TAICHI_AOT_FOLDER_PATH="taichi/tests" 9 | export TI_SKIP_VERSION_CHECK=ON 10 | export LD_LIBRARY_PATH=$PWD/build/:$LD_LIBRARY_PATH 11 | export TI_OFFLINE_CACHE_FILE_PATH=$PWD/.cache/taichi 12 | 13 | [[ "$IN_DOCKER" == "true" ]] && cd taichi 14 | 15 | python3 .github/workflows/scripts/build.py --permissive --write-env=/tmp/ti-env.sh 16 | . /tmp/ti-env.sh 17 | 18 | pip3 install -i https://pypi.taichi.graphics/simple/ taichi-nightly 19 | python3 tests/generate_compat_test_modules.py 20 | python3 -m pip uninstall taichi-nightly -y 21 | 22 | install_taichi_wheel 23 | 24 | python3 tests/run_c_api_compat_test.py 25 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | [MESSAGES CONTROL] 2 | disable=all 3 | enable= 4 | C0121,C0200,C0209,C0321,C0325,C0415, 5 | W0101,W0108,W0235,W0401,W0404,W0611,W0621,W0622,W1309, 6 | E1101, 7 | R0205,R0402,R1703,R1705,R1710,R1732 8 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include python/taichi/*.md 2 | recursive-include python/taichi/assets * 3 | recursive-include python/taichi/examples *.py 4 | include python/taichi/examples/autodiff/diff_sph/fc1_pretrained.pkl 5 | include python/taichi/examples/autodiff/diff_sph/fc2_pretrained.pkl 6 | include python/taichi/examples/algorithm/circle-packing/taichi_logo.png 7 | recursive-include python/taichi/_lib/c_api * 8 | include python/taichi/_lib/core/*.so 9 | include python/taichi/_lib/core/*.pyd 10 | include python/taichi/_lib/runtime/*.bc 11 | include python/taichi/_lib/runtime/*.dylib 12 | include python/taichi/shaders/*.spv 13 | include python/taichi/shaders/*.vert 14 | include python/taichi/shaders/*.frag 15 | 16 | global-exclude *.pyc *.pyo 17 | global-exclude ffmpeg 18 | -------------------------------------------------------------------------------- /benchmarks/microbenchmarks/__init__.py: -------------------------------------------------------------------------------- 1 | from .atomic_ops import AtomicOpsPlan 2 | from .fill import FillPlan 3 | from .math_opts import MathOpsPlan 4 | from .matrix_ops import MatrixOpsPlan 5 | from .memcpy import MemcpyPlan 6 | from .saxpy import SaxpyPlan 7 | from .stencil2d import Stencil2DPlan 8 | 9 | benchmark_plan_list = [ 10 | AtomicOpsPlan, 11 | FillPlan, 12 | MathOpsPlan, 13 | MatrixOpsPlan, 14 | MemcpyPlan, 15 | SaxpyPlan, 16 | Stencil2DPlan, 17 | ] 18 | -------------------------------------------------------------------------------- /benchmarks/requirements.txt: -------------------------------------------------------------------------------- 1 | jsbeautifier 2 | bokeh 3 | -------------------------------------------------------------------------------- /benchmarks/utils.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import functools 3 | import json 4 | import os 5 | 6 | import jsbeautifier 7 | 8 | 9 | def get_benchmark_dir(): 10 | return os.path.dirname(os.path.realpath(__file__)) 11 | 12 | 13 | def dump2json(obj): 14 | obj2dict = obj if type(obj) is dict else obj.__dict__ 15 | options = jsbeautifier.default_options() 16 | options.indent_size = 4 17 | return jsbeautifier.beautify(json.dumps(obj2dict), options) 18 | 19 | 20 | def datatime_with_format(): 21 | return datetime.datetime.now().isoformat() 22 | -------------------------------------------------------------------------------- /build.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | from pathlib import Path 5 | 6 | path = Path(__file__).resolve().parent / ".github" / "workflows" / "scripts" 7 | sys.path.insert(0, str(path)) 8 | 9 | import ti_build.entry 10 | 11 | sys.exit(ti_build.entry.main()) 12 | -------------------------------------------------------------------------------- /c_api/.gitignore: -------------------------------------------------------------------------------- 1 | !taichi.json 2 | unity/*.cs 3 | -------------------------------------------------------------------------------- /c_api/include/taichi/taichi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef TAICHI_H 3 | #define TAICHI_H 4 | 5 | #include "taichi_platform.h" 6 | 7 | #include "taichi_core.h" 8 | 9 | #ifdef TI_WITH_VULKAN 10 | #include "taichi_vulkan.h" 11 | #endif // TI_WITH_VULKAN 12 | 13 | #ifdef TI_WITH_OPENGL 14 | #include "taichi_opengl.h" 15 | #endif // TI_WITH_OPENGL 16 | 17 | #ifdef TI_WITH_CUDA 18 | #include "taichi_cuda.h" 19 | #endif // TI_WITH_CUDA 20 | 21 | #ifdef TI_WITH_CPU 22 | #include "taichi_cpu.h" 23 | #endif // TI_WITH_CPU 24 | 25 | #ifdef TI_WITH_METAL 26 | #include "taichi_metal.h" 27 | #endif // TI_WITH_METAL 28 | 29 | #endif // TAICHI_H 30 | -------------------------------------------------------------------------------- /c_api/include/taichi/taichi_cpu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef TAICHI_H 4 | #include "taichi.h" 5 | #endif // TAICHI_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif // __cplusplus 10 | 11 | // Structure `TiCpuMemoryInteropInfo` 12 | typedef struct TiCpuMemoryInteropInfo { 13 | void *ptr; 14 | uint64_t size; 15 | } TiCpuMemoryInteropInfo; 16 | 17 | // Function `ti_export_cpu_memory` 18 | TI_DLL_EXPORT void TI_API_CALL 19 | ti_export_cpu_memory(TiRuntime runtime, 20 | TiMemory memory, 21 | TiCpuMemoryInteropInfo *interop_info); 22 | 23 | TI_DLL_EXPORT TiMemory TI_API_CALL ti_import_cpu_memory(TiRuntime runtime, 24 | void *ptr, 25 | size_t memory_size); 26 | 27 | #ifdef __cplusplus 28 | } // extern "C" 29 | #endif // __cplusplus 30 | -------------------------------------------------------------------------------- /c_api/src/taichi_opengl_impl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef TI_WITH_OPENGL 3 | 4 | #include "taichi_gfx_impl.h" 5 | #include "taichi/rhi/opengl/opengl_api.h" 6 | #include "taichi/rhi/opengl/opengl_device.h" 7 | 8 | class OpenglRuntime : public GfxRuntime { 9 | private: 10 | taichi::lang::opengl::GLDevice device_; 11 | taichi::lang::gfx::GfxRuntime gfx_runtime_; 12 | 13 | public: 14 | OpenglRuntime(); 15 | virtual taichi::lang::Device &get() override final; 16 | virtual taichi::lang::gfx::GfxRuntime &get_gfx_runtime() override final; 17 | taichi::lang::opengl::GLDevice &get_gl() { 18 | return device_; 19 | } 20 | }; 21 | 22 | #endif // TI_WITH_OPENGL 23 | -------------------------------------------------------------------------------- /c_api/unity/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/c_api/unity/.gitkeep -------------------------------------------------------------------------------- /c_api/version_scripts/README.md: -------------------------------------------------------------------------------- 1 | Taichi C-API uses version script to control symbol exports from the shared library (https://github.com/taichi-dev/taichi/issues/6722) 2 | 3 | Note that the two version scripts export_symbols_linux.ld and export_symbols_mac.ld should have consistent contents otherwise will cause symbols mismatch on different platforms. 4 | 5 | CI will check for symbol leakage automatically, the regular expression rule of which should also stay consistent with the version scripts. CI scripts can be found at "check-c-api-export-symbols" function in .github/workflows/scripts/aot-demo.sh 6 | -------------------------------------------------------------------------------- /c_api/version_scripts/export_symbols_linux.lds: -------------------------------------------------------------------------------- 1 | LIB_C_API_1.0 { 2 | global: # specify symbols to be export from libtaichi_c_api 3 | ti_*; # CAPI interface starts with "ti_*" 4 | _ZN4capi5utils*; # matches "capi::utils::*" for CAPI tests 5 | 6 | local: 7 | *; # all other symbols will be convert to local bind type whatsoever 8 | }; 9 | -------------------------------------------------------------------------------- /c_api/version_scripts/export_symbols_mac.lds: -------------------------------------------------------------------------------- 1 | _ti_* 2 | __ZN4capi5utils* 3 | -------------------------------------------------------------------------------- /ci/.gitignore: -------------------------------------------------------------------------------- 1 | .generated-dockerfile 2 | -------------------------------------------------------------------------------- /cmake/CMakeGraphVizOptions.cmake: -------------------------------------------------------------------------------- 1 | # CMakeGraphVizOptions.cmake 2 | set(GRAPHVIZ_EXTERNAL_LIBS FALSE) 3 | set(GRAPHVIZ_INTERFACE_LIBS FALSE) 4 | set(GRAPHVIZ_EXECUTABLES FALSE) 5 | set(GRAPHVIZ_GENERATE_PER_TARGET FALSE) 6 | set(GRAPHVIZ_GENERATE_DEPENDERS FALSE) 7 | set(GRAPHVIZ_GENERATE_DEPENDERS FALSE) 8 | set(GRAPHVIZ_IGNORE_TARGETS "SPIRV-Tools*;spirv-cross*;gtest*;gmock*") 9 | -------------------------------------------------------------------------------- /cmake/Distributed.cmake: -------------------------------------------------------------------------------- 1 | if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 2 | message(FATAL_ERROR "Distributed compiling only supports Clang for now." ) 3 | endif() 4 | 5 | message(WARNING "Enabling distributed compiling support, this is experimental and only tested in Taichi's internal CI/CD system, use at your own risk.") 6 | 7 | execute_process( 8 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 9 | COMMAND ${CMAKE_CXX_COMPILER} -print-target-triple 10 | OUTPUT_VARIABLE TRIPLET 11 | OUTPUT_STRIP_TRAILING_WHITESPACE) 12 | 13 | # Essentially cross compiling 14 | add_compile_options(--target=${TRIPLET}) 15 | 16 | # False alarm caused by macro expansion 17 | # if(LSB_SET(x)) => if((x & 1)) 18 | add_compile_options(-Wno-parentheses-equality) 19 | 20 | # False alarm caused by macro expansion 21 | # taichi/python/export_lang.cpp:1241 22 | # MAKE_SPARSE_MATRIX(32, ColMajor, f) 23 | add_compile_options(-Wno-self-assign-overloaded) 24 | -------------------------------------------------------------------------------- /cmake/PythonNumpyPybind11.cmake: -------------------------------------------------------------------------------- 1 | # Python, numpy, and pybind11 2 | execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pybind11 --cmake 3 | OUTPUT_VARIABLE pybind11_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) 4 | execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy;print(numpy.get_include())" 5 | OUTPUT_VARIABLE NUMPY_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) 6 | 7 | message("-- Python: Using ${PYTHON_EXECUTABLE} as the interpreter") 8 | message(" version: ${PYTHON_VERSION_STRING}") 9 | message(" include: ${PYTHON_INCLUDE_DIR}") 10 | message(" library: ${PYTHON_LIBRARY}") 11 | message(" numpy include: ${NUMPY_INCLUDE_DIR}") 12 | 13 | include_directories(${NUMPY_INCLUDE_DIR}) 14 | 15 | find_package(pybind11 CONFIG REQUIRED) 16 | -------------------------------------------------------------------------------- /cmake/TaichiConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/TaichiTargets.cmake") 4 | 5 | check_required_components("Runtime") 6 | -------------------------------------------------------------------------------- /cmake/utils.cmake: -------------------------------------------------------------------------------- 1 | function(target_enable_function_level_linking TARGET) 2 | if(APPLE) 3 | target_link_options(${TARGET} PRIVATE -Wl,-dead_strip) 4 | elseif(MSVC) # WIN32 5 | target_link_options(${TARGET} PRIVATE /Gy) 6 | else() # Linux / *nix / gcc compatible 7 | target_link_options(${TARGET} PRIVATE -Wl,--gc-sections) 8 | endif() 9 | endfunction() 10 | -------------------------------------------------------------------------------- /conda/README.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | :::note 4 | The scripts provided here only work for Linux/macOS. 5 | 6 | We need an equivalent bat script for Windows. 7 | ::: 8 | 9 | Download and install the `conda` matching your OS: https://docs.conda.io/en/latest/miniconda.html. 10 | 11 | Run the following commands: 12 | 13 | ```bash 14 | # Assuming you're in the root directory 15 | $ cd conda 16 | 17 | $ conda env create -f conda_env.yaml 18 | $ conda activate taichi-dev 19 | 20 | # This will only install the dependencies to the 'taichi-dev' environment. 21 | (taichi-dev) $ python3 -m pip install -r ../requirements_dev.txt 22 | ``` 23 | 24 | # Update `taichi-dev`'s environment variables 25 | 26 | ```bash 27 | # Change scripts/activate_env_vars.sh 28 | 29 | $ conda activate taichi-dev 30 | 31 | (taichi-dev) $ ./update_env_vars.sh 32 | ``` 33 | -------------------------------------------------------------------------------- /conda/conda_env.yaml: -------------------------------------------------------------------------------- 1 | # How to update the env: 2 | # 3 | # conda activate taichi-dev 4 | # conda env update --file conda_env.yaml --prune 5 | # https://stackoverflow.com/a/43873901/12003165 6 | 7 | name: taichi-dev 8 | dependencies: 9 | - python=3.8 # Replace this with your favorite Python version 10 | -------------------------------------------------------------------------------- /conda/scripts/activate_env_vars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -x 4 | 5 | ### Path to clang++ ### 6 | # export CXX=/path/to/clang++ 7 | 8 | ### LLVM toolchain directory ### 9 | # export LLVM_DIR=/usr/local/lib/cmake/llvm 10 | 11 | ### Additional CMake args for building Taichi ### 12 | # export TAICHI_CMAKE_ARGS="-DCMAKE_CXX_COMPILER=clang++" 13 | 14 | ### Number of threads used when running Taichi tests ### 15 | # export TI_TEST_THREADS=4 16 | 17 | set +x 18 | -------------------------------------------------------------------------------- /conda/update_env_vars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$CONDA_DEFAULT_ENV" != "taichi-dev" ]; then 4 | echo "Please run inside taichi-dev conda env" 5 | exit 1 6 | fi 7 | 8 | # https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself 9 | export MY_DIR="$( cd "$(dirname "$0")" ; pwd -P )" 10 | export SCRIPTS_DIR=$MY_DIR/scripts 11 | 12 | # installs the activation/deactivation scripts for taichi-dev 13 | 14 | # See https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#macos-and-linux 15 | 16 | cd $CONDA_PREFIX 17 | 18 | # install activation script 19 | 20 | DST_DIR=./etc/conda/activate.d 21 | 22 | mkdir -p $DST_DIR 23 | pushd $DST_DIR 24 | rm -f env_vars.sh 25 | cp $SCRIPTS_DIR/activate_env_vars.sh env_vars.sh 26 | popd 27 | -------------------------------------------------------------------------------- /cpp_examples/rhi_examples/common_metal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define GLFW_INCLUDE_NONE 4 | #import 5 | #define GLFW_EXPOSE_NATIVE_COCOA 6 | #import 7 | #include "glm/glm.hpp" 8 | 9 | #include "taichi/rhi/metal/metal_api.h" 10 | #include "taichi/rhi/metal/metal_device.h" 11 | 12 | using namespace taichi::lang; 13 | 14 | class App { 15 | public: 16 | explicit App(int width, int height, const std::string &title); 17 | virtual ~App(); 18 | 19 | virtual std::vector render_loop( 20 | StreamSemaphore image_available_semaphore) { 21 | return {}; 22 | } 23 | 24 | void run(); 25 | 26 | GLFWwindow *glfw_window; 27 | metal::MetalDevice *device; 28 | 29 | std::unique_ptr surface; 30 | }; 31 | -------------------------------------------------------------------------------- /cpp_examples/rhi_examples/sample_1_window.cpp: -------------------------------------------------------------------------------- 1 | #ifdef RHI_EXAMPLE_BACKEND_VULKAN 2 | #include "common_vulkan.h" 3 | #endif // RHI_EXAMPLE_BACKEND_VULKAN 4 | 5 | #ifdef RHI_EXAMPLE_BACKEND_METAL 6 | #include "common_metal.h" 7 | #endif 8 | 9 | class SampleApp : public App { 10 | public: 11 | SampleApp() : App(1920, 1080, "Sample 1: Window") { 12 | } 13 | 14 | std::vector render_loop( 15 | StreamSemaphore image_available_semaphore) override { 16 | return {}; 17 | } 18 | 19 | public: 20 | }; 21 | 22 | int main() { 23 | std::unique_ptr app = std::make_unique(); 24 | app->run(); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /cpp_examples/rhi_examples/shaders/2_triangle.frag: -------------------------------------------------------------------------------- 1 | #version 460 2 | 3 | layout(location = 0) in vec3 color; 4 | 5 | layout(location = 0) out vec4 frag_output; 6 | 7 | void main() { 8 | frag_output = vec4(color, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /cpp_examples/rhi_examples/shaders/2_triangle.vert: -------------------------------------------------------------------------------- 1 | #version 460 2 | 3 | layout(location = 0) in vec2 v_position; 4 | layout(location = 1) in vec3 v_color; 5 | 6 | layout(location = 0) out vec3 color; 7 | 8 | void main() { 9 | gl_Position = vec4(v_position, 0.0, 1.0); 10 | color = v_color; 11 | } 12 | -------------------------------------------------------------------------------- /cpp_examples/rhi_examples/shaders/3_triangle.frag: -------------------------------------------------------------------------------- 1 | #version 460 2 | 3 | layout(location = 0) in vec3 color; 4 | layout(location = 1) in vec2 frag_texcoord; 5 | 6 | layout(location = 0) out vec4 frag_output; 7 | 8 | layout(binding = 5) uniform sampler2D texSampler; 9 | 10 | void main() { 11 | frag_output = vec4(color * texture(texSampler, frag_texcoord).r, 1.0); 12 | } 13 | -------------------------------------------------------------------------------- /cpp_examples/rhi_examples/shaders/3_triangle.vert: -------------------------------------------------------------------------------- 1 | #version 460 2 | 3 | layout(location = 0) in vec2 v_position; 4 | layout(location = 1) in vec3 v_color; 5 | layout(location = 2) in vec2 v_texcoord; 6 | 7 | layout(location = 0) out vec3 color; 8 | layout(location = 1) out vec2 frag_texcoord; 9 | 10 | layout(binding = 3) uniform UBO { 11 | float scale; 12 | } 13 | ubo; 14 | 15 | void main() { 16 | gl_Position = vec4(v_position * ubo.scale, 0.0, 1.0); 17 | color = v_color; 18 | frag_texcoord = v_texcoord; 19 | } 20 | -------------------------------------------------------------------------------- /docs/fragments/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/fragments/.gitkeep -------------------------------------------------------------------------------- /docs/lang/articles/about/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Why Taichi", 3 | "position": 0 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/advanced/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Advanced Programming", 3 | "position": 6 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/basic/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Data Containers", 3 | "position": 4 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/c-api/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Taichi Runtime C-API", 3 | "position": 11 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/contribution/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Contribution", 3 | "position": 13 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/debug/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Debugging", 3 | "position": 9 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/deployment/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Deployment", 3 | "position": 10 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/differentiable/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Differentiable Programming", 3 | "position": 5 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/faqs/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "FAQ", 3 | "position": 16 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/get-started/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Get Started", 3 | "position": 1 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/glossary/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Glossary", 3 | "position": 17 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/internals/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Internals", 3 | "position": 15 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/internals/life_of_kernel_lowres.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/internals/life_of_kernel_lowres.jpg -------------------------------------------------------------------------------- /docs/lang/articles/kernels/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Kernels & Functions", 3 | "position": 2 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/math/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Math Library", 3 | "position": 12 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/performance_tuning/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Performance", 3 | "position": 8 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/reference/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "References", 3 | "position": 14 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/aot_tutorial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/aot_tutorial.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/arrow_field.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/arrow_field.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/arrows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/arrows.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/bitpacked_fields_layout_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/bitpacked_fields_layout_example.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/bls_indices_mapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/bls_indices_mapping.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/circles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/circles.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/colored_circles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/colored_circles.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/effect_of_offline_cache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/effect_of_offline_cache.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/floating-point_formats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/floating-point_formats.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/fractal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/fractal.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/lines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/lines.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/point_field.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/point_field.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/quant_array_layout_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/quant_array_layout_example.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/rect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/rect.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/runtime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/runtime.png -------------------------------------------------------------------------------- /docs/lang/articles/static/assets/triangles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/lang/articles/static/assets/triangles.png -------------------------------------------------------------------------------- /docs/lang/articles/type_system/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Type System", 3 | "position": 3 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/utilities/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Tools & Utilities", 3 | "position": 3 4 | } 5 | -------------------------------------------------------------------------------- /docs/lang/articles/visualization/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Visualization", 3 | "position": 7 4 | } 5 | -------------------------------------------------------------------------------- /docs/rfcs/res/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/docs/rfcs/res/.gitkeep -------------------------------------------------------------------------------- /docs/variable.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /external/amdgpu_libdevice/ockl.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/ockl.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_abi_version_400.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_abi_version_400.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_correctly_rounded_sqrt_off.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_correctly_rounded_sqrt_off.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_daz_opt_off.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_daz_opt_off.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_finite_only_off.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_finite_only_off.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1010.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1010.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1011.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1011.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1012.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1012.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1013.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1013.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1030.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1030.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1031.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1031.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1032.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1032.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1033.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1033.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1034.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1034.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_1035.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_1035.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_600.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_600.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_601.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_601.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_602.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_602.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_700.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_700.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_701.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_701.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_702.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_702.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_703.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_703.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_704.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_704.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_705.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_705.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_801.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_801.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_802.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_802.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_803.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_803.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_805.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_805.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_810.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_810.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_900.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_900.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_902.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_902.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_904.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_904.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_906.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_906.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_908.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_908.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_909.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_909.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_90a.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_90a.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_isa_version_90c.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_isa_version_90c.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_unsafe_math_off.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_unsafe_math_off.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/oclc_wavefrontsize64_off.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/oclc_wavefrontsize64_off.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/ocml.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/ocml.bc -------------------------------------------------------------------------------- /external/amdgpu_libdevice/opencl.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/amdgpu_libdevice/opencl.bc -------------------------------------------------------------------------------- /external/cuda_libdevice/slim_libdevice.10.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/external/cuda_libdevice/slim_libdevice.10.bc -------------------------------------------------------------------------------- /misc/appveyor_filter.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | msg = os.environ["APPVEYOR_REPO_COMMIT_MESSAGE"] 5 | if msg.startswith("[release]") or sys.version_info[1] == 6: 6 | exit(0) # Build for this configuration (starts with '[release]', or python version is 3.6) 7 | else: 8 | print(f"[appveyor_filer] Not build for [{msg}] with Python {sys.version[:5]}") 9 | exit(1) # Do not build this configuration. See appveyor.yml 10 | -------------------------------------------------------------------------------- /misc/baselines/.gitignore: -------------------------------------------------------------------------------- 1 | results* 2 | taichi.h 3 | *.png 4 | atomics 5 | ma 6 | rand 7 | rand_nvcc 8 | rand_clang 9 | *.ll 10 | *.ptx 11 | gpu_memory_bound 12 | cpu_memory_bound 13 | gpu_reduction 14 | laplace 15 | -------------------------------------------------------------------------------- /misc/baselines/deadlock.txt: -------------------------------------------------------------------------------- 1 | bool leaveLoop = false; 2 | while (!leaveLoop) { 3 | // printf("attempting...\n"); 4 | if (atomicExch(&lock, 1) == 0) { 5 | // printf("locked\n"); 6 | leaveLoop = true; 7 | atomicExch(&lock, 0); 8 | } else { 9 | //printf("%d failed...\n", threadIdx.x); 10 | } 11 | } 12 | 13 | 14 | cuobjdump mutex -ptx 15 | 16 | ld.param.u64 %rd2, [_Z3incP4Node_param_0]; 17 | cvta.to.global.u64 %rd3, %rd2; 18 | mov.u32 %r1, %ntid.x; 19 | mov.u32 %r2, %ctaid.x; 20 | mov.u32 %r3, %tid.x; 21 | mad.lo.s32 %r4, %r1, %r2, %r3; 22 | and.b32 %r5, %r4, 1; 23 | mul.wide.u32 %rd4, %r5, 8; 24 | add.s64 %rd1, %rd3, %rd4; 25 | 26 | BB0_1: 27 | atom.global.exch.b32 %r6, [%rd1], 1; 28 | setp.ne.s32 %p1, %r6, 0; 29 | @%p1 bra BB0_1; 30 | 31 | atom.global.exch.b32 %r7, [%rd1], 0; 32 | ret; 33 | } 34 | -------------------------------------------------------------------------------- /misc/baselines/get_time.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | double get_time() { 6 | struct timeval tv; 7 | gettimeofday(&tv, nullptr); 8 | return tv.tv_sec + 1e-6 * tv.tv_usec; 9 | } 10 | -------------------------------------------------------------------------------- /misc/baselines/ldg.cu: -------------------------------------------------------------------------------- 1 | // Compile this file with clang to see how CUDA 2 | // is translated into NVVM IR. 3 | 4 | __device__ int cube(int x) { 5 | int y; 6 | asm(".reg .u32 t1;\n\t" // temp reg t1 7 | " mul.lo.u32 t1, %1, %1;\n\t" // t1 = x * x 8 | " mul.lo.u32 %0, t1, %1;" // y = t1 * x 9 | : "=r"(y) 10 | : "r"(x)); 11 | return y + clock64(); 12 | } 13 | 14 | __global__ void __launch_bounds__(1024, 2) test_ldg(float *a, float *b) { 15 | unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; 16 | a[i] = cube(1); 17 | auto c = __ldg((float4 *)a); 18 | *a += __ffs(__ballot_sync(__activemask(), 1)); 19 | a[i] = __ldg(&b[i]) + __ldg((double *)&b[i]) + __ldg((char *)&b[i]) + 20 | __shfl_down_sync(__activemask(), i, 3); 21 | } 22 | 23 | int main() { 24 | float *a, *b; 25 | test_ldg<<<1, 1>>>(a, b); 26 | } 27 | -------------------------------------------------------------------------------- /misc/benchmark_bit_struct_stores.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init(arch=ti.cpu, kernel_profiler=True, print_ir=True) 4 | 5 | quant = True 6 | 7 | n = 1024 * 1024 * 256 8 | 9 | if quant: 10 | qi16 = ti.types.quant.int(16, True) 11 | 12 | x = ti.field(dtype=qi16) 13 | y = ti.field(dtype=qi16) 14 | 15 | ti.root.dense(ti.i, n).bit_struct(num_bits=32).place(x, y) 16 | else: 17 | x = ti.field(dtype=ti.i16) 18 | y = ti.field(dtype=ti.i16) 19 | 20 | ti.root.dense(ti.i, n).place(x, y) 21 | 22 | 23 | @ti.kernel 24 | def foo(): 25 | for i in range(n): 26 | x[i] = i & 1023 27 | y[i] = i & 15 28 | 29 | 30 | for i in range(10): 31 | foo() 32 | 33 | ti.print_kernel_profile_info() 34 | -------------------------------------------------------------------------------- /misc/benchmark_bls.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | import taichi as ti 4 | 5 | sys.path.append("../tests/python/") 6 | 7 | from bls_test_template import bls_test_template 8 | 9 | ti.init(arch=ti.gpu, print_ir=True, kernel_profiler=True, demote_dense_struct_fors=False) 10 | 11 | stencil = [(0, 0), (0, -1), (0, 1), (-1, 0), (1, 0)] 12 | bls_test_template(2, 4096, bs=16, stencil=stencil, scatter=False, benchmark=True, dense=True) 13 | -------------------------------------------------------------------------------- /misc/benchmark_reduction.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | # TODO: make this a real benchmark and set up regression 4 | 5 | ti.init(arch=ti.gpu) 6 | 7 | N = 1024 * 1024 * 1024 8 | 9 | a = ti.field(ti.i32, shape=N) 10 | tot = ti.field(ti.i32, shape=()) 11 | 12 | 13 | @ti.kernel 14 | def fill(): 15 | ti.block_dim(128) 16 | for i in a: 17 | a[i] = i 18 | 19 | 20 | @ti.kernel 21 | def reduce(): 22 | ti.block_dim(1024) 23 | for i in a: 24 | tot[None] += a[i] 25 | 26 | 27 | fill() 28 | fill() 29 | 30 | for i in range(10): 31 | reduce() 32 | 33 | ground_truth = 10 * N * (N - 1) / 2 % 2**32 34 | assert tot[None] % 2**32 == ground_truth 35 | ti.print_kernel_profile_info() 36 | -------------------------------------------------------------------------------- /misc/benchmark_scatter_bls.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | import taichi as ti 4 | 5 | sys.path.append("../tests/python/") 6 | 7 | from bls_test_template import bls_particle_grid 8 | 9 | ti.init(arch=ti.cuda, kernel_profiler=True) 10 | bls_particle_grid( 11 | N=512, 12 | ppc=10, 13 | block_size=16, 14 | scatter=True, 15 | benchmark=10, 16 | pointer_level=2, 17 | use_offset=True, 18 | ) 19 | 20 | ti.print_kernel_profile_info() 21 | -------------------------------------------------------------------------------- /misc/demo_constant_fold.py: -------------------------------------------------------------------------------- 1 | # https://github.com/taichi-dev/taichi/pull/839#issuecomment-626217806 2 | import taichi as ti 3 | 4 | ti.init(print_ir=True) 5 | # ti.core.toggle_advanced_optimization(False) 6 | 7 | 8 | @ti.kernel 9 | def calc_pi() -> ti.f32: 10 | term = 1.0 11 | sum = 0.0 12 | divisor = 1 13 | for i in ti.static(range(10)): 14 | sum += term / divisor 15 | term *= -1 / 3 16 | divisor += 2 17 | return sum * ti.sqrt(12.0) 18 | 19 | 20 | print(calc_pi()) 21 | -------------------------------------------------------------------------------- /misc/demo_launch_overhead.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import taichi as ti 4 | 5 | ti.init() 6 | 7 | 8 | @ti.kernel 9 | def compute_div(a: ti.i32): 10 | pass 11 | 12 | 13 | compute_div(0) 14 | print("starting...") 15 | t = time.time() 16 | for i in range(100000): 17 | compute_div(0) 18 | print((time.time() - t) * 10, "us") 19 | exit(0) 20 | -------------------------------------------------------------------------------- /misc/demo_listgen.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init(print_ir=True) 4 | 5 | x = ti.field(ti.i32) 6 | ti.root.dense(ti.i, 4).bitmasked(ti.i, 4).place(x) 7 | 8 | 9 | @ti.kernel 10 | def func(): 11 | for i in x: 12 | print(i) 13 | 14 | 15 | func() 16 | -------------------------------------------------------------------------------- /misc/demo_oob_ub.py: -------------------------------------------------------------------------------- 1 | # https://forum.taichi.graphics/t/taichi/1003 2 | import taichi as ti 3 | 4 | ti.init(arch=ti.cpu) 5 | 6 | N = 3 7 | 8 | x = ti.field(ti.i32, N) 9 | 10 | 11 | @ti.kernel 12 | def test(): 13 | for i in x: 14 | x[i] = 1000 + i 15 | for i in ti.static(range(-N, 2 * N)): 16 | print(i, x[i]) 17 | 18 | 19 | test() 20 | -------------------------------------------------------------------------------- /misc/demo_trackback.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init() 4 | 5 | 6 | @ti.func 7 | def func3(): 8 | ti.static_assert(1 + 1 == 3) 9 | 10 | 11 | @ti.func 12 | def func2(): 13 | func3() 14 | 15 | 16 | @ti.func 17 | def func1(): 18 | func2() 19 | 20 | 21 | @ti.kernel 22 | def func0(): 23 | func1() 24 | 25 | 26 | func0() 27 | -------------------------------------------------------------------------------- /misc/difftaichi_bibtex.txt: -------------------------------------------------------------------------------- 1 | @article{hu2019difftaichi, 2 | title={DiffTaichi: Differentiable Programming for Physical Simulation}, 3 | author={Hu, Yuanming and Anderson, Luke and Li, Tzu-Mao and Sun, Qi and Carr, Nathan and Ragan-Kelley, Jonathan and Durand, Fr{\'e}do}, 4 | journal={ICLR}, 5 | year={2020} 6 | } 7 | -------------------------------------------------------------------------------- /misc/idle_hello.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | 4 | @ti.kernel 5 | def func(): 6 | pass 7 | 8 | 9 | func() 10 | -------------------------------------------------------------------------------- /misc/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/misc/logo.png -------------------------------------------------------------------------------- /misc/minimal_timed.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import taichi as ti 4 | 5 | t = time.time() 6 | ti.init(arch=ti.cuda, print_kernel_llvm_ir_optimized=True) 7 | 8 | 9 | @ti.kernel 10 | def p(): 11 | print(42) 12 | 13 | 14 | p() 15 | 16 | print(f"{time.time() - t:.3f} s") 17 | ti.core.print_profile_info() 18 | -------------------------------------------------------------------------------- /misc/quantaichi_bibtex.txt: -------------------------------------------------------------------------------- 1 | @article{hu2021quantaichi, 2 | title={QuanTaichi: A Compiler for Quantized Simulations}, 3 | 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}, 4 | journal={ACM Transactions on Graphics (TOG)}, 5 | volume={40}, 6 | number={4}, 7 | year={2021}, 8 | publisher={ACM} 9 | } 10 | -------------------------------------------------------------------------------- /misc/tag_to_project.json: -------------------------------------------------------------------------------- 1 | { 2 | "aot": "AOT", 3 | "autodiff": "Autodiff", 4 | "benchmark": "Backend Performance", 5 | "build": "CI/CD & Build & Tests", 6 | "ci": "CI/CD & Build & Tests", 7 | "doc": "Docs & Examples & Tutorials", 8 | "docs": "Docs & Examples & Tutorials", 9 | "gui": "GGUI", 10 | "ir": "Compiler Frontend & Middle-end", 11 | "lang": "Lang Features & Python" 12 | } 13 | -------------------------------------------------------------------------------- /misc/taichi_bibtex.txt: -------------------------------------------------------------------------------- 1 | @article{hu2019taichi, 2 | title={Taichi: a language for high-performance computation on spatially sparse data structures}, 3 | author={Hu, Yuanming and Li, Tzu-Mao and Anderson, Luke and Ragan-Kelley, Jonathan and Durand, Fr{\'e}do}, 4 | journal={ACM Transactions on Graphics (TOG)}, 5 | volume={38}, 6 | number={6}, 7 | pages={201}, 8 | year={2019}, 9 | publisher={ACM} 10 | } 11 | -------------------------------------------------------------------------------- /misc/test_async_weaken_access.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init() 4 | 5 | x = ti.field(ti.i32) 6 | y = ti.field(ti.i32) 7 | 8 | ti.root.pointer(ti.ij, 4).dense(ti.ij, 8).place(x, y) 9 | 10 | 11 | @ti.kernel 12 | def copy(): 13 | for i, j in y: 14 | x[i, j] = y[i, j] 15 | 16 | 17 | copy() 18 | -------------------------------------------------------------------------------- /misc/test_gpu_async.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import taichi as ti 4 | 5 | ti.init(arch=ti.cuda) 6 | 7 | a = ti.field(ti.f32, shape=(1024 * 1024 * 1024)) 8 | 9 | 10 | @ti.kernel 11 | def fill(x: ti.f32): 12 | for i in a: 13 | a[i] = x 14 | 15 | 16 | for i in range(100): 17 | t = time.time() 18 | fill(i) 19 | print(time.time() - t) 20 | 21 | print(a[0]) 22 | -------------------------------------------------------------------------------- /misc/test_grid_stride_loop.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init(ti.opengl, saturating_grid_dim=8) 4 | ti.set_logging_level(ti.DEBUG) 5 | 6 | 7 | @ti.kernel 8 | def func(): 9 | for i in range(10): 10 | print(i) 11 | 12 | 13 | func() 14 | ti.sync() 15 | -------------------------------------------------------------------------------- /misc/test_gui.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | import taichi as ti 4 | 5 | gui = ti.GUI("Test GUI", (512, 512), background_color=0xFFFFFF) 6 | t = 0 7 | 8 | while True: 9 | t += 0.05 10 | gui.line((0.3, 0.3), (0.6, 0.6), radius=2, color=0x000000) 11 | gui.circle((0.5 + math.cos(t) * 0.1, 0.5), radius=10, color=0xFF0000) 12 | gui.triangle((0.25, 0.2), (0.4, 0.2), (0.4, 0.4 + math.sin(t) * 0.1), color=0x00FF00) 13 | gui.show() 14 | -------------------------------------------------------------------------------- /misc/test_memory_pool.py: -------------------------------------------------------------------------------- 1 | # This file is not part of standard tests since it uses too much GPU memory 2 | 3 | import taichi as ti 4 | 5 | ti.init(arch=ti.cuda, debug=True) 6 | 7 | res = 512 8 | 9 | mask = ti.field(ti.i32) 10 | val = ti.field(ti.f32) 11 | 12 | ti.root.dense(ti.ijk, 512).place(mask) 13 | block = ti.root.pointer(ti.ijk, 128).dense(ti.ijk, 4) 14 | block.dense(ti.l, 128).place(val) 15 | 16 | 17 | @ti.kernel 18 | def load_inputs(): 19 | for i, j, k in mask: 20 | for l in range(128): 21 | val[i, j, k, l] = 1 22 | 23 | 24 | load_inputs() 25 | -------------------------------------------------------------------------------- /misc/test_print.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init(ti.opengl) 4 | 5 | 6 | @ti.kernel 7 | def func(): 8 | print(42) 9 | 10 | 11 | func() 12 | -------------------------------------------------------------------------------- /misc/test_without_init.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import taichi as ti 4 | 5 | 6 | @pytest.mark.tryfirst 7 | def test_without_init(): 8 | # We want to check if Taichi works well without ``ti.init()``. 9 | # But in test ``ti.init()`` will always be called in last ``@ti.all_archs``. 10 | # So we have to create a new Taichi instance, i.e. test in a sandbox. 11 | assert ti.cfg.arch == ti.cpu 12 | 13 | x = ti.field(ti.i32, (2, 3)) 14 | assert x.shape == (2, 3) 15 | 16 | x[1, 2] = 4 17 | assert x[1, 2] == 4 18 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools", "wheel", 4 | "numpy", "pybind11", "cmake", 5 | "scikit-build", "ninja; platform_system != 'Windows'", 6 | ] 7 | build-backend = "setuptools.build_meta" 8 | 9 | [tool.pytest.ini_options] 10 | filterwarnings = [ 11 | "ignore:Calling non-taichi function", 12 | "ignore:`np.int` is a deprecated alias", 13 | "ignore:Operator \"is\" in Taichi scope is deprecated", 14 | "ignore:Operator \"is not\" in Taichi scope is deprecated" 15 | ] 16 | 17 | [tool.yapf] 18 | based_on_style = "pep8" 19 | blank_line_before_nested_class_or_def = false 20 | -------------------------------------------------------------------------------- /python/.gitignore: -------------------------------------------------------------------------------- 1 | taichi/_lib/c_api 2 | taichi/_lib/runtime 3 | taichi/_lib/core/*.so 4 | taichi/_lib/core/*.pyd 5 | taichi.egg-info 6 | taichi/include 7 | taichi/assets 8 | taichi/tests 9 | taichi/tests38 10 | release 11 | -------------------------------------------------------------------------------- /python/taichi/__main__.py: -------------------------------------------------------------------------------- 1 | from ._main import main 2 | 3 | main() 4 | -------------------------------------------------------------------------------- /python/taichi/_lib/__init__.py: -------------------------------------------------------------------------------- 1 | from taichi._lib.utils import ti_python_core as core 2 | -------------------------------------------------------------------------------- /python/taichi/_snode/__init__.py: -------------------------------------------------------------------------------- 1 | from taichi._snode.fields_builder import FieldsBuilder 2 | 3 | __all__ = ["FieldsBuilder"] 4 | -------------------------------------------------------------------------------- /python/taichi/_ti_module/__init__.py: -------------------------------------------------------------------------------- 1 | from taichi._ti_module.module import _main 2 | -------------------------------------------------------------------------------- /python/taichi/ad/__init__.py: -------------------------------------------------------------------------------- 1 | from taichi.ad._ad import * 2 | -------------------------------------------------------------------------------- /python/taichi/algorithms/__init__.py: -------------------------------------------------------------------------------- 1 | from ._algorithms import * 2 | -------------------------------------------------------------------------------- /python/taichi/aot/__init__.py: -------------------------------------------------------------------------------- 1 | """Taichi's AOT (ahead of time) module. 2 | 3 | Users can use Taichi as a GPU compute shader/kernel compiler by compiling their 4 | Taichi kernels into an AOT module. 5 | """ 6 | 7 | import taichi.aot.conventions 8 | from taichi.aot._export import export, export_as 9 | from taichi.aot.conventions.gfxruntime140 import GfxRuntime140 10 | from taichi.aot.module import Module 11 | -------------------------------------------------------------------------------- /python/taichi/aot/_export.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Dict, List, Optional 2 | 3 | 4 | class AotExportKernel: 5 | def __init__(self, f, name: str, template_types: Dict[str, Any]) -> None: 6 | self.kernel = f 7 | self.name = name 8 | self.template_types = template_types 9 | 10 | 11 | _aot_kernels: List[AotExportKernel] = [] 12 | 13 | 14 | def export_as(name: str, *, template_types: Optional[Dict[str, Any]] = None): 15 | def inner(f): 16 | assert hasattr(f, "_is_wrapped_kernel"), "Only Taichi kernels can be exported" 17 | 18 | record = AotExportKernel(f, name, template_types or {}) 19 | _aot_kernels.append(record) 20 | return f 21 | 22 | return inner 23 | 24 | 25 | def export(f): 26 | return export_as(f.__name__)(f) 27 | -------------------------------------------------------------------------------- /python/taichi/aot/conventions/__init__.py: -------------------------------------------------------------------------------- 1 | from taichi.aot.conventions import gfxruntime140 2 | -------------------------------------------------------------------------------- /python/taichi/examples/algorithm/circle-packing/taichi_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/examples/algorithm/circle-packing/taichi_logo.png -------------------------------------------------------------------------------- /python/taichi/examples/algorithm/laplace.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init(arch=ti.cpu) 4 | 5 | N = 16 6 | 7 | x, y = ti.field(ti.f32), ti.field(ti.f32) 8 | 9 | ti.root.dense(ti.ij, N).place(x, y) 10 | 11 | 12 | @ti.kernel 13 | def laplace(): 14 | for i, j in x: 15 | if (i + j) % 3 == 0 and 1 <= i < N - 1 and 1 <= j < N - 1: 16 | y[i, j] = 4.0 * x[i, j] - x[i - 1, j] - x[i + 1, j] - x[i, j - 1] - x[i, j + 1] 17 | else: 18 | y[i, j] = 0.0 19 | 20 | 21 | def main(): 22 | for i in range(10): 23 | x[i, i + 1] = 1.0 24 | 25 | laplace() 26 | 27 | for i in range(10): 28 | print(y[i, i + 1]) 29 | 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /python/taichi/examples/autodiff/diff_sph/fc1_pretrained.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/examples/autodiff/diff_sph/fc1_pretrained.pkl -------------------------------------------------------------------------------- /python/taichi/examples/autodiff/diff_sph/fc2_pretrained.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/examples/autodiff/diff_sph/fc2_pretrained.pkl -------------------------------------------------------------------------------- /python/taichi/examples/features/gui/fullscreen.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init(ti.gpu) 4 | 5 | res = (1920, 1080) 6 | img = ti.Vector.field(3, float, res) 7 | 8 | 9 | @ti.kernel 10 | def render(t: float): 11 | for i, j in img: 12 | a = ti.Vector([i / res[0], j / res[1] + 2, i / res[0] + 4]) 13 | img[i, j] = ti.cos(a + t) * 0.5 + 0.5 14 | 15 | 16 | gui = ti.GUI("UV", res, fullscreen=True, fast_gui=True) 17 | while not gui.get_event(ti.GUI.ESCAPE): 18 | render(gui.frame * 0.04) 19 | gui.set_image(img) 20 | gui.show() 21 | -------------------------------------------------------------------------------- /python/taichi/examples/features/gui/gui_image_io.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import taichi as ti 4 | 5 | ti.init(arch=ti.cpu) 6 | 7 | pixel = ti.field(ti.u8, shape=(512, 512, 3)) 8 | 9 | 10 | @ti.kernel 11 | def paint(): 12 | for I in ti.grouped(pixel): 13 | pixel[I] = ti.u8(ti.random() * 255) 14 | 15 | 16 | paint() 17 | pixel = pixel.to_numpy() 18 | ti.tools.imshow(pixel, "Random Generated") 19 | for ext in ["bmp", "png", "jpg"]: 20 | fn = "taichi-example-random-img." + ext 21 | ti.tools.imwrite(pixel, fn) 22 | pixel_r = ti.tools.imread(fn) 23 | if ext != "jpg": 24 | assert (pixel_r == pixel).all() 25 | else: 26 | ti.tools.imshow(pixel_r, "JPEG Read Result") 27 | os.remove(fn) 28 | -------------------------------------------------------------------------------- /python/taichi/examples/features/gui/gui_widgets.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | gui = ti.GUI("GUI widgets") 4 | 5 | radius = gui.slider("Radius", 1, 50, step=1) 6 | xcoor = gui.label("X-coordinate") 7 | okay = gui.button("OK") 8 | 9 | xcoor.value = 0.5 10 | radius.value = 10 11 | 12 | while gui.running: 13 | for e in gui.get_events(gui.PRESS): 14 | if e.key == gui.ESCAPE: 15 | gui.running = False 16 | elif e.key == "a": 17 | xcoor.value -= 0.05 18 | elif e.key == "d": 19 | xcoor.value += 0.05 20 | elif e.key == "s": 21 | radius.value -= 1 22 | elif e.key == "w": 23 | radius.value += 1 24 | elif e.key == okay: 25 | print("OK clicked") 26 | 27 | gui.circle((xcoor.value, 0.5), radius=radius.value) 28 | gui.show() 29 | -------------------------------------------------------------------------------- /python/taichi/examples/features/io/.gitignore: -------------------------------------------------------------------------------- 1 | *.ply 2 | -------------------------------------------------------------------------------- /python/taichi/examples/features/sparse/taichi_dynamic.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init() 4 | 5 | x = ti.field(ti.i32) 6 | l = ti.field(ti.i32) 7 | n = 16 8 | 9 | ti.root.dense(ti.i, n).dynamic(ti.j, n).place(x) 10 | ti.root.dense(ti.i, n).place(l) 11 | 12 | 13 | @ti.kernel 14 | def make_lists(): 15 | for i in range(n): 16 | for j in range(i): 17 | ti.append(x.parent(), i, j * j) 18 | l[i] = ti.length(x.parent(), i) 19 | 20 | 21 | def main(): 22 | make_lists() 23 | 24 | for i in range(n): 25 | assert l[i] == i 26 | for j in range(n): 27 | assert x[i, j] == (j * j if j < i else 0) 28 | 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /python/taichi/examples/features/sparse/tutorial.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | use_bitmask = False 4 | 5 | ti.init() 6 | 7 | x = ti.field(dtype=ti.i32) 8 | block = ti.root.pointer(ti.ij, (4, 4)) 9 | if use_bitmask: 10 | pixel = block.bitmasked(ti.ij, (2, 2)) 11 | else: 12 | pixel = block.dense(ti.ij, (2, 2)) 13 | pixel.place(x) 14 | 15 | 16 | @ti.kernel 17 | def sparse_struct_for(): 18 | x[2, 3] = 2 19 | x[5, 6] = 3 20 | 21 | for i, j in x: 22 | print(f"field x[i, j]={x[i, j]}") 23 | 24 | for i, j in block: 25 | print(f"Active block: [{i}, {j}]") 26 | 27 | 28 | print(f"use_bitmask={use_bitmask}") 29 | sparse_struct_for() 30 | -------------------------------------------------------------------------------- /python/taichi/examples/minimal.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init() 4 | 5 | 6 | @ti.kernel 7 | def p() -> ti.f32: 8 | print(42) 9 | return 40 + 2 10 | 11 | 12 | print(p()) 13 | -------------------------------------------------------------------------------- /python/taichi/examples/rendering/simple_uv.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | ti.init() 4 | 5 | res = (512, 512) 6 | pixels = ti.Vector.field(3, dtype=float, shape=res) 7 | 8 | 9 | @ti.kernel 10 | def paint(): 11 | for i, j in pixels: 12 | u = i / res[0] 13 | v = j / res[1] 14 | pixels[i, j] = [u, v, 0] 15 | 16 | 17 | gui = ti.GUI("UV", res) 18 | while not gui.get_event(ti.GUI.ESCAPE): 19 | paint() 20 | gui.set_image(pixels) 21 | gui.show() 22 | -------------------------------------------------------------------------------- /python/taichi/examples/rendering/taichi_logo.py: -------------------------------------------------------------------------------- 1 | from taichi.examples.patterns import taichi_logo 2 | 3 | import taichi as ti 4 | 5 | ti.init() 6 | 7 | n = 512 8 | x = ti.field(dtype=ti.f32, shape=(n, n)) 9 | 10 | 11 | @ti.kernel 12 | def paint(): 13 | for i, j in ti.ndrange(n * 4, n * 4): 14 | # 4x4 super sampling: 15 | ret = taichi_logo(ti.Vector([i, j]) / (n * 4)) 16 | x[i // 4, j // 4] += ret / 16 17 | 18 | 19 | def main(): 20 | paint() 21 | 22 | gui = ti.GUI("Logo", (n, n)) 23 | while gui.running: 24 | gui.set_image(x) 25 | gui.show() 26 | 27 | 28 | if __name__ == "__main__": 29 | main() 30 | -------------------------------------------------------------------------------- /python/taichi/experimental.py: -------------------------------------------------------------------------------- 1 | from taichi.lang.kernel_impl import real_func as _real_func 2 | import warnings 3 | 4 | 5 | def real_func(func): 6 | warnings.warn( 7 | "ti.experimental.real_func is deprecated because it is no longer experimental. " "Use ti.real_func instead.", 8 | DeprecationWarning, 9 | ) 10 | return _real_func(func) 11 | 12 | 13 | __all__ = ["real_func"] 14 | -------------------------------------------------------------------------------- /python/taichi/graph/__init__.py: -------------------------------------------------------------------------------- 1 | from ._graph import * 2 | -------------------------------------------------------------------------------- /python/taichi/lang/README.md: -------------------------------------------------------------------------------- 1 | Some notes about the current implementation 2 | 3 | There are lots of `from taichi._kernels import xx`. Unfortunately, this cannot be moved into the top of the file, and has to be delayed inside the function. Otherwise, it would result in some cyclic import issue that is not trivially resolvable. 4 | -------------------------------------------------------------------------------- /python/taichi/lang/ast/__init__.py: -------------------------------------------------------------------------------- 1 | from taichi.lang.ast.ast_transformer_utils import ASTTransformerContext 2 | from taichi.lang.ast.checkers import KernelSimplicityASTChecker 3 | from taichi.lang.ast.transform import transform_tree 4 | -------------------------------------------------------------------------------- /python/taichi/lang/ast/transform.py: -------------------------------------------------------------------------------- 1 | from taichi.lang.ast.ast_transformer import ASTTransformer 2 | from taichi.lang.ast.ast_transformer_utils import ASTTransformerContext 3 | 4 | 5 | def transform_tree(tree, ctx: ASTTransformerContext): 6 | ASTTransformer()(ctx, tree) 7 | return ctx.return_data 8 | -------------------------------------------------------------------------------- /python/taichi/lang/runtime_ops.py: -------------------------------------------------------------------------------- 1 | from taichi.lang import impl 2 | 3 | 4 | def sync(): 5 | """Blocks the calling thread until all the previously 6 | launched Taichi kernels have completed. 7 | """ 8 | impl.get_runtime().sync() 9 | 10 | 11 | __all__ = ["sync"] 12 | -------------------------------------------------------------------------------- /python/taichi/lang/simt/__init__.py: -------------------------------------------------------------------------------- 1 | from taichi.lang.simt import block, grid, subgroup, warp 2 | 3 | __all__ = ["warp", "subgroup", "block", "grid"] 4 | -------------------------------------------------------------------------------- /python/taichi/lang/simt/grid.py: -------------------------------------------------------------------------------- 1 | from taichi.lang import impl 2 | 3 | 4 | def memfence(): 5 | return impl.call_internal("grid_memfence", with_runtime_context=False) 6 | -------------------------------------------------------------------------------- /python/taichi/linalg/__init__.py: -------------------------------------------------------------------------------- 1 | """Taichi support module for sparse matrix operations.""" 2 | 3 | from taichi.linalg.sparse_cg import SparseCG 4 | from taichi.linalg.sparse_matrix import * 5 | from taichi.linalg.sparse_solver import SparseSolver 6 | from taichi.linalg.matrixfree_cg import * 7 | -------------------------------------------------------------------------------- /python/taichi/math/__init__.py: -------------------------------------------------------------------------------- 1 | """Taichi math module. 2 | 3 | The math module supports glsl-style vectors, matrices and functions. 4 | """ 5 | 6 | from ._complex import * 7 | from .mathimpl import * # pylint: disable=W0622 8 | 9 | del mathimpl 10 | -------------------------------------------------------------------------------- /python/taichi/profiler/__init__.py: -------------------------------------------------------------------------------- 1 | from taichi.profiler.kernel_metrics import * 2 | from taichi.profiler.kernel_profiler import * 3 | from taichi.profiler.memory_profiler import * 4 | from taichi.profiler.scoped_profiler import * 5 | -------------------------------------------------------------------------------- /python/taichi/profiler/memory_profiler.py: -------------------------------------------------------------------------------- 1 | from taichi.lang.impl import get_runtime 2 | 3 | 4 | def print_memory_profiler_info(): 5 | """Memory profiling tool for LLVM backends with full sparse support. 6 | 7 | This profiler is automatically on. 8 | """ 9 | get_runtime().materialize() 10 | get_runtime().prog.print_memory_profiler_info() 11 | 12 | 13 | __all__ = ["print_memory_profiler_info"] 14 | -------------------------------------------------------------------------------- /python/taichi/shaders/Circles_vk.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(binding = 0) uniform UBO { 4 | vec3 color; 5 | int use_per_vertex_color; 6 | int use_per_vertex_radius; 7 | float radius; 8 | float window_width; 9 | float window_height; 10 | } 11 | ubo; 12 | 13 | layout(location = 1) in vec3 selected_color; 14 | layout(location = 2) in vec2 pos_2d; 15 | 16 | layout(location = 0) out vec4 out_color; 17 | 18 | void main() { 19 | float dist_sq = dot(pos_2d, pos_2d); 20 | float alpha = 1.0 - step(1.0, dist_sq); 21 | 22 | /* 23 | if (length(pos_2d) >= 1.0) { 24 | discard; 25 | } 26 | */ 27 | 28 | out_color = vec4(selected_color, alpha); 29 | } 30 | -------------------------------------------------------------------------------- /python/taichi/shaders/Circles_vk_frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Circles_vk_frag.spv -------------------------------------------------------------------------------- /python/taichi/shaders/Circles_vk_vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Circles_vk_vert.spv -------------------------------------------------------------------------------- /python/taichi/shaders/Lines_vk.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 color; 4 | 5 | layout(location = 0) out vec4 out_color; 6 | 7 | void main() { 8 | out_color = vec4(color, 1); 9 | } 10 | -------------------------------------------------------------------------------- /python/taichi/shaders/Lines_vk.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 in_position; 4 | layout(location = 1) in uint in_color_encoded; 5 | 6 | layout(location = 0) out vec3 frag_color; 7 | 8 | void main() { 9 | gl_Position = vec4(in_position.x * 2.0 - 1.0, -(in_position.y * 2.0 - 1.0), 0.0, 1.0); 10 | frag_color = unpackUnorm4x8(in_color_encoded).rgb; 11 | } 12 | -------------------------------------------------------------------------------- /python/taichi/shaders/Lines_vk_frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Lines_vk_frag.spv -------------------------------------------------------------------------------- /python/taichi/shaders/Lines_vk_vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Lines_vk_vert.spv -------------------------------------------------------------------------------- /python/taichi/shaders/Mesh_vk_frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Mesh_vk_frag.spv -------------------------------------------------------------------------------- /python/taichi/shaders/Mesh_vk_vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Mesh_vk_vert.spv -------------------------------------------------------------------------------- /python/taichi/shaders/Particles_vk_frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Particles_vk_frag.spv -------------------------------------------------------------------------------- /python/taichi/shaders/Particles_vk_vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Particles_vk_vert.spv -------------------------------------------------------------------------------- /python/taichi/shaders/SceneLines2quad_vk_comp.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/SceneLines2quad_vk_comp.spv -------------------------------------------------------------------------------- /python/taichi/shaders/SceneLines_vk.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 color; 4 | 5 | layout(location = 0) out vec4 out_color; 6 | 7 | void main() { 8 | out_color = vec4(color, 1); 9 | } 10 | -------------------------------------------------------------------------------- /python/taichi/shaders/SceneLines_vk.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec4 in_position; 4 | layout(location = 1) in vec4 in_color; 5 | 6 | layout(location = 0) out vec3 frag_color; 7 | 8 | void main() { 9 | gl_Position = in_position; 10 | gl_Position.y = -gl_Position.y; 11 | frag_color = in_color.rgb; 12 | } 13 | -------------------------------------------------------------------------------- /python/taichi/shaders/SceneLines_vk_frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/SceneLines_vk_frag.spv -------------------------------------------------------------------------------- /python/taichi/shaders/SceneLines_vk_vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/SceneLines_vk_vert.spv -------------------------------------------------------------------------------- /python/taichi/shaders/SetImage_vk.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(binding = 0) uniform sampler2D texSampler; 4 | 5 | layout(location = 0) in vec2 frag_texcoord; 6 | 7 | layout(location = 0) out vec4 out_color; 8 | 9 | layout(binding = 1) uniform UBO { 10 | vec2 lower_bound; 11 | vec2 upper_bound; 12 | float x_factor; 13 | float y_factor; 14 | int is_transposed; 15 | } ubo; 16 | 17 | void main() { 18 | vec2 coord = frag_texcoord * vec2(ubo.x_factor,ubo.y_factor); 19 | coord = clamp(coord, ubo.lower_bound, ubo.upper_bound); 20 | out_color = textureLod(texSampler, ubo.is_transposed != 0 ? coord.yx : coord, 0); 21 | } 22 | -------------------------------------------------------------------------------- /python/taichi/shaders/SetImage_vk.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // layout(binding = 0) uniform UniformBufferObject {} ubo; 4 | 5 | layout(location = 0) in vec3 in_position; 6 | layout(location = 1) in vec3 in_normal; 7 | layout(location = 2) in vec2 in_texcoord; 8 | layout(location = 3) in vec4 in_color; 9 | 10 | layout(location = 0) out vec2 frag_texcoord; 11 | 12 | void main() { 13 | gl_Position = vec4(in_position.xy, 0.0, 1.0); 14 | frag_texcoord = in_texcoord; 15 | } 16 | -------------------------------------------------------------------------------- /python/taichi/shaders/SetImage_vk_frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/SetImage_vk_frag.spv -------------------------------------------------------------------------------- /python/taichi/shaders/SetImage_vk_vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/SetImage_vk_vert.spv -------------------------------------------------------------------------------- /python/taichi/shaders/Triangles_vk.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 frag_texcoord; 4 | layout(location = 1) in vec3 selected_color; 5 | 6 | layout(location = 0) out vec4 out_color; 7 | 8 | layout(binding = 0) uniform UniformBufferObject { 9 | vec3 color; 10 | int use_per_vertex_color; 11 | } 12 | ubo; 13 | 14 | void main() { 15 | out_color = vec4(selected_color, 1); 16 | } 17 | -------------------------------------------------------------------------------- /python/taichi/shaders/Triangles_vk.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 in_position; 4 | layout(location = 1) in vec3 in_normal; 5 | layout(location = 2) in vec2 in_texcoord; 6 | layout(location = 3) in vec4 in_color; 7 | 8 | layout(location = 0) out vec2 frag_texcoord; 9 | layout(location = 1) out vec3 selected_color; 10 | 11 | layout(binding = 0) uniform UniformBufferObject { 12 | vec3 color; 13 | int use_per_vertex_color; 14 | } 15 | ubo; 16 | 17 | void main() { 18 | float x = in_position.x * 2.0 - 1.0; 19 | float y = -(in_position.y * 2.0 - 1.0); 20 | 21 | gl_Position = vec4(x, y, 0.0, 1.0); 22 | frag_texcoord = in_texcoord; 23 | 24 | if (ubo.use_per_vertex_color == 0) { 25 | selected_color = ubo.color; 26 | } else { 27 | selected_color = in_color.rgb; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /python/taichi/shaders/Triangles_vk_frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Triangles_vk_frag.spv -------------------------------------------------------------------------------- /python/taichi/shaders/Triangles_vk_vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/Triangles_vk_vert.spv -------------------------------------------------------------------------------- /python/taichi/shaders/lines2quad_vk_comp.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/python/taichi/shaders/lines2quad_vk_comp.spv -------------------------------------------------------------------------------- /python/taichi/sparse/__init__.py: -------------------------------------------------------------------------------- 1 | from ._sparse_grid import * 2 | -------------------------------------------------------------------------------- /python/taichi/tools/__init__.py: -------------------------------------------------------------------------------- 1 | """Taichi utility module. 2 | 3 | - `image` submodule for image io. 4 | - `video` submodule for exporting results to video files. 5 | - `diagnose` submodule for printing system environment information. 6 | """ 7 | 8 | from taichi.tools.diagnose import * 9 | from taichi.tools.image import * 10 | from taichi.tools.np2ply import * 11 | from taichi.tools.video import * 12 | from taichi.tools.vtk import * 13 | -------------------------------------------------------------------------------- /python/taichi/types/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module defines data types in Taichi: 3 | 4 | - primitive: int, float, etc. 5 | - compound: matrix, vector, struct. 6 | - template: for reference types. 7 | - ndarray: for arbitrary arrays. 8 | - quant: for quantized types, see "https://yuanming.taichi.graphics/publication/2021-quantaichi/quantaichi.pdf" 9 | """ 10 | 11 | from taichi.types import quant 12 | from taichi.types.annotations import * 13 | from taichi.types.compound_types import * 14 | from taichi.types.ndarray_type import * 15 | from taichi.types.primitive_types import * 16 | from taichi.types.texture_type import * 17 | from taichi.types.utils import * 18 | -------------------------------------------------------------------------------- /python/taichi/types/utils.py: -------------------------------------------------------------------------------- 1 | from taichi._lib import core as ti_python_core 2 | 3 | is_signed = ti_python_core.is_signed 4 | 5 | is_integral = ti_python_core.is_integral 6 | 7 | is_real = ti_python_core.is_real 8 | 9 | is_tensor = ti_python_core.is_tensor 10 | 11 | __all__ = ["is_signed", "is_integral", "is_real", "is_tensor"] 12 | -------------------------------------------------------------------------------- /python/taichi/ui/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Taichi gui module for visualization. 3 | 4 | This module contains a cpu based GUI system, a vulkan based GGUI system, 5 | and other helper utilities like adding widgets and exporting video files. 6 | """ 7 | 8 | from .gui import * 9 | from .ui import * 10 | -------------------------------------------------------------------------------- /python/taichi/ui/constants.py: -------------------------------------------------------------------------------- 1 | """Key constants for :mod:`~taichi.ui`""" 2 | 3 | SHIFT = "Shift" 4 | ALT = "Alt" 5 | CTRL = "Control" 6 | ESCAPE = "Escape" 7 | RETURN = "Return" 8 | TAB = "Tab" 9 | BACKSPACE = "BackSpace" 10 | SPACE = " " 11 | UP = "Up" 12 | DOWN = "Down" 13 | LEFT = "Left" 14 | RIGHT = "Right" 15 | CAPSLOCK = "CapsLock" 16 | LMB = "LMB" 17 | MMB = "MMB" 18 | RMB = "RMB" 19 | 20 | # Event types 21 | PRESS = "Press" 22 | RELEASE = "Release" 23 | -------------------------------------------------------------------------------- /python/taichi/ui/ui.py: -------------------------------------------------------------------------------- 1 | from taichi._lib import core as _ti_core 2 | 3 | from .camera import Camera # pylint: disable=unused-import 4 | from .canvas import Canvas # pylint: disable=unused-import 5 | from .constants import * # pylint: disable=unused-import,wildcard-import 6 | from .imgui import Gui # pylint: disable=unused-import 7 | from .scene import Scene # pylint: disable=unused-import 8 | from .utils import check_ggui_availability # pylint: disable=unused-import 9 | from .window import Window # pylint: disable=unused-import 10 | 11 | 12 | # ---------------------- 13 | ProjectionMode = _ti_core.ProjectionMode if _ti_core.GGUI_AVAILABLE else None 14 | """Camera projection mode, 0 for perspective and 1 for orthogonal. 15 | """ 16 | 17 | 18 | def make_camera(): 19 | return Camera() 20 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | cmake<4.0.0 2 | colorama 3 | coverage 4 | Pillow 5 | pybind11 6 | GitPython 7 | yapf 8 | distro 9 | isort 10 | pylint 11 | requests 12 | twine 13 | wheel 14 | astunparse 15 | pre-commit 16 | scikit-build 17 | numpy 18 | ninja; platform_system != 'Windows' 19 | -------------------------------------------------------------------------------- /requirements_test.txt: -------------------------------------------------------------------------------- 1 | Pillow 2 | pytest 3 | git+https://github.com/taichi-dev/pytest-xdist@a3b5ad3038#egg=pytest-xdist 4 | pytest-rerunfailures 5 | pytest-cov 6 | numpy 7 | psutil 8 | autograd 9 | requests 10 | matplotlib<=3.7.3 11 | cffi 12 | scipy 13 | setproctitle 14 | nbmake 15 | marko 16 | PyYAML 17 | pyevtk 18 | wget 19 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | long_description = file: README.md 3 | long_description_content_type = text/markdown; charset=UTF-8 4 | -------------------------------------------------------------------------------- /taichi/analysis/gather_uniquely_accessed_pointers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/pass.h" 4 | 5 | namespace taichi::lang { 6 | 7 | class GatherUniquelyAccessedBitStructsPass : public Pass { 8 | public: 9 | static const PassID id; 10 | 11 | struct Result { 12 | std::unordered_map> 14 | uniquely_accessed_bit_structs; 15 | }; 16 | }; 17 | 18 | } // namespace taichi::lang 19 | -------------------------------------------------------------------------------- /taichi/analysis/offline_cache_util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "taichi/rhi/arch.h" 6 | 7 | namespace taichi::lang { 8 | 9 | struct CompileConfig; 10 | struct DeviceCapabilityConfig; 11 | class Program; 12 | class IRNode; 13 | class SNode; 14 | class Kernel; 15 | 16 | std::string get_hashed_offline_cache_key_of_snode(const SNode *snode); 17 | std::string get_hashed_offline_cache_key(const CompileConfig &config, 18 | const DeviceCapabilityConfig &caps, 19 | Kernel *kernel); 20 | void gen_offline_cache_key(IRNode *ast, std::ostream *os); 21 | 22 | } // namespace taichi::lang 23 | -------------------------------------------------------------------------------- /taichi/codegen/amdgpu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/codegen/amdgpu/CMakeLists.txt 2 | 3 | add_library(amdgpu_codegen) 4 | target_sources(amdgpu_codegen 5 | PRIVATE 6 | codegen_amdgpu.cpp 7 | ) 8 | 9 | target_include_directories(amdgpu_codegen 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${LLVM_INCLUDE_DIRS} 14 | ) 15 | 16 | target_link_libraries(amdgpu_codegen PRIVATE taichi_util) 17 | target_link_libraries(amdgpu_codegen PRIVATE amdgpu_runtime) 18 | -------------------------------------------------------------------------------- /taichi/codegen/cpu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/codegen/cpu/CMakeLists.txt 2 | 3 | add_library(cpu_codegen) 4 | target_sources(cpu_codegen 5 | PRIVATE 6 | codegen_cpu.cpp 7 | ) 8 | 9 | target_include_directories(cpu_codegen 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${LLVM_INCLUDE_DIRS} 14 | ) 15 | 16 | target_link_libraries(cpu_codegen PRIVATE taichi_util) 17 | target_link_libraries(cpu_codegen PRIVATE cpu_runtime) 18 | -------------------------------------------------------------------------------- /taichi/codegen/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/codegen/cuda/CMakeLists.txt 2 | 3 | add_library(cuda_codegen) 4 | target_sources(cuda_codegen 5 | PRIVATE 6 | codegen_cuda.cpp 7 | ) 8 | 9 | target_include_directories(cuda_codegen 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${LLVM_INCLUDE_DIRS} 14 | ) 15 | 16 | target_link_libraries(cuda_codegen PRIVATE taichi_util) 17 | target_link_libraries(cuda_codegen PRIVATE cuda_runtime) 18 | -------------------------------------------------------------------------------- /taichi/codegen/dx12/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/codegen/dx12/CMakeLists.txt 2 | 3 | add_library(dx12_codegen) 4 | target_sources(dx12_codegen 5 | PRIVATE 6 | codegen_dx12.cpp 7 | dx12_global_optimize_module.cpp 8 | dx12_lower_intrinsic.cpp 9 | dx12_lower_runtime_context.cpp 10 | ) 11 | 12 | target_include_directories(dx12_codegen 13 | PRIVATE 14 | ${PROJECT_SOURCE_DIR}/external/eigen 15 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 16 | ${PROJECT_SOURCE_DIR} 17 | ${LLVM_INCLUDE_DIRS} 18 | ) 19 | 20 | target_link_libraries(dx12_codegen PRIVATE taichi_util) 21 | target_link_libraries(dx12_codegen PRIVATE dx12_runtime) 22 | -------------------------------------------------------------------------------- /taichi/codegen/llvm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/codegen/llvm/CMakeLists.txt 2 | 3 | add_library(llvm_codegen) 4 | target_sources(llvm_codegen 5 | PRIVATE 6 | codegen_llvm.cpp 7 | codegen_llvm_quant.cpp 8 | llvm_codegen_utils.cpp 9 | struct_llvm.cpp 10 | compiled_kernel_data.cpp 11 | kernel_compiler.cpp 12 | ) 13 | 14 | target_include_directories(llvm_codegen 15 | PRIVATE 16 | ${PROJECT_SOURCE_DIR} 17 | ${PROJECT_SOURCE_DIR}/external/eigen 18 | ${LLVM_INCLUDE_DIRS} 19 | ) 20 | 21 | target_link_libraries(llvm_codegen PRIVATE taichi_util) 22 | target_link_libraries(llvm_codegen PRIVATE llvm_runtime) 23 | -------------------------------------------------------------------------------- /taichi/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/common/CMakeLists.txt 2 | 3 | add_library(taichi_common) 4 | target_sources(taichi_common 5 | PRIVATE 6 | cleanup.cpp 7 | core.cpp 8 | json.cpp 9 | logging.cpp 10 | symbol_version.cpp 11 | virtual_dir.cpp 12 | zip.cpp 13 | miniz.c 14 | dynamic_loader.cpp 15 | ) 16 | 17 | target_include_directories(taichi_common 18 | PUBLIC 19 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 20 | PRIVATE 21 | ${PROJECT_SOURCE_DIR} 22 | ) 23 | -------------------------------------------------------------------------------- /taichi/common/cleanup.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/common/cleanup.h" 2 | #include 3 | 4 | namespace taichi { 5 | 6 | RaiiCleanup::RaiiCleanup(Func fn) : fn_(std::move(fn)) { 7 | } 8 | 9 | RaiiCleanup::~RaiiCleanup() { 10 | if (fn_) { 11 | fn_(); 12 | fn_ = nullptr; 13 | } 14 | } 15 | 16 | RaiiCleanup make_cleanup(RaiiCleanup::Func fn) { 17 | return RaiiCleanup{std::move(fn)}; 18 | } 19 | 20 | } // namespace taichi 21 | -------------------------------------------------------------------------------- /taichi/common/cleanup.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace taichi { 6 | 7 | class RaiiCleanup { 8 | public: 9 | using Func = std::function; 10 | 11 | explicit RaiiCleanup(Func fn); 12 | ~RaiiCleanup(); 13 | RaiiCleanup(const RaiiCleanup &) = delete; 14 | RaiiCleanup &operator=(const RaiiCleanup &) = delete; 15 | RaiiCleanup(RaiiCleanup &&) = default; 16 | RaiiCleanup &operator=(RaiiCleanup &&) = default; 17 | 18 | private: 19 | Func fn_; 20 | }; 21 | 22 | RaiiCleanup make_cleanup(RaiiCleanup::Func fn); 23 | 24 | } // namespace taichi 25 | -------------------------------------------------------------------------------- /taichi/common/commit_hash.h.in: -------------------------------------------------------------------------------- 1 | #define TI_COMMIT_HASH "@TI_COMMIT_HASH@" 2 | -------------------------------------------------------------------------------- /taichi/common/utils.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | inline bool is_ci() { 4 | char *res = std::getenv("TI_CI"); 5 | if (res == nullptr) 6 | return false; 7 | return std::stoi(res); 8 | } 9 | -------------------------------------------------------------------------------- /taichi/common/version.h.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define TI_VERSION_MAJOR @TI_VERSION_MAJOR@ 3 | #define TI_VERSION_MINOR @TI_VERSION_MINOR@ 4 | #define TI_VERSION_PATCH @TI_VERSION_PATCH@ 5 | #define CUDA_VERSION "@CUDA_VERSION@" 6 | -------------------------------------------------------------------------------- /taichi/common/zip.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/common/core.h" 3 | 4 | namespace taichi { 5 | namespace zip { 6 | 7 | // (penguinliong) Currently only supports loading. 8 | struct ZipArchive { 9 | std::unordered_map> file_dict; 10 | 11 | ZipArchive() = default; 12 | ZipArchive(const ZipArchive &) = delete; 13 | ZipArchive(ZipArchive &&) = default; 14 | 15 | ZipArchive &operator=(const ZipArchive &) = delete; 16 | ZipArchive &operator=(ZipArchive &&) = default; 17 | 18 | // Parse a serialized Zip archive and extract the uncompressed data keyed by 19 | // its file name. Returns true if success. 20 | static bool try_from_bytes(const void *data, size_t size, ZipArchive &ar); 21 | }; 22 | 23 | } // namespace zip 24 | } // namespace taichi 25 | -------------------------------------------------------------------------------- /taichi/compilation_manager/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/com_mgr/CMakeLists.txt 2 | 3 | add_library(compilation_manager) 4 | target_sources(compilation_manager 5 | PRIVATE 6 | kernel_compilation_manager.cpp 7 | ) 8 | 9 | target_include_directories(compilation_manager 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 13 | ${PROJECT_SOURCE_DIR}/external/eigen 14 | ${LLVM_INCLUDE_DIRS} # For "llvm/ADT/SmallVector.h" included in ir.h 15 | ) 16 | -------------------------------------------------------------------------------- /taichi/inc/address_mode.inc.h: -------------------------------------------------------------------------------- 1 | PER_ADDRESS_MODE(repeat) 2 | PER_ADDRESS_MODE(mirrored_repeat) 3 | PER_ADDRESS_MODE(clamp_to_edge) 4 | -------------------------------------------------------------------------------- /taichi/inc/archs.inc.h: -------------------------------------------------------------------------------- 1 | // Potentially supported backends 2 | 3 | // CPU archs 4 | PER_ARCH(x64) // a.k.a. AMD64/x86_64 5 | PER_ARCH(arm64) // a.k.a. Aarch64, WIP 6 | PER_ARCH(js) // Javascript, N/A 7 | 8 | // GPU archs 9 | PER_ARCH(cuda) // NVIDIA CUDA 10 | PER_ARCH(metal) // Apple Metal 11 | PER_ARCH(opengl) // OpenGL Compute Shaders 12 | PER_ARCH(dx11) // Microsoft DirectX 11, WIP 13 | PER_ARCH(dx12) // Microsoft DirectX 12, WIP 14 | PER_ARCH(opencl) // OpenCL, N/A 15 | PER_ARCH(amdgpu) // AMD GPU 16 | PER_ARCH(vulkan) // Vulkan 17 | PER_ARCH(gles) // OpenGL ES 18 | -------------------------------------------------------------------------------- /taichi/inc/binary_op.inc.h: -------------------------------------------------------------------------------- 1 | PER_BINARY_OP(mul) 2 | PER_BINARY_OP(add) 3 | PER_BINARY_OP(sub) 4 | PER_BINARY_OP(truediv) 5 | PER_BINARY_OP(floordiv) 6 | PER_BINARY_OP(div) 7 | PER_BINARY_OP(mod) 8 | PER_BINARY_OP(max) 9 | PER_BINARY_OP(min) 10 | PER_BINARY_OP(bit_and) 11 | PER_BINARY_OP(bit_or) 12 | PER_BINARY_OP(bit_xor) 13 | PER_BINARY_OP(bit_shl) 14 | PER_BINARY_OP(bit_shr) 15 | PER_BINARY_OP(bit_sar) 16 | PER_BINARY_OP(cmp_lt) 17 | PER_BINARY_OP(cmp_le) 18 | PER_BINARY_OP(cmp_gt) 19 | PER_BINARY_OP(cmp_ge) 20 | PER_BINARY_OP(cmp_eq) 21 | PER_BINARY_OP(cmp_ne) 22 | PER_BINARY_OP(atan2) 23 | PER_BINARY_OP(pow) 24 | PER_BINARY_OP(undefined) 25 | PER_BINARY_OP(logical_or) 26 | PER_BINARY_OP(logical_and) 27 | -------------------------------------------------------------------------------- /taichi/inc/cuda_kernel_utils.inc.h: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | 3 | int thread_idx() { 4 | return 0; 5 | } 6 | 7 | int warp_size() { 8 | return 32; 9 | } 10 | 11 | int warp_idx() { 12 | return thread_idx() % warp_size(); 13 | } 14 | 15 | int block_idx() { 16 | return 0; 17 | } 18 | 19 | int block_dim() { 20 | return 0; 21 | } 22 | 23 | int grid_dim() { 24 | return 0; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /taichi/inc/data_type.inc.h: -------------------------------------------------------------------------------- 1 | PER_TYPE(f16) 2 | PER_TYPE(f32) 3 | PER_TYPE(f64) 4 | PER_TYPE(i8) 5 | PER_TYPE(i16) 6 | PER_TYPE(i32) 7 | PER_TYPE(i64) 8 | PER_TYPE(u1) // bool 9 | PER_TYPE(u8) 10 | PER_TYPE(u16) 11 | PER_TYPE(u32) 12 | PER_TYPE(u64) 13 | PER_TYPE(gen) // generic, "void *" when used together with pointer 14 | PER_TYPE(unknown) 15 | -------------------------------------------------------------------------------- /taichi/inc/data_type_with_c_type.inc.h: -------------------------------------------------------------------------------- 1 | // Doesn't contain f16. 2 | PER_C_TYPE(f32, float32) 3 | PER_C_TYPE(f64, float64) 4 | PER_C_TYPE(i8, int8) 5 | PER_C_TYPE(i16, int16) 6 | PER_C_TYPE(i32, int32) 7 | PER_C_TYPE(i64, int64) 8 | PER_C_TYPE(u1, uint1) 9 | PER_C_TYPE(u8, uint8) 10 | PER_C_TYPE(u16, uint16) 11 | PER_C_TYPE(u32, uint32) 12 | PER_C_TYPE(u64, uint64) 13 | -------------------------------------------------------------------------------- /taichi/inc/extensions.inc.h: -------------------------------------------------------------------------------- 1 | // Lists of extension features 2 | PER_EXTENSION(sparse) // Sparse data structures 3 | PER_EXTENSION(quant) // Quantization 4 | PER_EXTENSION(mesh) // MeshTaichi 5 | PER_EXTENSION(quant_basic) // Basic operations in quantization 6 | PER_EXTENSION(data64) // Metal doesn't support 64-bit data buffers yet... 7 | PER_EXTENSION(adstack) // For keeping the history of mutable local variables 8 | PER_EXTENSION(bls) // Block-local storage 9 | PER_EXTENSION(assertion) // Run-time asserts in Taichi kernels 10 | PER_EXTENSION(extfunc) // Invoke external functions or backend source 11 | -------------------------------------------------------------------------------- /taichi/inc/filter.inc.h: -------------------------------------------------------------------------------- 1 | PER_FILTER(nearest) 2 | PER_FILTER(linear) 3 | -------------------------------------------------------------------------------- /taichi/inc/frontend_statements.inc.h: -------------------------------------------------------------------------------- 1 | PER_STATEMENT(FrontendExternalFuncStmt) 2 | PER_STATEMENT(FrontendExprStmt) 3 | PER_STATEMENT(FrontendIfStmt) 4 | PER_STATEMENT(FrontendForStmt) 5 | PER_STATEMENT(FrontendPrintStmt) 6 | PER_STATEMENT(FrontendWhileStmt) 7 | PER_STATEMENT(FrontendBreakStmt) 8 | PER_STATEMENT(FrontendContinueStmt) 9 | PER_STATEMENT(FrontendAllocaStmt) 10 | PER_STATEMENT(FrontendAssignStmt) 11 | PER_STATEMENT(FrontendSNodeOpStmt) // activate, deactivate, append, clear 12 | PER_STATEMENT(FrontendAssertStmt) 13 | PER_STATEMENT(FrontendFuncDefStmt) 14 | PER_STATEMENT(FrontendReturnStmt) 15 | PER_STATEMENT(FrontendFuncCallStmt) 16 | -------------------------------------------------------------------------------- /taichi/inc/offloaded_task_type.inc.h: -------------------------------------------------------------------------------- 1 | PER_TASK_TYPE(serial) 2 | PER_TASK_TYPE(range_for) 3 | PER_TASK_TYPE(struct_for) 4 | PER_TASK_TYPE(mesh_for) 5 | PER_TASK_TYPE(listgen) 6 | PER_TASK_TYPE(gc) 7 | -------------------------------------------------------------------------------- /taichi/inc/opengl_extension.inc.h: -------------------------------------------------------------------------------- 1 | // Potentially supported OpenGL extensions 2 | 3 | PER_OPENGL_EXTENSION(GL_ARB_compute_shader) 4 | PER_OPENGL_EXTENSION(GL_ARB_gpu_shader_int64) 5 | PER_OPENGL_EXTENSION(GL_NV_shader_atomic_float) 6 | PER_OPENGL_EXTENSION(GL_NV_shader_atomic_float64) 7 | PER_OPENGL_EXTENSION(GL_NV_shader_atomic_int64) 8 | -------------------------------------------------------------------------------- /taichi/inc/snodes.inc.h: -------------------------------------------------------------------------------- 1 | PER_SNODE(root) 2 | PER_SNODE(dense) 3 | PER_SNODE(dynamic) 4 | PER_SNODE(pointer) 5 | PER_SNODE(bitmasked) 6 | PER_SNODE(hash) 7 | PER_SNODE(place) 8 | PER_SNODE(bit_struct) 9 | PER_SNODE(quant_array) 10 | PER_SNODE(undefined) 11 | -------------------------------------------------------------------------------- /taichi/inc/type_kind.inc.h: -------------------------------------------------------------------------------- 1 | PER_TYPE_KIND(Primitive) 2 | PER_TYPE_KIND(Pointer) 3 | PER_TYPE_KIND(Tensor) 4 | PER_TYPE_KIND(Struct) 5 | PER_TYPE_KIND(ArgPack) 6 | PER_TYPE_KIND(QuantInt) 7 | PER_TYPE_KIND(QuantFloat) 8 | PER_TYPE_KIND(QuantFixed) 9 | PER_TYPE_KIND(BitStruct) 10 | PER_TYPE_KIND(QuantArray) 11 | -------------------------------------------------------------------------------- /taichi/inc/unary_op.inc.h: -------------------------------------------------------------------------------- 1 | PER_UNARY_OP(neg) 2 | PER_UNARY_OP(sqrt) 3 | PER_UNARY_OP(round) 4 | PER_UNARY_OP(floor) 5 | PER_UNARY_OP(frexp) 6 | PER_UNARY_OP(ceil) 7 | PER_UNARY_OP(cast_value) 8 | PER_UNARY_OP(cast_bits) 9 | PER_UNARY_OP(abs) 10 | PER_UNARY_OP(sgn) 11 | PER_UNARY_OP(sin) 12 | PER_UNARY_OP(asin) 13 | PER_UNARY_OP(cos) 14 | PER_UNARY_OP(acos) 15 | PER_UNARY_OP(tan) 16 | PER_UNARY_OP(tanh) 17 | PER_UNARY_OP(inv) 18 | PER_UNARY_OP(rcp) 19 | PER_UNARY_OP(exp) 20 | PER_UNARY_OP(log) 21 | PER_UNARY_OP(popcnt) 22 | PER_UNARY_OP(clz) 23 | PER_UNARY_OP(rsqrt) 24 | PER_UNARY_OP(bit_not) 25 | PER_UNARY_OP(logic_not) 26 | PER_UNARY_OP(undefined) 27 | -------------------------------------------------------------------------------- /taichi/ir/expression_ops.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/ir/frontend_ir.h" 2 | 3 | #define TI_EXPRESSION_IMPLEMENTATION 4 | #include "taichi/ir/expression_ops.h" 5 | -------------------------------------------------------------------------------- /taichi/ir/offloaded_task_type.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/ir/offloaded_task_type.h" 2 | 3 | namespace taichi::lang { 4 | 5 | std::string offloaded_task_type_name(OffloadedTaskType tt) { 6 | if (false) { 7 | } 8 | #define PER_TASK_TYPE(x) else if (tt == OffloadedTaskType::x) return #x; 9 | #include "taichi/inc/offloaded_task_type.inc.h" 10 | #undef PER_TASK_TYPE 11 | else 12 | TI_NOT_IMPLEMENTED 13 | } 14 | 15 | } // namespace taichi::lang 16 | -------------------------------------------------------------------------------- /taichi/ir/offloaded_task_type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/common/core.h" 4 | 5 | #include 6 | 7 | namespace taichi::lang { 8 | 9 | enum class OffloadedTaskType : int { 10 | #define PER_TASK_TYPE(x) x, 11 | #include "taichi/inc/offloaded_task_type.inc.h" 12 | #undef PER_TASK_TYPE 13 | }; 14 | 15 | std::string offloaded_task_type_name(OffloadedTaskType tt); 16 | 17 | } // namespace taichi::lang 18 | -------------------------------------------------------------------------------- /taichi/ir/pass.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/ir/pass.h" 2 | 3 | namespace taichi::lang { 4 | 5 | const PassID Pass::id = "undefined"; 6 | 7 | } // namespace taichi::lang 8 | -------------------------------------------------------------------------------- /taichi/ir/scratch_pad.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/ir/scratch_pad.h" 2 | 3 | #include "taichi/ir/statements.h" 4 | 5 | namespace taichi::lang { 6 | 7 | std::string ScratchPad::global_to_linearized_local( 8 | const std::vector &loop_vars, 9 | const std::vector &indices) { 10 | std::string ret = ""; 11 | TI_ASSERT((int)indices.size() == dim); 12 | int step_size = pad_size_linear(); 13 | for (int i = 0; i < (int)indices.size(); i++) { 14 | TI_ASSERT(step_size % pad_size[i] == 0); 15 | step_size /= pad_size[i]; 16 | ret += fmt::format(" + ({} - {}_base - {}) * {}", indices[i]->raw_name(), 17 | loop_vars[i]->raw_name(), bounds[i].low, step_size); 18 | } 19 | return ret; 20 | } 21 | 22 | } // namespace taichi::lang 23 | -------------------------------------------------------------------------------- /taichi/ir/snode_types.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/ir/snode_types.h" 2 | 3 | #include "taichi/common/logging.h" 4 | 5 | namespace taichi::lang { 6 | 7 | std::string snode_type_name(SNodeType t) { 8 | switch (t) { 9 | #define PER_SNODE(i) \ 10 | case SNodeType::i: \ 11 | return #i; 12 | 13 | #include "taichi/inc/snodes.inc.h" 14 | 15 | #undef PER_SNODE 16 | default: 17 | TI_NOT_IMPLEMENTED; 18 | } 19 | } 20 | 21 | bool is_gc_able(SNodeType t) { 22 | return (t == SNodeType::pointer || t == SNodeType::dynamic); 23 | } 24 | 25 | } // namespace taichi::lang 26 | -------------------------------------------------------------------------------- /taichi/ir/snode_types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace taichi::lang { 6 | 7 | enum class SNodeType { 8 | #define PER_SNODE(x) x, 9 | #include "taichi/inc/snodes.inc.h" 10 | #undef PER_SNODE 11 | }; 12 | 13 | std::string snode_type_name(SNodeType t); 14 | 15 | bool is_gc_able(SNodeType t); 16 | 17 | } // namespace taichi::lang 18 | -------------------------------------------------------------------------------- /taichi/ir/visitors.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/ir/ir.h" 3 | 4 | namespace taichi::lang { 5 | 6 | // Visits all non-containing statements 7 | class BasicStmtVisitor : public IRVisitor { 8 | public: 9 | BasicStmtVisitor(); 10 | 11 | virtual void preprocess_container_stmt(Stmt *stmt) { 12 | } 13 | 14 | void visit(Block *stmt_list) override; 15 | 16 | void visit(IfStmt *if_stmt) override; 17 | 18 | void visit(WhileStmt *stmt) override; 19 | 20 | void visit(RangeForStmt *for_stmt) override; 21 | 22 | void visit(StructForStmt *for_stmt) override; 23 | 24 | void visit(MeshForStmt *for_stmt) override; 25 | 26 | void visit(OffloadedStmt *stmt) override; 27 | 28 | void visit(FrontendWhileStmt *stmt) override; 29 | 30 | void visit(FrontendForStmt *stmt) override; 31 | 32 | void visit(FrontendIfStmt *stmt) override; 33 | }; 34 | 35 | } // namespace taichi::lang 36 | -------------------------------------------------------------------------------- /taichi/math/arithmetic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "taichi/common/trait.h" 6 | 7 | namespace taichi { 8 | 9 | // Round up |a| to the closest multiple of |b|, works only for integers. 10 | template >> 13 | T iroundup(T a, U b) { 14 | static_assert(std::is_integral_v, "LHS must be integral type"); 15 | static_assert(std::is_integral_v, "RHS must be integral type"); 16 | return ((a + b - 1) / b) * b; 17 | } 18 | 19 | template 20 | uint32_t log2int(T value) { 21 | static_assert(std::is_integral_v, "Must be integral type"); 22 | 23 | uint32_t ret = 0; 24 | value >>= 1; 25 | while (value) { 26 | value >>= 1; 27 | ret += 1; 28 | } 29 | return ret; 30 | } 31 | 32 | } // namespace taichi 33 | -------------------------------------------------------------------------------- /taichi/math/array.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) The Taichi Authors (2016- ). All Rights Reserved. 3 | The use of this software is governed by the LICENSE file. 4 | *******************************************************************************/ 5 | 6 | #pragma once 7 | 8 | #include "array_2d.h" 9 | 10 | namespace taichi { 11 | template 12 | class IndexND; 13 | 14 | template 15 | class RegionND; 16 | 17 | template 18 | class ArrayND; 19 | 20 | } // namespace taichi 21 | -------------------------------------------------------------------------------- /taichi/math/array_fwd.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) The Taichi Authors (2016- ). All Rights Reserved. 3 | The use of this software is governed by the LICENSE file. 4 | *******************************************************************************/ 5 | 6 | #pragma once 7 | 8 | #include "taichi/common/core.h" 9 | 10 | namespace taichi { 11 | 12 | template 13 | class IndexND; 14 | 15 | template 16 | using TIndex = IndexND; 17 | 18 | template 19 | class RegionND; 20 | 21 | template 22 | using TRegion = RegionND; 23 | 24 | template 25 | class ArrayND; 26 | 27 | template 28 | using TArray = ArrayND; 29 | 30 | } // namespace taichi 31 | -------------------------------------------------------------------------------- /taichi/platform/amdgpu/detect_amdgpu.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/platform/amdgpu/detect_amdgpu.h" 2 | 3 | #if defined(TI_WITH_AMDGPU) 4 | #include "taichi/rhi/amdgpu/amdgpu_driver.h" 5 | #endif 6 | 7 | namespace taichi { 8 | 9 | bool is_rocm_api_available() { 10 | #if defined(TI_WITH_AMDGPU) 11 | return lang::AMDGPUDriver::get_instance_without_context().detected(); 12 | #else 13 | return false; 14 | #endif 15 | } 16 | 17 | } // namespace taichi 18 | -------------------------------------------------------------------------------- /taichi/platform/amdgpu/detect_amdgpu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace taichi { 4 | bool is_rocm_api_available(); 5 | } // namespace taichi 6 | -------------------------------------------------------------------------------- /taichi/platform/cuda/detect_cuda.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/platform/cuda/detect_cuda.h" 2 | 3 | #if defined(TI_WITH_CUDA) 4 | #include "taichi/rhi/cuda/cuda_driver.h" 5 | #endif 6 | 7 | namespace taichi { 8 | 9 | bool is_cuda_api_available() { 10 | #if defined(TI_WITH_CUDA) 11 | return lang::CUDADriver::get_instance_without_context().detected(); 12 | #else 13 | return false; 14 | #endif 15 | } 16 | 17 | } // namespace taichi 18 | -------------------------------------------------------------------------------- /taichi/platform/cuda/detect_cuda.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace taichi { 4 | bool is_cuda_api_available(); 5 | } // namespace taichi 6 | -------------------------------------------------------------------------------- /taichi/platform/windows/windows.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | // Never directly include . That will bring you evil max/min macros. 5 | #if defined(min) 6 | #undef min 7 | #endif 8 | #if defined(max) 9 | #undef max 10 | #endif 11 | -------------------------------------------------------------------------------- /taichi/program/extension.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/rhi/arch.h" 4 | 5 | #include 6 | 7 | namespace taichi::lang { 8 | 9 | // The Taichi core feature set (dense SNode) should probably be supported by all 10 | // the backends. In addition, each backend can optionally support features in 11 | // the extension set. 12 | // 13 | // The notion of core vs. extension feature set is defined mainly because the 14 | // Metal backend can only support the dense SNodes. We may need to define this 15 | // notion more precisely in the future. 16 | 17 | enum class Extension { 18 | #define PER_EXTENSION(x) x, 19 | #include "taichi/inc/extensions.inc.h" 20 | 21 | #undef PER_EXTENSION 22 | }; 23 | 24 | bool is_extension_supported(Arch arch, Extension ext); 25 | 26 | } // namespace taichi::lang 27 | -------------------------------------------------------------------------------- /taichi/program/function_key.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/program/function_key.h" 2 | 3 | namespace taichi::lang { 4 | 5 | FunctionKey::FunctionKey(const std::string &func_name, 6 | int func_id, 7 | int instance_id) 8 | : func_name(func_name), func_id(func_id), instance_id(instance_id) { 9 | } 10 | 11 | bool FunctionKey::operator==(const FunctionKey &other_key) const { 12 | return func_id == other_key.func_id && instance_id == other_key.instance_id; 13 | } 14 | 15 | std::string FunctionKey::get_full_name() const { 16 | return func_name + "_" + std::to_string(func_id) + "_" + 17 | std::to_string(instance_id); 18 | } 19 | 20 | } // namespace taichi::lang 21 | -------------------------------------------------------------------------------- /taichi/program/kernel_launcher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/codegen/compiled_kernel_data.h" 4 | #include "taichi/program/launch_context_builder.h" 5 | 6 | namespace taichi::lang { 7 | 8 | class KernelLauncher { 9 | public: 10 | using Handle = KernelLaunchHandle; 11 | 12 | virtual void launch_kernel(const CompiledKernelData &compiled_kernel_data, 13 | LaunchContextBuilder &ctx) = 0; 14 | 15 | virtual ~KernelLauncher() = default; 16 | }; 17 | 18 | } // namespace taichi::lang 19 | -------------------------------------------------------------------------------- /taichi/program/matrix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/type.h" 4 | 5 | namespace taichi::lang { 6 | 7 | /** 8 | * Matrix wrapper used in AOT. 9 | */ 10 | class Matrix { 11 | public: 12 | explicit Matrix(const uint32_t &length, 13 | const DataType dtype, 14 | const intptr_t &data) 15 | : length_(length), dtype_(dtype), data_(data) { 16 | } 17 | 18 | DataType dtype() const { 19 | return dtype_; 20 | } 21 | 22 | uint32_t length() const { 23 | // number of matrix elements 24 | return length_; 25 | } 26 | 27 | intptr_t data() const { 28 | return data_; 29 | } 30 | 31 | private: 32 | uint32_t length_{}; 33 | DataType dtype_{}; 34 | intptr_t data_{}; 35 | }; 36 | 37 | } // namespace taichi::lang 38 | -------------------------------------------------------------------------------- /taichi/program/py_print_buffer.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/program/py_print_buffer.h" 2 | 3 | namespace taichi { 4 | 5 | PythonPrintBuffer py_cout; 6 | 7 | } // namespace taichi 8 | -------------------------------------------------------------------------------- /taichi/program/py_print_buffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace taichi { 7 | 8 | // PythonPrintBuffer holds the logs printed from kernel before sending them back 9 | // to python. The name could be a bit misleading, as it is really just a string 10 | // buffer, and can be used without Python. 11 | struct PythonPrintBuffer { 12 | std::stringstream ss; 13 | bool enabled{false}; 14 | 15 | template 16 | PythonPrintBuffer &operator<<(const T &t) { 17 | if (enabled) 18 | ss << t; 19 | else 20 | std::cout << t; 21 | return *this; 22 | } 23 | std::string pop_content() { 24 | auto ret = ss.str(); 25 | ss = std::stringstream(); 26 | return ret; 27 | } 28 | }; 29 | 30 | extern PythonPrintBuffer py_cout; 31 | 32 | } // namespace taichi 33 | -------------------------------------------------------------------------------- /taichi/python/exception.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) The Taichi Authors (2016- ). All Rights Reserved. 3 | The use of this software is governed by the LICENSE file. 4 | *******************************************************************************/ 5 | 6 | #include "taichi/python/exception.h" 7 | 8 | namespace taichi { 9 | 10 | void raise_assertion_failure_in_python(const std::string &msg) { 11 | throw ExceptionForPython(msg); 12 | } 13 | 14 | } // namespace taichi 15 | 16 | void taichi_raise_assertion_failure_in_python(const char *msg) { 17 | taichi::raise_assertion_failure_in_python(std::string(msg)); 18 | } 19 | -------------------------------------------------------------------------------- /taichi/python/exception.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) The Taichi Authors (2016- ). All Rights Reserved. 3 | The use of this software is governed by the LICENSE file. 4 | *******************************************************************************/ 5 | 6 | #pragma once 7 | 8 | #include "taichi/common/core.h" 9 | 10 | #include 11 | 12 | namespace taichi { 13 | 14 | class ExceptionForPython : public std::exception { 15 | private: 16 | std::string msg_; 17 | 18 | public: 19 | explicit ExceptionForPython(const std::string &msg) : msg_(msg) { 20 | } 21 | char const *what() const noexcept override { 22 | return msg_.c_str(); 23 | } 24 | }; 25 | 26 | void raise_assertion_failure_in_python(const std::string &msg); 27 | 28 | } // namespace taichi 29 | -------------------------------------------------------------------------------- /taichi/python/export.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) The Taichi Authors (2016- ). All Rights Reserved. 3 | The use of this software is governed by the LICENSE file. 4 | *******************************************************************************/ 5 | 6 | #include "taichi/python/export.h" 7 | #include "taichi/common/interface.h" 8 | #include "taichi/util/io.h" 9 | 10 | namespace taichi { 11 | 12 | PYBIND11_MODULE(taichi_python, m) { 13 | m.doc() = "taichi_python"; 14 | 15 | for (auto &kv : InterfaceHolder::get_instance()->methods) { 16 | kv.second(&m); 17 | } 18 | 19 | export_lang(m); 20 | export_math(m); 21 | export_misc(m); 22 | export_visual(m); 23 | export_ggui(m); 24 | } 25 | 26 | } // namespace taichi 27 | -------------------------------------------------------------------------------- /taichi/python/memory_usage_monitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "taichi/common/core.h" 6 | 7 | namespace taichi { 8 | 9 | class MemoryMonitor { 10 | // avoid including py::dict 11 | // py::dict locals; 12 | void *locals_; 13 | std::ofstream log_; 14 | 15 | public: 16 | MemoryMonitor(int pid, std::string output_fn); 17 | ~MemoryMonitor(); 18 | uint64 get_usage() const; 19 | void append_sample(); 20 | }; 21 | 22 | void start_memory_monitoring(std::string output_fn, 23 | int pid = -1, 24 | real interval = 1); 25 | 26 | float64 get_memory_usage_gb(int pid = -1); 27 | uint64 get_memory_usage(int pid = -1); 28 | 29 | } // namespace taichi 30 | -------------------------------------------------------------------------------- /taichi/python/py_exception_translator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "pybind11/pybind11.h" 4 | 5 | namespace taichi { 6 | 7 | namespace { 8 | 9 | // Translates and propagates a CPP exception to Python. 10 | // TODO(#2198): How can we glob all these global variables used as initializaers 11 | // into a single function? 12 | class ExceptionTranslationImpl { 13 | public: 14 | explicit ExceptionTranslationImpl() { 15 | pybind11::register_exception_translator([](std::exception_ptr p) { 16 | try { 17 | if (p) 18 | std::rethrow_exception(p); 19 | } catch (const std::string &e) { 20 | PyErr_SetString(PyExc_RuntimeError, e.c_str()); 21 | } 22 | }); 23 | } 24 | }; 25 | 26 | ExceptionTranslationImpl _; 27 | 28 | } // namespace 29 | } // namespace taichi 30 | -------------------------------------------------------------------------------- /taichi/rhi/amdgpu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/rhi/amdgpu/CMakeLists.txt 2 | 3 | set(AMDGPU_RHI amdgpu_rhi) 4 | add_library(${AMDGPU_RHI}) 5 | target_sources(${AMDGPU_RHI} 6 | PRIVATE 7 | amdgpu_device.cpp 8 | amdgpu_context.cpp 9 | amdgpu_driver.cpp 10 | amdgpu_profiler.cpp 11 | ) 12 | 13 | target_include_directories(${AMDGPU_RHI} 14 | PRIVATE 15 | ${PROJECT_SOURCE_DIR} 16 | ${PROJECT_SOURCE_DIR}/external/eigen 17 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 18 | ${LLVM_INCLUDE_DIRS} 19 | ) 20 | -------------------------------------------------------------------------------- /taichi/rhi/amdgpu/amdgpu_types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef enum HIPfunction_attribute_enum { 4 | HIP_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK = 0, 5 | HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES = 1, 6 | HIP_FUNC_ATTRIBUTE_CONST_SIZE_BYTES = 2, 7 | HIP_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES = 3, 8 | HIP_FUNC_ATTRIBUTE_NUM_REGS = 4, 9 | HIP_FUNC_ATTRIBUTE_PTX_VERSION = 5, 10 | HIP_FUNC_ATTRIBUTE_BINARY_VERSION = 6, 11 | HIP_FUNC_ATTRIBUTE_CACHE_MODE_CA = 7, 12 | HIP_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES = 8, 13 | HIP_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT = 9, 14 | HIP_FUNC_ATTRIBUTE_MAX 15 | } HIPfunction_attribute; 16 | -------------------------------------------------------------------------------- /taichi/rhi/arch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace taichi { 6 | 7 | enum class Arch : int { 8 | #define PER_ARCH(x) x, 9 | #include "taichi/inc/archs.inc.h" 10 | 11 | #undef PER_ARCH 12 | }; 13 | 14 | std::string arch_name(Arch arch); 15 | 16 | Arch arch_from_name(const std::string &arch); 17 | 18 | bool arch_is_cpu(Arch arch); 19 | 20 | bool arch_is_cuda(Arch arch); 21 | 22 | bool arch_uses_llvm(Arch arch); 23 | 24 | bool arch_is_gpu(Arch arch); 25 | 26 | bool arch_uses_spirv(Arch arch); 27 | 28 | Arch host_arch(); 29 | 30 | bool arch_use_host_memory(Arch arch); 31 | 32 | int default_simd_width(Arch arch); 33 | 34 | } // namespace taichi 35 | -------------------------------------------------------------------------------- /taichi/rhi/common/window_system.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef TI_WITH_GLFW 4 | #include "GLFW/glfw3.h" 5 | #ifdef TI_WITH_METAL 6 | #define GLFW_EXPOSE_NATIVE_COCOA 7 | #import 8 | #endif 9 | #endif // TI_WITH_GLFW 10 | 11 | namespace taichi::lang::window_system { 12 | 13 | bool glfw_context_acquire(); 14 | void glfw_context_release(); 15 | 16 | } // namespace taichi::lang::window_system 17 | -------------------------------------------------------------------------------- /taichi/rhi/cpu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/rhi/cpu/CMakeLists.txt 2 | 3 | set(CPU_RHI cpu_rhi) 4 | add_library(${CPU_RHI}) 5 | target_sources(${CPU_RHI} 6 | PRIVATE 7 | cpu_device.cpp 8 | ) 9 | 10 | target_include_directories(${CPU_RHI} 11 | PRIVATE 12 | ${PROJECT_SOURCE_DIR} 13 | ${PROJECT_SOURCE_DIR}/external/eigen 14 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 15 | ${PROJECT_SOURCE_DIR}/external/glfw/include 16 | ) 17 | -------------------------------------------------------------------------------- /taichi/rhi/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/rhi/cuda/CMakeLists.txt 2 | 3 | set(CUDA_RHI cuda_rhi) 4 | add_library(${CUDA_RHI}) 5 | target_sources(${CUDA_RHI} 6 | PRIVATE 7 | cuda_device.cpp 8 | cuda_context.cpp 9 | cuda_driver.cpp 10 | cuda_profiler.cpp 11 | cupti_toolkit.cpp 12 | ) 13 | 14 | target_include_directories(${CUDA_RHI} 15 | PRIVATE 16 | ${PROJECT_SOURCE_DIR} 17 | ${PROJECT_SOURCE_DIR}/external/eigen 18 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 19 | ${PROJECT_SOURCE_DIR}/external/glfw/include 20 | ) 21 | 22 | target_link_libraries(${CUDA_RHI} PRIVATE interop_rhi) 23 | -------------------------------------------------------------------------------- /taichi/rhi/device.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/common/logging.h" 4 | #include "taichi/common/core.h" 5 | 6 | #include "public_device.h" 7 | -------------------------------------------------------------------------------- /taichi/rhi/dummy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/taichi/rhi/dummy.cpp -------------------------------------------------------------------------------- /taichi/rhi/dx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/rhi/dx/CMakeLists.txt 2 | 3 | set(DX_RHI dx_rhi) 4 | add_library(${DX_RHI}) 5 | target_sources(${DX_RHI} 6 | PRIVATE 7 | dx_api.cpp 8 | dx_device.cpp 9 | dx_info_queue.cpp 10 | ) 11 | 12 | target_include_directories(${DX_RHI} 13 | PRIVATE 14 | ${PROJECT_SOURCE_DIR} 15 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 16 | ${PROJECT_SOURCE_DIR}/external/SPIRV-Cross 17 | ) 18 | 19 | target_link_libraries(${DX_RHI} PRIVATE spirv-cross-hlsl spirv-cross-core) 20 | -------------------------------------------------------------------------------- /taichi/rhi/dx/dx_api.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/rhi/dx/dx_api.h" 2 | #include "taichi/rhi/dx/dx_device.h" 3 | 4 | namespace taichi::lang { 5 | namespace directx11 { 6 | 7 | bool is_dx_api_available() { 8 | #ifdef TI_WITH_DX11 9 | return true; 10 | #else 11 | return false; 12 | #endif 13 | } 14 | 15 | std::shared_ptr make_dx11_device() { 16 | return std::make_shared(); 17 | } 18 | 19 | } // namespace directx11 20 | } // namespace taichi::lang 21 | -------------------------------------------------------------------------------- /taichi/rhi/dx/dx_api.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/common/core.h" 3 | #include "taichi/rhi/device.h" 4 | 5 | #ifdef TI_WITH_DX11 6 | #pragma comment(lib, "d3d11.lib") 7 | #pragma comment(lib, "d3dcompiler.lib") 8 | #pragma comment(lib, "dxguid.lib") 9 | #include 10 | #endif 11 | 12 | namespace taichi::lang { 13 | namespace directx11 { 14 | 15 | bool is_dx_api_available(); 16 | 17 | std::shared_ptr make_dx11_device(); 18 | 19 | } // namespace directx11 20 | } // namespace taichi::lang 21 | -------------------------------------------------------------------------------- /taichi/rhi/dx12/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/rhi/dx12/CMakeLists.txt 2 | 3 | set(DX12_RHI dx12_rhi) 4 | add_library(${DX12_RHI}) 5 | target_sources(${DX12_RHI} 6 | PRIVATE 7 | dx12_api.cpp 8 | ) 9 | 10 | target_include_directories(${DX12_RHI} 11 | PRIVATE 12 | ${PROJECT_SOURCE_DIR} 13 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 14 | ) 15 | 16 | target_link_libraries(${DX12_RHI} PRIVATE ) 17 | -------------------------------------------------------------------------------- /taichi/rhi/dx12/dx12_api.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/rhi/dx12/dx12_api.h" 2 | 3 | namespace taichi::lang { 4 | namespace directx12 { 5 | 6 | bool is_dx12_api_available() { 7 | #ifdef TI_WITH_DX12 8 | return true; 9 | #else 10 | return false; 11 | #endif 12 | } 13 | 14 | std::shared_ptr make_dx12_device() { 15 | return nullptr; 16 | } 17 | 18 | std::vector validate_and_sign( 19 | std::vector &input_dxil_container) { 20 | // FIXME: implement validation and sign by calling IDxcValidator::Validate 21 | // from DXIL.dll. 22 | return input_dxil_container; 23 | } 24 | 25 | } // namespace directx12 26 | } // namespace taichi::lang 27 | -------------------------------------------------------------------------------- /taichi/rhi/dx12/dx12_api.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/common/core.h" 3 | #include "taichi/rhi/device.h" 4 | 5 | #ifdef TI_WITH_DX12 6 | 7 | #endif 8 | 9 | namespace taichi::lang { 10 | namespace directx12 { 11 | 12 | bool is_dx12_api_available(); 13 | 14 | std::shared_ptr make_dx12_device(); 15 | 16 | std::vector validate_and_sign( 17 | std::vector &input_dxil_container); 18 | 19 | } // namespace directx12 20 | } // namespace taichi::lang 21 | -------------------------------------------------------------------------------- /taichi/rhi/interop/vulkan_cpu_interop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/rhi/device.h" 4 | 5 | namespace taichi::lang { 6 | 7 | void memcpy_cpu_to_vulkan(DevicePtr dst, DevicePtr src, uint64_t size); 8 | 9 | void memcpy_cpu_to_vulkan_via_staging(DevicePtr dst, 10 | DevicePtr staging, 11 | DevicePtr src, 12 | uint64_t size); 13 | 14 | } // namespace taichi::lang 15 | -------------------------------------------------------------------------------- /taichi/rhi/interop/vulkan_cuda_interop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/rhi/device.h" 4 | 5 | namespace taichi::lang { 6 | 7 | void memcpy_cuda_to_vulkan(DevicePtr dst, DevicePtr src, uint64_t size); 8 | 9 | void memcpy_vulkan_to_cuda(DevicePtr dst, DevicePtr src, uint64_t size); 10 | 11 | } // namespace taichi::lang 12 | -------------------------------------------------------------------------------- /taichi/rhi/llvm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/rhi/llvm/CMakeLists.txt 2 | 3 | set(LLVM_RHI llvm_rhi) 4 | add_library(${LLVM_RHI}) 5 | target_sources(${LLVM_RHI} 6 | PRIVATE 7 | allocator.cpp 8 | device_memory_pool.cpp 9 | ) 10 | 11 | target_include_directories(${LLVM_RHI} 12 | PRIVATE 13 | ${PROJECT_SOURCE_DIR} 14 | ) 15 | 16 | target_link_libraries(${LLVM_RHI} PRIVATE taichi_util) 17 | -------------------------------------------------------------------------------- /taichi/rhi/llvm/allocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/common/core.h" 4 | #include "taichi/math/arithmetic.h" 5 | #include "taichi/rhi/llvm/llvm_device.h" 6 | #include "taichi/inc/constants.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace taichi::lang { 12 | 13 | class CachingAllocator { 14 | public: 15 | explicit CachingAllocator(bool merge_upon_release = true); 16 | 17 | uint64_t *allocate(LlvmDevice *device, 18 | const LlvmDevice::LlvmRuntimeAllocParams ¶ms); 19 | void release(size_t sz, uint64_t *ptr); 20 | 21 | private: 22 | void merge_and_insert(uint8_t *ptr, std::size_t size); 23 | 24 | std::set> mem_blocks_; 25 | std::map ptr_map_; 26 | 27 | // Allocator options 28 | bool merge_upon_release_ = true; 29 | }; 30 | 31 | } // namespace taichi::lang 32 | -------------------------------------------------------------------------------- /taichi/rhi/metal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/rhi/metal/CMakeLists.txt 2 | 3 | set(METAL_RHI metal_rhi) 4 | add_library(${METAL_RHI}) 5 | target_sources(${METAL_RHI} 6 | PRIVATE 7 | metal_api.cpp 8 | metal_device.mm 9 | ) 10 | 11 | # TODO(#4832) some dependencies here should not be required as they 12 | # are build requirements of other targets. 13 | target_include_directories(${METAL_RHI} 14 | PRIVATE 15 | ${PROJECT_SOURCE_DIR} 16 | ${PROJECT_SOURCE_DIR}/external/SPIRV-Cross 17 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 18 | ${PROJECT_SOURCE_DIR}/external/glad/include 19 | ${PROJECT_SOURCE_DIR}/external/glfw/include 20 | ) 21 | target_link_libraries(${METAL_RHI} PRIVATE spirv-cross-msl spirv-cross-core "-framework QuartzCore") 22 | -------------------------------------------------------------------------------- /taichi/rhi/metal/metal_api.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/rhi/metal/metal_api.h" 2 | #include "taichi/rhi/metal/metal_device.h" 3 | 4 | namespace taichi::lang { 5 | namespace metal { 6 | 7 | bool is_metal_api_available() { 8 | #if defined(__APPLE__) && defined(TI_WITH_METAL) 9 | return true; 10 | #else 11 | return false; 12 | #endif // defined(__APPLE__) && defined(TI_WITH_METAL) 13 | } 14 | 15 | std::shared_ptr create_metal_device() { 16 | #if defined(__APPLE__) && defined(TI_WITH_METAL) 17 | return std::shared_ptr(metal::MetalDevice::create()); 18 | #else 19 | return nullptr; 20 | #endif // defined(__APPLE__) && defined(TI_WITH_METAL) 21 | } 22 | 23 | } // namespace metal 24 | } // namespace taichi::lang 25 | -------------------------------------------------------------------------------- /taichi/rhi/metal/metal_api.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/rhi/device.h" 3 | 4 | namespace taichi::lang { 5 | namespace metal { 6 | 7 | bool is_metal_api_available(); 8 | 9 | std::shared_ptr create_metal_device(); 10 | 11 | } // namespace metal 12 | } // namespace taichi::lang 13 | -------------------------------------------------------------------------------- /taichi/rhi/opengl/opengl_api.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/common/core.h" 4 | #include "taichi/rhi/impl_support.h" 5 | #include "taichi/rhi/device.h" 6 | 7 | namespace taichi::lang { 8 | namespace opengl { 9 | 10 | void set_gles_override(bool value); 11 | void unset_gles_override(); 12 | bool initialize_opengl(bool use_gles = false, bool error_tolerance = false); 13 | bool is_opengl_api_available(bool use_gles = false); 14 | bool is_gles(); 15 | void reset_opengl(); 16 | 17 | std::shared_ptr make_opengl_device(); 18 | 19 | #define PER_OPENGL_EXTENSION(x) extern bool opengl_extension_##x; 20 | #include "taichi/inc/opengl_extension.inc.h" 21 | #undef PER_OPENGL_EXTENSION 22 | 23 | } // namespace opengl 24 | } // namespace taichi::lang 25 | -------------------------------------------------------------------------------- /taichi/rhi/vulkan/vulkan_memory_allocator.cpp: -------------------------------------------------------------------------------- 1 | #include "vulkan_device_creator.h" 2 | 3 | #define VMA_IMPLEMENTATION 4 | #define VMA_DEDICATED_ALLOCATION 0 5 | #define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 6 | #include "vk_mem_alloc.h" 7 | -------------------------------------------------------------------------------- /taichi/runtime/.gitignore: -------------------------------------------------------------------------------- 1 | *.ll 2 | *.bc 3 | -------------------------------------------------------------------------------- /taichi/runtime/amdgpu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/amdgpu/CMakeLists.txt 2 | 3 | add_library(amdgpu_runtime) 4 | target_sources(amdgpu_runtime 5 | PRIVATE 6 | jit_amdgpu.cpp 7 | kernel_launcher.cpp 8 | ) 9 | 10 | target_include_directories(amdgpu_runtime 11 | PRIVATE 12 | ${PROJECT_SOURCE_DIR} 13 | ${PROJECT_SOURCE_DIR}/external/eigen 14 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 15 | ${LLVM_INCLUDE_DIRS} 16 | ) 17 | -------------------------------------------------------------------------------- /taichi/runtime/cpu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/cpu/CMakeLists.txt 2 | 3 | add_library(cpu_runtime) 4 | target_sources(cpu_runtime 5 | PRIVATE 6 | jit_cpu.cpp 7 | kernel_launcher.cpp 8 | ) 9 | 10 | #TODO #4832, some path here should not be included as they are 11 | # dependencies of other targets. 12 | target_include_directories(cpu_runtime 13 | PRIVATE 14 | ${PROJECT_SOURCE_DIR} 15 | ${PROJECT_SOURCE_DIR}/external/eigen 16 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 17 | ${LLVM_INCLUDE_DIRS} 18 | ) 19 | -------------------------------------------------------------------------------- /taichi/runtime/cpu/kernel_launcher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/codegen/llvm/compiled_kernel_data.h" 4 | #include "taichi/runtime/llvm/kernel_launcher.h" 5 | 6 | namespace taichi::lang { 7 | namespace cpu { 8 | 9 | class KernelLauncher : public LLVM::KernelLauncher { 10 | using Base = LLVM::KernelLauncher; 11 | 12 | struct Context { 13 | using TaskFunc = int32 (*)(void *); 14 | std::vector task_funcs; 15 | std::vector, Callable::Parameter>> parameters; 16 | }; 17 | 18 | public: 19 | using Base::Base; 20 | 21 | void launch_llvm_kernel(Handle handle, LaunchContextBuilder &ctx) override; 22 | Handle register_llvm_kernel( 23 | const LLVM::CompiledKernelData &compiled) override; 24 | 25 | private: 26 | std::vector contexts_; 27 | }; 28 | 29 | } // namespace cpu 30 | } // namespace taichi::lang 31 | -------------------------------------------------------------------------------- /taichi/runtime/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/cuda/CMakeLists.txt 2 | 3 | add_library(cuda_runtime) 4 | target_sources(cuda_runtime 5 | PRIVATE 6 | jit_cuda.cpp 7 | kernel_launcher.cpp 8 | ) 9 | 10 | target_include_directories(cuda_runtime 11 | PRIVATE 12 | ${PROJECT_SOURCE_DIR} 13 | ${PROJECT_SOURCE_DIR}/external/eigen 14 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 15 | ${LLVM_INCLUDE_DIRS} 16 | ) 17 | -------------------------------------------------------------------------------- /taichi/runtime/dx12/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/dx12/CMakeLists.txt 2 | 3 | add_library(dx12_runtime) 4 | target_sources(dx12_runtime 5 | PRIVATE 6 | aot_module_builder_impl.cpp 7 | aot_module_loader_impl.cpp 8 | ) 9 | 10 | target_include_directories(dx12_runtime 11 | PRIVATE 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 14 | ${PROJECT_SOURCE_DIR} 15 | ${LLVM_INCLUDE_DIRS} 16 | ) 17 | -------------------------------------------------------------------------------- /taichi/runtime/dx12/aot_graph_data.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/aot/graph_data.h" 3 | 4 | namespace taichi { 5 | namespace lang { 6 | namespace directx12 { 7 | class KernelImpl : public aot::Kernel { 8 | public: 9 | explicit KernelImpl() { 10 | } 11 | 12 | void launch(LaunchContextBuilder &ctx) override { 13 | } 14 | }; 15 | } // namespace directx12 16 | } // namespace lang 17 | } // namespace taichi 18 | -------------------------------------------------------------------------------- /taichi/runtime/dx12/aot_module_loader_impl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "taichi/aot/module_builder.h" 8 | #include "taichi/aot/module_loader.h" 9 | 10 | namespace taichi { 11 | namespace lang { 12 | namespace directx12 { 13 | 14 | struct TI_DLL_EXPORT AotModuleParams { 15 | std::string module_path; 16 | }; 17 | 18 | TI_DLL_EXPORT std::unique_ptr make_aot_module( 19 | std::any mod_params, 20 | Arch device_api_backend); 21 | 22 | } // namespace directx12 23 | } // namespace lang 24 | } // namespace taichi 25 | -------------------------------------------------------------------------------- /taichi/runtime/gfx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/gfx/CMakeLists.txt 2 | 3 | add_library(gfx_runtime) 4 | target_sources(gfx_runtime 5 | PRIVATE 6 | runtime.cpp 7 | snode_tree_manager.cpp 8 | aot_module_builder_impl.cpp 9 | aot_module_loader_impl.cpp 10 | kernel_launcher.cpp 11 | ) 12 | #TODO 4832, some dependencies here should not be required as they 13 | # are build requirements of other targets. 14 | target_include_directories(gfx_runtime 15 | PRIVATE 16 | ${PROJECT_SOURCE_DIR} 17 | ${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include 18 | ${PROJECT_SOURCE_DIR}/external/eigen 19 | ${PROJECT_SOURCE_DIR}/external/FP16/include 20 | PRIVATE 21 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 22 | ${LLVM_INCLUDE_DIRS} 23 | ) 24 | target_link_libraries(gfx_runtime PRIVATE taichi_common) 25 | -------------------------------------------------------------------------------- /taichi/runtime/gfx/aot_utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "taichi/codegen/spirv/kernel_utils.h" 7 | #include "taichi/aot/module_loader.h" 8 | 9 | namespace taichi::lang { 10 | namespace gfx { 11 | 12 | /** 13 | * AOT module data for the Unified Device API backend. 14 | */ 15 | struct TaichiAotData { 16 | // BufferMetaData metadata; 17 | std::vector>> spirv_codes; 18 | std::vector kernels; 19 | std::vector fields; 20 | std::map required_caps; 21 | size_t root_buffer_size{0}; 22 | 23 | TI_IO_DEF(kernels, fields, required_caps, root_buffer_size); 24 | }; 25 | 26 | } // namespace gfx 27 | } // namespace taichi::lang 28 | -------------------------------------------------------------------------------- /taichi/runtime/gfx/kernel_launcher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/program/kernel_launcher.h" 4 | #include "taichi/runtime/gfx/runtime.h" 5 | 6 | namespace taichi::lang { 7 | namespace gfx { 8 | 9 | class KernelLauncher : public lang::KernelLauncher { 10 | public: 11 | struct Config { 12 | GfxRuntime *gfx_runtime_{nullptr}; 13 | }; 14 | 15 | explicit KernelLauncher(Config config); 16 | 17 | void launch_kernel(const lang::CompiledKernelData &compiled_kernel_data, 18 | LaunchContextBuilder &ctx) override; 19 | 20 | private: 21 | Handle register_kernel(const lang::CompiledKernelData &compiled_kernel_data); 22 | 23 | Config config_; 24 | }; 25 | 26 | } // namespace gfx 27 | } // namespace taichi::lang 28 | -------------------------------------------------------------------------------- /taichi/runtime/llvm/kernel_launcher.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/runtime/llvm/kernel_launcher.h" 2 | 3 | namespace taichi::lang { 4 | namespace LLVM { 5 | 6 | KernelLauncher::KernelLauncher(Config config) : config_(std::move(config)) { 7 | } 8 | 9 | void KernelLauncher::launch_kernel( 10 | const lang::CompiledKernelData &compiled_kernel_data, 11 | LaunchContextBuilder &ctx) { 12 | TI_ASSERT(arch_uses_llvm(compiled_kernel_data.arch())); 13 | const auto &llvm_ckd = 14 | dynamic_cast(compiled_kernel_data); 15 | auto handle = register_llvm_kernel(llvm_ckd); 16 | launch_llvm_kernel(handle, ctx); 17 | } 18 | 19 | } // namespace LLVM 20 | } // namespace taichi::lang 21 | -------------------------------------------------------------------------------- /taichi/runtime/llvm/llvm_fwd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace llvm { 4 | class LLVMContext; 5 | class Type; 6 | class Value; 7 | class Module; 8 | class Function; 9 | class DataLayout; 10 | class StructType; 11 | class JITSymbol; 12 | class ExitOnError; 13 | namespace orc { 14 | class ThreadSafeContext; 15 | } 16 | } // namespace llvm 17 | -------------------------------------------------------------------------------- /taichi/runtime/llvm/runtime_module/cuda_runtime-cuda-nvptx64-nvidia-cuda-sm_60.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/taichi/runtime/llvm/runtime_module/cuda_runtime-cuda-nvptx64-nvidia-cuda-sm_60.bc -------------------------------------------------------------------------------- /taichi/runtime/llvm/runtime_module/cuda_runtime.cu: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | Enable optimizations via hand-writting cuda kernels 5 | 6 | CUDA kernels defined in this file will be compiled by clang++ following: 7 | https://llvm.org/docs/CompileCudaWithLLVM.html. The resulting LLVM module 8 | will get loaded via "module_from_bitcode_file" and link with the LLVM Module 9 | from Taichi JIT compiler. 10 | 11 | During code generation, one may apply call("half2_atomic_add", ...) to make 12 | use of the kernels. 13 | */ 14 | 15 | extern "C" { 16 | 17 | __device__ void half2_atomic_add(void *ptr_i, void *old_val_i, void *val_i) { 18 | half *ptr = (half *)ptr_i; 19 | half *old_val = (half *)old_val_i; 20 | half *val = (half *)val_i; 21 | 22 | __half2 v = {val[0], val[1]}; 23 | __half2 old_v = atomicAdd((__half2 *)&ptr[0], v); 24 | 25 | *(__half2 *)&old_val[0] = old_v; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /taichi/runtime/llvm/runtime_module/node_dense.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Specialized Attributes and functions 4 | struct DenseMeta : public StructMeta { 5 | int morton_dim; 6 | }; 7 | 8 | STRUCT_FIELD(DenseMeta, morton_dim) 9 | 10 | i32 Dense_get_num_elements(Ptr meta, Ptr node) { 11 | return ((StructMeta *)meta)->max_num_elements; 12 | } 13 | 14 | void Dense_activate(Ptr meta, Ptr node, int i) { 15 | // Dense elements are always active 16 | } 17 | 18 | u1 Dense_is_active(Ptr meta, Ptr node, int i) { 19 | return true; 20 | } 21 | 22 | Ptr Dense_lookup_element(Ptr meta, Ptr node, int i) { 23 | return node + ((StructMeta *)meta)->element_size * i; 24 | } 25 | -------------------------------------------------------------------------------- /taichi/runtime/llvm/runtime_module/node_root.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct RootMeta : public StructMeta { 4 | int tag; 5 | }; 6 | 7 | STRUCT_FIELD(RootMeta, tag); 8 | 9 | void Root_activate(Ptr meta, Ptr node, int i) { 10 | } 11 | 12 | u1 Root_is_active(Ptr meta, Ptr node, int i) { 13 | return true; 14 | } 15 | 16 | Ptr Root_lookup_element(Ptr meta, Ptr node, int i) { 17 | // only one element 18 | return node; 19 | } 20 | 21 | i32 Root_get_num_elements(Ptr meta, Ptr node) { 22 | return 1; 23 | } 24 | -------------------------------------------------------------------------------- /taichi/runtime/llvm/snode_tree_buffer_manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/inc/constants.h" 3 | #include "taichi/struct/snode_tree.h" 4 | #include "taichi/rhi/public_device.h" 5 | #define TI_RUNTIME_HOST 6 | 7 | #include 8 | 9 | using Ptr = uint8_t *; 10 | 11 | namespace taichi::lang { 12 | 13 | class JITModule; 14 | class LlvmRuntimeExecutor; 15 | 16 | class SNodeTreeBufferManager { 17 | public: 18 | explicit SNodeTreeBufferManager(LlvmRuntimeExecutor *runtime_exec); 19 | 20 | Ptr allocate(std::size_t size, 21 | const int snode_tree_id, 22 | uint64 *result_buffer); 23 | 24 | void destroy(SNodeTree *snode_tree); 25 | 26 | private: 27 | LlvmRuntimeExecutor *runtime_exec_; 28 | std::map snode_tree_id_to_device_alloc_; 29 | }; 30 | 31 | } // namespace taichi::lang 32 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/dx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/program_impls/dx/CMakeLists.txt 2 | 3 | add_library(dx_program_impl) 4 | target_sources(dx_program_impl 5 | PRIVATE 6 | dx_program.cpp 7 | ) 8 | 9 | target_include_directories(dx_program_impl 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 14 | ${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include 15 | ${LLVM_INCLUDE_DIRS} 16 | ) 17 | 18 | target_link_libraries(dx_program_impl PRIVATE compilation_manager) 19 | target_link_libraries(dx_program_impl PRIVATE gfx_program_impl) 20 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/dx/dx_program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef TI_WITH_DX11 4 | 5 | #include "taichi/runtime/gfx/runtime.h" 6 | #include "taichi/runtime/gfx/snode_tree_manager.h" 7 | #include "taichi/runtime/program_impls/gfx/gfx_program.h" 8 | 9 | namespace taichi::lang { 10 | 11 | class Dx11ProgramImpl : public GfxProgramImpl { 12 | public: 13 | Dx11ProgramImpl(CompileConfig &config); 14 | 15 | void materialize_runtime(KernelProfilerBase *profiler, 16 | uint64 **result_buffer_ptr) override; 17 | }; 18 | 19 | } // namespace taichi::lang 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/dx12/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/program_impls/dx12/CMakeLists.txt 2 | 3 | add_library(dx12_program_impl) 4 | target_sources(dx12_program_impl 5 | PRIVATE 6 | dx12_program.cpp 7 | ) 8 | 9 | target_include_directories(dx12_program_impl 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 14 | 15 | ${PROJECT_SOURCE_DIR}/external/DirectX-Headers/include 16 | ${LLVM_INCLUDE_DIRS} 17 | ) 18 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/dx12/dx12_program.cpp: -------------------------------------------------------------------------------- 1 | #ifdef TI_WITH_DX12 2 | 3 | #include "taichi/runtime/program_impls/dx12/dx12_program.h" 4 | #include "taichi/runtime/dx12/aot_module_builder_impl.h" 5 | #include "taichi/rhi/dx12/dx12_api.h" 6 | 7 | namespace taichi { 8 | namespace lang { 9 | 10 | Dx12ProgramImpl::Dx12ProgramImpl(CompileConfig &config) 11 | : LlvmProgramImpl(config, nullptr) { 12 | } 13 | 14 | std::unique_ptr Dx12ProgramImpl::make_aot_module_builder( 15 | const DeviceCapabilityConfig &caps) { 16 | return std::make_unique(*config, this, 17 | *get_llvm_context()); 18 | } 19 | 20 | } // namespace lang 21 | } // namespace taichi 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/dx12/dx12_program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef TI_WITH_DX12 4 | 5 | #include "taichi/runtime/program_impls/llvm/llvm_program.h" 6 | 7 | namespace taichi { 8 | namespace lang { 9 | 10 | class Dx12ProgramImpl : public LlvmProgramImpl { 11 | public: 12 | Dx12ProgramImpl(CompileConfig &config); 13 | 14 | std::unique_ptr make_aot_module_builder( 15 | const DeviceCapabilityConfig &caps) override; 16 | }; 17 | 18 | } // namespace lang 19 | } // namespace taichi 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/gfx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/program_impls/gfx/CMakeLists.txt 2 | 3 | add_library(gfx_program_impl) 4 | target_sources(gfx_program_impl 5 | PRIVATE 6 | gfx_program.cpp 7 | ) 8 | 9 | target_include_directories(gfx_program_impl 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 14 | ${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include 15 | ${LLVM_INCLUDE_DIRS} 16 | ) 17 | 18 | target_link_libraries(gfx_program_impl PRIVATE gfx_runtime) 19 | target_link_libraries(gfx_program_impl PRIVATE compilation_manager) 20 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/llvm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/program_impls/llvm/CMakeLists.txt 2 | 3 | add_library(llvm_program_impl) 4 | target_sources(llvm_program_impl 5 | PRIVATE 6 | llvm_program.cpp 7 | ) 8 | 9 | target_include_directories(llvm_program_impl 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 14 | ${LLVM_INCLUDE_DIRS} 15 | ) 16 | 17 | target_link_libraries(llvm_program_impl PRIVATE llvm_codegen) 18 | 19 | target_link_libraries(llvm_program_impl PRIVATE cpu_runtime) 20 | if (TI_WITH_CUDA) 21 | target_link_libraries(llvm_program_impl PRIVATE cuda_runtime) 22 | endif() 23 | 24 | if (TI_WITH_AMDGPU) 25 | target_link_libraries(llvm_program_impl PRIVATE amdgpu_runtime) 26 | endif() 27 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/metal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/program_impls/metal/CMakeLists.txt 2 | 3 | add_library(metal_program_impl) 4 | target_sources(metal_program_impl 5 | PRIVATE 6 | metal_program.cpp 7 | ) 8 | 9 | target_include_directories(metal_program_impl 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 14 | ${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include 15 | ${LLVM_INCLUDE_DIRS} 16 | ) 17 | 18 | target_link_libraries(metal_program_impl PRIVATE spirv_codegen) 19 | target_link_libraries(metal_program_impl PRIVATE gfx_runtime) 20 | target_link_libraries(metal_program_impl PRIVATE gfx_program_impl) 21 | target_link_libraries(metal_program_impl PRIVATE compilation_manager) 22 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/opengl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/runtime/program_impls/opengl/CMakeLists.txt 2 | 3 | add_library(opengl_program_impl) 4 | target_sources(opengl_program_impl 5 | PRIVATE 6 | opengl_program.cpp 7 | ) 8 | 9 | target_include_directories(opengl_program_impl 10 | PRIVATE 11 | ${PROJECT_SOURCE_DIR} 12 | ${PROJECT_SOURCE_DIR}/external/eigen 13 | ${PROJECT_SOURCE_DIR}/external/spdlog/include 14 | ${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include 15 | ${LLVM_INCLUDE_DIRS} 16 | ) 17 | 18 | target_link_libraries(opengl_program_impl PRIVATE gfx_runtime) 19 | target_link_libraries(opengl_program_impl PRIVATE gfx_program_impl) 20 | target_link_libraries(opengl_program_impl PRIVATE compilation_manager) 21 | -------------------------------------------------------------------------------- /taichi/runtime/program_impls/opengl/opengl_program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/runtime/gfx/runtime.h" 4 | #include "taichi/runtime/gfx/snode_tree_manager.h" 5 | #include "taichi/program/program_impl.h" 6 | #include "taichi/runtime/program_impls/gfx/gfx_program.h" 7 | 8 | namespace taichi::lang { 9 | 10 | class OpenglProgramImpl : public GfxProgramImpl { 11 | public: 12 | explicit OpenglProgramImpl(CompileConfig &config); 13 | 14 | void finalize() override; 15 | 16 | void materialize_runtime(KernelProfilerBase *profiler, 17 | uint64 **result_buffer_ptr) override; 18 | }; 19 | 20 | } // namespace taichi::lang 21 | -------------------------------------------------------------------------------- /taichi/struct/struct.cpp: -------------------------------------------------------------------------------- 1 | // Codegen for the hierarchical data structure 2 | 3 | #include "struct.h" 4 | 5 | namespace taichi::lang { 6 | 7 | void StructCompiler::collect_snodes(SNode &snode) { 8 | snodes.push_back(&snode); 9 | for (int ch_id = 0; ch_id < (int)snode.ch.size(); ch_id++) { 10 | auto &ch = snode.ch[ch_id]; 11 | collect_snodes(*ch); 12 | } 13 | } 14 | 15 | } // namespace taichi::lang 16 | -------------------------------------------------------------------------------- /taichi/struct/struct.h: -------------------------------------------------------------------------------- 1 | // Codegen for the hierarchical data structure 2 | #pragma once 3 | 4 | #include "taichi/ir/snode.h" 5 | 6 | namespace taichi::lang { 7 | 8 | class StructCompiler { 9 | public: 10 | std::vector stack; 11 | std::vector snodes; 12 | std::size_t root_size{0}; 13 | 14 | virtual ~StructCompiler() = default; 15 | 16 | void collect_snodes(SNode &snode); 17 | 18 | // generate C++/llvm IR 19 | virtual void generate_types(SNode &snode) = 0; 20 | 21 | virtual void generate_child_accessors(SNode &snode) = 0; 22 | 23 | virtual void run(SNode &node) = 0; 24 | }; 25 | 26 | } // namespace taichi::lang 27 | -------------------------------------------------------------------------------- /taichi/system/hacked_signal_handler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace taichi { 4 | 5 | class HackedSignalRegister { 6 | public: 7 | explicit HackedSignalRegister(); 8 | ~HackedSignalRegister(); 9 | }; 10 | 11 | } // namespace taichi 12 | -------------------------------------------------------------------------------- /taichi/system/interface_registry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "taichi/common/interface.h" 4 | #include "taichi/common/task.h" 5 | #include "taichi/system/benchmark.h" 6 | 7 | namespace taichi { 8 | 9 | TI_INTERFACE_DEF(Benchmark, "benchmark") 10 | TI_INTERFACE_DEF(Task, "task") 11 | 12 | } // namespace taichi 13 | -------------------------------------------------------------------------------- /taichi/system/loader.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) The Taichi Authors (2016- ). All Rights Reserved. 3 | The use of this software is governed by the LICENSE file. 4 | *******************************************************************************/ 5 | -------------------------------------------------------------------------------- /taichi/system/run_tests.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (c) The Taichi Authors (2016- ). All Rights Reserved. 3 | The use of this software is governed by the LICENSE file. 4 | *******************************************************************************/ 5 | 6 | #include "taichi/common/core.h" 7 | #include "taichi/common/task.h" 8 | #include "taichi/util/testing.h" 9 | 10 | namespace taichi { 11 | 12 | class RunTests : public Task { 13 | std::string run(const std::vector ¶meters) override { 14 | return std::to_string(run_tests(parameters)); 15 | } 16 | }; 17 | 18 | TI_IMPLEMENTATION(Task, RunTests, "test"); 19 | 20 | } // namespace taichi 21 | -------------------------------------------------------------------------------- /taichi/system/traceback.h: -------------------------------------------------------------------------------- 1 | #include "taichi/common/core.h" 2 | 3 | namespace taichi { 4 | 5 | void print_traceback(); 6 | 7 | } // namespace taichi 8 | -------------------------------------------------------------------------------- /taichi/transforms/check_out_of_bound.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/pass.h" 4 | 5 | namespace taichi::lang { 6 | 7 | class CheckOutOfBoundPass : public Pass { 8 | public: 9 | static const PassID id; 10 | 11 | struct Args { 12 | std::string kernel_name; 13 | }; 14 | }; 15 | 16 | } // namespace taichi::lang 17 | -------------------------------------------------------------------------------- /taichi/transforms/constant_fold.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/pass.h" 4 | 5 | namespace taichi::lang { 6 | 7 | class ConstantFoldPass : public Pass { 8 | public: 9 | static const PassID id; 10 | 11 | struct Args { 12 | Program *program; 13 | }; 14 | }; 15 | 16 | } // namespace taichi::lang 17 | -------------------------------------------------------------------------------- /taichi/transforms/demote_mesh_statements.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/pass.h" 4 | 5 | namespace taichi::lang { 6 | 7 | class DemoteMeshStatements : public Pass { 8 | public: 9 | static const PassID id; 10 | 11 | struct Args { 12 | std::string kernel_name; 13 | }; 14 | }; 15 | 16 | } // namespace taichi::lang 17 | -------------------------------------------------------------------------------- /taichi/transforms/inlining.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/pass.h" 4 | 5 | namespace taichi::lang { 6 | 7 | class InliningPass : public Pass { 8 | public: 9 | static const PassID id; 10 | 11 | struct Args {}; 12 | }; 13 | 14 | } // namespace taichi::lang 15 | -------------------------------------------------------------------------------- /taichi/transforms/lower_access.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/pass.h" 4 | 5 | namespace taichi::lang { 6 | 7 | class LowerAccessPass : public Pass { 8 | public: 9 | static const PassID id; 10 | 11 | struct Args { 12 | std::vector kernel_forces_no_activate; 13 | bool lower_atomic; 14 | }; 15 | }; 16 | 17 | } // namespace taichi::lang 18 | -------------------------------------------------------------------------------- /taichi/transforms/make_block_local.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/pass.h" 4 | 5 | namespace taichi::lang { 6 | 7 | class MakeBlockLocalPass : public Pass { 8 | public: 9 | static const PassID id; 10 | 11 | struct Args { 12 | std::string kernel_name; 13 | bool verbose; 14 | }; 15 | }; 16 | 17 | } // namespace taichi::lang 18 | -------------------------------------------------------------------------------- /taichi/transforms/make_mesh_thread_local.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/pass.h" 4 | 5 | namespace taichi::lang { 6 | 7 | class MakeMeshThreadLocal : public Pass { 8 | public: 9 | static const PassID id; 10 | 11 | struct Args { 12 | std::string kernel_name; 13 | }; 14 | }; 15 | 16 | } // namespace taichi::lang 17 | -------------------------------------------------------------------------------- /taichi/transforms/simplify.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ir/pass.h" 4 | 5 | namespace taichi::lang { 6 | 7 | class FullSimplifyPass : public Pass { 8 | public: 9 | static const PassID id; 10 | 11 | struct Args { 12 | bool after_lower_access; 13 | // Switch off some optimization in store forwarding if there is an autodiff 14 | // pass after the full_simplify 15 | bool autodiff_enabled; 16 | std::string kernel_name = ""; 17 | bool verbose = false; 18 | }; 19 | }; 20 | 21 | } // namespace taichi::lang 22 | -------------------------------------------------------------------------------- /taichi/transforms/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace taichi::lang { 4 | 5 | // These two helper functions are targeting cases where x is assumed 6 | // non-negative but with a signed type so no automatic transformation to bitwise 7 | // operations can be applied in other compiler passes. 8 | Stmt *generate_mod(VecStatement *stmts, Stmt *x, int y); 9 | Stmt *generate_div(VecStatement *stmts, Stmt *x, int y); 10 | 11 | } // namespace taichi::lang 12 | -------------------------------------------------------------------------------- /taichi/ui/common/app_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "taichi/ui/utils/utils.h" 5 | #include "taichi/rhi/arch.h" 6 | 7 | namespace taichi { 8 | namespace ui { 9 | 10 | struct AppConfig { 11 | std::string name; 12 | int width{0}; 13 | int height{0}; 14 | int window_pos_x{0}; 15 | int window_pos_y{0}; 16 | bool vsync{false}; 17 | bool show_window{true}; 18 | double fps_limit{1000.0}; 19 | std::string package_path; 20 | Arch ti_arch; 21 | Arch ggui_arch{Arch::vulkan}; 22 | }; 23 | 24 | } // namespace ui 25 | } // namespace taichi 26 | -------------------------------------------------------------------------------- /taichi/ui/common/event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/ui/utils/utils.h" 3 | 4 | namespace taichi::ui { 5 | 6 | enum class EventType : int { Any = 0, Press = 1, Release = 2 }; 7 | 8 | struct Event { 9 | EventType tag; 10 | 11 | DEFINE_PROPERTY(std::string, key); 12 | }; 13 | 14 | } // namespace taichi::ui 15 | -------------------------------------------------------------------------------- /taichi/ui/common/renderable_info.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/ui/ggui/vertex.h" 4 | #include "taichi/program/field_info.h" 5 | #include "taichi/ui/utils/utils.h" 6 | 7 | namespace taichi::ui { 8 | 9 | struct RenderableInfo { 10 | FieldInfo vbo; 11 | FieldInfo indices; 12 | bool has_per_vertex_color{false}; 13 | bool has_per_vertex_radius{false}; 14 | VertexAttributes vbo_attrs{VboHelpers::all()}; 15 | bool has_user_customized_draw{false}; 16 | int draw_vertex_count{0}; 17 | int draw_first_vertex{0}; 18 | int draw_index_count{0}; 19 | int draw_first_index{0}; 20 | taichi::lang::PolygonMode display_mode{taichi::lang::PolygonMode::Fill}; 21 | }; 22 | 23 | } // namespace taichi::ui 24 | -------------------------------------------------------------------------------- /taichi/ui/ggui/nswindow_adapter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/rhi/common/window_system.h" 4 | #include "taichi/rhi/metal/metal_device.h" 5 | 6 | namespace taichi::ui { 7 | 8 | namespace vulkan { 9 | 10 | using namespace taichi::lang; 11 | using namespace taichi::lang::metal; 12 | 13 | struct NSWindowAdapter { 14 | void set_content_view(GLFWwindow *glfw_window, metal::MetalSurface *mtl_surf); 15 | }; 16 | 17 | } // namespace vulkan 18 | 19 | } // namespace taichi::ui 20 | -------------------------------------------------------------------------------- /taichi/ui/ggui/nswindow_adapter.mm: -------------------------------------------------------------------------------- 1 | #include "nswindow_adapter.h" 2 | 3 | #ifdef TI_WITH_METAL 4 | 5 | namespace taichi::ui { 6 | 7 | namespace vulkan { 8 | 9 | using namespace taichi::lang; 10 | using namespace taichi::lang::metal; 11 | 12 | void NSWindowAdapter::set_content_view(GLFWwindow *glfw_window, 13 | metal::MetalSurface *mtl_surf) { 14 | 15 | NSWindow *nswin = glfwGetCocoaWindow(glfw_window); 16 | nswin.contentView.layer = mtl_surf->mtl_layer(); 17 | nswin.contentView.wantsLayer = YES; 18 | } 19 | 20 | } // namespace vulkan 21 | 22 | } // namespace taichi::ui 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /taichi/ui/ggui/scene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/ui/common/scene_base.h" 3 | 4 | namespace taichi::ui { 5 | 6 | namespace vulkan { 7 | 8 | class Scene final : public SceneBase { 9 | public: 10 | void set_camera(const Camera &camera) override; 11 | void lines(const SceneLinesInfo &info) override; 12 | void mesh(const MeshInfo &info) override; 13 | void particles(const ParticlesInfo &info) override; 14 | void point_light(glm::vec3 pos, glm::vec3 color) override; 15 | void ambient_light(glm::vec3 color) override; 16 | }; 17 | 18 | } // namespace vulkan 19 | 20 | } // namespace taichi::ui 21 | -------------------------------------------------------------------------------- /taichi/ui/gui/android.cpp: -------------------------------------------------------------------------------- 1 | #include "taichi/ui/gui/gui.h" 2 | 3 | // GGUI is not supported on Android as the window management is handled by the 4 | // framework directly. It also provides a Canvas through Skia library that users 5 | // can leverage for rendering of 2D elements (circle, rectangle, ...) 6 | #if defined(TI_GUI_ANDROID) 7 | #include 8 | 9 | namespace taichi { 10 | 11 | void GUI::process_event() { 12 | TI_ERROR("GGUI not supported on Android"); 13 | } 14 | 15 | void GUI::create_window() { 16 | TI_ERROR("GGUI not supported on Android"); 17 | } 18 | 19 | void GUI::redraw() { 20 | TI_ERROR("GGUI not supported on Android"); 21 | } 22 | 23 | void GUI::set_title(std::string title) { 24 | TI_ERROR("GGUI not supported on Android"); 25 | } 26 | 27 | GUI::~GUI() { 28 | } 29 | 30 | } // namespace taichi 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /taichi/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./taichi/util/CMakeLists.txt 2 | 3 | add_library(taichi_util) 4 | target_sources(taichi_util 5 | PRIVATE 6 | bit.cpp 7 | file_sequence_writer.cpp 8 | image_buffer.cpp 9 | image_io.cpp 10 | lang_util.cpp 11 | offline_cache.cpp 12 | short_name.cpp 13 | str.cpp 14 | testing.cpp 15 | zip.cpp 16 | ) 17 | 18 | target_include_directories(taichi_util 19 | PRIVATE 20 | ${PROJECT_SOURCE_DIR} 21 | ${PROJECT_SOURCE_DIR}/external/include 22 | ${PROJECT_SOURCE_DIR}/external/eigen 23 | ${LLVM_INCLUDE_DIRS} 24 | ) 25 | 26 | target_link_libraries(taichi_util PUBLIC taichi_common) 27 | -------------------------------------------------------------------------------- /taichi/util/environ_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/common/core.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace taichi::lang { 9 | 10 | static inline int get_environ_config(const std::string &name, 11 | int default_value = 0) { 12 | char *res = std::getenv(name.c_str()); 13 | if (res == nullptr) 14 | return default_value; 15 | return std::stoi(res); 16 | } 17 | 18 | } // namespace taichi::lang 19 | -------------------------------------------------------------------------------- /taichi/util/file_sequence_writer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "taichi/util/lang_util.h" 4 | #ifdef TI_WITH_LLVM 5 | #include "taichi/runtime/llvm/llvm_fwd.h" 6 | #endif 7 | 8 | namespace taichi::lang { 9 | class IRNode; 10 | } // namespace taichi::lang 11 | 12 | namespace taichi { 13 | 14 | class FileSequenceWriter { 15 | public: 16 | FileSequenceWriter(std::string filename_template, std::string file_type); 17 | 18 | #ifdef TI_WITH_LLVM 19 | // returns filename 20 | std::string write(llvm::Module *module); 21 | #endif 22 | 23 | std::string write(lang::IRNode *irnode); 24 | 25 | std::string write(const std::string &str); 26 | 27 | private: 28 | int counter_; 29 | std::string filename_template_; 30 | std::string file_type_; 31 | 32 | std::pair create_new_file(); 33 | }; 34 | 35 | } // namespace taichi 36 | -------------------------------------------------------------------------------- /taichi/util/image_io.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace taichi { 7 | 8 | void imwrite(const std::string &filename, 9 | size_t ptr, 10 | int resx, 11 | int resy, 12 | int comp); 13 | std::vector imread(const std::string &filename, int comp); 14 | void imfree(size_t ptr); 15 | 16 | } // namespace taichi 17 | -------------------------------------------------------------------------------- /taichi/util/macros.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef STR 4 | #define _STR(...) #__VA_ARGS__ 5 | #define STR(...) _STR(__VA_ARGS__) 6 | #endif 7 | 8 | #ifndef CAT 9 | #define _CAT(x, y) x##y 10 | #define CAT(x, y) _CAT(x, y) 11 | #endif 12 | 13 | #ifndef CAT3 14 | #define _CAT3(x, y, z) x##y##z 15 | #define CAT3(x, y, z) _CAT3(x, y, z) 16 | #endif 17 | 18 | #ifndef EXP 19 | #define _EXP(x) x 20 | #define EXP(x) _EXP(x) 21 | #endif 22 | -------------------------------------------------------------------------------- /taichi/util/short_name.cpp: -------------------------------------------------------------------------------- 1 | #include "short_name.h" 2 | #include "base64.h" 3 | 4 | namespace taichi { 5 | namespace { 6 | const std::string alphatable = 7 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // e.g. `if` is not a good var name, but `If` 8 | // does. 9 | const std::string alnumtable = 10 | "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 11 | }; // namespace 12 | 13 | std::string make_short_name_by_id(int id) { 14 | std::string res; 15 | while (id >= alphatable.size()) { 16 | res.push_back(alnumtable[id % alnumtable.size()]); 17 | id /= alnumtable.size(); 18 | } 19 | res.push_back(alphatable[id]); 20 | std::reverse(res.begin(), res.end()); 21 | return res; 22 | } 23 | } // namespace taichi 24 | -------------------------------------------------------------------------------- /taichi/util/short_name.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "taichi/common/core.h" 5 | 6 | namespace taichi { 7 | 8 | std::string make_short_name_by_id(int id); 9 | 10 | } // namespace taichi 11 | -------------------------------------------------------------------------------- /taichi/util/str.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "taichi/util/lang_util.h" 9 | 10 | namespace taichi::lang { 11 | 12 | // Quote |str| with a pair of ". Escape special characters like \n, \t etc. 13 | std::string c_quoted(std::string const &str); 14 | 15 | std::string format_error_message(const std::string &error_message_template, 16 | const std::function &fetcher); 17 | 18 | } // namespace taichi::lang 19 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/__init__.py -------------------------------------------------------------------------------- /tests/cpp/aot/opengl/device_test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include "taichi/rhi/opengl/opengl_api.h" 3 | #include "tests/cpp/aot/gfx_utils.h" 4 | 5 | using namespace taichi; 6 | using namespace lang; 7 | 8 | TEST(DeviceTest, GLDevice) { 9 | if (!opengl::is_opengl_api_available()) { 10 | return; 11 | } 12 | 13 | auto device_ = taichi::lang::opengl::make_opengl_device(); 14 | 15 | aot_test_utils::view_devalloc_as_ndarray(device_.get()); 16 | } 17 | -------------------------------------------------------------------------------- /tests/cpp/aot/python_scripts/aot_module_test_.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | 4 | import taichi as ti 5 | 6 | 7 | def main(arch): 8 | ti.init(arch=arch) 9 | 10 | if ti.lang.impl.current_cfg().arch != arch: 11 | return 12 | 13 | arr = ti.ndarray(int, shape=16) 14 | 15 | assert "TAICHI_AOT_FOLDER_PATH" in os.environ.keys() 16 | dir_name = str(os.environ["TAICHI_AOT_FOLDER_PATH"]) 17 | 18 | m = ti.aot.Module() 19 | 20 | tcm_path = dir_name + "/module.tcm" 21 | m.save(dir_name) 22 | m.archive(tcm_path) 23 | print(tcm_path) 24 | 25 | 26 | if __name__ == "__main__": 27 | parser = argparse.ArgumentParser() 28 | parser.add_argument("--arch", type=str) 29 | args = parser.parse_args() 30 | 31 | if args.arch == "vulkan": 32 | main(arch=ti.vulkan) 33 | elif args.arch == "metal": 34 | main(arch=ti.metal) 35 | else: 36 | assert False 37 | -------------------------------------------------------------------------------- /tests/cpp/common/core_test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | 3 | #include "taichi/common/core.h" 4 | 5 | namespace taichi { 6 | 7 | TEST(CoreTest, Basic) { 8 | EXPECT_EQ(trim_string("hello taichi "), "hello taichi"); 9 | } 10 | 11 | } // namespace taichi 12 | -------------------------------------------------------------------------------- /tests/cpp/ir/ndarray_kernel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "taichi/ir/ir_builder.h" 3 | #include "taichi/ir/statements.h" 4 | #include "taichi/inc/constants.h" 5 | #include "taichi/program/program.h" 6 | 7 | namespace taichi::lang { 8 | 9 | std::unique_ptr setup_kernel1(Program *prog); 10 | 11 | std::unique_ptr setup_kernel2(Program *prog); 12 | } // namespace taichi::lang 13 | -------------------------------------------------------------------------------- /tests/cpp/program/test_program.cpp: -------------------------------------------------------------------------------- 1 | #include "tests/cpp/program/test_program.h" 2 | 3 | namespace taichi::lang { 4 | 5 | void TestProgram::setup(Arch arch) { 6 | prog_ = std::make_unique(arch); 7 | prog_->materialize_runtime(); 8 | prog_->add_snode_tree(std::make_unique(/*depth=*/0, SNodeType::root), 9 | /*compile_only=*/false); 10 | } 11 | 12 | } // namespace taichi::lang 13 | -------------------------------------------------------------------------------- /tests/cpp/program/test_program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "taichi/program/program.h" 6 | 7 | namespace taichi::lang { 8 | 9 | class TestProgram { 10 | public: 11 | void setup(Arch arch = Arch::x64); 12 | 13 | Program *prog() { 14 | return prog_.get(); 15 | } 16 | 17 | private: 18 | std::unique_ptr prog_{nullptr}; 19 | }; 20 | 21 | } // namespace taichi::lang 22 | -------------------------------------------------------------------------------- /tests/cpp/struct/fake_struct_compiler.h: -------------------------------------------------------------------------------- 1 | #include "taichi/struct/struct.h" 2 | 3 | namespace taichi::lang { 4 | 5 | class FakeStructCompiler : public StructCompiler { 6 | public: 7 | void generate_types(SNode &) override { 8 | } 9 | 10 | void generate_child_accessors(SNode &) override { 11 | } 12 | 13 | void run(SNode &root) override { 14 | } 15 | }; 16 | 17 | } // namespace taichi::lang 18 | -------------------------------------------------------------------------------- /tests/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | markers = 3 | run_in_serial: mark test to run serially(usually for resource intensive tests). 4 | sm70: Can only run on GPU with compute capability 7.0 or higher. 5 | -------------------------------------------------------------------------------- /tests/python/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/__init__.py -------------------------------------------------------------------------------- /tests/python/expected/test_depth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_depth.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_3d_lines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_3d_lines.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_lines.mac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_lines.mac.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_lines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_lines.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_mesh_instances.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_mesh_instances.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_part_of_lines.mac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_part_of_lines.mac.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_part_of_lines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_part_of_lines.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_part_of_mesh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_part_of_mesh.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_part_of_mesh_instances.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_part_of_mesh_instances.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_part_of_particles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_part_of_particles.png -------------------------------------------------------------------------------- /tests/python/expected/test_draw_part_of_particles_per_vertex_rad_and_col.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_draw_part_of_particles_per_vertex_rad_and_col.png -------------------------------------------------------------------------------- /tests/python/expected/test_geometry_2d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_geometry_2d.png -------------------------------------------------------------------------------- /tests/python/expected/test_geometry_3d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_geometry_3d.png -------------------------------------------------------------------------------- /tests/python/expected/test_imgui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_imgui.png -------------------------------------------------------------------------------- /tests/python/expected/test_set_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_set_image.png -------------------------------------------------------------------------------- /tests/python/expected/test_wireframe_mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taichi-dev/taichi/e2b5e9d184160d1c49cdafa730e873756439043d/tests/python/expected/test_wireframe_mode.png -------------------------------------------------------------------------------- /tests/python/test_ad_atomic.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_ad_reduce(): 7 | N = 16 8 | 9 | x = ti.field(dtype=ti.f32, shape=N, needs_grad=True) 10 | loss = ti.field(dtype=ti.f32, shape=(), needs_grad=True) 11 | 12 | @ti.kernel 13 | def func(): 14 | for i in x: 15 | loss[None] += x[i] ** 2 16 | 17 | total_loss = 0 18 | for i in range(N): 19 | x[i] = i 20 | total_loss += i * i 21 | 22 | loss.grad[None] = 1 23 | func() 24 | func.grad() 25 | 26 | assert total_loss == test_utils.approx(loss[None]) 27 | for i in range(N): 28 | assert x.grad[i] == test_utils.approx(i * 2) 29 | -------------------------------------------------------------------------------- /tests/python/test_ad_atomic_fwd.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_ad_reduce_fwd(): 7 | N = 16 8 | 9 | x = ti.field(dtype=ti.f32, shape=N) 10 | loss = ti.field(dtype=ti.f32, shape=()) 11 | ti.root.lazy_dual() 12 | 13 | @ti.kernel 14 | def func(): 15 | for i in x: 16 | loss[None] += x[i] ** 2 17 | 18 | total_loss = 0 19 | for i in range(N): 20 | x[i] = i 21 | total_loss += i * i 22 | 23 | with ti.ad.FwdMode(loss=loss, param=x, seed=[1.0 for _ in range(N)]): 24 | func() 25 | 26 | assert total_loss == test_utils.approx(loss[None]) 27 | sum = 0 28 | for i in range(N): 29 | sum += i * 2 30 | 31 | assert loss.dual[None] == test_utils.approx(sum) 32 | -------------------------------------------------------------------------------- /tests/python/test_ad_demote_dense.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(exclude=[ti.metal, ti.opengl]) 6 | def test_ad_demote_dense(): 7 | a = ti.field(ti.f32, shape=(7, 3, 19)) 8 | 9 | @ti.kernel 10 | def inc(): 11 | for i, j, k in a: 12 | a[i, j, k] += 1 13 | 14 | inc.grad() 15 | -------------------------------------------------------------------------------- /tests/python/test_ad_dynamic_index.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_matrix_non_constant_index(): 7 | m = ti.Matrix.field(2, 2, ti.f32, 5, needs_grad=True) 8 | n = ti.Matrix.field(2, 2, ti.f32, 5, needs_grad=True) 9 | loss = ti.field(ti.f32, (), needs_grad=True) 10 | 11 | n.fill(0) 12 | 13 | @ti.kernel 14 | def func1(): 15 | for i in range(5): 16 | for j, k in ti.ndrange(2, 2): 17 | m[i][j, k] = (j + 1) * (k + 1) * n[i][j, k] 18 | loss[None] += m[i][j, k] 19 | 20 | loss.grad[None] = 1.0 21 | func1.grad() 22 | 23 | for i in range(5): 24 | for j in range(2): 25 | for k in range(2): 26 | assert n.grad[i][j, k] == (j + 1) * (k + 1) 27 | -------------------------------------------------------------------------------- /tests/python/test_ad_math_func.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(require=ti.extension.adstack) 6 | def test_polar_decompose_2D(): 7 | # `polar_decompose3d` in current Taichi version (v1.1) does not support autodiff, 8 | # becasue it mixed usage of for-loops and statements without looping. 9 | dim = 2 10 | F_1 = ti.Matrix.field(dim, dim, dtype=ti.f32, shape=(), needs_grad=True) 11 | F = ti.Matrix.field(dim, dim, dtype=ti.f32, shape=(), needs_grad=True) 12 | loss = ti.field(dtype=ti.f32, shape=(), needs_grad=True) 13 | 14 | @ti.kernel 15 | def polar_decompose_2D(): 16 | r, s = ti.polar_decompose(F[None]) 17 | F_1[None] += r 18 | 19 | with ti.ad.Tape(loss=loss): 20 | polar_decompose_2D() 21 | -------------------------------------------------------------------------------- /tests/python/test_ad_offload.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_offload_order(): 7 | n = 128 8 | x = ti.field(ti.f32, shape=n, needs_grad=True) 9 | y = ti.field(ti.f32, shape=n, needs_grad=True) 10 | z = ti.field(ti.f32, shape=(), needs_grad=True) 11 | 12 | @ti.kernel 13 | def forward(): 14 | for i in x: 15 | y[i] = x[i] 16 | 17 | # for i in x: 18 | # z[None] += y[i] 19 | 20 | with ti.ad.Tape(z): 21 | forward() 22 | 23 | # for i in range(n): 24 | # assert x.grad[i] == 1 25 | -------------------------------------------------------------------------------- /tests/python/test_arg_alignment.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(exclude=[ti.opengl, ti.gles]) 6 | def test_ret_write(): 7 | @ti.kernel 8 | def func(a: ti.i16) -> ti.f32: 9 | return 3.0 10 | 11 | assert func(255) == 3.0 12 | 13 | 14 | @test_utils.test(exclude=[ti.opengl, ti.gles]) 15 | def test_arg_read(): 16 | x = ti.field(ti.i32, shape=()) 17 | 18 | @ti.kernel 19 | def func(a: ti.i8, b: ti.i32): 20 | x[None] = b 21 | 22 | func(255, 2) 23 | assert x[None] == 2 24 | -------------------------------------------------------------------------------- /tests/python/test_arg_check.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_argument_error(): 7 | x = ti.field(ti.i32) 8 | 9 | ti.root.place(x) 10 | 11 | try: 12 | 13 | @ti.kernel 14 | def set_i32_notype(v): 15 | pass 16 | 17 | except ti.TaichiSyntaxError: 18 | pass 19 | 20 | try: 21 | 22 | @ti.kernel 23 | def set_i32_args(*args): 24 | pass 25 | 26 | except ti.TaichiSyntaxError: 27 | pass 28 | 29 | try: 30 | 31 | @ti.kernel 32 | def set_i32_kwargs(**kwargs): 33 | pass 34 | 35 | except ti.TaichiSyntaxError: 36 | pass 37 | 38 | @ti.kernel 39 | def set_i32(v: ti.i32): 40 | x[None] = v 41 | 42 | set_i32(123) 43 | assert x[None] == 123 44 | -------------------------------------------------------------------------------- /tests/python/test_binding.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | 3 | 4 | def test_binding(): 5 | ti.init() 6 | taichi_lang = ti._lib.core 7 | print(taichi_lang.BinaryOpType.mul) 8 | one = taichi_lang.make_const_expr_int(ti.i32, 1) 9 | two = taichi_lang.make_const_expr_int(ti.i32, 2) 10 | expr = taichi_lang.make_binary_op_expr(taichi_lang.BinaryOpType.add, one, two) 11 | print(taichi_lang.make_global_store_stmt(None, None)) 12 | -------------------------------------------------------------------------------- /tests/python/test_bool_type.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(debug=True) 6 | def test_bool_type_anno(): 7 | @ti.func 8 | def f(x: bool) -> bool: 9 | return not x 10 | 11 | @ti.kernel 12 | def test(): 13 | assert f(True) == False 14 | assert f(False) == True 15 | 16 | test() 17 | 18 | 19 | @test_utils.test(debug=True) 20 | def test_bool_type_conv(): 21 | @ti.func 22 | def f(x: ti.u32) -> bool: 23 | return bool(x) 24 | 25 | @ti.kernel 26 | def test(): 27 | assert f(1000) == True 28 | assert f(ti.u32(4_294_967_295)) == True 29 | 30 | test() 31 | -------------------------------------------------------------------------------- /tests/python/test_cache_loop_invariant.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from taichi.lang import impl 3 | 4 | import taichi as ti 5 | from tests import test_utils 6 | 7 | 8 | @test_utils.test(arch=[ti.cuda, ti.cpu]) 9 | def test_local_matrix_non_constant_index_real_matrix(): 10 | N = 1 11 | x = ti.Vector.field(3, float, shape=1) 12 | 13 | @ti.kernel 14 | def test_invariant_cache(): 15 | for i in range(1): 16 | x[i][1] = x[i][1] + 1.0 17 | for j in range(1): 18 | x[i][1] = x[i][1] - 5.0 19 | for z in range(1): 20 | idx = 0 21 | if z == 0: 22 | idx = 1 23 | x_print = x[i][idx] 24 | 25 | assert x_print == x[i][1] 26 | 27 | test_invariant_cache() 28 | -------------------------------------------------------------------------------- /tests/python/test_cfg_continue.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(exclude=[ti.amdgpu]) 6 | def test_cfg_continue(): 7 | x = ti.field(dtype=int, shape=1) 8 | state = ti.field(dtype=int, shape=1) 9 | 10 | @ti.kernel 11 | def foo(): 12 | for p in range(1): 13 | if state[p] == 0: 14 | x[p] = 1 15 | continue 16 | if state[p] != 0: 17 | print("test") 18 | 19 | foo() 20 | assert x[0] == 1 21 | -------------------------------------------------------------------------------- /tests/python/test_cuda_internals.py: -------------------------------------------------------------------------------- 1 | from taichi.lang import impl 2 | 3 | import taichi as ti 4 | from tests import test_utils 5 | 6 | # TODO: these are not really tests... 7 | 8 | 9 | @test_utils.test(arch=ti.cuda) 10 | def test_do_nothing(): 11 | @ti.kernel 12 | def test(): 13 | for i in range(10): 14 | impl.call_internal("do_nothing") 15 | 16 | test() 17 | 18 | 19 | @test_utils.test(arch=ti.cuda) 20 | def test_active_mask(): 21 | @ti.kernel 22 | def test(): 23 | for i in range(48): 24 | if i % 2 == 0: 25 | impl.call_internal("test_active_mask") 26 | 27 | test() 28 | 29 | 30 | @test_utils.test(arch=ti.cuda) 31 | def test_shfl_down(): 32 | @ti.kernel 33 | def test(): 34 | for i in range(32): 35 | impl.call_internal("test_shfl") 36 | 37 | test() 38 | -------------------------------------------------------------------------------- /tests/python/test_delay_modify.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_simplify_bug(): 7 | @ti.kernel 8 | def foo() -> ti.types.vector(4, dtype=ti.i32): 9 | a = ti.Vector([0, 0, 0, 0]) 10 | for i in range(5): 11 | for k in ti.static(range(4)): 12 | if i == 3: 13 | a[k] = 1 14 | return a 15 | 16 | a = foo() 17 | 18 | assert (a == ti.Vector([1, 1, 1, 1])).all() == 1 19 | -------------------------------------------------------------------------------- /tests/python/test_dynamic_append_length.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | def _test_dynamic_append_length(dt): 6 | x = ti.field(int) 7 | block = ti.root.dense(ti.i, 10) 8 | pixel = block.dynamic(ti.j, 10) 9 | pixel.place(x) 10 | 11 | @ti.kernel 12 | def test(): 13 | for i in range(10): 14 | for j in range(i): 15 | x[i].append(j) 16 | for i in range(10): 17 | assert x[i].length() == i 18 | for j in range(i): 19 | assert x[i, j] == j 20 | 21 | test() 22 | 23 | 24 | @test_utils.test(require=ti.extension.sparse, exclude=[ti.metal], default_fp=ti.f32, debug=True) 25 | def test_dynamic_append_length_f32(): 26 | _test_dynamic_append_length(ti.f32) 27 | -------------------------------------------------------------------------------- /tests/python/test_empty.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_empty(): 7 | @ti.kernel 8 | def func(): 9 | pass 10 | 11 | func() 12 | 13 | 14 | @test_utils.test() 15 | def test_empty_args(): 16 | @ti.kernel 17 | def func(x: ti.i32, arr: ti.types.ndarray()): 18 | pass 19 | 20 | import numpy as np 21 | 22 | func(42, np.arange(10, dtype=np.float32)) 23 | -------------------------------------------------------------------------------- /tests/python/test_expr_list.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(ti.cpu) 6 | def test_expr_list_basic(): 7 | @ti.kernel 8 | def func(u: int, v: float) -> float: 9 | x = [2 + u, 3 + v] 10 | return x[0] * 100 + x[1] 11 | 12 | assert func(1, 1.1) == test_utils.approx(304.1) 13 | 14 | 15 | @test_utils.test() 16 | def test_listcomp_multiple_ifs(): 17 | x = ti.field(ti.i32, shape=(4,)) 18 | 19 | @ti.kernel 20 | def test() -> ti.i32: 21 | # Taichi doesn't support global fields appearing anywhere after "for" 22 | # here. 23 | a = [x[0] for j in range(100) if j > 2 if j < 5] 24 | return sum(a) 25 | 26 | for i in range(6): 27 | x[0] = i 28 | assert test() == i * 2 29 | -------------------------------------------------------------------------------- /tests/python/test_fp_flush_to_zero.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_ftz_f32(): 7 | a = ti.field(dtype=ti.f32, shape=2) 8 | 9 | @ti.kernel 10 | def foo(): 11 | a[0] = 1e-45 12 | a[1] = 1e-10 * 1e-35 13 | 14 | foo() 15 | assert a[0] == 0 16 | assert a[1] == 0 17 | 18 | 19 | @test_utils.test(require=ti.extension.data64) 20 | def test_ftz_f64(): 21 | a = ti.field(dtype=ti.f64, shape=2) 22 | 23 | @ti.kernel 24 | def foo(): 25 | a[0] = 1e-323 26 | x = 1e-300 27 | y = 1e-23 28 | a[1] = x * y 29 | 30 | foo() 31 | assert a[0] == 0 32 | assert a[1] == 0 33 | -------------------------------------------------------------------------------- /tests/python/test_function_parameter_by_value.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_pass_by_value(): 7 | @ti.func 8 | def set_val(x, i): 9 | x = i 10 | 11 | ret = ti.field(ti.i32, shape=()) 12 | 13 | @ti.kernel 14 | def task(): 15 | set_val(ret[None], 112) 16 | 17 | task() 18 | assert ret[None] == 0 19 | -------------------------------------------------------------------------------- /tests/python/test_global_buffer_misalined.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(require=ti.extension.data64) 6 | def test_global_buffer_misalignment(): 7 | @ti.kernel 8 | def test(x: ti.f32): 9 | a = x 10 | b = ti.cast(0.12, ti.f64) 11 | for i in range(8): 12 | b += a 13 | 14 | for i in range(8): 15 | test(0.1) 16 | -------------------------------------------------------------------------------- /tests/python/test_global_store_grad.py: -------------------------------------------------------------------------------- 1 | """ 2 | import taichi as ti 3 | 4 | ti.lang.impl.current_cfg().print_ir = True 5 | 6 | 7 | def test_global_store_branching(): 8 | # ti.reset() 9 | 10 | N = 16 11 | x = ti.field(ti.f32) 12 | y = ti.field(ti.f32) 13 | 14 | ti.root.dense(ti.i, N).place(x) 15 | ti.root.dense(ti.i, N).place(y) 16 | ti.root.lazy_grad() 17 | 18 | @ti.kernel 19 | def oldeven(): 20 | for i in range(N): 21 | if i % 2 == 0: 22 | x[i] = y[i] 23 | 24 | for i in range(N): 25 | x.grad[i] = 1 26 | 27 | oldeven() 28 | oldeven.grad() 29 | 30 | for i in range(N): 31 | assert y.grad[i] == (i % 2 == 0) 32 | """ 33 | -------------------------------------------------------------------------------- /tests/python/test_global_thread_idx.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | import taichi as ti 4 | from tests import test_utils 5 | 6 | 7 | @test_utils.test(arch=ti.cuda) 8 | def test_global_thread_idx(): 9 | n = 128 10 | x = ti.field(ti.i32, shape=n) 11 | 12 | @ti.kernel 13 | def func(): 14 | for i in range(n): 15 | tid = ti.global_thread_idx() 16 | x[tid] = tid 17 | 18 | func() 19 | assert np.arange(n).sum() == x.to_numpy().sum() 20 | -------------------------------------------------------------------------------- /tests/python/test_immediate_layout.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_1D(): 7 | N = 2 8 | x = ti.field(ti.f32) 9 | ti.root.dense(ti.i, N).place(x) 10 | 11 | x[0] = 42 12 | assert x[0] == 42 13 | assert x[1] == 0 14 | -------------------------------------------------------------------------------- /tests/python/test_lexical_scope.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(ti.cpu) 6 | def test_func_closure(): 7 | def my_test(): 8 | a = 32 9 | 10 | @ti.func 11 | def foo(): 12 | ti.static_assert(a == 32) 13 | 14 | @ti.kernel 15 | def func(): 16 | ti.static_assert(a == 32) 17 | foo() 18 | 19 | def dummy(): 20 | func() 21 | 22 | func() 23 | dummy() 24 | return dummy, func 25 | 26 | dummy, func = my_test() 27 | func() 28 | dummy() 29 | -------------------------------------------------------------------------------- /tests/python/test_local_atomic_opt.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_cse(): 7 | A = ti.field(ti.f32, shape=()) 8 | 9 | @ti.kernel 10 | def func(): 11 | a = 0 12 | a += 10 13 | a = a + 123 14 | A[None] = a 15 | 16 | func() 17 | assert A[None] == 133 18 | 19 | 20 | @test_utils.test() 21 | def test_store_forward(): 22 | A = ti.field(ti.f32, shape=()) 23 | 24 | @ti.kernel 25 | def func(): 26 | a = 0 27 | a = 123 28 | a += 10 29 | A[None] = a 30 | 31 | func() 32 | assert A[None] == 133 33 | -------------------------------------------------------------------------------- /tests/python/test_module_import.py: -------------------------------------------------------------------------------- 1 | import taichi as myowntaichi 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_module_import(): 7 | @myowntaichi.kernel 8 | def func(): 9 | for _ in myowntaichi.static(range(8)): 10 | pass 11 | 12 | func() 13 | -------------------------------------------------------------------------------- /tests/python/test_name_error.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import taichi as ti 4 | from tests import test_utils 5 | 6 | 7 | @test_utils.test() 8 | def test_name_error(): 9 | with pytest.raises(ti.TaichiNameError, match='Name "a" is not defined'): 10 | 11 | @ti.kernel 12 | def foo(): 13 | a + 1 14 | 15 | foo() 16 | -------------------------------------------------------------------------------- /tests/python/test_nested_kernel_error.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import taichi as ti 4 | from tests import test_utils 5 | 6 | 7 | @test_utils.test() 8 | def test_nested_kernel_error(): 9 | @ti.kernel 10 | def B(): 11 | pass 12 | 13 | @ti.kernel 14 | def A(): 15 | B() 16 | 17 | with pytest.raises(ti.TaichiCompilationError): 18 | A() 19 | -------------------------------------------------------------------------------- /tests/python/test_no_activate.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(require=ti.extension.sparse, exclude=ti.metal) 6 | def test_no_activate(): 7 | x = ti.field(ti.f32) 8 | 9 | n = 1024 10 | 11 | d = ti.root.dynamic(ti.i, n, chunk_size=32) 12 | d.place(x) 13 | 14 | @ti.kernel 15 | def initialize(): 16 | for i in range(n): 17 | x[i] = 1 18 | 19 | @ti.kernel 20 | def func(): 21 | ti.no_activate(d) 22 | for i in range(n // 2): 23 | x[i * 2 + 1] += 1 24 | 25 | initialize() 26 | 27 | func() 28 | 29 | for i in range(n): 30 | assert x[i] == i % 2 + 1 31 | -------------------------------------------------------------------------------- /tests/python/test_non_taichi_types_in_kernel.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(exclude=ti.amdgpu) 6 | def test_subscript_user_classes_in_kernel(): 7 | class MyList: 8 | def __init__(self, elements): 9 | self.elements = elements 10 | 11 | def __getitem__(self, index): 12 | return self.elements[index] 13 | 14 | @ti.kernel 15 | def func(): 16 | for i in ti.static(range(3)): 17 | print(a[i]) 18 | 19 | a = MyList([1, 2, 3]) 20 | func() 21 | -------------------------------------------------------------------------------- /tests/python/test_packed_size.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(arch=[ti.cpu, ti.cuda]) 6 | def test_packed_size(): 7 | x = ti.field(ti.i32) 8 | ti.root.dense(ti.l, 3).dense(ti.ijk, 129).place(x) 9 | assert x.shape == (129, 129, 129, 3) 10 | assert x.snode.parent().parent()._cell_size_bytes == 4 * 129**3 11 | -------------------------------------------------------------------------------- /tests/python/test_snode.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @ti.kernel 6 | def some_kernel(_: ti.template()): ... 7 | 8 | 9 | @test_utils.test(cpu_max_num_threads=1) 10 | def test_get_snode_tree_id(): 11 | s = ti.field(int, shape=()) 12 | some_kernel(s) 13 | assert s.snode._snode_tree_id == 0 14 | 15 | s = ti.field(int, shape=()) 16 | some_kernel(s) 17 | assert s.snode._snode_tree_id == 1 18 | 19 | s = ti.field(int, shape=()) 20 | some_kernel(s) 21 | assert s.snode._snode_tree_id == 2 22 | -------------------------------------------------------------------------------- /tests/python/test_sparse_grid.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test(require=ti.extension.sparse) 6 | def test_sparse_grid(): 7 | # create a 2D sparse grid 8 | grid = ti.sparse.grid( 9 | { 10 | "pos": ti.math.vec2, 11 | "mass": ti.f32, 12 | "grid2particles": ti.types.vector(20, ti.i32), 13 | }, 14 | shape=(10, 10), 15 | ) 16 | 17 | # access 18 | grid[0, 0].pos = ti.math.vec2(1, 2) 19 | grid[0, 0].mass = 1.0 20 | grid[0, 0].grid2particles[2] = 123 21 | 22 | # print the usage of the sparse grid, which is in [0,1] 23 | assert ti.sparse.usage(grid) == test_utils.approx(0.01) 24 | -------------------------------------------------------------------------------- /tests/python/test_sparse_multi_tree.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import taichi as ti 4 | from tests import test_utils 5 | 6 | 7 | @test_utils.test(arch=[ti.cpu, ti.cuda]) 8 | def test_pointer(): 9 | e = ti.Vector.field(2, dtype=int, shape=16) 10 | 11 | e[0] = ti.Vector([0, 0]) 12 | 13 | a = ti.field(float, shape=512) 14 | b = ti.field(dtype=float) 15 | ti.root.pointer(ti.i, 32).dense(ti.i, 16).place(b) 16 | 17 | @ti.kernel 18 | def test(): 19 | for i in a: 20 | a[i] = i 21 | for i in a: 22 | b[i] += a[i] 23 | 24 | test() 25 | ti.sync() 26 | 27 | b_np = b.to_numpy() 28 | for i in range(512): 29 | assert b_np[i] == i 30 | -------------------------------------------------------------------------------- /tests/python/test_stencils.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_simple(): 7 | # Note: access simplification does not work in this case. Maybe worth fixing. 8 | x = ti.field(ti.i32) 9 | y = ti.field(ti.i32) 10 | 11 | n = 128 12 | 13 | ti.root.dense(ti.i, n).place(x, y) 14 | 15 | @ti.kernel 16 | def run(): 17 | for i in range(n - 1): 18 | x[i] = 1 19 | y[i + 1] = 2 20 | 21 | run() 22 | 23 | for i in range(n - 1): 24 | assert x[i] == 1 25 | assert y[i + 1] == 2 26 | -------------------------------------------------------------------------------- /tests/python/test_struct_for_intermediate.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | def _test_nested(): 6 | x = ti.field(ti.i32) 7 | 8 | p, q = 3, 7 9 | n, m = 2, 4 10 | 11 | ti.root.dense(ti.ij, (p, q)).dense(ti.ij, (n, m)).place(x) 12 | 13 | @ti.kernel 14 | def iterate(): 15 | for i, j in x.parent(): 16 | x[i, j] += 1 17 | 18 | iterate() 19 | for i in range(p): 20 | for j in range(q): 21 | assert x[i * n, j * m] == 1, (i, j) 22 | 23 | 24 | @test_utils.test(require=ti.extension.sparse, demote_dense_struct_fors=False) 25 | def test_nested(): 26 | _test_nested() 27 | 28 | 29 | @test_utils.test(demote_dense_struct_fors=True) 30 | def test_nested_demote(): 31 | _test_nested() 32 | -------------------------------------------------------------------------------- /tests/python/test_sync.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_kernel_sync(): 7 | n = 128 8 | x = ti.field(ti.i32, shape=(3,)) 9 | y = ti.field(ti.i32, shape=(n,)) 10 | # These [] calls are all on CPU, so no synchronization needed 11 | x[0] = 42 12 | assert x[0] == 42 13 | x[1] = 233 14 | x[2] = -1 15 | 16 | @ti.kernel 17 | def func(): 18 | for i in y: 19 | y[i] = x[i % 3] 20 | 21 | # Kernel *may* run on GPU 22 | # Note that the previous kernel is a write, which didn't do a sync. But that 23 | # should be fine -- we only need to sync the memory after GPU -> CPU. 24 | func() 25 | # These [] calls are on CPU. They should be smart enough to sync only once. 26 | for i in range(n): 27 | assert y[i] == x[i % 3] 28 | -------------------------------------------------------------------------------- /tests/python/test_threading.py: -------------------------------------------------------------------------------- 1 | from taichi.lang.misc import get_host_arch_list 2 | 3 | import taichi as ti 4 | from tests import test_utils 5 | 6 | 7 | @test_utils.test(arch=get_host_arch_list()) 8 | def test_while(): 9 | assert ti._lib.core.test_threading() 10 | -------------------------------------------------------------------------------- /tests/python/test_while.py: -------------------------------------------------------------------------------- 1 | import taichi as ti 2 | from tests import test_utils 3 | 4 | 5 | @test_utils.test() 6 | def test_while(): 7 | x = ti.field(ti.f32) 8 | 9 | N = 1 10 | 11 | ti.root.dense(ti.i, N).place(x) 12 | 13 | @ti.kernel 14 | def func(): 15 | i = 0 16 | s = 0 17 | while i < 10: 18 | s += i 19 | i += 1 20 | x[0] = s 21 | 22 | func() 23 | assert x[0] == 45 24 | 25 | 26 | @test_utils.test() 27 | def test_break(): 28 | ret = ti.field(ti.i32, shape=()) 29 | 30 | @ti.kernel 31 | def func(): 32 | i = 0 33 | s = 0 34 | while True: 35 | s += i 36 | i += 1 37 | if i > 10: 38 | break 39 | ret[None] = s 40 | 41 | func() 42 | assert ret[None] == 55 43 | -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | v1.8.0 2 | -------------------------------------------------------------------------------- /vs-chromium-project.txt: -------------------------------------------------------------------------------- 1 | [SourceExplorer.ignore] 2 | .git/ 3 | .vs/ 4 | .vscode/ 5 | .pytest_cache/ 6 | *.csproj 7 | *.vcxproj 8 | 9 | [SearchableFiles.ignore] 10 | out/ 11 | build/ 12 | .vs/ 13 | .vscode/ 14 | .pytest_cache/ 15 | _skbuild/ 16 | build_clang_tidy/ 17 | .git/ 18 | .vs/ 19 | .vscode/ 20 | 21 | [SearchableFiles.include] 22 | *.cpp 23 | *.c 24 | *.h 25 | *.cu 26 | *.cxx 27 | *.py 28 | *.json 29 | *.txt 30 | *.frag 31 | *.vert 32 | --------------------------------------------------------------------------------