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

KOKKOS_RESTRICT... #2038

Closed
kyungjoo-kim opened this issue Mar 18, 2019 · 8 comments
Closed

KOKKOS_RESTRICT... #2038

kyungjoo-kim opened this issue Mar 18, 2019 · 8 comments

Comments

@kyungjoo-kim
Copy link
Contributor

Why do we KOKKOS_RESTRICT is defined for Intel architectures ? NVCC suppports the __restrict__ keyword, too.

@kyungjoo-kim
Copy link
Contributor Author

@crtrott Can we add the #define KOKKOS_RESTRICT __restrict__ keyword if a compiler does not complain about it ?

@lucbv , put your hands up if u like this !!

@mhoemmen
Copy link
Contributor

We would need to add a CMake test for this, but it's not hard:

INCLUDE(CheckCXXSourceCompiles)

FUNCTION(CHECK_RESTRICT_COMPILES VARNAME)
  SET(SOURCE
  "
#define KOKKOS_RESTRICT_LOCAL __restrict__

double test_restrict (const double* KOKKOS_RESTRICT_LOCAL x, const int N) {
  double sum = 0.0;
  for (int i = 0; i < N; ++i) {
    sum += x[i];
  }
  return sum;
}

int main() {
  constexpr int N = 10;
  const double arr[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
  const double sum = test_restrict (arr, N);
  return sum == 15.0 ? 0 : -1; 
}
  "
  )
  
  # This is a local variable name.  ${VARNAME} is the output variable.
  CHECK_CXX_SOURCE_COMPILES("${SOURCE}" KOKKOS_ENABLE_RESTRICT_LOCAL)

  IF(KOKKOS_ENABLE_RESTRICT_LOCAL)
    GLOBAL_SET(${VARNAME} TRUE)
    MESSAGE(STATUS "C++ compiler supports __restrict__")
  ELSE()
    GLOBAL_SET(${VARNAME} FALSE)
    MESSAGE(STATUS "C++ compiler does NOT support __restrict__")
  ENDIF()
ENDFUNCTION()

@lucbv
Copy link
Contributor

lucbv commented Mar 19, 2019

@kyungjoo-kim thanks for adding this issue, I am in favor of allowing restrict in kokkos/kokkos-kernels. It is often useful for vectorization.
Also it would be nice to have this type of macro being maintained for GNU compiler, not only intel...

@mhoemmen
Copy link
Contributor

@lucbv The above CMake test should work fine for any compiler.

@nmhamster
Copy link
Contributor

You need to check which restrict is supported and if flags are needed to enable it. If memory serves, the compilers don’t all agree on how this is written.

@mhoemmen
Copy link
Contributor

@nmhamster I don't know how to do that in Kokkos' raw Makefiles-based build system, but the above CMake test could be modified easily enough to cover variations on __restrict__.

@kyungjoo-kim
Copy link
Contributor Author

When I have this kind of problem (cmake can test certain compiler options while makefile cannot do so), I just give a overriding option to users in the makefile configuration. Mostly, when people use makefile, we generally assume that those users know what they are doing.

@ibaned
Copy link
Contributor

ibaned commented Mar 20, 2019

This is a duplicate of #1922, I'm going to close this one since it came later but we do want to start defining KOKKOS_RESTRICT for non-Intel compilers. Exactly how we do this may still be up for debate.

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

No branches or pull requests

5 participants