Skip to content

Commit 4b90f3e

Browse files
committed
Merge branch 'regression' into spack
2 parents 56ebbff + 4080ef4 commit 4b90f3e

27 files changed

+1278
-1122
lines changed

CMakeLists.txt

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -283,35 +283,29 @@ elseif (DEFINED ENV{PLSSVM_TARGET_PLATFORMS})
283283
set(PLSSVM_TARGET_PLATFORMS $ENV{PLSSVM_TARGET_PLATFORMS} CACHE STRING "The target platforms to compile for." FORCE)
284284
else ()
285285
# check for Python3 and all necessary libraries
286-
# find_package(Python3 COMPONENTS Interpreter Development)
287-
# if (NOT Python3_FOUND)
288-
# message(FATAL_ERROR "Can't find Python3. Please manually specify PLSSVM_TARGET_PLATFORMS (e.g. -DPLSSVM_TARGET_PLATFORMS=\"cpu;nvidia:sm_70,sm_86;amd:gfx906;intel:skl\"!")
289-
# endif ()
290-
291-
# include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_python_libs.cmake)
292-
# set(PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS cpuinfo GPUtil pyamdgpuinfo pylspci)
293-
# message(STATUS "Checking required Python3 libraries (${PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS}) to automatically determine the PLSSVM_TARGET_PLATFORMS.")
294-
# set(PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS_ERROR_MESSAGE "or manually define PLSSVM_TARGET_PLATFORMS (e.g. -DPLSSVM_TARGET_PLATFORMS=\"cpu;nvidia:sm_70,sm_86;amd:gfx906;intel:skl\"!")
295-
# check_python_libs(${PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS} ${PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS_ERROR_MESSAGE})
296-
297-
# # run our `plssvm_target_platforms.py` script to determine the PLSSVM_TARGET_PLATFORMS string
298-
# execute_process(
299-
# COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/utility_scripts/plssvm_target_platforms.py" "--quiet"
300-
# RESULT_VARIABLE PLSSVM_PYTHON_TARGET_PLATFORMS_EXIT_CODE
301-
# OUTPUT_VARIABLE PLSSVM_PYTHON_TARGET_PLATFORMS_OUTPUT
302-
# )
286+
find_package(Python3 COMPONENTS Interpreter Development)
287+
if (NOT Python3_FOUND)
288+
message(FATAL_ERROR "Can't find Python3. Please manually specify PLSSVM_TARGET_PLATFORMS (e.g. -DPLSSVM_TARGET_PLATFORMS=\"cpu;nvidia:sm_70,sm_86;amd:gfx906;intel:skl\"!")
289+
endif ()
290+
291+
# run our `plssvm_target_platforms.py` script to determine the PLSSVM_TARGET_PLATFORMS string
292+
execute_process(
293+
COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/utility_scripts/plssvm_target_platforms.py" "--quiet"
294+
RESULT_VARIABLE PLSSVM_PYTHON_TARGET_PLATFORMS_EXIT_CODE
295+
OUTPUT_VARIABLE PLSSVM_PYTHON_TARGET_PLATFORMS_OUTPUT
296+
)
303297

304-
# # an error occurred when running our python script
305-
# if (NOT ${PLSSVM_PYTHON_TARGET_PLATFORMS_EXIT_CODE} EQUAL 0)
306-
# message(FATAL_ERROR
307-
# "Error running '${CMAKE_CURRENT_SOURCE_DIR}/utility_scripts/plssvm_target_platforms.py'."
308-
# "Please manually specify PLSSVM_TARGET_PLATFORMS (e.g. -DPLSSVM_TARGET_PLATFORMS=\"cpu;nvidia:sm_70,sm_86;amd:gfx906;intel:skl\"!"
309-
# )
310-
# endif ()
298+
# an error occurred when running our python script
299+
if (NOT ${PLSSVM_PYTHON_TARGET_PLATFORMS_EXIT_CODE} EQUAL 0)
300+
message(FATAL_ERROR
301+
"Error running '${CMAKE_CURRENT_SOURCE_DIR}/utility_scripts/plssvm_target_platforms.py'."
302+
"Please manually specify PLSSVM_TARGET_PLATFORMS (e.g. -DPLSSVM_TARGET_PLATFORMS=\"cpu;nvidia:sm_70,sm_86;amd:gfx906;intel:skl\"!"
303+
)
304+
endif ()
311305

