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

Avoid copying examples when building tests #281

Merged
merged 7 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
export FT_DIR=$(pwd)
VN=$(python -c "import sys; print('.'.join(sys.version.split('.')[:2]))")
export Torch_DIR=${VIRTUAL_ENV}/lib/python${VN}/site-packages
export BUILD_DIR=$(pwd)/src/build
export BUILD_DIR=$(pwd)/build
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${BUILD_DIR} -DCMAKE_Fortran_FLAGS="-std=f2008" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_suite_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
. ftorch/bin/activate
VN=$(python -c "import sys; print('.'.join(sys.version.split('.')[:2]))")
export Torch_DIR=${VIRTUAL_ENV}/lib/python${VN}/site-packages
export BUILD_DIR=$(pwd)/src/build
export BUILD_DIR=$(pwd)/build
# NOTE: The pFUnit version (pinned during installation above) is used in the install path.
export PFUNIT_DIR=$(pwd)/pFUnit/build/installed/PFUNIT-4.10
mkdir ${BUILD_DIR}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test_suite_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ jobs:
- name: Build FTorch
shell: cmd
run: |
cd src
rem find torch location
for /f "tokens=2*" %%i in ('pip show torch ^| findstr /R "^Location"') do set torch_path=%%i
cmake ^
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ coverage.xml
.pytest_cache/
cover/
Testing/
src/test/examples

# Translations
*.mo
Expand Down
27 changes: 4 additions & 23 deletions src/CMakeLists.txt → CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ set(CMAKE_INSTALL_RPATH $ORIGIN/${relDir})
find_package(Torch REQUIRED)

# Library with C and Fortran bindings
add_library(${LIB_NAME} SHARED ctorch.cpp ftorch.F90 ftorch_test_utils.f90)
add_library(${LIB_NAME} SHARED src/ctorch.cpp src/ftorch.F90
src/ftorch_test_utils.f90)

if(UNIX)
if(NOT APPLE) # only add definition for linux (not apple which is also unix)
Expand All @@ -66,7 +67,7 @@ endif()
add_library(${PROJECT_NAME}::${LIB_NAME} ALIAS ${LIB_NAME})
# cmake-format: off
set_target_properties(
${LIB_NAME} PROPERTIES PUBLIC_HEADER "ctorch.h"
${LIB_NAME} PROPERTIES PUBLIC_HEADER "src/ctorch.h"
Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/modules")
# cmake-format: on
# Link TorchScript
Expand Down Expand Up @@ -118,25 +119,5 @@ if(CMAKE_BUILD_TESTS)
endif()

# Integration tests
file(MAKE_DIRECTORY test/examples)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../examples/CMakeLists.txt
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/test/examples)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../examples/1_SimpleNet
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/test/examples)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../examples/2_ResNet18
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/test/examples)
if(ENABLE_CUDA)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../examples/3_MultiGPU
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/test/examples)
endif()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../examples/4_MultiIO
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/test/examples)
# NOTE: Example 5_Looping is built here but not run as part of the integration
# test suite. This is because it demonstrates 'good' versus 'bad'
# practice, as opposed to functionality.
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../examples/5_Looping
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/test/examples)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../examples/6_Autograd
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/test/examples)
add_subdirectory(test/examples)
add_subdirectory(examples)
endif()
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ To build and install the library:
git clone https://github.com/Cambridge-ICCS/FTorch.git
```
to clone via https.
2. Navigate to the source directory by running:
2. Navigate to the root FTorch directory by running:
```
cd FTorch/src/
cd FTorch/
```
3. Build the library using CMake with the relevant options from the table below:
```
Expand Down Expand Up @@ -248,7 +248,7 @@ instructions to modify, build, and run as necessary.

