Is there a way to sum the whole var?

Is there a way to sum the whole var?

No, but you can write a 4-line kernel for this purpose.

Try this:

import taichi as ti
ti.init()
x = ti.var(ti.i32, n)
def func():
  ret = 0
  for i in range(n):
    ret += x[i]
  print(ret)
func()