diff --git a/python/taichi/__init__.py b/python/taichi/__init__.py index 034052ed5bd73..a6f6bf06148fa 100644 --- a/python/taichi/__init__.py +++ b/python/taichi/__init__.py @@ -10,7 +10,7 @@ from taichi.types.primitive_types import * -from taichi import ad, algorithms, experimental, graph, linalg, math, sparse, tools, types +from taichi import ad, algorithms, graph, linalg, math, sparse, tools, types from taichi.ui import GUI, hex_to_rgb, rgb_to_hex, ui # Issue#2223: Do not reorder, or we're busted with partially initialized module diff --git a/python/taichi/examples/real_func/algorithm/marching_squares.py b/python/taichi/examples/real_func/algorithm/marching_squares.py index 9c0c6ffd405e4..d9a2f2ffb16e4 100644 --- a/python/taichi/examples/real_func/algorithm/marching_squares.py +++ b/python/taichi/examples/real_func/algorithm/marching_squares.py @@ -48,14 +48,14 @@ iTime = ti.field(float, shape=()) -@ti.experimental.real_func +@ti.real_func def hash22(p_: tm.vec2) -> tm.vec2: n = tm.sin(tm.dot(p_, tm.vec2(41, 289))) p = tm.fract(tm.vec2(262144, 32768) * n) return tm.sin(p * 6.28 + iTime[None]) -@ti.experimental.real_func +@ti.real_func def noise(p_: tm.vec2) -> float: ip = tm.floor(p_) p = p_ - ip @@ -69,17 +69,17 @@ def noise(p_: tm.vec2) -> float: return tm.mix(tm.mix(v.x, v.y, p.x), tm.mix(v.z, v.w, p.x), p.y) -@ti.experimental.real_func +@ti.real_func def isofunc(p: tm.vec2) -> float: return noise(p / 4 + 1) -@ti.experimental.real_func +@ti.real_func def interp(p1: tm.vec2, p2: tm.vec2, v1: float, v2: float, isovalue: float) -> tm.vec2: return tm.mix(p1, p2, (isovalue - v1) / (v2 - v1)) -@ti.experimental.real_func +@ti.real_func def get_vertex(vertex_id: int, values: tm.vec4, isovalue: float) -> tm.vec2: v = tm.vec2(0) square = [tm.vec2(0), tm.vec2(1, 0), tm.vec2(1, 1), tm.vec2(0, 1)] @@ -133,7 +133,7 @@ def march_squares() -> int: return edges.length() -@ti.experimental.real_func +@ti.real_func def dseg(p_: tm.vec2, a: tm.vec2, b_: tm.vec2) -> ti.f32: p = p_ - a b = b_ - a diff --git a/python/taichi/examples/real_func/algorithm/poisson_disk_sampling.py b/python/taichi/examples/real_func/algorithm/poisson_disk_sampling.py index b8e1480a1b995..a8e16fae3f2d8 100644 --- a/python/taichi/examples/real_func/algorithm/poisson_disk_sampling.py +++ b/python/taichi/examples/real_func/algorithm/poisson_disk_sampling.py @@ -30,7 +30,7 @@ sample_count = ti.field(int, shape=()) -@ti.experimental.real_func +@ti.real_func def coord_to_index(p: tm.vec2) -> tm.ivec2: return (p * tm.vec2(grid_n)).cast(int) @@ -52,7 +52,7 @@ def refresh_scene(): img[i, j] = tm.vec3(1) -@ti.experimental.real_func +@ti.real_func def find_nearest_point(p: tm.vec2) -> typing.Tuple[float, tm.vec2]: x, y = coord_to_index(p) dmin = 1e5 @@ -90,12 +90,12 @@ def poisson_disk_sample(num_samples: int) -> int: return tail[None] -@ti.experimental.real_func +@ti.real_func def hash21(p: tm.vec2) -> float: return tm.fract(tm.sin(tm.dot(p, tm.vec2(127.619, 157.583))) * 43758.5453) -@ti.experimental.real_func +@ti.real_func def sample_dist(uv_: tm.vec2) -> tm.vec4: uv = uv_ * iResolution x, y = tm.clamp(0, iResolution - 1, uv).cast(int) diff --git a/python/taichi/examples/real_func/graph/stable_fluid_graph.py b/python/taichi/examples/real_func/graph/stable_fluid_graph.py index b7e05fdc77894..919afb4f46ac3 100644 --- a/python/taichi/examples/real_func/graph/stable_fluid_graph.py +++ b/python/taichi/examples/real_func/graph/stable_fluid_graph.py @@ -40,17 +40,17 @@ def sample_impl(qf: ti.template(), u: int, v: int): return qf[I] -@ti.experimental.real_func +@ti.real_func def sample2(qf: ti.types.ndarray(ndim=2), u: int, v: int) -> vec2: return sample_impl(qf, u, v) -@ti.experimental.real_func +@ti.real_func def sample3(qf: ti.types.ndarray(ndim=2), u: int, v: int) -> vec3: return sample_impl(qf, u, v) -@ti.experimental.real_func +@ti.real_func def sample0(qf: ti.types.ndarray(ndim=2), u: int, v: int) -> float: return sample_impl(qf, u, v) @@ -86,12 +86,12 @@ def bilerp_impl(vf: ti.template(), p): return lerp(lerp(a, b, fu), lerp(c, d, fu), fv) -@ti.experimental.real_func +@ti.real_func def bilerp2(vf: ti.types.ndarray(ndim=2), p: vec2) -> vec2: return bilerp_impl(vf, p) -@ti.experimental.real_func +@ti.real_func def bilerp3(vf: ti.types.ndarray(ndim=2), p: vec2) -> vec3: return bilerp_impl(vf, p) @@ -105,7 +105,7 @@ def bilerp(vf: ti.template(), p): # 3rd order Runge-Kutta -@ti.experimental.real_func +@ti.real_func def backtrace(vf: ti.types.ndarray(ndim=2), p: vec2, dt_: float) -> vec2: v1 = bilerp(vf, p) p1 = p - 0.5 * dt_ * v1 diff --git a/python/taichi/examples/real_func/rendering/cornell_box.py b/python/taichi/examples/real_func/rendering/cornell_box.py index 338369b1b6272..fd4233ff7e010 100644 --- a/python/taichi/examples/real_func/rendering/cornell_box.py +++ b/python/taichi/examples/real_func/rendering/cornell_box.py @@ -48,7 +48,7 @@ ) -@ti.experimental.real_func +@ti.real_func def rotate(a: vec3) -> mat3: s, c = sin(a), cos(a) return ( @@ -58,14 +58,14 @@ def rotate(a: vec3) -> mat3: ) -@ti.experimental.real_func +@ti.real_func def signed_distance(obj: SDFObject, pos: vec3) -> float: p = obj.transform.matrix @ (pos - obj.transform.position) q = abs(p) - obj.transform.scale return length(max(q, 0)) + min(max(q.x, max(q.y, q.z)), 0) -@ti.experimental.real_func +@ti.real_func def nearest_object(p: vec3) -> (int, float): index, min_dis = 0, 1e32 for i in ti.static(range(8)): @@ -75,7 +75,7 @@ def nearest_object(p: vec3) -> (int, float): return index, min_dis -@ti.experimental.real_func +@ti.real_func def calc_normal(obj: SDFObject, p: vec3) -> vec3: e = vec2(1, -1) * 0.5773 * 0.005 return normalize( @@ -86,7 +86,7 @@ def calc_normal(obj: SDFObject, p: vec3) -> vec3: ) -@ti.experimental.real_func +@ti.real_func def raycast(ray: Ray) -> (SDFObject, vec3, bool): w, s, d, cerr = 1.6, 0.0, 0.0, 1e32 index, t, position, hit = 0, 0.005, vec3(0), False @@ -113,7 +113,7 @@ def raycast(ray: Ray) -> (SDFObject, vec3, bool): return objects[index], position, hit -@ti.experimental.real_func +@ti.real_func def hemispheric_sampling(normal: vec3) -> vec3: z = 2.0 * ti.random() - 1.0 a = ti.random() * 2.0 * pi @@ -121,7 +121,7 @@ def hemispheric_sampling(normal: vec3) -> vec3: return normalize(normal + vec3(xy, z)) -@ti.experimental.real_func +@ti.real_func def raytrace(ray: Ray) -> Ray: for _ in range(3): object, position, hit = raycast(ray) diff --git a/python/taichi/examples/real_func/rendering/taichi_ngp.py b/python/taichi/examples/real_func/rendering/taichi_ngp.py index fe6ea40d19568..0b816e3288d47 100644 --- a/python/taichi/examples/real_func/rendering/taichi_ngp.py +++ b/python/taichi/examples/real_func/rendering/taichi_ngp.py @@ -63,12 +63,12 @@ def depth2img(depth): # <----------------- hash table util code -----------------> -@ti.experimental.real_func +@ti.real_func def calc_dt(t: data_type, exp_step_factor: data_type, grid_size: int, scale: data_type) -> data_type: return ti.math.clamp(t * exp_step_factor, SQRT3_MAX_SAMPLES, SQRT3_2 * scale / grid_size) -@ti.experimental.real_func +@ti.real_func def __expand_bits(v_: uvec3) -> uvec3: v = (v_ * ti.uint32(0x00010001)) & ti.uint32(0xFF0000FF) v = (v * ti.uint32(0x00000101)) & ti.uint32(0x0F00F00F) @@ -77,13 +77,13 @@ def __expand_bits(v_: uvec3) -> uvec3: return v -@ti.experimental.real_func +@ti.real_func def __morton3D(xyz_: uvec3) -> ti.u32: xyz = __expand_bits(xyz_) return xyz[0] | (xyz[1] << 1) | (xyz[2] << 2) -@ti.experimental.real_func +@ti.real_func def fast_hash(pos_grid_local: uvec3) -> ti.u32: result = ti.uint32(0) primes = uvec3(ti.uint32(1), ti.uint32(2654435761), ti.uint32(805459861)) @@ -92,7 +92,7 @@ def fast_hash(pos_grid_local: uvec3) -> ti.u32: return result -@ti.experimental.real_func +@ti.real_func def under_hash(pos_grid_local: uvec3, resolution: ti.u32) -> ti.u32: result = ti.uint32(0) stride = ti.uint32(1) @@ -102,7 +102,7 @@ def under_hash(pos_grid_local: uvec3, resolution: ti.u32) -> ti.u32: return result -@ti.experimental.real_func +@ti.real_func def grid_pos2hash_index(indicator: ti.i32, pos_grid_local: uvec3, resolution: ti.u32, map_size: ti.u32) -> ti.u32: hash_result = ti.uint32(0) if indicator == 1: @@ -116,20 +116,20 @@ def grid_pos2hash_index(indicator: ti.i32, pos_grid_local: uvec3, resolution: ti # <----------------- hash table util code -----------------> -@ti.experimental.real_func +@ti.real_func def random_in_unit_disk() -> tf_vec2: theta = 2.0 * np.pi * ti.random() return ti.Vector([ti.sin(theta), ti.cos(theta)]) -@ti.experimental.real_func +@ti.real_func def random_normal() -> tf_vec2: x = ti.random() * 2.0 - 1.0 y = ti.random() * 2.0 - 1.0 return tf_vec2(x, y) -@ti.experimental.real_func +@ti.real_func def dir_encode_func(dir_: tf_vec3) -> tf_vec32: out_feat = tf_vec32(0.0) dir_n = dir_ / dir_.norm() @@ -341,7 +341,7 @@ def reset(self): for i, j in ti.ndrange(self.N_rays, 2): self.alive_indices[i * 2 + j] = i - @ti.experimental.real_func + @ti.real_func def _ray_aabb_intersec(self, ray_o: tf_vec3, ray_d: tf_vec3) -> tf_vec2: inv_d = 1.0 / ray_d diff --git a/python/taichi/experimental.py b/python/taichi/experimental.py deleted file mode 100644 index 13df4c4a9baf3..0000000000000 --- a/python/taichi/experimental.py +++ /dev/null @@ -1,3 +0,0 @@ -from taichi.lang.kernel_impl import real_func - -__all__ = ["real_func"] diff --git a/python/taichi/lang/kernel_impl.py b/python/taichi/lang/kernel_impl.py index 8dc641ee195b8..5bb3c1461671b 100644 --- a/python/taichi/lang/kernel_impl.py +++ b/python/taichi/lang/kernel_impl.py @@ -1232,4 +1232,4 @@ def _getattr(self, item): return cls -__all__ = ["data_oriented", "func", "kernel", "pyfunc"] +__all__ = ["data_oriented", "func", "kernel", "pyfunc", "real_func"] diff --git a/tests/python/test_api.py b/tests/python/test_api.py index 651f53f2954cf..4782ad6b74379 100644 --- a/tests/python/test_api.py +++ b/tests/python/test_api.py @@ -129,7 +129,6 @@ def _get_expected_matrix_apis(): "dx12", "eig", "exp", - "experimental", "extension", "f16", "f32", @@ -199,6 +198,7 @@ def _get_expected_matrix_apis(): "random", "raw_div", "raw_mod", + "real_func", "ref", "rescale_index", "reset", diff --git a/tests/python/test_argument.py b/tests/python/test_argument.py index 2119a7ebb7780..a957765375fc1 100644 --- a/tests/python/test_argument.py +++ b/tests/python/test_argument.py @@ -240,7 +240,7 @@ def test_struct_arg_with_matrix_real_func(): s0 = ti.types.struct(a=mat, b=ti.f32) s1 = ti.types.struct(a=ti.i32, b=s0) - @ti.experimental.real_func + @ti.real_func def foo(a: s1) -> ti.i32: ret = a.a + a.b.b for i in range(3): diff --git a/tests/python/test_function.py b/tests/python/test_function.py index 6368de4a5c61f..a41c96a116607 100644 --- a/tests/python/test_function.py +++ b/tests/python/test_function.py @@ -8,7 +8,7 @@ def test_function_without_return(): x = ti.field(ti.i32, shape=()) - @ti.experimental.real_func + @ti.real_func def foo(val: ti.i32): x[None] += val @@ -26,7 +26,7 @@ def run(): def test_function_with_return(): x = ti.field(ti.i32, shape=()) - @ti.experimental.real_func + @ti.real_func def foo(val: ti.i32) -> ti.i32: x[None] += val return val @@ -46,7 +46,7 @@ def run(): def test_call_expressions(): x = ti.field(ti.i32, shape=()) - @ti.experimental.real_func + @ti.real_func def foo(val: ti.i32) -> ti.i32: if x[None] > 10: x[None] += 1 @@ -150,7 +150,7 @@ def run_kernel(): assert x[None] == 11 assert y[None] == 21 - @ti.experimental.real_func + @ti.real_func def inc(x: ti.template()): x[None] += 1 @@ -182,7 +182,7 @@ def verify(): def test_missing_arg_annotation(): with pytest.raises(ti.TaichiSyntaxError, match="must be type annotated"): - @ti.experimental.real_func + @ti.real_func def add(a, b: ti.i32) -> ti.i32: return a + b @@ -191,7 +191,7 @@ def add(a, b: ti.i32) -> ti.i32: def test_missing_return_annotation(): with pytest.raises(ti.TaichiCompilationError, match="return value must be annotated"): - @ti.experimental.real_func + @ti.real_func def add(a: ti.i32, b: ti.i32): return a + b @@ -204,7 +204,7 @@ def run(): @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_different_argument_type(): - @ti.experimental.real_func + @ti.real_func def add(a: ti.f32, b: ti.f32) -> ti.f32: return a + b @@ -218,7 +218,7 @@ def run() -> ti.i32: @pytest.mark.run_in_serial @test_utils.test(arch=[ti.cpu, ti.cuda], cuda_stack_limit=8192) def test_recursion(): - @ti.experimental.real_func + @ti.real_func def sum(f: ti.template(), l: ti.i32, r: ti.i32) -> ti.i32: if l == r: return f[l] @@ -239,7 +239,7 @@ def get_sum() -> ti.i32: @pytest.mark.run_in_serial @test_utils.test(arch=[ti.cpu, ti.cuda], cuda_stack_limit=32768) def test_deep_recursion(): - @ti.experimental.real_func + @ti.real_func def sum_func(n: ti.i32) -> ti.i32: if n == 0: return 0 @@ -256,7 +256,7 @@ def sum(n: ti.i32) -> ti.i32: def test_multiple_return(): x = ti.field(ti.i32, shape=()) - @ti.experimental.real_func + @ti.real_func def foo(val: ti.i32) -> ti.i32: if x[None] > 10: if x[None] > 20: @@ -278,7 +278,7 @@ def run(): @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_return_in_for(): - @ti.experimental.real_func + @ti.real_func def foo() -> ti.i32: for i in range(10): return 42 @@ -292,7 +292,7 @@ def bar() -> ti.i32: @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_return_in_while(): - @ti.experimental.real_func + @ti.real_func def foo() -> ti.i32: i = 1 while i: @@ -307,7 +307,7 @@ def bar() -> ti.i32: @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_return_in_if_in_for(): - @ti.experimental.real_func + @ti.real_func def foo(a: ti.i32) -> ti.i32: s = 0 for i in range(100): @@ -326,7 +326,7 @@ def bar(a: ti.i32) -> ti.i32: @test_utils.test(arch=[ti.cpu, ti.cuda], debug=True) def test_ref(): - @ti.experimental.real_func + @ti.real_func def foo(a: ti.ref(ti.f32)): a = 7 @@ -349,7 +349,7 @@ def test_ref_atomic(): "Skip this test on Pascal (and potentially older) architecture, ask turbo0628/Proton for more information" ) - @ti.experimental.real_func + @ti.real_func def foo(a: ti.ref(ti.f32)): a += a @@ -448,7 +448,7 @@ def k(): @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_real_func_matrix_arg(): - @ti.experimental.real_func + @ti.real_func def mat_arg(a: ti.math.mat2, b: ti.math.vec2) -> float: return a[0, 0] + a[0, 1] + a[1, 0] + a[1, 1] + b[0] + b[1] @@ -466,7 +466,7 @@ def foo() -> float: @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_real_func_matrix_return(): - @ti.experimental.real_func + @ti.real_func def mat_ret() -> ti.math.mat2: return ti.math.mat2(1, 2, 3, 4) @@ -481,7 +481,7 @@ def foo() -> ti.math.mat2: def test_real_func_struct_ret(): s = ti.types.struct(a=ti.i16, b=ti.f64) - @ti.experimental.real_func + @ti.real_func def bar() -> s: return s(a=123, b=ti.f64(1.2345e300)) @@ -498,7 +498,7 @@ def test_real_func_struct_ret_with_matrix(): s0 = ti.types.struct(a=ti.math.vec3, b=ti.i16) s1 = ti.types.struct(a=ti.f32, b=s0) - @ti.experimental.real_func + @ti.real_func def bar() -> s1: return s1(a=1, b=s0(a=ti.Vector([100, 0.2, 3], dt=ti.f32), b=65537)) @@ -512,7 +512,7 @@ def foo() -> ti.f32: @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_break_in_real_func(): - @ti.experimental.real_func + @ti.real_func def bar() -> int: a = 0 for i in range(10): @@ -530,7 +530,7 @@ def foo() -> int: @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_continue_in_real_func(): - @ti.experimental.real_func + @ti.real_func def bar() -> int: a = 0 for i in range(10): diff --git a/tests/python/test_ndarray.py b/tests/python/test_ndarray.py index f9d3bd6dfc051..2c8fd552e12f4 100644 --- a/tests/python/test_ndarray.py +++ b/tests/python/test_ndarray.py @@ -1032,7 +1032,7 @@ def foo(weight: ti.types.ndarray(ti.f32, ndim=3)) -> ti.f32: @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_pass_ndarray_to_real_func(): - @ti.experimental.real_func + @ti.real_func def bar(weight: ti.types.ndarray(ti.f32, ndim=3)) -> ti.f32: return weight[1, 1, 1] @@ -1049,7 +1049,7 @@ def foo(weight: ti.types.ndarray(ti.f32, ndim=3)) -> ti.f32: def test_pass_ndarray_outside_kernel_to_real_func(): weight = ti.ndarray(dtype=ti.f32, shape=(2, 2, 2)) - @ti.experimental.real_func + @ti.real_func def bar(weight: ti.types.ndarray(ti.f32, ndim=3)) -> ti.f32: return weight[1, 1, 1] @@ -1131,7 +1131,7 @@ def foo(x: ti.types.ndarray(float, ndim=0)) -> ti.f32: @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_real_func_vector_ndarray_arg(): - @ti.experimental.real_func + @ti.real_func def foo(x: ti.types.ndarray(ndim=1)) -> vec3: return x[0] @@ -1146,7 +1146,7 @@ def test(x: ti.types.ndarray(ndim=1)) -> vec3: @test_utils.test(arch=[ti.cpu, ti.cuda]) def test_real_func_write_ndarray_cfg(): - @ti.experimental.real_func + @ti.real_func def bar(a: ti.types.ndarray(ndim=1)): a[0] = vec3(1) diff --git a/tests/python/test_offline_cache.py b/tests/python/test_offline_cache.py index 56f49b5a1a6aa..e61cae7d64c07 100644 --- a/tests/python/test_offline_cache.py +++ b/tests/python/test_offline_cache.py @@ -477,7 +477,7 @@ def added_files(): return cache_files_cnt() - count_of_cache_file def helper1(): - @ti.experimental.real_func + @ti.real_func def sum(l: ti.i32, r: ti.i32) -> ti.i32: if l == r: return l @@ -491,7 +491,7 @@ def get_sum() -> ti.i32: assert get_sum() == 99 * 50 def helper2(): - @ti.experimental.real_func + @ti.real_func def sum(l: ti.i32, r: ti.i32) -> ti.i32: if l == r: return l diff --git a/tests/python/test_oop.py b/tests/python/test_oop.py index be981ca41b9fe..d0c908191fb59 100644 --- a/tests/python/test_oop.py +++ b/tests/python/test_oop.py @@ -46,11 +46,11 @@ def __init__(self, n, m): self.m = m self.val = ti.field(ti.f32, shape=(n, m)) - @ti.experimental.real_func + @ti.real_func def inc(self, i: ti.i32, j: ti.i32): self.val[i, j] += i * j - @ti.experimental.real_func + @ti.real_func def mul(self, i: ti.i32, j: ti.i32) -> ti.i32: return i * j diff --git a/tests/python/test_return.py b/tests/python/test_return.py index d15909173e2b1..9ea1df4b02821 100644 --- a/tests/python/test_return.py +++ b/tests/python/test_return.py @@ -215,7 +215,7 @@ def foo() -> s1: def test_real_func_tuple_ret_39(): s0 = ti.types.struct(a=ti.math.vec3, b=ti.i16) - @ti.experimental.real_func + @ti.real_func def foo() -> tuple[ti.f32, s0]: return 1, s0(a=ti.math.vec3([100, 0.2, 3]), b=65537) @@ -235,7 +235,7 @@ def bar() -> tuple[ti.f32, s0]: def test_real_func_tuple_ret_typing_tuple(): s0 = ti.types.struct(a=ti.math.vec3, b=ti.i16) - @ti.experimental.real_func + @ti.real_func def foo() -> Tuple[ti.f32, s0]: return 1, s0(a=ti.math.vec3([100, 0.2, 3]), b=65537) @@ -255,7 +255,7 @@ def bar() -> Tuple[ti.f32, s0]: def test_real_func_tuple_ret(): s0 = ti.types.struct(a=ti.math.vec3, b=ti.i16) - @ti.experimental.real_func + @ti.real_func def foo() -> (ti.f32, s0): return 1, s0(a=ti.math.vec3([100, 0.2, 3]), b=65537)