diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index 303929aa..8c25dcaf 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -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 diff --git a/.github/workflows/test_suite_ubuntu.yml b/.github/workflows/test_suite_ubuntu.yml index d0a9626a..aab34ede 100644 --- a/.github/workflows/test_suite_ubuntu.yml +++ b/.github/workflows/test_suite_ubuntu.yml @@ -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} diff --git a/.github/workflows/test_suite_windows.yml b/.github/workflows/test_suite_windows.yml index f63afe2b..c99e8ee3 100644 --- a/.github/workflows/test_suite_windows.yml +++ b/.github/workflows/test_suite_windows.yml @@ -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 ^ diff --git a/.gitignore b/.gitignore index e593292d..fe627d29 100644 --- a/.gitignore +++ b/.gitignore @@ -87,7 +87,6 @@ coverage.xml .pytest_cache/ cover/ Testing/ -src/test/examples # Translations *.mo diff --git a/src/CMakeLists.txt b/CMakeLists.txt similarity index 71% rename from src/CMakeLists.txt rename to CMakeLists.txt index 7bc29e8b..ead82aac 100644 --- a/src/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 @@ -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() diff --git a/README.md b/README.md index c0d52c88..393f20ab 100644 --- a/README.md +++ b/README.md @@ -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: ``` @@ -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 diff --git a/pages/cmake.md b/pages/cmake.md index b83626d9..6ea13407 100644 --- a/pages/cmake.md +++ b/pages/cmake.md @@ -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 @@ -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 ``` diff --git a/pages/testing.md b/pages/testing.md index a8ea51a9..aa76ee15 100644 --- a/pages/testing.md +++ b/pages/testing.md @@ -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. @@ -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. diff --git a/pages/troubleshooting.md b/pages/troubleshooting.md index 28132ca3..e41c2b8b 100644 --- a/pages/troubleshooting.md +++ b/pages/troubleshooting.md @@ -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 ^ diff --git a/pages/updates.md b/pages/updates.md index f3d76cfe..f0ca4319 100644 --- a/pages/updates.md +++ b/pages/updates.md @@ -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 .. +``` + ## January 2025 If you use a version of FTorch from before commit diff --git a/run_test_suite.bat b/run_test_suite.bat index 73ef49aa..601889a9 100644 --- a/run_test_suite.bat +++ b/run_test_suite.bat @@ -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 diff --git a/run_test_suite.sh b/run_test_suite.sh index 31a7bb87..755c419a 100755 --- a/run_test_suite.sh +++ b/run_test_suite.sh @@ -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 @@ -18,7 +18,7 @@ show_help() { echo " [--verbose | -V] [--help | h]" echo echo "Options:" - echo " BUILD_DIR= Specify the build directory (default: src/build)." + echo " 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." @@ -26,7 +26,7 @@ show_help() { } # Parse command line arguments -BUILD_DIR="src/build" +BUILD_DIR="build" RUN_INTEGRATION=true RUN_UNIT=true VERBOSE=false @@ -82,7 +82,7 @@ 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" @@ -90,7 +90,7 @@ if [ "${RUN_INTEGRATION}" = true ]; then 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 diff --git a/src/test/README.md b/test/README.md similarity index 90% rename from src/test/README.md rename to test/README.md index 94222c52..085a444e 100644 --- a/src/test/README.md +++ b/test/README.md @@ -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. diff --git a/src/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt similarity index 100% rename from src/test/unit/CMakeLists.txt rename to test/unit/CMakeLists.txt diff --git a/src/test/unit/README.md b/test/unit/README.md similarity index 100% rename from src/test/unit/README.md rename to test/unit/README.md diff --git a/src/test/unit/test_tensor_constructors.pf b/test/unit/test_tensor_constructors.pf similarity index 100% rename from src/test/unit/test_tensor_constructors.pf rename to test/unit/test_tensor_constructors.pf diff --git a/src/test/unit/test_tensor_interrogation.pf b/test/unit/test_tensor_interrogation.pf similarity index 100% rename from src/test/unit/test_tensor_interrogation.pf rename to test/unit/test_tensor_interrogation.pf diff --git a/src/test/unit/test_tensor_interrogation_cuda.pf b/test/unit/test_tensor_interrogation_cuda.pf similarity index 100% rename from src/test/unit/test_tensor_interrogation_cuda.pf rename to test/unit/test_tensor_interrogation_cuda.pf diff --git a/src/test/unit/test_tensor_operator_overloads.pf b/test/unit/test_tensor_operator_overloads.pf similarity index 100% rename from src/test/unit/test_tensor_operator_overloads.pf rename to test/unit/test_tensor_operator_overloads.pf