312-
# # set PLSSVM_TARGET_PLATFORMS
313-
# string(STRIP "${PLSSVM_PYTHON_TARGET_PLATFORMS_OUTPUT}" PLSSVM_TARGET_PLATFORMS)
314-
# message(STATUS "Automatically derived PLSSVM_TARGET_PLATFORMS=\"${PLSSVM_TARGET_PLATFORMS}\".")
306+
# set PLSSVM_TARGET_PLATFORMS
307+
string(STRIP "${PLSSVM_PYTHON_TARGET_PLATFORMS_OUTPUT}" PLSSVM_TARGET_PLATFORMS)
308+
message(STATUS "Automatically derived PLSSVM_TARGET_PLATFORMS=\"${PLSSVM_TARGET_PLATFORMS}\".")
315309
endif ()
316310

317311

@@ -606,7 +600,7 @@ list(POP_BACK CMAKE_MESSAGE_INDENT)
606600
option(PLSSVM_ENABLE_FORMATTING "Enable a formatting targets using clang-format." OFF)
607601
if (PLSSVM_ENABLE_FORMATTING)
608602
list(APPEND CMAKE_MESSAGE_INDENT "Formatting: ")
609-
603+
610604
## install library to add a clang-format target
611605
set(PLSSVM_format_VERSION d22c36043bea6ef85f3eb68b823f50703bd1cc21)
612606
find_package(format QUIET)
@@ -625,7 +619,7 @@ if (PLSSVM_ENABLE_FORMATTING)
625619
)
626620
FetchContent_MakeAvailable(format)
627621
endif ()
628-
622+
629623
list(POP_BACK CMAKE_MESSAGE_INDENT)
630624
endif ()
631625

