warp-lang 1.6.2__py3-none-macosx_10_13_universal2.whl → 1.7.0__py3-none-macosx_10_13_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of warp-lang might be problematic. Click here for more details.

Files changed (179) hide show
  1. warp/__init__.py +7 -1
  2. warp/bin/libwarp-clang.dylib +0 -0
  3. warp/bin/libwarp.dylib +0 -0
  4. warp/build.py +410 -0
  5. warp/build_dll.py +6 -14
  6. warp/builtins.py +452 -362
  7. warp/codegen.py +179 -119
  8. warp/config.py +42 -6
  9. warp/context.py +490 -271
  10. warp/dlpack.py +8 -6
  11. warp/examples/assets/nonuniform.usd +0 -0
  12. warp/examples/assets/nvidia_logo.png +0 -0
  13. warp/examples/benchmarks/benchmark_tile_load_store.py +103 -0
  14. warp/examples/core/example_sample_mesh.py +300 -0
  15. warp/examples/fem/example_apic_fluid.py +1 -1
  16. warp/examples/fem/example_burgers.py +2 -2
  17. warp/examples/fem/example_deformed_geometry.py +1 -1
  18. warp/examples/fem/example_distortion_energy.py +1 -1
  19. warp/examples/fem/example_magnetostatics.py +6 -6
  20. warp/examples/fem/utils.py +9 -3
  21. warp/examples/interop/example_jax_callable.py +116 -0
  22. warp/examples/interop/example_jax_ffi_callback.py +132 -0
  23. warp/examples/interop/example_jax_kernel.py +205 -0
  24. warp/examples/optim/example_fluid_checkpoint.py +497 -0
  25. warp/examples/tile/example_tile_matmul.py +2 -4
  26. warp/fem/__init__.py +11 -1
  27. warp/fem/adaptivity.py +4 -4
  28. warp/fem/field/nodal_field.py +22 -68
  29. warp/fem/field/virtual.py +62 -23
  30. warp/fem/geometry/adaptive_nanogrid.py +9 -10
  31. warp/fem/geometry/closest_point.py +1 -1
  32. warp/fem/geometry/deformed_geometry.py +5 -2
  33. warp/fem/geometry/geometry.py +5 -0
  34. warp/fem/geometry/grid_2d.py +12 -12
  35. warp/fem/geometry/grid_3d.py +12 -15
  36. warp/fem/geometry/hexmesh.py +5 -7
  37. warp/fem/geometry/nanogrid.py +9 -11
  38. warp/fem/geometry/quadmesh.py +13 -13
  39. warp/fem/geometry/tetmesh.py +3 -4
  40. warp/fem/geometry/trimesh.py +3 -8
  41. warp/fem/integrate.py +262 -93
  42. warp/fem/linalg.py +5 -5
  43. warp/fem/quadrature/pic_quadrature.py +37 -22
  44. warp/fem/quadrature/quadrature.py +194 -25
  45. warp/fem/space/__init__.py +1 -1
  46. warp/fem/space/basis_function_space.py +4 -2
  47. warp/fem/space/basis_space.py +25 -18
  48. warp/fem/space/hexmesh_function_space.py +2 -2
  49. warp/fem/space/partition.py +6 -2
  50. warp/fem/space/quadmesh_function_space.py +8 -8
  51. warp/fem/space/shape/cube_shape_function.py +23 -23
  52. warp/fem/space/shape/square_shape_function.py +12 -12
  53. warp/fem/space/shape/triangle_shape_function.py +1 -1
  54. warp/fem/space/tetmesh_function_space.py +3 -3
  55. warp/fem/space/trimesh_function_space.py +2 -2
  56. warp/fem/utils.py +12 -6
  57. warp/jax.py +14 -1
  58. warp/jax_experimental/__init__.py +16 -0
  59. warp/{jax_experimental.py → jax_experimental/custom_call.py} +14 -27
  60. warp/jax_experimental/ffi.py +698 -0
  61. warp/jax_experimental/xla_ffi.py +602 -0
  62. warp/math.py +89 -0
  63. warp/native/array.h +13 -0
  64. warp/native/builtin.h +29 -3
  65. warp/native/bvh.cpp +3 -1
  66. warp/native/bvh.cu +42 -14
  67. warp/native/bvh.h +2 -1
  68. warp/native/clang/clang.cpp +30 -3
  69. warp/native/cuda_util.cpp +14 -0
  70. warp/native/cuda_util.h +2 -0
  71. warp/native/exports.h +68 -63
  72. warp/native/intersect.h +26 -26
  73. warp/native/intersect_adj.h +33 -33
  74. warp/native/marching.cu +1 -1
  75. warp/native/mat.h +513 -9
  76. warp/native/mesh.h +10 -10
  77. warp/native/quat.h +99 -11
  78. warp/native/rand.h +6 -0
  79. warp/native/sort.cpp +122 -59
  80. warp/native/sort.cu +152 -15
  81. warp/native/sort.h +8 -1
  82. warp/native/sparse.cpp +43 -22
  83. warp/native/sparse.cu +52 -17
  84. warp/native/svd.h +116 -0
  85. warp/native/tile.h +301 -105
  86. warp/native/tile_reduce.h +46 -3
  87. warp/native/vec.h +68 -7
  88. warp/native/volume.cpp +85 -113
  89. warp/native/volume_builder.cu +25 -10
  90. warp/native/volume_builder.h +6 -0
  91. warp/native/warp.cpp +5 -6
  92. warp/native/warp.cu +99 -10
  93. warp/native/warp.h +19 -10
  94. warp/optim/linear.py +10 -10
  95. warp/sim/articulation.py +4 -4
  96. warp/sim/collide.py +21 -10
  97. warp/sim/import_mjcf.py +449 -155
  98. warp/sim/import_urdf.py +32 -12
  99. warp/sim/integrator_euler.py +5 -5
  100. warp/sim/integrator_featherstone.py +3 -10
  101. warp/sim/integrator_vbd.py +207 -2
  102. warp/sim/integrator_xpbd.py +5 -5
  103. warp/sim/model.py +42 -13
  104. warp/sim/utils.py +2 -2
  105. warp/sparse.py +642 -555
  106. warp/stubs.py +216 -19
  107. warp/tests/__main__.py +0 -15
  108. warp/tests/cuda/__init__.py +0 -0
  109. warp/tests/{test_mempool.py → cuda/test_mempool.py} +39 -0
  110. warp/tests/{test_streams.py → cuda/test_streams.py} +71 -0
  111. warp/tests/geometry/__init__.py +0 -0
  112. warp/tests/{test_mesh_query_point.py → geometry/test_mesh_query_point.py} +66 -63
  113. warp/tests/{test_mesh_query_ray.py → geometry/test_mesh_query_ray.py} +1 -1
  114. warp/tests/{test_volume.py → geometry/test_volume.py} +41 -6
  115. warp/tests/interop/__init__.py +0 -0
  116. warp/tests/{test_dlpack.py → interop/test_dlpack.py} +28 -5
  117. warp/tests/sim/__init__.py +0 -0
  118. warp/tests/{disabled_kinematics.py → sim/disabled_kinematics.py} +9 -10
  119. warp/tests/{test_collision.py → sim/test_collision.py} +2 -2
  120. warp/tests/{test_model.py → sim/test_model.py} +40 -0
  121. warp/tests/{test_sim_kinematics.py → sim/test_sim_kinematics.py} +2 -1
  122. warp/tests/sim/test_vbd.py +597 -0
  123. warp/tests/test_bool.py +1 -1
  124. warp/tests/test_examples.py +28 -36
  125. warp/tests/test_fem.py +23 -4
  126. warp/tests/test_linear_solvers.py +0 -11
  127. warp/tests/test_mat.py +233 -79
  128. warp/tests/test_mat_scalar_ops.py +4 -4
  129. warp/tests/test_overwrite.py +0 -60
  130. warp/tests/test_quat.py +67 -46
  131. warp/tests/test_rand.py +44 -37
  132. warp/tests/test_sparse.py +47 -6
  133. warp/tests/test_spatial.py +75 -0
  134. warp/tests/test_static.py +1 -1
  135. warp/tests/test_utils.py +84 -4
  136. warp/tests/test_vec.py +46 -34
  137. warp/tests/tile/__init__.py +0 -0
  138. warp/tests/{test_tile.py → tile/test_tile.py} +136 -51
  139. warp/tests/{test_tile_load.py → tile/test_tile_load.py} +1 -1
  140. warp/tests/{test_tile_mathdx.py → tile/test_tile_mathdx.py} +9 -6
  141. warp/tests/{test_tile_mlp.py → tile/test_tile_mlp.py} +25 -14
  142. warp/tests/{test_tile_reduce.py → tile/test_tile_reduce.py} +60 -1
  143. warp/tests/{test_tile_view.py → tile/test_tile_view.py} +1 -1
  144. warp/tests/unittest_serial.py +1 -0
  145. warp/tests/unittest_suites.py +45 -59
  146. warp/tests/unittest_utils.py +2 -1
  147. warp/thirdparty/unittest_parallel.py +3 -1
  148. warp/types.py +110 -658
  149. warp/utils.py +137 -72
  150. {warp_lang-1.6.2.dist-info → warp_lang-1.7.0.dist-info}/METADATA +29 -7
  151. {warp_lang-1.6.2.dist-info → warp_lang-1.7.0.dist-info}/RECORD +172 -162
  152. {warp_lang-1.6.2.dist-info → warp_lang-1.7.0.dist-info}/WHEEL +1 -1
  153. warp/examples/optim/example_walker.py +0 -317
  154. warp/native/cutlass_gemm.cpp +0 -43
  155. warp/native/cutlass_gemm.cu +0 -382
  156. warp/tests/test_matmul.py +0 -511
  157. warp/tests/test_matmul_lite.py +0 -411
  158. warp/tests/test_vbd.py +0 -386
  159. warp/tests/unused_test_misc.py +0 -77
  160. /warp/tests/{test_async.py → cuda/test_async.py} +0 -0
  161. /warp/tests/{test_ipc.py → cuda/test_ipc.py} +0 -0
  162. /warp/tests/{test_multigpu.py → cuda/test_multigpu.py} +0 -0
  163. /warp/tests/{test_peer.py → cuda/test_peer.py} +0 -0
  164. /warp/tests/{test_pinned.py → cuda/test_pinned.py} +0 -0
  165. /warp/tests/{test_bvh.py → geometry/test_bvh.py} +0 -0
  166. /warp/tests/{test_hash_grid.py → geometry/test_hash_grid.py} +0 -0
  167. /warp/tests/{test_marching_cubes.py → geometry/test_marching_cubes.py} +0 -0
  168. /warp/tests/{test_mesh.py → geometry/test_mesh.py} +0 -0
  169. /warp/tests/{test_mesh_query_aabb.py → geometry/test_mesh_query_aabb.py} +0 -0
  170. /warp/tests/{test_volume_write.py → geometry/test_volume_write.py} +0 -0
  171. /warp/tests/{test_jax.py → interop/test_jax.py} +0 -0
  172. /warp/tests/{test_paddle.py → interop/test_paddle.py} +0 -0
  173. /warp/tests/{test_torch.py → interop/test_torch.py} +0 -0
  174. /warp/tests/{flaky_test_sim_grad.py → sim/flaky_test_sim_grad.py} +0 -0
  175. /warp/tests/{test_coloring.py → sim/test_coloring.py} +0 -0
  176. /warp/tests/{test_sim_grad_bounce_linear.py → sim/test_sim_grad_bounce_linear.py} +0 -0
  177. /warp/tests/{test_tile_shared_memory.py → tile/test_tile_shared_memory.py} +0 -0
  178. {warp_lang-1.6.2.dist-info → warp_lang-1.7.0.dist-info/licenses}/LICENSE.md +0 -0
  179. {warp_lang-1.6.2.dist-info → warp_lang-1.7.0.dist-info}/top_level.txt +0 -0
