Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiangyu/sycl loop ranges #712

Merged
merged 60 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4c5c4b3
to continue
Xiangyu-Hu Oct 11, 2024
306c65e
to replace configuration dynamics
Xiangyu-Hu Oct 11, 2024
ef08b41
dambreak_ck ok
Xiangyu-Hu Oct 11, 2024
23b312f
dambreak_sycl ok
Xiangyu-Hu Oct 12, 2024
a2f6b80
reverse wrongly delete functions
Xiangyu-Hu Oct 12, 2024
eceefb2
unit test compiled
Xiangyu-Hu Oct 12, 2024
02354f5
std exclusive_scan in std lib numeric
Oct 13, 2024
f79516a
another place requires std lib
Oct 13, 2024
4448a25
still other places
Oct 13, 2024
93a88b8
Merge branch 'master' into xiangyu/sycl_loop_ranges
Xiangyu-Hu Nov 22, 2024
7616a64
add unique singular variable
Xiangyu-Hu Nov 25, 2024
3bf83a3
Merge branch 'xiangyu/range_by_particle' into xiangyu/sycl_loop_ranges
Xiangyu-Hu Nov 25, 2024
373ab35
add LoopRangeCK<ExecutionPolicy, BodyPartByParticle>
Xiangyu-Hu Nov 26, 2024
32e90ee
add constraint compiled to put it into a case
Xiangyu-Hu Nov 27, 2024
85a07ef
back to master to decouple computing from simbody
Xiangyu-Hu Nov 30, 2024
862b425
Merge branch 'master' into xiangyu/sycl_loop_ranges
Xiangyu-Hu Dec 4, 2024
aa6bbe9
delete redundant code in 2d stfb case
Xiangyu-Hu Dec 4, 2024
33441f4
to continue
Xiangyu-Hu Dec 4, 2024
7522c76
begin viscous force
Xiangyu-Hu Dec 4, 2024
15bc4aa
I pause here , to update Kernel correction kernel first
Xiangyu-Hu Dec 5, 2024
b0fda1f
Merge branch 'master' into xiangyu/sycl_loop_ranges
Xiangyu-Hu Dec 7, 2024
6b4e418
viscous force ck header done
Xiangyu-Hu Dec 7, 2024
799998a
viscous force draft done, to work on simbody constraint
Xiangyu-Hu Dec 7, 2024
826d946
wait for inline vector up and degrading
Xiangyu-Hu Dec 7, 2024
6c11ecb
inlined vector up and degrade
Xiangyu-Hu Dec 7, 2024
aca3b1e
Merge branch 'xinagyu/vector_up_degrading' into xiangyu/sycl_loop_ranges
Xiangyu-Hu Dec 7, 2024
e76bebc
compiled, to test
Xiangyu-Hu Dec 7, 2024
3e6f962
using WithWall for interaction with wall
Xiangyu-Hu Dec 8, 2024
089e349
lid driven cavity ck, nor done yet
Xiangyu-Hu Dec 8, 2024
ef08fe3
compiled, to test
Xiangyu-Hu Dec 8, 2024
1c46af8
use FSI namespace
Xiangyu-Hu Dec 9, 2024
3a0825f
fsi in separate folder
Xiangyu-Hu Dec 10, 2024
61dc454
to solve the issue of force prior (constructing without local dynamics)
Xiangyu-Hu Dec 10, 2024
cf58809
ForcePriorCK now not local dynamics
Xiangyu-Hu Dec 11, 2024
48a7481
to handle registerComputingKernel for update kernel in Contact<WithU…
Xiangyu-Hu Dec 11, 2024
c6ce807
only register interact kernels
Xiangyu-Hu Dec 12, 2024
de4a00e
Merge branch 'xinagyu/vector_up_degrading' into xiangyu/sycl_loop_ranges
Xiangyu-Hu Dec 12, 2024
f957cda
using templated loop range
Xiangyu-Hu Dec 12, 2024
b149560
optimal local range by query device
Xiangyu-Hu Dec 13, 2024
bb6ef0d
something wrong, to check locally
Xiangyu-Hu Dec 13, 2024
eab30a7
contact relation for fsi
Xiangyu-Hu Dec 14, 2024
6e23c57
to solve non-device copyable issue for stk vectors
Xiangyu-Hu Dec 14, 2024
4c01f97
to handle reduce operators
Xiangyu-Hu Dec 14, 2024
5685f7f
reduce operators have no data member
Xiangyu-Hu Dec 15, 2024
7e653c8
Merge branch 'xinagyu/vector_up_degrading' into xiangyu/sycl_loop_ranges
Xiangyu-Hu Dec 15, 2024
84c6a67
add simbody variable device copyable
Xiangyu-Hu Dec 15, 2024
4f4f671
to test locally
Xiangyu-Hu Dec 15, 2024
e89a080
output bug found
Xiangyu-Hu Dec 15, 2024
d459f1f
small change
Xiangyu-Hu Dec 16, 2024
9dbc4ef
simplify the loop range
Xiangyu-Hu Dec 16, 2024
32461b5
using template for loop range
Xiangyu-Hu Dec 16, 2024
4c98ac7
further simplify loop range
Xiangyu-Hu Dec 16, 2024
29c34ee
delete unprepared case
Xiangyu-Hu Dec 16, 2024
a8eda35
warning corrected
Xiangyu-Hu Dec 16, 2024
0331f16
Revert "warning corrected"
Xiangyu-Hu Dec 17, 2024
6b1b38e
Revert "delete unprepared case"
Xiangyu-Hu Dec 17, 2024
33b4855
delete unprepared case
Xiangyu-Hu Dec 17, 2024
1e73630
warning corrected
Xiangyu-Hu Dec 17, 2024
66b9bfe
particle reduce unit test pass
Xiangyu-Hu Dec 18, 2024
4e91c4f
revise for running sycl on intel CPU
Xiangyu-Hu Dec 19, 2024
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
5 changes: 4 additions & 1 deletion src/for_2D_build/common/data_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ const Matd reduced_unit_matrix{

/** initial local normal, only works for thin structure dynamics. */
const Vecd local_pseudo_n_0 = Vecd(0.0, 1.0);

const Vecd ZeroVecd = Vec2d::Zero();

inline Vecd degradeToVecd(const Vec3d &input) { return Vecd(input[0], input[1]); };
inline Matd degradeToMatd(const Mat3d &input) { return input.block<2, 2>(0, 0); };

} // namespace SPH

