Skip to content

Commit

Permalink
return inverse permutatuin for gpund and gpumnd
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdhn committed Sep 16, 2024
1 parent 41cee4d commit 95bcdc7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
40 changes: 20 additions & 20 deletions apps/NDReorder/test_all_permutations.cu
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ void no_permute(rxmesh::RXMeshStatic& rx, const EigeMatT& eigen_mat)
RXMESH_INFO(" No-permutation NNZ = {}", nnz);
}

template <typename T>
std::vector<T> inverse_permutation(const std::vector<T>& perm)
{
std::vector<int> perm_inv(perm.size());

for (int i = 0; i < perm_inv.size(); ++i) {
perm_inv[perm[i]] = i;
}

return perm_inv;
}


template <typename T, typename EigeMatT>
void with_metis(rxmesh::RXMeshStatic& rx,
Expand Down Expand Up @@ -160,6 +148,10 @@ void with_gpumgnd(rxmesh::RXMeshStatic& rx, const EigeMatT& eigen_mat)
EXPECT_TRUE(
rxmesh::is_unique_permutation(h_permute.size(), h_permute.data()));

std::vector<int> helper(rx.get_num_vertices());
rxmesh::inverse_permutation(
rx.get_num_vertices(), h_permute.data(), helper.data());

// render_permutation(rx, h_permute, "GPUMGND");

int nnz = count_nnz_fillin(eigen_mat, h_permute, "gpumgnd");
Expand All @@ -177,6 +169,10 @@ void with_gpu_nd(rxmesh::RXMeshStatic& rx, const EigeMatT& eigen_mat)
EXPECT_TRUE(
rxmesh::is_unique_permutation(h_permute.size(), h_permute.data()));

std::vector<int> helper(rx.get_num_vertices());
rxmesh::inverse_permutation(
rx.get_num_vertices(), h_permute.data(), helper.data());

// render_permutation(rx, h_permute, "GPUND");

int nnz = count_nnz_fillin(eigen_mat, h_permute, "gpund");
Expand All @@ -201,15 +197,17 @@ void with_amd(rxmesh::RXMeshStatic& rx,
h_permute.size() * sizeof(int));


std::vector<int> h_permute_inv = inverse_permutation(h_permute);
std::vector<int> helper(rx.get_num_vertices());
rxmesh::inverse_permutation(
rx.get_num_vertices(), h_permute.data(), helper.data());


EXPECT_TRUE(rxmesh::is_unique_permutation(h_permute_inv.size(),
h_permute_inv.data()));
EXPECT_TRUE(
rxmesh::is_unique_permutation(h_permute.size(), h_permute.data()));

// render_permutation(rx, h_permute_inv, "AMD");
// render_permutation(rx, h_permute, "AMD");

int nnz = count_nnz_fillin(eigen_mat, h_permute_inv, "amd");
int nnz = count_nnz_fillin(eigen_mat, h_permute, "amd");

RXMESH_INFO(" With AMD NNZ = {}", nnz);
}
Expand All @@ -233,11 +231,13 @@ void with_symrcm(rxmesh::RXMeshStatic& rx,
EXPECT_TRUE(
rxmesh::is_unique_permutation(h_permute.size(), h_permute.data()));

std::vector<int> h_permute_inv = inverse_permutation(h_permute);
std::vector<int> helper(rx.get_num_vertices());
rxmesh::inverse_permutation(
rx.get_num_vertices(), h_permute.data(), helper.data());

// render_permutation(rx, h_permute_inv, "symrcm");
// render_permutation(rx, h_permute, "symrcm");

int nnz = count_nnz_fillin(eigen_mat, h_permute_inv, "symrcm");
int nnz = count_nnz_fillin(eigen_mat, h_permute, "symrcm");

RXMESH_INFO(" With SYMRCM NNZ = {}", nnz);
}
Expand Down
5 changes: 5 additions & 0 deletions include/rxmesh/matrix/mgnd_permute.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <thrust/execution_policy.h>
#include <thrust/scan.h>

#include "rxmesh/matrix/permute_util.h"

namespace rxmesh {

namespace detail {
Expand Down Expand Up @@ -150,6 +152,9 @@ inline void mgnd_permute(const RXMeshStatic& rx, int* h_permute)
rx.get_num_vertices() * sizeof(int),
cudaMemcpyDeviceToHost));

std::vector<int> helper(rx.get_num_vertices());
inverse_permutation(rx.get_num_vertices(), h_permute, helper.data());

GPU_FREE(d_v_ordering_prefix_sum);
GPU_FREE(d_permute);
}
Expand Down
4 changes: 4 additions & 0 deletions include/rxmesh/matrix/nd_permute.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,10 @@ void nd_permute(RXMeshStatic& rx, int* h_permute)
rx.get_num_vertices() * sizeof(int),
cudaMemcpyDeviceToHost));


std::vector<int> helper(rx.get_num_vertices());
inverse_permutation(rx.get_num_vertices(), h_permute, helper.data());

GPU_FREE(d_permute);
GPU_FREE(d_patch_proj_l);
GPU_FREE(d_patch_proj_l1);
Expand Down
14 changes: 14 additions & 0 deletions include/rxmesh/matrix/permute_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@ bool is_unique_permutation(uint32_t size, T* h_permute)

return true;
}

/**
* @brief given a permutation array, overwrite it with its inverse
*/
template <typename T>
void inverse_permutation(uint32_t size, T* perm, T* helper)
{
for (int i = 0; i < size; ++i) {
helper[perm[i]] = i;
}
for (int i = 0; i < size; ++i) {
perm[i] = helper[i];
}
}
} // namespace rxmesh

0 comments on commit 95bcdc7

Please sign in to comment.