Skip to content

Commit 775054a

Browse files
authored
Merge Pull Request #230 from abagusetty/EKAT/feature/sycl
Automatically Merged using E3SM Pull Request AutoTester PR Title: Support for SYCL PR Author: abagusetty
2 parents ca50c2e + b95d0eb commit 775054a

14 files changed

Lines changed: 92 additions & 19 deletions

CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,18 @@ option (EKAT_DISABLE_TPL_WARNINGS "Whether we should suppress warnings when comp
9595
set (EKAT_TPL_LIBRARIES_INTERNAL)
9696

9797
# A good chunk of EKAT is a utility layer over kokkos
98-
BuildKokkos()
99-
list (APPEND EKAT_TPL_LIBRARIES_INTERNAL ${Kokkos_LIBRARIES})
98+
# Note: for SYCL/HIP backend, bleeding edge of kokkos/develop might be needed to test some functionality
99+
# Kokkos_ROOT can point to custom installation directory
100+
if (Kokkos_ROOT)
101+
find_package(Kokkos REQUIRED)
102+
set(Kokkos_LIBRARIES Kokkos::kokkos)
103+
else()
104+
BuildKokkos()
105+
endif()
106+
list (APPEND EKAT_TPL_LIBRARIES_INTERNAL ${Kokkos_LIBRARIES})
100107

101108
set (EKAT_ENABLE_GPU False)
102-
if (Kokkos_ENABLE_CUDA)
103-
set (EKAT_ENABLE_GPU True)
104-
endif ()
105-
if (Kokkos_ENABLE_HIP)
109+
if (Kokkos_ENABLE_CUDA OR Kokkos_ENABLE_HIP OR Kokkos_ENABLE_SYCL)
106110
set (EKAT_ENABLE_GPU True)
107111
endif ()
108112

cmake/EkatSetCompilerFlags.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ macro (SetWarningFlags)
131131
set (FFLAGS -Wall)
132132
set (CXXFLAGS -Wall)
133133
endif()
134-
134+
135135
SetFlags(FFLAGS ${FFLAGS} CFLAGS -Wall CXXFLAGS ${CXXFLAGS})
136136
endmacro()
137137

@@ -217,6 +217,8 @@ macro (SetReleaseFlags)
217217
string (APPEND CMAKE_CXX_FLAGS_RELEASE " -fopenmp-simd")
218218
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
219219
string (APPEND CMAKE_CXX_FLAGS_RELEASE " -qopenmp-simd")
220+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
221+
string (APPEND CMAKE_CXX_FLAGS_RELEASE " -fsycl -fsycl-unnamed-lambda -sycl-std=2020 -qopenmp-simd -Wsycl-strict -fsycl-device-code-split=per_kernel")
220222
endif()
221223
endif ()
222224
endif ()
@@ -275,6 +277,8 @@ macro (SetDebugFlags)
275277
string (APPEND CMAKE_CXX_FLAGS_DEBUG " -fopenmp-simd")
276278
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
277279
string (APPEND CMAKE_CXX_FLAGS_DEBUG " -qopenmp-simd")
280+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
281+
string (APPEND CMAKE_CXX_FLAGS_DEBUG " -qopenmp-simd -fsycl -fsycl-unnamed-lambda -sycl-std=2020 -Wsycl-strict -fno-sycl-dead-args-optimization")
278282
endif()
279283
endif ()
280284
endif ()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Load gen9 arch with SYCL backend for kokkos
2+
set(CMAKE_CXX_STANDARD 17)
3+
include (${CMAKE_CURRENT_LIST_DIR}/kokkos/intel-gen9.cmake)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Load XEHP arch with SYCL backend for kokkos
2+
include (${CMAKE_CURRENT_LIST_DIR}/kokkos/intel-xehp.cmake)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include (${CMAKE_CURRENT_LIST_DIR}/generic.cmake)
2+
3+
option(Kokkos_ARCH_INTEL_GEN9 "" ON)
4+
set(Kokkos_ENABLE_SYCL TRUE CACHE BOOL "")
5+
set(Kokkos_ENABLE_DEPRECATED_CODE_3 FALSE CACHE BOOL "")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include (${CMAKE_CURRENT_LIST_DIR}/generic.cmake)
2+
3+
option(Kokkos_ARCH_INTEL_XEHP "" ON)
4+
set(Kokkos_ENABLE_SYCL TRUE CACHE BOOL "")
5+
set(Kokkos_ENABLE_DEPRECATED_CODE_3 FALSE CACHE BOOL "")

src/ekat/ekat.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ static constexpr bool ekatBFB = false;
2525
typedef Kokkos::Cuda EkatGpuSpace;
2626
# elif defined KOKKOS_ENABLE_HIP
2727
typedef Kokkos::Experimental::HIP EkatGpuSpace;
28+
# elif defined KOKKOS_ENABLE_SYCL
29+
typedef Kokkos::Experimental::SYCL EkatGpuSpace;
2830
# else
29-
error "EKAT does not recognize a GPU space other than Cuda and HIP."
31+
error "EKAT does not recognize a GPU space other than Cuda, HIP and SYCL".
3032
# endif
3133
#endif
3234

src/ekat/ekat_assert.hpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,25 @@
2727
} \
2828
} while(0)
2929

