forked from NVIDIA/warp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
32 lines (21 loc) · 775 Bytes
/
test.py
File metadata and controls
32 lines (21 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import numpy as np
import warp as wp
wp.clear_kernel_cache()
# wp.init()
num_points = 1024
@wp.kernel
def length(points: wp.array(dtype=wp.vec3), lengths: wp.array(dtype=float)):
# thread index
tid = wp.tid()
# compute distance of each point from origin
lengths[tid] = wp.length(points[tid])
# allocate an array of 3d points
points = wp.array(np.random.rand(num_points, 3), dtype=wp.vec3)
lengths = wp.zeros(num_points, dtype=float)
# launch kernel
wp.launch(kernel=length, dim=len(points), inputs=[points, lengths])
np_lengths = np.linalg.norm(points.numpy(), 2, axis=-1)
assert np.allclose(
lengths.numpy(), np_lengths
), f"Numpy and Warp outputs do not match: {lengths.numpy()} vs {np_lengths}"
print("Sanity check completed successfully.")