warp-lang 1.0.2__py3-none-manylinux2014_x86_64.whl → 1.2.0__py3-none-manylinux2014_x86_64.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.
- warp/__init__.py +108 -97
- warp/__init__.pyi +1 -1
- warp/bin/warp-clang.so +0 -0
- warp/bin/warp.so +0 -0
- warp/build.py +88 -113
- warp/build_dll.py +383 -375
- warp/builtins.py +3693 -3354
- warp/codegen.py +2925 -2792
- warp/config.py +40 -36
- warp/constants.py +49 -45
- warp/context.py +5409 -5102
- warp/dlpack.py +442 -442
- warp/examples/__init__.py +16 -16
- warp/examples/assets/bear.usd +0 -0
- warp/examples/assets/bunny.usd +0 -0
- warp/examples/assets/cartpole.urdf +110 -110
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/cube.usd +0 -0
- warp/examples/assets/nv_ant.xml +92 -92
- warp/examples/assets/nv_humanoid.xml +183 -183
- warp/examples/assets/quadruped.urdf +267 -267
- warp/examples/assets/rocks.nvdb +0 -0
- warp/examples/assets/rocks.usd +0 -0
- warp/examples/assets/sphere.usd +0 -0
- warp/examples/benchmarks/benchmark_api.py +381 -383
- warp/examples/benchmarks/benchmark_cloth.py +278 -277
- warp/examples/benchmarks/benchmark_cloth_cupy.py +88 -88
- warp/examples/benchmarks/benchmark_cloth_jax.py +97 -100
- warp/examples/benchmarks/benchmark_cloth_numba.py +146 -142
- warp/examples/benchmarks/benchmark_cloth_numpy.py +77 -77
- warp/examples/benchmarks/benchmark_cloth_pytorch.py +86 -86
- warp/examples/benchmarks/benchmark_cloth_taichi.py +112 -112
- warp/examples/benchmarks/benchmark_cloth_warp.py +145 -146
- warp/examples/benchmarks/benchmark_launches.py +293 -295
- warp/examples/browse.py +29 -29
- warp/examples/core/example_dem.py +232 -219
- warp/examples/core/example_fluid.py +291 -267
- warp/examples/core/example_graph_capture.py +142 -126
- warp/examples/core/example_marching_cubes.py +186 -174
- warp/examples/core/example_mesh.py +172 -155
- warp/examples/core/example_mesh_intersect.py +203 -193
- warp/examples/core/example_nvdb.py +174 -170
- warp/examples/core/example_raycast.py +103 -90
- warp/examples/core/example_raymarch.py +197 -178
- warp/examples/core/example_render_opengl.py +183 -141
- warp/examples/core/example_sph.py +403 -387
- warp/examples/core/example_torch.py +219 -181
- warp/examples/core/example_wave.py +261 -248
- warp/examples/fem/bsr_utils.py +378 -380
- warp/examples/fem/example_apic_fluid.py +432 -389
- warp/examples/fem/example_burgers.py +262 -0
- warp/examples/fem/example_convection_diffusion.py +180 -168
- warp/examples/fem/example_convection_diffusion_dg.py +217 -209
- warp/examples/fem/example_deformed_geometry.py +175 -159
- warp/examples/fem/example_diffusion.py +199 -173
- warp/examples/fem/example_diffusion_3d.py +178 -152
- warp/examples/fem/example_diffusion_mgpu.py +219 -214
- warp/examples/fem/example_mixed_elasticity.py +242 -222
- warp/examples/fem/example_navier_stokes.py +257 -243
- warp/examples/fem/example_stokes.py +218 -192
- warp/examples/fem/example_stokes_transfer.py +263 -249
- warp/examples/fem/mesh_utils.py +133 -109
- warp/examples/fem/plot_utils.py +292 -287
- warp/examples/optim/example_bounce.py +258 -246
- warp/examples/optim/example_cloth_throw.py +220 -209
- warp/examples/optim/example_diffray.py +564 -536
- warp/examples/optim/example_drone.py +862 -835
- warp/examples/optim/example_inverse_kinematics.py +174 -168
- warp/examples/optim/example_inverse_kinematics_torch.py +183 -169
- warp/examples/optim/example_spring_cage.py +237 -231
- warp/examples/optim/example_trajectory.py +221 -199
- warp/examples/optim/example_walker.py +304 -293
- warp/examples/sim/example_cartpole.py +137 -129
- warp/examples/sim/example_cloth.py +194 -186
- warp/examples/sim/example_granular.py +122 -111
- warp/examples/sim/example_granular_collision_sdf.py +195 -186
- warp/examples/sim/example_jacobian_ik.py +234 -214
- warp/examples/sim/example_particle_chain.py +116 -105
- warp/examples/sim/example_quadruped.py +191 -180
- warp/examples/sim/example_rigid_chain.py +195 -187
- warp/examples/sim/example_rigid_contact.py +187 -177
- warp/examples/sim/example_rigid_force.py +125 -125
- warp/examples/sim/example_rigid_gyroscopic.py +107 -95
- warp/examples/sim/example_rigid_soft_contact.py +132 -122
- warp/examples/sim/example_soft_body.py +188 -177
- warp/fabric.py +337 -335
- warp/fem/__init__.py +61 -27
- warp/fem/cache.py +403 -388
- warp/fem/dirichlet.py +178 -179
- warp/fem/domain.py +262 -263
- warp/fem/field/__init__.py +100 -101
- warp/fem/field/field.py +148 -149
- warp/fem/field/nodal_field.py +298 -299
- warp/fem/field/restriction.py +22 -21
- warp/fem/field/test.py +180 -181
- warp/fem/field/trial.py +183 -183
- warp/fem/geometry/__init__.py +16 -19
- warp/fem/geometry/closest_point.py +69 -70
- warp/fem/geometry/deformed_geometry.py +270 -271
- warp/fem/geometry/element.py +748 -744
- warp/fem/geometry/geometry.py +184 -186
- warp/fem/geometry/grid_2d.py +380 -373
- warp/fem/geometry/grid_3d.py +437 -435
- warp/fem/geometry/hexmesh.py +953 -953
- warp/fem/geometry/nanogrid.py +455 -0
- warp/fem/geometry/partition.py +374 -376
- warp/fem/geometry/quadmesh_2d.py +532 -532
- warp/fem/geometry/tetmesh.py +840 -840
- warp/fem/geometry/trimesh_2d.py +577 -577
- warp/fem/integrate.py +1684 -1615
- warp/fem/operator.py +190 -191
- warp/fem/polynomial.py +214 -213
- warp/fem/quadrature/__init__.py +2 -2
- warp/fem/quadrature/pic_quadrature.py +243 -245
- warp/fem/quadrature/quadrature.py +295 -294
- warp/fem/space/__init__.py +179 -292
- warp/fem/space/basis_space.py +522 -489
- warp/fem/space/collocated_function_space.py +100 -105
- warp/fem/space/dof_mapper.py +236 -236
- warp/fem/space/function_space.py +148 -145
- warp/fem/space/grid_2d_function_space.py +148 -267
- warp/fem/space/grid_3d_function_space.py +167 -306
- warp/fem/space/hexmesh_function_space.py +253 -352
- warp/fem/space/nanogrid_function_space.py +202 -0
- warp/fem/space/partition.py +350 -350
- warp/fem/space/quadmesh_2d_function_space.py +261 -369
- warp/fem/space/restriction.py +161 -160
- warp/fem/space/shape/__init__.py +90 -15
- warp/fem/space/shape/cube_shape_function.py +728 -738
- warp/fem/space/shape/shape_function.py +102 -103
- warp/fem/space/shape/square_shape_function.py +611 -611
- warp/fem/space/shape/tet_shape_function.py +565 -567
- warp/fem/space/shape/triangle_shape_function.py +429 -429
- warp/fem/space/tetmesh_function_space.py +224 -292
- warp/fem/space/topology.py +297 -295
- warp/fem/space/trimesh_2d_function_space.py +153 -221
- warp/fem/types.py +77 -77
- warp/fem/utils.py +495 -495
- warp/jax.py +166 -141
- warp/jax_experimental.py +341 -339
- warp/native/array.h +1081 -1025
- warp/native/builtin.h +1603 -1560
- warp/native/bvh.cpp +402 -398
- warp/native/bvh.cu +533 -525
- warp/native/bvh.h +430 -429
- warp/native/clang/clang.cpp +496 -464
- warp/native/crt.cpp +42 -32
- warp/native/crt.h +352 -335
- warp/native/cuda_crt.h +1049 -1049
- warp/native/cuda_util.cpp +549 -540
- warp/native/cuda_util.h +288 -203
- warp/native/cutlass_gemm.cpp +34 -34
- warp/native/cutlass_gemm.cu +372 -372
- warp/native/error.cpp +66 -66
- warp/native/error.h +27 -27
- warp/native/exports.h +187 -0
- warp/native/fabric.h +228 -228
- warp/native/hashgrid.cpp +301 -278
- warp/native/hashgrid.cu +78 -77
- warp/native/hashgrid.h +227 -227
- warp/native/initializer_array.h +32 -32
- warp/native/intersect.h +1204 -1204
- warp/native/intersect_adj.h +365 -365
- warp/native/intersect_tri.h +322 -322
- warp/native/marching.cpp +2 -2
- warp/native/marching.cu +497 -497
- warp/native/marching.h +2 -2
- warp/native/mat.h +1545 -1498
- warp/native/matnn.h +333 -333
- warp/native/mesh.cpp +203 -203
- warp/native/mesh.cu +292 -293
- warp/native/mesh.h +1887 -1887
- warp/native/nanovdb/GridHandle.h +366 -0
- warp/native/nanovdb/HostBuffer.h +590 -0
- warp/native/nanovdb/NanoVDB.h +6624 -4782
- warp/native/nanovdb/PNanoVDB.h +3390 -2553
- warp/native/noise.h +850 -850
- warp/native/quat.h +1112 -1085
- warp/native/rand.h +303 -299
- warp/native/range.h +108 -108
- warp/native/reduce.cpp +156 -156
- warp/native/reduce.cu +348 -348
- warp/native/runlength_encode.cpp +61 -61
- warp/native/runlength_encode.cu +46 -46
- warp/native/scan.cpp +30 -30
- warp/native/scan.cu +36 -36
- warp/native/scan.h +7 -7
- warp/native/solid_angle.h +442 -442
- warp/native/sort.cpp +94 -94
- warp/native/sort.cu +97 -97
- warp/native/sort.h +14 -14
- warp/native/sparse.cpp +337 -337
- warp/native/sparse.cu +544 -544
- warp/native/spatial.h +630 -630
- warp/native/svd.h +562 -562
- warp/native/temp_buffer.h +30 -30
- warp/native/vec.h +1177 -1133
- warp/native/volume.cpp +529 -297
- warp/native/volume.cu +58 -32
- warp/native/volume.h +960 -538
- warp/native/volume_builder.cu +446 -425
- warp/native/volume_builder.h +34 -19
- warp/native/volume_impl.h +61 -0
- warp/native/warp.cpp +1057 -1052
- warp/native/warp.cu +2949 -2828
- warp/native/warp.h +321 -305
- warp/optim/__init__.py +9 -9
- warp/optim/adam.py +120 -120
- warp/optim/linear.py +1104 -939
- warp/optim/sgd.py +104 -92
- warp/render/__init__.py +10 -10
- warp/render/render_opengl.py +3356 -3204
- warp/render/render_usd.py +768 -749
- warp/render/utils.py +152 -150
- warp/sim/__init__.py +52 -59
- warp/sim/articulation.py +685 -685
- warp/sim/collide.py +1594 -1590
- warp/sim/import_mjcf.py +489 -481
- warp/sim/import_snu.py +220 -221
- warp/sim/import_urdf.py +536 -516
- warp/sim/import_usd.py +887 -881
- warp/sim/inertia.py +316 -317
- warp/sim/integrator.py +234 -233
- warp/sim/integrator_euler.py +1956 -1956
- warp/sim/integrator_featherstone.py +1917 -1991
- warp/sim/integrator_xpbd.py +3288 -3312
- warp/sim/model.py +4473 -4314
- warp/sim/particles.py +113 -112
- warp/sim/render.py +417 -403
- warp/sim/utils.py +413 -410
- warp/sparse.py +1289 -1227
- warp/stubs.py +2192 -2469
- warp/tape.py +1162 -225
- warp/tests/__init__.py +1 -1
- warp/tests/__main__.py +4 -4
- warp/tests/assets/test_index_grid.nvdb +0 -0
- warp/tests/assets/torus.usda +105 -105
- warp/tests/aux_test_class_kernel.py +26 -26
- warp/tests/aux_test_compile_consts_dummy.py +10 -10
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -21
- warp/tests/aux_test_dependent.py +20 -22
- warp/tests/aux_test_grad_customs.py +21 -23
- warp/tests/aux_test_reference.py +9 -11
- warp/tests/aux_test_reference_reference.py +8 -10
- warp/tests/aux_test_square.py +15 -17
- warp/tests/aux_test_unresolved_func.py +14 -14
- warp/tests/aux_test_unresolved_symbol.py +14 -14
- warp/tests/disabled_kinematics.py +237 -239
- warp/tests/run_coverage_serial.py +31 -31
- warp/tests/test_adam.py +155 -157
- warp/tests/test_arithmetic.py +1088 -1124
- warp/tests/test_array.py +2415 -2326
- warp/tests/test_array_reduce.py +148 -150
- warp/tests/test_async.py +666 -656
- warp/tests/test_atomic.py +139 -141
- warp/tests/test_bool.py +212 -149
- warp/tests/test_builtins_resolution.py +1290 -1292
- warp/tests/test_bvh.py +162 -171
- warp/tests/test_closest_point_edge_edge.py +227 -228
- warp/tests/test_codegen.py +562 -553
- warp/tests/test_compile_consts.py +217 -101
- warp/tests/test_conditional.py +244 -246
- warp/tests/test_copy.py +230 -215
- warp/tests/test_ctypes.py +630 -632
- warp/tests/test_dense.py +65 -67
- warp/tests/test_devices.py +89 -98
- warp/tests/test_dlpack.py +528 -529
- warp/tests/test_examples.py +403 -378
- warp/tests/test_fabricarray.py +952 -955
- warp/tests/test_fast_math.py +60 -54
- warp/tests/test_fem.py +1298 -1278
- warp/tests/test_fp16.py +128 -130
- warp/tests/test_func.py +336 -337
- warp/tests/test_generics.py +596 -571
- warp/tests/test_grad.py +885 -640
- warp/tests/test_grad_customs.py +331 -336
- warp/tests/test_hash_grid.py +208 -164
- warp/tests/test_import.py +37 -39
- warp/tests/test_indexedarray.py +1132 -1134
- warp/tests/test_intersect.py +65 -67
- warp/tests/test_jax.py +305 -307
- warp/tests/test_large.py +169 -164
- warp/tests/test_launch.py +352 -354
- warp/tests/test_lerp.py +217 -261
- warp/tests/test_linear_solvers.py +189 -171
- warp/tests/test_lvalue.py +419 -493
- warp/tests/test_marching_cubes.py +63 -65
- warp/tests/test_mat.py +1799 -1827
- warp/tests/test_mat_lite.py +113 -115
- warp/tests/test_mat_scalar_ops.py +2905 -2889
- warp/tests/test_math.py +124 -193
- warp/tests/test_matmul.py +498 -499
- warp/tests/test_matmul_lite.py +408 -410
- warp/tests/test_mempool.py +186 -190
- warp/tests/test_mesh.py +281 -324
- warp/tests/test_mesh_query_aabb.py +226 -241
- warp/tests/test_mesh_query_point.py +690 -702
- warp/tests/test_mesh_query_ray.py +290 -303
- warp/tests/test_mlp.py +274 -276
- warp/tests/test_model.py +108 -110
- warp/tests/test_module_hashing.py +111 -0
- warp/tests/test_modules_lite.py +36 -39
- warp/tests/test_multigpu.py +161 -163
- warp/tests/test_noise.py +244 -248
- warp/tests/test_operators.py +248 -250
- warp/tests/test_options.py +121 -125
- warp/tests/test_peer.py +131 -137
- warp/tests/test_pinned.py +76 -78
- warp/tests/test_print.py +52 -54
- warp/tests/test_quat.py +2084 -2086
- warp/tests/test_rand.py +324 -288
- warp/tests/test_reload.py +207 -217
- warp/tests/test_rounding.py +177 -179
- warp/tests/test_runlength_encode.py +188 -190
- warp/tests/test_sim_grad.py +241 -0
- warp/tests/test_sim_kinematics.py +89 -97
- warp/tests/test_smoothstep.py +166 -168
- warp/tests/test_snippet.py +303 -266
- warp/tests/test_sparse.py +466 -460
- warp/tests/test_spatial.py +2146 -2148
- warp/tests/test_special_values.py +362 -0
- warp/tests/test_streams.py +484 -473
- warp/tests/test_struct.py +708 -675
- warp/tests/test_tape.py +171 -148
- warp/tests/test_torch.py +741 -743
- warp/tests/test_transient_module.py +85 -87
- warp/tests/test_types.py +554 -659
- warp/tests/test_utils.py +488 -499
- warp/tests/test_vec.py +1262 -1268
- warp/tests/test_vec_lite.py +71 -73
- warp/tests/test_vec_scalar_ops.py +2097 -2099
- warp/tests/test_verify_fp.py +92 -94
- warp/tests/test_volume.py +961 -736
- warp/tests/test_volume_write.py +338 -265
- warp/tests/unittest_serial.py +38 -37
- warp/tests/unittest_suites.py +367 -359
- warp/tests/unittest_utils.py +434 -578
- warp/tests/unused_test_misc.py +69 -71
- warp/tests/walkthrough_debug.py +85 -85
- warp/thirdparty/appdirs.py +598 -598
- warp/thirdparty/dlpack.py +143 -143
- warp/thirdparty/unittest_parallel.py +563 -561
- warp/torch.py +321 -295
- warp/types.py +4941 -4450
- warp/utils.py +1008 -821
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/LICENSE.md +126 -126
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/METADATA +365 -400
- warp_lang-1.2.0.dist-info/RECORD +359 -0
- warp/examples/assets/cube.usda +0 -42
- warp/examples/assets/sphere.usda +0 -56
- warp/examples/assets/torus.usda +0 -105
- warp/examples/fem/example_convection_diffusion_dg0.py +0 -194
- warp/native/nanovdb/PNanoVDBWrite.h +0 -295
- warp_lang-1.0.2.dist-info/RECORD +0 -352
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/WHEEL +0 -0
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/top_level.txt +0 -0
warp/native/sparse.cpp
CHANGED
|
@@ -1,338 +1,338 @@
|
|
|
1
|
-
#include "warp.h"
|
|
2
|
-
|
|
3
|
-
#include <algorithm>
|
|
4
|
-
#include <numeric>
|
|
5
|
-
#include <vector>
|
|
6
|
-
|
|
7
|
-
namespace
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
// Specialized is_zero and accumulation function for common block sizes
|
|
11
|
-
// Rely on compiler to unroll loops when block size is known
|
|
12
|
-
|
|
13
|
-
template <int N, typename T> bool bsr_fixed_block_is_zero(const T *val, int value_size)
|
|
14
|
-
{
|
|
15
|
-
return std::all_of(val, val + N, [](float v) { return v == T(0); });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
template <typename T> bool bsr_dyn_block_is_zero(const T *val, int value_size)
|
|
19
|
-
{
|
|
20
|
-
return std::all_of(val, val + value_size, [](float v) { return v == T(0); });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
template <int N, typename T> void bsr_fixed_block_accumulate(const T *val, T *sum, int value_size)
|
|
24
|
-
{
|
|
25
|
-
for (int i = 0; i < N; ++i, ++val, ++sum)
|
|
26
|
-
{
|
|
27
|
-
*sum += *val;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
template <typename T> void bsr_dyn_block_accumulate(const T *val, T *sum, int value_size)
|
|
32
|
-
{
|
|
33
|
-
for (int i = 0; i < value_size; ++i, ++val, ++sum)
|
|
34
|
-
{
|
|
35
|
-
*sum += *val;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
template <int Rows, int Cols, typename T>
|
|
40
|
-
void bsr_fixed_block_transpose(const T *src, T *dest, int row_count, int col_count)
|
|
41
|
-
{
|
|
42
|
-
for (int r = 0; r < Rows; ++r)
|
|
43
|
-
{
|
|
44
|
-
for (int c = 0; c < Cols; ++c)
|
|
45
|
-
{
|
|
46
|
-
dest[c * Rows + r] = src[r * Cols + c];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
template <typename T> void bsr_dyn_block_transpose(const T *src, T *dest, int row_count, int col_count)
|
|
52
|
-
{
|
|
53
|
-
for (int r = 0; r < row_count; ++r)
|
|
54
|
-
{
|
|
55
|
-
for (int c = 0; c < col_count; ++c)
|
|
56
|
-
{
|
|
57
|
-
dest[c * row_count + r] = src[r * col_count + c];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
} // namespace
|
|
63
|
-
|
|
64
|
-
template <typename T>
|
|
65
|
-
int bsr_matrix_from_triplets_host(const int rows_per_block, const int cols_per_block, const int row_count,
|
|
66
|
-
const int nnz, const int *tpl_rows, const int *tpl_columns, const T *tpl_values,
|
|
67
|
-
int *bsr_offsets, int *bsr_columns, T *bsr_values)
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
// get specialized accumulator for common block sizes (1,1), (1,2), (1,3),
|
|
71
|
-
// (2,2), (2,3), (3,3)
|
|
72
|
-
const int block_size = rows_per_block * cols_per_block;
|
|
73
|
-
void (*block_accumulate_func)(const T *, T *, int);
|
|
74
|
-
bool (*block_is_zero_func)(const T *, int);
|
|
75
|
-
switch (block_size)
|
|
76
|
-
{
|
|
77
|
-
case 1:
|
|
78
|
-
block_accumulate_func = bsr_fixed_block_accumulate<1, T>;
|
|
79
|
-
block_is_zero_func = bsr_fixed_block_is_zero<1, T>;
|
|
80
|
-
break;
|
|
81
|
-
case 2:
|
|
82
|
-
block_accumulate_func = bsr_fixed_block_accumulate<2, T>;
|
|
83
|
-
block_is_zero_func = bsr_fixed_block_is_zero<2, T>;
|
|
84
|
-
break;
|
|
85
|
-
case 3:
|
|
86
|
-
block_accumulate_func = bsr_fixed_block_accumulate<3, T>;
|
|
87
|
-
block_is_zero_func = bsr_fixed_block_is_zero<3, T>;
|
|
88
|
-
break;
|
|
89
|
-
case 4:
|
|
90
|
-
block_accumulate_func = bsr_fixed_block_accumulate<4, T>;
|
|
91
|
-
block_is_zero_func = bsr_fixed_block_is_zero<4, T>;
|
|
92
|
-
break;
|
|
93
|
-
case 6:
|
|
94
|
-
block_accumulate_func = bsr_fixed_block_accumulate<6, T>;
|
|
95
|
-
block_is_zero_func = bsr_fixed_block_is_zero<6, T>;
|
|
96
|
-
break;
|
|
97
|
-
case 9:
|
|
98
|
-
block_accumulate_func = bsr_fixed_block_accumulate<9, T>;
|
|
99
|
-
block_is_zero_func = bsr_fixed_block_is_zero<9, T>;
|
|
100
|
-
break;
|
|
101
|
-
default:
|
|
102
|
-
block_accumulate_func = bsr_dyn_block_accumulate<T>;
|
|
103
|
-
block_is_zero_func = bsr_dyn_block_is_zero<T>;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
std::vector<int> block_indices(nnz);
|
|
107
|
-
std::iota(block_indices.begin(), block_indices.end(), 0);
|
|
108
|
-
|
|
109
|
-
// remove zero block indices
|
|
110
|
-
if (tpl_values)
|
|
111
|
-
{
|
|
112
|
-
block_indices.erase(std::remove_if(block_indices.begin(), block_indices.end(),
|
|
113
|
-
[block_is_zero_func, tpl_values, block_size](int i) {
|
|
114
|
-
return block_is_zero_func(tpl_values + i * block_size, block_size);
|
|
115
|
-
}),
|
|
116
|
-
block_indices.end());
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// sort block indices according to lexico order
|
|
120
|
-
std::sort(block_indices.begin(), block_indices.end(), [tpl_rows, tpl_columns](int i, int j) -> bool {
|
|
121
|
-
return tpl_rows[i] < tpl_rows[j] || (tpl_rows[i] == tpl_rows[j] && tpl_columns[i] < tpl_columns[j]);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// accumulate blocks at same locations, count blocks per row
|
|
125
|
-
std::fill_n(bsr_offsets, row_count + 1, 0);
|
|
126
|
-
|
|
127
|
-
int current_row = -1;
|
|
128
|
-
int current_col = -1;
|
|
129
|
-
|
|
130
|
-
// so that we get back to the start for the first block
|
|
131
|
-
if (bsr_values)
|
|
132
|
-
{
|
|
133
|
-
bsr_values -= block_size;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
for (int i = 0; i < block_indices.size(); ++i)
|
|
137
|
-
{
|
|
138
|
-
int idx = block_indices[i];
|
|
139
|
-
int row = tpl_rows[idx];
|
|
140
|
-
int col = tpl_columns[idx];
|
|
141
|
-
const T *val = tpl_values + idx * block_size;
|
|
142
|
-
|
|
143
|
-
if (row == current_row && col == current_col)
|
|
144
|
-
{
|
|
145
|
-
if (bsr_values)
|
|
146
|
-
{
|
|
147
|
-
block_accumulate_func(val, bsr_values, block_size);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else
|
|
151
|
-
{
|
|
152
|
-
*(bsr_columns++) = col;
|
|
153
|
-
|
|
154
|
-
if (bsr_values)
|
|
155
|
-
{
|
|
156
|
-
bsr_values += block_size;
|
|
157
|
-
std::copy_n(val, block_size, bsr_values);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
bsr_offsets[row + 1]++;
|
|
161
|
-
|
|
162
|
-
current_row = row;
|
|
163
|
-
current_col = col;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// build postfix sum of row counts
|
|
168
|
-
std::partial_sum(bsr_offsets, bsr_offsets + row_count + 1, bsr_offsets);
|
|
169
|
-
|
|
170
|
-
return bsr_offsets[row_count];
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
template <typename T>
|
|
174
|
-
void bsr_transpose_host(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
175
|
-
const int *bsr_offsets, const int *bsr_columns, const T *bsr_values,
|
|
176
|
-
int *transposed_bsr_offsets, int *transposed_bsr_columns, T *transposed_bsr_values)
|
|
177
|
-
{
|
|
178
|
-
|
|
179
|
-
const int block_size = rows_per_block * cols_per_block;
|
|
180
|
-
|
|
181
|
-
void (*block_transpose_func)(const T *, T *, int, int) = bsr_dyn_block_transpose<T>;
|
|
182
|
-
switch (rows_per_block)
|
|
183
|
-
{
|
|
184
|
-
case 1:
|
|
185
|
-
switch (cols_per_block)
|
|
186
|
-
{
|
|
187
|
-
case 1:
|
|
188
|
-
block_transpose_func = bsr_fixed_block_transpose<1, 1, T>;
|
|
189
|
-
break;
|
|
190
|
-
case 2:
|
|
191
|
-
block_transpose_func = bsr_fixed_block_transpose<1, 2, T>;
|
|
192
|
-
break;
|
|
193
|
-
case 3:
|
|
194
|
-
block_transpose_func = bsr_fixed_block_transpose<1, 3, T>;
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
break;
|
|
198
|
-
case 2:
|
|
199
|
-
switch (cols_per_block)
|
|
200
|
-
{
|
|
201
|
-
case 1:
|
|
202
|
-
block_transpose_func = bsr_fixed_block_transpose<2, 1, T>;
|
|
203
|
-
break;
|
|
204
|
-
case 2:
|
|
205
|
-
block_transpose_func = bsr_fixed_block_transpose<2, 2, T>;
|
|
206
|
-
break;
|
|
207
|
-
case 3:
|
|
208
|
-
block_transpose_func = bsr_fixed_block_transpose<2, 3, T>;
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
break;
|
|
212
|
-
case 3:
|
|
213
|
-
switch (cols_per_block)
|
|
214
|
-
{
|
|
215
|
-
case 1:
|
|
216
|
-
block_transpose_func = bsr_fixed_block_transpose<3, 1, T>;
|
|
217
|
-
break;
|
|
218
|
-
case 2:
|
|
219
|
-
block_transpose_func = bsr_fixed_block_transpose<3, 2, T>;
|
|
220
|
-
break;
|
|
221
|
-
case 3:
|
|
222
|
-
block_transpose_func = bsr_fixed_block_transpose<3, 3, T>;
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
std::vector<int> block_indices(nnz), bsr_rows(nnz);
|
|
229
|
-
std::iota(block_indices.begin(), block_indices.end(), 0);
|
|
230
|
-
|
|
231
|
-
// Fill row indices from offsets
|
|
232
|
-
for (int row = 0; row < row_count; ++row)
|
|
233
|
-
{
|
|
234
|
-
std::fill(bsr_rows.begin() + bsr_offsets[row], bsr_rows.begin() + bsr_offsets[row + 1], row);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// sort block indices according to (transposed) lexico order
|
|
238
|
-
std::sort(block_indices.begin(), block_indices.end(), [&bsr_rows, bsr_columns](int i, int j) -> bool {
|
|
239
|
-
return bsr_columns[i] < bsr_columns[j] || (bsr_columns[i] == bsr_columns[j] && bsr_rows[i] < bsr_rows[j]);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
// Count blocks per column and transpose blocks
|
|
243
|
-
std::fill_n(transposed_bsr_offsets, col_count + 1, 0);
|
|
244
|
-
|
|
245
|
-
for (int i = 0; i < nnz; ++i)
|
|
246
|
-
{
|
|
247
|
-
int idx = block_indices[i];
|
|
248
|
-
int row = bsr_rows[idx];
|
|
249
|
-
int col = bsr_columns[idx];
|
|
250
|
-
|
|
251
|
-
++transposed_bsr_offsets[col + 1];
|
|
252
|
-
transposed_bsr_columns[i] = row;
|
|
253
|
-
|
|
254
|
-
const T *src_block = bsr_values + idx * block_size;
|
|
255
|
-
T *dst_block = transposed_bsr_values + i * block_size;
|
|
256
|
-
block_transpose_func(src_block, dst_block, rows_per_block, cols_per_block);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// build postfix sum of column counts
|
|
260
|
-
std::partial_sum(transposed_bsr_offsets, transposed_bsr_offsets + col_count + 1, transposed_bsr_offsets);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
WP_API int bsr_matrix_from_triplets_float_host(int rows_per_block, int cols_per_block, int row_count, int nnz,
|
|
264
|
-
uint64_t tpl_rows, uint64_t tpl_columns, uint64_t tpl_values,
|
|
265
|
-
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values)
|
|
266
|
-
{
|
|
267
|
-
return bsr_matrix_from_triplets_host(
|
|
268
|
-
rows_per_block, cols_per_block, row_count, nnz, reinterpret_cast<const int *>(tpl_rows),
|
|
269
|
-
reinterpret_cast<const int *>(tpl_columns), reinterpret_cast<const float *>(tpl_values),
|
|
270
|
-
reinterpret_cast<int *>(bsr_offsets), reinterpret_cast<int *>(bsr_columns),
|
|
271
|
-
reinterpret_cast<float *>(bsr_values));
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
WP_API int bsr_matrix_from_triplets_double_host(int rows_per_block, int cols_per_block, int row_count, int nnz,
|
|
275
|
-
uint64_t tpl_rows, uint64_t tpl_columns, uint64_t tpl_values,
|
|
276
|
-
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values)
|
|
277
|
-
{
|
|
278
|
-
return bsr_matrix_from_triplets_host(
|
|
279
|
-
rows_per_block, cols_per_block, row_count, nnz, reinterpret_cast<const int *>(tpl_rows),
|
|
280
|
-
reinterpret_cast<const int *>(tpl_columns), reinterpret_cast<const double *>(tpl_values),
|
|
281
|
-
reinterpret_cast<int *>(bsr_offsets), reinterpret_cast<int *>(bsr_columns),
|
|
282
|
-
reinterpret_cast<double *>(bsr_values));
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
WP_API void bsr_transpose_float_host(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
286
|
-
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values,
|
|
287
|
-
uint64_t transposed_bsr_offsets, uint64_t transposed_bsr_columns,
|
|
288
|
-
uint64_t transposed_bsr_values)
|
|
289
|
-
{
|
|
290
|
-
bsr_transpose_host(rows_per_block, cols_per_block, row_count, col_count, nnz,
|
|
291
|
-
reinterpret_cast<const int *>(bsr_offsets), reinterpret_cast<const int *>(bsr_columns),
|
|
292
|
-
reinterpret_cast<const float *>(bsr_values), reinterpret_cast<int *>(transposed_bsr_offsets),
|
|
293
|
-
reinterpret_cast<int *>(transposed_bsr_columns),
|
|
294
|
-
reinterpret_cast<float *>(transposed_bsr_values));
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
WP_API void bsr_transpose_double_host(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
298
|
-
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values,
|
|
299
|
-
uint64_t transposed_bsr_offsets, uint64_t transposed_bsr_columns,
|
|
300
|
-
uint64_t transposed_bsr_values)
|
|
301
|
-
{
|
|
302
|
-
bsr_transpose_host(rows_per_block, cols_per_block, row_count, col_count, nnz,
|
|
303
|
-
reinterpret_cast<const int *>(bsr_offsets), reinterpret_cast<const int *>(bsr_columns),
|
|
304
|
-
reinterpret_cast<const double *>(bsr_values), reinterpret_cast<int *>(transposed_bsr_offsets),
|
|
305
|
-
reinterpret_cast<int *>(transposed_bsr_columns),
|
|
306
|
-
reinterpret_cast<double *>(transposed_bsr_values));
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
#if !WP_ENABLE_CUDA
|
|
310
|
-
WP_API int bsr_matrix_from_triplets_float_device(int rows_per_block, int cols_per_block, int row_count, int nnz,
|
|
311
|
-
uint64_t tpl_rows, uint64_t tpl_columns, uint64_t tpl_values,
|
|
312
|
-
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values)
|
|
313
|
-
{
|
|
314
|
-
return 0;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
WP_API int bsr_matrix_from_triplets_double_device(int rows_per_block, int cols_per_block, int row_count, int nnz,
|
|
318
|
-
uint64_t tpl_rows, uint64_t tpl_columns, uint64_t tpl_values,
|
|
319
|
-
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values)
|
|
320
|
-
{
|
|
321
|
-
return 0;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
WP_API void bsr_transpose_float_device(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
325
|
-
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values,
|
|
326
|
-
uint64_t transposed_bsr_offsets, uint64_t transposed_bsr_columns,
|
|
327
|
-
uint64_t transposed_bsr_values)
|
|
328
|
-
{
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
WP_API void bsr_transpose_double_device(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
332
|
-
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values,
|
|
333
|
-
uint64_t transposed_bsr_offsets, uint64_t transposed_bsr_columns,
|
|
334
|
-
uint64_t transposed_bsr_values)
|
|
335
|
-
{
|
|
336
|
-
}
|
|
337
|
-
|
|
1
|
+
#include "warp.h"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <numeric>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
namespace
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
// Specialized is_zero and accumulation function for common block sizes
|
|
11
|
+
// Rely on compiler to unroll loops when block size is known
|
|
12
|
+
|
|
13
|
+
template <int N, typename T> bool bsr_fixed_block_is_zero(const T *val, int value_size)
|
|
14
|
+
{
|
|
15
|
+
return std::all_of(val, val + N, [](float v) { return v == T(0); });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
template <typename T> bool bsr_dyn_block_is_zero(const T *val, int value_size)
|
|
19
|
+
{
|
|
20
|
+
return std::all_of(val, val + value_size, [](float v) { return v == T(0); });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
template <int N, typename T> void bsr_fixed_block_accumulate(const T *val, T *sum, int value_size)
|
|
24
|
+
{
|
|
25
|
+
for (int i = 0; i < N; ++i, ++val, ++sum)
|
|
26
|
+
{
|
|
27
|
+
*sum += *val;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
template <typename T> void bsr_dyn_block_accumulate(const T *val, T *sum, int value_size)
|
|
32
|
+
{
|
|
33
|
+
for (int i = 0; i < value_size; ++i, ++val, ++sum)
|
|
34
|
+
{
|
|
35
|
+
*sum += *val;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
template <int Rows, int Cols, typename T>
|
|
40
|
+
void bsr_fixed_block_transpose(const T *src, T *dest, int row_count, int col_count)
|
|
41
|
+
{
|
|
42
|
+
for (int r = 0; r < Rows; ++r)
|
|
43
|
+
{
|
|
44
|
+
for (int c = 0; c < Cols; ++c)
|
|
45
|
+
{
|
|
46
|
+
dest[c * Rows + r] = src[r * Cols + c];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
template <typename T> void bsr_dyn_block_transpose(const T *src, T *dest, int row_count, int col_count)
|
|
52
|
+
{
|
|
53
|
+
for (int r = 0; r < row_count; ++r)
|
|
54
|
+
{
|
|
55
|
+
for (int c = 0; c < col_count; ++c)
|
|
56
|
+
{
|
|
57
|
+
dest[c * row_count + r] = src[r * col_count + c];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
} // namespace
|
|
63
|
+
|
|
64
|
+
template <typename T>
|
|
65
|
+
int bsr_matrix_from_triplets_host(const int rows_per_block, const int cols_per_block, const int row_count,
|
|
66
|
+
const int nnz, const int *tpl_rows, const int *tpl_columns, const T *tpl_values,
|
|
67
|
+
int *bsr_offsets, int *bsr_columns, T *bsr_values)
|
|
68
|
+
{
|
|
69
|
+
|
|
70
|
+
// get specialized accumulator for common block sizes (1,1), (1,2), (1,3),
|
|
71
|
+
// (2,2), (2,3), (3,3)
|
|
72
|
+
const int block_size = rows_per_block * cols_per_block;
|
|
73
|
+
void (*block_accumulate_func)(const T *, T *, int);
|
|
74
|
+
bool (*block_is_zero_func)(const T *, int);
|
|
75
|
+
switch (block_size)
|
|
76
|
+
{
|
|
77
|
+
case 1:
|
|
78
|
+
block_accumulate_func = bsr_fixed_block_accumulate<1, T>;
|
|
79
|
+
block_is_zero_func = bsr_fixed_block_is_zero<1, T>;
|
|
80
|
+
break;
|
|
81
|
+
case 2:
|
|
82
|
+
block_accumulate_func = bsr_fixed_block_accumulate<2, T>;
|
|
83
|
+
block_is_zero_func = bsr_fixed_block_is_zero<2, T>;
|
|
84
|
+
break;
|
|
85
|
+
case 3:
|
|
86
|
+
block_accumulate_func = bsr_fixed_block_accumulate<3, T>;
|
|
87
|
+
block_is_zero_func = bsr_fixed_block_is_zero<3, T>;
|
|
88
|
+
break;
|
|
89
|
+
case 4:
|
|
90
|
+
block_accumulate_func = bsr_fixed_block_accumulate<4, T>;
|
|
91
|
+
block_is_zero_func = bsr_fixed_block_is_zero<4, T>;
|
|
92
|
+
break;
|
|
93
|
+
case 6:
|
|
94
|
+
block_accumulate_func = bsr_fixed_block_accumulate<6, T>;
|
|
95
|
+
block_is_zero_func = bsr_fixed_block_is_zero<6, T>;
|
|
96
|
+
break;
|
|
97
|
+
case 9:
|
|
98
|
+
block_accumulate_func = bsr_fixed_block_accumulate<9, T>;
|
|
99
|
+
block_is_zero_func = bsr_fixed_block_is_zero<9, T>;
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
block_accumulate_func = bsr_dyn_block_accumulate<T>;
|
|
103
|
+
block_is_zero_func = bsr_dyn_block_is_zero<T>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
std::vector<int> block_indices(nnz);
|
|
107
|
+
std::iota(block_indices.begin(), block_indices.end(), 0);
|
|
108
|
+
|
|
109
|
+
// remove zero block indices
|
|
110
|
+
if (tpl_values)
|
|
111
|
+
{
|
|
112
|
+
block_indices.erase(std::remove_if(block_indices.begin(), block_indices.end(),
|
|
113
|
+
[block_is_zero_func, tpl_values, block_size](int i) {
|
|
114
|
+
return block_is_zero_func(tpl_values + i * block_size, block_size);
|
|
115
|
+
}),
|
|
116
|
+
block_indices.end());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// sort block indices according to lexico order
|
|
120
|
+
std::sort(block_indices.begin(), block_indices.end(), [tpl_rows, tpl_columns](int i, int j) -> bool {
|
|
121
|
+
return tpl_rows[i] < tpl_rows[j] || (tpl_rows[i] == tpl_rows[j] && tpl_columns[i] < tpl_columns[j]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// accumulate blocks at same locations, count blocks per row
|
|
125
|
+
std::fill_n(bsr_offsets, row_count + 1, 0);
|
|
126
|
+
|
|
127
|
+
int current_row = -1;
|
|
128
|
+
int current_col = -1;
|
|
129
|
+
|
|
130
|
+
// so that we get back to the start for the first block
|
|
131
|
+
if (bsr_values)
|
|
132
|
+
{
|
|
133
|
+
bsr_values -= block_size;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
for (int i = 0; i < block_indices.size(); ++i)
|
|
137
|
+
{
|
|
138
|
+
int idx = block_indices[i];
|
|
139
|
+
int row = tpl_rows[idx];
|
|
140
|
+
int col = tpl_columns[idx];
|
|
141
|
+
const T *val = tpl_values + idx * block_size;
|
|
142
|
+
|
|
143
|
+
if (row == current_row && col == current_col)
|
|
144
|
+
{
|
|
145
|
+
if (bsr_values)
|
|
146
|
+
{
|
|
147
|
+
block_accumulate_func(val, bsr_values, block_size);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else
|
|
151
|
+
{
|
|
152
|
+
*(bsr_columns++) = col;
|
|
153
|
+
|
|
154
|
+
if (bsr_values)
|
|
155
|
+
{
|
|
156
|
+
bsr_values += block_size;
|
|
157
|
+
std::copy_n(val, block_size, bsr_values);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
bsr_offsets[row + 1]++;
|
|
161
|
+
|
|
162
|
+
current_row = row;
|
|
163
|
+
current_col = col;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// build postfix sum of row counts
|
|
168
|
+
std::partial_sum(bsr_offsets, bsr_offsets + row_count + 1, bsr_offsets);
|
|
169
|
+
|
|
170
|
+
return bsr_offsets[row_count];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
template <typename T>
|
|
174
|
+
void bsr_transpose_host(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
175
|
+
const int *bsr_offsets, const int *bsr_columns, const T *bsr_values,
|
|
176
|
+
int *transposed_bsr_offsets, int *transposed_bsr_columns, T *transposed_bsr_values)
|
|
177
|
+
{
|
|
178
|
+
|
|
179
|
+
const int block_size = rows_per_block * cols_per_block;
|
|
180
|
+
|
|
181
|
+
void (*block_transpose_func)(const T *, T *, int, int) = bsr_dyn_block_transpose<T>;
|
|
182
|
+
switch (rows_per_block)
|
|
183
|
+
{
|
|
184
|
+
case 1:
|
|
185
|
+
switch (cols_per_block)
|
|
186
|
+
{
|
|
187
|
+
case 1:
|
|
188
|
+
block_transpose_func = bsr_fixed_block_transpose<1, 1, T>;
|
|
189
|
+
break;
|
|
190
|
+
case 2:
|
|
191
|
+
block_transpose_func = bsr_fixed_block_transpose<1, 2, T>;
|
|
192
|
+
break;
|
|
193
|
+
case 3:
|
|
194
|
+
block_transpose_func = bsr_fixed_block_transpose<1, 3, T>;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
case 2:
|
|
199
|
+
switch (cols_per_block)
|
|
200
|
+
{
|
|
201
|
+
case 1:
|
|
202
|
+
block_transpose_func = bsr_fixed_block_transpose<2, 1, T>;
|
|
203
|
+
break;
|
|
204
|
+
case 2:
|
|
205
|
+
block_transpose_func = bsr_fixed_block_transpose<2, 2, T>;
|
|
206
|
+
break;
|
|
207
|
+
case 3:
|
|
208
|
+
block_transpose_func = bsr_fixed_block_transpose<2, 3, T>;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
case 3:
|
|
213
|
+
switch (cols_per_block)
|
|
214
|
+
{
|
|
215
|
+
case 1:
|
|
216
|
+
block_transpose_func = bsr_fixed_block_transpose<3, 1, T>;
|
|
217
|
+
break;
|
|
218
|
+
case 2:
|
|
219
|
+
block_transpose_func = bsr_fixed_block_transpose<3, 2, T>;
|
|
220
|
+
break;
|
|
221
|
+
case 3:
|
|
222
|
+
block_transpose_func = bsr_fixed_block_transpose<3, 3, T>;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
std::vector<int> block_indices(nnz), bsr_rows(nnz);
|
|
229
|
+
std::iota(block_indices.begin(), block_indices.end(), 0);
|
|
230
|
+
|
|
231
|
+
// Fill row indices from offsets
|
|
232
|
+
for (int row = 0; row < row_count; ++row)
|
|
233
|
+
{
|
|
234
|
+
std::fill(bsr_rows.begin() + bsr_offsets[row], bsr_rows.begin() + bsr_offsets[row + 1], row);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// sort block indices according to (transposed) lexico order
|
|
238
|
+
std::sort(block_indices.begin(), block_indices.end(), [&bsr_rows, bsr_columns](int i, int j) -> bool {
|
|
239
|
+
return bsr_columns[i] < bsr_columns[j] || (bsr_columns[i] == bsr_columns[j] && bsr_rows[i] < bsr_rows[j]);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Count blocks per column and transpose blocks
|
|
243
|
+
std::fill_n(transposed_bsr_offsets, col_count + 1, 0);
|
|
244
|
+
|
|
245
|
+
for (int i = 0; i < nnz; ++i)
|
|
246
|
+
{
|
|
247
|
+
int idx = block_indices[i];
|
|
248
|
+
int row = bsr_rows[idx];
|
|
249
|
+
int col = bsr_columns[idx];
|
|
250
|
+
|
|
251
|
+
++transposed_bsr_offsets[col + 1];
|
|
252
|
+
transposed_bsr_columns[i] = row;
|
|
253
|
+
|
|
254
|
+
const T *src_block = bsr_values + idx * block_size;
|
|
255
|
+
T *dst_block = transposed_bsr_values + i * block_size;
|
|
256
|
+
block_transpose_func(src_block, dst_block, rows_per_block, cols_per_block);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// build postfix sum of column counts
|
|
260
|
+
std::partial_sum(transposed_bsr_offsets, transposed_bsr_offsets + col_count + 1, transposed_bsr_offsets);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
WP_API int bsr_matrix_from_triplets_float_host(int rows_per_block, int cols_per_block, int row_count, int nnz,
|
|
264
|
+
uint64_t tpl_rows, uint64_t tpl_columns, uint64_t tpl_values,
|
|
265
|
+
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values)
|
|
266
|
+
{
|
|
267
|
+
return bsr_matrix_from_triplets_host(
|
|
268
|
+
rows_per_block, cols_per_block, row_count, nnz, reinterpret_cast<const int *>(tpl_rows),
|
|
269
|
+
reinterpret_cast<const int *>(tpl_columns), reinterpret_cast<const float *>(tpl_values),
|
|
270
|
+
reinterpret_cast<int *>(bsr_offsets), reinterpret_cast<int *>(bsr_columns),
|
|
271
|
+
reinterpret_cast<float *>(bsr_values));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
WP_API int bsr_matrix_from_triplets_double_host(int rows_per_block, int cols_per_block, int row_count, int nnz,
|
|
275
|
+
uint64_t tpl_rows, uint64_t tpl_columns, uint64_t tpl_values,
|
|
276
|
+
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values)
|
|
277
|
+
{
|
|
278
|
+
return bsr_matrix_from_triplets_host(
|
|
279
|
+
rows_per_block, cols_per_block, row_count, nnz, reinterpret_cast<const int *>(tpl_rows),
|
|
280
|
+
reinterpret_cast<const int *>(tpl_columns), reinterpret_cast<const double *>(tpl_values),
|
|
281
|
+
reinterpret_cast<int *>(bsr_offsets), reinterpret_cast<int *>(bsr_columns),
|
|
282
|
+
reinterpret_cast<double *>(bsr_values));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
WP_API void bsr_transpose_float_host(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
286
|
+
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values,
|
|
287
|
+
uint64_t transposed_bsr_offsets, uint64_t transposed_bsr_columns,
|
|
288
|
+
uint64_t transposed_bsr_values)
|
|
289
|
+
{
|
|
290
|
+
bsr_transpose_host(rows_per_block, cols_per_block, row_count, col_count, nnz,
|
|
291
|
+
reinterpret_cast<const int *>(bsr_offsets), reinterpret_cast<const int *>(bsr_columns),
|
|
292
|
+
reinterpret_cast<const float *>(bsr_values), reinterpret_cast<int *>(transposed_bsr_offsets),
|
|
293
|
+
reinterpret_cast<int *>(transposed_bsr_columns),
|
|
294
|
+
reinterpret_cast<float *>(transposed_bsr_values));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
WP_API void bsr_transpose_double_host(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
298
|
+
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values,
|
|
299
|
+
uint64_t transposed_bsr_offsets, uint64_t transposed_bsr_columns,
|
|
300
|
+
uint64_t transposed_bsr_values)
|
|
301
|
+
{
|
|
302
|
+
bsr_transpose_host(rows_per_block, cols_per_block, row_count, col_count, nnz,
|
|
303
|
+
reinterpret_cast<const int *>(bsr_offsets), reinterpret_cast<const int *>(bsr_columns),
|
|
304
|
+
reinterpret_cast<const double *>(bsr_values), reinterpret_cast<int *>(transposed_bsr_offsets),
|
|
305
|
+
reinterpret_cast<int *>(transposed_bsr_columns),
|
|
306
|
+
reinterpret_cast<double *>(transposed_bsr_values));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
#if !WP_ENABLE_CUDA
|
|
310
|
+
WP_API int bsr_matrix_from_triplets_float_device(int rows_per_block, int cols_per_block, int row_count, int nnz,
|
|
311
|
+
uint64_t tpl_rows, uint64_t tpl_columns, uint64_t tpl_values,
|
|
312
|
+
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values)
|
|
313
|
+
{
|
|
314
|
+
return 0;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
WP_API int bsr_matrix_from_triplets_double_device(int rows_per_block, int cols_per_block, int row_count, int nnz,
|
|
318
|
+
uint64_t tpl_rows, uint64_t tpl_columns, uint64_t tpl_values,
|
|
319
|
+
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values)
|
|
320
|
+
{
|
|
321
|
+
return 0;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
WP_API void bsr_transpose_float_device(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
325
|
+
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values,
|
|
326
|
+
uint64_t transposed_bsr_offsets, uint64_t transposed_bsr_columns,
|
|
327
|
+
uint64_t transposed_bsr_values)
|
|
328
|
+
{
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
WP_API void bsr_transpose_double_device(int rows_per_block, int cols_per_block, int row_count, int col_count, int nnz,
|
|
332
|
+
uint64_t bsr_offsets, uint64_t bsr_columns, uint64_t bsr_values,
|
|
333
|
+
uint64_t transposed_bsr_offsets, uint64_t transposed_bsr_columns,
|
|
334
|
+
uint64_t transposed_bsr_values)
|
|
335
|
+
{
|
|
336
|
+
}
|
|
337
|
+
|
|
338
338
|
#endif
|