You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: PPU4ILGPU/PPU4ILGPU.csproj
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
<ImplicitUsings>enable</ImplicitUsings>
6
6
<Nullable>enable</Nullable>
7
7
<PackageId>PPU4ILGPU</PackageId>
8
-
<Version>1.0.0</Version>
8
+
<Version>1.1.0</Version>
9
9
<Authors>okozelsk</Authors>
10
10
<Description>Library of parallel processing utils for ILGPU. Offers thread-safe balanced utilization of all available GPU devices on host machine and fast loading of once compiled GPU kernels.</Description>
/// Simulates a job execution, utilizing a GPU accelerator if available, or falling back to CPU processing.
43
+
/// </summary>
44
+
/// <remarks>If a GPU accelerator is available, it is acquired and used for processing. The method
45
+
/// ensures thread safety by locking the GPU accelerator during its usage. If no GPU is available, the job is
46
+
/// processed on the CPU. The method logs the processing details, including whether the GPU or CPU was used, and
47
+
/// the total execution time.</remarks>
48
+
/// <param name="threadName">The name of the thread executing the job. This is used for logging purposes to identify the source of the
49
+
/// output.</param>
50
+
privatestaticvoidJobSimulation(stringthreadName)
51
+
{
52
+
Stopwatchsw=new();
53
+
//Start measuring time
54
+
sw.Start();
55
+
56
+
//Try to acquire a GPU accelerator for processing
57
+
GPUWrappedAccelerator?a=GPU.Allocator.Acquire();
58
+
if(a==null)
59
+
{
60
+
// No GPU available, fallback to CPU processing
61
+
Console.WriteLine($"[{threadName}] started processing on CPU...");
62
+
Thread.Sleep(100);// Simulate some CPU work
63
+
}
64
+
else
65
+
{
66
+
// GPU is available, use it for processing
67
+
Console.WriteLine($"[{threadName}] started processing on device {a.AccelObj.Device.Name}...");
68
+
//Lock the accelerator to ensure thread safety
69
+
lock(a.ThreadLock)
70
+
{
71
+
Thread.Sleep(100);// Simulate some CPU work
72
+
GPU.Allocator.Release(a);
73
+
}
74
+
}
75
+
//Stop measuring time
76
+
sw.Stop();
77
+
Console.WriteLine($"[{threadName}] finished in {sw.ElapsedMilliseconds} ms.");
78
+
return;
79
+
}
80
+
81
+
/// <summary>
82
+
/// Executes a sequence of six parallel operations, each performing fictive job.
83
+
/// </summary>
84
+
privatevoidExecuteParallelSequence()
85
+
{
86
+
Stopwatchsw=new();
87
+
Console.WriteLine();
88
+
Console.WriteLine($"Parallel sequence started with {nameof(GPUAllocator)} operation mode {Enum.GetName(typeof(GPUAllocator.Mode),GPU.Allocator.CurrentMode())}...");
89
+
// Start measuring time
90
+
sw.Start();
91
+
// Execute the neighbor sum calculations in parallel
92
+
Parallel.Invoke(
93
+
()=>{JobSimulation($"T1");},
94
+
()=>{JobSimulation($"T2");},
95
+
()=>{JobSimulation($"T3");},
96
+
()=>{JobSimulation($"T4");},
97
+
()=>{JobSimulation($"T5");},
98
+
()=>{JobSimulation($"T6");}
99
+
);
100
+
// Stop measuring time
101
+
sw.Stop();
102
+
Console.WriteLine($"Parallel sequence completed in {sw.ElapsedMilliseconds} ms.");
103
+
return;
104
+
}
105
+
106
+
/// <summary>
107
+
/// Executes a sequence of operations utilizing available GPUs, demonstrating GPU allocation, reservation, and
108
+
/// release.
109
+
/// </summary>
110
+
/// <remarks>This method performs the following steps: <list type="number"> <item> Lists all
111
+
/// available GPUs, sorted from the most powerful to the least powerful. </item> <item> Executes a parallel
112
+
/// sequence using all available GPUs. </item> <item> Attempts to reserve the most powerful GPU for exclusive
113
+
/// use and executes another parallel sequence with the remaining GPUs. </item> <item> Releases the reserved GPU
114
+
/// and executes a final parallel sequence with all GPUs available again. </item> If no GPUs are available at
115
+
/// the start, the method exits early. The method also handles scenarios where GPU reservation or release
116
+
/// fails.</remarks>
117
+
publicvoidRun()
118
+
{
119
+
Console.WriteLine("All available GPUs sorted from the most powerfull to the least powerfull");
0 commit comments