❔ is there any way i can run my csharp console app net framwork program executable on my gpu?

Hi, i want to know if there is any way i can run my c# console app net framwork executable file on my gpu insted of my cpu becuase i think my gpu would run the program i wrote faster then my cpu.
48 Replies
Anton
Anton2y ago
why do you think so
GlitchYourDevice
becuase its a program that does other stuff butt stuff almost like a cryptominer does and a cryptominer works best with the gpu
Sossenbinder
Sossenbinder2y ago
GitHub
GitHub - Sergio0694/ComputeSharp: A .NET library to run C# code in ...
A .NET library to run C# code in parallel on the GPU through DX12, D2D1, and dynamically generated HLSL compute shaders, with the goal of making GPU computing easy to use for all .NET developers! 🚀...
Anton
Anton2y ago
write a compute shader
GlitchYourDevice
what is that
Anton
Anton2y ago
you do work on the gpu via shaders that abstraction they sent above generates said shaders from .NET IL code dynamically I'm guessing
GlitchYourDevice
can i not just put all my c# code it to some kind of converter and then use the converted code so it will be runned on my gpu
Anton
Anton2y ago
that's what they sent above but it's not as simple as that gpus are highly multithreaded which means the program has to be written with that in mind converting an arbitrary program doesn't give you any benefit shaders are programs that run e.g. per pixel on the screen, each on a separate thread, in a mini context
GlitchYourDevice
ok but this is the program that i want to convert using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Globalization; using System.Runtime.CompilerServices; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { string filepath = @"D:\text1.txt"; string filepath2 = @"D:\text2.txt"; List<string> lines = File.ReadAllLines(filepath).ToList(); List<string> lines2 = File.ReadAllLines(filepath2).ToList(); for (int i = 0; i < lines.Count; i++) { for (int j = 0; j < lines2.Count; j++) { if (lines[i] == lines2[j].Split(':')[0]) { Console.WriteLine(lines2[j]); } } } Console.WriteLine("\nDone"); Console.ReadLine(); } } }
GlitchYourDevice
this works with the cpu becuase its not many rows in text1 and text2
Aaron
Aaron2y ago
uhhh I don't think this is exactly what GPUs are built to do there are other ways to optimize this though
GlitchYourDevice
but i have a other "text1" doucument with 8k rows and the "txt2 document" has 8000000 rows with my 8k txt1 and 8000k txt2 document this takes to long with the cpu
Aaron
Aaron2y ago
you could get rid of the outer loop over lines, for example and use a HashSet with HashSet.Contains instead
GlitchYourDevice
what do you mean? where in my code?
Aaron
Aaron2y ago
you have for (int i = 0; i < lines.Count; i++) you could get rid of that loop
GlitchYourDevice
ok
Aaron
Aaron2y ago
have HashSet<string> lines = new HashSet<string>(File.ReadAllLines("D:\text1.txt"));
GlitchYourDevice
ok
Aaron
Aaron2y ago
then do lines.Contains(lines2[j].Split(':')[0]) in the if
GlitchYourDevice
ok
Aaron
Aaron2y ago
and that should be significantly faster you can also multithread this on your CPU instead of trying to make it run on a GPU
GlitchYourDevice
i will try it and write back here if i dont get it to work using System.Text; using System.Threading.Tasks; using System.IO; using System.Globalization; using System.Runtime.CompilerServices; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { string filepath = @"D:\text1.txt"; string filepath2 = @"D:\text2.txt"; List<string> lines2 = File.ReadAllLines(filepath2).ToList(); HashSet<string> lines = new HashSet<string>(File.ReadAllLines("D:\text1.txt"));
for (int j = 0; j < lines2.Count; j++) { if (lines.Contains(lines2[j].Split(':')[0])) { Console.WriteLine(lines2[j]); } } Console.WriteLine("\nDone"); Console.ReadLine(); } } } that does not work at all
Aaron
Aaron2y ago
it's doing almost the same thing as the code from before though it doesn't print multiple times for one row if the same line exists in text1 more than once
GlitchYourDevice
it is no duplicates so that do i not need to worry about with my bigger txt documents
Aaron
Aaron2y ago
what doesn't work about it
GlitchYourDevice
i cant even run it can you just please rewrite the code and send it here i have never even used hashset before
Aaron
Aaron2y ago
why can't you run it
GlitchYourDevice
it said that varible lines is already used
Aaron
Aaron2y ago
what
GlitchYourDevice
System.ArgumentException: 'Illegal characters in path.'
Aaron
Aaron2y ago
oh because the thing in the ReadAllLines should've just been filepath
Torn
Torn2y ago
Gonna need to escape the backslash I think \\
Aaron
Aaron2y ago
instead of the string
GlitchYourDevice
ok
Aaron
Aaron2y ago
currently there's a tab in the string lmao
GlitchYourDevice
this is the code now using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Globalization; using System.Runtime.CompilerServices; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { string filepath = @"D:\text1.txt"; string filepath2 = @"D:\text2.txt"; List<string> lines2 = File.ReadAllLines(filepath2).ToList(); HashSet<string> lines = new HashSet<string>(File.ReadAllLines("D:\text1.txt"));
for (int j = 0; j < lines2.Count; j++) { if (lines.Contains(lines2[j].Split(':')[0])) { Console.WriteLine(lines2[j]); } } Console.WriteLine("\nDone"); Console.ReadLine(); } } } what should i change
Aaron
Aaron2y ago
did you fix the ArgumentException
GlitchYourDevice
thanks it worked now but i have no idea how it worked and why is it so much faster?
Anton
Anton2y ago
it had quadratic complexity, but you made it linear or is it n logn
Aaron
Aaron2y ago
HashSets can check whether they contain something in O(1) time
GlitchYourDevice
ok
Aaron
Aaron2y ago
meaning no matter how many lines there are in text1, it will take the same amount of time to do .Contains that takes the number of iterations you do from 8k * 8000000 to just 8000000 which is much smaller! you were right, it's linear based on the line count of text2 understanding time complexity, and how to reduce it, is one of the best ways to become better at optimizing code
Anton
Anton2y ago
yeah a search tree would've been n log n, constructing hash sets is linear
Aaron
Aaron2y ago
not sure why you'd use a binary tree here
Anton
Anton2y ago
you wouldn't, I was just reminding myself of its complexity
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ How to get the type that got inheri ?I got a list of PetProfileCardsGroupModel Is there a way I can get a List<PetProfileCardModel> from ❔ edit - how do i map the output of EnumerateAudioEndPoints to the wave device numbers?when i have an endpoint notification callback registered, and try to dispose any sort of waveout or ❔ Winforms Property from BaseClass Form not getting transferred to derived FormHi. Don't know if you guys can help an amateur. I know most of you guys don't like winforms, but... ❔ Repeating parameters vs variadic functionsDoes anybody know why the `params` keyword is not used more commonly? This example if from the `Immu❔ does an interface go inside a generic parent class?```csharp using Godot; using System; public class StateTemplate : Node { public enum State { ❔ Copying video on Delegates, why doesn't my version work?Why does my code not work, but the code in the video i'm following does. <:OhNo:632294461048881222>❔ how can WPF change the hover mouseover color of something like Winforms can?I'm getting increasingly frustrated at how many features WPF is just lacking compared to winforms, a✅ Need some help with classesdisplayTeam and displapPlayer methods not working correctly❔ Is there any way to use a proxy with TestServer?Looking at the integration/functional tests in the eShopOnContainers sample application https://gith❔ how can I add a custom analyzer to omnisharp(vscdoe's css extention)?I was having problems with auto complete while using unity, I tracked the problem down to this issue