Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
4cc237c
working code
abhiyan123 Mar 1, 2025
d5b2cc0
add normalization routine
abhiyan123 Mar 1, 2025
c4b06bc
add min_max normalization routine
abhiyan123 Mar 2, 2025
0473cbf
add relative distance normalization
abhiyan123 Mar 2, 2025
3b951b5
add test cases for normalization routine
abhiyan123 Mar 2, 2025
87ca3a1
add test for normalization
abhiyan123 Mar 2, 2025
c527ccf
update file
abhiyan123 Mar 2, 2025
2e3cee7
add file for spr test
abhiyan123 Mar 2, 2025
5557207
add test for qr serial
abhiyan123 Mar 3, 2025
bc2cae0
update
abhiyan123 Mar 3, 2025
d8eedf3
add serial qr test
abhiyan123 Mar 3, 2025
914af9e
add a header for team level array operations
abhiyan123 Mar 4, 2025
213f1af
add test case for serial qr solver
abhiyan123 Mar 4, 2025
b72696c
add functions for row scaling
abhiyan123 Mar 4, 2025
00d4c95
update test_serial_qr.cpp
abhiyan123 Mar 4, 2025
9dc3da0
implement serial qr
abhiyan123 Mar 4, 2025
42daeb4
add new file for team level matrix operations
abhiyan123 Mar 4, 2025
08433ce
update a file
abhiyan123 Mar 4, 2025
f647560
add serial scd routine
abhiyan123 Mar 5, 2025
8ec7155
implement serial svd
abhiyan123 Mar 11, 2025
646d89c
add test for svd
abhiyan123 Mar 11, 2025
3496b63
add logger
abhiyan123 Mar 11, 2025
d5a331e
add logger file in CMakeList
abhiyan123 Mar 11, 2025
861d8b3
svd implementation but broken
abhiyan123 Mar 14, 2025
7d6976b
svd implementation but broken
abhiyan123 Mar 14, 2025
826e82c
add ridge regularization
abhiyan123 Mar 18, 2025
c5de3e5
update lambda parameter in function argument
abhiyan123 Mar 18, 2025
7dc4669
add defaualt argument for lambda parameter
abhiyan123 Mar 18, 2025
1b73884
update lambda
abhiyan123 Mar 18, 2025
beb74d7
update expected solution
abhiyan123 Mar 18, 2025
2ecc821
Merge branch 'develop' of github.com:SCOREC/pcms into mls_interpolation
abhiyan123 Mar 18, 2025
8fae10b
remove commented lines
abhiyan123 Mar 25, 2025
11bd901
remove print statements
abhiyan123 Mar 25, 2025
81dc8d4
remove commented code
abhiyan123 Mar 25, 2025
a6f3a07
remove note not required for svd
abhiyan123 Mar 25, 2025
5419b86
update
abhiyan123 Mar 25, 2025
97c2f4d
remove commented
abhiyan123 Mar 25, 2025
0a3cf0c
generalize for any dimension
abhiyan123 Mar 26, 2025
3c8d492
remove min max normalization function
abhiyan123 Mar 26, 2025
1a80098
add new argument
abhiyan123 Mar 26, 2025
4ce25f5
add new argument lambda
abhiyan123 Mar 26, 2025
1a25111
add new argument lambda
abhiyan123 Mar 26, 2025
7b6e325
add lambda
abhiyan123 Mar 26, 2025
7d46e8d
delete file
abhiyan123 Mar 26, 2025
43c42ef
change MAX_DIM to 6
abhiyan123 Mar 28, 2025
e8bb7fa
remove Omega_h_array_ops
abhiyan123 Mar 28, 2025
ceae062
use kokkos sqrt function
abhiyan123 Mar 28, 2025
5337afa
remove commented line
abhiyan123 Mar 28, 2025
0b3b7d5
remove using namespace
abhiyan123 Mar 28, 2025
c1d10f7
remove commented line
abhiyan123 Mar 28, 2025
f8cd558
remove test_serial_qr.cpp
abhiyan123 Mar 28, 2025
af76eb3
remove using namespace
abhiyan123 Mar 28, 2025
64b1500
remove print statement
abhiyan123 Mar 28, 2025
a34d804
fix indentation
abhiyan123 Mar 28, 2025
2a7077f
remove using namespace
abhiyan123 Mar 28, 2025
8bfb6a6
remove using namespace
abhiyan123 Mar 28, 2025
0d7f5a9
works for gtc-gnet coupling
abhiyan123 Apr 7, 2025
c7ff6c4
CUDA backend works
abhiyan123 Apr 8, 2025
0c81b4b
Merge branch 'develop' of github.com:SCOREC/pcms into develop
abhiyan123 Apr 9, 2025
fde7a23
Merge branch 'develop' of github.com:SCOREC/pcms into develop_update
abhiyan123 Apr 9, 2025
b487027
Merge branch 'mls_interpolation_svd_solver' into develop_update
abhiyan123 Apr 9, 2025
c038fce
change lambda factor to lambda
abhiyan123 Apr 9, 2025
fe5b7d1
clean up
abhiyan123 May 6, 2025
8d6d705
comment out logger
abhiyan123 May 6, 2025
abae37a
bring tol to user level
abhiyan123 May 6, 2025
16776a8
add comment
abhiyan123 May 6, 2025
86b1458
update the arguments
abhiyan123 May 6, 2025
2d867fb
delete test_linear_solver.cpp
abhiyan123 May 6, 2025
0f6b255
remove test_linear_solver
abhiyan123 May 6, 2025
cfd8c8b
remmove lu solver and add svd solver
abhiyan123 May 6, 2025
9022acc
Merge branch 'develop' of github.com:SCOREC/pcms into mls_interpolati…
abhiyan123 May 7, 2025
16d520f
Merge branch 'develop' of github.com:SCOREC/pcms into develop
abhiyan123 May 7, 2025
cb74274
make decay factor user defined parameter
abhiyan123 May 8, 2025
bf1229f
make decay factor user defined parameter
abhiyan123 May 8, 2025
ef56be9
make decay factor user defined parameter
abhiyan123 May 8, 2025
0c76714
compilation error
abhiyan123 May 9, 2025
ab7e764
update parameters
abhiyan123 May 12, 2025
88d49d2
update parameter
abhiyan123 May 12, 2025
2e0de9d
replace printf with Kokkos::printf
abhiyan123 May 12, 2025
ad8fcfc
Merge branch 'develop' of github.com:SCOREC/pcms into develop
abhiyan123 May 12, 2025
bc52834
Merge branch 'develop' into mls_interpolation_svd_solver
abhiyan123 May 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/pcms/interpolator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set(PCMS_FIELD_TRANSFER_HEADERS
linear_interpolant.hpp
multidimarray.hpp
mls_interpolation.hpp
pcms_interpolator_view_utils.hpp
pcms_interpolator_logger.hpp
)

