Repository navigation
configuration mechanism #242
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
Open
Gitubrr
wants to merge
74
commits into
SparseLinearAlgebra:main
Choose a base branch
from
Gitubrr:config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
88c57b4
made lib compare
Gitubrr f6c9ff1
added more comparison points
Gitubrr 7419e16
added list of dependences
Gitubrr 21279b0
CI -> +
Gitubrr e2a2ad1
Just formatting changes to README
Gitubrr 2ed3b03
added config params info
Gitubrr fc33885
added config structure
Gitubrr d680949
formatting only
Gitubrr de27aa7
added performance parameter
Gitubrr e0c9b47
formatting only
Gitubrr 0b8ca49
formatting
Gitubrr b880e9e
added 2 libs, removed 'Пакетные менеджеры'
Gitubrr e0c730b
added SPLA usage scenarios
Gitubrr b5b7580
making defolt scenario
Gitubrr af09acd
added 1 question about errors
Gitubrr 627b027
added new scenaries
Gitubrr c1b7f2d
added manual
Gitubrr 8c9ddff
Fixed the incorrect format name in 1 example in CONFIGURATION FALE se…
Gitubrr c90f185
add parsers
Gitubrr 82028eb
fixed formatting errors
Gitubrr 464aaa0
changed cli parser, file parser, made validate
Gitubrr f8cea29
changed init
Gitubrr 0af1432
made apply() and started changing cl_accelerator.cpp,.hpp + added num…
Gitubrr 73045f1
removed apply(), changed init() -> init(conf)
Gitubrr a28e55e
for formatter only
Gitubrr 8e333d8
add configuration mechanism
Gitubrr c9b84f3
made UserManual and UserGuide
Gitubrr 3e87443
unnecessary changes
Gitubrr aa11385
fixed
Gitubrr 60ecdff
for formatter and ubuntu build
Gitubrr 53fb6c4
changed make file
Gitubrr 5aa6e52
changed deps in make file
Gitubrr 54b10b1
! grep -qE \[ FAILED \]
Gitubrr 24dcab7
CL_TARGET_OPENCL_VERSION=300
Gitubrr 2291458
made verbosity
Gitubrr 3082114
added MIT license back
Gitubrr 0b14b37
add MIT license to cl_configure
Gitubrr 48613f8
made new user guide
Gitubrr ac5f337
chanjed config structure
Gitubrr 60f09aa
added new params to cnfig
Gitubrr 7586978
fixed build err
Gitubrr ec9897a
CL_TARGET_OPENCL_VERSION=300 -> 120 back
Gitubrr 788e7b4
fixed CL_HPP_MINIMUM_OPENCL_VERSION
Gitubrr b895cd9
for deps
Gitubrr 3e7f817
for formatter
Gitubrr 17ec47a
removed base from UserGuide
Gitubrr 73a39f6
removed "configs" and "current_config"
Gitubrr 103f80e
added about how to run with user conf
Gitubrr 4f9309f
fixed ci scenar
Gitubrr e6a8c45
Запуск с -> Запуск ci с
Gitubrr 0dc7fba
added new configuration func
Gitubrr ae1209d
removed comment
Gitubrr 2b2448e
fix for windows
Gitubrr 66f1a3a
deleted and renamed files
Gitubrr 14c6bf1
cl_config_status.hpp -> config_status.hpp
Gitubrr e31094b
chanjed ci back
Gitubrr 0a82109
chanjed lang to english
Gitubrr 6042947
chacged logs
Gitubrr c190a0c
chacged logic
Gitubrr 7edb644
fixed sources
Gitubrr 010b864
win error
Gitubrr 3a3277c
removed unnecessary
Gitubrr 7461633
for clang
Gitubrr bbb1b6f
fixed docs
Gitubrr bfa3d4b
fixed softcheck
Gitubrr 7c1b83c
traceback
Gitubrr b0ecfa0
simplifyed configure
Gitubrr d15257b
removed accelerator status
Gitubrr 8cc1cac
format
Gitubrr dd0d04d
removed unnecessary from bridge
Gitubrr 7772bc5
for traceback
Gitubrr f4be1dd
format
Gitubrr 6c47e3b
cmake
Gitubrr 006d90c
added opencl_cpu
Gitubrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,22 @@ | ||
| cmake_minimum_required(VERSION 3.15 FATAL_ERROR) | ||
| project(spla LANGUAGES CXX) | ||
|
|
||
| ###################################################################### | ||
| ## Package version | ||
| ## python/VERSION.md is the single source of truth for the version: | ||
| ## python/setup.py reads it for the PyPI package and the C++ library | ||
| ## gets it as the SPLA_VERSION compile definition. | ||
|
|
||
| file(READ "${CMAKE_CURRENT_LIST_DIR}/python/VERSION.md" SPLA_VERSION_RAW) | ||
| string(STRIP "${SPLA_VERSION_RAW}" SPLA_VERSION) | ||
| message(STATUS "SPLA package version: ${SPLA_VERSION}") | ||
|
|
||
| ###################################################################### | ||
| ## public options | ||
|
|
||
| option(SPLA_BUILD_TESTS "Build test folder with modules tests" YES) | ||
| option(SPLA_BUILD_EXAMPLES "Build library example applications with algorithms" YES) | ||
| set(SPLA_BUILD_TOOLS YES) | ||
| option(SPLA_BUILD_OPENCL "Build library with opencl backend" YES) | ||
|
|
||
| ###################################################################### | ||
|
|
@@ -178,6 +189,22 @@ endfunction() | |
| add_subdirectory(deps/robin_hood) | ||
| add_subdirectory(deps/svector) | ||
|
|
||
| message(STATUS "Add CLI11 as CLI/ENV parser") | ||
| include(FetchContent) | ||
|
|
||
| FetchContent_Declare(CLI11 | ||
| GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git | ||
| GIT_TAG v2.4.2 | ||
| ) | ||
| FetchContent_MakeAvailable(CLI11) | ||
|
|
||
| message(STATUS "Add nlohmann/json as JSON parser") | ||
| FetchContent_Declare(nlohmann_json | ||
| GIT_REPOSITORY https://github.com/nlohmann/json.git | ||
| GIT_TAG v3.11.3 | ||
| ) | ||
| FetchContent_MakeAvailable(nlohmann_json) | ||
|
|
||
| if (SPLA_BUILD_OPENCL) | ||
| if (SPLA_TARGET_MACOSX) | ||
| message(STATUS "Add standard Apple OpenCL package") | ||
|
|
@@ -200,8 +227,6 @@ if (SPLA_BUILD_OPENCL) | |
| set(OPENCL_ICD_LOADER_BUILD_TESTING OFF CACHE BOOL "" FORCE) | ||
| add_subdirectory(deps/opencl-icd-loader) | ||
| endif () | ||
|
|
||
|
|
||
| message(STATUS "Add Khronos OpenCL HPP bindings") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It made to prevent linking against the Apple framework on Linux/Windows |
||
| add_library(HeadersCpp INTERFACE) | ||
| add_library(OpenCL::HeadersCpp ALIAS HeadersCpp) | ||
|
|
@@ -297,6 +322,9 @@ add_library(spla SHARED | |
| include/spla/vector.hpp | ||
| src/core/accelerator.hpp | ||
| src/core/common.hpp | ||
| src/core/config_status.hpp | ||
| src/core/configure.cpp | ||
| src/core/configure.hpp | ||
| src/core/dispatcher.cpp | ||
| src/core/dispatcher.hpp | ||
| src/core/logger.cpp | ||
|
|
@@ -368,9 +396,13 @@ target_include_directories(spla PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src) | |
|
|
||
| set_target_properties(spla PROPERTIES OUTPUT_NAME "spla_${SPLA_ARCH}") | ||
| target_compile_definitions(spla PRIVATE SPLA_EXPORTS) | ||
| target_compile_definitions(spla PRIVATE SPLA_VERSION="${SPLA_VERSION}") | ||
|
|
||
| target_link_libraries(spla PRIVATE robin_hood) | ||
| target_link_libraries(spla PRIVATE svector) | ||
| target_link_libraries(spla PRIVATE CLI11::CLI11) | ||
| target_link_libraries(spla PRIVATE nlohmann_json::nlohmann_json) | ||
| target_link_libraries(spla PRIVATE ${CMAKE_DL_LIBS}) | ||
|
|
||
| if (SPLA_BUILD_OPENCL) | ||
| target_link_libraries(spla PUBLIC OpenCL) | ||
|
|
@@ -383,6 +415,13 @@ spla_target_compile_definitions(spla) | |
| spla_target_compile_options(spla) | ||
| spla_target_link_options(spla) | ||
|
|
||
| set(SPLA_CONF_SRC "${CMAKE_CURRENT_LIST_DIR}/python/pyspla/spla_conf.json") | ||
| set(SPLA_CONF_DST "${CMAKE_BINARY_DIR}/spla_conf.json") | ||
| add_custom_command(TARGET spla POST_BUILD | ||
| COMMAND "${CMAKE_COMMAND}" -E copy_if_different | ||
| "${SPLA_CONF_SRC}" "${SPLA_CONF_DST}" | ||
| COMMENT "Copying shipped configuration file spla_conf.json next to the library") | ||
|
|
||
| ###################################################################### | ||
| ## Add examples directory | ||
|
|
||
|
|
@@ -404,6 +443,18 @@ if (SPLA_BUILD_EXAMPLES) | |
| spla_example_application(convert) | ||
| endif () | ||
|
|
||
| ###################################################################### | ||
| ## Add command line tools | ||
|
|
||
| if (SPLA_BUILD_TOOLS) | ||
| message(STATUS "Add command line tools to build") | ||
|
|
||
| add_executable(spla_cli tools/soft_check.cpp) | ||
| target_link_libraries(spla_cli PRIVATE spla) | ||
| target_link_libraries(spla_cli PRIVATE CLI11::CLI11) | ||
| set_target_properties(spla_cli PROPERTIES OUTPUT_NAME spla) | ||
| endif () | ||
|
|
||
| ###################################################################### | ||
| ## Add unit-tests directory | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,258 @@ | ||
| # User Guide | ||
|
gsvgit marked this conversation as resolved.
Resolved
|
||
|
|
||
| The user guide for the spla library. Contains usage scenarios for the configuration mechanism: from a quick start without configuration to running tests in CI. The complete reference of all parameters, flags and environment variables is given in the [User Manual](UserManual.md). | ||
|
|
||
| ## Contents | ||
|
|
||
| 1. [Environment check](#environment-check) | ||
| 2. [Scenario 1. Quick start without configuration](#scenario-1-quick-start-without-configuration) | ||
| 3. [Scenario 2. Choosing between CPU and GPU without specifying indexes](#scenario-2-choosing-between-cpu-and-gpu-without-specifying-indexes) | ||
| 4. [Scenario 3. Multiple devices and modes in one file](#scenario-3-multiple-devices-and-modes-in-one-file) | ||
| 5. [Scenario 4. Running in CI with a file from the repository](#scenario-4-running-in-ci-with-a-file-from-the-repository) | ||
| 6. [Priority of configuration sources](#priority-of-configuration-sources) | ||
| 7. [Where the configuration files are located](#where-the-configuration-files-are-located) | ||
|
|
||
| ## Environment check | ||
|
|
||
| After installation, run the command that confirms the library is ready to use: | ||
|
|
||
| ```bash | ||
| ./program spla --softcheck | ||
| ``` | ||
|
|
||
| The command: | ||
|
|
||
| 1. Reads the configuration file shipped with the library. | ||
| 2. Initializes OpenCL, selects the platform and device. | ||
| 3. Runs a simple test task `2 + 3`. | ||
| 4. Reports the status. | ||
|
|
||
| Example of successful output: | ||
|
|
||
| ```bash | ||
| $ s./program spla --softcheck | ||
| [spla:check] Starting sanity check... | ||
| [spla:check] Initializing OpenCL... | ||
| [spla:check] Selected accelerator: OpenCL NVIDIA CUDA | device: NVIDIA GeForce RTX 3070 Laptop GPU | vendor: nvidia | mcu: 40 | wave: 32 | mwgs: 1024 | ||
| [spla:check] Running test task: 2 + 3 = ... | ||
| [spla:check] Result: 5 (expected 5) | ||
| [spla:check] SUCCESS - spla works correctly | ||
| ``` | ||
|
|
||
| ## Scenario 1. Quick start without configuration | ||
|
|
||
| You want a working application without configuration - nothing needs to be configured. The library uses the default parameters from the configuration file shipped with the library. | ||
|
|
||
| ```bash | ||
| ./program | ||
| ``` | ||
|
|
||
| The scenario works the same on Linux, macOS and Windows. If OpenCL acceleration is unavailable, the library automatically switches to the pure native CPU by default (the `if_opencl_unavailable: "use_cpu"` parameter), reporting it. | ||
|
|
||
| Before the first run it is recommended to run [`spla --softcheck`](#environment-check) to make sure that everything required for spla is installed. | ||
|
|
||
| ## Scenario 2. Choosing between CPU and GPU without specifying indexes | ||
|
|
||
| You want to control the device type, but not specify concrete OpenCL platform and device indexes. | ||
|
|
||
| The device type is set by the `backend` parameter in the configuration file: | ||
|
|
||
| ```json | ||
| { | ||
| "gpu_only": { "backend": "opencl_gpu" }, | ||
| "cpu_only": { "backend": "cpu" } | ||
| } | ||
| ``` | ||
|
|
||
| - `"opencl_gpu"` - use the first available OpenCL GPU, | ||
| - `"cpu"` - use the pure native CPU without touching OpenCL. | ||
|
|
||
| The `platform_index` and `device_index` indexes are ignored with these values. | ||
|
|
||
| ### Behavior when OpenCL is unavailable | ||
|
|
||
| If `backend: "opencl_gpu"` is selected, but no OpenCL GPU is available, the behavior is defined by the `if_opencl_unavailable` parameter: | ||
|
|
||
| ```json | ||
| { | ||
| "gpu_or_cpu": { | ||
| "backend": "opencl_gpu", | ||
| "if_opencl_unavailable": "use_cpu" | ||
| }, | ||
| "gpu_only": { | ||
| "backend": "opencl_gpu", | ||
| "if_opencl_unavailable": "abort" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| - `"use_cpu"` - the library switches to the pure native CPU and continues working, | ||
| - `"abort"` - the library fails initialization and the process exits with the error status. | ||
|
|
||
| Running the required configuration: | ||
|
|
||
| ```bash | ||
| ./program --spla-config=gpu_or_cpu | ||
| ./program --spla-config=gpu_only | ||
| ``` | ||
|
|
||
| `if_opencl_unavailable` is applied with `backend: "opencl_gpu"` and `"by_index"`. With `backend: "cpu"` the parameter is ignored. | ||
|
|
||
| ## Scenario 3. Multiple devices and modes in one file | ||
|
|
||
| You regularly run the same program on different GPUs and in different modes - for example, on GPU 0 and 1, in debug mode and in performance measurement mode. Instead of several configuration files, you describe everything in one. | ||
|
|
||
| ```json | ||
| { | ||
| "default": { "backend": "opencl_gpu", "verbosity": 2 }, | ||
|
|
||
| "gpu0": { | ||
| "extends": ["default"], | ||
| "backend": "by_index", | ||
| "platform_index": 0, | ||
| "device_index": 0 | ||
| }, | ||
| "gpu1": { | ||
| "extends": ["default"], | ||
| "backend": "by_index", | ||
| "platform_index": 0, | ||
| "device_index": 1 | ||
| }, | ||
|
|
||
| "debug": { | ||
| "extends": ["default"], | ||
| "verbosity": 3, | ||
| "profiling": true | ||
| }, | ||
| "bench": { | ||
| "extends": ["default"], | ||
| "verbosity": 0 | ||
| }, | ||
|
|
||
| "debug_gpu1": { "extends": ["debug", "gpu1"] }, | ||
| "bench_gpu0": { "extends": ["bench", "gpu0"] } | ||
| } | ||
| ``` | ||
|
|
||
| Running: | ||
|
|
||
| ```bash | ||
| ./program --spla-config=gpu1 | ||
| ./program --spla-config=debug | ||
| ./program --spla-config=debug_gpu1 | ||
| ./program --spla-config=bench_gpu0 | ||
| ``` | ||
|
|
||
| Configurations inherited through `extends` are applied in order: each next parent overrides the previous one, and the parameters of the configuration itself override all parents. Circular inheritance is detected and results in an error. | ||
|
|
||
| ## Scenario 4. Running in CI with a file from the repository | ||
|
|
||
| You need to run tests in CI with a separate configuration file. | ||
|
|
||
| In a CI environment it is inconvenient and undesirable to touch the system and user configuration files, and the test configurations must live in the repository. Therefore the configurations are described in a separate file inside the repository and its path is given at launch together with the configuration name - these are the command line arguments `--spla-config-file` and `--spla-config`. | ||
|
|
||
| ``` | ||
| my_project/ | ||
| ├── .github/ | ||
| │ └── workflows/ | ||
| │ ├── ci.yml | ||
| │ └── ci_spla_conf.json | ||
| ├── src/ | ||
| └── tests/ | ||
| ``` | ||
|
|
||
| ### ci_spla_conf.json | ||
|
|
||
| ```json | ||
| { | ||
| "test_cpu": { | ||
| "backend": "cpu", | ||
| "queues_count": 1, | ||
| "profiling": false, | ||
| "allocator_type": "general", | ||
| "verbosity": 1 | ||
| }, | ||
| "test_gpu0": { | ||
| "backend": "by_index", | ||
| "platform_index": 0, | ||
| "device_index": 0, | ||
| "if_opencl_unavailable": "abort", | ||
| "queues_count": 2, | ||
| "profiling": false, | ||
| "allocator_type": "general", | ||
| "verbosity": 0 | ||
| }, | ||
| "test_gpu1": { | ||
| "backend": "by_index", | ||
| "platform_index": 0, | ||
| "device_index": 1, | ||
| "if_opencl_unavailable": "abort", | ||
| "queues_count": 2, | ||
| "profiling": false, | ||
| "allocator_type": "linear", | ||
| "linear_alloc_size": 8, | ||
| "verbosity": 0 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### ci.yml | ||
|
|
||
| ```yml | ||
| name: CI | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Test (${{ matrix.config }}) | ||
| runs-on: [self-hosted, gpu] | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| config: [test_cpu, test_gpu0, test_gpu1] | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install pyspla pytest | ||
|
|
||
| - name: Run tests | ||
| run: python src/my_app.py --spla-config-file=.github/workflows/ci_spla_conf.json --spla-config=${{ matrix.config }} | ||
| ``` | ||
|
|
||
| The file path and the configuration name are passed at launch as command arguments, not through environment variables - in CI this makes the launch command self-contained and reproducible. | ||
|
|
||
| ## Priority of configuration sources | ||
|
|
||
| Sources are applied in descending priority order: parameters from a higher-priority source override lower-priority ones. This matters for the scenarios: any flag or environment variable overrides values from files. | ||
|
|
||
| | # | Source | | ||
| |---:|:---| | ||
| | 1 | Command line arguments (`--spla-*`) | | ||
| | 2 | Environment variables (`SPLA_*`) | | ||
| | 3 | File with an explicitly specified path (`--spla-config-file`) | | ||
| | 4 | User configuration file | | ||
| | 5 | System configuration file | | ||
| | 6 | Configuration file shipped with the library | | ||
|
|
||
| If the configuration name is not specified, the `"default"` configuration from the file shipped with the library is used. For details on the collection order and merging of sources, see the [User Manual](UserManual.md#configuration-mechanism-overview). | ||
|
|
||
| ## Where the configuration files are located | ||
|
|
||
| - **Shipped with the library** - next to the library file (in the pyspla package - inside the installed package). | ||
| - **System** - Linux: `/etc/spla/spla_conf.json`. | ||
| - **User** - Linux: `~/.config/spla/spla_conf.json`. | ||
| - **Explicit** - any path via `--spla-config-file`. | ||
|
|
||
| Paths for macOS and Windows and the rules for "file missing / file cannot be opened" are in the [User Manual](UserManual.md#configuration-files). | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these changes required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My code requirs newer OpenCL headers. Apple removed them from macOS SDKs, so find_package fails. I bundle Khronos headers to build new code, while linking the system framework for macOS compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code? Your code just configure existing library. Why it requires newer OpenCL?