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

Apply CMake formatting #204

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ jobs:
cd ${BUILD_DIR}
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${BUILD_DIR} -DCMAKE_Fortran_FLAGS="-std=f2008" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

# Apply CMake linter, cmake-lint
- name: cmake
if: always()
run: |
cd ${{ github.workspace }}
. ftorch_venv/bin/activate
pip install cmakelang
cmake-lint $(find . -name CMakeLists.txt)

# Apply Fortran linter, fortitude
# Configurable using the fortitude.toml file if present
- name: fortitude source
Expand Down Expand Up @@ -98,6 +107,7 @@ jobs:
. ftorch_venv/bin/activate
fortitude check examples

# Apply Python linter, ruff
- name: ruff
if: always()
run: |
Expand Down
50 changes: 31 additions & 19 deletions examples/1_SimpleNet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#policy CMP0076 - target_sources source files are relative to file where target_sources is run
cmake_policy (SET CMP0076 NEW)
# policy CMP0076 - target_sources source files are relative to file where
# target_sources is run
cmake_policy(SET CMP0076 NEW)

set(PROJECT_NAME SimpleNetExample)

project(${PROJECT_NAME} LANGUAGES Fortran)

# Build in Debug mode if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "" FORCE)
endif()

find_package(FTorch)
Expand All @@ -23,28 +26,37 @@ if(CMAKE_BUILD_TESTS)
include(CTest)

# 1. Check the PyTorch model runs and its outputs meet expectations
add_test(NAME simplenet
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/simplenet.py)
add_test(NAME simplenet COMMAND ${PYTHON_EXECUTABLE}
${PROJECT_SOURCE_DIR}/simplenet.py)

