{"id":17981009,"url":"https://github.com/nvidia/numbast","last_synced_at":"2025-03-25T18:31:03.459Z","repository":{"id":232307439,"uuid":"775078696","full_name":"NVIDIA/numbast","owner":"NVIDIA","description":"Numbast is a tool to build an automated pipeline that converts CUDA APIs into Numba bindings.","archived":false,"fork":false,"pushed_at":"2025-03-18T18:24:56.000Z","size":6533,"stargazers_count":36,"open_issues_count":23,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-18T19:42:10.226Z","etag":null,"topics":["cuda","numba"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NVIDIA.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-20T18:09:39.000Z","updated_at":"2025-03-11T23:36:17.000Z","dependencies_parsed_at":"2024-12-04T12:30:53.941Z","dependency_job_id":"d0d3ec77-e889-4364-a3db-c5be947add3c","html_url":"https://github.com/NVIDIA/numbast","commit_stats":null,"previous_names":["nvidia/numbast"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA%2Fnumbast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA%2Fnumbast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA%2Fnumbast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA%2Fnumbast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NVIDIA","download_url":"https://codeload.github.com/NVIDIA/numbast/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245519908,"owners_count":20628791,"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":["cuda","numba"],"created_at":"2024-10-29T18:07:19.388Z","updated_at":"2025-03-25T18:31:03.446Z","avatar_url":"https://github.com/NVIDIA.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Numbast\n\n## Overview\nNumbast = Numba + AST (Abstract Syntax Tree)\n\nNumbast's mission is to establish an automated pipeline that converts CUDA APIs into Numba bindings. On a high level, top-level declarations are read from CUDA C++ header files, serialized as string and passed to python APIs. Numba binding generators then iterate through these bindings and make Numba extensions for each of the APIs.\n\nThere are several subcomponents: AST_Canopy, Numbast and a set of Numba Extensions\n\n- [ast_canopy](ast_canopy/README.md): CUDA Header Parser that depends on clangTooling\n- [numbast](numbast/README.md): Numba Binding Generator\n- [numbast_extensions](numbast_extensions/README.md): a set of Numba bindings for several CUDA libraries using Numbast\n\n## Get Started\n\nFirst, install conda environment and activate:\n\n```bash\nconda env create -f conda/environment.yaml \u0026\u0026 \\\n  conda activate numbast\n```\n\nNext, install all subcomponents:\n\n```bash\nbash ast_canopy/build.sh\npip install numbast/ \\\n  numbast_extensions/bf16 \\\n  numbast_extensions/fp16 \\\n  numbast_extensions/curand_device \\\n  numbast_extensions/curand_host\n```\n\nValidate the installation by running the tests:\n\n```bash\npytest ast_canopy/ numbast_extensions/\n```\n\n### Example\n\nGiven a C++ struct (or function) declaration:\n```c++\nstruct __attribute__((aligned(2))) __myfloat16\n{\nprivate:\n  half data;\n\npublic:\n  __host__ __device__ __myfloat16();\n\n  __host__ __device__ __myfloat16(double val);\n\n  __host__ __device__ operator double() const;\n};\n\n__host__ __device__ __myfloat16 operator+(const __myfloat16 \u0026lh, const __myfloat16 \u0026rh);\n\n__device__ __myfloat16 hsqrt(const __myfloat16 a);\n```\n\nNumbast can convert it into Numba bindings:\n\n```python\nimport os\nfrom ast_canopy import parse_declarations_from_source\nfrom numbast import bind_cxx_struct, bind_cxx_function, MemoryShimWriter\n\nfrom numba import types, cuda\nfrom numba.core.datamodel.models import PrimitiveModel\n\nimport numpy as np\n\n# Use `AST_Canopy` to parse demo.cuh as AST, read all declarations from it.\nsource = os.path.join(os.path.dirname(__file__), \"demo.cuh\")\n# Assume your machine has a GPU that supports \"sm_80\" compute capability,\n# parse the header with sm_80 compute capability.\ndecls = parse_declarations_from_source(source, [source], \"sm_80\")\n\nshim_writer = MemoryShimWriter(f'#include \"{source}\"')\n\n# Make Numba bindings from the declarations.\n# New type \"myfloat16\" is a Number type, data model is PrimitiveModel.\nmyfloat16 = bind_cxx_struct(shim_writer, decls.structs[0], types.Number, PrimitiveModel)\nbind_cxx_function(shim_writer, decls.functions[0])\nhsqrt = bind_cxx_function(shim_writer, decls.functions[1])\n```\n\n`myfloat16` struct can now be used within Numba:\n\n```python\n@cuda.jit(link=shim_writer.links())\ndef kernel(arr):\n    one = myfloat16(1.0)\n    two = myfloat16(2.0)\n    three = one + two\n    sqrt3 = hsqrt(three)\n    arr[0] = types.float64(three)\n    arr[1] = types.float64(sqrt3)\n\n\narr = np.array([0.0, 0.0], dtype=np.float64)\nkernel[1, 1](arr)\n\nnp.testing.assert_allclose(arr, [3.0, np.sqrt(3.0)], rtol=1e-2)\n```\n\nSee detail of test in [demo tests](./numbast/tests/demo/).\n\n## Contribution Guidelines\nSee [CONTRIBUTING.md](./CONTRIBUTING.md)\n\n## Community\nDiscussions are welcome! If you spotted bugs / have idea for new features, please submit at the issue board.\n\n## References\nThe project depends on [Clang](https://github.com/llvm/llvm-project) and [Numba](https://numba.readthedocs.io/en/stable/)\n\n## License\nThis project is licensed under the Apache 2.0 License - see the LICENSE.md file for details\n\n## Key Visual\n\nThe numbat (Myrmecobius fasciatus) is a small, endangered marsupial native to Western Australia.\n\n![Australian Numbat](./static/numbat.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnvidia%2Fnumbast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnvidia%2Fnumbast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnvidia%2Fnumbast/lists"}