{"id":13676574,"url":"https://github.com/kunzmi/managedCuda","last_synced_at":"2025-04-29T07:32:52.133Z","repository":{"id":35767532,"uuid":"40047089","full_name":"kunzmi/managedCuda","owner":"kunzmi","description":"ManagedCUDA aims an easy integration of NVidia's CUDA in .net applications written in C#, Visual Basic or any other .net language.","archived":false,"fork":false,"pushed_at":"2025-03-03T19:26:08.000Z","size":8138,"stargazers_count":468,"open_issues_count":47,"forks_count":85,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-04-22T14:57:54.280Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kunzmi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-08-01T13:16:36.000Z","updated_at":"2025-04-16T02:12:17.000Z","dependencies_parsed_at":"2022-08-08T11:15:35.945Z","dependency_job_id":"53abb4fe-e0a5-47e3-93ac-bcc7bd9ad3c8","html_url":"https://github.com/kunzmi/managedCuda","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunzmi%2FmanagedCuda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunzmi%2FmanagedCuda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunzmi%2FmanagedCuda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kunzmi%2FmanagedCuda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kunzmi","download_url":"https://codeload.github.com/kunzmi/managedCuda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251456053,"owners_count":21592285,"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":[],"created_at":"2024-08-02T13:00:29.883Z","updated_at":"2025-04-29T07:32:47.122Z","avatar_url":"https://github.com/kunzmi.png","language":"C#","readme":"It all started as a hobby project to easily access CUDA from C# - at that time CUDA was available in version 3. Now more than 10 years later, managedCuda is still alive and is updated regularly by me to the latest versions of CUDA. In order to support further developments, I switched from the LGPL license to a dual-license GPLv3 / commercial license starting with managedCuda for Cuda version 12 onwards. In case you plan to use managedCuda 12 for a commercial project, please contact me by mail: managedcuda@articimaging.eu. If you use the open-source license and want to contribute to future development, you can donate me a beer here: \n[![Support via PayPal](https://www.paypalobjects.com/en_GB/i/btn/btn_donate_SM.gif)](https://www.paypal.me/kunzmi/)\n\n# Official nuget packages\nOne can find multiple packages for managedCuda on nuget, but the official packages are:\n- [ManagedCuda-12](https://www.nuget.org/packages/ManagedCuda-12/) (core library without dependencies)\n- [CUBLAS](https://www.nuget.org/packages/ManagedCuda-CUBLAS) (wrapper for cuBlas library, depends on ManagedCuda-12)\n- [CUFFT](https://www.nuget.org/packages/ManagedCuda-CUFFT) (wrapper for cuFFT library, depends on ManagedCuda-12)\n- [CURAND](https://www.nuget.org/packages/ManagedCuda-CURAND) (wrapper for cuRand library, depends on ManagedCuda-12)\n- [CUSOLVE](https://www.nuget.org/packages/ManagedCuda-CUSOLVE) (wrapper for cuSolver library, depends on ManagedCuda-12)\n- [CUSPARSE](https://www.nuget.org/packages/ManagedCuda-CUSPARSE) (wrapper for cuSparse library, depends on ManagedCuda-12)\n- [NPP](https://www.nuget.org/packages/ManagedCuda-NPP) (wrapper for NPP library, depends on ManagedCuda-12)\n- [NVJITLINK](https://www.nuget.org/packages/ManagedCuda-NVJITLINK) (wrapper for nvJitLink library, depends on ManagedCuda-12)\n- [NVJPEG](https://www.nuget.org/packages/ManagedCuda-NVJPEG) (wrapper for nvjpeg library, depends on ManagedCuda-12)\n- [NVRTC](https://www.nuget.org/packages/ManagedCuda-NVRTC) (wrapper for nvrtc library, depends on ManagedCuda-12)\n\n# managedCuda\nManagedCUDA aims an easy integration of NVidia's CUDA in .net applications written in C#, Visual Basic or any other .net language.\n\nFor this it includes:\n- A complete wrapper for the  CUDA Driver API, version 12.4 (a 1:1 representation of cuda.h in C#) \n- Based on this, wrapper classes for CUDA context, kernel, device variable, etc. \n- Wrapper for graphics interop with DirectX and OpenGL, respectively SlimDX and OpenTK \n- CUDA vector types like int2, float3 etc. with ToString() methods and operators (+, –, *, /) \n- Define your own types: CudaDeviceVariable accepts any user defined type if it is a value type, i.e. a struct in C# \n- Includes CUDA libraries: CUBLAS, CUFFT, CURAND, CUSOLVER, CUSPARSE, NPP, NvJPEG, NvJitLink and NVRTC\n- Compatibility for .net Framework 4.8 (might be dropped in a future version) and .net Core \u003e3.1.\n- Native Linux support for .net Core \u003e3.1: Automatically switches the native library names.\n- Access device memory directly per element using [] operator:\n```C#\nCudaDeviceVariable\u003cfloat\u003e devVar = new CudaDeviceVariable\u003cfloat\u003e(64);\ndevVar[0] = 1.0f;\ndevVar[1] = 2.0f;\nfloat hostVar1 = devVar[0];\nfloat hostVar2 = devVar[1];\n```\n- Implicit converter operators: Allocate and initialize device or host arrays in only one line of code: \n```C#\nfloat3[] array_host = new float3[100];\nfor (int i = 0; i \u003c 100; i++)\n{\n\tarray_host[i] = new float3(i, i+1, i+2);\n}\n//alloc device memory and copy data:\nCudaDeviceVariable\u003cfloat3\u003e array_device = array_host;\n//alloc host array and copy data: \nfloat3[] array_host2 = array_device; \n```\n- NPPs extension methods for CudaDeviceVariable. Add a reference to the NPP library and include the ManagedCuda.NPP.NPPsExtensions namespace: \n```C#\nRandom rand = new Random();\nint length = 256;\n\n//init some ramdom values\ndouble[] randoms = new double[length];\nfor (int i = 0; i \u003c length; i++)\n{\n\trandoms[i] = rand.NextDouble();\n}\n\n//Alloc device memory\nCudaDeviceVariable\u003cdouble\u003e a = randoms;\nCudaDeviceVariable\u003cdouble\u003e b = new CudaDeviceVariable\u003cdouble\u003e(length);\nb.Set(10.0); //NPPs method\nint size = a.MeanGetBufferSize(); //NPPs method\n//Alloc temporary memory for NPPs mean method\nCudaDeviceVariable\u003cbyte\u003e buffer = new CudaDeviceVariable\u003cbyte\u003e(size);\nCudaDeviceVariable\u003cdouble\u003e mean = new CudaDeviceVariable\u003cdouble\u003e(1);\n\na.Mul(b); //NPPs method\na.DivC(10.0); //NPPs method\na.Mean(mean, buffer); //NPPs method\n\n//Copy data back to host\ndouble m = mean;\ndouble[] res = a;\n\n//Clean up\nmean.Dispose();\nbuffer.Dispose();\nb.Dispose();\na.Dispose();\n```\n\n- The new feature 'per thread default stream' is available as a compiler directive of the managedCuda main library: Compile the library with the option \"_PerThreadDefaultStream\" to enable it.\n\n# Note about Cuda context\nNvidia changed the cuda context behavior in the cuda libraries (NPP, Cufft, etc.) why it is highly recommended to use a ```PrimaryContext``` instead of a ```CudaContext``` when using ManagedCUDA together with Cuda libraries. To create a ```PrimaryContext``` in ManagedCUDA, use the following lines of code:\n```C#\nint deviceID = 0;\nPrimaryContext ctx = new PrimaryContext(deviceID);\n// Set current to CPU thread, mandatory for a PrimaryContext\nctx.SetCurrent();\n```\n\n# NppStreamContext\nIn order to use the NppStreamContext-API of NPP, initialize a ```NppStreamContext``` like this:\n```C#\nCudaStream cudaStream = new CudaStream();          //optional, \nNPPNativeMethods.NPPCore.nppSetStream(cudaStream); //if not set, NPP will work on the default null-stream\nNppStreamContext nppCtx = NPPNativeMethods.NPPCore.nppGetStreamContext();\n```","funding_links":["https://www.paypal.me/kunzmi/"],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkunzmi%2FmanagedCuda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkunzmi%2FmanagedCuda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkunzmi%2FmanagedCuda/lists"}