#endif // DATA_TYPE_2D_H
23 changes: 0 additions & 23 deletions src/for_2D_build/common/vector_functions_2d.cpp

This file was deleted.

4 changes: 3 additions & 1 deletion src/for_3D_build/common/data_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ const Matd reduced_unit_matrix{
/** initial local normal, only works for thin structure dynamics. */
const Vecd local_pseudo_n_0 = Vecd(0.0, 0.0, 1.0);
const Vecd local_pseudo_b_n_0 = Vecd(0.0, 1.0, 0.0);

const Vecd ZeroVecd = Vec3d::Zero();

inline Vecd degradeToVecd(const Vec3d &input) { return input; };
inline Matd degradeToMatd(const Mat3d &input) { return input; };
} // namespace SPH
#endif // DATA_TYPE_3D_H
1 change: 1 addition & 0 deletions src/for_3D_build/common/scalar_functions_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ int NextAxis(int first_axis)
{
return first_axis == 2 ? 0 : first_axis + 1;
}
//=================================================================================================//
} // namespace SPH
16 changes: 0 additions & 16 deletions src/for_3D_build/common/vector_functions_3d.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class BarStressRelaxationFirstHalf : public BaseBarRelaxation

/**
* @class BarStressRelaxationSecondHalf
* @brief computing stress relaxation process by verlet time stepping
* @brief computing stress relaxation process by Verlet time stepping
* This is the second step
*/
class BarStressRelaxationSecondHalf : public BaseBarRelaxation
Expand Down
5 changes: 0 additions & 5 deletions src/shared/bodies/base_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ BoundingBox SPHBody::getSPHBodyBounds()
return is_bound_set_ ? bound_ : initial_shape_->getBounds();
}
//=================================================================================================//
void SPHBody::registerComputingKernel(execution::Implementation<Base> *implementation)
{
all_simple_reduce_computing_kernels_.push_back(implementation);
}
//=================================================================================================//
void SPHBody::defineAdaptationRatios(Real h_spacing_ratio, Real new_system_refinement_ratio)
{
sph_adaptation_->resetAdaptationRatios(h_spacing_ratio, new_system_refinement_ratio);
Expand Down
7 changes: 2 additions & 5 deletions src/shared/bodies/base_body.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
#include "adaptation.h"
#include "all_geometries.h"
#include "base_data_package.h"
#include "base_implementation.h"
#include "base_material.h"
#include "base_particle_generator.h"
#include "base_particles.h"
#include "cell_linked_list.h"
#include "execution.h"
#include "sph_system.h"
#include "sphinxsys_containers.h"

Expand Down Expand Up @@ -76,9 +76,7 @@ class SPHBody
bool is_bound_set_; /**< whether the bounding box is set */
BoundingBox bound_; /**< bounding box of the body */
Shape *initial_shape_; /**< initial volumetric geometry enclosing the body */
int total_body_parts_;
StdVec<execution::Implementation<Base> *> all_simple_reduce_computing_kernels_;
/**< total number of body parts */
int total_body_parts_; /**< total number of body parts */

public:
SPHAdaptation *sph_adaptation_; /**< numerical adaptation policy */
Expand Down Expand Up @@ -109,7 +107,6 @@ class SPHBody
void setSPHBodyBounds(const BoundingBox &bound);
BoundingBox getSPHBodyBounds();
BoundingBox getSPHSystemBounds();
void registerComputingKernel(execution::Implementation<Base> *implementation);
int getNewBodyPartID();
int getTotalBodyParts() { return total_body_parts_; };
//----------------------------------------------------------------------
Expand Down
17 changes: 16 additions & 1 deletion src/shared/bodies/base_body_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@
namespace SPH
{
//=================================================================================================//
BodyPart::BodyPart(SPHBody &sph_body, const std::string &body_part_name)
: sph_body_(sph_body), part_id_(sph_body.getNewBodyPartID()),
body_part_name_(body_part_name),
base_particles_(sph_body.getBaseParticles()),
dv_index_list_(nullptr), sv_range_size_(nullptr),
pos_(base_particles_.getVariableDataByName<Vecd>("Position")) {}
//=================================================================================================//
BodyPartByParticle::BodyPartByParticle(SPHBody &sph_body, const std::string &body_part_name)
: BodyPart(sph_body, body_part_name),
body_part_bounds_(Vecd::Zero(), Vecd::Zero()), body_part_bounds_set_(false) {}
//=================================================================================================//
void BodyPartByParticle::tagParticles(TaggingParticleMethod &tagging_particle_method)
{
for (size_t i = 0; i < base_particles_.TotalRealParticles(); ++i)
{
tagging_particle_method(i);
}
dv_index_list_ = base_particles_.addUniqueDiscreteVariableOnly<UnsignedInt>(
body_part_name_, body_part_particles_.size(), [&](size_t i) -> Real
{ return body_part_particles_[i]; });
sv_range_size_ = base_particles_.addUniqueSingularVariableOnly<UnsignedInt>(
body_part_name_ + "_Size", body_part_particles_.size());
};
//=============================================================================================//
size_t BodyPartByCell::SizeOfLoopRange()
Expand Down Expand Up @@ -41,7 +57,6 @@ BodyRegionByParticle::BodyRegionByParticle(SPHBody &sph_body, SharedPtr<Shape> s
{
shape_ptr_keeper_.assignRef(shape_ptr);
}
//==
//=================================================================================================//
void BodyRegionByParticle::tagByContain(size_t particle_index)
{
Expand Down
16 changes: 6 additions & 10 deletions src/shared/bodies/base_body_part.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,22 @@ using namespace std::placeholders;
class BodyPart
{
public:
BodyPart(SPHBody &sph_body, const std::string &body_part_name)
: sph_body_(sph_body), part_id_(sph_body.getNewBodyPartID()),
body_part_name_(body_part_name),
base_particles_(sph_body.getBaseParticles()),
pos_(base_particles_.getVariableDataByName<Vecd>("Position")){};
BodyPart(SPHBody &sph_body, const std::string &body_part_name);
virtual ~BodyPart(){};

SPHBody &getSPHBody() { return sph_body_; };
SPHSystem &getSPHSystem() { return sph_body_.getSPHSystem(); };
std::string getName() { return body_part_name_; };
int getPartID() { return part_id_; };
DiscreteVariable<UnsignedInt> *dvIndexList() { return dv_index_list_; };
SingularVariable<UnsignedInt> *svRangeSize() { return sv_range_size_; };

protected:
SPHBody &sph_body_;
int part_id_;
std::string body_part_name_;
BaseParticles &base_particles_;
DiscreteVariable<UnsignedInt> *dv_index_list_;
SingularVariable<UnsignedInt> *sv_range_size_;
Vecd *pos_;
};

Expand All @@ -75,10 +74,7 @@ class BodyPartByParticle : public BodyPart
BaseParticles &getBaseParticles() { return base_particles_; };
IndexVector &LoopRange() { return body_part_particles_; };
size_t SizeOfLoopRange() { return body_part_particles_.size(); };

BodyPartByParticle(SPHBody &sph_body, const std::string &body_part_name)
: BodyPart(sph_body, body_part_name),
body_part_bounds_(Vecd::Zero(), Vecd::Zero()), body_part_bounds_set_(false){};
BodyPartByParticle(SPHBody &sph_body, const std::string &body_part_name);
virtual ~BodyPartByParticle(){};

void setBodyPartBounds(BoundingBox bbox)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/body_relations/base_body_relation.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "base_geometry.h"
#include "base_particles.h"
#include "cell_linked_list.h"
#include "execution.h"
#include "base_implementation.h"
#include "neighborhood.h"

namespace SPH
Expand Down
2 changes: 2 additions & 0 deletions src/shared/body_relations/contact_body_relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "base_particle_dynamics.h"
#include "cell_linked_list.hpp"

#include <numeric>

namespace SPH
{
//=================================================================================================//
Expand Down
32 changes: 0 additions & 32 deletions src/shared/common/base_data_package.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,6 @@ using DataContainerAddressAssemble = DataAssemble<DataContainerAddressKeeper, Co
template <template <typename> typename ContainerType>
using DataContainerUniquePtrAssemble = DataAssemble<DataContainerUniquePtrKeeper, ContainerType>;

/** a type irrelevant operation on the data assembles */
template <template <typename> typename OperationType>
class DataAssembleOperation
{
OperationType<int> integer_operation;
OperationType<Real> scalar_operation;
OperationType<Vec2d> vector2d_operation;
OperationType<Mat2d> matrix2d_operation;
OperationType<Vec3d> vector3d_operation;
OperationType<Mat3d> matrix3d_operation;

public:
template <typename... Args>
DataAssembleOperation(Args &&...args)
: integer_operation(std::forward<Args>(args)...),
scalar_operation(std::forward<Args>(args)...),
vector2d_operation(std::forward<Args>(args)...),
matrix2d_operation(std::forward<Args>(args)...),
vector3d_operation(std::forward<Args>(args)...),
matrix3d_operation(std::forward<Args>(args)...){};
template <typename... OperationArgs>
void operator()(OperationArgs &&...operation_args)
{
integer_operation(std::forward<OperationArgs>(operation_args)...);
scalar_operation(std::forward<OperationArgs>(operation_args)...);
vector2d_operation(std::forward<OperationArgs>(operation_args)...);
matrix2d_operation(std::forward<OperationArgs>(operation_args)...);
vector3d_operation(std::forward<OperationArgs>(operation_args)...);
matrix3d_operation(std::forward<OperationArgs>(operation_args)...);
}
};

// Please refer: https://www.cppstories.com/2022/tuple-iteration-basics/ for the following code
template <typename DataAssembleType, typename OperationType>
class OperationOnDataAssemble
Expand Down
5 changes: 5 additions & 0 deletions src/shared/common/scalar_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ inline bool Not_a_number(T a)
return (std::isnan(a) || !(std::isfinite(a))) ? true : false;
}

inline Real harmonic_average(const Real &a, const Real &b)
{
return 2.0 * a * b / (a + b);
}

inline Real rand_normal(Real u, Real std)
{
unsigned seed = (unsigned)std::chrono::system_clock::now().time_since_epoch().count();
Expand Down
2 changes: 2 additions & 0 deletions src/shared/common/sphinxsys_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Wall; /**< Interaction with wall boundary */
class Extended; /**< An extened method of an interaction type */
class SpatialTemporal; /**< A interaction considering spatial temporal correlations */
class Dynamic; /**< A dynamic interaction */
class Constant; /**< A constant parameter */
class Variable; /**< A variable parameter */

using MaterialVector = StdVec<BaseMaterial *>;
using SPHBodyVector = StdVec<SPHBody *>;
Expand Down
2 changes: 0 additions & 2 deletions src/shared/common/sphinxsys_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ class SingularVariable : public Entity
~SingularVariable() { delete value_; };

DataType *ValueAddress() { return delegated_; };

void setValue(const DataType &value) { *delegated_ = value; };
DataType getValue() { return *delegated_; };

void incrementValue(const DataType &value) { *delegated_ += value; };

template <class ExecutionPolicy>
Expand Down
60 changes: 0 additions & 60 deletions src/shared/common/vector_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,6 @@ Vec3d FirstAxisVector(const Vec3d &zero_vector)
return Vec3d(1.0, 0.0, 0.0);
};
//=================================================================================================//
Vec3d upgradeToVec3d(const Real &input)
{
return Vec3d(input, 0.0, 0.0);
}
//=================================================================================================//
Vec3d upgradeToVec3d(const Vec2d &input)
{
return Vec3d(input[0], input[1], 0.0);
}
//=================================================================================================//
Vec3d upgradeToVec3d(const Vec3d &input)
{
return input;
}
//=================================================================================================//
Mat3d upgradeToMat3d(const Mat2d &input)
{
Mat3d output = Mat3d::Zero();
output.block<2, 2>(0, 0) = input;
return output;
}
//=================================================================================================//
Mat3d upgradeToMat3d(const Mat3d &input)
{
return input;
}
//=================================================================================================//
Mat2d getInverse(const Mat2d &A)
{
Mat2d minv = Mat2d::Zero();
Real det = A(0, 0) * A(1, 1) - A(0, 1) * A(1, 0);
Real invdet = 1.0 / det;
minv(0, 0) = A(1, 1) * invdet;
minv(0, 1) = -A(0, 1) * invdet;
minv(1, 0) = -A(1, 0) * invdet;
minv(1, 1) = A(0, 0) * invdet;
return minv;
}
//=================================================================================================//
Mat3d getInverse(const Mat3d &A)
{
Real det = A(0, 0) * (A(1, 1) * A(2, 2) - A(2, 1) * A(1, 2)) -
A(0, 1) * (A(1, 0) * A(2, 2) - A(1, 2) * A(2, 0)) +
A(0, 2) * (A(1, 0) * A(2, 1) - A(1, 1) * A(2, 0));

Real invdet = 1 / det;
Mat3d minv = Mat3d::Zero();
minv(0, 0) = (A(1, 1) * A(2, 2) - A(2, 1) * A(1, 2)) * invdet;
minv(0, 1) = (A(0, 2) * A(2, 1) - A(0, 1) * A(2, 2)) * invdet;
minv(0, 2) = (A(0, 1) * A(1, 2) - A(0, 2) * A(1, 1)) * invdet;
minv(1, 0) = (A(1, 2) * A(2, 0) - A(1, 0) * A(2, 2)) * invdet;
minv(1, 1) = (A(0, 0) * A(2, 2) - A(0, 2) * A(2, 0)) * invdet;
minv(1, 2) = (A(1, 0) * A(0, 2) - A(0, 0) * A(1, 2)) * invdet;
minv(2, 0) = (A(1, 0) * A(2, 1) - A(2, 0) * A(1, 1)) * invdet;
minv(2, 1) = (A(2, 0) * A(0, 1) - A(0, 0) * A(2, 1)) * invdet;
minv(2, 2) = (A(0, 0) * A(1, 1) - A(1, 0) * A(0, 1)) * invdet;

return minv;
}
//=================================================================================================//
Mat2d getAverageValue(const Mat2d &A, const Mat2d &B)
{
Mat2d C = Mat2d::Identity();
Expand Down
25 changes: 16 additions & 9 deletions src/shared/common/vector_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,24 @@ namespace SPH
Vec2d FirstAxisVector(const Vec2d &zero_vector);
Vec3d FirstAxisVector(const Vec3d &zero_vector);

Vec3d upgradeToVec3d(const Real &input);
Vec3d upgradeToVec3d(const Vec2d &input);
Vec3d upgradeToVec3d(const Vec3d &input);
Mat3d upgradeToMat3d(const Mat2d &input);
Mat3d upgradeToMat3d(const Mat3d &input);
inline Vec3d upgradeToVec3d(const Real &input)
{
return Vec3d(input, 0.0, 0.0);
};
inline Vec3d upgradeToVec3d(const Vec2d &input)
{
return Vec3d(input[0], input[1], 0.0);
};
inline Vec3d upgradeToVec3d(const Vec3d &input) { return input; };

Vecd degradeToVecd(const Vec3d &input);
Matd degradeToMatd(const Mat3d &input);
inline Mat3d upgradeToMat3d(const Mat2d &input)
{
Mat3d output = Mat3d::Zero();
output.block<2, 2>(0, 0) = input;
return output;
};
inline Mat3d upgradeToMat3d(const Mat3d &input) { return input; };

Mat2d getInverse(const Mat2d &A);
Mat3d getInverse(const Mat3d &A);
Mat2d getAverageValue(const Mat2d &A, const Mat2d &B);
Mat3d getAverageValue(const Mat3d &A, const Mat3d &B);
Mat2d inverseCholeskyDecomposition(const Mat2d &A);
Expand Down
Loading
Loading