Skip to content

Commit d06c2ad

Browse files
committed
Clarify native snippet examples
Review bots noted that two native snippet examples were less clear than they should be. The differentiability example used positional decorator arguments even though the surrounding prose names adj_snippet, and the shared-memory example launched with arr and out without defining them in the same block. Use keyword arguments for adj_snippet examples and make the shared-memory launch snippet define its inputs before launch. This keeps the docs easier to copy and less dependent on decorator argument order. Signed-off-by: Eric Shi <ershi@nvidia.com>
1 parent dfad38b commit d06c2ad

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

docs/user_guide/differentiability.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ an adjoint implementation for the native operation. Provide it with the
672672
adj_y[tid] += adj_out[tid];
673673
"""
674674

675-
@wp.func_native(snippet, adj_snippet)
675+
@wp.func_native(snippet=snippet, adj_snippet=adj_snippet)
676676
def axpy(
677677
x: wp.array[float],
678678
y: wp.array[float],

docs/user_guide/extending_warp.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ one result per block.
6363

6464
.. code-block:: python
6565
66+
import numpy as np
67+
import warp as wp
68+
6669
snippet = """
6770
__shared__ int sum[128];
6871
@@ -93,6 +96,8 @@ one result per block.
9396
reduce(arr, out, tid)
9497
9598
99+
arr = wp.array(np.arange(128, dtype=np.int32), dtype=wp.int32, device="cuda")
100+
out = wp.zeros(1, dtype=wp.int32, device="cuda")
96101
wp.launch(reduce_kernel, dim=128, inputs=[arr], outputs=[out], block_dim=128, device="cuda")
97102
98103
Returning Values
@@ -131,7 +136,7 @@ variables use the ``adj_`` prefix, and return-value adjoints are named
131136
"""
132137
133138
134-
@wp.func_native(snippet, adj_snippet)
139+
@wp.func_native(snippet=snippet, adj_snippet=adj_snippet)
135140
def axpy(
136141
x: wp.array[wp.float32],
137142
y: wp.array[wp.float32],

warp/_src/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ def reverse_block(arr: wp.array[int], out: wp.array[int], tid: int): ...
10801080
'''
10811081

10821082

1083-
@wp.func_native(snippet, adj_snippet)
1083+
@wp.func_native(snippet=snippet, adj_snippet=adj_snippet)
10841084
def axpy(
10851085
x: wp.array[wp.float32],
10861086
y: wp.array[wp.float32],

0 commit comments

Comments
 (0)