{"id":15414308,"url":"https://github.com/eliphatfs/torchoptix","last_synced_at":"2025-05-07T08:12:45.343Z","repository":{"id":257025918,"uuid":"856136275","full_name":"eliphatfs/torchoptix","owner":"eliphatfs","description":"Modular wrapper for using OptiX with PyTorch.","archived":false,"fork":false,"pushed_at":"2025-02-28T05:31:22.000Z","size":122,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-07T08:12:39.824Z","etag":null,"topics":["ease-of-use","optix","optix7","python","pytorch","raytracing"],"latest_commit_sha":null,"homepage":"","language":"C++","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/eliphatfs.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2024-09-12T03:50:27.000Z","updated_at":"2025-03-14T04:11:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"9e195a74-f3e5-4814-9e48-38a67425a246","html_url":"https://github.com/eliphatfs/torchoptix","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"1bc9f82ae55c854e44f10806d87611666e5ad8ed"},"previous_names":["eliphatfs/torchoptix"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliphatfs%2Ftorchoptix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliphatfs%2Ftorchoptix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliphatfs%2Ftorchoptix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliphatfs%2Ftorchoptix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eliphatfs","download_url":"https://codeload.github.com/eliphatfs/torchoptix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252839296,"owners_count":21812090,"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":["ease-of-use","optix","optix7","python","pytorch","raytracing"],"created_at":"2024-10-01T17:02:22.031Z","updated_at":"2025-05-07T08:12:45.324Z","avatar_url":"https://github.com/eliphatfs.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TorchOptiX\n\nModular wrapper for using OptiX with PyTorch.\n\n## Requirements\n\nMost requirements are the same as running OptiX.\n\n+ **Hardware:** All NVIDIA GPUs of Compute Capability 5.0 (Maxwell) or higher are supported.\n+ **Driver:** An driver version of R515+ is required. You may check with `nvidia-smi`.\n+ **Python:** 3.8 or higher.\n+ **PyTorch:** 2 or higher is recommended. May also work for older versions.\n\n### Running in containers like Docker\n\nTo run inside a container, you need to configure the driver for OptiX. You can choose from the following options:\n\n1. Set `ENV NVIDIA_DRIVER_CAPABILITIES compute,utility,graphics` and `ENV PYOPENGL_PLATFORM egl` in `Dockerfile` when building the image.\n2. Set `-e NVIDIA_DRIVER_CAPABILITIES=graphics,compute,utility` when creating the container.\n3. Copy or mount `/usr/lib/x86_64-linux-gnu/libnvoptix.so.\u003cversion\u003e` on the host or download a same version of the library to `/usr/lib/x86_64-linux-gnu/libnvoptix.so.1` in the container; copy `/usr/lib/x86_64-linux-gnu/libnvidia-rtcore.so.\u003cversion\u003e` on the host or download a same version of the library to `/usr/lib/x86_64-linux-gnu/libnvidia-rtcore.so.\u003cversion\u003e` in the container.\n\n## Installation\n\nStable release (Windows or Linux 64-bit):\n\n```bash\npip install torchoptix\n```\n\nThe wheel contains prebuilt binaries, and you do not need CUDA development toolkit to run the code.\n\nDevelopment (or if you are not using a common system supported by prebuilt binaries):\n\n```bash\npip install git+https://github.com/eliphatfs/torchoptix.git\n```\n\nYou will need to have `CUDA_HOME` set to compile or develop. The code does not depend on CUDA runtime libraries or `nvcc`, but needs CUDA driver API header and link libraries.\n\nTo regenerate resources for device code if you modified it in development:\n\n```\nbash generate.sh\n```\n\n## Usage\n\n### Example Wrapper\n\n```python\nimport torch\nfrom typing import Tuple\n\nclass TorchOptiX:\n    @torch.no_grad()\n    def __init__(self, verts: torch.Tensor, tris: torch.IntTensor) -\u003e None:\n        self.handle = None\n        import torchoptix\n        self.optix = torchoptix\n        self.verts = verts.contiguous()\n        self.tris = tris.contiguous()\n        self.handle = self.optix.build(\n            self.verts.data_ptr(), self.tris.data_ptr(),\n            len(verts), len(tris)\n        )\n\n    @torch.no_grad()\n    def query(self, rays_o: torch.Tensor, rays_d: torch.Tensor, far: float) -\u003e Tuple[torch.Tensor]:\n        # out_i starts at 0 and is 0 when not hit.\n        # you can decide hits via `t \u003c far`.\n        out_t = rays_o.new_empty([len(rays_o)])\n        out_i = rays_o.new_empty([len(rays_o)], dtype=torch.int32)\n        rays_o = rays_o.contiguous()\n        rays_d = rays_d.contiguous()\n        self.optix.trace_rays(\n            self.handle,\n            rays_o.data_ptr(),\n            rays_d.data_ptr(),\n            out_t.data_ptr(), out_i.data_ptr(),\n            far, len(rays_o)\n        )\n        return out_t, out_i\n\n    def __del__(self):\n        if self.handle is not None and self.optix is not None and self.optix.release is not None:\n            self.optix.release(self.handle)\n            self.handle = None\n```\n\nExample:\n\n```python\nimport torch.nn.functional as F\naccel = TorchOptiX(torch.randn(10, 3).cuda(), torch.randint(0, 10, [5, 3]).cuda().int())\nt, i = accel.query(torch.randn(20, 3).cuda(), F.normalize(torch.randn(20, 3).cuda(), dim=-1), far=32767)\nprint(t, i, sep='\\n')\n```\n\n### Low-level API\n\n```\nNAME\n    torchoptix - Modular OptiX ray tracing functions interop with PyTorch.\n\nFUNCTIONS\n    build(...)\n        build(verts, tris, n_verts, n_tris) -\u003e handle\n\n        Build OptiX acceleration structure.\n\n    release(...)\n        release(handle)\n\n        Release OptiX acceleration structure.\n\n    set_log_level(...)\n        set_log_level(level)\n\n        Set OptiX log level (0-4).\n\n    trace_rays(...)\n        trace_rays(handle, rays_o, rays_d, out_t, out_i, t_max, n_rays)\n\n        Trace rays with OptiX.\n```\n\n`verts`, `tris`, `rays_o`, `rays_d`, `out_t`, `out_i` are CUDA device pointers.\n`tris` and `out_i` are contiguous `int32` arrays, and others are `float32` arrays.\n`t_max` (float) is maximum distance of ray to trace.\n\nThe functions need to be called when the same CUDA device context is active.\nThe APIs are not thread-safe on the same device.\nIn PyTorch, to run on multiple devices you need to use distributed parallelism, and each process runs a device. Multi-threading on devices is not supported.\n\nIt is not necessary that the arrays originate from PyTorch. It can be allocated with native CUDA.\n\n## Citation\n\n```bibtex\n@misc{TorchOptiX,\n  title = {TorchOptiX},\n  howpublished = {\\url{https://github.com/eliphatfs/torchoptix}},\n  note = {Accessed: 2024-09-13}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliphatfs%2Ftorchoptix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feliphatfs%2Ftorchoptix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliphatfs%2Ftorchoptix/lists"}