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

[CC] Ship the C backend! #1644

Open
3 of 9 tasks
archibate opened this issue Aug 5, 2020 · 6 comments
Open
3 of 9 tasks

[CC] Ship the C backend! #1644

archibate opened this issue Aug 5, 2020 · 6 comments
Assignees
Labels
feature request Suggest an idea on this project
Milestone

Comments

@archibate
Copy link
Collaborator

archibate commented Aug 5, 2020

Continue our talk in #1332.

Concisely describe the proposed feature
Currently our C backend is capable of passing all the tests on my end. I think it's time to officially release the C backend!

Describe the solution you'd like (if any)

Additional comments
To make C backend work on Windows could be challenging because:

  1. The %PATH% does not have an official /bin directory, it would be hard to seek for the correct compiler.
  2. The MSVC's compiler argument, IIRC, uses / as option prefix instead of -, e.g.: /O3 instead of -O3.
  3. Windows doesn't provide full POSIX support, some functions like drand48() could be unavailable there.

So we'd release C backend on Linux and OS X first, then deal with Windows.

@archibate archibate added the feature request Suggest an idea on this project label Aug 5, 2020
@archibate archibate self-assigned this Aug 5, 2020
@archibate archibate added this to the v0.7.0 milestone Aug 5, 2020
@yuanming-hu yuanming-hu mentioned this issue Aug 7, 2020
10 tasks
@samuela
Copy link
Contributor

samuela commented Aug 10, 2020

I just attempted the instructions here but I'm getting an error:

[I 08/09/20 23:44:16.054] [__init__.py:init@200] Following TI_ARCH setting up for arch=cc
[W 08/09/20 23:44:16.257] [__init__.py:adaptive_arch_select@383] Arch=Arch.cc is not supported, falling back to CPU

Am I doing something wrong?

@archibate
Copy link
Collaborator Author

archibate commented Aug 10, 2020

Sorry, the C backend is not release yet. You need to clone the Taichi repo and build it from source, see dev_install.rst.
Also note that currently the C backend is not compiled by default, please use -DTI_WITH_CC:BOOL=ON to override it:

cmake -Bbuild -S. -DTI_WITH_CC:BOOL=ON
make -Cbuild -j4

@samuela
Copy link
Contributor

samuela commented Aug 10, 2020

Ah, got it! I'll try building from source!

samuela added a commit to samuela/taichi that referenced this issue Aug 10, 2020
@samuela
Copy link
Contributor

samuela commented Aug 10, 2020

Awesome, so I now got TI_ARCH=cc working by editing the Dockerfile: #1680. Now I'm faced with a new issue:

root@425af79fc248:/difftaichi# TI_ACTION_RECORD=deleteme.yaml TI_ARCH=cc python3 examples/mass_spring.py 2 train
[Taichi] mode=development
[Taichi] preparing sandbox at /tmp/taichi-pdt02mkw
[I 08/10/20 22:13:05.615] [action_recorder.cpp:start_recording@27] ActionRecorder: start recording to [deleteme.yaml]
[Taichi] <dev mode>, llvm 10.0.0, commit bf403b58, python 3.6.9
[W 08/10/20 22:13:05.673] [shell.py:<module>@7] `sourceinspect` not installed!
[W 08/10/20 22:13:05.673] [shell.py:<module>@8] This may cause Taichi not functional in IDLE interactive shell, Blender scripting module and Python native shell.
[W 08/10/20 22:13:05.673] [shell.py:<module>@10] Please run `python3 -m pip install sourceinspect` to install.
[I 08/10/20 22:13:06.019] [__init__.py:init@208] Following TI_ARCH setting up for arch=cc
No protocol specified
[Taichi] Starting on arch=cc
n_objects= 20    n_springs= 46
[Taichi] materializing...
[I 08/10/20 22:13:07.144] [cc_program.cpp:compile_layout@137] [cc] C backend root buffer size: 9554712 B
[E 08/10/20 22:13:14.848] [statements.inc.h:visit@41] Not supported.


