warp-lang 1.0.1__py3-none-macosx_10_13_universal2.whl → 1.1.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 (346) hide show
  1. warp/__init__.py +108 -97
  2. warp/__init__.pyi +1 -1
  3. warp/bin/libwarp-clang.dylib +0 -0
  4. warp/bin/libwarp.dylib +0 -0
  5. warp/build.py +115 -113
  6. warp/build_dll.py +383 -375
  7. warp/builtins.py +3425 -3354
  8. warp/codegen.py +2878 -2792
  9. warp/config.py +40 -36
  10. warp/constants.py +45 -45
  11. warp/context.py +5194 -5102
  12. warp/dlpack.py +442 -442
  13. warp/examples/__init__.py +16 -16
  14. warp/examples/assets/bear.usd +0 -0
  15. warp/examples/assets/bunny.usd +0 -0
  16. warp/examples/assets/cartpole.urdf +110 -110
  17. warp/examples/assets/crazyflie.usd +0 -0
  18. warp/examples/assets/cube.usd +0 -0
  19. warp/examples/assets/nv_ant.xml +92 -92
  20. warp/examples/assets/nv_humanoid.xml +183 -183
  21. warp/examples/assets/quadruped.urdf +267 -267
  22. warp/examples/assets/rocks.nvdb +0 -0
  23. warp/examples/assets/rocks.usd +0 -0
  24. warp/examples/assets/sphere.usd +0 -0
  25. warp/examples/benchmarks/benchmark_api.py +383 -383
  26. warp/examples/benchmarks/benchmark_cloth.py +278 -279
  27. warp/examples/benchmarks/benchmark_cloth_cupy.py +88 -88
  28. warp/examples/benchmarks/benchmark_cloth_jax.py +97 -100
  29. warp/examples/benchmarks/benchmark_cloth_numba.py +146 -142
  30. warp/examples/benchmarks/benchmark_cloth_numpy.py +77 -77
  31. warp/examples/benchmarks/benchmark_cloth_pytorch.py +86 -86
  32. warp/examples/benchmarks/benchmark_cloth_taichi.py +112 -112
  33. warp/examples/benchmarks/benchmark_cloth_warp.py +146 -146
  34. warp/examples/benchmarks/benchmark_launches.py +295 -295
  35. warp/examples/browse.py +29 -28
  36. warp/examples/core/example_dem.py +234 -221
  37. warp/examples/core/example_fluid.py +293 -267
  38. warp/examples/core/example_graph_capture.py +144 -129
  39. warp/examples/core/example_marching_cubes.py +188 -176
  40. warp/examples/core/example_mesh.py +174 -154
  41. warp/examples/core/example_mesh_intersect.py +205 -193
  42. warp/examples/core/example_nvdb.py +176 -169
  43. warp/examples/core/example_raycast.py +105 -89
  44. warp/examples/core/example_raymarch.py +199 -178
  45. warp/examples/core/example_render_opengl.py +185 -141
  46. warp/examples/core/example_sph.py +405 -389
  47. warp/examples/core/example_torch.py +222 -181
  48. warp/examples/core/example_wave.py +263 -249
  49. warp/examples/fem/bsr_utils.py +378 -380
  50. warp/examples/fem/example_apic_fluid.py +407 -391
  51. warp/examples/fem/example_convection_diffusion.py +182 -168
  52. warp/examples/fem/example_convection_diffusion_dg.py +219 -209
  53. warp/examples/fem/example_convection_diffusion_dg0.py +204 -194
  54. warp/examples/fem/example_deformed_geometry.py +177 -159
  55. warp/examples/fem/example_diffusion.py +201 -173
  56. warp/examples/fem/example_diffusion_3d.py +177 -152
  57. warp/examples/fem/example_diffusion_mgpu.py +221 -214
  58. warp/examples/fem/example_mixed_elasticity.py +244 -222
  59. warp/examples/fem/example_navier_stokes.py +259 -243
  60. warp/examples/fem/example_stokes.py +220 -192
  61. warp/examples/fem/example_stokes_transfer.py +265 -249
  62. warp/examples/fem/mesh_utils.py +133 -109
  63. warp/examples/fem/plot_utils.py +292 -287
  64. warp/examples/optim/example_bounce.py +260 -248
  65. warp/examples/optim/example_cloth_throw.py +222 -210
  66. warp/examples/optim/example_diffray.py +566 -535
  67. warp/examples/optim/example_drone.py +864 -835
  68. warp/examples/optim/example_inverse_kinematics.py +176 -169
  69. warp/examples/optim/example_inverse_kinematics_torch.py +185 -170
  70. warp/examples/optim/example_spring_cage.py +239 -234
  71. warp/examples/optim/example_trajectory.py +223 -201
  72. warp/examples/optim/example_walker.py +306 -292
  73. warp/examples/sim/example_cartpole.py +139 -128
  74. warp/examples/sim/example_cloth.py +196 -184
  75. warp/examples/sim/example_granular.py +124 -113
  76. warp/examples/sim/example_granular_collision_sdf.py +197 -185
  77. warp/examples/sim/example_jacobian_ik.py +236 -213
  78. warp/examples/sim/example_particle_chain.py +118 -106
  79. warp/examples/sim/example_quadruped.py +193 -179
  80. warp/examples/sim/example_rigid_chain.py +197 -189
  81. warp/examples/sim/example_rigid_contact.py +189 -176
  82. warp/examples/sim/example_rigid_force.py +127 -126
  83. warp/examples/sim/example_rigid_gyroscopic.py +109 -97
  84. warp/examples/sim/example_rigid_soft_contact.py +134 -124
  85. warp/examples/sim/example_soft_body.py +190 -178
  86. warp/fabric.py +337 -335
  87. warp/fem/__init__.py +60 -27
  88. warp/fem/cache.py +401 -388
  89. warp/fem/dirichlet.py +178 -179
  90. warp/fem/domain.py +262 -263
  91. warp/fem/field/__init__.py +100 -101
  92. warp/fem/field/field.py +148 -149
  93. warp/fem/field/nodal_field.py +298 -299
  94. warp/fem/field/restriction.py +22 -21
  95. warp/fem/field/test.py +180 -181
  96. warp/fem/field/trial.py +183 -183
  97. warp/fem/geometry/__init__.py +15 -19
  98. warp/fem/geometry/closest_point.py +69 -70
  99. warp/fem/geometry/deformed_geometry.py +270 -271
  100. warp/fem/geometry/element.py +744 -744
  101. warp/fem/geometry/geometry.py +184 -186
  102. warp/fem/geometry/grid_2d.py +380 -373
  103. warp/fem/geometry/grid_3d.py +441 -435
  104. warp/fem/geometry/hexmesh.py +953 -953
  105. warp/fem/geometry/partition.py +374 -376
  106. warp/fem/geometry/quadmesh_2d.py +532 -532
  107. warp/fem/geometry/tetmesh.py +840 -840
  108. warp/fem/geometry/trimesh_2d.py +577 -577
  109. warp/fem/integrate.py +1630 -1615
  110. warp/fem/operator.py +190 -191
  111. warp/fem/polynomial.py +214 -213
  112. warp/fem/quadrature/__init__.py +2 -2
  113. warp/fem/quadrature/pic_quadrature.py +243 -245
  114. warp/fem/quadrature/quadrature.py +295 -294
  115. warp/fem/space/__init__.py +294 -292
  116. warp/fem/space/basis_space.py +488 -489
  117. warp/fem/space/collocated_function_space.py +100 -105
  118. warp/fem/space/dof_mapper.py +236 -236
  119. warp/fem/space/function_space.py +148 -145
  120. warp/fem/space/grid_2d_function_space.py +267 -267
  121. warp/fem/space/grid_3d_function_space.py +305 -306
  122. warp/fem/space/hexmesh_function_space.py +350 -352
  123. warp/fem/space/partition.py +350 -350
  124. warp/fem/space/quadmesh_2d_function_space.py +368 -369
  125. warp/fem/space/restriction.py +158 -160
  126. warp/fem/space/shape/__init__.py +13 -15
  127. warp/fem/space/shape/cube_shape_function.py +738 -738
  128. warp/fem/space/shape/shape_function.py +102 -103
  129. warp/fem/space/shape/square_shape_function.py +611 -611
  130. warp/fem/space/shape/tet_shape_function.py +565 -567
  131. warp/fem/space/shape/triangle_shape_function.py +429 -429
  132. warp/fem/space/tetmesh_function_space.py +294 -292
  133. warp/fem/space/topology.py +297 -295
  134. warp/fem/space/trimesh_2d_function_space.py +223 -221
  135. warp/fem/types.py +77 -77
  136. warp/fem/utils.py +495 -495
  137. warp/jax.py +166 -141
  138. warp/jax_experimental.py +341 -339
  139. warp/native/array.h +1072 -1025
  140. warp/native/builtin.h +1560 -1560
  141. warp/native/bvh.cpp +398 -398
  142. warp/native/bvh.cu +525 -525
  143. warp/native/bvh.h +429 -429
  144. warp/native/clang/clang.cpp +495 -464
  145. warp/native/crt.cpp +31 -31
  146. warp/native/crt.h +334 -334
  147. warp/native/cuda_crt.h +1049 -1049
  148. warp/native/cuda_util.cpp +549 -540
  149. warp/native/cuda_util.h +288 -203
  150. warp/native/cutlass_gemm.cpp +34 -34
  151. warp/native/cutlass_gemm.cu +372 -372
  152. warp/native/error.cpp +66 -66
  153. warp/native/error.h +27 -27
  154. warp/native/fabric.h +228 -228
  155. warp/native/hashgrid.cpp +301 -278
  156. warp/native/hashgrid.cu +78 -77
  157. warp/native/hashgrid.h +227 -227
  158. warp/native/initializer_array.h +32 -32
  159. warp/native/intersect.h +1204 -1204
  160. warp/native/intersect_adj.h +365 -365
  161. warp/native/intersect_tri.h +322 -322
  162. warp/native/marching.cpp +2 -2
  163. warp/native/marching.cu +497 -497
  164. warp/native/marching.h +2 -2
  165. warp/native/mat.h +1498 -1498
  166. warp/native/matnn.h +333 -333
  167. warp/native/mesh.cpp +203 -203
  168. warp/native/mesh.cu +293 -293
  169. warp/native/mesh.h +1887 -1887
  170. warp/native/nanovdb/NanoVDB.h +4782 -4782
  171. warp/native/nanovdb/PNanoVDB.h +2553 -2553
  172. warp/native/nanovdb/PNanoVDBWrite.h +294 -294
  173. warp/native/noise.h +850 -850
  174. warp/native/quat.h +1084 -1084
  175. warp/native/rand.h +299 -299
  176. warp/native/range.h +108 -108
  177. warp/native/reduce.cpp +156 -156
  178. warp/native/reduce.cu +348 -348
  179. warp/native/runlength_encode.cpp +61 -61
  180. warp/native/runlength_encode.cu +46 -46
  181. warp/native/scan.cpp +30 -30
  182. warp/native/scan.cu +36 -36
  183. warp/native/scan.h +7 -7
  184. warp/native/solid_angle.h +442 -442
  185. warp/native/sort.cpp +94 -94
  186. warp/native/sort.cu +97 -97
  187. warp/native/sort.h +14 -14
  188. warp/native/sparse.cpp +337 -337
  189. warp/native/sparse.cu +544 -544
  190. warp/native/spatial.h +630 -630
  191. warp/native/svd.h +562 -562
  192. warp/native/temp_buffer.h +30 -30
  193. warp/native/vec.h +1132 -1132
  194. warp/native/volume.cpp +297 -297
  195. warp/native/volume.cu +32 -32
  196. warp/native/volume.h +538 -538
  197. warp/native/volume_builder.cu +425 -425
  198. warp/native/volume_builder.h +19 -19
  199. warp/native/warp.cpp +1057 -1052
  200. warp/native/warp.cu +2943 -2828
  201. warp/native/warp.h +313 -305
  202. warp/optim/__init__.py +9 -9
  203. warp/optim/adam.py +120 -120
  204. warp/optim/linear.py +1104 -939
  205. warp/optim/sgd.py +104 -92
  206. warp/render/__init__.py +10 -10
  207. warp/render/render_opengl.py +3217 -3204
  208. warp/render/render_usd.py +768 -749
  209. warp/render/utils.py +152 -150
  210. warp/sim/__init__.py +52 -59
  211. warp/sim/articulation.py +685 -685
  212. warp/sim/collide.py +1594 -1590
  213. warp/sim/import_mjcf.py +489 -481
  214. warp/sim/import_snu.py +220 -221
  215. warp/sim/import_urdf.py +536 -516
  216. warp/sim/import_usd.py +887 -881
  217. warp/sim/inertia.py +316 -317
  218. warp/sim/integrator.py +234 -233
  219. warp/sim/integrator_euler.py +1956 -1956
  220. warp/sim/integrator_featherstone.py +1910 -1991
  221. warp/sim/integrator_xpbd.py +3294 -3312
  222. warp/sim/model.py +4473 -4314
  223. warp/sim/particles.py +113 -112
  224. warp/sim/render.py +417 -403
  225. warp/sim/utils.py +413 -410
  226. warp/sparse.py +1227 -1227
  227. warp/stubs.py +2109 -2469
  228. warp/tape.py +1162 -225
  229. warp/tests/__init__.py +1 -1
  230. warp/tests/__main__.py +4 -4
  231. warp/tests/assets/torus.usda +105 -105
  232. warp/tests/aux_test_class_kernel.py +26 -26
  233. warp/tests/aux_test_compile_consts_dummy.py +10 -10
  234. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -21
  235. warp/tests/aux_test_dependent.py +22 -22
  236. warp/tests/aux_test_grad_customs.py +23 -23
  237. warp/tests/aux_test_reference.py +11 -11
  238. warp/tests/aux_test_reference_reference.py +10 -10
  239. warp/tests/aux_test_square.py +17 -17
  240. warp/tests/aux_test_unresolved_func.py +14 -14
  241. warp/tests/aux_test_unresolved_symbol.py +14 -14
  242. warp/tests/disabled_kinematics.py +239 -239
  243. warp/tests/run_coverage_serial.py +31 -31
  244. warp/tests/test_adam.py +157 -157
  245. warp/tests/test_arithmetic.py +1124 -1124
  246. warp/tests/test_array.py +2417 -2326
  247. warp/tests/test_array_reduce.py +150 -150
  248. warp/tests/test_async.py +668 -656
  249. warp/tests/test_atomic.py +141 -141
  250. warp/tests/test_bool.py +204 -149
  251. warp/tests/test_builtins_resolution.py +1292 -1292
  252. warp/tests/test_bvh.py +164 -171
  253. warp/tests/test_closest_point_edge_edge.py +228 -228
  254. warp/tests/test_codegen.py +566 -553
  255. warp/tests/test_compile_consts.py +97 -101
  256. warp/tests/test_conditional.py +246 -246
  257. warp/tests/test_copy.py +232 -215
  258. warp/tests/test_ctypes.py +632 -632
  259. warp/tests/test_dense.py +67 -67
  260. warp/tests/test_devices.py +91 -98
  261. warp/tests/test_dlpack.py +530 -529
  262. warp/tests/test_examples.py +400 -378
  263. warp/tests/test_fabricarray.py +955 -955
  264. warp/tests/test_fast_math.py +62 -54
  265. warp/tests/test_fem.py +1277 -1278
  266. warp/tests/test_fp16.py +130 -130
  267. warp/tests/test_func.py +338 -337
  268. warp/tests/test_generics.py +571 -571
  269. warp/tests/test_grad.py +746 -640
  270. warp/tests/test_grad_customs.py +333 -336
  271. warp/tests/test_hash_grid.py +210 -164
  272. warp/tests/test_import.py +39 -39
  273. warp/tests/test_indexedarray.py +1134 -1134
  274. warp/tests/test_intersect.py +67 -67
  275. warp/tests/test_jax.py +307 -307
  276. warp/tests/test_large.py +167 -164
  277. warp/tests/test_launch.py +354 -354
  278. warp/tests/test_lerp.py +261 -261
  279. warp/tests/test_linear_solvers.py +191 -171
  280. warp/tests/test_lvalue.py +421 -493
  281. warp/tests/test_marching_cubes.py +65 -65
  282. warp/tests/test_mat.py +1801 -1827
  283. warp/tests/test_mat_lite.py +115 -115
  284. warp/tests/test_mat_scalar_ops.py +2907 -2889
  285. warp/tests/test_math.py +126 -193
  286. warp/tests/test_matmul.py +500 -499
  287. warp/tests/test_matmul_lite.py +410 -410
  288. warp/tests/test_mempool.py +188 -190
  289. warp/tests/test_mesh.py +284 -324
  290. warp/tests/test_mesh_query_aabb.py +228 -241
  291. warp/tests/test_mesh_query_point.py +692 -702
  292. warp/tests/test_mesh_query_ray.py +292 -303
  293. warp/tests/test_mlp.py +276 -276
  294. warp/tests/test_model.py +110 -110
  295. warp/tests/test_modules_lite.py +39 -39
  296. warp/tests/test_multigpu.py +163 -163
  297. warp/tests/test_noise.py +248 -248
  298. warp/tests/test_operators.py +250 -250
  299. warp/tests/test_options.py +123 -125
  300. warp/tests/test_peer.py +133 -137
  301. warp/tests/test_pinned.py +78 -78
  302. warp/tests/test_print.py +54 -54
  303. warp/tests/test_quat.py +2086 -2086
  304. warp/tests/test_rand.py +288 -288
  305. warp/tests/test_reload.py +217 -217
  306. warp/tests/test_rounding.py +179 -179
  307. warp/tests/test_runlength_encode.py +190 -190
  308. warp/tests/test_sim_grad.py +243 -0
  309. warp/tests/test_sim_kinematics.py +91 -97
  310. warp/tests/test_smoothstep.py +168 -168
  311. warp/tests/test_snippet.py +305 -266
  312. warp/tests/test_sparse.py +468 -460
  313. warp/tests/test_spatial.py +2148 -2148
  314. warp/tests/test_streams.py +486 -473
  315. warp/tests/test_struct.py +710 -675
  316. warp/tests/test_tape.py +173 -148
  317. warp/tests/test_torch.py +743 -743
  318. warp/tests/test_transient_module.py +87 -87
  319. warp/tests/test_types.py +556 -659
  320. warp/tests/test_utils.py +490 -499
  321. warp/tests/test_vec.py +1264 -1268
  322. warp/tests/test_vec_lite.py +73 -73
  323. warp/tests/test_vec_scalar_ops.py +2099 -2099
  324. warp/tests/test_verify_fp.py +94 -94
  325. warp/tests/test_volume.py +737 -736
  326. warp/tests/test_volume_write.py +255 -265
  327. warp/tests/unittest_serial.py +37 -37
  328. warp/tests/unittest_suites.py +363 -359
  329. warp/tests/unittest_utils.py +603 -578
  330. warp/tests/unused_test_misc.py +71 -71
  331. warp/tests/walkthrough_debug.py +85 -85
  332. warp/thirdparty/appdirs.py +598 -598
  333. warp/thirdparty/dlpack.py +143 -143
  334. warp/thirdparty/unittest_parallel.py +566 -561
  335. warp/torch.py +321 -295
  336. warp/types.py +4504 -4450
  337. warp/utils.py +1008 -821
  338. {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/LICENSE.md +126 -126
  339. {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/METADATA +338 -400
  340. warp_lang-1.1.0.dist-info/RECORD +352 -0
  341. warp/examples/assets/cube.usda +0 -42
  342. warp/examples/assets/sphere.usda +0 -56
  343. warp/examples/assets/torus.usda +0 -105
  344. warp_lang-1.0.1.dist-info/RECORD +0 -352
  345. {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/WHEEL +0 -0
  346. {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/top_level.txt +0 -0
warp/native/warp.cpp CHANGED
@@ -1,1052 +1,1057 @@
1
- /** Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
2
- * NVIDIA CORPORATION and its licensors retain all intellectual property
3
- * and proprietary rights in and to this software, related documentation
4
- * and any modifications thereto. Any use, reproduction, disclosure or
5
- * distribution of this software and related documentation without an express
6
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
7
- */
8
-
9
- #include "warp.h"
10
- #include "scan.h"
11
- #include "array.h"
12
- #include "exports.h"
13
- #include "error.h"
14
-
15
- #include <stdlib.h>
16
- #include <string.h>
17
-
18
- uint16_t float_to_half_bits(float x)
19
- {
20
- // adapted from Fabien Giesen's post: https://gist.github.com/rygorous/2156668
21
- union fp32
22
- {
23
- uint32_t u;
24
- float f;
25
-
26
- struct
27
- {
28
- unsigned int mantissa : 23;
29
- unsigned int exponent : 8;
30
- unsigned int sign : 1;
31
- };
32
- };
33
-
34
- fp32 f;
35
- f.f = x;
36
-
37
- fp32 f32infty = { 255 << 23 };
38
- fp32 f16infty = { 31 << 23 };
39
- fp32 magic = { 15 << 23 };
40
- uint32_t sign_mask = 0x80000000u;
41
- uint32_t round_mask = ~0xfffu;
42
- uint16_t u;
43
-
44
- uint32_t sign = f.u & sign_mask;
45
- f.u ^= sign;
46
-
47
- // NOTE all the integer compares in this function can be safely
48
- // compiled into signed compares since all operands are below
49
- // 0x80000000. Important if you want fast straight SSE2 code
50
- // (since there's no unsigned PCMPGTD).
51
-
52
- if (f.u >= f32infty.u) // Inf or NaN (all exponent bits set)
53
- u = (f.u > f32infty.u) ? 0x7e00 : 0x7c00; // NaN->qNaN and Inf->Inf
54
- else // (De)normalized number or zero
55
- {
56
- f.u &= round_mask;
57
- f.f *= magic.f;
58
- f.u -= round_mask;
59
- if (f.u > f16infty.u) f.u = f16infty.u; // Clamp to signed infinity if overflowed
60
-
61
- u = f.u >> 13; // Take the bits!
62
- }
63
-
64
- u |= sign >> 16;
65
- return u;
66
- }
67
-
68
- float half_bits_to_float(uint16_t u)
69
- {
70
- // adapted from Fabien Giesen's post: https://gist.github.com/rygorous/2156668
71
- union fp32
72
- {
73
- uint32_t u;
74
- float f;
75
-
76
- struct
77
- {
78
- unsigned int mantissa : 23;
79
- unsigned int exponent : 8;
80
- unsigned int sign : 1;
81
- };
82
- };
83
-
84
- static const fp32 magic = { 113 << 23 };
85
- static const uint32_t shifted_exp = 0x7c00 << 13; // exponent mask after shift
86
- fp32 o;
87
-
88
- o.u = (u & 0x7fff) << 13; // exponent/mantissa bits
89
- uint32_t exp = shifted_exp & o.u; // just the exponent
90
- o.u += (127 - 15) << 23; // exponent adjust
91
-
92
- // handle exponent special cases
93
- if (exp == shifted_exp) // Inf/NaN?
94
- o.u += (128 - 16) << 23; // extra exp adjust
95
- else if (exp == 0) // Zero/Denormal?
96
- {
97
- o.u += 1 << 23; // extra exp adjust
98
- o.f -= magic.f; // renormalize
99
- }
100
-
101
- o.u |= (u & 0x8000) << 16; // sign bit
102
- return o.f;
103
- }
104
-
105
- int init()
106
- {
107
- #if WP_ENABLE_CUDA
108
- int cuda_init();
109
- // note: it's safe to proceed even if CUDA initialization failed
110
- cuda_init();
111
- #endif
112
-
113
- return 0;
114
- }
115
-
116
- void shutdown()
117
- {
118
- }
119
-
120
- const char* get_error_string()
121
- {
122
- return wp::get_error_string();
123
- }
124
-
125
- void set_error_output_enabled(int enable)
126
- {
127
- wp::set_error_output_enabled(bool(enable));
128
- }
129
-
130
- int is_error_output_enabled()
131
- {
132
- return int(wp::is_error_output_enabled());
133
- }
134
-
135
- int is_cuda_enabled()
136
- {
137
- return int(WP_ENABLE_CUDA);
138
- }
139
-
140
- int is_cuda_compatibility_enabled()
141
- {
142
- return int(WP_ENABLE_CUDA_COMPATIBILITY);
143
- }
144
-
145
- int is_cutlass_enabled()
146
- {
147
- return int(WP_ENABLE_CUTLASS);
148
- }
149
-
150
- int is_debug_enabled()
151
- {
152
- return int(WP_ENABLE_DEBUG);
153
- }
154
-
155
- void* alloc_host(size_t s)
156
- {
157
- return malloc(s);
158
- }
159
-
160
- void free_host(void* ptr)
161
- {
162
- free(ptr);
163
- }
164
-
165
- bool memcpy_h2h(void* dest, void* src, size_t n)
166
- {
167
- memcpy(dest, src, n);
168
- return true;
169
- }
170
-
171
- void memset_host(void* dest, int value, size_t n)
172
- {
173
- if ((n%4) > 0)
174
- {
175
- memset(dest, value, n);
176
- }
177
- else
178
- {
179
- const size_t num_words = n/4;
180
- for (size_t i=0; i < num_words; ++i)
181
- ((int*)dest)[i] = value;
182
- }
183
- }
184
-
185
- // fill memory buffer with a value: this is a faster memtile variant
186
- // for types bigger than one byte, but requires proper alignment of dst
187
- template <typename T>
188
- void memtile_value_host(T* dst, T value, size_t n)
189
- {
190
- while (n--)
191
- *dst++ = value;
192
- }
193
-
194
- void memtile_host(void* dst, const void* src, size_t srcsize, size_t n)
195
- {
196
- size_t dst_addr = reinterpret_cast<size_t>(dst);
197
- size_t src_addr = reinterpret_cast<size_t>(src);
198
-
199
- // try memtile_value first because it should be faster, but we need to ensure proper alignment
200
- if (srcsize == 8 && (dst_addr & 7) == 0 && (src_addr & 7) == 0)
201
- memtile_value_host(reinterpret_cast<int64_t*>(dst), *reinterpret_cast<const int64_t*>(src), n);
202
- else if (srcsize == 4 && (dst_addr & 3) == 0 && (src_addr & 3) == 0)
203
- memtile_value_host(reinterpret_cast<int32_t*>(dst), *reinterpret_cast<const int32_t*>(src), n);
204
- else if (srcsize == 2 && (dst_addr & 1) == 0 && (src_addr & 1) == 0)
205
- memtile_value_host(reinterpret_cast<int16_t*>(dst), *reinterpret_cast<const int16_t*>(src), n);
206
- else if (srcsize == 1)
207
- memset(dst, *reinterpret_cast<const int8_t*>(src), n);
208
- else
209
- {
210
- // generic version
211
- while (n--)
212
- {
213
- memcpy(dst, src, srcsize);
214
- dst = (int8_t*)dst + srcsize;
215
- }
216
- }
217
- }
218
-
219
- void array_scan_int_host(uint64_t in, uint64_t out, int len, bool inclusive)
220
- {
221
- scan_host((const int*)in, (int*)out, len, inclusive);
222
- }
223
-
224
- void array_scan_float_host(uint64_t in, uint64_t out, int len, bool inclusive)
225
- {
226
- scan_host((const float*)in, (float*)out, len, inclusive);
227
- }
228
-
229
-
230
- static void array_copy_nd(void* dst, const void* src,
231
- const int* dst_strides, const int* src_strides,
232
- const int*const* dst_indices, const int*const* src_indices,
233
- const int* shape, int ndim, int elem_size)
234
- {
235
- if (ndim == 1)
236
- {
237
- for (int i = 0; i < shape[0]; i++)
238
- {
239
- int src_idx = src_indices[0] ? src_indices[0][i] : i;
240
- int dst_idx = dst_indices[0] ? dst_indices[0][i] : i;
241
- const char* p = (const char*)src + src_idx * src_strides[0];
242
- char* q = (char*)dst + dst_idx * dst_strides[0];
243
- // copy element
244
- memcpy(q, p, elem_size);
245
- }
246
- }
247
- else
248
- {
249
- for (int i = 0; i < shape[0]; i++)
250
- {
251
- int src_idx = src_indices[0] ? src_indices[0][i] : i;
252
- int dst_idx = dst_indices[0] ? dst_indices[0][i] : i;
253
- const char* p = (const char*)src + src_idx * src_strides[0];
254
- char* q = (char*)dst + dst_idx * dst_strides[0];
255
- // recurse on next inner dimension
256
- array_copy_nd(q, p, dst_strides + 1, src_strides + 1, dst_indices + 1, src_indices + 1, shape + 1, ndim - 1, elem_size);
257
- }
258
- }
259
- }
260
-
261
-
262
- static void array_copy_to_fabric(wp::fabricarray_t<void>& dst, const void* src_data,
263
- int src_stride, const int* src_indices, int elem_size)
264
- {
265
- const int8_t* src_ptr = static_cast<const int8_t*>(src_data);
266
-
267
- if (src_indices)
268
- {
269
- // copy from indexed array
270
- for (size_t i = 0; i < dst.nbuckets; i++)
271
- {
272
- const wp::fabricbucket_t& bucket = dst.buckets[i];
273
- int8_t* dst_ptr = static_cast<int8_t*>(bucket.ptr);
274
- size_t bucket_size = bucket.index_end - bucket.index_start;
275
- for (size_t j = 0; j < bucket_size; j++)
276
- {
277
- int idx = *src_indices;
278
- memcpy(dst_ptr, src_ptr + idx * elem_size, elem_size);
279
- dst_ptr += elem_size;
280
- ++src_indices;
281
- }
282
- }
283
- }
284
- else
285
- {
286
- if (src_stride == elem_size)
287
- {
288
- // copy from contiguous array
289
- for (size_t i = 0; i < dst.nbuckets; i++)
290
- {
291
- const wp::fabricbucket_t& bucket = dst.buckets[i];
292
- size_t num_bytes = (bucket.index_end - bucket.index_start) * elem_size;
293
- memcpy(bucket.ptr, src_ptr, num_bytes);
294
- src_ptr += num_bytes;
295
- }
296
- }
297
- else
298
- {
299
- // copy from strided array
300
- for (size_t i = 0; i < dst.nbuckets; i++)
301
- {
302
- const wp::fabricbucket_t& bucket = dst.buckets[i];
303
- int8_t* dst_ptr = static_cast<int8_t*>(bucket.ptr);
304
- size_t bucket_size = bucket.index_end - bucket.index_start;
305
- for (size_t j = 0; j < bucket_size; j++)
306
- {
307
- memcpy(dst_ptr, src_ptr, elem_size);
308
- src_ptr += src_stride;
309
- dst_ptr += elem_size;
310
- }
311
- }
312
- }
313
- }
314
- }
315
-
316
- static void array_copy_from_fabric(const wp::fabricarray_t<void>& src, void* dst_data,
317
- int dst_stride, const int* dst_indices, int elem_size)
318
- {
319
- int8_t* dst_ptr = static_cast<int8_t*>(dst_data);
320
-
321
- if (dst_indices)
322
- {
323
- // copy to indexed array
324
- for (size_t i = 0; i < src.nbuckets; i++)
325
- {
326
- const wp::fabricbucket_t& bucket = src.buckets[i];
327
- const int8_t* src_ptr = static_cast<const int8_t*>(bucket.ptr);
328
- size_t bucket_size = bucket.index_end - bucket.index_start;
329
- for (size_t j = 0; j < bucket_size; j++)
330
- {
331
- int idx = *dst_indices;
332
- memcpy(dst_ptr + idx * elem_size, src_ptr, elem_size);
333
- src_ptr += elem_size;
334
- ++dst_indices;
335
- }
336
- }
337
- }
338
- else
339
- {
340
- if (dst_stride == elem_size)
341
- {
342
- // copy to contiguous array
343
- for (size_t i = 0; i < src.nbuckets; i++)
344
- {
345
- const wp::fabricbucket_t& bucket = src.buckets[i];
346
- size_t num_bytes = (bucket.index_end - bucket.index_start) * elem_size;
347
- memcpy(dst_ptr, bucket.ptr, num_bytes);
348
- dst_ptr += num_bytes;
349
- }
350
- }
351
- else
352
- {
353
- // copy to strided array
354
- for (size_t i = 0; i < src.nbuckets; i++)
355
- {
356
- const wp::fabricbucket_t& bucket = src.buckets[i];
357
- const int8_t* src_ptr = static_cast<const int8_t*>(bucket.ptr);
358
- size_t bucket_size = bucket.index_end - bucket.index_start;
359
- for (size_t j = 0; j < bucket_size; j++)
360
- {
361
- memcpy(dst_ptr, src_ptr, elem_size);
362
- dst_ptr += dst_stride;
363
- src_ptr += elem_size;
364
- }
365
- }
366
- }
367
- }
368
- }
369
-
370
- static void array_copy_fabric_to_fabric(wp::fabricarray_t<void>& dst, const wp::fabricarray_t<void>& src, int elem_size)
371
- {
372
- wp::fabricbucket_t* dst_bucket = dst.buckets;
373
- const wp::fabricbucket_t* src_bucket = src.buckets;
374
- int8_t* dst_ptr = static_cast<int8_t*>(dst_bucket->ptr);
375
- const int8_t* src_ptr = static_cast<const int8_t*>(src_bucket->ptr);
376
- size_t dst_remaining = dst_bucket->index_end - dst_bucket->index_start;
377
- size_t src_remaining = src_bucket->index_end - src_bucket->index_start;
378
- size_t total_copied = 0;
379
-
380
- while (total_copied < dst.size)
381
- {
382
- if (dst_remaining <= src_remaining)
383
- {
384
- // copy to destination bucket
385
- size_t num_elems = dst_remaining;
386
- size_t num_bytes = num_elems * elem_size;
387
- memcpy(dst_ptr, src_ptr, num_bytes);
388
-
389
- // advance to next destination bucket
390
- ++dst_bucket;
391
- dst_ptr = static_cast<int8_t*>(dst_bucket->ptr);
392
- dst_remaining = dst_bucket->index_end - dst_bucket->index_start;
393
-
394
- // advance source offset
395
- src_ptr += num_bytes;
396
- src_remaining -= num_elems;
397
-
398
- total_copied += num_elems;
399
- }
400
- else
401
- {
402
- // copy to destination bucket
403
- size_t num_elems = src_remaining;
404
- size_t num_bytes = num_elems * elem_size;
405
- memcpy(dst_ptr, src_ptr, num_bytes);
406
-
407
- // advance to next source bucket
408
- ++src_bucket;
409
- src_ptr = static_cast<const int8_t*>(src_bucket->ptr);
410
- src_remaining = src_bucket->index_end - src_bucket->index_start;
411
-
412
- // advance destination offset
413
- dst_ptr += num_bytes;
414
- dst_remaining -= num_elems;
415
-
416
- total_copied += num_elems;
417
- }
418
- }
419
- }
420
-
421
-
422
- static void array_copy_to_fabric_indexed(wp::indexedfabricarray_t<void>& dst, const void* src_data,
423
- int src_stride, const int* src_indices, int elem_size)
424
- {
425
- const int8_t* src_ptr = static_cast<const int8_t*>(src_data);
426
-
427
- if (src_indices)
428
- {
429
- // copy from indexed array
430
- for (size_t i = 0; i < dst.size; i++)
431
- {
432
- size_t src_idx = src_indices[i];
433
- size_t dst_idx = dst.indices[i];
434
- void* dst_ptr = fabricarray_element_ptr(dst.fa, dst_idx, elem_size);
435
- memcpy(dst_ptr, src_ptr + dst_idx * elem_size, elem_size);
436
- }
437
- }
438
- else
439
- {
440
- // copy from contiguous/strided array
441
- for (size_t i = 0; i < dst.size; i++)
442
- {
443
- size_t dst_idx = dst.indices[i];
444
- void* dst_ptr = fabricarray_element_ptr(dst.fa, dst_idx, elem_size);
445
- if (dst_ptr)
446
- {
447
- memcpy(dst_ptr, src_ptr, elem_size);
448
- src_ptr += src_stride;
449
- }
450
- }
451
- }
452
- }
453
-
454
-
455
- static void array_copy_fabric_indexed_to_fabric(wp::fabricarray_t<void>& dst, const wp::indexedfabricarray_t<void>& src, int elem_size)
456
- {
457
- wp::fabricbucket_t* dst_bucket = dst.buckets;
458
- int8_t* dst_ptr = static_cast<int8_t*>(dst_bucket->ptr);
459
- int8_t* dst_end = dst_ptr + elem_size * (dst_bucket->index_end - dst_bucket->index_start);
460
-
461
- for (size_t i = 0; i < src.size; i++)
462
- {
463
- size_t src_idx = src.indices[i];
464
- const void* src_ptr = fabricarray_element_ptr(src.fa, src_idx, elem_size);
465
-
466
- if (dst_ptr >= dst_end)
467
- {
468
- // advance to next destination bucket
469
- ++dst_bucket;
470
- dst_ptr = static_cast<int8_t*>(dst_bucket->ptr);
471
- dst_end = dst_ptr + elem_size * (dst_bucket->index_end - dst_bucket->index_start);
472
- }
473
-
474
- memcpy(dst_ptr, src_ptr, elem_size);
475
-
476
- dst_ptr += elem_size;
477
- }
478
- }
479
-
480
-
481
- static void array_copy_fabric_indexed_to_fabric_indexed(wp::indexedfabricarray_t<void>& dst, const wp::indexedfabricarray_t<void>& src, int elem_size)
482
- {
483
- for (size_t i = 0; i < src.size; i++)
484
- {
485
- size_t src_idx = src.indices[i];
486
- size_t dst_idx = dst.indices[i];
487
-
488
- const void* src_ptr = fabricarray_element_ptr(src.fa, src_idx, elem_size);
489
- void* dst_ptr = fabricarray_element_ptr(dst.fa, dst_idx, elem_size);
490
-
491
- memcpy(dst_ptr, src_ptr, elem_size);
492
- }
493
- }
494
-
495
-
496
- static void array_copy_fabric_to_fabric_indexed(wp::indexedfabricarray_t<void>& dst, const wp::fabricarray_t<void>& src, int elem_size)
497
- {
498
- wp::fabricbucket_t* src_bucket = src.buckets;
499
- const int8_t* src_ptr = static_cast<const int8_t*>(src_bucket->ptr);
500
- const int8_t* src_end = src_ptr + elem_size * (src_bucket->index_end - src_bucket->index_start);
501
-
502
- for (size_t i = 0; i < dst.size; i++)
503
- {
504
- size_t dst_idx = dst.indices[i];
505
- void* dst_ptr = fabricarray_element_ptr(dst.fa, dst_idx, elem_size);
506
-
507
- if (src_ptr >= src_end)
508
- {
509
- // advance to next source bucket
510
- ++src_bucket;
511
- src_ptr = static_cast<int8_t*>(src_bucket->ptr);
512
- src_end = src_ptr + elem_size * (src_bucket->index_end - src_bucket->index_start);
513
- }
514
-
515
- memcpy(dst_ptr, src_ptr, elem_size);
516
-
517
- src_ptr += elem_size;
518
- }
519
- }
520
-
521
-
522
- static void array_copy_from_fabric_indexed(const wp::indexedfabricarray_t<void>& src, void* dst_data,
523
- int dst_stride, const int* dst_indices, int elem_size)
524
- {
525
- int8_t* dst_ptr = static_cast<int8_t*>(dst_data);
526
-
527
- if (dst_indices)
528
- {
529
- // copy to indexed array
530
- for (size_t i = 0; i < src.size; i++)
531
- {
532
- size_t idx = src.indices[i];
533
- if (idx < src.fa.size)
534
- {
535
- const void* src_ptr = fabricarray_element_ptr(src.fa, idx, elem_size);
536
- int dst_idx = dst_indices[i];
537
- memcpy(dst_ptr + dst_idx * elem_size, src_ptr, elem_size);
538
- }
539
- else
540
- {
541
- fprintf(stderr, "Warp copy error: Source index %llu is out of bounds for fabric array of size %llu",
542
- (unsigned long long)idx, (unsigned long long)src.fa.size);
543
- }
544
- }
545
- }
546
- else
547
- {
548
- // copy to contiguous/strided array
549
- for (size_t i = 0; i < src.size; i++)
550
- {
551
- size_t idx = src.indices[i];
552
- if (idx < src.fa.size)
553
- {
554
- const void* src_ptr = fabricarray_element_ptr(src.fa, idx, elem_size);
555
- memcpy(dst_ptr, src_ptr, elem_size);
556
- dst_ptr += dst_stride;
557
- }
558
- else
559
- {
560
- fprintf(stderr, "Warp copy error: Source index %llu is out of bounds for fabric array of size %llu",
561
- (unsigned long long)idx, (unsigned long long)src.fa.size);
562
- }
563
- }
564
- }
565
- }
566
-
567
-
568
- WP_API bool array_copy_host(void* dst, void* src, int dst_type, int src_type, int elem_size)
569
- {
570
- if (!src || !dst)
571
- return false;
572
-
573
- const void* src_data = NULL;
574
- void* dst_data = NULL;
575
- int src_ndim = 0;
576
- int dst_ndim = 0;
577
- const int* src_shape = NULL;
578
- const int* dst_shape = NULL;
579
- const int* src_strides = NULL;
580
- const int* dst_strides = NULL;
581
- const int*const* src_indices = NULL;
582
- const int*const* dst_indices = NULL;
583
-
584
- const wp::fabricarray_t<void>* src_fabricarray = NULL;
585
- wp::fabricarray_t<void>* dst_fabricarray = NULL;
586
-
587
- const wp::indexedfabricarray_t<void>* src_indexedfabricarray = NULL;
588
- wp::indexedfabricarray_t<void>* dst_indexedfabricarray = NULL;
589
-
590
- const int* null_indices[wp::ARRAY_MAX_DIMS] = { NULL };
591
-
592
- if (src_type == wp::ARRAY_TYPE_REGULAR)
593
- {
594
- const wp::array_t<void>& src_arr = *static_cast<const wp::array_t<void>*>(src);
595
- src_data = src_arr.data;
596
- src_ndim = src_arr.ndim;
597
- src_shape = src_arr.shape.dims;
598
- src_strides = src_arr.strides;
599
- src_indices = null_indices;
600
- }
601
- else if (src_type == wp::ARRAY_TYPE_INDEXED)
602
- {
603
- const wp::indexedarray_t<void>& src_arr = *static_cast<const wp::indexedarray_t<void>*>(src);
604
- src_data = src_arr.arr.data;
605
- src_ndim = src_arr.arr.ndim;
606
- src_shape = src_arr.shape.dims;
607
- src_strides = src_arr.arr.strides;
608
- src_indices = src_arr.indices;
609
- }
610
- else if (src_type == wp::ARRAY_TYPE_FABRIC)
611
- {
612
- src_fabricarray = static_cast<const wp::fabricarray_t<void>*>(src);
613
- src_ndim = 1;
614
- }
615
- else if (src_type == wp::ARRAY_TYPE_FABRIC_INDEXED)
616
- {
617
- src_indexedfabricarray = static_cast<const wp::indexedfabricarray_t<void>*>(src);
618
- src_ndim = 1;
619
- }
620
- else
621
- {
622
- fprintf(stderr, "Warp copy error: Invalid source array type (%d)\n", src_type);
623
- return false;
624
- }
625
-
626
- if (dst_type == wp::ARRAY_TYPE_REGULAR)
627
- {
628
- const wp::array_t<void>& dst_arr = *static_cast<const wp::array_t<void>*>(dst);
629
- dst_data = dst_arr.data;
630
- dst_ndim = dst_arr.ndim;
631
- dst_shape = dst_arr.shape.dims;
632
- dst_strides = dst_arr.strides;
633
- dst_indices = null_indices;
634
- }
635
- else if (dst_type == wp::ARRAY_TYPE_INDEXED)
636
- {
637
- const wp::indexedarray_t<void>& dst_arr = *static_cast<const wp::indexedarray_t<void>*>(dst);
638
- dst_data = dst_arr.arr.data;
639
- dst_ndim = dst_arr.arr.ndim;
640
- dst_shape = dst_arr.shape.dims;
641
- dst_strides = dst_arr.arr.strides;
642
- dst_indices = dst_arr.indices;
643
- }
644
- else if (dst_type == wp::ARRAY_TYPE_FABRIC)
645
- {
646
- dst_fabricarray = static_cast<wp::fabricarray_t<void>*>(dst);
647
- dst_ndim = 1;
648
- }
649
- else if (dst_type == wp::ARRAY_TYPE_FABRIC_INDEXED)
650
- {
651
- dst_indexedfabricarray = static_cast<wp::indexedfabricarray_t<void>*>(dst);
652
- dst_ndim = 1;
653
- }
654
- else
655
- {
656
- fprintf(stderr, "Warp copy error: Invalid destination array type (%d)\n", dst_type);
657
- return false;
658
- }
659
-
660
- if (src_ndim != dst_ndim)
661
- {
662
- fprintf(stderr, "Warp copy error: Incompatible array dimensionalities (%d and %d)\n", src_ndim, dst_ndim);
663
- return false;
664
- }
665
-
666
- // handle fabric arrays
667
- if (dst_fabricarray)
668
- {
669
- size_t n = dst_fabricarray->size;
670
- if (src_fabricarray)
671
- {
672
- // copy from fabric to fabric
673
- if (src_fabricarray->size != n)
674
- {
675
- fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
676
- return false;
677
- }
678
- array_copy_fabric_to_fabric(*dst_fabricarray, *src_fabricarray, elem_size);
679
- return true;
680
- }
681
- else if (src_indexedfabricarray)
682
- {
683
- // copy from fabric indexed to fabric
684
- if (src_indexedfabricarray->size != n)
685
- {
686
- fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
687
- return false;
688
- }
689
- array_copy_fabric_indexed_to_fabric(*dst_fabricarray, *src_indexedfabricarray, elem_size);
690
- return true;
691
- }
692
- else
693
- {
694
- // copy to fabric
695
- if (size_t(src_shape[0]) != n)
696
- {
697
- fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
698
- return false;
699
- }
700
- array_copy_to_fabric(*dst_fabricarray, src_data, src_strides[0], src_indices[0], elem_size);
701
- return true;
702
- }
703
- }
704
- else if (dst_indexedfabricarray)
705
- {
706
- size_t n = dst_indexedfabricarray->size;
707
- if (src_fabricarray)
708
- {
709
- // copy from fabric to fabric indexed
710
- if (src_fabricarray->size != n)
711
- {
712
- fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
713
- return false;
714
- }
715
- array_copy_fabric_to_fabric_indexed(*dst_indexedfabricarray, *src_fabricarray, elem_size);
716
- return true;
717
- }
718
- else if (src_indexedfabricarray)
719
- {
720
- // copy from fabric indexed to fabric indexed
721
- if (src_indexedfabricarray->size != n)
722
- {
723
- fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
724
- return false;
725
- }
726
- array_copy_fabric_indexed_to_fabric_indexed(*dst_indexedfabricarray, *src_indexedfabricarray, elem_size);
727
- return true;
728
- }
729
- else
730
- {
731
- // copy to fabric indexed
732
- if (size_t(src_shape[0]) != n)
733
- {
734
- fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
735
- return false;
736
- }
737
- array_copy_to_fabric_indexed(*dst_indexedfabricarray, src_data, src_strides[0], src_indices[0], elem_size);
738
- return true;
739
- }
740
- }
741
- else if (src_fabricarray)
742
- {
743
- // copy from fabric
744
- size_t n = src_fabricarray->size;
745
- if (size_t(dst_shape[0]) != n)
746
- {
747
- fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
748
- return false;
749
- }
750
- array_copy_from_fabric(*src_fabricarray, dst_data, dst_strides[0], dst_indices[0], elem_size);
751
- return true;
752
- }
753
- else if (src_indexedfabricarray)
754
- {
755
- // copy from fabric indexed
756
- size_t n = src_indexedfabricarray->size;
757
- if (size_t(dst_shape[0]) != n)
758
- {
759
- fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
760
- return false;
761
- }
762
- array_copy_from_fabric_indexed(*src_indexedfabricarray, dst_data, dst_strides[0], dst_indices[0], elem_size);
763
- return true;
764
- }
765
-
766
- for (int i = 0; i < src_ndim; i++)
767
- {
768
- if (src_shape[i] != dst_shape[i])
769
- {
770
- fprintf(stderr, "Warp copy error: Incompatible array shapes\n");
771
- return 0;
772
- }
773
- }
774
-
775
- array_copy_nd(dst_data, src_data,
776
- dst_strides, src_strides,
777
- dst_indices, src_indices,
778
- src_shape, src_ndim, elem_size);
779
-
780
- return true;
781
- }
782
-
783
-
784
- static void array_fill_strided(void* data, const int* shape, const int* strides, int ndim, const void* value, int value_size)
785
- {
786
- if (ndim == 1)
787
- {
788
- char* p = (char*)data;
789
- for (int i = 0; i < shape[0]; i++)
790
- {
791
- memcpy(p, value, value_size);
792
- p += strides[0];
793
- }
794
- }
795
- else
796
- {
797
- for (int i = 0; i < shape[0]; i++)
798
- {
799
- char* p = (char*)data + i * strides[0];
800
- // recurse on next inner dimension
801
- array_fill_strided(p, shape + 1, strides + 1, ndim - 1, value, value_size);
802
- }
803
- }
804
- }
805
-
806
-
807
- static void array_fill_indexed(void* data, const int* shape, const int* strides, const int*const* indices, int ndim, const void* value, int value_size)
808
- {
809
- if (ndim == 1)
810
- {
811
- for (int i = 0; i < shape[0]; i++)
812
- {
813
- int idx = indices[0] ? indices[0][i] : i;
814
- char* p = (char*)data + idx * strides[0];
815
- memcpy(p, value, value_size);
816
- }
817
- }
818
- else
819
- {
820
- for (int i = 0; i < shape[0]; i++)
821
- {
822
- int idx = indices[0] ? indices[0][i] : i;
823
- char* p = (char*)data + idx * strides[0];
824
- // recurse on next inner dimension
825
- array_fill_indexed(p, shape + 1, strides + 1, indices + 1, ndim - 1, value, value_size);
826
- }
827
- }
828
- }
829
-
830
-
831
- static void array_fill_fabric(wp::fabricarray_t<void>& fa, const void* value_ptr, int value_size)
832
- {
833
- for (size_t i = 0; i < fa.nbuckets; i++)
834
- {
835
- const wp::fabricbucket_t& bucket = fa.buckets[i];
836
- size_t bucket_size = bucket.index_end - bucket.index_start;
837
- memtile_host(bucket.ptr, value_ptr, value_size, bucket_size);
838
- }
839
- }
840
-
841
-
842
- static void array_fill_fabric_indexed(wp::indexedfabricarray_t<void>& ifa, const void* value_ptr, int value_size)
843
- {
844
- for (size_t i = 0; i < ifa.size; i++)
845
- {
846
- size_t idx = size_t(ifa.indices[i]);
847
- if (idx < ifa.fa.size)
848
- {
849
- void* p = fabricarray_element_ptr(ifa.fa, idx, value_size);
850
- memcpy(p, value_ptr, value_size);
851
- }
852
- }
853
- }
854
-
855
-
856
- WP_API void array_fill_host(void* arr_ptr, int arr_type, const void* value_ptr, int value_size)
857
- {
858
- if (!arr_ptr || !value_ptr)
859
- return;
860
-
861
- if (arr_type == wp::ARRAY_TYPE_REGULAR)
862
- {
863
- wp::array_t<void>& arr = *static_cast<wp::array_t<void>*>(arr_ptr);
864
- array_fill_strided(arr.data, arr.shape.dims, arr.strides, arr.ndim, value_ptr, value_size);
865
- }
866
- else if (arr_type == wp::ARRAY_TYPE_INDEXED)
867
- {
868
- wp::indexedarray_t<void>& ia = *static_cast<wp::indexedarray_t<void>*>(arr_ptr);
869
- array_fill_indexed(ia.arr.data, ia.shape.dims, ia.arr.strides, ia.indices, ia.arr.ndim, value_ptr, value_size);
870
- }
871
- else if (arr_type == wp::ARRAY_TYPE_FABRIC)
872
- {
873
- wp::fabricarray_t<void>& fa = *static_cast<wp::fabricarray_t<void>*>(arr_ptr);
874
- array_fill_fabric(fa, value_ptr, value_size);
875
- }
876
- else if (arr_type == wp::ARRAY_TYPE_FABRIC_INDEXED)
877
- {
878
- wp::indexedfabricarray_t<void>& ifa = *static_cast<wp::indexedfabricarray_t<void>*>(arr_ptr);
879
- array_fill_fabric_indexed(ifa, value_ptr, value_size);
880
- }
881
- else
882
- {
883
- fprintf(stderr, "Warp fill error: Invalid array type id %d\n", arr_type);
884
- }
885
- }
886
-
887
-
888
- // impl. files
889
- // TODO: compile as separate translation units
890
- #include "bvh.cpp"
891
- #include "scan.cpp"
892
-
893
-
894
- // stubs for platforms where there is no CUDA
895
- #if !WP_ENABLE_CUDA
896
-
897
- void* alloc_pinned(size_t s)
898
- {
899
- // CUDA is not available, fall back on system allocator
900
- return alloc_host(s);
901
- }
902
-
903
- void free_pinned(void* ptr)
904
- {
905
- // CUDA is not available, fall back on system allocator
906
- free_host(ptr);
907
- }
908
-
909
- void* alloc_device(void* context, size_t s)
910
- {
911
- return NULL;
912
- }
913
-
914
- void* alloc_device_default(void* context, size_t s)
915
- {
916
- return NULL;
917
- }
918
-
919
- void* alloc_device_async(void* context, size_t s)
920
- {
921
- return NULL;
922
- }
923
-
924
- void free_device(void* context, void* ptr)
925
- {
926
- }
927
-
928
- void free_device_default(void* context, void* ptr)
929
- {
930
- }
931
-
932
- void free_device_async(void* context, void* ptr)
933
- {
934
- }
935
-
936
- bool memcpy_h2d(void* context, void* dest, void* src, size_t n, void* stream)
937
- {
938
- return false;
939
- }
940
-
941
- bool memcpy_d2h(void* context, void* dest, void* src, size_t n, void* stream)
942
- {
943
- return false;
944
- }
945
-
946
- bool memcpy_d2d(void* context, void* dest, void* src, size_t n, void* stream)
947
- {
948
- return false;
949
- }
950
-
951
- bool memcpy_p2p(void* dst_context, void* dst, void* src_context, void* src, size_t n, void* stream)
952
- {
953
- return false;
954
- }
955
-
956
- void memset_device(void* context, void* dest, int value, size_t n)
957
- {
958
- }
959
-
960
- void memtile_device(void* context, void* dest, const void* src, size_t srcsize, size_t n)
961
- {
962
- }
963
-
964
- bool array_copy_device(void* context, void* dst, void* src, int dst_type, int src_type, int elem_size)
965
- {
966
- return false;
967
- }
968
-
969
- void array_fill_device(void* context, void* arr, int arr_type, const void* value, int value_size)
970
- {
971
- }
972
-
973
- WP_API int cuda_driver_version() { return 0; }
974
- WP_API int cuda_toolkit_version() { return 0; }
975
- WP_API bool cuda_driver_is_initialized() { return false; }
976
-
977
- WP_API int nvrtc_supported_arch_count() { return 0; }
978
- WP_API void nvrtc_supported_archs(int* archs) {}
979
-
980
- WP_API int cuda_device_get_count() { return 0; }
981
- WP_API void* cuda_device_get_primary_context(int ordinal) { return NULL; }
982
- WP_API const char* cuda_device_get_name(int ordinal) { return NULL; }
983
- WP_API int cuda_device_get_arch(int ordinal) { return 0; }
984
- WP_API void cuda_device_get_uuid(int ordinal, char uuid[16]) {}
985
- WP_API int cuda_device_get_pci_domain_id(int ordinal) { return -1; }
986
- WP_API int cuda_device_get_pci_bus_id(int ordinal) { return -1; }
987
- WP_API int cuda_device_get_pci_device_id(int ordinal) { return -1; }
988
- WP_API int cuda_device_is_uva(int ordinal) { return 0; }
989
- WP_API int cuda_device_is_mempool_supported(int ordinal) { return 0; }
990
- WP_API int cuda_device_set_mempool_release_threshold(int ordinal, uint64_t threshold) { return 0; }
991
- WP_API uint64_t cuda_device_get_mempool_release_threshold(int ordinal) { return 0; }
992
- WP_API void cuda_device_get_memory_info(int ordinal, size_t* free_mem, size_t* total_mem) {}
993
-
994
- WP_API void* cuda_context_get_current() { return NULL; }
995
- WP_API void cuda_context_set_current(void* ctx) {}
996
- WP_API void cuda_context_push_current(void* context) {}
997
- WP_API void cuda_context_pop_current() {}
998
- WP_API void* cuda_context_create(int device_ordinal) { return NULL; }
999
- WP_API void cuda_context_destroy(void* context) {}
1000
- WP_API void cuda_context_synchronize(void* context) {}
1001
- WP_API uint64_t cuda_context_check(void* context) { return 0; }
1002
- WP_API int cuda_context_get_device_ordinal(void* context) { return -1; }
1003
- WP_API int cuda_context_is_primary(void* context) { return 0; }
1004
- WP_API void* cuda_context_get_stream(void* context) { return NULL; }
1005
- WP_API void cuda_context_set_stream(void* context, void* stream, int sync) {}
1006
-
1007
- WP_API int cuda_is_peer_access_supported(int target_ordinal, int peer_ordinal) { return 0; }
1008
- WP_API int cuda_is_peer_access_enabled(void* target_context, void* peer_context) { return 0; }
1009
- WP_API int cuda_set_peer_access_enabled(void* target_context, void* peer_context, int enable) { return 0; }
1010
- WP_API int cuda_is_mempool_access_enabled(int target_ordinal, int peer_ordinal) { return 0; }
1011
- WP_API int cuda_set_mempool_access_enabled(int target_ordinal, int peer_ordinal, int enable) { return 0; }
1012
-
1013
- WP_API void* cuda_stream_create(void* context) { return NULL; }
1014
- WP_API void cuda_stream_destroy(void* context, void* stream) {}
1015
- WP_API void cuda_stream_register(void* context, void* stream) {}
1016
- WP_API void cuda_stream_unregister(void* context, void* stream) {}
1017
- WP_API void* cuda_stream_get_current() { return NULL; }
1018
- WP_API void cuda_stream_synchronize(void* stream) {}
1019
- WP_API void cuda_stream_wait_event(void* stream, void* event) {}
1020
- WP_API void cuda_stream_wait_stream(void* stream, void* other_stream, void* event) {}
1021
- WP_API int cuda_stream_is_capturing(void* stream) { return 0; }
1022
-
1023
- WP_API void* cuda_event_create(void* context, unsigned flags) { return NULL; }
1024
- WP_API void cuda_event_destroy(void* event) {}
1025
- WP_API void cuda_event_record(void* event, void* stream) {}
1026
- WP_API void cuda_event_synchronize(void* event) {}
1027
-
1028
- WP_API bool cuda_graph_begin_capture(void* context, void* stream, int external) { return false; }
1029
- WP_API bool cuda_graph_end_capture(void* context, void* stream, void** graph_ret) { return false; }
1030
- WP_API bool cuda_graph_launch(void* graph, void* stream) { return false; }
1031
- WP_API bool cuda_graph_destroy(void* context, void* graph) { return false; }
1032
-
1033
- WP_API size_t cuda_compile_program(const char* cuda_src, int arch, const char* include_dir, bool debug, bool verbose, bool verify_fp, bool fast_math, const char* output_file) { return 0; }
1034
-
1035
- WP_API void* cuda_load_module(void* context, const char* ptx) { return NULL; }
1036
- WP_API void cuda_unload_module(void* context, void* module) {}
1037
- WP_API void* cuda_get_kernel(void* context, void* module, const char* name) { return NULL; }
1038
- WP_API size_t cuda_launch_kernel(void* context, void* kernel, size_t dim, int max_blocks, void** args, void* stream) { return 0; }
1039
-
1040
- WP_API void cuda_set_context_restore_policy(bool always_restore) {}
1041
- WP_API int cuda_get_context_restore_policy() { return false; }
1042
-
1043
- WP_API void array_scan_int_device(uint64_t in, uint64_t out, int len, bool inclusive) {}
1044
- WP_API void array_scan_float_device(uint64_t in, uint64_t out, int len, bool inclusive) {}
1045
-
1046
- WP_API void cuda_graphics_map(void* context, void* resource) {}
1047
- WP_API void cuda_graphics_unmap(void* context, void* resource) {}
1048
- WP_API void cuda_graphics_device_ptr_and_size(void* context, void* resource, uint64_t* ptr, size_t* size) {}
1049
- WP_API void* cuda_graphics_register_gl_buffer(void* context, uint32_t gl_buffer, unsigned int flags) { return NULL; }
1050
- WP_API void cuda_graphics_unregister_resource(void* context, void* resource) {}
1051
-
1052
- #endif // !WP_ENABLE_CUDA
1
+ /** Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
2
+ * NVIDIA CORPORATION and its licensors retain all intellectual property
3
+ * and proprietary rights in and to this software, related documentation
4
+ * and any modifications thereto. Any use, reproduction, disclosure or
5
+ * distribution of this software and related documentation without an express
6
+ * license agreement from NVIDIA CORPORATION is strictly prohibited.
7
+ */
8
+
9
+ #include "warp.h"
10
+ #include "scan.h"
11
+ #include "array.h"
12
+ #include "exports.h"
13
+ #include "error.h"
14
+
15
+ #include <stdlib.h>
16
+ #include <string.h>
17
+
18
+ uint16_t float_to_half_bits(float x)
19
+ {
20
+ // adapted from Fabien Giesen's post: https://gist.github.com/rygorous/2156668
21
+ union fp32
22
+ {
23
+ uint32_t u;
24
+ float f;
25
+
26
+ struct
27
+ {
28
+ unsigned int mantissa : 23;
29
+ unsigned int exponent : 8;
30
+ unsigned int sign : 1;
31
+ };
32
+ };
33
+
34
+ fp32 f;
35
+ f.f = x;
36
+
37
+ fp32 f32infty = { 255 << 23 };
38
+ fp32 f16infty = { 31 << 23 };
39
+ fp32 magic = { 15 << 23 };
40
+ uint32_t sign_mask = 0x80000000u;
41
+ uint32_t round_mask = ~0xfffu;
42
+ uint16_t u;
43
+
44
+ uint32_t sign = f.u & sign_mask;
45
+ f.u ^= sign;
46
+
47
+ // NOTE all the integer compares in this function can be safely
48
+ // compiled into signed compares since all operands are below
49
+ // 0x80000000. Important if you want fast straight SSE2 code
50
+ // (since there's no unsigned PCMPGTD).
51
+
52
+ if (f.u >= f32infty.u) // Inf or NaN (all exponent bits set)
53
+ u = (f.u > f32infty.u) ? 0x7e00 : 0x7c00; // NaN->qNaN and Inf->Inf
54
+ else // (De)normalized number or zero
55
+ {
56
+ f.u &= round_mask;
57
+ f.f *= magic.f;
58
+ f.u -= round_mask;
59
+ if (f.u > f16infty.u) f.u = f16infty.u; // Clamp to signed infinity if overflowed
60
+
61
+ u = f.u >> 13; // Take the bits!
62
+ }
63
+
64
+ u |= sign >> 16;
65
+ return u;
66
+ }
67
+
68
+ float half_bits_to_float(uint16_t u)
69
+ {
70
+ // adapted from Fabien Giesen's post: https://gist.github.com/rygorous/2156668
71
+ union fp32
72
+ {
73
+ uint32_t u;
74
+ float f;
75
+
76
+ struct
77
+ {
78
+ unsigned int mantissa : 23;
79
+ unsigned int exponent : 8;
80
+ unsigned int sign : 1;
81
+ };
82
+ };
83
+
84
+ static const fp32 magic = { 113 << 23 };
85
+ static const uint32_t shifted_exp = 0x7c00 << 13; // exponent mask after shift
86
+ fp32 o;
87
+
88
+ o.u = (u & 0x7fff) << 13; // exponent/mantissa bits
89
+ uint32_t exp = shifted_exp & o.u; // just the exponent
90
+ o.u += (127 - 15) << 23; // exponent adjust
91
+
92
+ // handle exponent special cases
93
+ if (exp == shifted_exp) // Inf/NaN?
94
+ o.u += (128 - 16) << 23; // extra exp adjust
95
+ else if (exp == 0) // Zero/Denormal?
96
+ {
97
+ o.u += 1 << 23; // extra exp adjust
98
+ o.f -= magic.f; // renormalize
99
+ }
100
+
101
+ o.u |= (u & 0x8000) << 16; // sign bit
102
+ return o.f;
103
+ }
104
+
105
+ int init()
106
+ {
107
+ #if WP_ENABLE_CUDA
108
+ int cuda_init();
109
+ // note: it's safe to proceed even if CUDA initialization failed
110
+ cuda_init();
111
+ #endif
112
+
113
+ return 0;
114
+ }
115
+
116
+ void shutdown()
117
+ {
118
+ }
119
+
120
+ const char* get_error_string()
121
+ {
122
+ return wp::get_error_string();
123
+ }
124
+
125
+ void set_error_output_enabled(int enable)
126
+ {
127
+ wp::set_error_output_enabled(bool(enable));
128
+ }
129
+
130
+ int is_error_output_enabled()
131
+ {
132
+ return int(wp::is_error_output_enabled());
133
+ }
134
+
135
+ int is_cuda_enabled()
136
+ {
137
+ return int(WP_ENABLE_CUDA);
138
+ }
139
+
140
+ int is_cuda_compatibility_enabled()
141
+ {
142
+ return int(WP_ENABLE_CUDA_COMPATIBILITY);
143
+ }
144
+
145
+ int is_cutlass_enabled()
146
+ {
147
+ return int(WP_ENABLE_CUTLASS);
148
+ }
149
+
150
+ int is_debug_enabled()
151
+ {
152
+ return int(WP_ENABLE_DEBUG);
153
+ }
154
+
155
+ void* alloc_host(size_t s)
156
+ {
157
+ return malloc(s);
158
+ }
159
+
160
+ void free_host(void* ptr)
161
+ {
162
+ free(ptr);
163
+ }
164
+
165
+ bool memcpy_h2h(void* dest, void* src, size_t n)
166
+ {
167
+ memcpy(dest, src, n);
168
+ return true;
169
+ }
170
+
171
+ void memset_host(void* dest, int value, size_t n)
172
+ {
173
+ if ((n%4) > 0)
174
+ {
175
+ memset(dest, value, n);
176
+ }
177
+ else
178
+ {
179
+ const size_t num_words = n/4;
180
+ for (size_t i=0; i < num_words; ++i)
181
+ ((int*)dest)[i] = value;
182
+ }
183
+ }
184
+
185
+ // fill memory buffer with a value: this is a faster memtile variant
186
+ // for types bigger than one byte, but requires proper alignment of dst
187
+ template <typename T>
188
+ void memtile_value_host(T* dst, T value, size_t n)
189
+ {
190
+ while (n--)
191
+ *dst++ = value;
192
+ }
193
+
194
+ void memtile_host(void* dst, const void* src, size_t srcsize, size_t n)
195
+ {
196
+ size_t dst_addr = reinterpret_cast<size_t>(dst);
197
+ size_t src_addr = reinterpret_cast<size_t>(src);
198
+
199
+ // try memtile_value first because it should be faster, but we need to ensure proper alignment
200
+ if (srcsize == 8 && (dst_addr & 7) == 0 && (src_addr & 7) == 0)
201
+ memtile_value_host(reinterpret_cast<int64_t*>(dst), *reinterpret_cast<const int64_t*>(src), n);
202
+ else if (srcsize == 4 && (dst_addr & 3) == 0 && (src_addr & 3) == 0)
203
+ memtile_value_host(reinterpret_cast<int32_t*>(dst), *reinterpret_cast<const int32_t*>(src), n);
204
+ else if (srcsize == 2 && (dst_addr & 1) == 0 && (src_addr & 1) == 0)
205
+ memtile_value_host(reinterpret_cast<int16_t*>(dst), *reinterpret_cast<const int16_t*>(src), n);
206
+ else if (srcsize == 1)
207
+ memset(dst, *reinterpret_cast<const int8_t*>(src), n);
208
+ else
209
+ {
210
+ // generic version
211
+ while (n--)
212
+ {
213
+ memcpy(dst, src, srcsize);
214
+ dst = (int8_t*)dst + srcsize;
215
+ }
216
+ }
217
+ }
218
+
219
+ void array_scan_int_host(uint64_t in, uint64_t out, int len, bool inclusive)
220
+ {
221
+ scan_host((const int*)in, (int*)out, len, inclusive);
222
+ }
223
+
224
+ void array_scan_float_host(uint64_t in, uint64_t out, int len, bool inclusive)
225
+ {
226
+ scan_host((const float*)in, (float*)out, len, inclusive);
227
+ }
228
+
229
+
230
+ static void array_copy_nd(void* dst, const void* src,
231
+ const int* dst_strides, const int* src_strides,
232
+ const int*const* dst_indices, const int*const* src_indices,
233
+ const int* shape, int ndim, int elem_size)
234
+ {
235
+ if (ndim == 1)
236
+ {
237
+ for (int i = 0; i < shape[0]; i++)
238
+ {
239
+ int src_idx = src_indices[0] ? src_indices[0][i] : i;
240
+ int dst_idx = dst_indices[0] ? dst_indices[0][i] : i;
241
+ const char* p = (const char*)src + src_idx * src_strides[0];
242
+ char* q = (char*)dst + dst_idx * dst_strides[0];
243
+ // copy element
244
+ memcpy(q, p, elem_size);
245
+ }
246
+ }
247
+ else
248
+ {
249
+ for (int i = 0; i < shape[0]; i++)
250
+ {
251
+ int src_idx = src_indices[0] ? src_indices[0][i] : i;
252
+ int dst_idx = dst_indices[0] ? dst_indices[0][i] : i;
253
+ const char* p = (const char*)src + src_idx * src_strides[0];
254
+ char* q = (char*)dst + dst_idx * dst_strides[0];
255
+ // recurse on next inner dimension
256
+ array_copy_nd(q, p, dst_strides + 1, src_strides + 1, dst_indices + 1, src_indices + 1, shape + 1, ndim - 1, elem_size);
257
+ }
258
+ }
259
+ }
260
+
261
+
262
+ static void array_copy_to_fabric(wp::fabricarray_t<void>& dst, const void* src_data,
263
+ int src_stride, const int* src_indices, int elem_size)
264
+ {
265
+ const int8_t* src_ptr = static_cast<const int8_t*>(src_data);
266
+
267
+ if (src_indices)
268
+ {
269
+ // copy from indexed array
270
+ for (size_t i = 0; i < dst.nbuckets; i++)
271
+ {
272
+ const wp::fabricbucket_t& bucket = dst.buckets[i];
273
+ int8_t* dst_ptr = static_cast<int8_t*>(bucket.ptr);
274
+ size_t bucket_size = bucket.index_end - bucket.index_start;
275
+ for (size_t j = 0; j < bucket_size; j++)
276
+ {
277
+ int idx = *src_indices;
278
+ memcpy(dst_ptr, src_ptr + idx * elem_size, elem_size);
279
+ dst_ptr += elem_size;
280
+ ++src_indices;
281
+ }
282
+ }
283
+ }
284
+ else
285
+ {
286
+ if (src_stride == elem_size)
287
+ {
288
+ // copy from contiguous array
289
+ for (size_t i = 0; i < dst.nbuckets; i++)
290
+ {
291
+ const wp::fabricbucket_t& bucket = dst.buckets[i];
292
+ size_t num_bytes = (bucket.index_end - bucket.index_start) * elem_size;
293
+ memcpy(bucket.ptr, src_ptr, num_bytes);
294
+ src_ptr += num_bytes;
295
+ }
296
+ }
297
+ else
298
+ {
299
+ // copy from strided array
300
+ for (size_t i = 0; i < dst.nbuckets; i++)
301
+ {
302
+ const wp::fabricbucket_t& bucket = dst.buckets[i];
303
+ int8_t* dst_ptr = static_cast<int8_t*>(bucket.ptr);
304
+ size_t bucket_size = bucket.index_end - bucket.index_start;
305
+ for (size_t j = 0; j < bucket_size; j++)
306
+ {
307
+ memcpy(dst_ptr, src_ptr, elem_size);
308
+ src_ptr += src_stride;
309
+ dst_ptr += elem_size;
310
+ }
311
+ }
312
+ }
313
+ }
314
+ }
315
+
316
+ static void array_copy_from_fabric(const wp::fabricarray_t<void>& src, void* dst_data,
317
+ int dst_stride, const int* dst_indices, int elem_size)
318
+ {
319
+ int8_t* dst_ptr = static_cast<int8_t*>(dst_data);
320
+
321
+ if (dst_indices)
322
+ {
323
+ // copy to indexed array
324
+ for (size_t i = 0; i < src.nbuckets; i++)
325
+ {
326
+ const wp::fabricbucket_t& bucket = src.buckets[i];
327
+ const int8_t* src_ptr = static_cast<const int8_t*>(bucket.ptr);
328
+ size_t bucket_size = bucket.index_end - bucket.index_start;
329
+ for (size_t j = 0; j < bucket_size; j++)
330
+ {
331
+ int idx = *dst_indices;
332
+ memcpy(dst_ptr + idx * elem_size, src_ptr, elem_size);
333
+ src_ptr += elem_size;
334
+ ++dst_indices;
335
+ }
336
+ }
337
+ }
338
+ else
339
+ {
340
+ if (dst_stride == elem_size)
341
+ {
342
+ // copy to contiguous array
343
+ for (size_t i = 0; i < src.nbuckets; i++)
344
+ {
345
+ const wp::fabricbucket_t& bucket = src.buckets[i];
346
+ size_t num_bytes = (bucket.index_end - bucket.index_start) * elem_size;
347
+ memcpy(dst_ptr, bucket.ptr, num_bytes);
348
+ dst_ptr += num_bytes;
349
+ }
350
+ }
351
+ else
352
+ {
353
+ // copy to strided array
354
+ for (size_t i = 0; i < src.nbuckets; i++)
355
+ {
356
+ const wp::fabricbucket_t& bucket = src.buckets[i];
357
+ const int8_t* src_ptr = static_cast<const int8_t*>(bucket.ptr);
358
+ size_t bucket_size = bucket.index_end - bucket.index_start;
359
+ for (size_t j = 0; j < bucket_size; j++)
360
+ {
361
+ memcpy(dst_ptr, src_ptr, elem_size);
362
+ dst_ptr += dst_stride;
363
+ src_ptr += elem_size;
364
+ }
365
+ }
366
+ }
367
+ }
368
+ }
369
+
370
+ static void array_copy_fabric_to_fabric(wp::fabricarray_t<void>& dst, const wp::fabricarray_t<void>& src, int elem_size)
371
+ {
372
+ wp::fabricbucket_t* dst_bucket = dst.buckets;
373
+ const wp::fabricbucket_t* src_bucket = src.buckets;
374
+ int8_t* dst_ptr = static_cast<int8_t*>(dst_bucket->ptr);
375
+ const int8_t* src_ptr = static_cast<const int8_t*>(src_bucket->ptr);
376
+ size_t dst_remaining = dst_bucket->index_end - dst_bucket->index_start;
377
+ size_t src_remaining = src_bucket->index_end - src_bucket->index_start;
378
+ size_t total_copied = 0;
379
+
380
+ while (total_copied < dst.size)
381
+ {
382
+ if (dst_remaining <= src_remaining)
383
+ {
384
+ // copy to destination bucket
385
+ size_t num_elems = dst_remaining;
386
+ size_t num_bytes = num_elems * elem_size;
387
+ memcpy(dst_ptr, src_ptr, num_bytes);
388
+
389
+ // advance to next destination bucket
390
+ ++dst_bucket;
391
+ dst_ptr = static_cast<int8_t*>(dst_bucket->ptr);
392
+ dst_remaining = dst_bucket->index_end - dst_bucket->index_start;
393
+
394
+ // advance source offset
395
+ src_ptr += num_bytes;
396
+ src_remaining -= num_elems;
397
+
398
+ total_copied += num_elems;
399
+ }
400
+ else
401
+ {
402
+ // copy to destination bucket
403
+ size_t num_elems = src_remaining;
404
+ size_t num_bytes = num_elems * elem_size;
405
+ memcpy(dst_ptr, src_ptr, num_bytes);
406
+
407
+ // advance to next source bucket
408
+ ++src_bucket;
409
+ src_ptr = static_cast<const int8_t*>(src_bucket->ptr);
410
+ src_remaining = src_bucket->index_end - src_bucket->index_start;
411
+
412
+ // advance destination offset
413
+ dst_ptr += num_bytes;
414
+ dst_remaining -= num_elems;
415
+
416
+ total_copied += num_elems;
417
+ }
418
+ }
419
+ }
420
+
421
+
422
+ static void array_copy_to_fabric_indexed(wp::indexedfabricarray_t<void>& dst, const void* src_data,
423
+ int src_stride, const int* src_indices, int elem_size)
424
+ {
425
+ const int8_t* src_ptr = static_cast<const int8_t*>(src_data);
426
+
427
+ if (src_indices)
428
+ {
429
+ // copy from indexed array
430
+ for (size_t i = 0; i < dst.size; i++)
431
+ {
432
+ size_t src_idx = src_indices[i];
433
+ size_t dst_idx = dst.indices[i];
434
+ void* dst_ptr = fabricarray_element_ptr(dst.fa, dst_idx, elem_size);
435
+ memcpy(dst_ptr, src_ptr + dst_idx * elem_size, elem_size);
436
+ }
437
+ }
438
+ else
439
+ {
440
+ // copy from contiguous/strided array
441
+ for (size_t i = 0; i < dst.size; i++)
442
+ {
443
+ size_t dst_idx = dst.indices[i];
444
+ void* dst_ptr = fabricarray_element_ptr(dst.fa, dst_idx, elem_size);
445
+ if (dst_ptr)
446
+ {
447
+ memcpy(dst_ptr, src_ptr, elem_size);
448
+ src_ptr += src_stride;
449
+ }
450
+ }
451
+ }
452
+ }
453
+
454
+
455
+ static void array_copy_fabric_indexed_to_fabric(wp::fabricarray_t<void>& dst, const wp::indexedfabricarray_t<void>& src, int elem_size)
456
+ {
457
+ wp::fabricbucket_t* dst_bucket = dst.buckets;
458
+ int8_t* dst_ptr = static_cast<int8_t*>(dst_bucket->ptr);
459
+ int8_t* dst_end = dst_ptr + elem_size * (dst_bucket->index_end - dst_bucket->index_start);
460
+
461
+ for (size_t i = 0; i < src.size; i++)
462
+ {
463
+ size_t src_idx = src.indices[i];
464
+ const void* src_ptr = fabricarray_element_ptr(src.fa, src_idx, elem_size);
465
+
466
+ if (dst_ptr >= dst_end)
467
+ {
468
+ // advance to next destination bucket
469
+ ++dst_bucket;
470
+ dst_ptr = static_cast<int8_t*>(dst_bucket->ptr);
471
+ dst_end = dst_ptr + elem_size * (dst_bucket->index_end - dst_bucket->index_start);
472
+ }
473
+
474
+ memcpy(dst_ptr, src_ptr, elem_size);
475
+
476
+ dst_ptr += elem_size;
477
+ }
478
+ }
479
+
480
+
481
+ static void array_copy_fabric_indexed_to_fabric_indexed(wp::indexedfabricarray_t<void>& dst, const wp::indexedfabricarray_t<void>& src, int elem_size)
482
+ {
483
+ for (size_t i = 0; i < src.size; i++)
484
+ {
485
+ size_t src_idx = src.indices[i];
486
+ size_t dst_idx = dst.indices[i];
487
+
488
+ const void* src_ptr = fabricarray_element_ptr(src.fa, src_idx, elem_size);
489
+ void* dst_ptr = fabricarray_element_ptr(dst.fa, dst_idx, elem_size);
490
+
491
+ memcpy(dst_ptr, src_ptr, elem_size);
492
+ }
493
+ }
494
+
495
+
496
+ static void array_copy_fabric_to_fabric_indexed(wp::indexedfabricarray_t<void>& dst, const wp::fabricarray_t<void>& src, int elem_size)
497
+ {
498
+ wp::fabricbucket_t* src_bucket = src.buckets;
499
+ const int8_t* src_ptr = static_cast<const int8_t*>(src_bucket->ptr);
500
+ const int8_t* src_end = src_ptr + elem_size * (src_bucket->index_end - src_bucket->index_start);
501
+
502
+ for (size_t i = 0; i < dst.size; i++)
503
+ {
504
+ size_t dst_idx = dst.indices[i];
505
+ void* dst_ptr = fabricarray_element_ptr(dst.fa, dst_idx, elem_size);
506
+
507
+ if (src_ptr >= src_end)
508
+ {
509
+ // advance to next source bucket
510
+ ++src_bucket;
511
+ src_ptr = static_cast<int8_t*>(src_bucket->ptr);
512
+ src_end = src_ptr + elem_size * (src_bucket->index_end - src_bucket->index_start);
513
+ }
514
+
515
+ memcpy(dst_ptr, src_ptr, elem_size);
516
+
517
+ src_ptr += elem_size;
518
+ }
519
+ }
520
+
521
+
522
+ static void array_copy_from_fabric_indexed(const wp::indexedfabricarray_t<void>& src, void* dst_data,
523
+ int dst_stride, const int* dst_indices, int elem_size)
524
+ {
525
+ int8_t* dst_ptr = static_cast<int8_t*>(dst_data);
526
+
527
+ if (dst_indices)
528
+ {
529
+ // copy to indexed array
530
+ for (size_t i = 0; i < src.size; i++)
531
+ {
532
+ size_t idx = src.indices[i];
533
+ if (idx < src.fa.size)
534
+ {
535
+ const void* src_ptr = fabricarray_element_ptr(src.fa, idx, elem_size);
536
+ int dst_idx = dst_indices[i];
537
+ memcpy(dst_ptr + dst_idx * elem_size, src_ptr, elem_size);
538
+ }
539
+ else
540
+ {
541
+ fprintf(stderr, "Warp copy error: Source index %llu is out of bounds for fabric array of size %llu",
542
+ (unsigned long long)idx, (unsigned long long)src.fa.size);
543
+ }
544
+ }
545
+ }
546
+ else
547
+ {
548
+ // copy to contiguous/strided array
549
+ for (size_t i = 0; i < src.size; i++)
550
+ {
551
+ size_t idx = src.indices[i];
552
+ if (idx < src.fa.size)
553
+ {
554
+ const void* src_ptr = fabricarray_element_ptr(src.fa, idx, elem_size);
555
+ memcpy(dst_ptr, src_ptr, elem_size);
556
+ dst_ptr += dst_stride;
557
+ }
558
+ else
559
+ {
560
+ fprintf(stderr, "Warp copy error: Source index %llu is out of bounds for fabric array of size %llu",
561
+ (unsigned long long)idx, (unsigned long long)src.fa.size);
562
+ }
563
+ }
564
+ }
565
+ }
566
+
567
+
568
+ WP_API bool array_copy_host(void* dst, void* src, int dst_type, int src_type, int elem_size)
569
+ {
570
+ if (!src || !dst)
571
+ return false;
572
+
573
+ const void* src_data = NULL;
574
+ void* dst_data = NULL;
575
+ int src_ndim = 0;
576
+ int dst_ndim = 0;
577
+ const int* src_shape = NULL;
578
+ const int* dst_shape = NULL;
579
+ const int* src_strides = NULL;
580
+ const int* dst_strides = NULL;
581
+ const int*const* src_indices = NULL;
582
+ const int*const* dst_indices = NULL;
583
+
584
+ const wp::fabricarray_t<void>* src_fabricarray = NULL;
585
+ wp::fabricarray_t<void>* dst_fabricarray = NULL;
586
+
587
+ const wp::indexedfabricarray_t<void>* src_indexedfabricarray = NULL;
588
+ wp::indexedfabricarray_t<void>* dst_indexedfabricarray = NULL;
589
+
590
+ const int* null_indices[wp::ARRAY_MAX_DIMS] = { NULL };
591
+
592
+ if (src_type == wp::ARRAY_TYPE_REGULAR)
593
+ {
594
+ const wp::array_t<void>& src_arr = *static_cast<const wp::array_t<void>*>(src);
595
+ src_data = src_arr.data;
596
+ src_ndim = src_arr.ndim;
597
+ src_shape = src_arr.shape.dims;
598
+ src_strides = src_arr.strides;
599
+ src_indices = null_indices;
600
+ }
601
+ else if (src_type == wp::ARRAY_TYPE_INDEXED)
602
+ {
603
+ const wp::indexedarray_t<void>& src_arr = *static_cast<const wp::indexedarray_t<void>*>(src);
604
+ src_data = src_arr.arr.data;
605
+ src_ndim = src_arr.arr.ndim;
606
+ src_shape = src_arr.shape.dims;
607
+ src_strides = src_arr.arr.strides;
608
+ src_indices = src_arr.indices;
609
+ }
610
+ else if (src_type == wp::ARRAY_TYPE_FABRIC)
611
+ {
612
+ src_fabricarray = static_cast<const wp::fabricarray_t<void>*>(src);
613
+ src_ndim = 1;
614
+ }
615
+ else if (src_type == wp::ARRAY_TYPE_FABRIC_INDEXED)
616
+ {
617
+ src_indexedfabricarray = static_cast<const wp::indexedfabricarray_t<void>*>(src);
618
+ src_ndim = 1;
619
+ }
620
+ else
621
+ {
622
+ fprintf(stderr, "Warp copy error: Invalid source array type (%d)\n", src_type);
623
+ return false;
624
+ }
625
+
626
+ if (dst_type == wp::ARRAY_TYPE_REGULAR)
627
+ {
628
+ const wp::array_t<void>& dst_arr = *static_cast<const wp::array_t<void>*>(dst);
629
+ dst_data = dst_arr.data;
630
+ dst_ndim = dst_arr.ndim;
631
+ dst_shape = dst_arr.shape.dims;
632
+ dst_strides = dst_arr.strides;
633
+ dst_indices = null_indices;
634
+ }
635
+ else if (dst_type == wp::ARRAY_TYPE_INDEXED)
636
+ {
637
+ const wp::indexedarray_t<void>& dst_arr = *static_cast<const wp::indexedarray_t<void>*>(dst);
638
+ dst_data = dst_arr.arr.data;
639
+ dst_ndim = dst_arr.arr.ndim;
640
+ dst_shape = dst_arr.shape.dims;
641
+ dst_strides = dst_arr.arr.strides;
642
+ dst_indices = dst_arr.indices;
643
+ }
644
+ else if (dst_type == wp::ARRAY_TYPE_FABRIC)
645
+ {
646
+ dst_fabricarray = static_cast<wp::fabricarray_t<void>*>(dst);
647
+ dst_ndim = 1;
648
+ }
649
+ else if (dst_type == wp::ARRAY_TYPE_FABRIC_INDEXED)
650
+ {
651
+ dst_indexedfabricarray = static_cast<wp::indexedfabricarray_t<void>*>(dst);
652
+ dst_ndim = 1;
653
+ }
654
+ else
655
+ {
656
+ fprintf(stderr, "Warp copy error: Invalid destination array type (%d)\n", dst_type);
657
+ return false;
658
+ }
659
+
660
+ if (src_ndim != dst_ndim)
661
+ {
662
+ fprintf(stderr, "Warp copy error: Incompatible array dimensionalities (%d and %d)\n", src_ndim, dst_ndim);
663
+ return false;
664
+ }
665
+
666
+ // handle fabric arrays
667
+ if (dst_fabricarray)
668
+ {
669
+ size_t n = dst_fabricarray->size;
670
+ if (src_fabricarray)
671
+ {
672
+ // copy from fabric to fabric
673
+ if (src_fabricarray->size != n)
674
+ {
675
+ fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
676
+ return false;
677
+ }
678
+ array_copy_fabric_to_fabric(*dst_fabricarray, *src_fabricarray, elem_size);
679
+ return true;
680
+ }
681
+ else if (src_indexedfabricarray)
682
+ {
683
+ // copy from fabric indexed to fabric
684
+ if (src_indexedfabricarray->size != n)
685
+ {
686
+ fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
687
+ return false;
688
+ }
689
+ array_copy_fabric_indexed_to_fabric(*dst_fabricarray, *src_indexedfabricarray, elem_size);
690
+ return true;
691
+ }
692
+ else
693
+ {
694
+ // copy to fabric
695
+ if (size_t(src_shape[0]) != n)
696
+ {
697
+ fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
698
+ return false;
699
+ }
700
+ array_copy_to_fabric(*dst_fabricarray, src_data, src_strides[0], src_indices[0], elem_size);
701
+ return true;
702
+ }
703
+ }
704
+ else if (dst_indexedfabricarray)
705
+ {
706
+ size_t n = dst_indexedfabricarray->size;
707
+ if (src_fabricarray)
708
+ {
709
+ // copy from fabric to fabric indexed
710
+ if (src_fabricarray->size != n)
711
+ {
712
+ fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
713
+ return false;
714
+ }
715
+ array_copy_fabric_to_fabric_indexed(*dst_indexedfabricarray, *src_fabricarray, elem_size);
716
+ return true;
717
+ }
718
+ else if (src_indexedfabricarray)
719
+ {
720
+ // copy from fabric indexed to fabric indexed
721
+ if (src_indexedfabricarray->size != n)
722
+ {
723
+ fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
724
+ return false;
725
+ }
726
+ array_copy_fabric_indexed_to_fabric_indexed(*dst_indexedfabricarray, *src_indexedfabricarray, elem_size);
727
+ return true;
728
+ }
729
+ else
730
+ {
731
+ // copy to fabric indexed
732
+ if (size_t(src_shape[0]) != n)
733
+ {
734
+ fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
735
+ return false;
736
+ }
737
+ array_copy_to_fabric_indexed(*dst_indexedfabricarray, src_data, src_strides[0], src_indices[0], elem_size);
738
+ return true;
739
+ }
740
+ }
741
+ else if (src_fabricarray)
742
+ {
743
+ // copy from fabric
744
+ size_t n = src_fabricarray->size;
745
+ if (size_t(dst_shape[0]) != n)
746
+ {
747
+ fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
748
+ return false;
749
+ }
750
+ array_copy_from_fabric(*src_fabricarray, dst_data, dst_strides[0], dst_indices[0], elem_size);
751
+ return true;
752
+ }
753
+ else if (src_indexedfabricarray)
754
+ {
755
+ // copy from fabric indexed
756
+ size_t n = src_indexedfabricarray->size;
757
+ if (size_t(dst_shape[0]) != n)
758
+ {
759
+ fprintf(stderr, "Warp copy error: Incompatible array sizes\n");
760
+ return false;
761
+ }
762
+ array_copy_from_fabric_indexed(*src_indexedfabricarray, dst_data, dst_strides[0], dst_indices[0], elem_size);
763
+ return true;
764
+ }
765
+
766
+ for (int i = 0; i < src_ndim; i++)
767
+ {
768
+ if (src_shape[i] != dst_shape[i])
769
+ {
770
+ fprintf(stderr, "Warp copy error: Incompatible array shapes\n");
771
+ return 0;
772
+ }
773
+ }
774
+
775
+ array_copy_nd(dst_data, src_data,
776
+ dst_strides, src_strides,
777
+ dst_indices, src_indices,
778
+ src_shape, src_ndim, elem_size);
779
+
780
+ return true;
781
+ }
782
+
783
+
784
+ static void array_fill_strided(void* data, const int* shape, const int* strides, int ndim, const void* value, int value_size)
785
+ {
786
+ if (ndim == 1)
787
+ {
788
+ char* p = (char*)data;
789
+ for (int i = 0; i < shape[0]; i++)
790
+ {
791
+ memcpy(p, value, value_size);
792
+ p += strides[0];
793
+ }
794
+ }
795
+ else
796
+ {
797
+ for (int i = 0; i < shape[0]; i++)
798
+ {
799
+ char* p = (char*)data + i * strides[0];
800
+ // recurse on next inner dimension
801
+ array_fill_strided(p, shape + 1, strides + 1, ndim - 1, value, value_size);
802
+ }
803
+ }
804
+ }
805
+
806
+
807
+ static void array_fill_indexed(void* data, const int* shape, const int* strides, const int*const* indices, int ndim, const void* value, int value_size)
808
+ {
809
+ if (ndim == 1)
810
+ {
811
+ for (int i = 0; i < shape[0]; i++)
812
+ {
813
+ int idx = indices[0] ? indices[0][i] : i;
814
+ char* p = (char*)data + idx * strides[0];
815
+ memcpy(p, value, value_size);
816
+ }
817
+ }
818
+ else
819
+ {
820
+ for (int i = 0; i < shape[0]; i++)
821
+ {
822
+ int idx = indices[0] ? indices[0][i] : i;
823
+ char* p = (char*)data + idx * strides[0];
824
+ // recurse on next inner dimension
825
+ array_fill_indexed(p, shape + 1, strides + 1, indices + 1, ndim - 1, value, value_size);
826
+ }
827
+ }
828
+ }
829
+
830
+
831
+ static void array_fill_fabric(wp::fabricarray_t<void>& fa, const void* value_ptr, int value_size)
832
+ {
833
+ for (size_t i = 0; i < fa.nbuckets; i++)
834
+ {
835
+ const wp::fabricbucket_t& bucket = fa.buckets[i];
836
+ size_t bucket_size = bucket.index_end - bucket.index_start;
837
+ memtile_host(bucket.ptr, value_ptr, value_size, bucket_size);
838
+ }
839
+ }
840
+
841
+
842
+ static void array_fill_fabric_indexed(wp::indexedfabricarray_t<void>& ifa, const void* value_ptr, int value_size)
843
+ {
844
+ for (size_t i = 0; i < ifa.size; i++)
845
+ {
846
+ size_t idx = size_t(ifa.indices[i]);
847
+ if (idx < ifa.fa.size)
848
+ {
849
+ void* p = fabricarray_element_ptr(ifa.fa, idx, value_size);
850
+ memcpy(p, value_ptr, value_size);
851
+ }
852
+ }
853
+ }
854
+
855
+
856
+ WP_API void array_fill_host(void* arr_ptr, int arr_type, const void* value_ptr, int value_size)
857
+ {
858
+ if (!arr_ptr || !value_ptr)
859
+ return;
860
+
861
+ if (arr_type == wp::ARRAY_TYPE_REGULAR)
862
+ {
863
+ wp::array_t<void>& arr = *static_cast<wp::array_t<void>*>(arr_ptr);
864
+ array_fill_strided(arr.data, arr.shape.dims, arr.strides, arr.ndim, value_ptr, value_size);
865
+ }
866
+ else if (arr_type == wp::ARRAY_TYPE_INDEXED)
867
+ {
868
+ wp::indexedarray_t<void>& ia = *static_cast<wp::indexedarray_t<void>*>(arr_ptr);
869
+ array_fill_indexed(ia.arr.data, ia.shape.dims, ia.arr.strides, ia.indices, ia.arr.ndim, value_ptr, value_size);
870
+ }
871
+ else if (arr_type == wp::ARRAY_TYPE_FABRIC)
872
+ {
873
+ wp::fabricarray_t<void>& fa = *static_cast<wp::fabricarray_t<void>*>(arr_ptr);
874
+ array_fill_fabric(fa, value_ptr, value_size);
875
+ }
876
+ else if (arr_type == wp::ARRAY_TYPE_FABRIC_INDEXED)
877
+ {
878
+ wp::indexedfabricarray_t<void>& ifa = *static_cast<wp::indexedfabricarray_t<void>*>(arr_ptr);
879
+ array_fill_fabric_indexed(ifa, value_ptr, value_size);
880
+ }
881
+ else
882
+ {
883
+ fprintf(stderr, "Warp fill error: Invalid array type id %d\n", arr_type);
884
+ }
885
+ }
886
+
887
+
888
+ // impl. files
889
+ // TODO: compile as separate translation units
890
+ #include "bvh.cpp"
891
+ #include "scan.cpp"
892
+
893
+
894
+ // stubs for platforms where there is no CUDA
895
+ #if !WP_ENABLE_CUDA
896
+
897
+ void* alloc_pinned(size_t s)
898
+ {
899
+ // CUDA is not available, fall back on system allocator
900
+ return alloc_host(s);
901
+ }
902
+
903
+ void free_pinned(void* ptr)
904
+ {
905
+ // CUDA is not available, fall back on system allocator
906
+ free_host(ptr);
907
+ }
908
+
909
+ void* alloc_device(void* context, size_t s)
910
+ {
911
+ return NULL;
912
+ }
913
+
914
+ void* alloc_device_default(void* context, size_t s)
915
+ {
916
+ return NULL;
917
+ }
918
+
919
+ void* alloc_device_async(void* context, size_t s)
920
+ {
921
+ return NULL;
922
+ }
923
+
924
+ void free_device(void* context, void* ptr)
925
+ {
926
+ }
927
+
928
+ void free_device_default(void* context, void* ptr)
929
+ {
930
+ }
931
+
932
+ void free_device_async(void* context, void* ptr)
933
+ {
934
+ }
935
+
936
+ bool memcpy_h2d(void* context, void* dest, void* src, size_t n, void* stream)
937
+ {
938
+ return false;
939
+ }
940
+
941
+ bool memcpy_d2h(void* context, void* dest, void* src, size_t n, void* stream)
942
+ {
943
+ return false;
944
+ }
945
+
946
+ bool memcpy_d2d(void* context, void* dest, void* src, size_t n, void* stream)
947
+ {
948
+ return false;
949
+ }
950
+
951
+ bool memcpy_p2p(void* dst_context, void* dst, void* src_context, void* src, size_t n, void* stream)
952
+ {
953
+ return false;
954
+ }
955
+
956
+ void memset_device(void* context, void* dest, int value, size_t n)
957
+ {
958
+ }
959
+
960
+ void memtile_device(void* context, void* dest, const void* src, size_t srcsize, size_t n)
961
+ {
962
+ }
963
+
964
+ bool array_copy_device(void* context, void* dst, void* src, int dst_type, int src_type, int elem_size)
965
+ {
966
+ return false;
967
+ }
968
+
969
+ void array_fill_device(void* context, void* arr, int arr_type, const void* value, int value_size)
970
+ {
971
+ }
972
+
973
+ WP_API int cuda_driver_version() { return 0; }
974
+ WP_API int cuda_toolkit_version() { return 0; }
975
+ WP_API bool cuda_driver_is_initialized() { return false; }
976
+
977
+ WP_API int nvrtc_supported_arch_count() { return 0; }
978
+ WP_API void nvrtc_supported_archs(int* archs) {}
979
+
980
+ WP_API int cuda_device_get_count() { return 0; }
981
+ WP_API void* cuda_device_get_primary_context(int ordinal) { return NULL; }
982
+ WP_API const char* cuda_device_get_name(int ordinal) { return NULL; }
983
+ WP_API int cuda_device_get_arch(int ordinal) { return 0; }
984
+ WP_API void cuda_device_get_uuid(int ordinal, char uuid[16]) {}
985
+ WP_API int cuda_device_get_pci_domain_id(int ordinal) { return -1; }
986
+ WP_API int cuda_device_get_pci_bus_id(int ordinal) { return -1; }
987
+ WP_API int cuda_device_get_pci_device_id(int ordinal) { return -1; }
988
+ WP_API int cuda_device_is_uva(int ordinal) { return 0; }
989
+ WP_API int cuda_device_is_mempool_supported(int ordinal) { return 0; }
990
+ WP_API int cuda_device_set_mempool_release_threshold(int ordinal, uint64_t threshold) { return 0; }
991
+ WP_API uint64_t cuda_device_get_mempool_release_threshold(int ordinal) { return 0; }
992
+ WP_API void cuda_device_get_memory_info(int ordinal, size_t* free_mem, size_t* total_mem) {}
993
+
994
+ WP_API void* cuda_context_get_current() { return NULL; }
995
+ WP_API void cuda_context_set_current(void* ctx) {}
996
+ WP_API void cuda_context_push_current(void* context) {}
997
+ WP_API void cuda_context_pop_current() {}
998
+ WP_API void* cuda_context_create(int device_ordinal) { return NULL; }
999
+ WP_API void cuda_context_destroy(void* context) {}
1000
+ WP_API void cuda_context_synchronize(void* context) {}
1001
+ WP_API uint64_t cuda_context_check(void* context) { return 0; }
1002
+ WP_API int cuda_context_get_device_ordinal(void* context) { return -1; }
1003
+ WP_API int cuda_context_is_primary(void* context) { return 0; }
1004
+ WP_API void* cuda_context_get_stream(void* context) { return NULL; }
1005
+ WP_API void cuda_context_set_stream(void* context, void* stream, int sync) {}
1006
+
1007
+ WP_API int cuda_is_peer_access_supported(int target_ordinal, int peer_ordinal) { return 0; }
1008
+ WP_API int cuda_is_peer_access_enabled(void* target_context, void* peer_context) { return 0; }
1009
+ WP_API int cuda_set_peer_access_enabled(void* target_context, void* peer_context, int enable) { return 0; }
1010
+ WP_API int cuda_is_mempool_access_enabled(int target_ordinal, int peer_ordinal) { return 0; }
1011
+ WP_API int cuda_set_mempool_access_enabled(int target_ordinal, int peer_ordinal, int enable) { return 0; }
1012
+
1013
+ WP_API void* cuda_stream_create(void* context) { return NULL; }
1014
+ WP_API void cuda_stream_destroy(void* context, void* stream) {}
1015
+ WP_API void cuda_stream_register(void* context, void* stream) {}
1016
+ WP_API void cuda_stream_unregister(void* context, void* stream) {}
1017
+ WP_API void* cuda_stream_get_current() { return NULL; }
1018
+ WP_API void cuda_stream_synchronize(void* stream) {}
1019
+ WP_API void cuda_stream_wait_event(void* stream, void* event) {}
1020
+ WP_API void cuda_stream_wait_stream(void* stream, void* other_stream, void* event) {}
1021
+ WP_API int cuda_stream_is_capturing(void* stream) { return 0; }
1022
+
1023
+ WP_API void* cuda_event_create(void* context, unsigned flags) { return NULL; }
1024
+ WP_API void cuda_event_destroy(void* event) {}
1025
+ WP_API void cuda_event_record(void* event, void* stream) {}
1026
+ WP_API void cuda_event_synchronize(void* event) {}
1027
+ WP_API float cuda_event_elapsed_time(void* start_event, void* end_event) { return 0.0f; }
1028
+
1029
+ WP_API bool cuda_graph_begin_capture(void* context, void* stream, int external) { return false; }
1030
+ WP_API bool cuda_graph_end_capture(void* context, void* stream, void** graph_ret) { return false; }
1031
+ WP_API bool cuda_graph_launch(void* graph, void* stream) { return false; }
1032
+ WP_API bool cuda_graph_destroy(void* context, void* graph) { return false; }
1033
+
1034
+ WP_API size_t cuda_compile_program(const char* cuda_src, int arch, const char* include_dir, bool debug, bool verbose, bool verify_fp, bool fast_math, const char* output_file) { return 0; }
1035
+
1036
+ WP_API void* cuda_load_module(void* context, const char* ptx) { return NULL; }
1037
+ WP_API void cuda_unload_module(void* context, void* module) {}
1038
+ WP_API void* cuda_get_kernel(void* context, void* module, const char* name) { return NULL; }
1039
+ WP_API size_t cuda_launch_kernel(void* context, void* kernel, size_t dim, int max_blocks, void** args, void* stream) { return 0; }
1040
+
1041
+ WP_API void cuda_set_context_restore_policy(bool always_restore) {}
1042
+ WP_API int cuda_get_context_restore_policy() { return false; }
1043
+
1044
+ WP_API void array_scan_int_device(uint64_t in, uint64_t out, int len, bool inclusive) {}
1045
+ WP_API void array_scan_float_device(uint64_t in, uint64_t out, int len, bool inclusive) {}
1046
+
1047
+ WP_API void cuda_graphics_map(void* context, void* resource) {}
1048
+ WP_API void cuda_graphics_unmap(void* context, void* resource) {}
1049
+ WP_API void cuda_graphics_device_ptr_and_size(void* context, void* resource, uint64_t* ptr, size_t* size) {}
1050
+ WP_API void* cuda_graphics_register_gl_buffer(void* context, uint32_t gl_buffer, unsigned int flags) { return NULL; }
1051
+ WP_API void cuda_graphics_unregister_resource(void* context, void* resource) {}
1052
+
1053
+ WP_API void cuda_timing_begin(int flags) {}
1054
+ WP_API int cuda_timing_get_result_count() { return 0; }
1055
+ WP_API void cuda_timing_end(timing_result_t* results, int size) {}
1056
+
1057
+ #endif // !WP_ENABLE_CUDA