warp-lang 1.0.2__py3-none-win_amd64.whl → 1.2.0__py3-none-win_amd64.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 (356) hide show
  1. warp/__init__.py +108 -97
  2. warp/__init__.pyi +1 -1
  3. warp/bin/warp-clang.dll +0 -0
  4. warp/bin/warp.dll +0 -0
  5. warp/build.py +88 -113
  6. warp/build_dll.py +383 -375
  7. warp/builtins.py +3693 -3354
  8. warp/codegen.py +2925 -2792
  9. warp/config.py +40 -36
  10. warp/constants.py +49 -45
  11. warp/context.py +5409 -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 +381 -383
  26. warp/examples/benchmarks/benchmark_cloth.py +278 -277
  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 +145 -146
  34. warp/examples/benchmarks/benchmark_launches.py +293 -295
  35. warp/examples/browse.py +29 -29
  36. warp/examples/core/example_dem.py +232 -219
  37. warp/examples/core/example_fluid.py +291 -267
  38. warp/examples/core/example_graph_capture.py +142 -126
  39. warp/examples/core/example_marching_cubes.py +186 -174
  40. warp/examples/core/example_mesh.py +172 -155
  41. warp/examples/core/example_mesh_intersect.py +203 -193
  42. warp/examples/core/example_nvdb.py +174 -170
  43. warp/examples/core/example_raycast.py +103 -90
  44. warp/examples/core/example_raymarch.py +197 -178
  45. warp/examples/core/example_render_opengl.py +183 -141
  46. warp/examples/core/example_sph.py +403 -387
  47. warp/examples/core/example_torch.py +219 -181
  48. warp/examples/core/example_wave.py +261 -248
  49. warp/examples/fem/bsr_utils.py +378 -380
  50. warp/examples/fem/example_apic_fluid.py +432 -389
  51. warp/examples/fem/example_burgers.py +262 -0
  52. warp/examples/fem/example_convection_diffusion.py +180 -168
  53. warp/examples/fem/example_convection_diffusion_dg.py +217 -209
  54. warp/examples/fem/example_deformed_geometry.py +175 -159
  55. warp/examples/fem/example_diffusion.py +199 -173
  56. warp/examples/fem/example_diffusion_3d.py +178 -152
  57. warp/examples/fem/example_diffusion_mgpu.py +219 -214
  58. warp/examples/fem/example_mixed_elasticity.py +242 -222
  59. warp/examples/fem/example_navier_stokes.py +257 -243
  60. warp/examples/fem/example_stokes.py +218 -192
  61. warp/examples/fem/example_stokes_transfer.py +263 -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 +258 -246
  65. warp/examples/optim/example_cloth_throw.py +220 -209
  66. warp/examples/optim/example_diffray.py +564 -536
  67. warp/examples/optim/example_drone.py +862 -835
  68. warp/examples/optim/example_inverse_kinematics.py +174 -168
  69. warp/examples/optim/example_inverse_kinematics_torch.py +183 -169
  70. warp/examples/optim/example_spring_cage.py +237 -231
  71. warp/examples/optim/example_trajectory.py +221 -199
  72. warp/examples/optim/example_walker.py +304 -293
  73. warp/examples/sim/example_cartpole.py +137 -129
  74. warp/examples/sim/example_cloth.py +194 -186
  75. warp/examples/sim/example_granular.py +122 -111
  76. warp/examples/sim/example_granular_collision_sdf.py +195 -186
  77. warp/examples/sim/example_jacobian_ik.py +234 -214
  78. warp/examples/sim/example_particle_chain.py +116 -105
  79. warp/examples/sim/example_quadruped.py +191 -180
  80. warp/examples/sim/example_rigid_chain.py +195 -187
  81. warp/examples/sim/example_rigid_contact.py +187 -177
  82. warp/examples/sim/example_rigid_force.py +125 -125
  83. warp/examples/sim/example_rigid_gyroscopic.py +107 -95
  84. warp/examples/sim/example_rigid_soft_contact.py +132 -122
  85. warp/examples/sim/example_soft_body.py +188 -177
  86. warp/fabric.py +337 -335
  87. warp/fem/__init__.py +61 -27
  88. warp/fem/cache.py +403 -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 +16 -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 +748 -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 +437 -435
  104. warp/fem/geometry/hexmesh.py +953 -953
  105. warp/fem/geometry/nanogrid.py +455 -0
  106. warp/fem/geometry/partition.py +374 -376
  107. warp/fem/geometry/quadmesh_2d.py +532 -532
  108. warp/fem/geometry/tetmesh.py +840 -840
  109. warp/fem/geometry/trimesh_2d.py +577 -577
  110. warp/fem/integrate.py +1684 -1615
  111. warp/fem/operator.py +190 -191
  112. warp/fem/polynomial.py +214 -213
  113. warp/fem/quadrature/__init__.py +2 -2
  114. warp/fem/quadrature/pic_quadrature.py +243 -245
  115. warp/fem/quadrature/quadrature.py +295 -294
  116. warp/fem/space/__init__.py +179 -292
  117. warp/fem/space/basis_space.py +522 -489
  118. warp/fem/space/collocated_function_space.py +100 -105
  119. warp/fem/space/dof_mapper.py +236 -236
  120. warp/fem/space/function_space.py +148 -145
  121. warp/fem/space/grid_2d_function_space.py +148 -267
  122. warp/fem/space/grid_3d_function_space.py +167 -306
  123. warp/fem/space/hexmesh_function_space.py +253 -352
  124. warp/fem/space/nanogrid_function_space.py +202 -0
  125. warp/fem/space/partition.py +350 -350
  126. warp/fem/space/quadmesh_2d_function_space.py +261 -369
  127. warp/fem/space/restriction.py +161 -160
  128. warp/fem/space/shape/__init__.py +90 -15
  129. warp/fem/space/shape/cube_shape_function.py +728 -738
  130. warp/fem/space/shape/shape_function.py +102 -103
  131. warp/fem/space/shape/square_shape_function.py +611 -611
  132. warp/fem/space/shape/tet_shape_function.py +565 -567
  133. warp/fem/space/shape/triangle_shape_function.py +429 -429
  134. warp/fem/space/tetmesh_function_space.py +224 -292
  135. warp/fem/space/topology.py +297 -295
  136. warp/fem/space/trimesh_2d_function_space.py +153 -221
  137. warp/fem/types.py +77 -77
  138. warp/fem/utils.py +495 -495
  139. warp/jax.py +166 -141
  140. warp/jax_experimental.py +341 -339
  141. warp/native/array.h +1081 -1025
  142. warp/native/builtin.h +1603 -1560
  143. warp/native/bvh.cpp +402 -398
  144. warp/native/bvh.cu +533 -525
  145. warp/native/bvh.h +430 -429
  146. warp/native/clang/clang.cpp +496 -464
  147. warp/native/crt.cpp +42 -32
  148. warp/native/crt.h +352 -335
  149. warp/native/cuda_crt.h +1049 -1049
  150. warp/native/cuda_util.cpp +549 -540
  151. warp/native/cuda_util.h +288 -203
  152. warp/native/cutlass_gemm.cpp +34 -34
  153. warp/native/cutlass_gemm.cu +372 -372
  154. warp/native/error.cpp +66 -66
  155. warp/native/error.h +27 -27
  156. warp/native/exports.h +187 -0
  157. warp/native/fabric.h +228 -228
  158. warp/native/hashgrid.cpp +301 -278
  159. warp/native/hashgrid.cu +78 -77
  160. warp/native/hashgrid.h +227 -227
  161. warp/native/initializer_array.h +32 -32
  162. warp/native/intersect.h +1204 -1204
  163. warp/native/intersect_adj.h +365 -365
  164. warp/native/intersect_tri.h +322 -322
  165. warp/native/marching.cpp +2 -2
  166. warp/native/marching.cu +497 -497
  167. warp/native/marching.h +2 -2
  168. warp/native/mat.h +1545 -1498
  169. warp/native/matnn.h +333 -333
  170. warp/native/mesh.cpp +203 -203
  171. warp/native/mesh.cu +292 -293
  172. warp/native/mesh.h +1887 -1887
  173. warp/native/nanovdb/GridHandle.h +366 -0
  174. warp/native/nanovdb/HostBuffer.h +590 -0
  175. warp/native/nanovdb/NanoVDB.h +6624 -4782
  176. warp/native/nanovdb/PNanoVDB.h +3390 -2553
  177. warp/native/noise.h +850 -850
  178. warp/native/quat.h +1112 -1085
  179. warp/native/rand.h +303 -299
  180. warp/native/range.h +108 -108
  181. warp/native/reduce.cpp +156 -156
  182. warp/native/reduce.cu +348 -348
  183. warp/native/runlength_encode.cpp +61 -61
  184. warp/native/runlength_encode.cu +46 -46
  185. warp/native/scan.cpp +30 -30
  186. warp/native/scan.cu +36 -36
  187. warp/native/scan.h +7 -7
  188. warp/native/solid_angle.h +442 -442
  189. warp/native/sort.cpp +94 -94
  190. warp/native/sort.cu +97 -97
  191. warp/native/sort.h +14 -14
  192. warp/native/sparse.cpp +337 -337
  193. warp/native/sparse.cu +544 -544
  194. warp/native/spatial.h +630 -630
  195. warp/native/svd.h +562 -562
  196. warp/native/temp_buffer.h +30 -30
  197. warp/native/vec.h +1177 -1133
  198. warp/native/volume.cpp +529 -297
  199. warp/native/volume.cu +58 -32
  200. warp/native/volume.h +960 -538
  201. warp/native/volume_builder.cu +446 -425
  202. warp/native/volume_builder.h +34 -19
  203. warp/native/volume_impl.h +61 -0
  204. warp/native/warp.cpp +1057 -1052
  205. warp/native/warp.cu +2949 -2828
  206. warp/native/warp.h +321 -305
  207. warp/optim/__init__.py +9 -9
  208. warp/optim/adam.py +120 -120
  209. warp/optim/linear.py +1104 -939
  210. warp/optim/sgd.py +104 -92
  211. warp/render/__init__.py +10 -10
  212. warp/render/render_opengl.py +3356 -3204
  213. warp/render/render_usd.py +768 -749
  214. warp/render/utils.py +152 -150
  215. warp/sim/__init__.py +52 -59
  216. warp/sim/articulation.py +685 -685
  217. warp/sim/collide.py +1594 -1590
  218. warp/sim/import_mjcf.py +489 -481
  219. warp/sim/import_snu.py +220 -221
  220. warp/sim/import_urdf.py +536 -516
  221. warp/sim/import_usd.py +887 -881
  222. warp/sim/inertia.py +316 -317
  223. warp/sim/integrator.py +234 -233
  224. warp/sim/integrator_euler.py +1956 -1956
  225. warp/sim/integrator_featherstone.py +1917 -1991
  226. warp/sim/integrator_xpbd.py +3288 -3312
  227. warp/sim/model.py +4473 -4314
  228. warp/sim/particles.py +113 -112
  229. warp/sim/render.py +417 -403
  230. warp/sim/utils.py +413 -410
  231. warp/sparse.py +1289 -1227
  232. warp/stubs.py +2192 -2469
  233. warp/tape.py +1162 -225
  234. warp/tests/__init__.py +1 -1
  235. warp/tests/__main__.py +4 -4
  236. warp/tests/assets/test_index_grid.nvdb +0 -0
  237. warp/tests/assets/torus.usda +105 -105
  238. warp/tests/aux_test_class_kernel.py +26 -26
  239. warp/tests/aux_test_compile_consts_dummy.py +10 -10
  240. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -21
  241. warp/tests/aux_test_dependent.py +20 -22
  242. warp/tests/aux_test_grad_customs.py +21 -23
  243. warp/tests/aux_test_reference.py +9 -11
  244. warp/tests/aux_test_reference_reference.py +8 -10
  245. warp/tests/aux_test_square.py +15 -17
  246. warp/tests/aux_test_unresolved_func.py +14 -14
  247. warp/tests/aux_test_unresolved_symbol.py +14 -14
  248. warp/tests/disabled_kinematics.py +237 -239
  249. warp/tests/run_coverage_serial.py +31 -31
  250. warp/tests/test_adam.py +155 -157
  251. warp/tests/test_arithmetic.py +1088 -1124
  252. warp/tests/test_array.py +2415 -2326
  253. warp/tests/test_array_reduce.py +148 -150
  254. warp/tests/test_async.py +666 -656
  255. warp/tests/test_atomic.py +139 -141
  256. warp/tests/test_bool.py +212 -149
  257. warp/tests/test_builtins_resolution.py +1290 -1292
  258. warp/tests/test_bvh.py +162 -171
  259. warp/tests/test_closest_point_edge_edge.py +227 -228
  260. warp/tests/test_codegen.py +562 -553
  261. warp/tests/test_compile_consts.py +217 -101
  262. warp/tests/test_conditional.py +244 -246
  263. warp/tests/test_copy.py +230 -215
  264. warp/tests/test_ctypes.py +630 -632
  265. warp/tests/test_dense.py +65 -67
  266. warp/tests/test_devices.py +89 -98
  267. warp/tests/test_dlpack.py +528 -529
  268. warp/tests/test_examples.py +403 -378
  269. warp/tests/test_fabricarray.py +952 -955
  270. warp/tests/test_fast_math.py +60 -54
  271. warp/tests/test_fem.py +1298 -1278
  272. warp/tests/test_fp16.py +128 -130
  273. warp/tests/test_func.py +336 -337
  274. warp/tests/test_generics.py +596 -571
  275. warp/tests/test_grad.py +885 -640
  276. warp/tests/test_grad_customs.py +331 -336
  277. warp/tests/test_hash_grid.py +208 -164
  278. warp/tests/test_import.py +37 -39
  279. warp/tests/test_indexedarray.py +1132 -1134
  280. warp/tests/test_intersect.py +65 -67
  281. warp/tests/test_jax.py +305 -307
  282. warp/tests/test_large.py +169 -164
  283. warp/tests/test_launch.py +352 -354
  284. warp/tests/test_lerp.py +217 -261
  285. warp/tests/test_linear_solvers.py +189 -171
  286. warp/tests/test_lvalue.py +419 -493
  287. warp/tests/test_marching_cubes.py +63 -65
  288. warp/tests/test_mat.py +1799 -1827
  289. warp/tests/test_mat_lite.py +113 -115
  290. warp/tests/test_mat_scalar_ops.py +2905 -2889
  291. warp/tests/test_math.py +124 -193
  292. warp/tests/test_matmul.py +498 -499
  293. warp/tests/test_matmul_lite.py +408 -410
  294. warp/tests/test_mempool.py +186 -190
  295. warp/tests/test_mesh.py +281 -324
  296. warp/tests/test_mesh_query_aabb.py +226 -241
  297. warp/tests/test_mesh_query_point.py +690 -702
  298. warp/tests/test_mesh_query_ray.py +290 -303
  299. warp/tests/test_mlp.py +274 -276
  300. warp/tests/test_model.py +108 -110
  301. warp/tests/test_module_hashing.py +111 -0
  302. warp/tests/test_modules_lite.py +36 -39
  303. warp/tests/test_multigpu.py +161 -163
  304. warp/tests/test_noise.py +244 -248
  305. warp/tests/test_operators.py +248 -250
  306. warp/tests/test_options.py +121 -125
  307. warp/tests/test_peer.py +131 -137
  308. warp/tests/test_pinned.py +76 -78
  309. warp/tests/test_print.py +52 -54
  310. warp/tests/test_quat.py +2084 -2086
  311. warp/tests/test_rand.py +324 -288
  312. warp/tests/test_reload.py +207 -217
  313. warp/tests/test_rounding.py +177 -179
  314. warp/tests/test_runlength_encode.py +188 -190
  315. warp/tests/test_sim_grad.py +241 -0
  316. warp/tests/test_sim_kinematics.py +89 -97
  317. warp/tests/test_smoothstep.py +166 -168
  318. warp/tests/test_snippet.py +303 -266
  319. warp/tests/test_sparse.py +466 -460
  320. warp/tests/test_spatial.py +2146 -2148
  321. warp/tests/test_special_values.py +362 -0
  322. warp/tests/test_streams.py +484 -473
  323. warp/tests/test_struct.py +708 -675
  324. warp/tests/test_tape.py +171 -148
  325. warp/tests/test_torch.py +741 -743
  326. warp/tests/test_transient_module.py +85 -87
  327. warp/tests/test_types.py +554 -659
  328. warp/tests/test_utils.py +488 -499
  329. warp/tests/test_vec.py +1262 -1268
  330. warp/tests/test_vec_lite.py +71 -73
  331. warp/tests/test_vec_scalar_ops.py +2097 -2099
  332. warp/tests/test_verify_fp.py +92 -94
  333. warp/tests/test_volume.py +961 -736
  334. warp/tests/test_volume_write.py +338 -265
  335. warp/tests/unittest_serial.py +38 -37
  336. warp/tests/unittest_suites.py +367 -359
  337. warp/tests/unittest_utils.py +434 -578
  338. warp/tests/unused_test_misc.py +69 -71
  339. warp/tests/walkthrough_debug.py +85 -85
  340. warp/thirdparty/appdirs.py +598 -598
  341. warp/thirdparty/dlpack.py +143 -143
  342. warp/thirdparty/unittest_parallel.py +563 -561
  343. warp/torch.py +321 -295
  344. warp/types.py +4941 -4450
  345. warp/utils.py +1008 -821
  346. {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/LICENSE.md +126 -126
  347. {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/METADATA +365 -400
  348. warp_lang-1.2.0.dist-info/RECORD +359 -0
  349. warp/examples/assets/cube.usda +0 -42
  350. warp/examples/assets/sphere.usda +0 -56
  351. warp/examples/assets/torus.usda +0 -105
  352. warp/examples/fem/example_convection_diffusion_dg0.py +0 -194
  353. warp/native/nanovdb/PNanoVDBWrite.h +0 -295
  354. warp_lang-1.0.2.dist-info/RECORD +0 -352
  355. {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/WHEEL +0 -0
  356. {warp_lang-1.0.2.dist-info → warp_lang-1.2.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