# 2. Check the model is saved to file in the expected location with the pt2ts.py script
add_test(NAME pt2ts
# 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
${PROJECT_BINARY_DIR}
# Command line argument: filepath for saving the model
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

# 3. Check the model can be loaded from file and run in Python and that its outputs
# meet expectations
add_test(NAME simplenet_infer_python
# 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
${PROJECT_BINARY_DIR}
# Command line argument: filepath to find the model
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

# 4. 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 # Command line argument: model file
# 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
# Command line argument: model file
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
set_tests_properties(simplenet_infer_fortran PROPERTIES PASS_REGULAR_EXPRESSION
"SimpleNet example ran successfully")
set_tests_properties(
simplenet_infer_fortran PROPERTIES PASS_REGULAR_EXPRESSION
"SimpleNet example ran successfully")
endif()
41 changes: 26 additions & 15 deletions examples/2_ResNet18/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#policy CMP0076 - target_sources source files are relative to file where target_sources is run
cmake_policy (SET CMP0076 NEW)
# policy CMP0076 - target_sources source files are relative to file where
# target_sources is run
cmake_policy(SET CMP0076 NEW)

set(PROJECT_NAME ResNetExample)

project(${PROJECT_NAME} LANGUAGES Fortran)

# Build in Debug mode if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "" FORCE)
endif()

find_package(FTorch)
Expand All @@ -23,23 +26,31 @@ if(CMAKE_BUILD_TESTS)
include(CTest)

# 1. Check the PyTorch model runs and its outputs meet expectations
add_test(NAME resnet18
add_test(
NAME resnet18
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/resnet18.py
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

# 2. Check the model is saved to file in the expected location with the pt2ts.py script
add_test(NAME pt2ts
# 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
${PROJECT_BINARY_DIR}
# Command line argument: filepath for saving the model
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

# 3. 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 # Command line argument: model file
${PROJECT_SOURCE_DIR}/data # Command line argument: data directory filepath
# 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
${PROJECT_SOURCE_DIR}/data
# Command line arguments: model file and data directory filepath
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
set_tests_properties(resnet_infer_fortran PROPERTIES PASS_REGULAR_EXPRESSION
"ResNet18 example ran successfully")
set_tests_properties(
resnet_infer_fortran PROPERTIES PASS_REGULAR_EXPRESSION
"ResNet18 example ran successfully")
endif()
9 changes: 6 additions & 3 deletions examples/3_MultiGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#policy CMP0076 - target_sources source files are relative to file where target_sources is run
cmake_policy (SET CMP0076 NEW)
# policy CMP0076 - target_sources source files are relative to file where
# target_sources is run
cmake_policy(SET CMP0076 NEW)

set(PROJECT_NAME MultiGPUExample)

project(${PROJECT_NAME} LANGUAGES Fortran)

# Build in Debug mode if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "" FORCE)
endif()

find_package(FTorch)
Expand Down
53 changes: 33 additions & 20 deletions examples/4_MultiIO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#policy CMP0076 - target_sources source files are relative to file where target_sources is run
cmake_policy (SET CMP0076 NEW)
# policy CMP0076 - target_sources source files are relative to file where
# target_sources is run
cmake_policy(SET CMP0076 NEW)

set(PROJECT_NAME MultiIONetExample)

project(${PROJECT_NAME} LANGUAGES Fortran)

# Build in Debug mode if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "" FORCE)
endif()

find_package(FTorch)
Expand All @@ -23,28 +26,38 @@ if(CMAKE_BUILD_TESTS)
include(CTest)

# 1. Check the PyTorch model runs and its outputs meet expectations
add_test(NAME multiionet
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/multiionet.py)
add_test(NAME multiionet COMMAND ${PYTHON_EXECUTABLE}
${PROJECT_SOURCE_DIR}/multiionet.py)

# 2. Check the model is saved to file in the expected location with the pt2ts.py script
add_test(NAME pt2ts
# 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
${PROJECT_BINARY_DIR}
# Command line argument: filepath for saving the model
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

# 3. 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
# 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
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

# 4. 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 # Command line argument: model file
# 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
# Command line argument: model file
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
set_tests_properties(multiionet_infer_fortran PROPERTIES PASS_REGULAR_EXPRESSION
"MultiIO example ran successfully")
set_tests_properties(
multiionet_infer_fortran PROPERTIES PASS_REGULAR_EXPRESSION
"MultiIO example ran successfully")
endif()
13 changes: 8 additions & 5 deletions examples/5_Looping/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#policy CMP0076 - target_sources source files are relative to file where target_sources is run
cmake_policy (SET CMP0076 NEW)
# policy CMP0076 - target_sources source files are relative to file where
# target_sources is run
cmake_policy(SET CMP0076 NEW)

set(PROJECT_NAME LoopingExample)

project(${PROJECT_NAME} LANGUAGES Fortran)

# Build in Debug mode if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "" FORCE)
endif()

find_package(FTorch)
Expand All @@ -17,9 +20,9 @@ message(STATUS "Building with Fortran PyTorch coupling")
# Fortran example - bad
add_executable(simplenet_infer_fortran_bad bad/simplenet_infer_fortran.f90)
target_link_libraries(simplenet_infer_fortran_bad PRIVATE FTorch::ftorch)
target_sources ( simplenet_infer_fortran_bad PRIVATE bad/fortran_ml_mod.f90 )
target_sources(simplenet_infer_fortran_bad PRIVATE bad/fortran_ml_mod.f90)

# Fortran example - good
add_executable(simplenet_infer_fortran_good good/simplenet_infer_fortran.f90)
target_link_libraries(simplenet_infer_fortran_good PRIVATE FTorch::ftorch)
target_sources ( simplenet_infer_fortran_good PRIVATE good/fortran_ml_mod.f90 )
target_sources(simplenet_infer_fortran_good PRIVATE good/fortran_ml_mod.f90)
20 changes: 12 additions & 8 deletions examples/6_Autograd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#policy CMP0076 - target_sources source files are relative to file where target_sources is run
cmake_policy (SET CMP0076 NEW)
# policy CMP0076 - target_sources source files are relative to file where
# target_sources is run
cmake_policy(SET CMP0076 NEW)

set(PROJECT_NAME AutogradExample)

project(${PROJECT_NAME} LANGUAGES Fortran)

# Build in Debug mode if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "" FORCE)
endif()

find_package(FTorch)
Expand All @@ -23,13 +26,14 @@ if(CMAKE_BUILD_TESTS)
include(CTest)

# 1. Check the Python Autograd script runs successfully
add_test(NAME pyautograd
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/autograd.py)
add_test(NAME pyautograd COMMAND ${PYTHON_EXECUTABLE}
${PROJECT_SOURCE_DIR}/autograd.py)

# 2. Check the Fortran Autograd script runs successfully
add_test(NAME fautograd
# 1. Check the Fortran Autograd script runs successfully
add_test(
NAME fautograd
COMMAND autograd
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
set_tests_properties(fautograd PROPERTIES PASS_REGULAR_EXPRESSION
"Autograd example ran successfully")
"Autograd example ran successfully")
endif()
Loading
Loading