Skip to content

Commit 6bf1525

Browse files
authored
Merge pull request #522 from drewgilliam/cache_dir
feat: rtc_set_cache_dir
2 parents 1477416 + 2756619 commit 6bf1525

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

bindings/torch/tinycudann/modules.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import gc
1010
import importlib
1111
import os
12+
import tempfile
1213
import warnings
1314

1415
import torch
@@ -72,15 +73,36 @@ def _get_system_compute_capability():
7273

7374
# _C.set_log_callback(_log)
7475

76+
def rtc_set_cache_dir(dir):
77+
if not dir:
78+
_C.rtc_set_cache_dir('')
79+
return
80+
81+
if not os.path.isdir(dir):
82+
raise OSError(f"Missing RTC cache directory {dir}")
83+
84+
# check write permission
85+
try:
86+
with tempfile.TemporaryFile(dir=dir):
87+
pass
88+
except OSError as err:
89+
raise OSError(f"Invalid RTC cache directory {dir}") from err
90+
91+
# `str` to handle pathlib.Path objects
92+
_C.rtc_set_cache_dir(str(dir))
93+
7594
# Set up JIT runtime compilation
7695
_rtc_dir = os.path.join(os.path.dirname(__file__), "rtc")
7796

7897
_rtc_include_dir = os.path.join(_rtc_dir, "include")
7998
_C.rtc_set_include_dir(_rtc_include_dir)
8099

81100
_rtc_cache_dir = os.path.join(_rtc_dir, "cache")
82-
os.makedirs(_rtc_cache_dir, exist_ok=True)
83-
_C.rtc_set_cache_dir(_rtc_cache_dir)
101+
try:
102+
os.makedirs(_rtc_cache_dir, exist_ok=True)
103+
rtc_set_cache_dir(_rtc_cache_dir)
104+
except OSError:
105+
pass
84106

85107
def _torch_precision(tcnn_precision):
86108
if tcnn_precision == _C.Precision.Fp16:

0 commit comments

Comments
 (0)