Skip to content

Commit

Permalink
[opengl] add TI_WITH_OPENGL env var to disable OpenGL (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate authored May 13, 2020
1 parent 8d5fa29 commit e919a2c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions taichi/backends/cuda/cuda_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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();
}

Expand Down
3 changes: 3 additions & 0 deletions taichi/backends/metal/api.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "taichi/backends/metal/api.h"
#include "taichi/util/environ_config.h"

TLANG_NAMESPACE_BEGIN

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions taichi/backends/opengl/opengl_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions taichi/core/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions taichi/util/environ_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "taichi/common/util.h"
#include <string>
#include <cstdlib>

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

0 comments on commit e919a2c

Please sign in to comment.