taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.05k stars 2.26k forks source link

Replace TI_RUNTIME_HOST with #ifdef __cplusplus #4956

Open k-ye opened 2 years ago

k-ye commented 2 years ago

Right now we are using #ifdef TI_RUNTIME_HOST to provide CPP side functions for RuntimeContext: https://github.com/taichi-dev/taichi/blob/c3631c09c1b2416f2e2740628acf78b7c06fb394/taichi/program/context.h#L35-L86. This can be replaced with a #ifdef __cplusplus check. That way other part of the CPP codebase using this context will not have to define TI_RUNTIME_HOST anymore (https://github.com/taichi-dev/taichi/search?q=TI_RUNTIME_HOST).

cyberkillor commented 1 year ago

Hi, I'm wondering if this replacement is effective. Since __cplusplus is still defined even access in extern "C" closure.

For example, in file taichi/runtime/llvm/runtime_module/runtime.cpp, line 156 use extern "C" and line 346 include context.h.

if replace TI_RUNTIME_HOST with __cplusplus in taichi/program/context.h. it will still try to complie the code in __cplusplus closure and report an error templates must have C++ linkage, which seems cannnot be handled