***********************************
* Taichi Compiler Stack Traceback *
***********************************
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::Logger::error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::IRVisitor::visit(taichi::lang::LocalStoreStmt*)
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::MakeAdjoint::visit(taichi::lang::IfStmt*)
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::MakeAdjoint::visit(taichi::lang::Block*)
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::irpass::auto_diff(taichi::lang::IRNode*, bool)
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::irpass::compile_to_offloads(taichi::lang::IRNode*, taichi::lang::CompileConfig const&, bool, bool, bool, bool)
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::irpass::compile_to_executable(taichi::lang::IRNode*, taichi::lang::CompileConfig const&, bool, bool, bool, bool, bool, bool, bool)
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::cccp::CCTransformer::lower_ast()
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::cccp::CCTransformer::run()
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::cccp::CCKernelGen::compile()
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::cccp::compile_kernel(taichi::lang::Kernel*)
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::Program::compile(taichi::lang::Kernel&)
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::Kernel::compile()
/tmp/taichi-pdt02mkw/taichi_core.so: taichi::lang::Kernel::operator()()
/tmp/taichi-pdt02mkw/taichi_core.so(+0x48a1d9) [0x7fe360fa51d9]
/tmp/taichi-pdt02mkw/taichi_core.so(+0x3c6090) [0x7fe360ee1090]
python3(_PyCFunction_FastCallDict+0x35c) [0x566ddc]
python3() [0x594b71]
python3() [0x54ac61]
python3(_PyObject_FastCallKeywords+0x19c) [0x5a9eec]
python3() [0x50a783]
python3(_PyEval_EvalFrameDefault+0x444) [0x50c1f4]
python3() [0x507f24]
python3() [0x588ddb]
python3(PyObject_Call+0x3e) [0x59fe1e]
python3(_PyEval_EvalFrameDefault+0x17e6) [0x50d596]
python3() [0x507f24]
python3(_PyFunction_FastCallDict+0x2e2) [0x509202]
python3() [0x594b01]
python3() [0x54ac61]
python3(PyObject_Call+0x3e) [0x59fe1e]
python3(_PyEval_EvalFrameDefault+0x17e6) [0x50d596]
python3() [0x509918]
python3() [0x50a64d]
python3(_PyEval_EvalFrameDefault+0x444) [0x50c1f4]
python3(_PyFunction_FastCallDict+0xf5) [0x509015]
python3() [0x594b01]
python3(_PyObject_FastCallDict+0x17c) [0x5a4a0c]
python3(PyObject_CallFunctionObjArgs+0xd8) [0x5a50d8]
python3(_PyEval_EvalFrameDefault+0x1af3) [0x50d8a3]
python3() [0x507f24]
python3() [0x509c50]
python3() [0x50a64d]
python3(_PyEval_EvalFrameDefault+0x1226) [0x50cfd6]
python3() [0x509918]
python3() [0x50a64d]
python3(_PyEval_EvalFrameDefault+0x444) [0x50c1f4]
python3() [0x507f24]
python3(PyEval_EvalCode+0x23) [0x50b053]
python3() [0x634dd2]
python3(PyRun_FileExFlags+0x97) [0x634e87]
python3(PyRun_SimpleFileExFlags+0x17f) [0x63863f]
python3(Py_Main+0x591) [0x6391e1]
python3(main+0xe0) [0x4b0dc0]
/lib/x86_64-linux-gnu/libc.so.6: __libc_start_main
python3(_start+0x2a) [0x5b26fa]

Internal Error occurred, check this page for possible solutions:
https://taichi.readthedocs.io/en/stable/install.html#troubleshooting
Traceback (most recent call last):
  File "examples/mass_spring.py", line 390, in <module>
    main()
  File "examples/mass_spring.py", line 384, in main
    optimize(toi=True, visualize=False)
  File "examples/mass_spring.py", line 321, in optimize
    forward(visualize=visualize)
  File "/taichi-dev/taichi/python/taichi/lang/tape.py", line 18, in __exit__
    self.grad()
  File "/taichi-dev/taichi/python/taichi/lang/tape.py", line 27, in grad
    func.grad(*args)
  File "/taichi-dev/taichi/python/taichi/lang/kernel.py", line 499, in __call__
    return self.compiled_functions[key](*args)
  File "/taichi-dev/taichi/python/taichi/lang/kernel.py", line 461, in func__
    t_kernel()
RuntimeError: [statements.inc.h:visit@41] Not supported.
root@425af79fc248:/difftaichi# 

Does the CC backend not support gradients?

@archibate
Copy link
Collaborator Author

Does the CC backend not support gradients?

Yes, that example probably needs adstack, which is not yet implemented on CC. I'll try to add it in the future.

@samuela
Copy link
Contributor

samuela commented Aug 11, 2020

Ah ok, I really need the AD system, so I'll try using taichi through PyCall.jl then for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Suggest an idea on this project
Projects
None yet
Development

No branches or pull requests

2 participants