{"id":28639748,"url":"https://github.com/deepakkumar1984/superchargedarray","last_synced_at":"2025-06-12T19:41:12.399Z","repository":{"id":38074308,"uuid":"189502254","full_name":"deepakkumar1984/SuperchargedArray","owner":"deepakkumar1984","description":"A super accelerated array extension for C# supported to run on multiple hardware: CPU, GPU (NVIDIA, AMD, Intel) to achieve accelerated speed","archived":false,"fork":false,"pushed_at":"2022-06-22T23:31:04.000Z","size":2399,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-08T00:51:18.928Z","etag":null,"topics":["amd","array-helper","array-manipulations","arrays","intel","multi-dimensional-array","ndarray","nvidia"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deepakkumar1984.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}},"created_at":"2019-05-31T00:49:07.000Z","updated_at":"2023-08-10T15:23:18.000Z","dependencies_parsed_at":"2022-09-26T22:30:15.439Z","dependency_job_id":null,"html_url":"https://github.com/deepakkumar1984/SuperchargedArray","commit_stats":null,"previous_names":["tech-quantum/superchargedarray"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/deepakkumar1984/SuperchargedArray","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakkumar1984%2FSuperchargedArray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakkumar1984%2FSuperchargedArray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakkumar1984%2FSuperchargedArray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakkumar1984%2FSuperchargedArray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepakkumar1984","download_url":"https://codeload.github.com/deepakkumar1984/SuperchargedArray/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepakkumar1984%2FSuperchargedArray/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259520285,"owners_count":22870415,"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":["amd","array-helper","array-manipulations","arrays","intel","multi-dimensional-array","ndarray","nvidia"],"created_at":"2025-06-12T19:41:11.547Z","updated_at":"2025-06-12T19:41:12.380Z","avatar_url":"https://github.com/deepakkumar1984.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SuperchargedArray\n\nThe .NET default built-in System.Array is very limited in terms of processing and usability. Here is the extended version of the Array with accelerated speed to execute operations on almost any hardware supporting OpenCL like Intel CPU, NVIDIA, AMD, Intel GPU, FPGA etc.\n\n## Easy to use:\nCreate an array and perform some math operations. Currenly supporting float and double. \n\nBelow is how you will do in .NET standard Array. I am trying to implement a math operation for 3x2 Matrix array with elementwise operations. \n\n```csharp\n\n//Create an array with values\nArray a = new float[,] { { 1, 2 }, { 3, 4 }, { 5, 6 } };\n\n//Create a array with constant value 2\nArray b = new float[3, 2];\nfor (int i = 0; i \u003c b.GetLength(0); i++)\n{\n    for (int j = 0; j \u003c b.GetLength(1); j++)\n    {\n        b.SetValue(2, i, j);\n    }\n}\n\n//Perform Math operation on the array: 2A + Log(B) + Exp(A)\nArray r = new float[3, 2];\nfor (int i = 0; i \u003c b.GetLength(0); i++)\n{\n    for (int j = 0; j \u003c b.GetLength(1); j++)\n    {\n        float A = (float)a.GetValue(i, j);\n        float B = (float)b.GetValue(i, j);\n\n        float rvalue = 2 * A - MathF.Log(B) + MathF.Exp(A);\n        r.SetValue(rvalue, i, j);\n    }\n}\n\n//Print the Array\nfor (int i = 0; i \u003c r.GetLength(0); i++)\n{\n    for (int j = 0; j \u003c r.GetLength(1); j++)\n    {\n        Console.Write(r.GetValue(i, j) + \"  \");\n    }\n\n    Console.WriteLine();\n}\n```\n\nA super simplified version with SuperchargedArray\n```csharp\nvar K = Global.OP;\n//Create an array with values\nSuperArray a = new float[,] { { 1, 2 }, { 3, 4 }, { 5, 6 } };\n\n//Create a array with constant value 2\nSuperArray b = new float[3, 2];\n//SuperArray b = new SuperArray(3, 2);\nb.Fill(2);\n\n//Perform Math operation on the array: 2A + Log(B) + Exp(A)\nvar r = 2 * a - Ops.Log(b) + Ops.Exp(a);\n\n//Print the Array\nr.Print();\n```\n\n\n## Accelerated Version\nSuperchargedArray is not all about simplicity, it is well defined to execute the code on special hardwares like Intel GPU, NVIDIA, AMD cards. Below is the simple performance test done to process 100 million executions. And see the result:\n\n```csharp\npublic void Run()\n{\n    int count = 100000000;\n    Random rnd = new Random();\n\n    //Create variable A with random values\n    float[] a = new float[count];\n    Parallel.For(0, count, (i) =\u003e {\n        a[i] = (float)rnd.NextDouble();\n    });\n\n    //Create variable B with constant value 0.5\n    float[] b = new float[count];\n    Parallel.For(0, count, (i) =\u003e {\n        b[i] = 0.5f;\n    });\n\n    RunStandardLoop(count, a, b);\n    Console.WriteLine();\n\n    var devices = Accelerator.Devices;\n    foreach (var item in devices)\n    {\n        RunArrayAccelerated(count, a, b, item.ID);\n        Console.WriteLine();\n    }\n\n    RunArrayDefault(count, a, b, 33);\n    RunArrayDefault(count, a, b, 66);\n    RunArrayDefault(count, a, b, 100);\n    Console.WriteLine();\n}\n\npublic void RunStandardLoop(int count, Array a, Array b)\n{\n    Stopwatch sw = new Stopwatch();\n    sw.Start();\n\n    //Execute math operation Truncate(a * Sin(b) + Cos(a) * Exp(b)) and store the result to R\n    Array r = new float[count];\n    for (int i = 0; i \u003c count; i++)\n    {\n        var rv = MathF.Truncate((float)a.GetValue(i) * MathF.Sin((float)b.GetValue(i)) + MathF.Cos((float)a.GetValue(i)) * MathF.Exp((float)b.GetValue(i)));\n        r.SetValue(rv, i);\n    }\n\n    sw.Stop();\n    Console.WriteLine(\".NET For Loop Time (in ms): \" + sw.ElapsedMilliseconds);\n}\n\npublic void RunArrayDefault(int count, SuperArray a, SuperArray b, int cpu)\n{\n    SuperchargedArray.Accelerated.Global.UseDefault(cpu);\n    Stopwatch sw = new Stopwatch();\n    sw.Start();\n\n    var K = SuperchargedArray.Global.OP;\n\n    var r = Ops.Trunc(a * Ops.Sin(b) + Ops.Cos(a) * Ops.Exp(b));\n    sw.Stop();\n\n    Console.WriteLine(\"With Parallel Thread Time (in ms): {1}\", cpu, sw.ElapsedMilliseconds);\n}\n\npublic void RunArrayAccelerated(int count, SuperArray a, SuperArray b, int deviceid)\n{\n    try\n    {\n        Accelerator.UseDevice(deviceid);\n        Stopwatch sw = new Stopwatch();\n        sw.Start();\n\n        var K = SuperchargedArray.Accelerated.Global.OP;\n\n        var r = Ops.Trunc(a * Ops.Sin(b) + Ops.Cos(a) * Ops.Exp(b));\n        sw.Stop();\n\n        Console.WriteLine(\"With Accelerator (in ms): \" + sw.ElapsedMilliseconds);\n        Accelerator.Dispose();\n    }\n    catch(Exception ex)\n    {\n        Console.WriteLine(\"Error: \" + ex.Message);\n    }\n}\n```\n\n### Execution Result:\n\nTest result to execute math ops y = trunc(a * Sin(b) + cos(a) * exp(b)) for 100 million elements\n\n.NET For Loop Time (in ms): 22317\n\nGeForce GTX 1080 Ti                    : 8741 ms\n\nIntel(R) UHD Graphics 630              : 6723 ms\n\nIntel(R) Core(TM) i7-8700 CPU @ 3.20GHz: 7380 ms\n\n33% of CPU parallel processing                  : 14332 ms\n\n66% of CPU parallel processing                  : 7716 ms\n\n100% of CPU parallel processing:\t\t\t\t: 6420 ms\n\nThe .NET standard loop takes about 22 seconds, whereas with 100% CPU parallel approach using ArrayExtension it finishes off in 6 sec which is one-fourth of time taken. But for long running process using full CPU is not ideal. With ArrayExtension.Accelerated, which internally uses SIMD (Single Instruction Multiple Data), you can achive greater speed without using 100% of the hardware. But you can always fine-tune to use 100% of the hardware and achieve ultimate speed.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepakkumar1984%2Fsuperchargedarray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepakkumar1984%2Fsuperchargedarray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepakkumar1984%2Fsuperchargedarray/lists"}