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

[cuda] [test] Add TI_DEVICE_MEMORY_GB and TI_DEVICE_MEMORY_FRACTION environment variable #769

Merged
merged 11 commits into from
Apr 26, 2020
37 changes: 23 additions & 14 deletions python/taichi/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,31 @@ def init(arch=None,
for k, v in kwargs.items():
setattr(ti.cfg, k, v)

def boolean_config(key, name=None):
if name is None:
name = 'TI_' + key.upper()
value = os.environ.get(name)
if value is not None:
setattr(ti.cfg, key, len(value) and bool(int(value)))
def bool_int(x):
return bool(int(x))

def environ_config(key, cast=bool_int):
name = 'TI_' + key.upper()
value = os.environ.get(name, '')
if len(value):
setattr(ti.cfg, key, cast(value))

# TI_ASYNC= : not work
# TI_ASYNC=0 : False
# TI_ASYNC=1 : True

# does override
boolean_config("print_ir")
boolean_config("verbose")
boolean_config("fast_math")
boolean_config("async")
boolean_config("print_benchmark_stat")
gdb_trigger = os.environ.get("TI_GDB_TRIGGER")
if gdb_trigger is not None:
ti.set_gdb_trigger(len(gdb_trigger) and bool(int(gdb_trigger)))
environ_config("print_ir")
environ_config("verbose")
environ_config("fast_math")
environ_config("async")
environ_config("print_benchmark_stat")
environ_config("device_memory_fraction", float)
environ_config("device_memory_GB", float)
environ_config("gdb_trigger")

# Q: Why not environ_config("arch", ti.core.arch_from_name)?
# A: We need adaptive_arch_select for all.
env_arch = os.environ.get("TI_ARCH")
if env_arch is not None:
print(f'Following TI_ARCH setting up for arch={env_arch}')
Expand Down
1 change: 1 addition & 0 deletions python/taichi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_python(args):
threads = min(8, cpu_count()) # To prevent running out of memory
except:
threads = 2
os.environ['TI_DEVICE_MEMORY_GB'] = '0.5' # Discussion: #769
arg_threads = None
if args.threads is not None:
arg_threads = int(args.threads)
Expand Down
8 changes: 5 additions & 3 deletions taichi/program/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ void Program::initialize_runtime_system(StructCompiler *scomp) {
if (config.device_memory_fraction == 0) {
TI_ASSERT(config.device_memory_GB > 0);
prealloc_size = std::size_t(config.device_memory_GB * (1UL << 30));
} else
} else {
prealloc_size = std::size_t(config.device_memory_fraction * total_mem);
}
TI_ASSERT(prealloc_size <= total_mem);

TI_TRACE("Allocating device memory {:.2f} GB",
1.0 * prealloc_size / (1UL << 30));
Expand Down Expand Up @@ -485,8 +487,8 @@ void Program::finalize() {
std::string file_name = current_test;
auto py_pos = file_name.find(".py::");
TI_ASSERT(py_pos != file_name.npos);
file_name = file_name.substr(0, py_pos) + "__" +
file_name.substr(py_pos + 5);
file_name =
file_name.substr(0, py_pos) + "__" + file_name.substr(py_pos + 5);
auto first_space_pos = file_name.find_first_of(' ');
TI_ASSERT(first_space_pos != file_name.npos);
file_name = file_name.substr(0, first_space_pos);
Expand Down