Skip to content

Commit

Permalink
Enable OpenMP back-ends for clang-cuda
Browse files Browse the repository at this point in the history
  • Loading branch information
j-stephan committed Sep 11, 2023
1 parent 2b8e52a commit 168f284
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 55 deletions.
4 changes: 3 additions & 1 deletion cmake/alpakaCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ if(alpaka_ACC_GPU_CUDA_ENABLE)
endif()

if(alpaka_ACC_CPU_B_OMP2_T_SEQ_ENABLE OR alpaka_ACC_CPU_B_SEQ_T_OMP2_ENABLE)
message(FATAL_ERROR "Clang as a CUDA compiler does not support OpenMP 2!")
# FindOpenMP.cmake guards the OpenMP::OpenMP_CXX target with a $<COMPILE_LANGUAGE:CXX> generator expression.
# We have to duplicate the flags here.
alpaka_set_compiler_options(DEVICE target alpaka "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:${OpenMP_CXX_FLAGS}>")
endif()

target_compile_options(alpaka INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:-Wno-unknown-cuda-version>)
Expand Down
11 changes: 9 additions & 2 deletions include/alpaka/acc/AccCpuOmp2Blocks.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Axel Huebl, Benjamin Worpitz, René Widera, Jan Stephan, Bernhard Manfred Gruber
/* Copyright 2023 Axel Hübl, Benjamin Worpitz, René Widera, Jan Stephan, Bernhard Manfred Gruber
* SPDX-License-Identifier: MPL-2.0
*/

Expand Down Expand Up @@ -40,7 +40,12 @@

#ifdef ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED

# if _OPENMP < 200203
/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if(_OPENMP < 200203) && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

Expand Down Expand Up @@ -223,4 +228,6 @@ namespace alpaka
} // namespace trait
} // namespace alpaka

# pragma clang diagnostic pop

#endif
11 changes: 9 additions & 2 deletions include/alpaka/acc/AccCpuOmp2Threads.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Axel Huebl, Benjamin Worpitz, René Widera, Jan Stephan, Bernhard Manfred Gruber
/* Copyright 2023 Axel Hübl, Benjamin Worpitz, René Widera, Jan Stephan, Bernhard Manfred Gruber
* SPDX-License-Identifier: MPL-2.0
*/

Expand Down Expand Up @@ -40,7 +40,12 @@

#ifdef ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED

# if _OPENMP < 200203
/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if _OPENMP < 200203 && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

Expand Down Expand Up @@ -233,4 +238,6 @@ namespace alpaka
} // namespace trait
} // namespace alpaka

# pragma clang diagnostic pop

#endif
25 changes: 18 additions & 7 deletions include/alpaka/atomic/AtomicOmpBuiltIn.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 René Widera, Bernhard Manfred Gruber
/* Copyright 2023 René Widera, Bernhard Manfred Gruber, Jan Stephan
* SPDX-License-Identifier: MPL-2.0
*/

Expand All @@ -8,7 +8,16 @@
#include "alpaka/atomic/Traits.hpp"
#include "alpaka/core/BoostPredef.hpp"

#ifdef _OPENMP
#if defined(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED) || defined(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED)

/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if(_OPENMP < 200203) && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

namespace alpaka
{
Expand All @@ -24,7 +33,7 @@ namespace alpaka
{
// check for OpenMP 3.1+
// "omp atomic capture" is not supported before OpenMP 3.1
# if _OPENMP >= 201107
# if _OPENMP >= 201107 || BOOST_COMP_CLANG_CUDA

//! The OpenMP accelerators atomic operation: ADD
template<typename T, typename THierarchy>
Expand Down Expand Up @@ -169,11 +178,11 @@ namespace alpaka
}
};

# endif // _OPENMP >= 201107
# endif // _OPENMP >= 201107 || BOOST_COMP_CLANG_CUDA

// check for OpenMP 5.1+
// "omp atomic compare" was introduced with OpenMP 5.1
# if _OPENMP >= 202011
// "omp atomic compare" was introduced with OpenMP 5.1 (supported since clang-15)
# if _OPENMP >= 202011 || (BOOST_COMP_CLANG_CUDA >= BOOST_VERSION_NUMBER(15, 0, 0))

