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

[opengl] add TI_ENABLE_OPENGL env var to disable OpenGL #962

Merged
merged 5 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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