README.md

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![![PLSSVM](../resources/logo_245x150.png)](docs/resources/logo_245x150.png)
1+
![PLSSVM](https://github.com/SC-SGS/PLSSVM/raw/main/docs/resources/logo_245x150.png)
22

33
# PLSSVM - Parallel Least Squares Support Vector Machine
44

@@ -35,7 +35,7 @@ To predict to which class a new, unseen data point belongs, the SVM simply has t
3535
This is very efficient since it only involves a single scalar product of the size corresponding to the numer of features of the data set.
3636

3737
<p align="center">
38-
<img alt="Basic idea of an Support Vector Machine as classification model." src=".figures/support_vector_machine.png" width="50%">
38+
<img alt="Basic idea of an Support Vector Machine as classification model." src="https://github.com/SC-SGS/PLSSVM/raw/main/.figures/support_vector_machine.png" width="50%">
3939
</p>
4040

4141
However, normal SVMs suffer in their potential parallelizability.
@@ -188,13 +188,9 @@ Valid targets are:
188188
- `intel`: compile for Intel GPUs; **at least one** architectural specification is necessary, e.g., `intel:skl`
189189

190190
At least one of the above targets must be present. If the option `PLSSVM_TARGET_PLATFORMS` is not present, the targets
191-
are automatically determined using the Python3 `utility_scripts/plssvm_target_platforms.py` script (required Python3 dependencies:
192-
[`argparse`](https://docs.python.org/3/library/argparse.html), [`py-cpuinfo`](https://pypi.org/project/py-cpuinfo/),
193-
[`GPUtil`](https://pypi.org/project/GPUtil/), [`pyamdgpuinfo`](https://pypi.org/project/pyamdgpuinfo/), and
194-
[`pylspci`](https://pypi.org/project/pylspci/)).
191+
are automatically determined using the Python3 `utility_scripts/plssvm_target_platforms.py` script.
195192

196-
Note that when using DPC++/icpx only a single architectural specification for `cpu`, `nvidia` or `amd` is allowed and that
197-
automatically retrieving AMD GPU information on Windows is currently not supported due to `pyamdgpuinfo` limitations.
193+
Note that when using DPC++/icpx only a single architectural specification for `cpu`, `nvidia` or `amd` is allowed.
198194

199195

200196
```bash
@@ -204,8 +200,9 @@ python3 utility_scripts/plssvm_target_platforms.py --help
204200
usage: plssvm_target_platforms.py [-h] [--quiet]
205201
206202
optional arguments:
207-
-h, --help show this help message and exit
208-
--quiet only output the final PLSSVM_TARGET_PLATFORMS string
203+
-h, --help show this help message and exit
204+
--quiet only output the final PLSSVM_TARGET_PLATFORMS string
205+
--gpus_only only output gpu architectures to the final PLSSVM_TARGET_PLATFORMS string
209206
```
210207

211208
Example invocation:
@@ -214,10 +211,9 @@ Example invocation:
214211
python3 utility_scripts/plssvm_target_platforms.py
215212
```
216213
```
217-
Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz: {'avx512': True, 'avx2': True, 'avx': True, 'sse4_2': True}
214+
supported CPU SIMD flags: {'avx512': True, 'avx2': True, 'avx': True, 'sse4_2': True}
218215
219-
Found 1 NVIDIA GPU(s):
220-
1x NVIDIA GeForce RTX 3080: sm_86
216+
Found 1 NVIDIA GPU(s): [sm_86]
221217
222218
Possible -DPLSSVM_TARGET_PLATFORMS entries:
223219
cpu:avx512;nvidia:sm_86
@@ -231,13 +227,11 @@ or with the `--quiet` flag provided:
231227
python3 utility_scripts/plssvm_target_platforms.py --quiet
232228
```
233229
```
234-
cpu:avx512;intel:dg1
230+
cpu:avx512;nvidia:sm_86
235231
```
236232

237233
If the architectural information for the requested GPU could not be retrieved, one option would be to have a look at:
238234

239-
- for NVIDIA GPUs: [Your GPU Compute Capability](https://developer.nvidia.com/cuda-gpus)
240-
- for AMD GPUs: [clang AMDGPU backend usage](https://llvm.org/docs/AMDGPUUsage.html)
241235
- for Intel GPUs and CPUs: [Ahead of Time Compilation](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compilation/ahead-of-time-compilation.html) and [Intel graphics processor table](https://dgpu-docs.intel.com/devices/hardware-table.html)
242236

243237

@@ -498,6 +492,8 @@ The documentation of the current state of the main branch can be found [here](ht
498492

499493
### Installing
500494

495+
#### Install via CMake
496+
501497
The library supports the `install` target:
502498

503499
```bash
@@ -515,6 +511,48 @@ export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64
515511
export CPLUS_INCLUDE_PATH=${CMAKE_INSTALL_PREFIX}/include:${CPLUS_INCLUDE_PATH}
516512
```
517513

514+
If our library was built with the Python bindings enabled, the `PYTHONPATH` must additionally be set:
515+
516+
```bash
517+
export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:${PYTHONPATH}
518+
```
519+
520+
#### Install via pip
521+
522+
We also support a pip packages that can be used to install our library:
523+
524+
```bash
525+
pip install plssvm
526+
```
527+
528+
This pip install behaves **as if** the CMake `all_python` preset is used.
529+
This means that the `PLSSVM_TARGET_PLATFORMS` are automatically determined and PLSSVM is build with all supported
530+
backends that available on the target machine at the point of the `pip install plssvm` invocation.
531+
To check the installation, including, e.g., the installed backends, we provide the `plssvm-install-check` command after
532+
PLSSVM has been installed via pip.
533+
An example output of this command can look like:
534+
535+
```text
536+
PLSSVM - Parallel Least Squares Support Vector Machine (3.0.0)
537+
538+
Copyright(C) 2018-today The PLSSVM project - All Rights Reserved
539+
This is free software distributed under the MIT license.
540+
541+
Available target platforms: TargetPlatform.AUTOMATIC, TargetPlatform.GPU_NVIDIA, TargetPlatform.CPU
542+
Default target platform: TargetPlatform.GPU_NVIDIA
543+
544+
Available backends: BackendType.AUTOMATIC, BackendType.OPENMP, BackendType.CUDA, BackendType.OPENCL, BackendType.SYCL
545+
Default backend for target platform TargetPlatform.GPU_NVIDIA: BackendType.CUDA
546+
Default backend for target platform TargetPlatform.CPU: BackendType.SYCL
547+
548+
Available SYCL implementations: ImplementationType.AUTOMATIC, ImplementationType.ADAPTIVECPP
549+
550+
551+
Repository: https://github.com/SC-SGS/PLSSVM.git
552+
Documentation: https://sc-sgs.github.io/PLSSVM
553+
Issues: https://github.com/SC-SGS/PLSSVM/issues
554+
```
555+
518556
## Usage
519557

520558
PLSSVM provides three executables: `plssvm-train`, `plssvm-predict`, and `plssvm-scale`.
@@ -963,7 +1001,7 @@ weighted avg 0.91 0.91 0.91 569
9631001
Score: 91.39%
9641002
```
9651003
<p align="center">
966-
<img alt="Example classification task breast cancer decision boundary output." src=".figures/classification_example.png" width="80%">
1004+
<img alt="Example classification task breast cancer decision boundary output." src="https://github.com/SC-SGS/PLSSVM/raw/regression/.figures/classification_example.png" width="80%">
9671005
</p>
9681006

9691007
A regression example comparing PLSSVM's `SVR` Python binding and `sklearn.SVR` using a sine curve:
@@ -1030,15 +1068,9 @@ plt.show()
10301068
```
10311069
with an example output:
10321070
<p align="center">
1033-
<img alt="Example regression output using a sine curve." src=".figures/regression_example.png" width="80%">
1071+
<img alt="Example regression output using a sine curve." src="https://github.com/SC-SGS/PLSSVM/raw/regression/.figures/regression_example.png" width="80%">
10341072
</p>
10351073

1036-
**Note:** it may be necessary to set the environment variable `PYTHONPATH` to the `lib` folder in the PLSSVM install path.
1037-
1038-
```bash
1039-
export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:${PYTHONPATH}
1040-
```
1041-
10421074
Note that currently not all sklearn `SVC` and `SVR` functionality has been implemented in PLSSVM.
10431075
The respective functions will throw a Python `AttributeError` if called.
10441076
For a detailed overview of the functions that are currently implemented, see [our API documentation](bindings/Python/README.md).

bindings/Python/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,13 @@ target_compile_options(${PLSSVM_BASE_LIBRARY_NAME} PUBLIC -fPIC)
124124

125125
# append pybind11 bindings library to installed targets
126126
append_local_and_parent(PLSSVM_TARGETS_TO_INSTALL ${PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME})
127+
128+
# install the __init__.py file so Python recognizes the package when installed via pip
129+
# install the __cli__.py file so the PLSSVM executables can be used when installed via pip
130+
# install the __install_check__.py file creating a new executable plssvm-install-check outputting some information when installed via pip
131+
include(GNUInstallDirs)
132+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py"
133+
"${CMAKE_CURRENT_SOURCE_DIR}/__cli__.py"
134+
"${CMAKE_CURRENT_SOURCE_DIR}/__install_check__.py"
135+
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
136+
)

bindings/Python/__cli__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
import subprocess
3+
from pathlib import Path
4+
5+
6+
# support for plssvm-train including command line arguments
7+
def train():
8+
exe_path = Path(__file__).parent / "plssvm-train"
9+
subprocess.run([str(exe_path)] + sys.argv[1:])
10+
11+
12+
# support for plssvm-predict including command line arguments
13+
def predict():
14+
exe_path = Path(__file__).parent / "plssvm-predict"
15+
subprocess.run([str(exe_path)] + sys.argv[1:])
16+
17+
18+
# support for plssvm-scale including command line arguments
19+
def scale():
20+
exe_path = Path(__file__).parent / "plssvm-scale"
21+
subprocess.run([str(exe_path)] + sys.argv[1:])

bindings/Python/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# import all bindings from the compiled PLSSVM module
2+
from .plssvm import *
3+
4+
# explicitly set the module level attributes
5+
__doc__ = plssvm.__doc__
6+
__version__ = plssvm.__version__
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import plssvm
2+
3+
# print information regarding the current installation after an installation via pip
4+
def check():
5+
print("{} ({})".format(plssvm.__doc__, plssvm.__version__))
6+
print()
7+
8+
print("Copyright(C) 2018-today The PLSSVM project - All Rights Reserved")
9+
print("This is free software distributed under the MIT license.")
10+
print()
11+
12+
print("Available target platforms: {}".format(', '.join(str(target) for target in plssvm.list_available_target_platforms())))
13+
print("Default target platform: {}\n".format(str(plssvm.determine_default_target_platform())))
14+
15+
print("Available backends: {}".format(', '.join(str(backend) for backend in plssvm.list_available_backends())))
16+
for target in plssvm.list_available_target_platforms():
17+
if target == plssvm.TargetPlatform.AUTOMATIC:
18+
continue
19+
try:
20+
backend = plssvm.determine_default_backend(available_target_platforms=[target])
21+
print("Default backend for target platform {}: {}".format(str(target), str(backend)))
22+
except:
23+
pass
24+
print()
25+
26+
if plssvm.BackendType.SYCL in plssvm.list_available_backends():
27+
print("Available SYCL implementations: {}".format(', '.join(str(impl) for impl in plssvm.sycl.list_available_sycl_implementations())))
28+
print()
29+
30+
print()
31+
print("Repository: https://github.com/SC-SGS/PLSSVM.git")
32+
print("Documentation: https://sc-sgs.github.io/PLSSVM/")
33+
print("Issues: https://github.com/SC-SGS/PLSSVM/issues")

0 commit comments

Comments
 (0)