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

OpenMPTarget: Enable Cray compiler for the OpenMPTarget backend. #5889

Merged
merged 4 commits into from
May 19, 2023

Conversation

rgayatri23
Copy link
Contributor

The PR does the following :

  1. Adds a macro for Clang based Cray compiler as KOKKOS_COMPILER_CRAY_CLANG
  2. Enables appropriate flags for OpenMPTarget backend with Cray compiler in Makefile.kokkos and in cmake/kokkos_arch.cmake.
  3. Disable unit tests that do not compile or fail at runtime with the OpenMPTarget backend and Cray compiler.

Copy link
Member

@crtrott crtrott left a comment

Choose a reason for hiding this comment

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

Some small changes needed (comments and indentation)

@@ -93,13 +93,16 @@ void OpenMPTargetInternal::impl_initialize() {

// FIXME_OPENMPTARGET: Only fix the number of teams for NVIDIA architectures
// from Pascal and upwards.
// Cray compiler did not yet implement omp_set_num_teams.
Copy link
Member

Choose a reason for hiding this comment

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

sigh

Copy link
Member

Choose a reason for hiding this comment

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

Add a FIXME for Cray

@@ -353,6 +353,12 @@ if(Kokkos_ENABLE_OPENMPTARGET)
${CMAKE_CURRENT_BINARY_DIR}/openmptarget/TestOpenMPTarget_Other.cpp
${CMAKE_CURRENT_BINARY_DIR}/openmptarget/TestOpenMPTarget_TeamReductionScan.cpp
${CMAKE_CURRENT_BINARY_DIR}/openmptarget/TestOpenMPTarget_WorkGraph.cpp
# The following tests fail at compile time when the OpenMPTarget backend is enabled with the Cray compiler.
Copy link
Member

Choose a reason for hiding this comment

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

Add a FIXME comment also this is all kinds of atomic stuff - this could be a real issue. As if compare/exchange doesn't work properly.

if (std::is_same_v<TEST_EXECSPACE, Kokkos::Experimental::OpenMPTarget>)
GTEST_SKIP() << "Cray compiler fails correctness at runtime with the "
"OpenMPTarget backend.";
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Add a FIXME comment

if (std::is_same_v<TEST_EXECSPACE, Kokkos::Experimental::OpenMPTarget>)
GTEST_SKIP() << "Cray compiler fails correctness at runtime with the "
"OpenMPTarget backend.";
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Add a FIXME comment something with "Cray" in the same line too.

@@ -680,12 +680,18 @@ ENDIF()
IF (KOKKOS_ENABLE_OPENMPTARGET)
SET(CLANG_CUDA_ARCH ${KOKKOS_CUDA_ARCH_FLAG})
IF (CLANG_CUDA_ARCH)
IF(KOKKOS_CLANG_IS_CRAY)
Copy link
Member

Choose a reason for hiding this comment

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

fix identation.

Copy link
Member

@dalg24 dalg24 left a comment

Choose a reason for hiding this comment

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

Can you comment about the choice to distinguish between the legacy and the Clang-based Cray compilers?

Also with Intel we do not define KOKKOS_COMPILER_CLANG

#if defined(__clang__) && !defined(KOKKOS_COMPILER_INTEL)
#define KOKKOS_COMPILER_CLANG \

Did you mean to define both KOKKOS_COMPILER_CRAYCLANG and KOKKOS_COMPILER_CLANG?

@rgayatri23
Copy link
Contributor Author

The KOKKOS_COMPILER_CLANG gets defined in the lines above since its already checking for __clang__ .
I added a comment to differentiate between classical cray and clang based cray compilers. Also added version number math for KOKKOS_COMPILER_CRAYCLANG similar to the clang compiler.

With respect to Intel compiler, I assume the same __clang__ will be defined which will define the respective macro (although I am not sure about it).

@dalg24
Copy link
Member

dalg24 commented Feb 20, 2023

With respect to Intel compiler, I assume the same __clang__ will be defined which will define the respective macro (although I am not sure about it).

Look at the code snippet I referenced. We define KOKKOS_COMPILER_CLANG only if KOKKOS_COMPILER_INTEL is not defined.

@dalg24
Copy link
Member

dalg24 commented Feb 20, 2023

I added a comment to differentiate between classical cray and clang based cray compilers.

I am asking about clarifying why we want to distinguish them in the first place. I am not necessary suggesting we should not distinguish them. I just observing we don't do it for Intel and I am wondering whether you thought about it and why you decided to do it this way.

Makefile.kokkos Outdated
Comment on lines 270 to 276
# Cray compiler only needs fopenmp flag for target offload.
ifeq ($(KOKKOS_INTERNAL_COMPILER_CRAY_CLANG), 1)
KOKKOS_INTERNAL_OPENMPTARGET_FLAG := -DKOKKOS_WORKAROUND_OPENMPTARGET_CLANG -fopenmp
else
KOKKOS_INTERNAL_OPENMPTARGET_FLAG := -DKOKKOS_WORKAROUND_OPENMPTARGET_CLANG -fopenmp -fopenmp=libomp -Wno-openmp-mapping
KOKKOS_INTERNAL_OPENMPTARGET_LIB := -lomptarget
endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Cray compiler only needs fopenmp flag for target offload.
ifeq ($(KOKKOS_INTERNAL_COMPILER_CRAY_CLANG), 1)
KOKKOS_INTERNAL_OPENMPTARGET_FLAG := -DKOKKOS_WORKAROUND_OPENMPTARGET_CLANG -fopenmp
else
KOKKOS_INTERNAL_OPENMPTARGET_FLAG := -DKOKKOS_WORKAROUND_OPENMPTARGET_CLANG -fopenmp -fopenmp=libomp -Wno-openmp-mapping
KOKKOS_INTERNAL_OPENMPTARGET_LIB := -lomptarget
endif
# Cray compiler only needs fopenmp flag for target offload.
ifeq ($(KOKKOS_INTERNAL_COMPILER_CRAY_CLANG), 1)
KOKKOS_INTERNAL_OPENMPTARGET_FLAG := -DKOKKOS_WORKAROUND_OPENMPTARGET_CLANG -fopenmp
else
KOKKOS_INTERNAL_OPENMPTARGET_FLAG := -DKOKKOS_WORKAROUND_OPENMPTARGET_CLANG -fopenmp -fopenmp=libomp -Wno-openmp-mapping
KOKKOS_INTERNAL_OPENMPTARGET_LIB := -lomptarget
endif

Makefile.kokkos Outdated
Comment on lines 979 to 975
# Not necessary for the Cray compiler.
ifeq ($(KOKKOS_INTERNAL_COMPILER_CRAY_CLANG), 0)
ifeq ($(KOKKOS_INTERNAL_COMPILER_CLANG), 1)
KOKKOS_INTERNAL_CUDA_ARCH_FLAG=-fopenmp-targets=nvptx64 -Xopenmp-target -march
endif
endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Not necessary for the Cray compiler.
ifeq ($(KOKKOS_INTERNAL_COMPILER_CRAY_CLANG), 0)
ifeq ($(KOKKOS_INTERNAL_COMPILER_CLANG), 1)
KOKKOS_INTERNAL_CUDA_ARCH_FLAG=-fopenmp-targets=nvptx64 -Xopenmp-target -march
endif
endif
# Not necessary for the Cray compiler.
ifeq ($(KOKKOS_INTERNAL_COMPILER_CRAY_CLANG), 0)
ifeq ($(KOKKOS_INTERNAL_COMPILER_CLANG), 1)
KOKKOS_INTERNAL_CUDA_ARCH_FLAG=-fopenmp-targets=nvptx64 -Xopenmp-target -march
endif
endif

Comment on lines +988 to +979
# Do not add this flag it its the cray compiler.
ifeq ($(KOKKOS_INTERNAL_COMPILER_CRAY_CLANG), 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also indent accordingly.
So the Cray compiler doesn't take any architecture flags at all?!
Does this also apply if compiling for the Cuda backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No Cray compiler does not take any architecture flags. I was also surprised by that update. Why would we compile Cuda backend with Cray compiler, do you mean using Cray Wrappers? Cuda backend points to nvcc_wrapper anyways right?

@@ -153,6 +153,13 @@
__clang_major__ * 100 + __clang_minor__ * 10 + __clang_patchlevel__
#endif

// Macro for the Cray compiler based on clang.
// Different from classical Cray wihch is defined above.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Different from classical Cray wihch is defined above.
// Different from classical Cray which is defined above.

Is it a problem that the compiler now identifies as both CLANG and CRAYCLANG?

@rgayatri23
Copy link
Contributor Author

With respect to Intel compiler, I assume the same __clang__ will be defined which will define the respective macro (although I am not sure about it).

Look at the code snippet I referenced. We define KOKKOS_COMPILER_CLANG only if KOKKOS_COMPILER_INTEL is not defined.

Ah yes thanks. I missed the 2nd condition on that line.

@rgayatri23
Copy link
Contributor Author

I added a comment to differentiate between classical cray and clang based cray compilers.

I am asking about clarifying why we want to distinguish them in the first place. I am not necessary suggesting we should not distinguish them. I just observing we don't do it for Intel and I am wondering whether you thought about it and why you decided to do it this way.

Added a comment on the need for a new macro since the newer Clang based Cray compilers have a mature OpenMP offload implementation but we still want the older Classical Cray macro for the host if that is being used somewhere.

@rgayatri23
Copy link
Contributor Author

rgayatri23 commented Feb 20, 2023

@masterleinad has a good point which even @dalg24 is referring to, that now we define both Clang and CRAYCLANG and that might be an issue. I can disable KOKKOS_COMPILER_CLANG macro if KOKKOS_COMPILER_CRAYCLANG is defined, which I suppose is being done with Intel compilers. Any suggestions? I do not have an opinion on that right now.

@masterleinad
Copy link
Contributor

@rgayatri23 This needs rebasing.

Comment on lines 685 to 695
IF(KOKKOS_CLANG_IS_CRAY)
COMPILER_SPECIFIC_FLAGS(
Cray -fopenmp
)
ELSE()
STRING(REPLACE "sm_" "cc" NVHPC_CUDA_ARCH ${CLANG_CUDA_ARCH})
COMPILER_SPECIFIC_FLAGS(
Clang -Xopenmp-target -march=${CLANG_CUDA_ARCH} -fopenmp-targets=nvptx64
NVHPC -gpu=${NVHPC_CUDA_ARCH}
)
ENDIF()
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that most of it pre-existed but could you fix the indentation here in a sensible way?
Like that the closing ")" is at least as indented as the opening one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting the closing bracket in the same level as the opening one looks weird, I tried to put the opening one in the next line but that does not match the style in the rest of the file. I indented the lines inside the brackets to make the nesting look obvious. Let me know if thats acceptable.

Copy link
Contributor

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

Otherwise, this looks Ok to me.

cmake/kokkos_arch.cmake Outdated Show resolved Hide resolved
Copy link
Contributor

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

Thanks for bearing with me! 🙂

@masterleinad masterleinad dismissed crtrott’s stale review May 11, 2023 16:19

Requested changes have been addressed.

@dalg24 dalg24 merged commit b2645f8 into kokkos:develop May 19, 2023
28 checks passed
@nmm0 nmm0 mentioned this pull request Jun 16, 2023
nliber pushed a commit to nliber/kokkos that referenced this pull request Jun 22, 2023
…kos#5889)

* OpenMPTarget: Enable Cray compiler for the OpenMPTarget backend.

* OpenMPTarget: Adding a fixme for Cray compiler.

* OpenMPTarget: Add fixme for cray compiler.

* OpenMPTarget: fix indentation.

---------

Co-authored-by: Rahulkumar Gayatri <rgayatri@lbl.gov>
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.

None yet

4 participants