//! The OpenMP accelerators atomic operation: Min
template<typename T, typename THierarchy>
Expand Down Expand Up @@ -319,9 +328,11 @@ namespace alpaka
}
};

# endif // _OPENMP >= 202011
# endif // _OPENMP >= 202011 || (BOOST_COMP_CLANG_CUDA >= BOOST_VERSION_NUMBER(15, 0, 0))

} // namespace trait
} // namespace alpaka

# pragma clang diagnostic pop

#endif
13 changes: 12 additions & 1 deletion include/alpaka/block/sync/BlockSyncBarrierOmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@

#include <cstdint>

#ifdef _OPENMP
#if defined(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED) || defined(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED)

/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if(_OPENMP < 200203) && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

namespace alpaka
{
Expand Down Expand Up @@ -106,4 +115,6 @@ namespace alpaka
} // namespace trait
} // namespace alpaka

# pragma clang diagnostic pop

#endif
14 changes: 11 additions & 3 deletions include/alpaka/core/OmpSchedule.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
/* Copyright 2022 Sergei Bastrakov, Bernhard Manfred Gruber
/* Copyright 2023 Sergei Bastrakov, Bernhard Manfred Gruber, Jan Stephan
* SPDX-License-Identifier: MPL-2.0
*/

#pragma once

#include "alpaka/core/BoostPredef.hpp"
#include "alpaka/core/Common.hpp"

#ifdef _OPENMP
#if defined(_OPENMP)
# include <omp.h>
#endif

#include <cstdint>

/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundef"

namespace alpaka::omp
{
//! Representation of OpenMP schedule information: kind and chunk size. This class can be used regardless of
Expand All @@ -30,7 +36,7 @@ namespace alpaka::omp
Dynamic = 2u,
Guided = 3u,
// Auto supported since OpenMP 3.0
#if defined _OPENMP && _OPENMP >= 200805
#if(defined _OPENMP && _OPENMP >= 200805) || BOOST_COMP_CLANG_CUDA
Auto = 4u,
#endif
Runtime = 5u
Expand Down Expand Up @@ -86,3 +92,5 @@ namespace alpaka::omp
}
}
} // namespace alpaka::omp

#pragma clang diagnostic pop
15 changes: 13 additions & 2 deletions include/alpaka/idx/bt/IdxBtOmp.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Axel Huebl, Benjamin Worpitz, Matthias Werner, Jan Stephan, Bernhard Manfred Gruber
/* Copyright 2023 Axel Hübl, Benjamin Worpitz, Matthias Werner, Jan Stephan, Bernhard Manfred Gruber, Jan Stephan
* SPDX-License-Identifier: MPL-2.0
*/

Expand All @@ -12,7 +12,16 @@
#include "alpaka/vec/Vec.hpp"
#include "alpaka/workdiv/Traits.hpp"

#ifdef _OPENMP
#ifdef ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED

/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if(_OPENMP < 200203) && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

# include <omp.h>

Expand Down Expand Up @@ -74,4 +83,6 @@ namespace alpaka
} // namespace trait
} // namespace alpaka

# pragma clang diagnostic pop

#endif
15 changes: 11 additions & 4 deletions include/alpaka/kernel/TaskKernelCpuOmp2Blocks.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Benjamin Worpitz, Bert Wesarg, René Widera, Sergei Bastrakov, Bernhard Manfred Gruber
/* Copyright 2023 Benjamin Worpitz, Bert Wesarg, René Widera, Sergei Bastrakov, Bernhard Manfred Gruber, Jan Stephan
* SPDX-License-Identifier: MPL-2.0
*/

Expand Down Expand Up @@ -31,7 +31,12 @@

#ifdef ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED

# if _OPENMP < 200203
/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if _OPENMP < 200203 && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

Expand Down Expand Up @@ -515,7 +520,7 @@ namespace alpaka
{
};

