Skip to content

Commit

Permalink
Consistent case for Python, Fortran, C, C++, CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 authored and jatkinson1000 committed Apr 2, 2024
1 parent 0efa2ba commit cacf522
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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.1
* CMake >= 3.1
* [libtorch](https://pytorch.org/cppdocs/installing.html)<sup>*</sup> or [PyTorch](https://pytorch.org/)
* Fortran, C++ (must fully support C++17), and C compilers

Expand Down Expand Up @@ -133,12 +133,12 @@ To build and install the library:

<sup>1</sup> _On Windows this may need to be the full path to the compiler if CMake cannot locate it by default._

<sup>2</sup> _The path to the Torch installation needs to allow cmake to locate the relevant Torch cmake files.
<sup>2</sup> _The path to the Torch installation needs to allow CMake to locate the relevant Torch CMake files.
If Torch has been [installed as libtorch](https://pytorch.org/cppdocs/installing.html)
then this should be the absolute path to the unzipped libtorch distribution.
If Torch has been installed as PyTorch in a python [venv (virtual environment)](https://docs.python.org/3/library/venv.html),
If Torch has been installed as PyTorch in a Python [venv (virtual environment)](https://docs.python.org/3/library/venv.html),
e.g. with `pip install torch`, then this should be `</path/to/venv/>lib/python<3.xx>/site-packages/torch/`.
You can find the location of your torch install by importing torch from your python environment (`import torch`) and running `print(torch.__file__)`_
You can find the location of your torch install by importing torch from your Python environment (`import torch`) and running `print(torch.__file__)`_
4. Make and install the library to the desired location with either:
```
Expand All @@ -150,7 +150,7 @@ To build and install the library:
cmake --install .
```

Note: If you are using cmake<3.15 then you will need to build and install separately
Note: If you are using CMake < 3.15 then you will need to build and install separately
using the make system specific commands.
For example, if using `make` on UNIX this would be:
```
Expand Down
16 changes: 8 additions & 8 deletions examples/1_SimpleNet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ covered in later examples.

## Description

A python file `simplenet.py` is provided that defines a very simple PyTorch 'net' that takes an input
A Python file `simplenet.py` is provided that defines a very simple PyTorch 'net' that takes an input
vector of length 5 and applies a single `Linear` layer to multiply it by 2.

A modified version of the `pt2ts.py` tool saves this simple net to TorchScript.
Expand All @@ -21,15 +21,15 @@ TorchScript model in inference mode.

To run this example requires:

- cmake
- fortran compiler
- CMake
- Fortran compiler
- FTorch (installed as described in main package)
- python3
- Python 3

## Running

To run this example install FTorch as described in the main documentation.
Then from this directory create a virtual environment and install the necessary python
Then from this directory create a virtual environment and install the necessary Python
modules:
```
python3 -m venv venv
Expand Down Expand Up @@ -63,12 +63,12 @@ This reads the model in from the TorchScript file and runs it with an input tens
tensor([[0, 2, 4, 6, 8]])
```

At this point we no longer require python, so can deactivate the virtual environment:
At this point we no longer require Python, so can deactivate the virtual environment:
```
deactivate
```

To call the saved SimpleNet model from fortran we need to compile the `simplenet_infer`
To call the saved SimpleNet model from Fortran we need to compile the `simplenet_infer`
files.
This can be done using the included `CMakeLists.txt` as follows:
```
Expand All @@ -89,7 +89,7 @@ This runs the model with the array `[0.0, 1.0, 2.0, 3.0, 4.0]` should produce th
0.00000000 2.00000000 4.00000000 6.00000000 8.00000000
```

Alternatively we can use `make`, instead of cmake, with the included Makefile.
Alternatively we can use `make`, instead of CMake, with the included Makefile.
However, to do this you will need to modify `Makefile` to link to and include your
installation of FTorch as described in the main documentation. Also check that the compiler is the same as the one you built the Library with.
```
Expand Down
16 changes: 8 additions & 8 deletions examples/2_ResNet18/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ As the input to this model is four-dimensional (batch size, colour, x, y), care

## Description

A python file is provided that downloads the pretrained
A Python file is provided that downloads the pretrained
[ResNet-18](https://pytorch.org/vision/main/models/generated/torchvision.models.resnet18.html)
model from [TorchVision](https://pytorch.org/vision/stable/index.html).

Expand All @@ -19,15 +19,15 @@ TorchScript ResNet-18 model in inference mode.

To run this example requires:

- cmake
- fortran compiler
- CMake
- Fortran compiler
- FTorch (installed as described in main package)
- python3
- Python 3

## Running

To run this example install FTorch as described in the main documentation.
Then from this directory create a virtual environment an install the neccessary python
Then from this directory create a virtual environment an install the neccessary Python
modules:
```
python3 -m venv venv
Expand Down Expand Up @@ -59,12 +59,12 @@ To save the pretrained ResNet-18 model to TorchScript run the modified version o
python3 pt2ts.py
```

At this point we no longer require python, so can deactivate the virtual environment:
At this point we no longer require Python, so can deactivate the virtual environment:
```
deactivate
```

To call the saved ResNet-18 model from fortran we need to compile the `resnet_infer`
To call the saved ResNet-18 model from Fortran we need to compile the `resnet_infer`
files.
This can be done using the included `CMakeLists.txt` as follows:
```
Expand All @@ -89,7 +89,7 @@ This should produce the same top result:
```


Alternatively we can use `make`, instead of cmake, with the included Makefile.
Alternatively we can use `make`, instead of CMake, with the included Makefile.
However, to do this you will need to modify `Makefile` to link to and include your
installation of FTorch as described in the main documentation. Also check that the compiler is the same as the one you built the Library with.
You will also likely need to add the location of the `.so` files to your `LD_LIBRARY_PATH`:
Expand Down
12 changes: 6 additions & 6 deletions examples/3_MultiGPU/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ multiple GPU devices.

## Description

The same python file `simplenet.py` is used from the earlier example. Recall that it
The same Python file `simplenet.py` is used from the earlier example. Recall that it
defines a very simple PyTorch network that takes an input of length 5 and applies a
single `Linear` layer to multiply it by 2.

Expand All @@ -19,16 +19,16 @@ TorchScript model in inference mode.

To run this example requires:

- cmake
- CMake
- An MPI installation.
- mpif90
- FTorch (installed as described in main package)
- python3
- Python 3

## Running

To run this example install FTorch as described in the main documentation. Then from
this directory create a virtual environment and install the necessary python modules:
this directory create a virtual environment and install the necessary Python modules:
```
python3 -m venv venv
source venv/bin/activate
Expand Down Expand Up @@ -70,7 +70,7 @@ entry. The result should be (some permutation of):
3: tensor([[ 6., 8., 10., 12., 14.]])
```

At this point we no longer require python, so can deactivate the virtual environment:
At this point we no longer require Python, so can deactivate the virtual environment:
```
deactivate
```
Expand Down Expand Up @@ -105,7 +105,7 @@ output on rank2: [ 4.0, 6.0, 8.0, 10.0, 12.0]
output on rank3: [ 6.0, 8.0, 10.0, 12.0, 14.0]
```

Alternatively, we can use `make`, instead of cmake, copying the Makefile over from the
Alternatively, we can use `make`, instead of CMake, copying the Makefile over from the
first example:
```
cp ../1_SimpleNet/Makefile .
Expand Down
24 changes: 12 additions & 12 deletions examples/n_c_and_cpp/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Example n - ResNet-18 for c and c++
# Example n - ResNet-18 for C and C++

**Note: This Example is not currently functional and is still being developed.**

This example provides a demonstration of how to use the library to interface to c and c++.
This example provides a demonstration of how to use the library to interface to C and C++.

## Description

A python file is provided that downloads the pretrained
A Python file is provided that downloads the pretrained
[ResNet-18](https://pytorch.org/vision/main/models/generated/torchvision.models.resnet18.html)
model from [TorchVision](https://pytorch.org/vision/stable/index.html).

Expand All @@ -19,16 +19,16 @@ TorchScript ResNet-18 model in inference mode.

To run this example requires:

- cmake
- c compiler
- c++ compiler
- CMake
- C compiler
- C++ compiler
- FTorch (installed as described in main package)
- python3
- Python 3

## Running

To run this example install FTorch as described in the main documentation.
Then from this directory create a virtual environment an install the neccessary python
Then from this directory create a virtual environment an install the neccessary Python
modules:
```
python3 -m venv venv
Expand All @@ -48,12 +48,12 @@ To save the pretrained ResNet-18 model to TorchScript run the modified version o
python3 pt2ts.py
```

At this point we no longer require python, so can deactivate the virtual environment:
At this point we no longer require Python, so can deactivate the virtual environment:
```
deactivate
```

To call the saved ResNet-18 model from fortran we need to compile the `resnet_infer`
To call the saved ResNet-18 model from Fortran we need to compile the `resnet_infer`
files.
This can be done using the included `CMakeLists.txt` as follows:
```
Expand Down Expand Up @@ -86,7 +86,7 @@ language you wish
* ctorch.h - Header file for C++ wrapper
* ftorch.f90 - Wrapper onto PyTorch for Fortran

* CMakeLists.txt - Provides the cmake build system configuration
* CMakeLists.txt - Provides the CMake build system configuration



Expand All @@ -96,7 +96,7 @@ language you wish
make

This will build the separate examples. Next, from this directory, you need
to run the python code to generate the saved model:
to run the Python code to generate the saved model:

python3 ../pt2ts.py

Expand Down
2 changes: 1 addition & 1 deletion pages/cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The following CMake flags are available and can be passed as arguments through `
> <sup>2</sup> _The path to the Torch installation needs to allow CMake to locate the relevant Torch CMake files.
> If Torch has been [installed as libtorch](https://pytorch.org/cppdocs/installing.html)
> then this should be the absolute path to the unzipped libtorch distribution.
> If Torch has been installed as PyTorch in a python [venv (virtual environment)](https://docs.python.org/3/library/venv.html),
> If Torch has been installed as PyTorch in a Python [venv (virtual environment)](https://docs.python.org/3/library/venv.html),
> e.g. with `pip install torch`, then this should be `</path/to/venv/>lib/python<3.xx>/site-packages/torch/`._
>
> <sup>3</sup> _This is often overridden by PyTorch. When installing with pip, the `index-url` flag can be used to ensure a CPU or GPU only version is installed, e.g.
Expand Down
2 changes: 1 addition & 1 deletion pages/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This can be done from within your code using the
[`jit.script`](https://pytorch.org/docs/stable/generated/torch.jit.script.html#torch.jit.script)
or
[`jit.trace`](https://pytorch.org/docs/stable/generated/torch.jit.trace.html#torch.jit.trace)
functionalities from within python.
functionalities from within Python.

If you are not familiar with these we provide a tool
[`pt2ts.py`](https://github.com/Cambridge-ICCS/FTorch/blob/main/utils/pt2ts.py)
Expand Down
4 changes: 2 additions & 2 deletions pages/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ From CMD this can be done with:
"C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
```

Finally you will need to add `-G "NMake Makefiles"` to the cmake command in the
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:
```
Expand All @@ -49,7 +49,7 @@ cmake --install .

It may be tempting to build on Windows using MinGW.
However, [libtorch does not currently support MinGW](https://github.com/pytorch/pytorch/issues/15099).
Instead please build using Visual Studio and the intel fortran compiler (ifort) as
Instead please build using Visual Studio and the intel Fortran compiler (ifort) as
detailed in the project README.

## Apple Silicon
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ To build, follow the instructions in the [main repository README](/README.md).
* ctorch.cpp - Wrapper onto PyTorch for C++
* ctorch.h - Header file for C++ wrapper
* ftorch.f90 - Wrapper onto PyTorch for Fortran
* CMakeLists.txt - Provides the cmake build system configuration
* CMakeLists.txt - Provides the CMake build system configuration

0 comments on commit cacf522

Please sign in to comment.