30-
#define IMPL_KERNEL_THROW(condition, msg) \
31-
do { \
32-
if ( ! (condition) ) { \
33-
printf("KERNEL CHECK FAILED:\n %s\n %s\n",#condition,msg); \
34-
Kokkos::abort(""); \
35-
} \
30+
// SYCL cannot printf like the other backends quite yet
31+
#ifdef __SYCL_DEVICE_ONLY__
32+
#define IMPL_KERNEL_THROW(condition, msg) \
33+
do { \
34+
if ( ! (condition) ) { \
35+
const __attribute__((opencl_constant)) char format[] = "KERNEL CHECK FAILED:\n %s %s\n"; \
36+
sycl::ext::oneapi::experimental::printf(format,#condition,msg); \
37+
Kokkos::abort(""); \
38+
} \
3639
} while (0)
40+
#else
41+
#define IMPL_KERNEL_THROW(condition, msg) \
42+
do { \
43+
if ( ! (condition) ) { \
44+
printf("KERNEL CHECK FAILED:\n %s\n %s\n",#condition,msg); \
45+
Kokkos::abort(""); \
46+
} \
47+
} while (0)
48+
#endif
3749

3850
#ifndef NDEBUG
3951
#define EKAT_ASSERT(condition) IMPL_THROW(condition, "", std::logic_error)

src/ekat/ekat_config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// Decide whether ekat defaults to BFB behavior when possible/appropriate
2323
#cmakedefine EKAT_FPE
2424

25-
// A GPU space has been enabled in Kokkos, e.g., CUDA or HIP.
25+
// A GPU space has been enabled in Kokkos, e.g., CUDA or HIP OR SYCL.
2626
#cmakedefine EKAT_ENABLE_GPU
2727

2828
#endif // EKAT_CONFIG_H

src/ekat/ekat_session.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ void initialize_kokkos () {
3232
# elif defined KOKKOS_ENABLE_HIP
3333
const auto ret = hipGetDeviceCount(&nd);
3434
const bool ok = ret == hipSuccess;
35+
# elif defined KOKKOS_ENABLE_SYCL
36+
nd = 0;
37+
auto gpu_devs = sycl::device::get_devices(sycl::info::device_type::gpu);
38+
for (auto &dev : gpu_devs) {
39+
if (dev.get_info<sycl::info::device::partition_max_sub_devices>() > 0) {
40+
auto subDevs = dev.create_sub_devices<sycl::info::partition_property::partition_by_affinity_domain>(sycl::info::partition_affinity_domain::numa);
41+
nd += subDevs.size();
42+
} else {
43+
nd++;
44+
}
45+
}
46+
const bool ok = true;
3547
# else
3648
error "No valid GPU space, yet EKAT_ENABLE_GPU is defined."
3749
# endif

0 commit comments

Comments
 (0)