{"id":16476422,"url":"https://github.com/luc99hen/fta","last_synced_at":"2025-03-21T07:30:24.284Z","repository":{"id":182699726,"uuid":"405651340","full_name":"luc99hen/FTA","owner":"luc99hen","description":"An Adapter aimed for using a PyTorch model directly from a Fortran program","archived":false,"fork":false,"pushed_at":"2024-07-10T05:52:25.000Z","size":42729,"stargazers_count":17,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-17T22:21:17.320Z","etag":null,"topics":["fortran","libtorch","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luc99hen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-09-12T13:36:53.000Z","updated_at":"2025-03-17T14:54:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"e9071cd6-1ba2-4b11-a40f-224c9f0b484f","html_url":"https://github.com/luc99hen/FTA","commit_stats":null,"previous_names":["luc99hen/fta"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luc99hen%2FFTA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luc99hen%2FFTA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luc99hen%2FFTA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luc99hen%2FFTA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luc99hen","download_url":"https://codeload.github.com/luc99hen/FTA/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244757013,"owners_count":20505301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fortran","libtorch","pytorch"],"created_at":"2024-10-11T12:42:27.818Z","updated_at":"2025-03-21T07:30:21.318Z","avatar_url":"https://github.com/luc99hen.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"FTA is a Fortran-Torch-Adapter aimed for integrating deep learning model into Fortran environment. It has been used in replacing parameterization schemes in WRF with a [published paper](https://www.frontiersin.org/journals/earth-science/articles/10.3389/feart.2023.1149566/full)\n\n```Fortran\n! fortran program main\n! \n! use PyTorch modle resnet.pt in a Fortran program with FTA library torch_wrapper\n!\n\nprogram  main\n    use torch_wrapper\n    implicit none\n\n    CHARACTER(100), TARGET :: model_loc;\n    TYPE(ftorchmodel) :: model;\n    INTEGER :: res\n    REAL(C_float) :: input(1, 3, 224, 224) = 1.0\n    REAL :: output(1, 1000)\n    INTEGER(C_INT) :: use_gpu = 1                  ! should be compatible with your script module device\n\n\n    model_loc = \"/home/dl/luc/FTB/demo/lib/resnet.pt\"//CHAR(0)  ! CHAR(0) is necessary for C string termination \n\n    print *, \"Torch Start\"\n\n    model = resnet18_new(model_loc, use_gpu)        ! initialize the model\n    res = resnet18_forward(model, input, output)    ! use the model to perform reasoning task\n    call resnet18_delete(model)                     ! delete this model\n\n    print *, output(1, 1)\n    print *, \"Torch End\"\n\nend program  main\n```\n\n# Dependencies\n\n- CMake (\u003e=3.0)\n- gcc or icc compiler \n- [libtorch](https://pytorch.org/)\n- Docker \u0026 nvidia-container-toolkit (OPTIONAL)\n\n# How to Use\n\n\u003e Notice: we assume you already have a machine with Nvidia Driver installed properly.\n\n## Manually setup\n\n1. download libtorch \n    1. match your local CUDA version\n    2. C++11 ABI ([choose this version if your compiler is `icc`](https://stackoverflow.com/questions/66192285/libtorch-works-with-g-but-fails-with-intel-compiler)) \n2. define your model in the [configuration file](./src/configure.conf)\n    - data type supported: float, int, double\n    - data size format: a, b, c\n    - model name: will be used for interface name\n3. run [`./build.sh`](./src/build.sh)\n4. use the `torch_wrapper` library in your Fortran program\n\n## Setup with Docker \n\n1. install [nvidia-container-toolkit \u0026 Docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#getting-started)\n2. get image \n    1. build locally `docker build -t fortran-torch-adapter .`\n    2. Or you can pull from dockerhub `docker pull 1813927768/fortran-torch-adapter:latest`\n3. start the container `docker run -it  --rm --gpus all fortran-torch-adapter /bin/bash`\n4. run `./build.sh` in the container\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluc99hen%2Ffta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluc99hen%2Ffta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluc99hen%2Ffta/lists"}