warp-lang 1.8.1__py3-none-manylinux_2_34_aarch64.whl → 1.9.0__py3-none-manylinux_2_34_aarch64.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 (134) hide show
  1. warp/__init__.py +282 -103
  2. warp/__init__.pyi +482 -110
  3. warp/bin/warp-clang.so +0 -0
  4. warp/bin/warp.so +0 -0
  5. warp/build.py +93 -30
  6. warp/build_dll.py +47 -67
  7. warp/builtins.py +955 -137
  8. warp/codegen.py +312 -206
  9. warp/config.py +1 -1
  10. warp/context.py +1249 -784
  11. warp/examples/core/example_marching_cubes.py +1 -0
  12. warp/examples/core/example_render_opengl.py +100 -3
  13. warp/examples/fem/example_apic_fluid.py +98 -52
  14. warp/examples/fem/example_convection_diffusion_dg.py +25 -4
  15. warp/examples/fem/example_diffusion_mgpu.py +8 -3
  16. warp/examples/fem/utils.py +68 -22
  17. warp/fabric.py +1 -1
  18. warp/fem/cache.py +27 -19
  19. warp/fem/domain.py +2 -2
  20. warp/fem/field/nodal_field.py +2 -2
  21. warp/fem/field/virtual.py +264 -166
  22. warp/fem/geometry/geometry.py +5 -5
  23. warp/fem/integrate.py +129 -51
  24. warp/fem/space/restriction.py +4 -0
  25. warp/fem/space/shape/tet_shape_function.py +3 -10
  26. warp/jax_experimental/custom_call.py +1 -1
  27. warp/jax_experimental/ffi.py +2 -1
  28. warp/marching_cubes.py +708 -0
  29. warp/native/array.h +99 -4
  30. warp/native/builtin.h +82 -5
  31. warp/native/bvh.cpp +64 -28
  32. warp/native/bvh.cu +58 -58
  33. warp/native/bvh.h +2 -2
  34. warp/native/clang/clang.cpp +7 -7
  35. warp/native/coloring.cpp +8 -2
  36. warp/native/crt.cpp +2 -2
  37. warp/native/crt.h +3 -5
  38. warp/native/cuda_util.cpp +41 -10
  39. warp/native/cuda_util.h +10 -4
  40. warp/native/exports.h +1842 -1908
  41. warp/native/fabric.h +2 -1
  42. warp/native/hashgrid.cpp +37 -37
  43. warp/native/hashgrid.cu +2 -2
  44. warp/native/initializer_array.h +1 -1
  45. warp/native/intersect.h +2 -2
  46. warp/native/mat.h +1910 -116
  47. warp/native/mathdx.cpp +43 -43
  48. warp/native/mesh.cpp +24 -24
  49. warp/native/mesh.cu +26 -26
  50. warp/native/mesh.h +4 -2
  51. warp/native/nanovdb/GridHandle.h +179 -12
  52. warp/native/nanovdb/HostBuffer.h +8 -7
  53. warp/native/nanovdb/NanoVDB.h +517 -895
  54. warp/native/nanovdb/NodeManager.h +323 -0
  55. warp/native/nanovdb/PNanoVDB.h +2 -2
  56. warp/native/quat.h +331 -14
  57. warp/native/range.h +7 -1
  58. warp/native/reduce.cpp +10 -10
  59. warp/native/reduce.cu +13 -14
  60. warp/native/runlength_encode.cpp +2 -2
  61. warp/native/runlength_encode.cu +5 -5
  62. warp/native/scan.cpp +3 -3
  63. warp/native/scan.cu +4 -4
  64. warp/native/sort.cpp +10 -10
  65. warp/native/sort.cu +22 -22
  66. warp/native/sparse.cpp +8 -8
  67. warp/native/sparse.cu +13 -13
  68. warp/native/spatial.h +366 -17
  69. warp/native/temp_buffer.h +2 -2
  70. warp/native/tile.h +283 -69
  71. warp/native/vec.h +381 -14
  72. warp/native/volume.cpp +54 -54
  73. warp/native/volume.cu +1 -1
  74. warp/native/volume.h +2 -1
  75. warp/native/volume_builder.cu +30 -37
  76. warp/native/warp.cpp +150 -149
  77. warp/native/warp.cu +323 -192
  78. warp/native/warp.h +227 -226
  79. warp/optim/linear.py +736 -271
  80. warp/render/imgui_manager.py +289 -0
  81. warp/render/render_opengl.py +85 -6
  82. warp/sim/graph_coloring.py +2 -2
  83. warp/sparse.py +558 -175
  84. warp/tests/aux_test_module_aot.py +7 -0
  85. warp/tests/cuda/test_async.py +3 -3
  86. warp/tests/cuda/test_conditional_captures.py +101 -0
  87. warp/tests/geometry/test_marching_cubes.py +233 -12
  88. warp/tests/sim/test_coloring.py +6 -6
  89. warp/tests/test_array.py +56 -5
  90. warp/tests/test_codegen.py +3 -2
  91. warp/tests/test_context.py +8 -15
  92. warp/tests/test_enum.py +136 -0
  93. warp/tests/test_examples.py +2 -2
  94. warp/tests/test_fem.py +45 -2
  95. warp/tests/test_fixedarray.py +229 -0
  96. warp/tests/test_func.py +18 -15
  97. warp/tests/test_future_annotations.py +7 -5
  98. warp/tests/test_linear_solvers.py +30 -0
  99. warp/tests/test_map.py +1 -1
  100. warp/tests/test_mat.py +1518 -378
  101. warp/tests/test_mat_assign_copy.py +178 -0
  102. warp/tests/test_mat_constructors.py +574 -0
  103. warp/tests/test_module_aot.py +287 -0
  104. warp/tests/test_print.py +69 -0
  105. warp/tests/test_quat.py +140 -34
  106. warp/tests/test_quat_assign_copy.py +145 -0
  107. warp/tests/test_reload.py +2 -1
  108. warp/tests/test_sparse.py +71 -0
  109. warp/tests/test_spatial.py +140 -34
  110. warp/tests/test_spatial_assign_copy.py +160 -0
  111. warp/tests/test_struct.py +43 -3
  112. warp/tests/test_types.py +0 -20
  113. warp/tests/test_vec.py +179 -34
  114. warp/tests/test_vec_assign_copy.py +143 -0
  115. warp/tests/tile/test_tile.py +184 -18
  116. warp/tests/tile/test_tile_cholesky.py +605 -0
  117. warp/tests/tile/test_tile_load.py +169 -0
  118. warp/tests/tile/test_tile_mathdx.py +2 -558
  119. warp/tests/tile/test_tile_matmul.py +1 -1
  120. warp/tests/tile/test_tile_mlp.py +1 -1
  121. warp/tests/tile/test_tile_shared_memory.py +5 -5
  122. warp/tests/unittest_suites.py +6 -0
  123. warp/tests/walkthrough_debug.py +1 -1
  124. warp/thirdparty/unittest_parallel.py +108 -9
  125. warp/types.py +554 -264
  126. warp/utils.py +68 -86
  127. {warp_lang-1.8.1.dist-info → warp_lang-1.9.0.dist-info}/METADATA +28 -65
  128. {warp_lang-1.8.1.dist-info → warp_lang-1.9.0.dist-info}/RECORD +131 -121
  129. warp/native/marching.cpp +0 -19
  130. warp/native/marching.cu +0 -514
  131. warp/native/marching.h +0 -19
  132. {warp_lang-1.8.1.dist-info → warp_lang-1.9.0.dist-info}/WHEEL +0 -0
  133. {warp_lang-1.8.1.dist-info → warp_lang-1.9.0.dist-info}/licenses/LICENSE.md +0 -0
  134. {warp_lang-1.8.1.dist-info → warp_lang-1.9.0.dist-info}/top_level.txt +0 -0
