[metal backend] OS is stuck and restart

import taichi as ti
import time

ti.init(arch=ti.gpu, kernel_profiler=True)

f32  = lambda : ti.field(ti.f32)

x = f32()
y = f32()
u = f32()
v = f32()
ti.root.place(x,y,u,v)

def main() :
    t0 = time.time()
    for i in range(1000) :
        forward()
    print(f'PI = {u[None]/v[None]:.6f}')
    print(f'Time escape = {time.time() - t0:.2f}s')

@ti.kernel
def forward() :
    x[None] = 0.0
    y[None] = 0.0
    for i in range(1000000) :
        d = (ti.random()-0.5) ** 2 + (ti.random()-0.5) ** 2
        if d <= 0.5 ** 2 :
            x[None] += 1.0
        else :
            y[None] += 1.0
    u[None] += x[None]*4/((y[None]+x[None]))
    v[None] += 1.0

if __name__ == '__main__' :
    main()
    # ti.print_profile_info()
    ti.kernel_profiler_print()

I write this code to test the performance of metal backend.
but my macOS is stuck and restart.
Is it happened on your computer when run above code?

OS version info :
(10.15.7, Intel Iris Graphics 6100 1536 MB)

[Taichi] mode=release
[Taichi] preparing sandbox at /var/folders/k7/_bdt1q011bq2kgx0vtmj05zw0000gn/T/taichi-bkfejkjg
[Taichi] version 0.7.0, llvm 10.0.0, commit 0298bca3, osx, python 3.7.3
[Taichi] Starting on arch=metal
[Taichi] materializing...

Hi! I tried to run your code snippet with 0.7.1 (we may need to look into this since there’s no git tag for 0.7.1 but it’s on PyPI) and it worked fine:

~/Projects/openCode python3.8Env ❯ python ti_test.py
[Taichi] mode=release
[Taichi] preparing sandbox at /var/folders/dl/yyl2yx6j1_1g8zh26tbvm_th0000gp/T/taichi-fq7wxkmy
[Taichi] version 0.7.1, llvm 10.0.0, commit fc0f8be7, osx, python 3.8.2
[Taichi] Starting on arch=metal
[Taichi] materializing...
PI = 3.141563
Time escape = 12.32s
metal Profiler
=========================================================================
[      %     total   count |      min       avg       max   ] Kernel name
[100.00%  11.325 s     13x |    0.059   871.186 11128.040 ms] metal_synchronize
-------------------------------------------------------------------------
[100.00%] Total kernel execution time:  11.325 s   number of records: 1
=========================================================================

OS version info :
(10.15.7,
AMD Radeon Pro 5300M 4 GB
Intel UHD Graphics 630 1536 MB)

maybe you could share info more about your setup?

2 个赞

Thanks~ :+1:
Upgrade to 0.7.1, and it worked fine.

[Taichi] mode=release
[Taichi] preparing sandbox at /var/folders/k7/_bdt1q011bq2kgx0vtmj05zw0000gn/T/taichi-7ozq4co_
[Taichi] version 0.7.1, llvm 10.0.0, commit fc0f8be7, osx, python 3.7.3
[Taichi] Starting on arch=metal
[Taichi] materializing...
PI = 3.141802
Time escape = 51.84s
metal Profiler
=========================================================================
[      %     total   count |      min       avg       max   ] Kernel name
[100.00%  49.998 s     13x |    0.098  3845.972 49960.113 ms] metal_synchronize
-------------------------------------------------------------------------
[100.00%] Total kernel execution time:  49.998 s   number of records: 1
=========================================================================