Skip to content

Commit 101b9eb

Browse files
Implemented auto opaque feature
1 parent 02b5351 commit 101b9eb

File tree

9 files changed

+938
-299
lines changed

9 files changed

+938
-299
lines changed

drjit/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,7 @@ def freeze(
24142414
max_cache_size: Optional[int] = None,
24152415
warn_recording_count: int = 10,
24162416
backend: Optional[JitBackend] = None,
2417+
auto_opaque: bool = True,
24172418
) -> Callable[[F], F]:
24182419
"""
24192420
Decorator to freeze a function for replaying kernels without re-tracing.
@@ -2460,11 +2461,6 @@ def freeze(
24602461
y = dr.gather(type(x), x, dr.width(x)//2)
24612462
```
24622463
2463-
Similarly, calculating the mean of a variable relies on the number of entries,
2464-
which will be baked into the frozen function. To avoid this, we suggest
2465-
supplying the number of entries as a Dr.Jit literal in the arguments to the
2466-
function.
2467-
24682464
Args:
24692465
f: The function to be frozen
24702466
@@ -2485,6 +2481,12 @@ def freeze(
24852481
frozen function, the backend used has to be specified using this argument.
24862482
It has to be the same backend that is used for variables inside the function,
24872483
otherwise recording will fail and variables may be leaked.
2484+
2485+
auto_opaque: (bool): If this flag is set true and only literal values
2486+
or their size changes between calls to the function, these variables
2487+
will be marked and made opaque. This reduces the memory usage, traversal
2488+
overhead, and can improved the performance of generated kernels.
2489+
If the flag is set to false, all input variables will be made opaque.
24882490
"""
24892491

24902492

@@ -2496,6 +2498,7 @@ def freeze(
24962498
max_cache_size: Optional[int] = None,
24972499
warn_recording_count: int = 10,
24982500
backend: Optional[JitBackend] = None,
2501+
auto_opaque: bool = True,
24992502
) -> F: ...
25002503

25012504

@@ -2506,6 +2509,7 @@ def freeze(
25062509
max_cache_size: Optional[int] = None,
25072510
warn_recording_count: int = 10,
25082511
backend: Optional[JitBackend] = None,
2512+
auto_opaque: bool = True,
25092513
) -> Union[F, Callable[[F2], F2]]:
25102514
max_cache_size = max_cache_size if max_cache_size is not None else -1
25112515
backend = backend if backend is not None else JitBackend.Invalid
@@ -2530,10 +2534,7 @@ def __init__(self, f) -> None:
25302534
closure = inspect.getclosurevars(f)
25312535
self.closure = (closure.nonlocals, closure.globals)
25322536
self.frozen = detail.FrozenFunction(
2533-
inner,
2534-
max_cache_size,
2535-
warn_recording_count,
2536-
backend,
2537+
inner, max_cache_size, warn_recording_count, backend, auto_opaque
25372538
)
25382539

25392540
def __call__(self, *args, **kwargs):

0 commit comments

Comments
 (0)