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

Perf: optimize function pow in module_gint #4680

Merged
merged 8 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
22 changes: 22 additions & 0 deletions source/module_hamilt_lcao/module_gint/gint_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ class Gint_inout

namespace Gint_Tools
{

inline double pow(const double base, const int exp)
{
switch (exp)
{
case 0:
return 1.0;
case 1:
return base;
case 2:
return base * base;
case 3:
return base * base * base;
case 4:
return base * base * base * base;
case 5:
return base * base * base * base * base;
default:
double result = std::pow(base, exp);
return result;
}
}
// vindex[pw.bxyz]
int* get_vindex(const int bxyz,
const int bx,
Expand Down
3 changes: 2 additions & 1 deletion source/module_hamilt_lcao/module_gint/grid_meshball.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "grid_meshball.h"
#include "gint_tools.h" // for pow(double, int)
#include "module_base/memory.h"

Grid_MeshBall::Grid_MeshBall()
Expand Down Expand Up @@ -127,7 +128,7 @@ double Grid_MeshBall::deal_with_atom_spillage(const double *pos)
cell[ip] = i*this->bigcell_vec1[ip] +
j*this->bigcell_vec2[ip] +
k*this->bigcell_vec3[ip];
dx += std::pow(cell[ip] - pos[ip], 2);
dx += pow(cell[ip] - pos[ip], 2);
dzzz2001 marked this conversation as resolved.
Show resolved Hide resolved
}
r2 = std::min(dx, r2);
}
Expand Down
22 changes: 22 additions & 0 deletions source/module_hamilt_lcao/module_gint/kernels/cuda/interp.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@

namespace GintKernel
{
static __device__ double pow(double base, int exp)
{
switch (exp)
{
case 0:
return 1.0;
case 1:
return base;
case 2:
return base * base;
case 3:
return base * base * base;
case 4:
return base * base * base * base;
case 5:
return base * base * base * base * base;
default:
double result = std::pow(base, exp);
return result;
}
}

static __device__ void interp_rho(const double dist,
const double delta_r,
const int atype,
Expand Down
Loading