warp/native/tile_reduce.h CHANGED
@@ -24,6 +24,8 @@
24
24
  namespace wp
25
25
  {
26
26
 
27
+ #if defined(__CUDA_ARCH__)
28
+
27
29
  template <typename T>
28
30
  inline CUDA_CALLABLE T warp_shuffle_down(T val, int offset, int mask)
29
31
  {
@@ -157,7 +159,39 @@ auto tile_reduce_impl(Op f, Tile& t)
157
159
  return output;
158
160
  }
159
161
 
160
- void adj_tile_reduce_impl()
162
+ #else
163
+
164
+ // CPU implementation
165
+
166
+ template <typename Tile, typename Op>
167
+ auto tile_reduce_impl(Op f, Tile& t)
168
+ {
169
+ using T = typename Tile::Type;
170
+
171
+ auto input = t.copy_to_register();
172
+ auto output = tile_register_t<T, tile_layout_register_t<tile_shape_t<1>>>();
173
+
174
+ using Layout = typename decltype(input)::Layout;
175
+
176
+ T sum = input.data[0];
177
+
178
+ WP_PRAGMA_UNROLL
179
+ for (int i=1; i < Layout::NumRegs; ++i)
180
+ {
181
+ int linear = Layout::linear_from_register(i);
182
+ if (!Layout::valid(linear))
183
+ break;
184
+
185
+ sum = f(sum, input.data[i]);
186
+ }
187
+
188
+ output.data[0] = sum;
189
+ return output;
190
+ }
191
+
192
+ #endif // !defined(__CUDA_ARCH__)
193
+
194
+ inline void adj_tile_reduce_impl()
161
195
  {
162
196
  // todo: general purpose reduction gradients not implemented
163
197
  }
@@ -180,16 +214,25 @@ void adj_tile_sum(Tile& t, Tile& adj_t, AdjTile& adj_ret)
180
214
  {
181
215
  using T = typename Tile::Type;
182
216
 
217
+ #if !defined(__CUDA_ARCH__)
218
+
219
+ for (int i=0; i < Tile::Layout::Size; ++i)
220
+ {
221
+ adj_t(i) += adj_ret.data[0];
222
+
223
+ }
224
+ #else
183
225
  // broadcast incoming adjoint to block
184
226
  WP_TILE_SHARED T scratch;
185
- if (threadIdx.x == 0)
227
+ if (WP_TILE_THREAD_IDX == 0)
186
228
  scratch = adj_ret.data[0];
187
229
 
188
230
  WP_TILE_SYNC();
189
231
 
190
232
  // broadcast scalar across input dimensions (note zero strides)
191
- auto adj_ret_reg = tile_shared_t<T, tile_layout_strided_t<typename Tile::Layout::Shape, tile_stride_t<0, 0>>>(&scratch, NULL).copy_to_register();
233
+ auto adj_ret_reg = tile_shared_t<T, tile_layout_strided_t<typename Tile::Layout::Shape, tile_stride_t<0, 0>>, false>(&scratch, nullptr).copy_to_register();
192
234
  adj_t.grad_add(adj_ret_reg);
235
+ #endif
193
236
  }
194
237
 
195
238
  template <typename Tile>
warp/native/vec.h CHANGED
@@ -506,37 +506,98 @@ inline CUDA_CALLABLE void adj_indexref(vec_t<Length, Type>* v, int idx,
506
506
 
507
507
 
508
508
  template<unsigned Length, typename Type>
509
- inline CUDA_CALLABLE void augassign_add(vec_t<Length, Type>& v, int idx, Type value)
509
+ inline CUDA_CALLABLE void add_inplace(vec_t<Length, Type>& v, int idx, Type value)
510
510
  {
511
+ #ifndef NDEBUG
512
+ if (idx < 0 || idx >= Length)
513
+ {
514
+ printf("vec index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
515
+ assert(0);
516
+ }
517
+ #endif
518
+
511
519
  v[idx] += value;
512
520
  }
513
521
 
514
522
 
515
523
  template<unsigned Length, typename Type>
516
- inline CUDA_CALLABLE void adj_augassign_add(vec_t<Length, Type>& v, int idx, Type value,
524
+ inline CUDA_CALLABLE void adj_add_inplace(vec_t<Length, Type>& v, int idx, Type value,
517
525
  vec_t<Length, Type>& adj_v, int adj_idx, Type& adj_value)
518
526
  {
527
+ #ifndef NDEBUG
528
+ if (idx < 0 || idx >= Length)
529
+ {
530
+ printf("vec index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
531
+ assert(0);
532
+ }
533
+ #endif
534
+
519
535
  adj_value += adj_v[idx];
520
536
  }
521
537
 
522
538
 
523
539
  template<unsigned Length, typename Type>
524
- inline CUDA_CALLABLE void augassign_sub(vec_t<Length, Type>& v, int idx, Type value)
540
+ inline CUDA_CALLABLE void sub_inplace(vec_t<Length, Type>& v, int idx, Type value)
525
541
  {
542
+ #ifndef NDEBUG
543
+ if (idx < 0 || idx >= Length)
544
+ {
545
+ printf("vec index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
546
+ assert(0);
547
+ }
548
+ #endif
549
+
526
550
  v[idx] -= value;
527
551
  }
528
552
 
529
553
 
530
554
  template<unsigned Length, typename Type>
531
- inline CUDA_CALLABLE void adj_augassign_sub(vec_t<Length, Type>& v, int idx, Type value,
555
+ inline CUDA_CALLABLE void adj_sub_inplace(vec_t<Length, Type>& v, int idx, Type value,
532
556
  vec_t<Length, Type>& adj_v, int adj_idx, Type& adj_value)
533
557
  {
558
+ #ifndef NDEBUG
559
+ if (idx < 0 || idx >= Length)
560
+ {
561
+ printf("vec index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
562
+ assert(0);
563
+ }
564
+ #endif
565
+
534
566
  adj_value -= adj_v[idx];
535
567
  }
536
568
 
537
569
 
538
570
  template<unsigned Length, typename Type>
539
- inline CUDA_CALLABLE vec_t<Length, Type> assign(vec_t<Length, Type>& v, int idx, Type value)
571
+ inline CUDA_CALLABLE void assign_inplace(vec_t<Length, Type>& v, int idx, Type value)
572
+ {
573
+ #ifndef NDEBUG
574
+ if (idx < 0 || idx >= Length)
575
+ {
576
+ printf("vec index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
577
+ assert(0);
578
+ }
579
+ #endif
580
+
581
+ v[idx] = value;
582
+ }
583
+
584
+ template<unsigned Length, typename Type>
585
+ inline CUDA_CALLABLE void adj_assign_inplace(vec_t<Length, Type>& v, int idx, Type value, vec_t<Length, Type>& adj_v, int& adj_idx, Type& adj_value)
586
+ {
587
+ #ifndef NDEBUG
588
+ if (idx < 0 || idx >= Length)
589
+ {
590
+ printf("vec index %d out of bounds at %s %d\n", idx, __FILE__, __LINE__);
591
+ assert(0);
592
+ }
593
+ #endif
594
+
595
+ adj_value += adj_v[idx];
596
+ }
597
+
598
+
599
+ template<unsigned Length, typename Type>
600
+ inline CUDA_CALLABLE vec_t<Length, Type> assign_copy(vec_t<Length, Type>& v, int idx, Type value)
540
601
  {
541
602
  #ifndef NDEBUG
542
603
  if (idx < 0 || idx >= Length)
@@ -552,7 +613,7 @@ inline CUDA_CALLABLE vec_t<Length, Type> assign(vec_t<Length, Type>& v, int idx,
552
613
  }
553
614
 
554
615
  template<unsigned Length, typename Type>
555
- inline CUDA_CALLABLE void adj_assign(vec_t<Length, Type>& v, int idx, Type value, vec_t<Length, Type>& adj_v, int& adj_idx, Type& adj_value, const vec_t<Length, Type>& adj_ret)
616
+ inline CUDA_CALLABLE void adj_assign_copy(vec_t<Length, Type>& v, int idx, Type value, vec_t<Length, Type>& adj_v, int& adj_idx, Type& adj_value, const vec_t<Length, Type>& adj_ret)
556
617
  {
557
618
  #ifndef NDEBUG
558
619
  if (idx < 0 || idx >= Length)
@@ -774,7 +835,7 @@ inline CUDA_CALLABLE vec_t<Length,Type> sign(vec_t<Length,Type> v)
774
835
  template<unsigned Length, typename Type>
775
836
  inline CUDA_CALLABLE void expect_near(const vec_t<Length, Type>& actual, const vec_t<Length, Type>& expected, const Type& tolerance)
776
837
  {
777
- const Type diff(0);
838
+ Type diff(0);
778
839
  for(size_t i=0; i<Length; ++i)
779
840
  {
780
841
  diff = max(diff,abs(actual[i] - expected[i]));
warp/native/volume.cpp CHANGED
@@ -30,7 +30,7 @@ namespace
30
30
  struct VolumeDesc
31
31
  {
32
32
  // NanoVDB buffer either in device or host memory
33
- void *buffer;
33
+ void* buffer;
34
34
  uint64_t size_in_bytes;
35
35
  bool owner; // whether the buffer should be deallocated when the volume is destroyed
36
36
 
@@ -38,23 +38,23 @@ struct VolumeDesc
38
38
  pnanovdb_tree_t tree_data;
39
39
 
40
40
  // Host-accessible version of the blind metadata (copy if GPU, alias if CPU)
41
- pnanovdb_gridblindmetadata_t *blind_metadata;
41
+ pnanovdb_gridblindmetadata_t* blind_metadata;
42
42
 
43
43
  // CUDA context for this volume (NULL if CPU)
44
- void *context;
44
+ void* context;
45
45
 
46
- pnanovdb_buf_t as_pnano() const { return pnanovdb_make_buf(static_cast<uint32_t *>(buffer), size_in_bytes); }
46
+ pnanovdb_buf_t as_pnano() const { return pnanovdb_make_buf(static_cast<uint32_t*>(buffer), size_in_bytes); }
47
47
  };
48
48
 
49
49
  // Host-side volume descriptors. Maps each CPU/GPU volume buffer address (id) to a CPU desc
50
50
  std::map<uint64_t, VolumeDesc> g_volume_descriptors;
51
51
 
52
- bool volume_get_descriptor(uint64_t id, const VolumeDesc *&volumeDesc)
52
+ bool volume_get_descriptor(uint64_t id, const VolumeDesc*& volumeDesc)
53
53
  {
54
54
  if (id == 0)
55
55
  return false;
56
56
 
57
- const auto &iter = g_volume_descriptors.find(id);
57
+ const auto& iter = g_volume_descriptors.find(id);
58
58
  if (iter == g_volume_descriptors.end())
59
59
  return false;
60
60
  else
@@ -62,21 +62,21 @@ bool volume_get_descriptor(uint64_t id, const VolumeDesc *&volumeDesc)
62
62
  return true;
63
63
  }
64
64
 
65
- bool volume_exists(const void *id)
65
+ bool volume_exists(const void* id)
66
66
  {
67
- const VolumeDesc *volume;
67
+ const VolumeDesc* volume;
68
68
  return volume_get_descriptor((uint64_t)id, volume);
69
69
  }
70
70
 
71
- void volume_add_descriptor(uint64_t id, VolumeDesc &&volumeDesc) { g_volume_descriptors[id] = std::move(volumeDesc); }
71
+ void volume_add_descriptor(uint64_t id, VolumeDesc&& volumeDesc) { g_volume_descriptors[id] = std::move(volumeDesc); }
72
72
 
73
73
  void volume_rem_descriptor(uint64_t id) { g_volume_descriptors.erase(id); }
74
74
 
75
- void volume_set_map(nanovdb::Map &map, const float transform[9], const float translation[3])
75
+ void volume_set_map(nanovdb::Map& map, const float transform[9], const float translation[3])
76
76
  {
77
77
  // Need to transpose as Map::set is transposing again
78
- const mat_t<3, 3, double> transpose(transform[0], transform[3], transform[6], transform[1], transform[4], transform[7],
79
- transform[2], transform[5], transform[8]);
78
+ const mat_t<3, 3, double> transpose(transform[0], transform[3], transform[6], transform[1], transform[4],
79
+ transform[7], transform[2], transform[5], transform[8]);
80
80
  const mat_t<3, 3, double> inv = inverse(transpose);
81
81
 
82
82
  map.set(transpose.data, inv.data, translation);
@@ -85,7 +85,7 @@ void volume_set_map(nanovdb::Map &map, const float transform[9], const float tra
85
85
  } // anonymous namespace
86
86
 
87
87
  // NB: buf must be a host pointer
88
- uint64_t volume_create_host(void *buf, uint64_t size, bool copy, bool owner)
88
+ uint64_t volume_create_host(void* buf, uint64_t size, bool copy, bool owner)
89
89
  {
90
90
  if (size > 0 && size < sizeof(pnanovdb_grid_t) + sizeof(pnanovdb_tree_t))
91
91
  return 0; // This cannot be a valid NanoVDB grid with data
@@ -100,7 +100,7 @@ uint64_t volume_create_host(void *buf, uint64_t size, bool copy, bool owner)
100
100
  volume.context = NULL;
101
101
 
102
102
  memcpy_h2h(&volume.grid_data, buf, sizeof(pnanovdb_grid_t));
103
- memcpy_h2h(&volume.tree_data, (pnanovdb_grid_t *)buf + 1, sizeof(pnanovdb_tree_t));
103
+ memcpy_h2h(&volume.tree_data, (pnanovdb_grid_t*)buf + 1, sizeof(pnanovdb_tree_t));
104
104
 
105
105
  if (volume.grid_data.magic != PNANOVDB_MAGIC_NUMBER && volume.grid_data.magic != PNANOVDB_MAGIC_GRID)
106
106
  return 0;
@@ -125,8 +125,8 @@ uint64_t volume_create_host(void *buf, uint64_t size, bool copy, bool owner)
125
125
  }
126
126
 
127
127
  // Alias blind metadata
128
- volume.blind_metadata = reinterpret_cast<pnanovdb_gridblindmetadata_t *>(static_cast<uint8_t *>(volume.buffer) +
129
- volume.grid_data.blind_metadata_offset);
128
+ volume.blind_metadata = reinterpret_cast<pnanovdb_gridblindmetadata_t*>(static_cast<uint8_t*>(volume.buffer) +
129
+ volume.grid_data.blind_metadata_offset);
130
130
 
131
131
  uint64_t id = (uint64_t)volume.buffer;
132
132
 
@@ -136,7 +136,7 @@ uint64_t volume_create_host(void *buf, uint64_t size, bool copy, bool owner)
136
136
  }
137
137
 
138
138
  // NB: buf must be a pointer on the same device
139
- uint64_t volume_create_device(void *context, void *buf, uint64_t size, bool copy, bool owner)
139
+ uint64_t volume_create_device(void* context, void* buf, uint64_t size, bool copy, bool owner)
140
140
  {
141
141
  if (size > 0 && size < sizeof(pnanovdb_grid_t) + sizeof(pnanovdb_tree_t))
142
142
  return 0; // This cannot be a valid NanoVDB grid with data
@@ -153,7 +153,7 @@ uint64_t volume_create_device(void *context, void *buf, uint64_t size, bool copy
153
153
  volume.context = context ? context : cuda_context_get_current();
154
154
 
155
155
  memcpy_d2h(WP_CURRENT_CONTEXT, &volume.grid_data, buf, sizeof(pnanovdb_grid_t));
156
- memcpy_d2h(WP_CURRENT_CONTEXT, &volume.tree_data, (pnanovdb_grid_t *)buf + 1, sizeof(pnanovdb_tree_t));
156
+ memcpy_d2h(WP_CURRENT_CONTEXT, &volume.tree_data, (pnanovdb_grid_t*)buf + 1, sizeof(pnanovdb_tree_t));
157
157
  // no sync needed since the above copies are to pageable memory
158
158
 
159
159
  if (volume.grid_data.magic != PNANOVDB_MAGIC_NUMBER && volume.grid_data.magic != PNANOVDB_MAGIC_GRID)
@@ -180,9 +180,9 @@ uint64_t volume_create_device(void *context, void *buf, uint64_t size, bool copy
180
180
 
181
181
  // Make blind metadata accessible on host
182
182
  const uint64_t blindmetadata_size = volume.grid_data.blind_metadata_count * sizeof(pnanovdb_gridblindmetadata_t);
183
- volume.blind_metadata = static_cast<pnanovdb_gridblindmetadata_t *>(alloc_pinned(blindmetadata_size));
183
+ volume.blind_metadata = static_cast<pnanovdb_gridblindmetadata_t*>(alloc_pinned(blindmetadata_size));
184
184
  memcpy_d2h(WP_CURRENT_CONTEXT, volume.blind_metadata,
185
- static_cast<uint8_t *>(volume.buffer) + volume.grid_data.blind_metadata_offset, blindmetadata_size);
185
+ static_cast<uint8_t*>(volume.buffer) + volume.grid_data.blind_metadata_offset, blindmetadata_size);
186
186
 
187
187
  uint64_t id = (uint64_t)volume.buffer;
188
188
  volume_add_descriptor(id, std::move(volume));
@@ -190,12 +190,12 @@ uint64_t volume_create_device(void *context, void *buf, uint64_t size, bool copy
190
190
  return id;
191
191
  }
192
192
 
193
- void volume_get_buffer_info(uint64_t id, void **buf, uint64_t *size)
193
+ void volume_get_buffer_info(uint64_t id, void** buf, uint64_t* size)
194
194
  {
195
195
  *buf = 0;
196
196
  *size = 0;
197
197
 
198
- const VolumeDesc *volume;
198
+ const VolumeDesc* volume;
199
199
  if (volume_get_descriptor(id, volume))
200
200
  {
201
201
  *buf = volume->buffer;
@@ -203,11 +203,11 @@ void volume_get_buffer_info(uint64_t id, void **buf, uint64_t *size)
203
203
  }
204
204
  }
205
205
 
206
- void volume_get_voxel_size(uint64_t id, float *dx, float *dy, float *dz)
206
+ void volume_get_voxel_size(uint64_t id, float* dx, float* dy, float* dz)
207
207
  {
208
208
  *dx = *dx = *dz = 0.0f;
209
209
 
210
- const VolumeDesc *volume;
210
+ const VolumeDesc* volume;
211
211
  if (volume_get_descriptor(id, volume))
212
212
  {
213
213
  *dx = (float)volume->grid_data.voxel_size[0];
@@ -216,12 +216,12 @@ void volume_get_voxel_size(uint64_t id, float *dx, float *dy, float *dz)
216
216
  }
217
217
  }
218
218
 
219
- void volume_get_tile_and_voxel_count(uint64_t id, uint32_t &tile_count, uint64_t &voxel_count)
219
+ void volume_get_tile_and_voxel_count(uint64_t id, uint32_t& tile_count, uint64_t& voxel_count)
220
220
  {
221
221
  tile_count = 0;
222
222
  voxel_count = 0;
223
223
 
224
- const VolumeDesc *volume;
224
+ const VolumeDesc* volume;
225
225
  if (volume_get_descriptor(id, volume))
226
226
  {
227
227
  tile_count = volume->tree_data.node_count_leaf;
@@ -242,13 +242,13 @@ void volume_get_tile_and_voxel_count(uint64_t id, uint32_t &tile_count, uint64_t
242
242
  }
243
243
  }
244
244
 
245
- const char *volume_get_grid_info(uint64_t id, uint64_t *grid_size, uint32_t *grid_index, uint32_t *grid_count,
245
+ const char* volume_get_grid_info(uint64_t id, uint64_t* grid_size, uint32_t* grid_index, uint32_t* grid_count,
246
246
  float translation[3], float transform[9], char type_str[16])
247
247
  {
248
- const VolumeDesc *volume;
248
+ const VolumeDesc* volume;
249
249
  if (volume_get_descriptor(id, volume))
250
250
  {
251
- const pnanovdb_grid_t &grid_data = volume->grid_data;
251
+ const pnanovdb_grid_t& grid_data = volume->grid_data;
252
252
  *grid_count = grid_data.grid_count;
253
253
  *grid_index = grid_data.grid_index;
254
254
  *grid_size = grid_data.grid_size;
@@ -257,7 +257,7 @@ const char *volume_get_grid_info(uint64_t id, uint64_t *grid_size, uint32_t *gri
257
257
  memcpy(transform, grid_data.map.matf, sizeof(grid_data.map.matf));
258
258
 
259
259
  nanovdb::toStr(type_str, static_cast<nanovdb::GridType>(grid_data.grid_type));
260
- return (const char *)grid_data.grid_name;
260
+ return (const char*)grid_data.grid_name;
261
261
  }
262
262
 
263
263
  *grid_size = 0;
@@ -270,7 +270,7 @@ const char *volume_get_grid_info(uint64_t id, uint64_t *grid_size, uint32_t *gri
270
270
 
271
271
  uint32_t volume_get_blind_data_count(uint64_t id)
272
272
  {
273
- const VolumeDesc *volume;
273
+ const VolumeDesc* volume;
274
274
  if (volume_get_descriptor(id, volume))
275
275
  {
276
276
  return volume->grid_data.blind_metadata_count;
@@ -278,20 +278,20 @@ uint32_t volume_get_blind_data_count(uint64_t id)
278
278
  return 0;
279
279
  }
280
280
 
281
- const char *volume_get_blind_data_info(uint64_t id, uint32_t data_index, void **buf, uint64_t *value_count,
282
- uint32_t *value_size, char type_str[16])
281
+ const char* volume_get_blind_data_info(uint64_t id, uint32_t data_index, void** buf, uint64_t* value_count,
282
+ uint32_t* value_size, char type_str[16])
283
283
  {
284
- const VolumeDesc *volume;
284
+ const VolumeDesc* volume;
285
285
  if (volume_get_descriptor(id, volume) && data_index < volume->grid_data.blind_metadata_count)
286
286
  {
287
- const pnanovdb_gridblindmetadata_t &metadata = volume->blind_metadata[data_index];
287
+ const pnanovdb_gridblindmetadata_t& metadata = volume->blind_metadata[data_index];
288
288
  *value_count = metadata.value_count;
289
289
  *value_size = metadata.value_size;
290
290
 
291
291
  nanovdb::toStr(type_str, static_cast<nanovdb::GridType>(metadata.data_type));
292
- *buf = static_cast<uint8_t *>(volume->buffer) + volume->grid_data.blind_metadata_offset +
292
+ *buf = static_cast<uint8_t*>(volume->buffer) + volume->grid_data.blind_metadata_offset +
293
293
  data_index * sizeof(pnanovdb_gridblindmetadata_t) + metadata.data_offset;
294
- return (const char *)metadata.name;
294
+ return (const char*)metadata.name;
295
295
  }
296
296
  *buf = nullptr;
297
297
  *value_count = 0;
@@ -300,16 +300,16 @@ const char *volume_get_blind_data_info(uint64_t id, uint32_t data_index, void **
300
300
  return nullptr;
301
301
  }
302
302
 
303
- void volume_get_tiles_host(uint64_t id, void *buf)
303
+ void volume_get_tiles_host(uint64_t id, void* buf)
304
304
  {
305
305
  static constexpr uint32_t MASK = (1u << 3u) - 1u; // mask for bit operations
306
306
 
307
- const VolumeDesc *volume;
307
+ const VolumeDesc* volume;
308
308
  if (volume_get_descriptor(id, volume))
309
309
  {
310
310
  const uint32_t leaf_count = volume->tree_data.node_count_leaf;
311
311
 
312
- pnanovdb_coord_t *leaf_coords = static_cast<pnanovdb_coord_t *>(buf);
312
+ pnanovdb_coord_t* leaf_coords = static_cast<pnanovdb_coord_t*>(buf);
313
313
 
314
314
  const uint64_t first_leaf =
315
315
  (uint64_t)volume->buffer + sizeof(pnanovdb_grid_t) + volume->tree_data.node_offset_leaf;
@@ -325,16 +325,16 @@ void volume_get_tiles_host(uint64_t id, void *buf)
325
325
  }
326
326
  }
327
327
 
328
- void volume_get_voxels_host(uint64_t id, void *buf)
328
+ void volume_get_voxels_host(uint64_t id, void* buf)
329
329
  {
330
- const VolumeDesc *volume;
330
+ const VolumeDesc* volume;
331
331
  if (volume_get_descriptor(id, volume))
332
332
  {
333
333
  uint32_t leaf_count;
334
334
  uint64_t voxel_count;
335
335
  volume_get_tile_and_voxel_count(id, leaf_count, voxel_count);
336
336
 
337
- pnanovdb_coord_t *voxel_coords = static_cast<pnanovdb_coord_t *>(buf);
337
+ pnanovdb_coord_t* voxel_coords = static_cast<pnanovdb_coord_t*>(buf);
338
338
 
339
339
  const pnanovdb_buf_t pnano_buf = volume->as_pnano();
340
340
  for (uint32_t i = 0; i < leaf_count; ++i)
@@ -363,7 +363,7 @@ void volume_get_voxels_host(uint64_t id, void *buf)
363
363
 
364
364
  void volume_destroy_host(uint64_t id)
365
365
  {
366
- const VolumeDesc *volume;
366
+ const VolumeDesc* volume;
367
367
  if (volume_get_descriptor(id, volume))
368
368
  {
369
369
  if (volume->owner)
@@ -376,7 +376,7 @@ void volume_destroy_host(uint64_t id)
376
376
 
377
377
  void volume_destroy_device(uint64_t id)
378
378
  {
379
- const VolumeDesc *volume;
379
+ const VolumeDesc* volume;
380
380
  if (volume_get_descriptor(id, volume))
381
381
  {
382
382
  ContextGuard guard(volume->context);
@@ -391,52 +391,35 @@ void volume_destroy_device(uint64_t id)
391
391
 
392
392
  #if WP_ENABLE_CUDA
393
393
 
394
- uint64_t volume_f_from_tiles_device(void *context, void *points, int num_points, float transform[9],
395
- float translation[3], bool points_in_world_space, float bg_value)
394
+ uint64_t volume_from_tiles_device(void* context, void* points, int num_points, float transform[9], float translation[3],
395
+ bool points_in_world_space, const void* value_ptr, uint32_t value_size,
396
+ const char* value_type)
396
397
  {
397
- nanovdb::FloatGrid *grid;
398
- size_t gridSize;
399
- BuildGridParams<float> params;
400
- params.background_value = bg_value;
401
- volume_set_map(params.map, transform, translation);
402
-
403
- build_grid_from_points(grid, gridSize, points, num_points, points_in_world_space, params);
404
-
405
- return volume_create_device(context, grid, gridSize, false, true);
406
- }
407
-
408
- uint64_t volume_v_from_tiles_device(void *context, void *points, int num_points, float transform[9],
409
- float translation[3], bool points_in_world_space, float bg_value[3])
410
- {
411
- nanovdb::Vec3fGrid *grid;
412
- size_t gridSize;
413
- BuildGridParams<nanovdb::Vec3f> params;
414
- params.background_value = nanovdb::Vec3f{bg_value[0], bg_value[1], bg_value[2]};
415
- volume_set_map(params.map, transform, translation);
416
-
417
- build_grid_from_points(grid, gridSize, points, num_points, points_in_world_space, params);
418
-
419
- return volume_create_device(context, grid, gridSize, false, true);
420
- }
421
-
422
- uint64_t volume_i_from_tiles_device(void *context, void *points, int num_points, float transform[9],
423
- float translation[3], bool points_in_world_space, int bg_value)
424
- {
425
- nanovdb::Int32Grid *grid;
426
- size_t gridSize;
427
- BuildGridParams<int32_t> params;
428
- params.background_value = (int32_t)(bg_value);
429
- volume_set_map(params.map, transform, translation);
398
+ char gridTypeStr[12];
399
+
400
+ #define EXPAND_BUILDER_TYPE(type) \
401
+ nanovdb::toStr(gridTypeStr, nanovdb::toGridType<type>()); \
402
+ if (strncmp(gridTypeStr, value_type, sizeof(gridTypeStr)) == 0) \
403
+ { \
404
+ BuildGridParams<type> params; \
405
+ memcpy(&params.background_value, value_ptr, value_size); \
406
+ volume_set_map(params.map, transform, translation); \
407
+ size_t gridSize; \
408
+ nanovdb::Grid<nanovdb::NanoTree<type>>* grid; \
409
+ build_grid_from_points(grid, gridSize, points, num_points, points_in_world_space, params); \
410
+ return volume_create_device(context, grid, gridSize, false, true); \
411
+ }
430
412
 
431
- build_grid_from_points(grid, gridSize, points, num_points, points_in_world_space, params);
413
+ WP_VOLUME_BUILDER_INSTANTIATE_TYPES
414
+ #undef EXPAND_BUILDER_TYPE
432
415
 
433
- return volume_create_device(context, grid, gridSize, false, true);
416
+ return 0;
434
417
  }
435
418
 
436
- uint64_t volume_index_from_tiles_device(void *context, void *points, int num_points, float transform[9],
419
+ uint64_t volume_index_from_tiles_device(void* context, void* points, int num_points, float transform[9],
437
420
  float translation[3], bool points_in_world_space)
438
421
  {
439
- nanovdb::IndexGrid *grid;
422
+ nanovdb::IndexGrid* grid;
440
423
  size_t gridSize;
441
424
  BuildGridParams<nanovdb::ValueIndex> params;
442
425
  volume_set_map(params.map, transform, translation);
@@ -446,10 +429,10 @@ uint64_t volume_index_from_tiles_device(void *context, void *points, int num_poi
446
429
  return volume_create_device(context, grid, gridSize, false, true);
447
430
  }
448
431
 
449
- uint64_t volume_from_active_voxels_device(void *context, void *points, int num_points, float transform[9],
432
+ uint64_t volume_from_active_voxels_device(void* context, void* points, int num_points, float transform[9],
450
433
  float translation[3], bool points_in_world_space)
451
434
  {
452
- nanovdb::OnIndexGrid *grid;
435
+ nanovdb::OnIndexGrid* grid;
453
436
  size_t gridSize;
454
437
  BuildGridParams<nanovdb::ValueOnIndex> params;
455
438
  volume_set_map(params.map, transform, translation);
@@ -459,71 +442,60 @@ uint64_t volume_from_active_voxels_device(void *context, void *points, int num_p
459
442
  return volume_create_device(context, grid, gridSize, false, true);
460
443
  }
461
444
 
462
- void launch_get_leaf_coords(void *context, const uint32_t leaf_count, pnanovdb_coord_t *leaf_coords,
445
+ void launch_get_leaf_coords(void* context, const uint32_t leaf_count, pnanovdb_coord_t* leaf_coords,
463
446
  pnanovdb_buf_t buf);
464
- void launch_get_voxel_coords(void *context, const uint32_t leaf_count, const uint32_t voxel_count,
465
- pnanovdb_coord_t *voxel_coords, pnanovdb_buf_t buf);
447
+ void launch_get_voxel_coords(void* context, const uint32_t leaf_count, const uint32_t voxel_count,
448
+ pnanovdb_coord_t* voxel_coords, pnanovdb_buf_t buf);
466
449
 
467
- void volume_get_tiles_device(uint64_t id, void *buf)
450
+ void volume_get_tiles_device(uint64_t id, void* buf)
468
451
  {
469
- const VolumeDesc *volume;
452
+ const VolumeDesc* volume;
470
453
  if (volume_get_descriptor(id, volume))
471
454
  {
472
455
  const uint32_t leaf_count = volume->tree_data.node_count_leaf;
473
456
 
474
- pnanovdb_coord_t *leaf_coords = static_cast<pnanovdb_coord_t *>(buf);
457
+ pnanovdb_coord_t* leaf_coords = static_cast<pnanovdb_coord_t*>(buf);
475
458
  launch_get_leaf_coords(volume->context, leaf_count, leaf_coords, volume->as_pnano());
476
459
  }
477
460
  }
478
461
 
479
- void volume_get_voxels_device(uint64_t id, void *buf)
462
+ void volume_get_voxels_device(uint64_t id, void* buf)
480
463
  {
481
- const VolumeDesc *volume;
464
+ const VolumeDesc* volume;
482
465
  if (volume_get_descriptor(id, volume))
483
466
  {
484
467
  uint32_t leaf_count;
485
468
  uint64_t voxel_count;
486
469
  volume_get_tile_and_voxel_count(id, leaf_count, voxel_count);
487
470
 
488
- pnanovdb_coord_t *voxel_coords = static_cast<pnanovdb_coord_t *>(buf);
471
+ pnanovdb_coord_t* voxel_coords = static_cast<pnanovdb_coord_t*>(buf);
489
472
  launch_get_voxel_coords(volume->context, leaf_count, voxel_count, voxel_coords, volume->as_pnano());
490
473
  }
491
474
  }
492
475
 
493
476
  #else
494
477
  // stubs for non-CUDA platforms
495
- uint64_t volume_f_from_tiles_device(void *context, void *points, int num_points, float transform[9],
496
- float translation[3], bool points_in_world_space, float bg_value)
497
- {
498
- return 0;
499
- }
500
-
501
- uint64_t volume_v_from_tiles_device(void *context, void *points, int num_points, float transform[9],
502
- float translation[3], bool points_in_world_space, float bg_value[3])
503
- {
504
- return 0;
505
- }
506
-
507
- uint64_t volume_i_from_tiles_device(void *context, void *points, int num_points, float transform[9],
508
- float translation[3], bool points_in_world_space, int bg_value)
478
+ uint64_t volume_from_tiles_device(void* context, void* points, int num_points, float transform[9],
479
+ float translation[3], bool points_in_world_space, const void* value_ptr, uint32_t value_size,
480
+ const char* value_type)
509
481
  {
510
482
  return 0;
511
483
  }
512
484
 
513
- uint64_t volume_index_from_tiles_device(void *context, void *points, int num_points, float transform[9],
485
+ uint64_t volume_index_from_tiles_device(void* context, void* points, int num_points, float transform[9],
514
486
  float translation[3], bool points_in_world_space)
515
487
  {
516
488
  return 0;
517
489
  }
518
490
 
519
- uint64_t volume_from_active_voxels_device(void *context, void *points, int num_points, float transform[9],
491
+ uint64_t volume_from_active_voxels_device(void* context, void* points, int num_points, float transform[9],
520
492
  float translation[3], bool points_in_world_space)
521
493
  {
522
494
  return 0;
523
495
  }
524
496
 
525
- void volume_get_tiles_device(uint64_t id, void *buf) {}
497
+ void volume_get_tiles_device(uint64_t id, void* buf) {}
526
498
 
527
- void volume_get_voxels_device(uint64_t id, void *buf) {}
499
+ void volume_get_voxels_device(uint64_t id, void* buf) {}
528
500
 
529
501
  #endif