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

Port Verdict to GPUs #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

adayton1
Copy link

@adayton1 adayton1 commented Nov 19, 2024

  • Use C math functions instead of C++ ones for best compatibility with CUDA/HIP (you can use them directly in device code)
  • Use constexpr for constants whenever possible so that they can be used directly in device code
  • For non-constexpr constants, wrap in functions instead
  • Add VERDICT_HOST_DEVICE macro to apply __host__ __device__ specifiers to all functions

@adayton1 adayton1 mentioned this pull request Nov 19, 2024

static const double one_third = 1.0 / 3.0;
static const double two_thirds = 2.0 / 3.0;
static const double sqrt3 = std::sqrt(3.0);
Copy link
Author

Choose a reason for hiding this comment

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

Would you prefer if I did something like the following so that sqrt3 is a constant on the host rather than always recomputed?

VERDICT_HOST_DEVICE static double sqrt3()
{
#if defined(VERDICT_DEVICE_COMPILE)
  return sqrt(3);
#else
  static const double s_sqrt3 = sqrt(3);
  return s_sqrt3;
#endif

double warpage = std::pow(
std::min(corner_normals[0] % corner_normals[2], corner_normals[1] % corner_normals[3]), 3);
double warpage = fmin(corner_normals[0] % corner_normals[2], corner_normals[1] % corner_normals[3]);
warpage = warpage * warpage * warpage;
Copy link
Author

Choose a reason for hiding this comment

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

The c pow function is much slower for integer exponents than manually multiplying. Is this change acceptable or would you like me to write a cube function?


/* quality functions for hex elements */

//! Calculates hex edge ratio metric.
/** Hmax / Hmin where Hmax and Hmin are respectively the maximum and the
minimum edge lengths */
VERDICT_EXPORT double hex_edge_ratio(int num_nodes, const double coordinates[][3]);
VERDICT_EXPORT VERDICT_HOST_DEVICE double hex_edge_ratio(int num_nodes, const double coordinates[][3]);
Copy link
Author

Choose a reason for hiding this comment

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

I could fold in VERDICT_HOST_DEVICE into the definition of VERDICT_EXPORT if desired.

@@ -4,10 +4,30 @@

cmake_minimum_required(VERSION 3.16)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED 1)
set(CMAKE_CXX_STANDARD 11 CACHE STRING "")
Copy link
Author

Choose a reason for hiding this comment

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

This change allows applications to build with newer c++ standards while leaving 11 as the default.

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.

1 participant