diff --git a/taichi/backends/cuda/cuda_driver.cpp b/taichi/backends/cuda/cuda_driver.cpp index 7f87619b99b90..2f21cbb0bd888 100644 --- a/taichi/backends/cuda/cuda_driver.cpp +++ b/taichi/backends/cuda/cuda_driver.cpp @@ -2,6 +2,7 @@ #include "taichi/system/dynamic_loader.h" #include "taichi/backends/cuda/cuda_context.h" +#include "taichi/util/environ_config.h" TLANG_NAMESPACE_BEGIN @@ -15,6 +16,8 @@ std::string get_cuda_error_message(uint32 err) { } bool CUDADriver::detected() { + if (get_environ_config("TI_ENABLE_CUDA", 1) == 0) + return false; return loader->loaded(); } diff --git a/taichi/backends/metal/api.cpp b/taichi/backends/metal/api.cpp index 36ebd57b3166d..d11d3fccb8ae8 100644 --- a/taichi/backends/metal/api.cpp +++ b/taichi/backends/metal/api.cpp @@ -1,4 +1,5 @@ #include "taichi/backends/metal/api.h" +#include "taichi/util/environ_config.h" TLANG_NAMESPACE_BEGIN @@ -133,6 +134,8 @@ size_t get_max_total_threads_per_threadgroup( bool is_metal_api_available() { #ifdef TI_PLATFORM_OSX + if (get_environ_config("TI_ENABLE_METAL", 1) == 0) + return false; // If the macOS is provided by a VM (e.g. Travis CI), it's possible that there // is no GPU device, so we still have to do a runtime check. auto device = mtl_create_system_default_device(); diff --git a/taichi/backends/opengl/opengl_api.cpp b/taichi/backends/opengl/opengl_api.cpp index b6d42eb245e19..fbf2d310b862a 100644 --- a/taichi/backends/opengl/opengl_api.cpp +++ b/taichi/backends/opengl/opengl_api.cpp @@ -4,6 +4,7 @@ #include "taichi/backends/opengl/opengl_kernel_util.h" #include "taichi/program/kernel.h" #include "taichi/program/program.h" +#include "taichi/util/environ_config.h" #ifdef TI_WITH_OPENGL #include "glad/glad.h" @@ -515,6 +516,8 @@ GLSLLaunchGuard::~GLSLLaunchGuard() { } bool is_opengl_api_available() { + if (get_environ_config("TI_ENABLE_OPENGL", 1) == 0) + return false; return initialize_opengl(true); } diff --git a/taichi/core/logging.cpp b/taichi/core/logging.cpp index 9327945630d80..6f2197fc713fd 100644 --- a/taichi/core/logging.cpp +++ b/taichi/core/logging.cpp @@ -155,8 +155,9 @@ std::string signal_name(int sig) { bool python_at_exit_called = false; void signal_handler(int signo) { - // It seems that there's no way to pass exception to Python in signal - // handlers? + // It seems that there's no way to pass exception to Python in signal handlers? + // @archibate found that in fact there are such solution: + // https://docs.python.org/3/library/faulthandler.html#module-faulthandler auto sig_name = signal_name(signo); logger.error(fmt::format("Received signal {} ({})", signo, sig_name), false); exit(-1); diff --git a/taichi/util/environ_config.h b/taichi/util/environ_config.h new file mode 100644 index 0000000000000..8b05f71a54310 --- /dev/null +++ b/taichi/util/environ_config.h @@ -0,0 +1,17 @@ +#pragma once + +#include "taichi/common/util.h" +#include +#include + +TLANG_NAMESPACE_BEGIN + +static inline int get_environ_config(const std::string &name, int default_value = 0) +{ + char *res = std::getenv(name.c_str()); + if (res == nullptr) + return default_value; + return std::stoi(res); +} + +TLANG_NAMESPACE_END