Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc] enhance ti.init for ti.gpu #843

Merged
merged 5 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ build_script:
- curl --retry 10 --retry-delay 5 https://github.com/yuanming-hu/taichi_assets/releases/download/llvm8/taichi-llvm-8.0.1-msvc2017.zip -LO
- 7z x taichi-llvm-8.0.1-msvc2017.zip -otaichi_llvm
- curl --retry 10 --retry-delay 5 https://github.com/yuanming-hu/taichi_assets/releases/download/llvm8/clang-7.0.1-win.zip -LO
- "echo %APPVEYOR_REPO_COMMIT_MESSAGE% | grep '^\\[format\\]' && curl http://kun.csail.mit.edu:31415/%APPVEYOR_PULL_REQUEST_NUMBER% -LO || true"
- "echo \"%APPVEYOR_REPO_COMMIT_MESSAGE%\" | grep '^\\[format\\]' && curl http://kun.csail.mit.edu:31415/%APPVEYOR_PULL_REQUEST_NUMBER% -LO || true"
- 7z x clang-7.0.1-win.zip -otaichi_clang
- set PATH=C:\taichi_llvm\bin;%PATH%;
- set PATH=C:\taichi_clang\bin;%PATH%
Expand Down
2 changes: 1 addition & 1 deletion examples/cornell_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
from renderer_utils import ray_aabb_intersection, intersect_sphere, ray_plane_intersect, reflect, refract

ti.init(arch=ti.cuda)
ti.init(arch=ti.gpu)
res = (800, 800)
color_buffer = ti.Vector(3, dt=ti.f32, shape=res)
max_ray_depth = 10
Expand Down
2 changes: 1 addition & 1 deletion examples/euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# for compressible gas dynamics with reactive fronts"

real = ti.f32
ti.init(arch=ti.cuda, default_fp=real)
ti.init(arch=ti.gpu, default_fp=real)

N = 1024 # grid resolution
CFL = .9 # keep below 1
Expand Down
2 changes: 1 addition & 1 deletion examples/fractal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import taichi as ti

ti.init(arch=ti.cuda)
ti.init(arch=ti.gpu)

n = 320
pixels = ti.var(dt=ti.f32, shape=(n * 2, n))
Expand Down
2 changes: 1 addition & 1 deletion examples/game_of_life.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import taichi as ti
import numpy as np

ti.init(arch=ti.opengl)
ti.init(arch=ti.gpu)

n = 100
celsiz = 4
Expand Down
2 changes: 1 addition & 1 deletion examples/laplace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import taichi as ti

ti.init(arch=ti.cuda)
ti.init(arch=ti.cpu)
x, y = ti.var(ti.f32), ti.var(ti.f32)

ti.root.dense(ti.ij, 16).place(x, y)
Expand Down
2 changes: 1 addition & 1 deletion examples/mpm128.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import taichi as ti
import numpy as np
ti.init(arch=ti.cuda) # Try to run on GPU, use ti.opengl if you don't have CUDA
ti.init(arch=ti.gpu) # Try to run on GPU
quality = 1 # Use a larger value for higher-res simulations
n_particles, n_grid = 9000 * quality ** 2, 128 * quality
dx, inv_dx = 1 / n_grid, float(n_grid)
Expand Down
2 changes: 1 addition & 1 deletion examples/mpm88.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import taichi as ti
import random

ti.init(arch=ti.cuda)
ti.init(arch=ti.gpu)

dim = 2
n_particles = 8192
Expand Down
2 changes: 1 addition & 1 deletion examples/mpm99.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import taichi as ti
import numpy as np
ti.init(arch=ti.cuda) # Try to run on GPU. Use arch=ti.opengl on old GPUs
ti.init(arch=ti.gpu) # Try to run on GPU
quality = 1 # Use a larger value for higher-res simulations
n_particles, n_grid = 9000 * quality ** 2, 128 * quality
dx, inv_dx = 1 / n_grid, float(n_grid)
Expand Down
2 changes: 1 addition & 1 deletion examples/mpm_lagrangian_forces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import taichi as ti
import os

ti.init(arch=ti.cuda)
ti.init(arch=ti.gpu)

real = ti.f32
dim = 2
Expand Down
3 changes: 1 addition & 2 deletions examples/nbody_oscillator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import taichi as ti

ti.init(
arch=ti.opengl) # Try to run on GPU, use ti.opengl if you don't have CUDA
ti.init(arch=ti.gpu)

N = 8000
pos = ti.Vector(2, dt=ti.f32, shape=N)
Expand Down
2 changes: 1 addition & 1 deletion examples/pbf2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import math

ti.init(arch=ti.cuda) # Try CUDA by default
ti.init(arch=ti.gpu)

screen_res = (800, 400)
screen_to_world_ratio = 10.0
Expand Down
2 changes: 1 addition & 1 deletion examples/sdf_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import math
import numpy as np

ti.init(arch=ti.cuda)
ti.init(arch=ti.gpu)
res = 1280, 720
color_buffer = ti.Vector(3, dt=ti.f32, shape=res)
max_ray_depth = 6
Expand Down
2 changes: 1 addition & 1 deletion examples/stable_fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

assert res > 2

ti.init(arch=ti.cuda)
ti.init(arch=ti.gpu)

_velocities = ti.Vector(2, dt=ti.f32, shape=(res, res))
_new_velocities = ti.Vector(2, dt=ti.f32, shape=(res, res))
Expand Down
29 changes: 24 additions & 5 deletions python/taichi/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
cuda = core.cuda
metal = core.metal
opengl = core.opengl
gpu = [cuda, metal, opengl]
cpu = core.host_arch()
profiler_print = lambda: core.get_current_program().profiler_print()
profiler_clear = lambda: core.get_current_program().profiler_clear()
profiler_start = lambda n: core.get_current_program().profiler_start(n)
Expand All @@ -55,7 +57,8 @@ def reset():
runtime = get_runtime()


def init(default_fp=None,
def init(arch=None,
default_fp=None,
default_ip=None,
print_preprocessed=None,
debug=None,
Expand Down Expand Up @@ -134,10 +137,12 @@ def boolean_config(key, name=None):
gdb_trigger = os.environ.get("TI_GDB_TRIGGER")
if gdb_trigger is not None:
ti.set_gdb_trigger(len(gdb_trigger) and bool(int(gdb_trigger)))
arch = os.environ.get("TI_ARCH")
if arch is not None:
print(f'Following TI_ARCH setting up for arch={arch}')
ti.cfg.arch = ti.core.arch_from_name(arch)
env_arch = os.environ.get("TI_ARCH")
if env_arch is not None:
print(f'Following TI_ARCH setting up for arch={env_arch}')
arch = ti.core.arch_from_name(env_arch)

ti.cfg.arch = adaptive_arch_select(arch)

log_level = os.environ.get("TI_LOG_LEVEL")
if log_level is not None:
Expand Down Expand Up @@ -265,6 +270,20 @@ def supported_archs():
return archs


def adaptive_arch_select(arch):
if arch is None:
return cpu
supported = supported_archs()
if isinstance(arch, list):
for a in arch:
if a in supported:
return a
elif arch in supported:
return arch
print(f'Arch={arch} not supported, falling back to CPU')
return cpu


class _ArchCheckers(object):
def __init__(self):
self._checkers = []
Expand Down