diff --git a/.github/workflows/test_suite.yml b/.github/workflows/test_suite_ubuntu.yml similarity index 83% rename from .github/workflows/test_suite.yml rename to .github/workflows/test_suite_ubuntu.yml index 5ec5a11e..ed9e74f7 100644 --- a/.github/workflows/test_suite.yml +++ b/.github/workflows/test_suite_ubuntu.yml @@ -1,5 +1,5 @@ # Workflow to run the FTorch test suite -name: TestSuite +name: TestSuiteUbuntu # Controls when the workflow will run on: @@ -10,7 +10,7 @@ on: # Triggers the workflow on pushes to open pull requests with code changes pull_request: paths: - - '.github/workflows/test_suite.yml' + - '.github/workflows/test_suite_ubuntu.yml' - '**.c' - '**.cpp' - '**.fypp' @@ -33,8 +33,8 @@ concurrency: # Workflow run - one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "test-suite" - test-suite: + # This workflow contains a single job called "test-suite-ubuntu" + test-suite-ubuntu: # The type of runner that the job will run on runs-on: ubuntu-latest strategy: @@ -68,7 +68,12 @@ jobs: export BUILD_DIR=$(pwd)/src/build mkdir ${BUILD_DIR} cd ${BUILD_DIR} - cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${BUILD_DIR} -DCMAKE_BUILD_TESTS=TRUE -DCMAKE_Fortran_FLAGS="-std=${{ matrix.std }}" + cmake .. \ + -DPython_EXECUTABLE="$(which python)" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \ + -DCMAKE_BUILD_TESTS=TRUE \ + -DCMAKE_Fortran_FLAGS="-std=${{matrix.std}}" cmake --build . cmake --install . diff --git a/.github/workflows/test_suite_windows.yml b/.github/workflows/test_suite_windows.yml new file mode 100644 index 00000000..3cfb2321 --- /dev/null +++ b/.github/workflows/test_suite_windows.yml @@ -0,0 +1,91 @@ +# Workflow to run the FTorch test suite +name: TestSuiteWindows + +# Controls when the workflow will run +on: + # Triggers the workflow on pushes to the "main" branch, i.e., PR merges + push: + branches: [ "main" ] + + # Triggers the workflow on pushes to open pull requests with code changes + pull_request: + paths: + - '.github/workflows/test_suite_windows.yml' + - '**.c' + - '**.cpp' + - '**.fypp' + - '**.f90' + - '**.F90' + - '**.pf' + - '**.py' + - '**.sh' + - '**CMakeLists.txt' + - '**requirements.txt' + - '**data/*' + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Cancel jobs running if new commits are pushed +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +# Workflow run - one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "test-suite-windows" + test-suite-windows: + # The type of runner that the job will run on + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + toolchain: + - {compiler: intel, version: '2023.2'} + + steps: + # configure windows VM with intel compilers + - uses: fortran-lang/setup-fortran@v1 + id: setup-fortran + with: + compiler: ${{ matrix.toolchain.compiler }} + version: ${{ matrix.toolchain.version }} + + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install PyTorch + shell: cmd + run: | + pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu + + - name: Build FTorch + shell: cmd + run: | + cd src + cmake ^ + -Bbuild ^ + -G "NMake Makefiles" ^ + -DCMAKE_Fortran_FLAGS="/fpscomp:logicals" ^ + -DCMAKE_PREFIX_PATH="C:\hostedtoolcache\windows\Python\3.12.7\x64\Lib\site-packages" ^ + -DCMAKE_BUILD_TYPE=Release ^ + -DCMAKE_Fortran_COMPILER=ifx ^ + -DCMAKE_C_COMPILER=icx ^ + -DCMAKE_CXX_COMPILER=icx ^ + -DCMAKE_BUILD_TESTS=TRUE + cmake --build build + cmake --install build + + - name: Integration tests + shell: cmd + run: | + set PATH=C:\hostedtoolcache\windows\Python\3.12.7\x64\Lib\site-packages;%PATH% + set PATH=C:\Program Files (x86)\FTorch\bin;%PATH% + set PATH=C:\hostedtoolcache\windows\Python\3.12.7\x64\Lib\site-packages\torch\lib;%PATH% + run_integration_tests.bat diff --git a/README.md b/README.md index dd5860d6..7f823da8 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ _For a similar approach to calling TensorFlow models from Fortran please see [Fo To install the library requires the following to be installed on the system: -* CMake >= 3.5 +* CMake >= 3.15 * [libtorch](https://pytorch.org/cppdocs/installing.html)* or [PyTorch](https://pytorch.org/) * Fortran (2008 standard compliant), C++ (must fully support C++17), and C compilers diff --git a/examples/1_SimpleNet/CMakeLists.txt b/examples/1_SimpleNet/CMakeLists.txt index 04bd3cde..e1fa84fe 100644 --- a/examples/1_SimpleNet/CMakeLists.txt +++ b/examples/1_SimpleNet/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) # policy CMP0076 - target_sources source files are relative to file where # target_sources is run cmake_policy(SET CMP0076 NEW) @@ -26,25 +26,25 @@ if(CMAKE_BUILD_TESTS) include(CTest) # 1. Check the PyTorch model runs and its outputs meet expectations - add_test(NAME simplenet COMMAND ${PYTHON_EXECUTABLE} + add_test(NAME simplenet COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/simplenet.py) # 1. Check the model is saved to file in the expected location with the # pt2ts.py script add_test( NAME pt2ts - COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/pt2ts.py - ${PROJECT_BINARY_DIR} - # Command line argument: filepath for saving the model + COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/pt2ts.py + ${PROJECT_BINARY_DIR} # Command line argument: filepath for saving + # the model WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) # 1. Check the model can be loaded from file and run in Python and that its # outputs meet expectations add_test( NAME simplenet_infer_python - COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/simplenet_infer_python.py - ${PROJECT_BINARY_DIR} - # Command line argument: filepath to find the model + COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/simplenet_infer_python.py + ${PROJECT_BINARY_DIR} # Command line argument: filepath to find the + # model WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) # 1. Check the model can be loaded from file and run in Fortran and that its @@ -52,8 +52,7 @@ if(CMAKE_BUILD_TESTS) add_test( NAME simplenet_infer_fortran COMMAND - simplenet_infer_fortran - ${PROJECT_BINARY_DIR}/saved_simplenet_model_cpu.pt + simplenet_infer_fortran ${PROJECT_BINARY_DIR}/saved_simplenet_model_cpu.pt # Command line argument: model file WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) set_tests_properties( diff --git a/examples/1_SimpleNet/pt2ts.py b/examples/1_SimpleNet/pt2ts.py old mode 100755 new mode 100644 index 478d5c88..161ea2e7 --- a/examples/1_SimpleNet/pt2ts.py +++ b/examples/1_SimpleNet/pt2ts.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Load a PyTorch model and convert it to TorchScript.""" import os diff --git a/examples/1_SimpleNet/simplenet.py b/examples/1_SimpleNet/simplenet.py old mode 100755 new mode 100644 index db1461d0..66e89952 --- a/examples/1_SimpleNet/simplenet.py +++ b/examples/1_SimpleNet/simplenet.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Module defining a simple PyTorch 'Net' for coupling to Fortran.""" import torch diff --git a/examples/1_SimpleNet/simplenet_infer_python.py b/examples/1_SimpleNet/simplenet_infer_python.py old mode 100755 new mode 100644 index 8df4792d..338f83c7 --- a/examples/1_SimpleNet/simplenet_infer_python.py +++ b/examples/1_SimpleNet/simplenet_infer_python.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Load saved SimpleNet to TorchScript and run inference example.""" import os diff --git a/examples/2_ResNet18/CMakeLists.txt b/examples/2_ResNet18/CMakeLists.txt index 14d1d354..0b46c93e 100644 --- a/examples/2_ResNet18/CMakeLists.txt +++ b/examples/2_ResNet18/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) # policy CMP0076 - target_sources source files are relative to file where # target_sources is run cmake_policy(SET CMP0076 NEW) @@ -28,16 +28,16 @@ if(CMAKE_BUILD_TESTS) # 1. Check the PyTorch model runs and its outputs meet expectations add_test( NAME resnet18 - COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/resnet18.py + COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/resnet18.py WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) # 1. Check the model is saved to file in the expected location with the # pt2ts.py script add_test( NAME pt2ts - COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/pt2ts.py - ${PROJECT_BINARY_DIR} - # Command line argument: filepath for saving the model + COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/pt2ts.py + ${PROJECT_BINARY_DIR} # Command line argument: filepath for saving + # the model WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) # 1. Check the model can be loaded from file and run in Fortran and that its @@ -45,8 +45,7 @@ if(CMAKE_BUILD_TESTS) add_test( NAME resnet_infer_fortran COMMAND - resnet_infer_fortran - ${PROJECT_BINARY_DIR}/saved_resnet18_model_cpu.pt + resnet_infer_fortran ${PROJECT_BINARY_DIR}/saved_resnet18_model_cpu.pt ${PROJECT_SOURCE_DIR}/data # Command line arguments: model file and data directory filepath WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) diff --git a/examples/2_ResNet18/pt2ts.py b/examples/2_ResNet18/pt2ts.py old mode 100755 new mode 100644 index 39f42b3d..d04cb5c4 --- a/examples/2_ResNet18/pt2ts.py +++ b/examples/2_ResNet18/pt2ts.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Load a PyTorch model and convert it to TorchScript.""" import os diff --git a/examples/2_ResNet18/resnet18.py b/examples/2_ResNet18/resnet18.py old mode 100755 new mode 100644 index 63472dde..d3c73faf --- a/examples/2_ResNet18/resnet18.py +++ b/examples/2_ResNet18/resnet18.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Load and run pretrained ResNet-18 from TorchVision.""" import numpy as np diff --git a/examples/3_MultiGPU/CMakeLists.txt b/examples/3_MultiGPU/CMakeLists.txt index dca170c2..04c2cf3e 100644 --- a/examples/3_MultiGPU/CMakeLists.txt +++ b/examples/3_MultiGPU/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) # policy CMP0076 - target_sources source files are relative to file where # target_sources is run cmake_policy(SET CMP0076 NEW) diff --git a/examples/4_MultiIO/CMakeLists.txt b/examples/4_MultiIO/CMakeLists.txt index bd964418..40952f11 100644 --- a/examples/4_MultiIO/CMakeLists.txt +++ b/examples/4_MultiIO/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) # policy CMP0076 - target_sources source files are relative to file where # target_sources is run cmake_policy(SET CMP0076 NEW) @@ -26,16 +26,16 @@ if(CMAKE_BUILD_TESTS) include(CTest) # 1. Check the PyTorch model runs and its outputs meet expectations - add_test(NAME multiionet COMMAND ${PYTHON_EXECUTABLE} + add_test(NAME multiionet COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/multiionet.py) # 1. Check the model is saved to file in the expected location with the # pt2ts.py script add_test( NAME pt2ts - COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/pt2ts.py - ${PROJECT_BINARY_DIR} - # Command line argument: filepath for saving the model + COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/pt2ts.py + ${PROJECT_BINARY_DIR} # Command line argument: filepath for saving + # the model WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) # 1. Check the model can be loaded from file and run in Python and that its @@ -43,9 +43,8 @@ if(CMAKE_BUILD_TESTS) add_test( NAME multiionet_infer_python COMMAND - ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/multiionet_infer_python.py - ${PROJECT_BINARY_DIR} - # Command line argument: filepath to find the model + ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/multiionet_infer_python.py + ${PROJECT_BINARY_DIR} # Command line argument: filepath to find the model WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) # 1. Check the model can be loaded from file and run in Fortran and that its @@ -53,8 +52,7 @@ if(CMAKE_BUILD_TESTS) add_test( NAME multiionet_infer_fortran COMMAND - multiionet_infer_fortran - ${PROJECT_BINARY_DIR}/saved_multiio_model_cpu.pt + multiionet_infer_fortran ${PROJECT_BINARY_DIR}/saved_multiio_model_cpu.pt # Command line argument: model file WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) set_tests_properties( diff --git a/examples/4_MultiIO/multiionet.py b/examples/4_MultiIO/multiionet.py old mode 100755 new mode 100644 index 52a5094b..44483325 --- a/examples/4_MultiIO/multiionet.py +++ b/examples/4_MultiIO/multiionet.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Module defining a simple PyTorch 'Net' for coupling to Fortran.""" import torch diff --git a/examples/4_MultiIO/multiionet_infer_python.py b/examples/4_MultiIO/multiionet_infer_python.py old mode 100755 new mode 100644 index 6aa23148..d5c9cf2d --- a/examples/4_MultiIO/multiionet_infer_python.py +++ b/examples/4_MultiIO/multiionet_infer_python.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Load saved MultIONet to TorchScript and run inference example.""" import os diff --git a/examples/4_MultiIO/pt2ts.py b/examples/4_MultiIO/pt2ts.py old mode 100755 new mode 100644 index 3378c276..e7cd67e6 --- a/examples/4_MultiIO/pt2ts.py +++ b/examples/4_MultiIO/pt2ts.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Load a PyTorch model and convert it to TorchScript.""" import os diff --git a/examples/5_Looping/CMakeLists.txt b/examples/5_Looping/CMakeLists.txt index f5f6cf6d..02e3b626 100644 --- a/examples/5_Looping/CMakeLists.txt +++ b/examples/5_Looping/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) # policy CMP0076 - target_sources source files are relative to file where # target_sources is run cmake_policy(SET CMP0076 NEW) diff --git a/examples/5_Looping/simplenet.py b/examples/5_Looping/simplenet.py old mode 100755 new mode 100644 index 4d796f01..f22d953d --- a/examples/5_Looping/simplenet.py +++ b/examples/5_Looping/simplenet.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Module defining a simple PyTorch 'Net' for coupling to Fortran.""" import torch diff --git a/examples/6_Autograd/CMakeLists.txt b/examples/6_Autograd/CMakeLists.txt index ce681460..c34543aa 100644 --- a/examples/6_Autograd/CMakeLists.txt +++ b/examples/6_Autograd/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) # policy CMP0076 - target_sources source files are relative to file where # target_sources is run cmake_policy(SET CMP0076 NEW) @@ -26,7 +26,7 @@ if(CMAKE_BUILD_TESTS) include(CTest) # 1. Check the Python Autograd script runs successfully - add_test(NAME pyautograd COMMAND ${PYTHON_EXECUTABLE} + add_test(NAME pyautograd COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/autograd.py) # 1. Check the Fortran Autograd script runs successfully diff --git a/examples/6_Autograd/autograd.py b/examples/6_Autograd/autograd.py old mode 100755 new mode 100644 index 3544e811..cc7ee753 --- a/examples/6_Autograd/autograd.py +++ b/examples/6_Autograd/autograd.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """Autograd demo taken from https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html.""" import torch diff --git a/examples/n_c_and_cpp/CMakeLists.txt b/examples/n_c_and_cpp/CMakeLists.txt index 49b9aa43..1b01479d 100644 --- a/examples/n_c_and_cpp/CMakeLists.txt +++ b/examples/n_c_and_cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) set(PROJECT_NAME FTorch) set(LIB_NAME ftorch) set(PACKAGE_VERSION 0.1) diff --git a/pages/cmake.md b/pages/cmake.md index 1763a4a6..d9953001 100644 --- a/pages/cmake.md +++ b/pages/cmake.md @@ -10,7 +10,7 @@ This is controlled by the `CMakeLists.txt` file in `src/`. To install the library requires the following to be installed on the system: -- CMake >= 3.5 +- CMake >= 3.15 - libtorch or PyTorch - Fortran (2008 standard compliant), C++ (must fully support C++17), and C compilers diff --git a/pages/testing.md b/pages/testing.md index 68ac59de..7cc64332 100644 --- a/pages/testing.md +++ b/pages/testing.md @@ -4,31 +4,28 @@ title: FTorch test suite ## Testing -FTorch's test suite is currently comprised of integration tests based on a -subset of the [examples](examples.html). These tests are built and run and their +FTorch's test suite currently comprises of integration tests based on a subset +of the [examples](examples.html). These tests are built and run and their outputs are analysed to check they contain expected regular expressions. ### Building the integration tests To enable FTorch's integration tests, ensure that the `CMAKE_BUILD_TESTS` option -is set to `TRUE` for the build. +is set to `TRUE` for the build i.e., `-DCMAKE_BUILD_TESTS=True`. ### Running the integration tests Once the build is complete, activate the Python virtual environment you created for FTorch1 and simply run the [helper script](https://github.com/Cambridge-ICCS/FTorch/blob/main/run_integration_tests.sh) -in the root FTorch directory: -``` -./run_integration_tests.sh -``` -This will automatically install any additional dependencies for the examples. +in the root FTorch directory. Depending on the OS you are running you will need +to use either: -> 1 _If you built FTorch against libtorch (rather than creating a -virtual environment) then either -[create a virtual environment](https://docs.python.org/3/library/venv.html) for -the purposes of testing, or note that this script may have your Python -environment install some modules._ +- `./run_integration_tests.sh` for unix (mac and linux) +- `run_integration_tests.bat` for windows + +This will automatically install any additional Python dependencies for the +examples. Alternatively, individual tests may be run by going to the corresponding subdirectory of `${BUILD_DIR}/test/examples` (where `${BUILD_DIR}` is the build @@ -36,3 +33,9 @@ directory for FTorch) and calling `ctest`. This will produce a report on which tests passed and which failed for your build. Note that some of the examples have additional dependencies, which may need installing into your virtual environment. + +> 1 _If you built FTorch against libtorch (rather than creating a +virtual environment) then either +[create a virtual environment](https://docs.python.org/3/library/venv.html) for +the purposes of testing, or note that this script may have your Python +environment install some modules._ diff --git a/pages/troubleshooting.md b/pages/troubleshooting.md index 92acd6be..d5204014 100644 --- a/pages/troubleshooting.md +++ b/pages/troubleshooting.md @@ -6,38 +6,98 @@ If you are experiencing problems building or using FTorch please see below for g ## Windows -If possible we recommend using the [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/) (WSL) to build the library. -In this case the build process is the same as for a Linux environment. +If possible we recommend using the [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/) (WSL) to build +the library. In this case the build process is the same as for a Linux environment. If you need to build in native Windows please read the following information: ### Visual Studio -It is possible to build using Visual Studio and the Intel Fortran Compiler -In this case you must install +It is possible to build using Visual Studio and the Intel Fortran Compiler. In this case you must install the following: * [Visual Studio](https://visualstudio.microsoft.com/) ensuring C++ tools are selected and installed. * [Intel OneAPI Basetoolkit](https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html) * [Intel OneAPI HPC toolkit](https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit.html) ensuring that the Intel Fortran compiler and VS integration is selected. -You will then need to load the intel Fortran compilers using `setvars.bat` -which is found in the Intel compiler install directory (see the -[intel docs](https://www.intel.com/content/www/us/en/docs/oneapi/programming-guide/2023-2/use-the-setvars-script-with-windows.html)) +You will then need to load the intel Fortran compilers using `setvars.bat` which is found in the Intel compiler install +directory (see the [intel +docs](https://www.intel.com/content/www/us/en/docs/oneapi/programming-guide/2023-2/use-the-setvars-script-with-windows.html)) for more details.
-From CMD this can be done with: + +From `cmd` this can be done with: ``` -"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" +call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" ``` Finally you will need to add `-G "NMake Makefiles"` to the `cmake` command in the [regular install instructions](doc/page/cmake.html).
-So the basic command to build from CMD becomes: +So the basic command to build from `cmd` becomes: ``` cmake -G "NMake Makefiles" -DCMAKE_PREFIX_PATH="C:\Users\\libtorch" -DCMAKE_BUILD_TYPE=Release .. cmake --build . cmake --install . ``` +The following is an example `cmd` script that installs FTorch and runs the integration tests. It assumes you have already +install `cmake`, `git`, the intel compilers and visual studio. + +```cmd +rem disable output for now +ECHO ON + +rem load intel compilers +call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" + +rem download ftorch +git clone https://github.com/Cambridge-ICCS/FTorch.git +cd FTorch + +rem make venv +python -m venv .ftorch + +rem activate the environment +call .ftorch\Scripts\activate + +rem install torch +pip install torch torchvision torchaudio + +rem enable output +ECHO ON + +rem run cmake to generate build scripts +rem (update CMAKE_PREFIX_PATH depending on location of ftorch venv) +cd src +cmake -Bbuild -G "NMake Makefiles" -DCMAKE_Fortran_FLAGS="/fpscomp:logicals" ^ + -DCMAKE_PREFIX_PATH="C:\Users\Quickemu\Downloads\FTorch\.ftorch\Lib\site-packages" ^ + -DCMAKE_BUILD_TYPE=Release ^ + -DCMAKE_BUILD_TESTS=True ^ + -DCMAKE_Fortran_COMPILER=ifx -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx + +rem build and install ftorch +cmake --build build +cmake --install build + +rem quit if this raises an error +if %errorlevel% neq 0 exit /b %errorlevel% + +ECHO OFF +rem add ftorch and pytorch libs to path +rem (update these depending on where you installed ftorch and where you created the venv) +set PATH=C:\Users\Quickemu\Downloads\FTorch\.ftorch\Lib\site-packages;%PATH% +set PATH=C:\Program Files (x86)\FTorch\bin;%PATH% +set PATH=C:\Users\Quickemu\Downloads\FTorch\.ftorch\Lib\site-packages\torch\lib;%PATH% + +cd .. + +rem run integration tests +ECHO ON +run_integration_tests.bat +if %errorlevel% neq 0 exit /b %errorlevel% +``` + +We would also recommend Windows users to review the Windows CI workflow (`.github/workflows/test_suite_windows.yml`) for more +information, as this provides another example of how to build and run FTorch and its integration tests. + If using powershell the setvars and build commands become: ``` cmd /k '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell' diff --git a/run_integration_tests.bat b/run_integration_tests.bat new file mode 100644 index 00000000..2a564535 --- /dev/null +++ b/run_integration_tests.bat @@ -0,0 +1,19 @@ +rem --- +rem Execute this shell script to run all of FTorch's integration tests. +rem +rem Assumes FTorch has been built with the `-DCMAKE_BUILD_TESTS=TRUE` option. +rem The `BUILD_DIR` variable in this script should be updated as appropriate for +rem your configuration. +rem +rem See `src/test/README.md` for more details on integration testing. +rem --- + +for /d %%i in (1_SimpleNet 2_ResNet18 4_MultiIO) do ( +pushd src\build\test\examples\%%i +rem run the tests +ctest +rem The following line will propagate the error back to the cmd shell +rem This is necessary for the CI to detect a failed test +if %errorlevel% neq 0 exit /b %errorlevel% +popd +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34299f49..9ee7e2bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) set(PROJECT_NAME FTorch) set(LIB_NAME ftorch) set(PACKAGE_VERSION 0.1) @@ -8,12 +8,12 @@ project( VERSION ${PACKAGE_VERSION} LANGUAGES C CXX Fortran) -if (WIN32) - # if building on windows we need to make sure the symbols are exported - set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) - # required to build the .dll on windows - set (BUILD_SHARED_LIBS TRUE) -endif () +if(WIN32) + # if building on windows we need to make sure the symbols are exported + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + # required to build the .dll on windows + set(BUILD_SHARED_LIBS TRUE) +endif() include(FortranCInterface) FortranCInterface_VERIFY(CXX QUIET) @@ -102,6 +102,13 @@ install(FILES "${CMAKE_BINARY_DIR}/modules/ftorch_test_utils.mod" # Build integration tests if(CMAKE_BUILD_TESTS) + + set(Python_FIND_VIRTUALENV FIRST) # cmake-lint: disable=C0103 + find_package( + Python + COMPONENTS Interpreter + REQUIRED) + file(MAKE_DIRECTORY test/examples) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../examples/CMakeLists.txt DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/test/examples) diff --git a/src/test/README.md b/src/test/README.md index 6287f38e..f129f4c4 100644 --- a/src/test/README.md +++ b/src/test/README.md @@ -24,8 +24,11 @@ which tests passed and which failed for your build. Note that the examples have additional dependencies, which may need installing into your virtual environment. -Alternatively, run the helper script in the root FTorch directory: -``` -./run_integration_tests.sh -``` -This will automatically install any additional dependencies for the examples. +Alternatively, run the helper script in the root FTorch directory. Depending on +which operating system you are running, you will need: + +- `./run_integration_tests.sh` for unix (mac and linux) +- `run_integration_tests.bat` for windows + +This will automatically install any additional Python dependencies for the +examples and run the tests.