set(PCMS_FIELD_TRANSFER_SOURCES
Expand Down
325 changes: 170 additions & 155 deletions src/pcms/interpolator/adj_search.hpp

Large diffs are not rendered by default.

107 changes: 70 additions & 37 deletions src/pcms/interpolator/mls_interpolation.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
#include <pcms/interpolator/mls_interpolation.hpp>
#include <Kokkos_MathematicalFunctions.hpp>
#include <cmath>
#include "mls_interpolation.hpp"

namespace pcms
{

// RBF_GAUSSIAN Functor
struct RBF_GAUSSIAN
{
// 'a' is a spreading factor/decay factor
// the value of 'a' is higher if the data is localized
// the value of 'a' is smaller if the data is farther

double a;

RBF_GAUSSIAN(double a_val) : a(a_val) {}

OMEGA_H_INLINE
double operator()(double r_sq, double rho_sq) const
{
double phi;
OMEGA_H_CHECK_PRINTF(rho_sq > 0,
OMEGA_H_CHECK_PRINTF(rho_sq >= 0,
"ERROR: square of cutoff distance should always be "
"positive but the value is %.16f\n",
rho_sq);

OMEGA_H_CHECK_PRINTF(r_sq > 0,
OMEGA_H_CHECK_PRINTF(r_sq >= 0,
"ERROR: square of distance should always be positive "
"but the value is %.16f\n",
r_sq);

// 'a' is a spreading factor/decay factor
// the value of 'a' is higher if the data is localized
// the value of 'a' is smaller if the data is farther
int a = 20;

double r = sqrt(r_sq);
double rho = sqrt(rho_sq);
double r = Kokkos::sqrt(r_sq);
double rho = Kokkos::sqrt(rho_sq);
double ratio = r / rho;
double limit = 1 - ratio;

if (limit < 0) {
phi = 0;

} else {
phi = exp(-a * a * r * r);
phi = Kokkos::exp(-a * a * r * r);
}

return phi;
Expand All @@ -45,15 +49,16 @@ struct RBF_GAUSSIAN
// RBF_C4 Functor
struct RBF_C4
{

OMEGA_H_INLINE
double operator()(double r_sq, double rho_sq) const
{
double phi;
double r = sqrt(r_sq);
double r = Kokkos::sqrt(r_sq);
OMEGA_H_CHECK_PRINTF(
rho_sq > 0, "ERROR: rho_sq in rbf has to be positive, but got %.16f\n",
rho_sq);
double rho = sqrt(rho_sq);
double rho = Kokkos::sqrt(rho_sq);
double ratio = r / rho;
double limit = 1 - ratio;
if (limit < 0) {
Expand All @@ -76,15 +81,16 @@ struct RBF_C4
//
struct RBF_CONST
{

OMEGA_H_INLINE
double operator()(double r_sq, double rho_sq) const
{
double phi;
double r = sqrt(r_sq);
double r = Kokkos::sqrt(r_sq);
OMEGA_H_CHECK_PRINTF(
rho_sq > 0, "ERROR: rho_sq in rbf has to be positive, but got %.16f\n",
rho_sq);
double rho = sqrt(rho_sq);
double rho = Kokkos::sqrt(rho_sq);
double ratio = r / rho;
double limit = 1 - ratio;
if (limit < 0) {
Expand All @@ -101,34 +107,46 @@ struct RBF_CONST
}
};

Write<Real> mls_interpolation(const Reals source_values,
const Reals source_coordinates,
const Reals target_coordinates,
const SupportResults& support, const LO& dim,
const LO& degree, RadialBasisFunction bf)
struct NoOp
{
OMEGA_H_INLINE
double operator()(double, double) const { return 1.0; }
};

Omega_h::Write<Omega_h::Real> mls_interpolation(
const Omega_h::Reals source_values, const Omega_h::Reals source_coordinates,
const Omega_h::Reals target_coordinates, const SupportResults& support,
const Omega_h::LO& dim, const Omega_h::LO& degree, RadialBasisFunction bf,
double lambda, double tol, double decay_factor)
{

const auto nvertices_target = target_coordinates.size() / dim;

Write<Real> interpolated_values(nvertices_target, 0,
"approximated target values");
Omega_h::Write<Omega_h::Real> interpolated_values(
nvertices_target, 0, "approximated target values");
switch (bf) {
case RadialBasisFunction::RBF_GAUSSIAN:
interpolated_values = detail::mls_interpolation(
source_values, source_coordinates, target_coordinates, support, dim,
degree, RBF_GAUSSIAN{});
degree, RBF_GAUSSIAN{decay_factor}, lambda, tol);
break;

case RadialBasisFunction::RBF_C4:
interpolated_values = detail::mls_interpolation(
source_values, source_coordinates, target_coordinates, support, dim,
degree, RBF_C4{});
degree, RBF_C4{}, lambda, tol);
break;

case RadialBasisFunction::RBF_CONST:
interpolated_values = detail::mls_interpolation(
source_values, source_coordinates, target_coordinates, support, dim,
degree, RBF_CONST{});
degree, RBF_CONST{}, lambda, tol);
break;

case RadialBasisFunction::NO_OP:
interpolated_values = detail::mls_interpolation(
source_values, source_coordinates, target_coordinates, support, dim,
degree, NoOp{}, lambda, tol);
break;
}

Expand Down Expand Up @@ -174,7 +192,8 @@ int calculate_basis_vector_size(const IntHostMatView& array)
}

int calculate_scratch_shared_size(const SupportResults& support,
const int nvertices_target, int basis_size)
const int nvertices_target, int basis_size,
int dim)
{

IntDeviceVecView shmem_each_team("stores the size required for each team",
Expand All @@ -186,21 +205,34 @@ int calculate_scratch_shared_size(const SupportResults& support,
int end_ptr = support.supports_ptr[i + 1];
int nsupports = end_ptr - start_ptr;

int max_size;
int min_size;
if (nsupports > basis_size) {
max_size = nsupports;
min_size = basis_size;
} else {
max_size = basis_size;
min_size = nsupports;
}
size_t total_shared_size = 0;

total_shared_size += ScratchMatView::shmem_size(basis_size, basis_size);
total_shared_size += ScratchMatView::shmem_size(basis_size, nsupports);
total_shared_size += ScratchMatView::shmem_size(nsupports, basis_size);
total_shared_size += ScratchVecView::shmem_size(basis_size);
total_shared_size += ScratchVecView::shmem_size(nsupports) * 3;
total_shared_size += ScratchMatView::shmem_size(nsupports, 2);
total_shared_size += ScratchMatView::shmem_size(nsupports, 1);
total_shared_size +=
ScratchMatView::shmem_size(basis_size, basis_size); // Vt
total_shared_size +=
ScratchMatView::shmem_size(basis_size, nsupports) * 2; // temp_matrix
total_shared_size +=
ScratchMatView::shmem_size(nsupports, basis_size); // vandermonde matrix
total_shared_size +=
ScratchVecView::shmem_size(basis_size) *
3; // sigma, target_basis_vector, solution_coefficients
total_shared_size += ScratchVecView::shmem_size(nsupports) *
3; // work, phi_vector, support_values
total_shared_size +=
ScratchMatView::shmem_size(nsupports, dim); // local_source_points
total_shared_size +=
ScratchMatView::shmem_size(nsupports, nsupports) * 2; // U, Ut
shmem_each_team(i) = total_shared_size;
});

// namespace KE = Kokkos::Experimental;
// auto shared_size = KE::max_element(Kokkos::DefaultExecutionSpace(),
// shmem_each_team); printf("shared size = %d", shared_size);
int shared_size = 0;
Kokkos::parallel_reduce(
"find_max", nvertices_target,
Expand All @@ -213,5 +245,6 @@ int calculate_scratch_shared_size(const SupportResults& support,

return shared_size;
}

} // namespace detail
} // namespace pcms
78 changes: 70 additions & 8 deletions src/pcms/interpolator/mls_interpolation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,84 @@

#include "mls_interpolation_impl.hpp"

using namespace Omega_h;

namespace pcms
{

/**
* @brief Enumeration of supported radial basis functions (RBF) for MLS
*interpolation.
*
* This enum specifies the type of radial basis function used to weight source
*points in the Moving Least Squares (MLS) interpolation process.
*
* Members:
* - RBF_GAUSSIAN:
* A Gaussian RBF: `exp(- a^2 * r^2)`, smooth and commonly used. Good for
*localized support. `a` is a spreading/decay factor
*
* - RBF_C4:
* A compactly supported C4-continuous function. Useful for bounded support
*and efficiency.
*
* - RBF_CONST:
* Constant basis function. Effectively uses uniform weights.
*
* - NO_OP:
* No operation. Disables RBF weighting — typically used when weights
* are externally defined or not needed.
*
* @note These are intended to be passed into function `mls_interpolation` to
*control weighting behavior.
*/
enum class RadialBasisFunction : LO
{
RBF_GAUSSIAN = 0,
RBF_C4,
RBF_CONST
RBF_CONST,
NO_OP

};

Write<Real> mls_interpolation(const Reals source_values,
const Reals source_coordinates,
const Reals target_coordinates,
const SupportResults& support, const LO& dim,
const LO& degree, RadialBasisFunction bf);
/**
* @brief Performs Moving Least Squares (MLS) interpolation at target points.
*
* This function computes interpolated values at a set of target coordinates
* using Moving Least Squares (MLS) based on the provided source values and
* coordinates. It supports different radial basis functions (RBFs), polynomial
* degrees, dimension, optional regularization and tolerance
*
* @param source_values A flat array of source data values. Length should
* be `num_sources`.
* @param source_coordinates A flat array of source point coordinates. Length
* should be `num_sources * dim`.
* @param target_coordinates A flat array of target point coordinates. Length
* should be `num_targets * dim`.
* @param support A data structure holding neighbor information for
* each target (in
* CSR format).
* @param dim Dimension
* @param degree Polynomial degree
* @param bf The radial basis function used for weighting
* (e.g., Gaussian, C4).
* @param lambda Optional regularization parameter (default is
* 0.0). Helps with stability in ill-conditioned systems.
* @param tol Optional solver tolerance (default is 1e-6).
* Small singular values below this are discarded.
*
* @return A Write<Real> array containing the interpolated values at each target
* point.
*
* @note
* - All input arrays are expected to reside in device memory (e.g., Kokkos
* device views).
* - Ensure consistency in dimensions: coordinate arrays must be sized as
* `num_points * dim`.
* - The result array length will match the number of target points.
*/
Omega_h::Write<Omega_h::Real> mls_interpolation(
const Omega_h::Reals source_values, const Omega_h::Reals source_coordinates,
const Omega_h::Reals target_coordinates, const SupportResults& support,
const Omega_h::LO& dim, const Omega_h::LO& degree, RadialBasisFunction bf,
double lambda = 0, double tol = 1e-6, double decay_factor = 5.0);
} // namespace pcms
#endif
Loading