# if _OPENMP >= 200805
# if _OPENMP >= 200805 || BOOST_COMP_CLANG_CUDA
//! Executor of parallel OpenMP loop with auto schedule set
//!
//! Does not use chunk size.
Expand Down Expand Up @@ -682,7 +687,7 @@ namespace alpaka
numIterations,
schedule);
break;
# if _OPENMP >= 200805
# if _OPENMP >= 200805 || BOOST_COMP_CLANG_CUDA
case omp::Schedule::Auto:
ParallelForImpl<TKernel, omp::Schedule, omp::Schedule::Auto>{}(
kernel,
Expand Down Expand Up @@ -949,4 +954,6 @@ namespace alpaka
} // namespace trait
} // namespace alpaka

# pragma clang diagnostic pop

#endif
11 changes: 9 additions & 2 deletions include/alpaka/kernel/TaskKernelCpuOmp2Threads.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Axel Huebl, Benjamin Worpitz, Bert Wesarg, René Widera, Jan Stephan, Bernhard Manfred Gruber
/* Copyright 2023 Axel Hübl, Benjamin Worpitz, Bert Wesarg, René Widera, Jan Stephan, Bernhard Manfred Gruber
* SPDX-License-Identifier: MPL-2.0
*/

Expand Down Expand Up @@ -29,7 +29,12 @@

#ifdef ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED

# if _OPENMP < 200203
/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if _OPENMP < 200203 && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

Expand Down Expand Up @@ -195,4 +200,6 @@ namespace alpaka
} // namespace trait
} // namespace alpaka

# pragma clang diagnostic pop

#endif
11 changes: 9 additions & 2 deletions include/alpaka/mem/fence/MemFenceOmp2Blocks.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Jan Stephan, Bernhard Manfred Gruber, Andrea Bocci
/* Copyright 2023 Jan Stephan, Bernhard Manfred Gruber, Andrea Bocci
* SPDX-License-Identifier: MPL-2.0
*/

Expand All @@ -9,7 +9,12 @@

#ifdef ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED

# if _OPENMP < 200203
/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if _OPENMP < 200203 && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

Expand Down Expand Up @@ -51,4 +56,6 @@ namespace alpaka
} // namespace trait
} // namespace alpaka

# pragma clang diagnostic pop

#endif
12 changes: 10 additions & 2 deletions include/alpaka/mem/fence/MemFenceOmp2Threads.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Jan Stephan, Bernhard Manfred Gruber
/* Copyright 2023 Jan Stephan, Bernhard Manfred Gruber
* SPDX-License-Identifier: MPL-2.0
*/

Expand All @@ -9,7 +9,12 @@

#ifdef ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED

# if _OPENMP < 200203
/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if _OPENMP < 200203 && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

Expand Down Expand Up @@ -65,4 +70,7 @@ namespace alpaka
};
} // namespace trait
} // namespace alpaka

# pragma clang diagnostic pop

#endif
11 changes: 9 additions & 2 deletions include/alpaka/test/queue/QueueCpuOmp2Collective.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Axel Huebl, Benjamin Worpitz, Matthias Werner, Jan Stephan, Bernhard Manfred Gruber
/* Copyright 2023 Axel Hübl, Benjamin Worpitz, Matthias Werner, Jan Stephan, Bernhard Manfred Gruber
* SPDX-License-Identifier: MPL-2.0
*/

Expand All @@ -21,7 +21,12 @@

#ifdef ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED

# if _OPENMP < 200203
/* clang doesn't define the _OPENMP macro when compiling in CUDA mode. We need to turn off -Wundef so clang doesn't
complain about our preprocessor guards.*/
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wundef"

# if _OPENMP < 200203 && !defined(BOOST_COMP_CLANG_CUDA)
# error If ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
# endif

Expand Down Expand Up @@ -292,6 +297,8 @@ namespace alpaka
};
} // namespace alpaka

# pragma clang diagnostic pop

# include "alpaka/event/EventCpu.hpp"

#endif
10 changes: 0 additions & 10 deletions script/job_generator/alpaka_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,4 @@ def alpaka_post_filter(row: List) -> bool:
):
return False

# OpenMP is not supported for clang as cuda compiler
# https://github.com/alpaka-group/alpaka/issues/639
if row_check_name(row, DEVICE_COMPILER, "==", CLANG_CUDA) and (
row_check_backend_version(row, ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE, "==", ON_VER)
or row_check_backend_version(
row, ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE, "==", ON_VER
)
):
return False

return True
Loading

0 comments on commit 168f284

Please sign in to comment.