{"id":29802943,"url":"https://github.com/amirmardan/pytorch_extending_cpp_binding","last_synced_at":"2025-07-28T10:44:36.310Z","repository":{"id":184095446,"uuid":"559407063","full_name":"AmirMardan/pytorch_extending_cpp_binding","owner":"AmirMardan","description":"Binding C++ to PyTorch and extending PyTorch","archived":false,"fork":false,"pushed_at":"2022-11-02T15:08:44.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-28T05:11:37.648Z","etag":null,"topics":["autograd","cpp-bindings","pytorch-examples","pytorch-extension","pytorch-learning","torch-cpp"],"latest_commit_sha":null,"homepage":"","language":"Python","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/AmirMardan.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":"2022-10-30T02:27:27.000Z","updated_at":"2024-04-20T11:58:45.000Z","dependencies_parsed_at":"2023-07-27T03:45:05.540Z","dependency_job_id":null,"html_url":"https://github.com/AmirMardan/pytorch_extending_cpp_binding","commit_stats":null,"previous_names":["amirmardan/pytorch_extending_cpp_binding"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AmirMardan/pytorch_extending_cpp_binding","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmirMardan%2Fpytorch_extending_cpp_binding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmirMardan%2Fpytorch_extending_cpp_binding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmirMardan%2Fpytorch_extending_cpp_binding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmirMardan%2Fpytorch_extending_cpp_binding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AmirMardan","download_url":"https://codeload.github.com/AmirMardan/pytorch_extending_cpp_binding/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmirMardan%2Fpytorch_extending_cpp_binding/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267504021,"owners_count":24098335,"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-07-28T02:00:09.689Z","response_time":68,"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":["autograd","cpp-bindings","pytorch-examples","pytorch-extension","pytorch-learning","torch-cpp"],"created_at":"2025-07-28T10:44:33.985Z","updated_at":"2025-07-28T10:44:36.299Z","avatar_url":"https://github.com/AmirMardan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Extending Torch and binding C++ function\n========================================\n\nWe can extend the autograd operation in both Python and C++ which is discussed in folders `example_extend_in_python` and `example_load_multifile_cpp`.\n\nTo bind C++ to Python, we can use just-in-time (JIT) method. \nFor this purpose, we write our functions in C++ and at the end of the C++ file, we define the functions that need to be wrapped using pybind11 as \n```C++\nTORCH_LIBRARY(module_name, m) {\n  m.def(\"name_of_function_in_python\", \u0026name_of_function_in_cpp);  \n}\n\n```\nThen, we load C++ files as \n\n```Python\nfrom torch.utils.cpp_extension import load\nmodule = load(\n    name='module_name',\n    sources=['source1.cpp',\n    'source2.cu'],\n     extra_cflags=['-O2'],\n     verbose=True)\n```\nand now, we can call the created function as \n```Python\nadd = torch.ops.module_name.name_of_function_in_python\n```\n\nReference\n==========\n- [Torch C++ Extension](https://pytorch.org/docs/stable/cpp_extension.html#torch-utils-cpp-extension)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirmardan%2Fpytorch_extending_cpp_binding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famirmardan%2Fpytorch_extending_cpp_binding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirmardan%2Fpytorch_extending_cpp_binding/lists"}