Skip to content

Fh kokkos b spline#3

Open
hsiehhRPI wants to merge 74 commits into
mainfrom
fh_Kokkos_BSpline
Open

Fh kokkos b spline#3
hsiehhRPI wants to merge 74 commits into
mainfrom
fh_Kokkos_BSpline

Conversation

@hsiehhRPI
Copy link
Copy Markdown
Collaborator

This branch included Kokkos version of the BSpline inplementation. The main file is BSplineKokkos2D.h which contains Kokkos version of the BSpline that utilize 2D view for control points. 1st and 2nd derivative evaluation are implemented.

Hsieh and others added 30 commits March 8, 2026 12:37
Hsieh and others added 27 commits April 19, 2026 21:35
Fixed indentation for formatting
Fix indentation for the nested loops
Fixed the indentation
Fixed the indentation and formatting
Comment thread BSplineKokkos.cpp
Comment on lines +3 to +53
/*template<typename ExecutionSpace>
BSplineKokkos<ExecutionSpace>::BSplineKokkos(int orderC, std::vector<double>& ctrlPtsC, std::vector<double>& knotsC, std::vector<double>& weightsC) {
order = orderC;
//Allocate appropriate view space based on the number of control points, copy the data over to view
ctrlPts("ctrlPts", ctrlPtsC.size());
for (int i = 0; i < ctrlPtsC.size(); i++) {
ctrlPts(i) = ctrlPtsC[i];
}
//Same for knots and weights
knots("knots", knotsC.size());
for (int i = 0; i < knotsC.size(); i++) {
knots(i) = knotsC[i];
}

weights("weights", weightsC.size());
for (int i = 0; i < weightsC.size(); i++) {
weights(i) = weightsC[i];
}
//Call the calculateDerivCoeff() to populate
//1st and 2nd deriavtive views

//NOTE: UNCOMMENT THIS ONCE ALL IN FRONT ARE RESOLVED
//calculateDerivCoeff();

}*/


/*template<typename ExecutionSpace>
void BSplineKokkos<ExecutionSpace>::calculateDerivCoeff() {
//Calculate first order derivative
//Allocate space for ctrlPts_1stD
ctrlPts_1stD("ctrlPts1Derivative", ctrlPts.extent(0)-1);
for (int i = 1; i < ctrlPts.extent(0); i++) {
double delta = double(order - 1)/(knots(i+order-1)-knots(i));
ctrlPts_1stD(i) = ((ctrlPts(i) - ctrlPts(i-1)*delta));

}

//Calculate second order derivative
//Allocate space for ctrlPts_2ndD
ctrlPts_2ndD("ctrlPts2Derivative", ctrlPts.extent(0)-2);
for (int i = 0; i < ctrlPts_1stD.extent(0); i++) {
double delta = double(order - 2) / (knots(i+order-1)-knots(i+1));
ctrlPts_2ndD(i) = ((ctrlPts_1stD(i) - ctrlPts_1stD(i-1))*delta);
}
//TODO: find another way to verify the size of the second derivative view

}*/

//Explicit instantiation of the templated class for Kokkos::serial
//template class BSplineKokkos<Kokkos::Serial>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove code that is commented out

Comment thread BSplineKokkos.h
Kokkos::deep_copy(cPOffset, host_cPOffsetV);
Kokkos::deep_copy(knotsOffset, host_knotsOffsetV);

//TO DO: Work on calculate derivative coeff
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this 'todo' comment can be removed.

Comment thread BSplineKokkos.h
}

void calculateDerivCoeff() {
//Moved here from the .cpp file since it uses <ExecutionSpace>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this comment

Comment thread BSplineKokkos2D.cpp
@@ -0,0 +1 @@
#include "BSplineKokkos2D.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this file (BSplineKokkos2D.cpp) and its entry in the CMakeLists.txt file

Comment thread BSplineKokkos2D.h
#include<string>

template<typename ExecutionSpace>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this blank line

//printSpline(kokkosBSP);
std::vector<double> evalAt = {0, 0.2, 0.41, 0.5, 0.66, 0.73, 0.75, 0.89, 0.94, 1};

for (int i = 0; i < 10; i++) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the length of the evalAt array instead of hardcoding 10

for (int i = 0; i < 10; i++) {
double derivX = serialBSP.x.evalFirstDeriv(evalAt[i]);
double derivY = serialBSP.y.evalFirstDeriv(evalAt[i]);
std::vector<double> kokkos1stDeriv = kokkosBSP.eval1stDeriv({evalAt[i]}, 0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we only loading test csv files with one spline?

Will this work on the GPU? From what I can see, we only have one eval1stDeriv(...) interface and it returns a kokkos view and not a std::vector.

Comment thread BSplineKokkos.h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file and BSplineKokkos.cpp. I assume we will only proceed with the version that uses rank 2 kokkos views. As such, after these are removed, we should also remove the 2D suffix from the BSplineKokkos2D.[cpp|h] file names.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this testing the rank 1 kokkos view implementation, and I assume the rank 2 kokkos view implementation is fully functional, this test file should be removed.

Comment thread testSplineKokkosBase.cpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should be removed assuming we are removing the other rank 1 implementations/tests

@cwsmith
Copy link
Copy Markdown
Contributor

cwsmith commented May 11, 2026

@hsiehhRPI Was clang-format ran on this? I saw some long lines (>80 chars) that I would have expected it to break into multiple lines.

Copy link
Copy Markdown
Contributor

@cwsmith cwsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please carefully review the comments on the rank 1 implementation/tests/etc and ensure that they are addressed in the rank 2 version if the same code exists there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants