{"id":18847673,"url":"https://github.com/lkedward/focal","last_synced_at":"2026-02-12T04:33:46.760Z","repository":{"id":46301020,"uuid":"218028719","full_name":"LKedward/focal","owner":"LKedward","description":"A modern Fortran abstraction layer for OpenCL","archived":false,"fork":false,"pushed_at":"2023-07-14T14:35:04.000Z","size":2592,"stargazers_count":41,"open_issues_count":5,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-23T00:33:00.461Z","etag":null,"topics":["fortran","fortran-library","fortran-modules","fortran2003","fortran2008","opencl","opencl-api"],"latest_commit_sha":null,"homepage":"https://lkedward.github.io/focal-docs","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LKedward.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-28T11:13:11.000Z","updated_at":"2025-05-01T20:45:33.000Z","dependencies_parsed_at":"2025-02-20T05:39:27.350Z","dependency_job_id":null,"html_url":"https://github.com/LKedward/focal","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/LKedward/focal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKedward%2Ffocal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKedward%2Ffocal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKedward%2Ffocal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKedward%2Ffocal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LKedward","download_url":"https://codeload.github.com/LKedward/focal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKedward%2Ffocal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271588743,"owners_count":24785751,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","fortran-library","fortran-modules","fortran2003","fortran2008","opencl","opencl-api"],"created_at":"2024-11-08T03:09:12.573Z","updated_at":"2026-02-12T04:33:41.693Z","avatar_url":"https://github.com/LKedward.png","language":"Fortran","readme":"# Focal\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![fpm test](https://github.com/LKedward/focal/actions/workflows/test.yml/badge.svg)](https://github.com/LKedward/focal/actions)\n[![codecov](https://codecov.io/gh/LKedward/focal/branch/v1.0rc/graph/badge.svg)](https://codecov.io/gh/LKedward/focal)\n\n## *A modern Fortran abstraction layer for OpenCL*\nFocal is a module library which wraps calls to the OpenCL runtime API (using [clfortran](https://github.com/cass-support/clfortran)) with a higher abstraction level appropriate to the Fortran language.\n\nThe goal of Focal is to provide a concise and accessible Fortran interface to the OpenCL API while retaining the full functionality thereof.\nThis is desirable in Fortran which as a language provides a higher level of abstraction than C; importantly this allows scientists and engineers to focus on their domain specific problem rather than details of low-level implementation.\n\n__Key features:__\n\n* Removes use of c pointers to call OpenCL API\n* Provides a level of type safety using typed buffer objects\n* Decreases verbosity of OpenCL API calls while still providing the same functionality\n* Abstracts away low level details, such as size in bytes\n* Contains built-in customisable error handling for all OpenCL API calls\n* Contains built-in 'debug' mode for checking program correctness\n* Contains build-in routines for collecting and presented profiling information\n\n__Project status:__ v1.0.1 stable release\n\n__Documentation__: [lkedward.github.io/focal-docs](https://lkedward.github.io/focal-docs/)\n\n__License__: [MIT](./LICENSE)\n\n__Prerequisites:__\n\n- [GNU make](https://www.gnu.org/software/make/) utility\n- Fortran compiler supporting the 2008 standard (tested in the CI with `gfortran` 9.3.0 and `ifort` (oneAPI) 21.3.0 )\n- An OpenCL development library (One of:\n[Intel OpenCL SDK](https://software.intel.com/en-us/opencl-sdk),\n[NVIDIA CUDA Toolkit](https://developer.nvidia.com/cuda-downloads),\n[AMD Radeon Software](https://www.amd.com/en/support) )\n\n\n## Getting started\n\n* [Building the Focal Library](https://lkedward.github.io/focal-docs/build)\n* [Using and linking Focal](https://lkedward.github.io/focal-docs/linking/)\n* [Quickstart programming guide](https://lkedward.github.io/focal-docs/quickstart/)\n* [Example programs](./examples)\n* [Lattice Boltzmann demo](https://github.com/LKedward/lbm2d_opencl)\n\n## Quick example\nThe following fortran program calculates the sum of two large arrays using an OpenCL kernel.\n\n```fortran\nprogram sum\n!! Focal example program: calculate the sum of two arrays on an OpenCL device\n\nuse Focal\nimplicit none\n\ninteger, parameter :: Nelem = 1E6           ! No. of array elements\nreal, parameter :: sumVal = 10.0            ! Target value for array sum\n\ninteger :: i                                ! Counter variable\ncharacter(:), allocatable :: kernelSrc      ! Kernel source string\ntype(fclDevice) :: device                   ! Device object\ntype(fclProgram) :: prog                    ! Focal program object\ntype(fclKernel) :: sumKernel                ! Focal kernel object\nreal :: array1(Nelem)                       ! Host array 1\nreal :: array2(Nelem)                       ! Host array 2\ntype(fclDeviceFloat) :: array1_d            ! Device array 1\ntype(fclDeviceFloat) :: array2_d            ! Device array 2\n\n! Select device with most cores and create command queue\ndevice = fclInit(vendor='nvidia',sortBy='cores')\ncall fclSetDefaultCommandQ(fclCreateCommandQ(device,enableProfiling=.true.))\n\n! Load kernel from file and compile\ncall fclSourceFromFile('examples/sum.cl',kernelSrc)\nprog = fclCompileProgram(kernelSrc)\nsumKernel = fclGetProgramKernel(prog,'sum')\n\n! Initialise device arrays\ncall fclInitBuffer(array1_d,Nelem)\ncall fclInitBuffer(array2_d,Nelem)\n\n! Initialise host array data\ndo i=1,Nelem\n  array1(i) = i\nend do\narray2 = sumVal - array1\n\n! Copy data to device\narray1_d = array1\narray2_d = array2\n\n! Set global work size equal to array length and launch kernel\nsumKernel%global_work_size(1) = Nelem\ncall sumKernel%launch(Nelem,array1_d,array2_d)\n\n! Copy result back to host and print out to check\narray2 = array2_d\nwrite(*,*) array2(1), array2(size(array2,1))\n\nend program sum\n```\n\nWhere `sum.cl` contains the following openCL kernel:\n```openCL\n__kernel void sum(const int nElem, const __global float * v1, __global float * v2){\n  int i = get_global_id(0);\n  if(i \u003c nElem) v2[i] += v1[i];\n}\n```\n\n## Bundled third-party sources\n\nThe following open source libraries are used as dependencies and bundled in the repository ([./external](https://github.com/LKedward/focal/tree/master/external)):\n\n* [fortran-utils](https://github.com/certik/fortran-utils)/[sorting](https://github.com/certik/fortran-utils/blob/master/src/sorting.f90) (MIT license)\n\n* [clfortran](https://github.com/cass-support/clfortran) (LGPL)\n\n* [M_strings](https://github.com/urbanjost/M_strings) (Unlicense/Public domain)\n\n## Acknowledgement\n\n_This work was funded by the MENtOR project, a UKVLN project\nsupported by the Engineering and Physical Sciences Research\nCouncil (EPSRC) of the UK. Grant reference number\nEP/S010378/1_.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flkedward%2Ffocal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flkedward%2Ffocal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flkedward%2Ffocal/lists"}