warp/native/marching.cu DELETED
@@ -1,514 +0,0 @@
1
- /*
2
- * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- #include "warp.h"
19
- #include "cuda_util.h"
20
- #include "scan.h"
21
-
22
- namespace wp {
23
-
24
-
25
- // point numbering
26
-
27
- // 7-----------6
28
- // /| /|
29
- // / | / |
30
- // / | / |
31
- // 4-----------5 |
32
- // | | | |
33
- // | 3-------|---2
34
- // | / | /
35
- // | / | /
36
- // |/ |/
37
- // 0-----------1
38
-
39
- // edge numbering
40
-
41
- // *-----6-----*
42
- // /| /|
43
- // 7 | 5 |
44
- // / 11 / 10
45
- // *-----4-----* |
46
- // | | | |
47
- // | *-----2-|---*
48
- // 8 / 9 /
49
- // | 3 | 1
50
- // |/ |/
51
- // *-----0-----*
52
-
53
-
54
- // z
55
- // | y
56
- // | /
57
- // |/
58
- // 0---- x
59
-
60
- __constant__ int marchingCubeCorners[8][3] = { {0,0,0}, {1,0,0},{1,1,0},{0,1,0}, {0,0,1}, {1,0,1},{1,1,1},{0,1,1} };
61
-
62
- __constant__ int firstMarchingCubesId[257] = {
63
- 0, 0, 3, 6, 12, 15, 21, 27, 36, 39, 45, 51, 60, 66, 75, 84, 90, 93, 99, 105, 114,
64
- 120, 129, 138, 150, 156, 165, 174, 186, 195, 207, 219, 228, 231, 237, 243, 252, 258, 267, 276, 288,
65
- 294, 303, 312, 324, 333, 345, 357, 366, 372, 381, 390, 396, 405, 417, 429, 438, 447, 459, 471, 480,
66
- 492, 507, 522, 528, 531, 537, 543, 552, 558, 567, 576, 588, 594, 603, 612, 624, 633, 645, 657, 666,
67
- 672, 681, 690, 702, 711, 723, 735, 750, 759, 771, 783, 798, 810, 825, 840, 852, 858, 867, 876, 888,
68
- 897, 909, 915, 924, 933, 945, 957, 972, 984, 999, 1008, 1014, 1023, 1035, 1047, 1056, 1068, 1083, 1092, 1098,
69
- 1110, 1125, 1140, 1152, 1167, 1173, 1185, 1188, 1191, 1197, 1203, 1212, 1218, 1227, 1236, 1248, 1254, 1263, 1272, 1284,
70
- 1293, 1305, 1317, 1326, 1332, 1341, 1350, 1362, 1371, 1383, 1395, 1410, 1419, 1425, 1437, 1446, 1458, 1467, 1482, 1488,
71
- 1494, 1503, 1512, 1524, 1533, 1545, 1557, 1572, 1581, 1593, 1605, 1620, 1632, 1647, 1662, 1674, 1683, 1695, 1707, 1716,
72
- 1728, 1743, 1758, 1770, 1782, 1791, 1806, 1812, 1827, 1839, 1845, 1848, 1854, 1863, 1872, 1884, 1893, 1905, 1917, 1932,
73
- 1941, 1953, 1965, 1980, 1986, 1995, 2004, 2010, 2019, 2031, 2043, 2058, 2070, 2085, 2100, 2106, 2118, 2127, 2142, 2154,
74
- 2163, 2169, 2181, 2184, 2193, 2205, 2217, 2232, 2244, 2259, 2268, 2280, 2292, 2307, 2322, 2328, 2337, 2349, 2355, 2358,
75
- 2364, 2373, 2382, 2388, 2397, 2409, 2415, 2418, 2427, 2433, 2445, 2448, 2454, 2457, 2460, 2460 };
76
-
77
- __constant__ int marchingCubesIds[2460] = {
78
- 0, 8, 3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, 9, 9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, 3, 7, 10, 3,
155
- 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, 1, 10, 2, 8, 7, 4, 4, 9, 1, 4, 1, 7, 7, 1, 3, 4, 9, 1, 4,
156
- 1, 7, 0, 8, 1, 8, 7, 1, 4, 0, 3, 7, 4, 3, 4, 8, 7, 9, 10, 8, 10, 11, 8, 3, 0, 9, 3, 9, 11, 11,
157
- 9, 10, 0, 1, 10, 0, 10, 8, 8, 10, 11, 3, 1, 10, 11, 3, 10, 1, 2, 11, 1, 11, 9, 9, 11, 8, 3, 0, 9, 3,
158
- 9, 11, 1, 2, 9, 2, 11, 9, 0, 2, 11, 8, 0, 11, 3, 2, 11, 2, 3, 8, 2, 8, 10, 10, 8, 9, 9, 10, 2, 0,
159
- 9, 2, 2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, 1, 10, 2, 1, 3, 8, 9, 1, 8, 0, 9, 1, 0, 3, 8};
160
-
161
- __constant__ int marchingCubesEdgeLocations[12][4] = {
162
- // relative cell coords, edge within cell
163
- {0, 0, 0, 0},
164
- {1, 0, 0, 1},
165
- {0, 1, 0, 0},
166
- {0, 0, 0, 1},
167
-
168
- {0, 0, 1, 0},
169
- {1, 0, 1, 1},
170
- {0, 1, 1, 0},
171
- {0, 0, 1, 1},
172
-
173
- {0, 0, 0, 2},
174
- {1, 0, 0, 2},
175
- {1, 1, 0, 2},
176
- {0, 1, 0, 2}
177
- };
178
-
179
-
180
- // ---------------------------------------------------------------------------------------
181
- struct MarchingCubes
182
- {
183
- MarchingCubes()
184
- {
185
- memset(this, 0, sizeof(MarchingCubes));
186
- first_cell_vert = nullptr;
187
- first_cell_tri = nullptr;
188
- cell_verts = nullptr;
189
- context = nullptr;
190
- }
191
-
192
- __device__ __host__ int cell_index(int xi, int yi, int zi) const
193
- {
194
- return (xi * ny + yi) * nz + zi;
195
- }
196
- __device__ __host__ void cell_coord(int cell_index, int& xi, int& yi, int& zi) const
197
- {
198
- zi = cell_index % nz; cell_index /= nz;
199
- yi = cell_index % ny;
200
- xi = cell_index / ny;
201
- }
202
-
203
- // grid
204
- int nx;
205
- int ny;
206
- int nz;
207
-
208
- int* first_cell_vert;
209
- int* first_cell_tri;
210
- int* cell_verts;
211
-
212
- int num_cells;
213
- int max_cells;
214
-
215
- void* context;
216
- };
217
-
218
-
219
- // -----------------------------------------------------------------------------------
220
- __global__ void count_cell_verts(MarchingCubes mc, const float* density, float threshold)
221
- {
222
- int cell_index = blockIdx.x * blockDim.x + threadIdx.x;
223
- if (cell_index >= mc.num_cells)
224
- return;
225
-
226
- int xi, yi, zi;
227
- mc.cell_coord(cell_index, xi, yi, zi);
228
-
229
- mc.first_cell_vert[cell_index] = 0;
230
- if (xi >= mc.nx - 1 || yi >= mc.ny - 1 || zi >= mc.nz - 1)
231
- return;
232
-
233
- float d0 = density[cell_index];
234
- float dx = density[mc.cell_index(xi + 1, yi, zi)];
235
- float dy = density[mc.cell_index(xi, yi + 1, zi)];
236
- float dz = density[mc.cell_index(xi, yi, zi + 1)];
237
-
238
- int num = 0;
239
- if ((d0 <= threshold && dx >= threshold) || (dx <= threshold && d0 >= threshold))
240
- num++;
241
- if ((d0 <= threshold && dy >= threshold) || (dy <= threshold && d0 >= threshold))
242
- num++;
243
- if ((d0 <= threshold && dz >= threshold) || (dz <= threshold && d0 >= threshold))
244
- num++;
245
-
246
- mc.first_cell_vert[cell_index] = num;
247
- }
248
-
249
- // -----------------------------------------------------------------------------------
250
- __global__ void create_cell_verts(MarchingCubes mc, vec3* __restrict__ vertices, vec3* normals, const float* __restrict__ density, float threshold)
251
- {
252
- int cell_index = blockIdx.x * blockDim.x + threadIdx.x;
253
- if (cell_index >= mc.num_cells)
254
- return;
255
-
256
- int xi, yi, zi;
257
- mc.cell_coord(cell_index, xi, yi, zi);
258
- if (xi >= mc.nx - 1 || yi >= mc.ny - 1 || zi >= mc.nz - 1)
259
- return;
260
-
261
- vec3 p = vec3(xi + 0.5f, yi + 0.5f, zi + 0.5f);
262
-
263
- float d0 = density[cell_index];
264
- float ds[3];
265
- ds[0] = density[mc.cell_index(xi + 1, yi, zi)];
266
- ds[1] = density[mc.cell_index(xi, yi + 1, zi)];
267
- ds[2] = density[mc.cell_index(xi, yi, zi + 1)];
268
-
269
- // vec3 n0 = densityNormal[cell_index];
270
- // vec3 ns[3];
271
- // ns[0] = densityNormal[mc.cell_index(xi + 1, yi, zi)];
272
- // ns[1] = densityNormal[mc.cell_index(xi, yi + 1, zi)];
273
- // ns[2] = densityNormal[mc.cell_index(xi, yi, zi + 1)];
274
-
275
- int first = mc.first_cell_vert[cell_index];
276
-
277
- for (int dim = 0; dim < 3; dim++)
278
- {
279
- float d = ds[dim];
280
- mc.cell_verts[3 * cell_index + dim] = 0;
281
-
282
- if ((d0 <= threshold && d >= threshold) || (d <= threshold && d0 >= threshold))
283
- {
284
- float t = (d != d0) ? clamp((threshold - d0) / (d - d0), 0.0f, 1.0f) : 0.5f;
285
- int id = first++;
286
-
287
- vec3 off;
288
- off[dim] = t;
289
- vertices[id] = p + off;
290
-
291
- // vec3 n = normalize(n0 + t * (ns[dim] - n0));
292
- // normals[id] = -n;
293
-
294
- mc.cell_verts[3 * cell_index + dim] = id;
295
- }
296
- }
297
- }
298
-
299
- // -----------------------------------------------------------------------------------
300
- __global__ void count_cell_tris(MarchingCubes mc, const float* __restrict__ density, float threshold)
301
- {
302
- int cell_index = blockIdx.x * blockDim.x + threadIdx.x;
303
- if (cell_index >= mc.num_cells)
304
- return;
305
-
306
- int xi, yi, zi;
307
- mc.cell_coord(cell_index, xi, yi, zi);
308
-
309
- mc.first_cell_tri[cell_index] = 0;
310
- if (xi >= mc.nx - 2 || yi >= mc.ny - 2 || zi >= mc.nz - 2)
311
- return;
312
-
313
- int code = 0;
314
- for (int i = 0; i < 8; i++) {
315
- int cxi = xi + marchingCubeCorners[i][0];
316
- int cyi = yi + marchingCubeCorners[i][1];
317
- int czi = zi + marchingCubeCorners[i][2];
318
-
319
- if (density[mc.cell_index(cxi, cyi, czi)] >= threshold)
320
- code |= (1 << i);
321
- }
322
-
323
- mc.first_cell_tri[cell_index] = firstMarchingCubesId[code + 1] - firstMarchingCubesId[code];
324
- }
325
-
326
- // -----------------------------------------------------------------------------------
327
- __global__ void create_cell_tris(MarchingCubes mc, const float* __restrict__ density, int* __restrict__ triangles, float threshold)
328
- {
329
- int cell_index = blockIdx.x * blockDim.x + threadIdx.x;
330
- if (cell_index >= mc.num_cells)
331
- return;
332
-
333
- int xi, yi, zi;
334
- mc.cell_coord(cell_index, xi, yi, zi);
335
- if (xi >= mc.nx - 2 || yi >= mc.ny - 2 || zi >= mc.nz - 2)
336
- return;
337
-
338
- int code = 0;
339
- for (int i = 0; i < 8; i++)
340
- {
341
- int cxi = xi + marchingCubeCorners[i][0];
342
- int cyi = yi + marchingCubeCorners[i][1];
343
- int czi = zi + marchingCubeCorners[i][2];
344
-
345
- if (density[mc.cell_index(cxi, cyi, czi)] >= threshold)
346
- code |= (1 << i);
347
- }
348
-
349
- int firstIn = firstMarchingCubesId[code];
350
- int num = firstMarchingCubesId[code + 1] - firstIn;
351
- int firstOut = mc.first_cell_tri[cell_index];
352
-
353
- for (int i = 0; i < num; i++)
354
- {
355
- int eid = marchingCubesIds[firstIn + i];
356
-
357
- int exi = xi + marchingCubesEdgeLocations[eid][0];
358
- int eyi = yi + marchingCubesEdgeLocations[eid][1];
359
- int ezi = zi + marchingCubesEdgeLocations[eid][2];
360
- int edgeNr = marchingCubesEdgeLocations[eid][3];
361
-
362
- int id = mc.cell_verts[3 * mc.cell_index(exi, eyi, ezi) + edgeNr];
363
- triangles[firstOut + i] = id;
364
- }
365
- }
366
-
367
- // -------------------------
368
- void marching_cubes_resize(MarchingCubes& mc, int nx, int ny, int nz)
369
- {
370
- mc.nx = nx;
371
- mc.ny = ny;
372
- mc.nz = nz;
373
-
374
- mc.num_cells = nx*ny*nz;
375
-
376
- if (mc.num_cells > mc.max_cells)
377
- {
378
- ContextGuard guard(mc.context);
379
-
380
- const int num_to_alloc = mc.num_cells*3/2;
381
-
382
- free_device(WP_CURRENT_CONTEXT, mc.first_cell_vert);
383
- free_device(WP_CURRENT_CONTEXT, mc.first_cell_tri);
384
- free_device(WP_CURRENT_CONTEXT, mc.cell_verts);
385
-
386
- mc.first_cell_vert = (int*)alloc_device(WP_CURRENT_CONTEXT, sizeof(int) * num_to_alloc);
387
- mc.first_cell_tri = (int*)alloc_device(WP_CURRENT_CONTEXT, sizeof(int) * num_to_alloc);
388
- mc.cell_verts = (int*)alloc_device(WP_CURRENT_CONTEXT, sizeof(int) * 3 * num_to_alloc);
389
-
390
- mc.max_cells = num_to_alloc;
391
- }
392
- }
393
-
394
- // -------------------------
395
- void marching_cubes_free(MarchingCubes& mc)
396
- {
397
- ContextGuard guard(mc.context);
398
-
399
- free_device(WP_CURRENT_CONTEXT, mc.first_cell_vert);
400
- free_device(WP_CURRENT_CONTEXT, mc.first_cell_tri);
401
- free_device(WP_CURRENT_CONTEXT, mc.cell_verts);
402
- }
403
-
404
- } // namespace wp
405
-
406
- uint64_t marching_cubes_create_device(void* context)
407
- {
408
- ContextGuard guard(context);
409
-
410
- wp::MarchingCubes* mc = new wp::MarchingCubes();
411
-
412
- mc->context = context ? context : cuda_context_get_current();
413
-
414
- return (uint64_t)(mc);
415
- }
416
-
417
- void marching_cubes_destroy_device(uint64_t id)
418
- {
419
- if (!id)
420
- return;
421
-
422
- wp::MarchingCubes* mc = (wp::MarchingCubes*)(id);
423
- wp::marching_cubes_free(*mc);
424
- delete mc;
425
- }
426
-
427
-
428
- WP_API int marching_cubes_surface_device(
429
- uint64_t id,
430
- const float* field,
431
- int nx,
432
- int ny,
433
- int nz,
434
- float threshold,
435
- wp::vec3* verts,
436
- int* triangles,
437
- int max_verts,
438
- int max_tris,
439
- int* out_num_verts,
440
- int* out_num_tris)
441
- {
442
-
443
- if (!id)
444
- return -1;
445
-
446
- if (!field)
447
- return -1;
448
-
449
- wp::MarchingCubes& mc = *(wp::MarchingCubes*)(id);
450
-
451
- ContextGuard guard(mc.context);
452
-
453
- // reset counts
454
- *out_num_verts = 0;
455
- *out_num_tris = 0;
456
-
457
- // resize temporary memory
458
- marching_cubes_resize(mc, nx, ny, nz);
459
-
460
- // create vertices
461
- wp_launch_device(WP_CURRENT_CONTEXT, wp::count_cell_verts, mc.num_cells, (mc, field, threshold) );
462
-
463
- int num_last;
464
- memcpy_d2h(WP_CURRENT_CONTEXT, &num_last, &mc.first_cell_vert[mc.num_cells - 1], sizeof(int));
465
-
466
- scan_device(mc.first_cell_vert, mc.first_cell_vert, mc.num_cells, false);
467
-
468
- int num_verts;
469
- memcpy_d2h(WP_CURRENT_CONTEXT, &num_verts, &mc.first_cell_vert[mc.num_cells - 1], sizeof(int));
470
- cuda_context_synchronize(WP_CURRENT_CONTEXT);
471
-
472
- num_verts += num_last;
473
-
474
- // check we have enough storage, if not then
475
- // return required vertex buffer size, let user resize
476
- if (num_verts > max_verts)
477
- {
478
- *out_num_verts = num_verts;
479
- return -1;
480
- }
481
-
482
- // create vertices
483
- wp_launch_device(WP_CURRENT_CONTEXT, wp::create_cell_verts, mc.num_cells, (mc, verts, NULL, field, threshold));
484
-
485
- // create triangles
486
- wp_launch_device(WP_CURRENT_CONTEXT, wp::count_cell_tris, mc.num_cells, (mc, field, threshold));
487
-
488
-
489
- memcpy_d2h(WP_CURRENT_CONTEXT, &num_last, &mc.first_cell_tri[mc.num_cells - 1], sizeof(int));
490
-
491
- scan_device(mc.first_cell_tri, mc.first_cell_tri, mc.num_cells, false);
492
-
493
-
494
- int num_indices;
495
- memcpy_d2h(WP_CURRENT_CONTEXT, &num_indices, &mc.first_cell_tri[mc.num_cells - 1], sizeof(int));
496
- cuda_context_synchronize(WP_CURRENT_CONTEXT);
497
-
498
- num_indices += num_last;
499
-
500
- int num_tris = num_indices/3;
501
-
502
- if (num_tris > max_tris)
503
- {
504
- *out_num_tris = num_tris;
505
- return -1;
506
- }
507
-
508
- wp_launch_device(WP_CURRENT_CONTEXT, wp::create_cell_tris, mc.num_cells, (mc, field, triangles, threshold));
509
-
510
- *out_num_verts = num_verts;
511
- *out_num_tris = num_tris;
512
-
513
- return 0;
514
- }
warp/native/marching.h DELETED
@@ -1,19 +0,0 @@
1
- /*
2
- * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- #pragma once
19
-