For information on testing, see the corresponding
[webpage](https://cambridge-iccs.github.io/FTorch/page/testing.html)
or the [`README` in the `test` subdirectory](src/test/README.md).
or the [`README` in the `test` subdirectory](test/README.md).

## License

Expand Down
4 changes: 2 additions & 2 deletions pages/cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Installation and Build Process

Installation of FTorch is done by CMake.

This is controlled by the `CMakeLists.txt` file in `src/`.
This is controlled by the `CMakeLists.txt` file in the root FTorch directory.

## Dependencies

Expand All @@ -19,7 +19,7 @@ To install the library requires the following to be installed on the system:

To build the library, first clone it from GitHub to your local machine and then run:
```
cd FTorch/src/
cd FTorch/
mkdir build
cd build
```
Expand Down
4 changes: 2 additions & 2 deletions pages/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ argument:
./run_test_suite.sh --integration-only
```
or individually by navigating to the corresponding subdirectory of
`${BUILD_DIR}/test/examples` (where `${BUILD_DIR}` is the build directory for
`${BUILD_DIR}/examples` (where `${BUILD_DIR}` is the build 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.
Expand All @@ -81,7 +81,7 @@ a suite with the command
./run_test_suite.bat
```
or individually by navigating to the corresponding subdirectory of
`${BUILD_DIR}/test/examples` (where `${BUILD_DIR}` is the build directory for
`${BUILD_DIR}/examples` (where `${BUILD_DIR}` is the build 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 change: 0 additions & 1 deletion pages/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ 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 ^
Expand Down
23 changes: 23 additions & 0 deletions pages/updates.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
title: Recent API Changes

## February 2025

If you use a version of FTorch from before commit
[f7fbebf](f7fbebfdad2a4801f57742a2bb12bc21e70881ff)
(February 2025) you will notice that the main `CMakeLists.txt` file has moved
from `src/` to the root level of the FTorch repository. This move was mainly to
simplify the development experience, such that the examples could be built as
integration tests as part of FTorch, without needing to copy the examples into
a subdirectory of `src/` (as was done previously). For consistency, the other
tests have also been moved from `src/tests/` to `tests/`, with the
`run_test_suite` scripts updated appropriately.

The only difference most users should need to take account of is that the build
directory should no longer be within `src/`. Instead, simply create the build
directory in the root level of the FTorch repository. For example:
```sh
cd /path/to/FTorch
rm -rf build
mkdir build
cd build
cmake .. <CMAKE_ARGUMENTS>
```

## January 2025

If you use a version of FTorch from before commit
Expand Down
4 changes: 2 additions & 2 deletions run_test_suite.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ 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 See `test/README.md` for more details on integration testing.
rem ---

rem NOTE: This version of run_test_suite only runs the integration tests, not
rem the unit tests. These are not currently supported on Windows.

for /d %%i in (1_SimpleNet 2_ResNet18 4_MultiIO) do (
pushd src\build\test\examples\%%i
pushd build\examples\%%i
rem run the tests
ctest
rem The following line will propagate the error back to the cmd shell
Expand Down
10 changes: 5 additions & 5 deletions run_test_suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# The `BUILD_DIR` variable in this script should be updated as appropriate for
# your configuration.
#
# See `src/test/README.md` for more details on the test suite.
# See `test/README.md` for more details on the test suite.
# ---

set -eu
Expand All @@ -18,15 +18,15 @@ show_help() {
echo " [--verbose | -V] [--help | h]"
echo
echo "Options:"
echo " BUILD_DIR=<build_dir> Specify the build directory (default: src/build)."
echo " BUILD_DIR=<build_dir> Specify the build directory (default: build)."
echo " --integration-only | -i Run integration tests only."
echo " --unit-only | -u Run unit tests only."
echo " --verbose | -V Run with verbose ctest output."
echo " --help | -h Show this help message and exit."
}

# Parse command line arguments
BUILD_DIR="src/build"
BUILD_DIR="build"
RUN_INTEGRATION=true
RUN_UNIT=true
VERBOSE=false
Expand Down Expand Up @@ -82,15 +82,15 @@ fi

# Run integration tests
if [ "${RUN_INTEGRATION}" = true ]; then
if [ -e "${BUILD_DIR}/test/examples/3_MultiGPU" ]; then
if [ -e "${BUILD_DIR}/examples/3_MultiGPU" ]; then
EXAMPLES="1_SimpleNet 2_ResNet18 3_MultiGPU 4_MultiIO 6_Autograd"
else
EXAMPLES="1_SimpleNet 2_ResNet18 4_MultiIO 6_Autograd"
fi
export PIP_REQUIRE_VIRTUALENV=true
for EXAMPLE in ${EXAMPLES}; do
python -m pip -q install -r examples/"${EXAMPLE}"/requirements.txt
cd "${BUILD_DIR}"/test/examples/"${EXAMPLE}"
cd "${BUILD_DIR}"/examples/"${EXAMPLE}"
ctest "${CTEST_ARGS}"
cd -
done
Expand Down
4 changes: 2 additions & 2 deletions src/test/README.md → test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ when building FTorch.
## Running

Having built the unit and integration tests, ensure the Python virtual
environment is active and run them by going to `src/build/test/unit` or the
corresponding subdirectory of `src/build/test/examples` and calling `ctest`.
environment is active and run them by going to `build/test/unit` or the
corresponding subdirectory of `build/test/examples` and calling `ctest`.
This will produce a report on which tests passed and which failed for your
build. Note that the examples have additional dependencies, which may need
installing into your virtual environment.
Expand Down
File renamed without changes.
File renamed without changes.