Skip to content
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

Windows CI build #168

Merged
merged 13 commits into from
Dec 10, 2024
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Workflow to run the FTorch test suite
name: TestSuite
name: TestSuiteUbuntu

# Controls when the workflow will run
on:
Expand All @@ -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'
Expand All @@ -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:
Expand Down Expand Up @@ -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 .

Expand Down
91 changes: 91 additions & 0 deletions .github/workflows/test_suite_windows.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)<sup>*</sup> or [PyTorch](https://pytorch.org/)
* Fortran (2008 standard compliant), C++ (must fully support C++17), and C compilers

Expand Down
19 changes: 9 additions & 10 deletions examples/1_SimpleNet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -26,34 +26,33 @@ 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
# outputs meet expectations
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(
Expand Down
1 change: 0 additions & 1 deletion examples/1_SimpleNet/pt2ts.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Load a PyTorch model and convert it to TorchScript."""

import os
Expand Down
1 change: 0 additions & 1 deletion examples/1_SimpleNet/simplenet.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Module defining a simple PyTorch 'Net' for coupling to Fortran."""

import torch
Expand Down
1 change: 0 additions & 1 deletion examples/1_SimpleNet/simplenet_infer_python.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Load saved SimpleNet to TorchScript and run inference example."""

import os
Expand Down
13 changes: 6 additions & 7 deletions examples/2_ResNet18/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -28,25 +28,24 @@ 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
# outputs meet expectations
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})
Expand Down
1 change: 0 additions & 1 deletion examples/2_ResNet18/pt2ts.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Load a PyTorch model and convert it to TorchScript."""

import os
Expand Down
1 change: 0 additions & 1 deletion examples/2_ResNet18/resnet18.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Load and run pretrained ResNet-18 from TorchVision."""

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion examples/3_MultiGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
18 changes: 8 additions & 10 deletions examples/4_MultiIO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -26,35 +26,33 @@ 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
# outputs meet expectations
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
# outputs meet expectations
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(
Expand Down
1 change: 0 additions & 1 deletion examples/4_MultiIO/multiionet.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Module defining a simple PyTorch 'Net' for coupling to Fortran."""

import torch
Expand Down
1 change: 0 additions & 1 deletion examples/4_MultiIO/multiionet_infer_python.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Load saved MultIONet to TorchScript and run inference example."""

import os
Expand Down
1 change: 0 additions & 1 deletion examples/4_MultiIO/pt2ts.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Load a PyTorch model and convert it to TorchScript."""

import os
Expand Down
2 changes: 1 addition & 1 deletion examples/5_Looping/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 0 additions & 1 deletion examples/5_Looping/simplenet.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Module defining a simple PyTorch 'Net' for coupling to Fortran."""

import torch
Expand Down
4 changes: 2 additions & 2 deletions examples/6_Autograd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion examples/6_Autograd/autograd.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""Autograd demo taken from https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html."""

import torch
Expand Down
2 changes: 1 addition & 1 deletion examples/n_c_and_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pages/cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading
Loading