Describe the bug
get a Segmentation Fault while invoke .norm()
environment: ubuntu 16.04 LTS / python 3.6.9 / taichi 0.6.7
Log/Screenshots
[E 06/06/20 20:55:45.920] Received signal 11 (Segmentation fault)
***********************************
* Taichi Compiler Stack Traceback *
***********************************
/usr/Software/anaconda3/lib/python3.6/site-packages/taichi/core/../lib/taichi_core.so: taichi::Logger::error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)
/usr/Software/anaconda3/lib/python3.6/site-packages/taichi/core/../lib/taichi_core.so: taichi::signal_handler(int)
/lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7ff227ba24b0]
/usr/Software/anaconda3/lib/python3.6/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::current_ast_builder()
/usr/Software/anaconda3/lib/python3.6/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::Var(taichi::lang::Expr const&)
/usr/Software/anaconda3/lib/python3.6/site-packages/taichi/core/../lib/taichi_core.so(+0x6f0a1a) [0x7ff1cad97a1a]
/usr/Software/anaconda3/lib/python3.6/site-packages/taichi/core/../lib/taichi_core.so(+0x655bef) [0x7ff1cacfcbef]
/usr/Software/anaconda3/bin/python: _PyCFunction_FastCallDict
/usr/Software/anaconda3/bin/python(+0x199abc) [0x55f39afb5abc]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x193c5b) [0x55f39afafc5b]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x192e66) [0x55f39afaee66]
/usr/Software/anaconda3/bin/python(+0x193ed6) [0x55f39afafed6]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x193c5b) [0x55f39afafc5b]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x193c5b) [0x55f39afafc5b]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x193c5b) [0x55f39afafc5b]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x192e66) [0x55f39afaee66]
/usr/Software/anaconda3/bin/python: _PyFunction_FastCallDict
/usr/Software/anaconda3/bin/python: _PyObject_FastCallDict
/usr/Software/anaconda3/bin/python: _PyObject_Call_Prepend
/usr/Software/anaconda3/bin/python: PyObject_Call
/usr/Software/anaconda3/bin/python(+0x16b6b0) [0x55f39af876b0]
/usr/Software/anaconda3/bin/python(+0x1f100e) [0x55f39b00d00e]
/usr/Software/anaconda3/bin/python: PyNumber_Power
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x193c5b) [0x55f39afafc5b]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x192e66) [0x55f39afaee66]
/usr/Software/anaconda3/bin/python(+0x193e73) [0x55f39afafe73]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python: PyEval_EvalCodeEx
/usr/Software/anaconda3/bin/python: PyEval_EvalCode
/usr/Software/anaconda3/bin/python(+0x1ba167) [0x55f39afd6167]
/usr/Software/anaconda3/bin/python: _PyCFunction_FastCallDict
/usr/Software/anaconda3/bin/python(+0x199abc) [0x55f39afb5abc]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python: _PyGen_Send
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python: _PyGen_Send
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python: _PyGen_Send
/usr/Software/anaconda3/bin/python: _PyCFunction_FastCallDict
/usr/Software/anaconda3/bin/python(+0x199abc) [0x55f39afb5abc]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x193c5b) [0x55f39afafc5b]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x193c5b) [0x55f39afafc5b]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x192e66) [0x55f39afaee66]
/usr/Software/anaconda3/bin/python(+0x193ed6) [0x55f39afafed6]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x192e66) [0x55f39afaee66]
/usr/Software/anaconda3/bin/python(+0x193e73) [0x55f39afafe73]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x192e66) [0x55f39afaee66]
/usr/Software/anaconda3/bin/python(+0x193e73) [0x55f39afafe73]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x193c5b) [0x55f39afafc5b]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x192e66) [0x55f39afaee66]
/usr/Software/anaconda3/bin/python: _PyFunction_FastCallDict
/usr/Software/anaconda3/bin/python: _PyObject_FastCallDict
/usr/Software/anaconda3/bin/python: _PyObject_Call_Prepend
/usr/Software/anaconda3/bin/python: PyObject_Call
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python(+0x192e66) [0x55f39afaee66]
/usr/Software/anaconda3/bin/python(+0x193ed6) [0x55f39afafed6]
/usr/Software/anaconda3/bin/python(+0x199b95) [0x55f39afb5b95]
/usr/Software/anaconda3/bin/python: _PyEval_EvalFrameDefault
/usr/Software/anaconda3/bin/python: PyEval_EvalCodeEx
/usr/Software/anaconda3/bin/python: PyEval_EvalCode
/usr/Software/anaconda3/bin/python(+0x215744) [0x55f39b031744]
/usr/Software/anaconda3/bin/python: PyRun_FileExFlags
/usr/Software/anaconda3/bin/python: PyRun_SimpleFileExFlags
/usr/Software/anaconda3/bin/python: Py_Main
/usr/Software/anaconda3/bin/python: main
/lib/x86_64-linux-gnu/libc.so.6: __libc_start_main
/usr/Software/anaconda3/bin/python(+0x1c3160) [0x55f39afdf160]
To Reproduce
import taichi as ti
a = ti.Vector([3,4,5])
print(a.norm())
print(a.dot(a))
same as outer_product
It seems that you're invoking norm and dot in Python-scope? For now, they can only be invoked in Taichi-scope, i.e.:
@ti.kernel
def taichi_kernel():
a = ti.Vector([3,4,5])
print(a.norm())
print(a.dot(a))
taichi_kernel()
Sorry for the confusing segmentation fault here, it will be replace with a friendly message in next release :)
Yeah for now these functions can only be called in Taichi-scope. We will gradually add Python-scope support in #1008
It seems that you're invoking
normanddotin Python-scope? For now, they can only be invoked in Taichi-scope, i.e.:@ti.kernel def taichi_kernel(): a = ti.Vector([3,4,5]) print(a.norm()) print(a.dot(a)) taichi_kernel()Sorry for the confusing segmentation fault here, it will be replace with a friendly message in next release :)
These functions cannot be called in Taichi-scope.

Did you run ti.init()? Does run from cmd or bash solve you problem?
Did you run
ti.init()? Does run fromcmdorbashsolve you problem?
Yes, but the problem remains.
environment: ubuntu18.04\ python 3.6.9\ taichi 0.6.7

The issue seems to be related to print(a.norm()), I could reproduce it with:
import taichi as ti
ti.init(arch=ti.cpu)
ti.reset()
@ti.kernel
def main():
a = ti.Vector([3,4])
a.norm() # -> OK
print(a.norm()) # -> Error out
main()
This line looks suspicious:

It seems that ti.Vector([3.0, 4.0]) solve the problem.
Because x.norm() needs sqrt, whose operand is i32 in this case.
Therefore it gives an error: sqrt is for float only!
@xumingkuan Can we promote operand to float for math functions like sqrt? So that ti.sqrt(3) won't result in an error?
Replaced by #1172.
Most helpful comment
The issue seems to be related to
print(a.norm()), I could reproduce it with:This line looks suspicious:
