Taichi: Disable Metal codegen on non-Mac systems, use TI_METAL or TI_OPENGL to configure

Created on 25 Feb 2020  路  1Comment  路  Source: taichi-dev/taichi

Concisely describe the proposed feature
I would like to make Metal backends not being shipped into libtaichi_core.so that is to be used in non-Mac environments (with great respect to @k-ye's work!)

Describe the solution you'd like
Use #if TI_PLATFORM_OSX guards to every Metal-related files, function calls.
May try TI_METAL and say Taichi not compiled with Metal support.
Then configure it by cmake arguments, or like make menuconfig of Linux.
Also try

#ifndef TI_METAL
#define TI_METAL 0 /* zero by default */
#endif

So that

if (TI_METAL) /* branch by constant */
  TI_INFO("Welcome!");
else
  TI_INFO("Sorry.");

works. The never-reached one will be optimized out by compiler.

Additional comments

$ find build/CMakeFiles -type f -name '*metal*' -exec du -h {} \;
672K    build/CMakeFiles/taichi_core.dir/taichi/platform/metal/metal_runtime.cpp.o
740K    build/CMakeFiles/taichi_core.dir/taichi/platform/metal/metal_kernel_util.cpp.o
692K    build/CMakeFiles/taichi_core.dir/taichi/platform/metal/metal_data_types.cpp.o
44K     build/CMakeFiles/taichi_core.dir/taichi/platform/metal/metal_api.cpp.o
1.3M    build/CMakeFiles/taichi_core.dir/taichi/backends/struct_metal.cpp.o
3.6M    build/CMakeFiles/taichi_core.dir/taichi/backends/codegen_metal.cpp.o

These codes are never reached on Linux and Windows platform, ld is not responsible for such optimization.
The attempt of code disabling for taichi may also help CUDA user to customize if OpenGL backend should be compiled. (inputs about GL are welcome at #495)

feature request

Most helpful comment

Yeah, I think it makes sense not to include metal codegen on non-Mac platforms.

As for TI_METAL, we actually started with this approach, but found that it was not so easy to check the existence of Metal at compile time, so we removed TI_METAL because it could be misleading.. I think guard with TI_PLATFORM_OSX is enough.

>All comments

Yeah, I think it makes sense not to include metal codegen on non-Mac platforms.

As for TI_METAL, we actually started with this approach, but found that it was not so easy to check the existence of Metal at compile time, so we removed TI_METAL because it could be misleading.. I think guard with TI_PLATFORM_OSX is enough.

Was this page helpful?
0 / 5 - 0 ratings