{"id":20040845,"url":"https://github.com/vadimkantorov/dotnetdlpack","last_synced_at":"2026-05-10T06:35:11.736Z","repository":{"id":146466411,"uuid":"288194488","full_name":"vadimkantorov/dotnetdlpack","owner":"vadimkantorov","description":"C# p/invoke bindings for DLPack ","archived":false,"fork":false,"pushed_at":"2020-08-18T11:52:00.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T19:22:03.013Z","etag":null,"topics":["csharp","dlpack","dotnet","pinvoke"],"latest_commit_sha":null,"homepage":"","language":"C","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/vadimkantorov.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-17T13:57:29.000Z","updated_at":"2020-08-18T11:52:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"a2dce012-e87a-47b4-acbb-2657f91e86dc","html_url":"https://github.com/vadimkantorov/dotnetdlpack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadimkantorov%2Fdotnetdlpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadimkantorov%2Fdotnetdlpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadimkantorov%2Fdotnetdlpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadimkantorov%2Fdotnetdlpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vadimkantorov","download_url":"https://codeload.github.com/vadimkantorov/dotnetdlpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241470364,"owners_count":19968041,"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":["csharp","dlpack","dotnet","pinvoke"],"created_at":"2024-11-13T10:44:12.238Z","updated_at":"2026-05-10T06:35:11.703Z","avatar_url":"https://github.com/vadimkantorov.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"P/Invoke bindings for [DLPack](http://github.com/dmlc/dlpack). It demonstrates consuming from C# a DLPack tensor produced in a C function.\n\nHopefully there will be official bindings: https://github.com/dmlc/dlpack/issues/56 and https://github.com/microsoft/onnxruntime/issues/4162.\n\nCurrently there is no example for constructing a DLPack tensor in C# and sending it to a C function.\n\nLimitations: due to [`ReadOnlySpan\u003cT\u003e`](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1.-ctor?view=netcore-3.1#System_ReadOnlySpan_1__ctor_System_Void__System_Int32_) supporting only Int32 lengths, the `ROS\u003cT\u003e`-returning method is called `DataSpanLessThan2Gb()`. Issues: https://github.com/dotnet/corefxlab/issues/896 and https://github.com/dotnet/apireviews/tree/master/2016/11-04-SpanOfT#spant-and-64-bit. This code assumes Linux, but could be made to work on Windows with a different Makefile.\n\nMore advanced example with libtorch (using the same [`dlpack.cs`](./dlpack.cs): https://github.com/vadimkantorov/dotnetlibtorch\n\n### Install .NET Core 3.1 SDK on Ubuntu 18.04\nFrom https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#1804- :\n```shell\nwget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb\nsudo dpkg -i packages-microsoft-prod.deb\n\nsudo apt-get update\nsudo apt-get install -y apt-transport-https\nsudo apt-get update \nsudo apt-get install -y dotnet-sdk-3.1\n```\n\n### Usage\n```shell\nmake dlpack\n./dlpack golden.bin\n\nmake libdlpack.so\ndotnet run test.cs csharp.bin\n\n#ndim 2\n#shape 3 2\n#(0, 0) = 0\n#(0, 1) = 1\n#(1, 0) = 2\n#(1, 1) = 3\n#(2, 0) = 4\n#(2, 1) = 5\n#Deleter calling\n#Deleter called\n\ndiff golden.bin csharp.bin\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvadimkantorov%2Fdotnetdlpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvadimkantorov%2Fdotnetdlpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvadimkantorov%2Fdotnetdlpack/lists"}