Skip to content

Commit ace2d49

Browse files
authored
Merge pull request #72 from SC-SGS/Kokkos
Add new Kokkos backend
2 parents b563c6f + cd6d31c commit ace2d49

File tree

91 files changed

+7409
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+7409
-364
lines changed

.clang-format

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
Language: Json
3+
DisableFormat: true
4+
---
25
Language: Cpp
36
AccessModifierOffset: -2
47
AlignAfterOpenBracket: Align
@@ -79,7 +82,7 @@ IncludeBlocks: Regroup
7982
IncludeCategories:
8083
- Regex: '^"plssvm/'
8184
Priority: 1
82-
- Regex: '^"(cuda|hip|CL|sycl|omp|hpx)'
85+
- Regex: '^"(cuda|hip|CL|sycl|omp|hpx|Kokkos)'
8386
Priority: 2
8487
- Regex: '^"(tests|bindings)/'
8588
Priority: 3

CMakeLists.txt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ endif ()
7272
########################################################################################################################
7373
## set base sources
7474
set(PLSSVM_BASE_SOURCES
75+
${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/backends/Kokkos/execution_space.cpp
7576
${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/backends/SYCL/implementation_types.cpp
7677
${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/backends/SYCL/kernel_invocation_types.cpp
7778
${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/backends/stdpar/implementation_types.cpp
@@ -411,6 +412,13 @@ if (PLSSVM_ENABLE_SYCL_BACKEND MATCHES "AUTO" OR PLSSVM_ENABLE_SYCL_BACKEND)
411412
add_subdirectory(src/plssvm/backends/SYCL)
412413
endif ()
413414

415+
## check for Kokkos backend
416+
set(PLSSVM_ENABLE_KOKKOS_BACKEND AUTO CACHE STRING "Enable SYCL Backend")
417+
set_property(CACHE PLSSVM_ENABLE_KOKKOS_BACKEND PROPERTY STRINGS AUTO ON OFF)
418+
if (PLSSVM_ENABLE_KOKKOS_BACKEND MATCHES "AUTO" OR PLSSVM_ENABLE_KOKKOS_BACKEND)
419+
add_subdirectory(src/plssvm/backends/Kokkos)
420+
endif ()
421+
414422
## check if ANY backend is available/has been enabled
415423
get_target_property(PLSSVM_LINKED_BACKENDS ${PLSSVM_ALL_LIBRARY_NAME} INTERFACE_LINK_LIBRARIES)
416424
if (NOT PLSSVM_LINKED_BACKENDS)
@@ -642,7 +650,7 @@ if (PLSSVM_ENABLE_FORMATTING)
642650
list(APPEND CMAKE_MESSAGE_INDENT "Formatting: ")
643651

644652
## install library to add a clang-format target
645-
set(PLSSVM_format_VERSION 7021abbf066e2e577926731c3fa4141f456c5024)
653+
set(PLSSVM_format_VERSION d22c36043bea6ef85f3eb68b823f50703bd1cc21)
646654
find_package(format QUIET)
647655
if (format_FOUND)
648656
message(STATUS "Found package format.")
@@ -734,6 +742,10 @@ if (TARGET ${PLSSVM_SYCL_BACKEND_LIBRARY_NAME})
734742
endforeach ()
735743
list(APPEND PLSSVM_BACKEND_NAME_LIST "sycl")
736744
endif ()
745+
if (TARGET ${PLSSVM_KOKKOS_BACKEND_LIBRARY_NAME})
746+
message(STATUS "${PLSSVM_KOKKOS_BACKEND_SUMMARY_STRING}")
747+
list(APPEND PLSSVM_BACKEND_NAME_LIST "kokkos")
748+
endif ()
737749
message(STATUS "")
738750

739751
########################################################################################################################
@@ -758,8 +770,8 @@ message(STATUS "Generating manpage files.")
758770
string(TIMESTAMP PLSSVM_CURRENT_BUILD_TIME "%d. %B %Y")
759771
string(REPLACE ";" "|" PLSSVM_PLATFORM_NAME_LIST "${PLSSVM_PLATFORM_NAME_LIST}")
760772
string(REPLACE ";" "|" PLSSVM_BACKEND_NAME_LIST "${PLSSVM_BACKEND_NAME_LIST}")
761-
string(REPLACE ";" "|" PLSSVM_SYCL_BACKEND_NAME_LIST "${PLSSVM_SYCL_BACKEND_NAME_LIST}")
762773
if (TARGET ${PLSSVM_SYCL_BACKEND_LIBRARY_NAME})
774+
string(REPLACE ";" "|" PLSSVM_SYCL_BACKEND_NAME_LIST "${PLSSVM_SYCL_BACKEND_NAME_LIST}")
763775
set(PLSSVM_SYCL_IMPLEMENTATION_TYPE_MANPAGE_ENTRY "
764776
.TP
765777
.B --sycl_implementation_type
@@ -772,6 +784,15 @@ choose the kernel invocation type when using SYCL as backend: automatic|nd_range
772784
")
773785
endif ()
774786
set(PLSSVM_SYCL_MANPAGE_ENTRY "${PLSSVM_SYCL_KERNEL_INVOCATION_TYPE_MANPAGE_ENTRY}${PLSSVM_SYCL_IMPLEMENTATION_TYPE_MANPAGE_ENTRY}")
787+
## assemble the Kokkos manpage entry
788+
if (TARGET ${PLSSVM_KOKKOS_BACKEND_LIBRARY_NAME})
789+
string(REPLACE ";" "|" PLSSVM_KOKKOS_BACKEND_AVAILABLE_EXECUTION_SPACES "${PLSSVM_KOKKOS_BACKEND_AVAILABLE_EXECUTION_SPACES}")
790+
set(PLSSVM_KOKKOS_MANPAGE_ENTRY "
791+
.TP
792+
.B --kokkos_execution_space
793+
choose the Kokkos execution space to be used in the Kokkos backend: automatic|${PLSSVM_KOKKOS_BACKEND_AVAILABLE_EXECUTION_SPACES} (default: automatic)
794+
")
795+
endif ()
775796
## assemble the performance tracker manpage entry
776797
if (PLSSVM_ENABLE_PERFORMANCE_TRACKING)
777798
set(PLSSVM_PERFORMANCE_TRACKER_MANPAGE_ENTRY "
@@ -787,6 +808,7 @@ configure_file(
787808
${CMAKE_CURRENT_SOURCE_DIR}/docs/plssvm-train.1
788809
@ONLY
789810
)
811+
# update manpage entry since plssvm-predict can't recognize the SYCL kernel invocation type
790812
set(PLSSVM_SYCL_MANPAGE_ENTRY "${PLSSVM_SYCL_IMPLEMENTATION_TYPE_MANPAGE_ENTRY}")
791813
configure_file(
792814
${CMAKE_CURRENT_SOURCE_DIR}/docs/plssvm-predict.1.in
@@ -866,6 +888,7 @@ install(FILES
866888
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/plssvm/plssvmHPXTargets.cmake"
867889
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/plssvm/plssvmAdaptiveCppTargets.cmake"
868890
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/plssvm/plssvmDPCPPTargets.cmake"
891+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/plssvm/plssvmKokkosTargets.cmake"
869892
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/plssvm/plssvmstdparTargets.cmake"
870893
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/plssvm/cmake
871894
)

CMakePresets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"cmake/presets/opencl.json",
1515
"cmake/presets/acpp.json",
1616
"cmake/presets/dpcpp.json",
17+
"cmake/presets/kokkos.json",
1718
"cmake/presets/all.json"
1819
]
1920
}

README.md

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ The main highlights of our SVM implementations are:
6565
- [HIP](https://github.com/ROCm-Developer-Tools/HIP)
6666
- [OpenCL](https://www.khronos.org/opencl/)
6767
- [SYCL](https://www.khronos.org/sycl/) (supported implementations are [DPC++](https://github.com/intel/llvm) and [AdaptiveCpp](https://github.com/AdaptiveCpp/AdaptiveCpp) (formerly known as hipSYCL); specifically the versions [sycl-nightly/20231201](https://github.com/intel/llvm/tree/sycl-nightly/20230110) and AdaptiveCpp release [v24.06.0](https://github.com/AdaptiveCpp/AdaptiveCpp/releases/tag/v23.10.0))
68+
- [Kokkos](https://github.com/kokkos/kokkos) (all execution spaces supported except `OpenMPTarget` and `OpenACC`); specifically the version [4.5.00](https://github.com/kokkos/kokkos/releases/tag/4.5.00)
6869
3. Six different kernel functions to be able to classify a large variety of different problems:
6970
- linear: $\vec{u}^T$ $\cdot$ $\vec{v}$
7071
- polynomial: $(\gamma$ $\cdot$ $\vec{u}^T$ $\cdot$ $\vec{v}$ $+$ $coef0)^{d}$
@@ -128,6 +129,10 @@ Additional dependencies for the SYCL backend:
128129

129130
- the code must be compiled with a SYCL capable compiler; currently supported are [DPC++](https://github.com/intel/llvm) and [AdaptiveCpp](https://github.com/AdaptiveCpp/AdaptiveCpp)
130131

132+
Additional dependencies for the Kokkos backend:
133+
134+
- a Kokkos installation with the respective execution spaces enabled; currently all execution spaces are supported except `OpenMPTarget` and `OpenACC`
135+
131136
Additional dependencies for the stdpar backend:
132137

133138
- the code must be compiled with a stdpar capable compiler; currently supported are [nvc++](https://developer.nvidia.com/hpc-sdk), [roc-stdpar](https://github.com/ROCm/roc-stdpar), [icpx](https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html), [AdaptiveCpp](https://github.com/AdaptiveCpp/AdaptiveCpp), and [GNU GCC](https://gcc.gnu.org/))
@@ -243,6 +248,11 @@ The `[optional_options]` can be one or multiple of:
243248
- `AUTO`: check for the OpenMP backend but **do not** fail if not available
244249
- `OFF`: do not check for the OpenMP backend
245250

251+
- `PLSSVM_ENABLE_HPX_BACKEND=ON|OFF|AUTO` (default: `AUTO`):
252+
- `ON`: check for the HPX backend and fail if not available
253+
- `AUTO`: check for the HPX backend but **do not** fail if not available
254+
- `OFF`: do not check for the HPX backend
255+
246256
- `PLSSVM_ENABLE_STDPAR_BACKEND=ON|OFF|AUTO` (default: `AUTO`):
247257
- `ON`: check for the stdpar backend and fail if not available
248258
- `AUTO`: check for the stdpar backend but **do not** fail if not available
@@ -268,6 +278,11 @@ The `[optional_options]` can be one or multiple of:
268278
- `AUTO`: check for the SYCL backend but **do not** fail if not available
269279
- `OFF`: do not check for the SYCL backend
270280

281+
- `PLSSVM_ENABLE_KOKKOS_BACKEND=ON|OFF|AUTO` (default: `AUTO`):
282+
- `ON`: check for the Kokkos backend and fail if not available
283+
- `AUTO`: check for the Kokkos backend but **do not** fail if not available
284+
- `OFF`: do not check for the Kokkos backend
285+
271286
**Attention:** at least one backend must be enabled and available!
272287

273288
- `PLSSVM_ENABLE_FAST_MATH=ON|OFF` (default depending on `CMAKE_BUILD_TYPE`: `ON` for Release or RelWithDebInfo, `OFF` otherwise): enable `fast-math` compiler flags for all backends
@@ -344,6 +359,10 @@ If more than one SYCL implementation is available the environment variables `PLS
344359

345360
- `PLSSVM_SYCL_BACKEND_PREFERRED_IMPLEMENTATION` (`dpcpp`|`adaptivecpp`): specify the preferred SYCL implementation if the `sycl_implementation_type` option is set to `automatic`; additional the specified SYCL implementation is used in the `plssvm::sycl` namespace, the other implementations are available in the `plssvm::dpcpp` and `plssvm::adaptivecpp` namespace respectively
346361

362+
If the Kokkos backend is available the following additional option is available (**note**: this option takes only effect if the Kokkos SYCL execution space is available):
363+
364+
- `PLSSVM_KOKKOS_BACKEND_INTEL_LLVM_ENABLE_AOT` (default: `ON`): enable Ahead-of-Time (AOT) compilation for the specified target platforms
365+
347366
If the stdpar backend is available, an additional options can be set.
348367

349368
- `PLSSVM_STDPAR_BACKEND_IMPLEMENTATION` (default: `AUTO`): explicitly specify the used stdpar implementation; must be one of: `AUTO`, `NVHPC`, `roc-stdpar`, `IntelLLVM`, `ACPP`, `GNU_TBB`.
@@ -363,24 +382,6 @@ Available configure presets:
363382
"hpx" - HPX backend
364383
"hpx_python" - HPX backend + Python bindings
365384
"hpx_test" - HPX backend tests
366-
"cuda" - CUDA backend
367-
"cuda_python" - CUDA backend + Python bindings
368-
"cuda_test" - CUDA backend tests
369-
"hip" - HIP backend
370-
"hip_python" - HIP backend + Python bindings
371-
"hip_test" - HIP backend tests
372-
"opencl" - OpenCL backend
373-
"opencl_python" - OpenCL backend + Python bindings
374-
"opencl_test" - OpenCL backend tests
375-
"acpp" - AdaptiveCpp SYCL backend
376-
"acpp_python" - AdaptiveCpp SYCL backend + Python bindings
377-
"acpp_test" - AdaptiveCpp SYCL backend tests
378-
"dpcpp" - DPC++/icpx SYCL backend
379-
"dpcpp_python" - DPC++/icpx backend + Python bindings
380-
"dpcpp_test" - DPC++/icpx backend tests
381-
"all" - All available backends
382-
"all_python" - All available backends + Python bindings
383-
"all_test" - All available backends tests
384385
"stdpar" - stdpar backend
385386
"stdpar_python" - stdpar backend + Python bindings
386387
"stdpar_test" - stdpar backend tests
@@ -399,6 +400,27 @@ Available configure presets:
399400
"stdpar_intelllvm" - stdpar IntelLLVM (icpx) backend
400401
"stdpar_intelllvm_python" - stdpar IntelLLVM (icpx) backend + Python bindings
401402
"stdpar_intelllvm_test" - stdpar IntelLLVM (icpx) backend tests
403+
"cuda" - CUDA backend
404+
"cuda_python" - CUDA backend + Python bindings
405+
"cuda_test" - CUDA backend tests
406+
"hip" - HIP backend
407+
"hip_python" - HIP backend + Python bindings
408+
"hip_test" - HIP backend tests
409+
"opencl" - OpenCL backend
410+
"opencl_python" - OpenCL backend + Python bindings
411+
"opencl_test" - OpenCL backend tests
412+
"acpp" - AdaptiveCpp SYCL backend
413+
"acpp_python" - AdaptiveCpp SYCL backend + Python bindings
414+
"acpp_test" - AdaptiveCpp SYCL backend tests
415+
"dpcpp" - DPC++/icpx SYCL backend
416+
"dpcpp_python" - DPC++/icpx backend + Python bindings
417+
"dpcpp_test" - DPC++/icpx backend tests
418+
"kokkos" - Kokkos backend
419+
"kokkos_python" - Kokkos backend + Python bindings
420+
"kokkos_test" - Kokkos backend tests
421+
"all" - All available backends
422+
"all_python" - All available backends + Python bindings
423+
"all_test" - All available backends tests
402424
```
403425

404426
With these presets, building and testing, e.g., our CUDA backend is as simple as typing (in the PLSSVM root directory):
@@ -553,12 +575,14 @@ Usage:
553575
-i, --max_iter arg set the maximum number of CG iterations (default: num_features)
554576
-l, --solver arg choose the solver: automatic|cg_explicit|cg_implicit (default: automatic)
555577
-a, --classification arg the classification strategy to use for multi-class classification: oaa|oao (default: oaa)
556-
-b, --backend arg choose the backend: automatic|openmp|hpx|cuda|hip|opencl|sycl|stdpar (default: automatic)
578+
-b, --backend arg choose the backend: automatic|openmp|hpx|cuda|hip|opencl|sycl|kokkos|stdpar (default: automatic)
557579
-p, --target_platform arg choose the target platform: automatic|cpu|gpu_nvidia|gpu_amd|gpu_intel (default: automatic)
558580
--sycl_kernel_invocation_type arg
559581
choose the kernel invocation type when using SYCL as backend: automatic|nd_range (default: automatic)
560582
--sycl_implementation_type arg
561583
choose the SYCL implementation to be used in the SYCL backend: automatic|dpcpp|adaptivecpp (default: automatic)
584+
--kokkos_execution_space arg
585+
choose the Kokkos execution space to be used in the Kokkos backend: automatic|Cuda|OpenMP|Serial (default: automatic)
562586
--performance_tracking arg
563587
the output YAML file where the performance tracking results are written to; if not provided, the results are dumped to stderr
564588
--use_strings_as_labels use strings as labels instead of plane numbers
@@ -594,10 +618,10 @@ Another example targeting NVIDIA GPUs using the SYCL backend looks like:
594618

595619
The `--backend=automatic` option works as follows:
596620

597-
- if the `gpu_nvidia` target is available, check for existing backends in order `cuda` 🠦 `hip` 🠦 `opencl` 🠦 `sycl` 🠦 `stdpar`
598-
- otherwise, if the `gpu_amd` target is available, check for existing backends in order `hip` 🠦 `opencl` 🠦 `sycl` 🠦 `stdpar`
599-
- otherwise, if the `gpu_intel` target is available, check for existing backends in order `sycl` 🠦 `opencl` 🠦 `stdpar`
600-
- otherwise, if the `cpu` target is available, check for existing backends in order `sycl` 🠦 `opencl` 🠦 `openmp` 🠦 `hpx` 🠦 `stdpar`
621+
- if the `gpu_nvidia` target is available, check for existing backends in order `cuda` 🠦 `hip` 🠦 `opencl` 🠦 `sycl` 🠦 `kokkos` 🠦 `stdpar`
622+
- otherwise, if the `gpu_amd` target is available, check for existing backends in order `hip` 🠦 `opencl` 🠦 `sycl` 🠦 `kokkos` 🠦 `stdpar`
623+
- otherwise, if the `gpu_intel` target is available, check for existing backends in order `sycl` 🠦 `opencl` 🠦 `kokkos` 🠦 `stdpar`
624+
- otherwise, if the `cpu` target is available, check for existing backends in order `sycl` 🠦 `kokkos` 🠦 `opencl` 🠦 `openmp` 🠦 `hpx` 🠦 `stdpar`
601625

602626
Note that during CMake configuration it is guaranteed that at least one of the above combinations does exist.
603627

@@ -609,11 +633,13 @@ The `--target_platform=automatic` option works for the different backends as fol
609633
- `HIP`: always selects an AMD GPU (if no AMD GPU is available, throws an exception)
610634
- `OpenCL`: tries to find available devices in the following order: NVIDIA GPUs 🠦 AMD GPUs 🠦 Intel GPUs 🠦 CPU
611635
- `SYCL`: tries to find available devices in the following order: NVIDIA GPUs 🠦 AMD GPUs 🠦 Intel GPUs 🠦 CPU
636+
- `Kokkos`: checks which execution spaces are available and which target platforms they support and then tries to find available devices in the following order: NVIDIA GPUs 🠦 AMD GPUs 🠦 Intel GPUs 🠦 CPU
612637
- `stdpar`: target device must be selected at compile time (using `PLSSVM_TARGET_PLATFORMS`) or using environment variables at runtime
613638

614639
The `--sycl_kernel_invocation_type` and `--sycl_implementation_type` flags are only used if the `--backend` is `sycl`, otherwise a warning is emitted on `stderr`.
615640
If the `--sycl_kernel_invocation_type` is `automatic`, the `nd_range` invocation type is currently always used.
616641
If the `--sycl_implementation_type` is `automatic`, the used SYCL implementation is determined by the `PLSSVM_SYCL_BACKEND_PREFERRED_IMPLEMENTATION` CMake flag.
642+
If the `--kokkos_execution_space` is `automatic`, uses the best fitting execution space based on the provided and/or available target platforms.
617643

618644
### Predicting using `plssvm-predict`
619645

@@ -628,10 +654,12 @@ LS-SVM with multiple (GPU-)backends
628654
Usage:
629655
./plssvm-predict [OPTION...] test_file model_file [output_file]
630656
631-
-b, --backend arg choose the backend: automatic|openmp|cuda|hip|opencl|sycl|stdpar (default: automatic)
657+
-b, --backend arg choose the backend: automatic|openmp|hpx|cuda|hip|opencl|sycl|kokkos|stdpar (default: automatic)
632658
-p, --target_platform arg choose the target platform: automatic|cpu|gpu_nvidia|gpu_amd|gpu_intel (default: automatic)
633659
--sycl_implementation_type arg
634660
choose the SYCL implementation to be used in the SYCL backend: automatic|dpcpp|adaptivecpp (default: automatic)
661+
--kokkos_execution_space arg
662+
choose the Kokkos execution space to be used in the Kokkos backend: automatic|Cuda|OpenMP|Serial (default: automatic)
635663
--performance_tracking arg
636664
the output YAML file where the performance tracking results are written to; if not provided, the results are dumped to stderr
637665
--use_strings_as_labels use strings as labels instead of plane numbers
@@ -777,9 +805,6 @@ Roughly the same can be achieved using our Python bindings with the following Py
777805
import plssvm
778806
from sklearn.metrics import classification_report
779807

780-
# correctly initialize and finalize environments
781-
environment_guard = plssvm.environment.ScopeGuard()
782-
783808
try:
784809
# create a new C-SVM parameter set, explicitly overriding the default kernel function
785810
params = plssvm.Parameter(kernel_type=plssvm.KernelFunctionType.POLYNOMIAL)

bindings/Python/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ set(PLSSVM_PYTHON_BINDINGS_SOURCES
4141
${CMAKE_CURRENT_LIST_DIR}/classification_types.cpp
4242
${CMAKE_CURRENT_LIST_DIR}/csvm.cpp
4343
${CMAKE_CURRENT_LIST_DIR}/data_set.cpp
44-
${CMAKE_CURRENT_LIST_DIR}/environment.cpp
4544
${CMAKE_CURRENT_LIST_DIR}/file_format_types.cpp
4645
${CMAKE_CURRENT_LIST_DIR}/gamma.cpp
4746
${CMAKE_CURRENT_LIST_DIR}/kernel_function_types.cpp
@@ -98,6 +97,9 @@ endif ()
9897
if (TARGET ${PLSSVM_SYCL_BACKEND_DPCPP_LIBRARY_NAME})
9998
list(APPEND PLSSVM_PYTHON_BINDINGS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/backends/dpcpp_csvm.cpp)
10099
endif ()
100+
if (TARGET ${PLSSVM_KOKKOS_BACKEND_LIBRARY_NAME})
101+
list(APPEND PLSSVM_PYTHON_BINDINGS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/backends/kokkos_csvm.cpp)
102+
endif ()
101103

102104
# create pybind11 module
103105
set(PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME plssvm)

0 commit comments

Comments
 (0)