diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6f89a50..dd3cac6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,6 @@ jobs: uses: mxschmitt/action-tmate@v3.13 if: ${{ inputs.debug_enabled }} - name: Setup conda environment - id: setup_conda uses: conda-incubator/setup-miniconda@v2 with: activate-environment: libnomp @@ -46,9 +45,13 @@ jobs: id: cache with: path: ${{ env.NOMP_CONDA_ENV }} - key: conda-${{ runner.os }}-${{ hashFiles('environment.yml') }}-${{ hashFiles('requirements.txt') }}-${{ env.NOMP_CACHE_NUMBER }} + key: >- + conda- + ${{ runner.os }}- + ${{ hashFiles('environment.yml') }}- + ${{ hashFiles('requirements.txt') }}- + ${{ env.NOMP_CACHE_NUMBER }} - name: Update conda environment - id: update_env run: | conda env update -n libnomp -f environment.yml if: steps.cache.outputs.cache-hit != 'true' @@ -58,21 +61,16 @@ jobs: path: ${{ env.NOMP_CONDA_ENV }}/lib/pocl key: ${{ runner.os }}-build-pocl-${{ env.POCL_CACHE_NUMBER }} - name: Install pocl - id: install_pocl run: | conda install -c conda-forge pocl - if: (steps.pocl_cache.outputs.cache-hit != 'true') || (steps.cache.outputs.cache-hit != 'true') + if: >- + steps.pocl_cache.outputs.cache-hit != 'true' || + steps.cache.outputs.cache-hit != 'true' - name: Build libnomp - id: build_libnomp run: | - ./lncfg --cc ${CC} \ - --install-prefix ${NOMP_INSTALL_DIR} \ - --prefix-path ${CONDA_PREFIX} \ - --enable-opencl --opencl-lib ${CONDA_PREFIX}/lib/libOpenCL.so \ + ./bin/lnbld --enable-opencl --opencl-lib ${CONDA_PREFIX}/lib/libOpenCL.so \ --enable-tests - ./lnbuild --install - name: Run libnomp tests - id: run_libnomp run: | ${NOMP_INSTALL_DIR}/bin/lnrun --test backend=opencl - name: Block to allow inspecting failures diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b67c7f76..6193626e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -40,7 +40,13 @@ jobs: uses: actions/cache@v3 with: path: ${{ env.NOMP_CONDA_ENV }} - key: conda-${{ runner.os }}-${{ hashFiles('environment-dev.yml') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-dev.txt') }}-${{ env.NOMP_CACHE_NUMBER }} + key: >- + conda- + ${{ runner.os }}- + ${{ hashFiles('environment-dev.yml') }}- + ${{ hashFiles('requirements.txt') }}- + ${{ hashFiles('requirements-dev.txt') }}- + ${{ env.NOMP_CACHE_NUMBER }} id: cache - name: Update conda environment id: update_env @@ -50,8 +56,8 @@ jobs: - name: Build documentation id: build_docs run: | - ./lncfg --install-prefix ${NOMP_INSTALL_DIR} --prefix-path ${CONDA_PREFIX} --enable-docs - ./lnbuild --install --update-shell + ./bin/lnbld --install-dir ${NOMP_INSTALL_DIR} --enable-docs \ + -DCMAKE_PREFIX_PATH=${CONDA_PREFIX} - name: Bypass Jekyll id: bypass_jekyll if: ${{ fromJSON(env.PUSH_ON_MAIN) }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a6f39ef3..31e6c2d9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,7 +28,6 @@ jobs: uses: mxschmitt/action-tmate@v3.13 if: ${{ inputs.debug_enabled }} - name: Setup conda environment - id: setup_conda uses: conda-incubator/setup-miniconda@v2 with: activate-environment: libnomp-dev @@ -37,35 +36,18 @@ jobs: uses: actions/cache@v3 with: path: ${{ env.NOMP_CONDA_ENV }} - key: conda-${{ runner.os }}-${{ hashFiles('environment-dev.yml') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements-dev.txt') }}-${{ env.NOMP_CACHE_NUMBER }} + key: >- + conda- + ${{ runner.os }}- + ${{ hashFiles('environment-dev.yml') }}- + ${{ hashFiles('requirements.txt') }}- + ${{ hashFiles('requirements-dev.txt') }}- + ${{ env.NOMP_CACHE_NUMBER }} id: cache - name: Update conda environment - id: update_env run: | conda env update -n libnomp-dev -f environment-dev.yml if: steps.cache.outputs.cache-hit != 'true' - - name: Run clang-format check + - name: Check formatting run: | - ./lncfg --install-prefix ${NOMP_INSTALL_DIR} --prefix-path ${CONDA_PREFIX} - ./lnbuild --format-check - - name: Run clang-tidy check - run: | - ./lncfg --install-prefix ${NOMP_INSTALL_DIR} --prefix-path ${CONDA_PREFIX} - # FIXME: Skipping the clang-tidy checks for now. - # ./lnbuild --tidy-check - - name: Run pylint check - run: | - ./lncfg --install-prefix ${NOMP_INSTALL_DIR} --prefix-path ${CONDA_PREFIX} - ./lnbuild --pylint-check - - name: Run black check - run: | - ./lncfg --install-prefix ${NOMP_INSTALL_DIR} --prefix-path ${CONDA_PREFIX} - ./lnbuild --black-check - - name: Run isort check - run: | - ./lncfg --install-prefix ${NOMP_INSTALL_DIR} --prefix-path ${CONDA_PREFIX} - ./lnbuild --isort-check - - name: Run flake8 check - run: | - ./lncfg --install-prefix ${NOMP_INSTALL_DIR} --prefix-path ${CONDA_PREFIX} - ./lnbuild --flake8-check + ./bin/lnchk --chk-fmt diff --git a/CMakeLists.txt b/CMakeLists.txt index 988647ac..87db0d76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,8 +39,7 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") # outside the build tree to the install RPATH set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -set(SOURCES src/nomp.c src/loopy.c src/symengine.c src/aux.c src/log.c - src/reduction.c) +set(SOURCES src/nomp.c src/loopy.c src/symengine.c src/aux.c src/log.c src/reduction.c) if (ENABLE_OPENCL) find_package(OpenCL REQUIRED) if (OpenCL_FOUND) @@ -117,68 +116,11 @@ if (ENABLE_TESTS) add_subdirectory(tests) endif() -# Add clang-format as a custom target if available. -find_program(CLANG_FORMAT NAMES clang-format) -if (CLANG_FORMAT) - add_custom_target(format - COMMAND ${CLANG_FORMAT} -i ${CMAKE_SOURCE_DIR}/*/*.[ch] - COMMENT "Running clang-format ...") - add_custom_target(format-check - COMMAND ${CLANG_FORMAT} --dry-run --Werror -i ${CMAKE_SOURCE_DIR}/*/*.[ch] - COMMENT "Running clang-format check ...") -endif() - -# Add clang-tidy as a custom target if available. -find_program(CLANG_TIDY NAMES clang-tidy) -if (CLANG_TIDY) - add_custom_target(tidy - COMMAND ${CLANG_TIDY} -p ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/*/*.[ch] - COMMENT "Running clang-tidy ...") -endif() - -# Add pylint as a custom target if available. -find_program(PYLINT NAMES pylint) -if (PYLINT) - add_custom_target(pylint - COMMAND ${PYLINT} ${CMAKE_SOURCE_DIR} --recursive yes --rcfile=${CMAKE_SOURCE_DIR}/pyproject.toml - COMMENT "Running pylint ...") -endif() - -# Add black as a custom target if available. -find_program(BLACK NAMES black) -if (BLACK) - add_custom_target(black - COMMAND ${BLACK} ${CMAKE_CURRENT_SOURCE_DIR}/ - COMMENT "Running black ...") - add_custom_target(black-check - COMMAND ${BLACK} --check ${CMAKE_CURRENT_SOURCE_DIR}/ - COMMENT "Running black check ...") -endif() - -# Add isort as a custom target if available. -find_program(ISORT NAMES isort) -if (ISORT) - add_custom_target(isort - COMMAND ${ISORT} ${CMAKE_CURRENT_SOURCE_DIR}/ - COMMENT "Running isort ...") - add_custom_target(isort-check - COMMAND ${ISORT} --check-only ${CMAKE_CURRENT_SOURCE_DIR}/ - COMMENT "Running isort check ...") -endif() - -# Add flake8 as a custom target if available. -find_program(FLAKE8 NAMES flake8) -if (FLAKE8) - add_custom_target(flake8 - COMMAND ${FLAKE8} ${CMAKE_CURRENT_SOURCE_DIR}/ - COMMENT "Running flake8 ...") -endif() - install(TARGETS nomp LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include) install(DIRECTORY ${CMAKE_SOURCE_DIR}/python DESTINATION ${CMAKE_INSTALL_PREFIX}) -install(DIRECTORY scripts/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin +install(DIRECTORY bin/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/bin/lnbld b/bin/lnbld new file mode 100755 index 00000000..f6ade6e0 --- /dev/null +++ b/bin/lnbld @@ -0,0 +1,82 @@ +#!/bin/bash + +# Check for nomp environment variables. +: ${NOMP_BUILD_DIR:=${PWD}/build} +: ${NOMP_INSTALL_DIR:=${PWD}/install} +: ${NOMP_TARGET:=install} +: ${NOMP_ENABLE_OPENCL:="OFF"} +: ${NOMP_OPENCL_LIBRARY:=""} +: ${NOMP_OPENCL_INCLUDE_DIR:=""} +: ${NOMP_ENABLE_CUDA:="OFF"} +: ${NOMP_ENABLE_HIP:="OFF"} +: ${NOMP_ENABLE_DOCS:="OFF"} +: ${NOMP_ENABLE_TESTS:="OFF"} +: ${NOMP_ENABLE_ASAN:="OFF"} + +# Terminal output colors. +red=$(tput setaf 1) +green=$(tput setaf 2) +cyan=$(tput setaf 6) +reset=$(tput sgr0) + +# Print the options. +function print_help() { + echo -e "Usage: ${0} [--help] [--build-dir ] " \ + "[--install-dir ] [--target ] " \ + "[--enable-opencl] [--opencl-lib ] " \ + "[--opencl-headers ] [--enable-hip] [--enable-cuda] " \ + "[--enable-docs] [--enable-tests] [--enable-asan]\n\n" \ + "${cyan}--help ${reset}\tPrint this help and exit.\n" \ + "${cyan}--build-dir ${reset}\tBuild directory.\n" \ + "${cyan}--install-dir ${reset}\tInstall directory.\n" \ + "${cyan}--target ${reset}\tCMake target to execute.\n" \ + "${cyan}--enable-opencl ${reset}\tBuild with OpenCL backend" \ + "${cyan}--opencl-lib ${reset}\tOpenCL library path.\n" \ + "${cyan}--opencl-headers${reset}\tOpenCL header path.\n" \ + "${cyan}--enable-hip ${reset}\tBuild with HIP backend\n" \ + "${cyan}--enable-cuda ${reset}\tBuild with CUDA backend\n" \ + "${cyan}--enable-docs ${reset}\tBuild user documentation\n" \ + "${cyan}--enable-tests ${reset}\tBuild libnomp unit tests\n" \ + "${cyan}--enable-asan ${reset}\tBuild with AddressSanitizer" \ + exit 0 +} + +# Parse the options. +USER_OPTS= +while [ $# -gt 0 ]; do + case $1 in + --help) print_help ;; + --build-dir) shift && NOMP_BUILD_DIR=$1 ;; + --install-dir) shift && NOMP_INSTALL_DIR=$1 ;; + --target) shift && NOMP_TARGET=$1 ;; + --enable-opencl) NOMP_ENABLE_OPENCL="ON" ;; + --opencl-lib) shift && NOMP_OPENCL_LIBRARY=$(realpath "$1") ;; + --opencl-headers) shift && NOMP_OPENCL_INCLUDE_DIR=$(realpath "$1") ;; + --enable-hip) NOMP_ENABLE_HIP="ON" ;; + --enable-cuda) NOMP_ENABLE_CUDA="ON" ;; + --enable-docs) NOMP_ENABLE_DOCS="ON" ;; + --enable-tests) NOMP_ENABLE_TESTS="ON" ;; + --enable-asan) NOMP_ENABLE_ASAN="ON" ;; + *) USER_OPTS+=("$1") && shift ;; + esac + shift +done + +# Update the cmake options. +NOMP_CMAKE_OPTS=("-S ${PWD} -B ${NOMP_BUILD_DIR}") +NOMP_CMAKE_OPTS+=("-DCMAKE_INSTALL_PREFIX=${NOMP_INSTALL_DIR}") +NOMP_CMAKE_OPTS+=("-DENABLE_HIP=${NOMP_ENABLE_HIP}") +NOMP_CMAKE_OPTS+=("-DENABLE_CUDA=${NOMP_ENABLE_CUDA}") +NOMP_CMAKE_OPTS+=("-DENABLE_OPENCL=${NOMP_ENABLE_OPENCL}") +[[ -n ${NOMP_OPENCL_LIBRARY} ]] && + NOMP_CMAKE_OPTS+=("-DOpenCL_LIBRARY=${NOMP_OPENCL_LIBRARY}") +[[ -n ${NOMP_OPENCL_INCLUDE_DIR} ]] && + NOMP_CMAKE_OPTS+=("-DOpenCL_INCLUDE_DIR=${NOMP_OPENCL_INCLUDE_DIR}") +NOMP_CMAKE_OPTS+=("-DENABLE_ASAN=${NOMP_ENABLE_ASAN}") +NOMP_CMAKE_OPTS+=("-DENABLE_DOCS=${NOMP_ENABLE_DOCS}") +NOMP_CMAKE_OPTS+=("-DENABLE_TESTS=${NOMP_ENABLE_TESTS}") + +echo "cmake ${NOMP_CMAKE_OPTS[@]} ${USER_OPTS[@]}" +cmake ${NOMP_CMAKE_OPTS[@]} ${USER_OPTS[@]} +echo "cmake --build ${NOMP_BUILD_DIR} --target ${NOMP_TARGET}" +cmake --build ${NOMP_BUILD_DIR} --target ${NOMP_TARGET} diff --git a/bin/lnchk b/bin/lnchk new file mode 100755 index 00000000..c81d3db4 --- /dev/null +++ b/bin/lnchk @@ -0,0 +1,29 @@ +#!/bin/bash +set -e +set -o pipefail + +: ${CLANG_FORMAT:=clang-format} + +############################ +# Don't touch what follows # +############################ +CSRC= + +if ! command -v $CLANG_FORMAT >/dev/null 2>&1; then + echo "Binary $CLANG_FORMAT not found!" + exit 1 +fi + +BINDIR=$(dirname -- "$(realpath -- "${BASH_SOURCE[0]}")") +CSRC=$(find $BINDIR/.. -type f -name "*.[ch]") + +if [[ "$1" == "--fmt" ]]; then + $CLANG_FORMAT -i $CSRC + ruff format . +elif [[ "$1" == "--chk-fmt" ]]; then + $CLANG_FORMAT --dry-run --Werror -i $CSRC + ruff format --check . + ruff check . +else + exit 1 +fi diff --git a/scripts/lnrun b/bin/lnrun similarity index 100% rename from scripts/lnrun rename to bin/lnrun diff --git a/docs/build.rst b/docs/build.rst index d4fa462c..46102ba1 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -40,9 +40,9 @@ Similarly, you can install the dev dependencies with mamba as well: mamba env create -f environment-dev.yml mamba activate libnomp-dev -Use `lncfg` to configure CMake build and `lnbuild` to build/install `libnomp`. To -see the available options, check out `lncfg --help`. `libnomp` currently supports -the following backends: +Use `lnbld` to configure the CMake build and build/install `libnomp` in a single +step. To see the available options, check out `lnbld --help`. `libnomp` +currently supports the following backends: #. OpenCL #. CUDA @@ -54,8 +54,7 @@ commands: .. code-block:: bash cd libnomp - ./lncfg --enable-opencl --install-prefix ${HOME}/.nomp - ./lnbuild + ./bin/lnbld --enable-opencl --install-dir ${HOME}/.nomp `NOMP_INSTALL_DIR` environment variable must be set to `libnomp` install directory or it should be passed as a command line argument using `--nomp-install-dir` during @@ -69,45 +68,38 @@ variable with `NOMP_INSTALL_DIR/bin`. export PATH=${NOMP_INSTALL_DIR}/bin:${PATH} Setting the environment variable and adding `NOMP_INSTALL_DIR/bin` to `PATH` will -enable you to use `lnrun` script without using its full path to open documentation, -run tests, debug tests, etc. You can update the shell configuration file automatically -by passing `--update-shell` to `lnbuild` script. You have to open a new shell in -order for changes to take affect in case you update the shell configuration file. +enable you to use the `lnrun` script without using its full path to open +documentation, run tests, debug tests, etc. -.. code-block:: bash - - cd libnomp - ./lncfg --enable-opencl --install-prefix ${HOME}/.nomp - ./lnbuild --update-shell - -Use `lnbuild --help` to see all the available options supported by `lnbuild` script. +Use `lnbld --help` to see all the available options supported by the `lnbld` +script. You might additionally want to specify OpenCL library path as below if CMake can't find OpenCL: .. code-block:: bash - ./lncfg --enable-opencl --opencl-lib /lib/x86_64-linux-gnu/libOpenCL.so + ./bin/lnbld --enable-opencl --opencl-lib /lib/x86_64-linux-gnu/libOpenCL.so If you used `conda` to install OpenCL (for example `pocl`_), do the following: .. code-block:: bash - ./lncfg --enable-opencl --opencl-lib ${CONDA_PREFIX}/lib/libOpenCL.so --opencl-headers ${CONDA_PREFIX}/include + ./bin/lnbld --enable-opencl --opencl-lib ${CONDA_PREFIX}/lib/libOpenCL.so --opencl-headers ${CONDA_PREFIX}/include Run `libnomp` tests ------------------- -You can run `libnomp` tests by executing `lnrun test` command. See below for -a few examples on how to use the script: +You can run `libnomp` tests by executing the `lnrun --test` command. See below +for a few examples on how to use the script: .. code-block:: bash - lnrun test - lnrun test --backend opencl + lnrun --test + lnrun --test backend=opencl -Use `lnrun help` to see all supported options. +Use `lnrun --help test` to see all supported options. nompcc ------ @@ -166,22 +158,22 @@ Documentation We use `Doxygen` for in source documentations and render those with `Sphinx` and `Breathe`. These packages must be available if you install the dev -dependencies using `conda`. You can enable docs by passing either `-docs` or -`--enable-docs` option to `lncfg` script. +dependencies using `conda`. You can enable docs by passing the `--enable-docs` +option to the `lnbld` script. .. code-block:: bash - ./lncfg --enable-docs - ./lnbuild + ./bin/lnbld --enable-docs -Use `lnrun` to open the user documentation locally. You can specify the browser -with option `--browser`. For example, to open the documentation in firefox: +Use `lnrun --docs` to open the user documentation locally. You can specify the +program used to open the documentation with the `program` option. For example, +to open the documentation in firefox: .. code-block:: bash - lnrun docs --browser firefox + lnrun --docs program=firefox -If you do not specify the browser, it opens the documentation in chrome by +If you do not specify the program, it opens the documentation with `open` by default. diff --git a/docs/developer-docs.rst b/docs/developer-docs.rst index 7d9f2ce3..d76d26b8 100644 --- a/docs/developer-docs.rst +++ b/docs/developer-docs.rst @@ -52,24 +52,21 @@ instead of: Formatting files before committing ---------------------------------- -Run `clang-format` before committing any changes you make on the source files. -`clang-format` will be available if you install the dev dependencies with conda. -Run `clang-format` as follows: +Run `lnchk --fmt` before committing any changes you make to the source files. +This formats all C source files with `clang-format` and all python files with +`ruff`. Both tools will be available if you install the dev dependencies with +conda. .. code-block:: bash - clang-format -i **/*.[ch] + ./bin/lnchk --fmt -If you change any python files, please use `black` and `isort` to format the -python code and then check with `flake8` before committing. `black`, `isort` -and `flake8` will be available if you install the dev dependencies with -conda. +To only check the formatting (and run the `ruff` linter) without modifying any +files, use `lnchk --chk-fmt`. This is the same check that is run in CI. .. code-block:: bash - black . - isort . - flake8 + ./bin/lnchk --chk-fmt Debugging github actions ------------------------ @@ -105,15 +102,15 @@ As a prerequisite you have to install the `gdbserver` which you can install with sudo apt install gdbserver -Use :code:`lnrun debug` command to host the debugging session. If you want to debug the -test case `nomp-api-200`: +Use the :code:`lnrun --debug` command to host the debugging session. If you want +to debug the test case `nomp-api-200`: .. code-block:: bash - lnrun debug api-200 + lnrun --debug api-200 Additionally, you can set the port and the target device for the specific session. -You can view the available options by :code:`lnrun help debug`. +You can view the available options by :code:`lnrun --help debug`. By default the test starts on `localhost:5005`, and a debug viewer should be connected to this target address. For example, the following figure shows how clion connects to diff --git a/lnbuild b/lnbuild deleted file mode 100755 index 7e3c696b..00000000 --- a/lnbuild +++ /dev/null @@ -1,201 +0,0 @@ -#!/bin/bash - -# Script variables. -: "${NOMP_SOURCE_DIR:="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"}" -: "${NOMP_SHELL_CONFIG_FILE:="${HOME}/.bashrc"}" - -# Terminal output colors. -red=$(tput setaf 1) -green=$(tput setaf 2) -cyan=$(tput setaf 6) -reset=$(tput sgr0) - -# Read state variables created by lncfg. -NOMP_LNSTATE_PATH="${NOMP_SOURCE_DIR}/.lnstate" -if [[ -f "${NOMP_LNSTATE_PATH}" ]]; then - source "${NOMP_LNSTATE_PATH}" -else - echo "${red}You should run ./lncfg before running ${0}${reset}." - exit 1 -fi -if [[ -z "${NOMP_INSTALL_DIR}" ]]; then - echo "${red}NOMP_INSTALL_DIR is not set in .lnstate file${reset}." - exit 1 -fi - -# Create commands which goes in shell configuration. -NOMP_ENVIRONMENT=$(cat <<-END -# Setup nomp environment variables. -export NOMP_INSTALL_DIR=${NOMP_INSTALL_DIR} -# Add lnrun script to path. -export PATH=${NOMP_INSTALL_DIR}/bin:\${PATH} -END -) - -# Check if the specified shell configuration file exists. If not, look for -# common config files. -if [[ ! -f "${NOMP_SHELL_CONFIG_FILE}" ]]; then - if [[ -f "${HOME}/.bashrc" ]]; then - NOMP_SHELL_CONFIG_FILE="${HOME}/.bashrc" - elif [[ -f "${HOME}/.zshrc" ]]; then - NOMP_SHELL_CONFIG_FILE="${HOME}/.zshrc" - else - NOMP_SHELL_CONFIG_FILE="" - fi -fi - -function print_help() { - echo -e "Usage: ${0} [options]\n" \ - "${cyan}--help ${reset}\tPrint help for lnbuild script.\n" \ - "${cyan}--install ${reset}\tInstall libnomp.\n" \ - "${cyan}--format ${reset}\tFormat C code using clang-format.\n" \ - "${cyan}--format-check ${reset}\tCheck if C code is formatted correctly.\n" \ - "${cyan}--tidy-check ${reset}\tRun clang-tidy to perform static" \ - "analysis on C source.\n" \ - "${cyan}--black ${reset}\tFormat python code using black.\n" \ - "${cyan}--black-check ${reset}\tCheck if python code is formatted" \ - "correctly.\n" \ - "${cyan}--isort ${reset}\tRun isort to format python imports.\n" \ - "${cyan}--isort-check ${reset}\tCheck if python imports are formatted" \ - "correctly.\n" \ - "${cyan}--flake8-check ${reset}\tRun flake8 tests on python source.\n" \ - "${cyan}--pylint-check ${reset}\tRun pylint to perform static analysis" \ - "on python source.\n" \ - "${cyan}--update-shell ${reset}\tUpdate shell configuration file." -} - -# Read in command line arguments. -: ${NOMP_INSTALL:="no"} -: ${NOMP_FORMAT:="no"} -: ${NOMP_FORMAT_CHECK:="no"} -: ${NOMP_TIDY:="no"} -: ${NOMP_PYLINT:="no"} -: ${NOMP_BLACK:="no"} -: ${NOMP_BLACK_CHECK:="no"} -: ${NOMP_ISORT:="no"} -: ${NOMP_ISORT_CHECK:="no"} -: ${NOMP_FLAKE8:="no"} -: ${NOMP_PROMPT:="no"} - -if [[ $# -eq 0 ]]; then - print_help - exit 1 -fi - -while [[ $# -gt 0 ]]; do - case $1 in - --help) - shift - print_help - exit 0 - ;; - --install) - NOMP_INSTALL="yes" - shift - ;; - --format) - NOMP_FORMAT="yes" - shift - ;; - --format-check) - NOMP_FORMAT_CHECK="yes" - shift - ;; - --tidy-check) - NOMP_TIDY="yes" - shift - ;; - --black) - NOMP_BLACK="yes" - shift - ;; - --black-check) - NOMP_BLACK_CHECK="yes" - shift - ;; - --isort) - NOMP_ISORT="yes" - shift - ;; - --isort-check) - NOMP_ISORT_CHECK="yes" - shift - ;; - --flake8-check) - NOMP_FLAKE8="yes" - shift - ;; - --pylint-check) - NOMP_PYLINT="yes" - shift - ;; - --update-shell) - NOMP_PROMPT="yes" - shift - ;; - *) echo "${red}Invalid option: ${1}${reset}." - echo "See ${cyan}${0} --help${reset} for the accepted options." - exit 1 ;; - esac -done - -if [[ ${NOMP_FORMAT} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target format - [[ $? -ne 0 ]] && exit 1 -fi - -if [[ ${NOMP_FORMAT_CHECK} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target format-check - [[ $? -ne 0 ]] && exit 1 -fi - -if [[ ${NOMP_TIDY} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target tidy - [[ $? -ne 0 ]] && exit 1 -fi - -if [[ ${NOMP_BLACK} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target black - [[ $? -ne 0 ]] && exit 1 -fi - -if [[ ${NOMP_BLACK_CHECK} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target black-check - [[ $? -ne 0 ]] && exit 1 -fi - -if [[ ${NOMP_ISORT} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target isort - [[ $? -ne 0 ]] && exit 1 -fi - -if [[ ${NOMP_ISORT_CHECK} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target isort-check - [[ $? -ne 0 ]] && exit 1 -fi - -if [[ ${NOMP_FLAKE8} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target flake8 - [[ $? -ne 0 ]] && exit 1 -fi - -if [[ ${NOMP_PYLINT} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target pylint - [[ $? -ne 0 ]] && exit 1 -fi - -if [[ ${NOMP_INSTALL} == "yes" ]]; then - cmake --build "${NOMP_BUILD_DIR}" --target install - [[ $? -ne 0 ]] && exit 1 - - [[ "${NOMP_PROMPT}" != "yes" ]] && exit 0 - - if [[ -f ${NOMP_SHELL_CONFIG_FILE} ]]; then - echo -e "${NOMP_ENVIRONMENT}" >> "${NOMP_SHELL_CONFIG_FILE}" - echo "${green}Successfully exported variables to ${NOMP_SHELL_CONFIG_FILE}${reset}." - exit 0 - else - echo "${red}Shell configration file ${NOMP_SHELL_CONFIG_FILE} doesn't exist{reset}." - exit 1 - fi -fi diff --git a/lncfg b/lncfg deleted file mode 100755 index ae2d35ca..00000000 --- a/lncfg +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash - -# Check for nomp environment variables. -: "${NOMP_SOURCE_DIR:="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"}" -: "${NOMP_BUILD_DIR:="${NOMP_SOURCE_DIR}/build"}" -: "${NOMP_INSTALL_DIR:="${HOME}/.nomp/libnomp"}" -: "${NOMP_PREFIX_PATH:=""}" -: "${NOMP_BUILD_TYPE:="Release"}" -: "${NOMP_ENABLE_OPENCL:="OFF"}" -: "${NOMP_OPENCL_LIBRARY:=""}" -: "${NOMP_OPENCL_INCLUDE_DIR:=""}" -: "${NOMP_ENABLE_CUDA:="OFF"}" -: "${NOMP_ENABLE_HIP:="OFF"}" -: "${NOMP_ENABLE_DOCS:="OFF"}" -: "${NOMP_ENABLE_TESTS:="OFF"}" -: "${NOMP_ENABLE_ASAN:="OFF"}" -: "${NOMP_C_COMPILER:=""}" -: "${NOMP_C_FLAGS:=""}" -: "${NOMP_LNSTATE_PATH:="${NOMP_SOURCE_DIR}/.lnstate"}" - -# Terminal output colors. -red=$(tput setaf 1) -green=$(tput setaf 2) -cyan=$(tput setaf 6) -reset=$(tput sgr0) - -# Print the options. -function print_help() { - echo -e "Usage: ${0} [--help] --cc [-cflags ]" \ - "[--install-prefix ]\n" \ - "[--build-type ] [--build-dir ]" \ - "[--prefix-path ]\n" \ - "[--enable-opencl] [--opencl-lib ]" \ - "[--opencl-headers ]\n" \ - "[--enable-hip] [--enable-cuda] [--enable-docs] [--enable-tests]" \ - "[--enable-asan]\n\n" \ - "${cyan}--help ${reset}\tPrint this help and exit.\n" \ - "${cyan}--cc ${reset}\tC Compiler.\n" \ - "${cyan}--cflags ${reset}\tC Compiler flags.\n" \ - "${cyan}--install-prefix${reset}\tInstall directory" \ - "(Default: ${NOMP_INSTALL_DIR}).\n" \ - "${cyan}--build-type ${reset}\tBuild type (Default: ${NOMP_BUILD_TYPE}," \ - "Allowed: Debug, Release, RelWithDebInfo and MinSizeRel).\n" \ - "${cyan}--build-dir ${reset}\tBuild directory" \ - "(Default: ${NOMP_BUILD_DIR}).\n" \ - "${cyan}--prefix-path ${reset}\tSemicolon separated list of prefix paths" \ - "for CMake.\n" \ - "${cyan}--enable-opencl ${reset}\tBuild with OpenCL backend" \ - "(Default: ${NOMP_ENABLE_OPENCL}).\n" \ - "${cyan}--opencl-lib ${reset}\tOpenCL library path.\n" \ - "${cyan}--opencl-headers${reset}\tOpenCL header path.\n" \ - "${cyan}--enable-hip ${reset}\tBuild with HIP backend" \ - "(Default: ${NOMP_ENABLE_HIP}).\n" \ - "${cyan}--enable-cuda ${reset}\tBuild with CUDA backend" \ - "(Default: ${NOMP_ENABLE_CUDA}).\n" \ - "${cyan}--enable-docs ${reset}\tBuild user documentation" \ - "(Default: ${NOMP_ENABLE_DOCS}).\n" \ - "${cyan}--enable-tests ${reset}\tBuild libnomp unit tests" \ - "(Default: ${NOMP_ENABLE_TESTS}).\n" \ - "${cyan}--enable-asan ${reset}\tBuild with AddressSanitizer" \ - "(Default: ${NOMP_ENABLE_ASAN})." - exit 0 -} - -# Parse the options. -while [ $# -gt 0 ]; do - case $1 in - --help) print_help ;; - --cc) shift && NOMP_C_COMPILER="${1}" ;; - --cflags) shift && NOMP_C_FLAGS="${1}" ;; - --build-type) shift && NOMP_BUILD_TYPE=${1} ;; - --build-dir) shift && NOMP_BUILD_DIR=$(realpath "${1}") ;; - --install-prefix) shift && NOMP_INSTALL_DIR="${1}" ;; - --prefix-path) shift && NOMP_PREFIX_PATH="${1}" ;; - --enable-hip) NOMP_ENABLE_HIP="ON" ;; - --enable-cuda) NOMP_ENABLE_CUDA="ON" ;; - --enable-opencl) NOMP_ENABLE_OPENCL="ON" ;; - --opencl-lib) shift && NOMP_OPENCL_LIBRARY=$(realpath "${1}") ;; - --opencl-headers) shift && NOMP_OPENCL_INCLUDE_DIR=$(realpath "${1}") ;; - --enable-asan) NOMP_ENABLE_ASAN="ON" ;; - --enable-docs) NOMP_ENABLE_DOCS="ON" ;; - --enable-tests) NOMP_ENABLE_TESTS="ON" ;; - *) echo "${red}Invalid option: ${1}${reset}." - echo "See ${cyan}./lncfg -h${reset} or ${cyan}./lncfg --help${reset} for " \ - "the accepted options." - exit 1 ;; - esac - shift -done - -# Update the cmake options. -NOMP_CMAKE_OPTS=() - -[[ -n ${NOMP_C_COMPILER} ]] && - NOMP_CMAKE_OPTS+=("-DCMAKE_C_COMPILER=${NOMP_C_COMPILER}") -[[ -n ${NOMP_C_FLAGS} ]] && - NOMP_CMAKE_OPTS+=("-DCMAKE_C_FLAGS=${NOMP_C_FLAGS}") - -NOMP_CMAKE_OPTS+=("-DCMAKE_BUILD_TYPE=${NOMP_BUILD_TYPE}") -NOMP_CMAKE_OPTS+=("-DCMAKE_INSTALL_PREFIX=${NOMP_INSTALL_DIR}") -[[ -n ${NOMP_PREFIX_PATH} ]] && - NOMP_CMAKE_OPTS+=("-DCMAKE_PREFIX_PATH=${NOMP_PREFIX_PATH}") - -NOMP_CMAKE_OPTS+=("-DENABLE_HIP=${NOMP_ENABLE_HIP}") -NOMP_CMAKE_OPTS+=("-DENABLE_CUDA=${NOMP_ENABLE_CUDA}") -NOMP_CMAKE_OPTS+=("-DENABLE_OPENCL=${NOMP_ENABLE_OPENCL}") -[[ -n ${NOMP_OPENCL_LIBRARY} ]] && - NOMP_CMAKE_OPTS+=("-DOpenCL_LIBRARY=${NOMP_OPENCL_LIBRARY}") -[[ -n ${NOMP_OPENCL_INCLUDE_DIR} ]] && - NOMP_CMAKE_OPTS+=("-DOpenCL_INCLUDE_DIR=${NOMP_OPENCL_INCLUDE_DIR}") - -NOMP_CMAKE_OPTS+=("-DENABLE_ASAN=${NOMP_ENABLE_ASAN}") -NOMP_CMAKE_OPTS+=("-DENABLE_DOCS=${NOMP_ENABLE_DOCS}") -NOMP_CMAKE_OPTS+=("-DENABLE_TESTS=${NOMP_ENABLE_TESTS}") - -# Update variables for lnstate scripts. -echo -e "NOMP_INSTALL_DIR=${NOMP_INSTALL_DIR}\n" \ - "NOMP_BUILD_DIR=${NOMP_BUILD_DIR}" >"${NOMP_LNSTATE_PATH}" - -# Create build directory if it doesn't exist. -[[ ! -d "${NOMP_BUILD_DIR}" ]] && mkdir "${NOMP_BUILD_DIR}" - -# Configure cmake build. -echo "Configuring build files for libnomp..." -echo "cmake -B ${NOMP_BUILD_DIR} -S ${NOMP_SOURCE_DIR} ${NOMP_CMAKE_OPTS[@]}" -cmake -B "${NOMP_BUILD_DIR}" -S "${NOMP_SOURCE_DIR}" "${NOMP_CMAKE_OPTS[@]}" - -if [[ $? -eq 0 ]]; then - echo "${green}Successfully created build files for libnomp${reset}." - echo "To install libnomp, either execute ${cyan}./lnbuild --install${reset} or" \ - "execute the command: ${cyan}cmake --build ${NOMP_BUILD_DIR} --target" \ - "install${reset}." - exit 0 -fi -echo "${red}Failed to create build files for libnomp${reset}." -exit 1 diff --git a/pyproject.toml b/pyproject.toml index bb358f3a..f4c643df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,15 +1,15 @@ -[tool.isort] -multi_line_output = 3 -include_trailing_comma = true -force_grid_wrap = 0 -use_parentheses = true -line_length = 80 -skip_glob = ['build/*', 'docs/*'] +[tool.ruff] +line-length = 80 +exclude = ["build", "docs"] -[tool.black] -line_length = 80 -preview = true -exclude = 'build/|docs/' +[tool.ruff.lint] +# Equivalent to the old flake8 rules + isort (I = isort, E/W = pycodestyle, F = pyflakes) +select = ["E", "F", "W", "I"] + +[tool.ruff.lint.isort] +# Matches the old isort settings +force-wrap-aliases = false +combine-as-imports = false [tool.pylint.master] ignore = "build,docs" diff --git a/python/loopy_api.py b/python/loopy_api.py index 586b2d5a..d98060a3 100644 --- a/python/loopy_api.py +++ b/python/loopy_api.py @@ -22,23 +22,23 @@ NOMP_VAR_PREFIX = "_nomp_var" _C_OPS_TO_PYMBOLIC_OPS = { - "*": lambda x, y: prim.Product((x, y)), - "+": lambda x, y: prim.Sum((x, y)), - "-": lambda l, r: prim.Sum((l, prim.Product((-1, r)))), + "*": lambda X, Y: prim.Product((X, Y)), + "+": lambda X, Y: prim.Sum((X, Y)), + "-": lambda L, R: prim.Sum((L, prim.Product((-1, R)))), "/": prim.Quotient, "//": prim.FloorDiv, "%": prim.Remainder, - "<": lambda l, r: prim.Comparison(l, "<", r), - "<=": lambda l, r: prim.Comparison(l, "<=", r), - ">": lambda l, r: prim.Comparison(l, ">", r), - ">=": lambda l, r: prim.Comparison(l, ">=", r), - "==": lambda l, r: prim.Comparison(l, "==", r), - "!=": lambda l, r: prim.Comparison(l, "!=", r), - "&&": lambda l, r: prim.LogicalAnd((l, r)), - "||": lambda l, r: prim.LogicalOr((l, r)), - "&": lambda l, r: prim.BitwiseAnd((l, r)), - "|": lambda l, r: prim.BitwiseOr((l, r)), - "^": lambda l, r: prim.BitwiseXor((l, r)), + "<": lambda L, R: prim.Comparison(L, "<", R), + "<=": lambda L, R: prim.Comparison(L, "<=", R), + ">": lambda L, R: prim.Comparison(L, ">", R), + ">=": lambda L, R: prim.Comparison(L, ">=", R), + "==": lambda L, R: prim.Comparison(L, "==", R), + "!=": lambda L, R: prim.Comparison(L, "!=", R), + "&&": lambda L, R: prim.LogicalAnd((L, R)), + "||": lambda L, R: prim.LogicalOr((L, R)), + "&": lambda L, R: prim.BitwiseAnd((L, R)), + "|": lambda L, R: prim.BitwiseOr((L, R)), + "^": lambda L, R: prim.BitwiseXor((L, R)), "<<": prim.LeftShift, ">>": prim.RightShift, } diff --git a/requirements-dev.txt b/requirements-dev.txt index 1e812bfe..4b3f93ae 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,4 @@ -isort==5.10.1 -black==24.3.0 -flake8==4.0.1 +ruff==0.4.4 breathe==4.34.0 Sphinx==5.1.1 sphinx-rtd-theme==1.0.0 diff --git a/requirements.txt b/requirements.txt index 94e98210..1b2bdf07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -loopy==2025.2 +loopy==2025.1 pymbolic==2025.1 libclang==14.0.6 pytools==2025.2.2 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 3eec6df7..00000000 --- a/setup.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[flake8] -max_line_length = 80 -extend_ignore = E127, E128, E203, W503, N802 -exclude = - build - docs