Skip to content

Commit 7da1af2

Browse files
authored
Merge pull request #6 from temotskipa/enhance-console-gpu-support
Add Real GPU Functionality to Console App with Enhanced CI/CD
2 parents 8c4d17c + cb4cc2a commit 7da1af2

6 files changed

Lines changed: 914 additions & 135 deletions

File tree

.github/workflows/build.yml

Lines changed: 112 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11-
build:
11+
build-gui:
12+
name: Build GUI Application (Windows)
1213
runs-on: windows-latest
1314

15+
strategy:
16+
matrix:
17+
build-type: [self-contained, framework-dependent]
18+
1419
steps:
1520
- name: Checkout code
1621
uses: actions/checkout@v4
@@ -20,32 +25,53 @@ jobs:
2025
with:
2126
dotnet-version: '9.0.x'
2227

23-
- name: Restore dependencies (win-x64)
24-
run: dotnet restore GDeflateGUI/GDeflateGUI.csproj --runtime win-x64
28+
- name: Restore dependencies
29+
run: dotnet restore GDeflateGUI/GDeflateGUI.csproj ${{ matrix.build-type == 'self-contained' && '--runtime win-x64' || '' }}
2530

26-
- name: Build application
31+
- name: Build GUI application
2732
run: dotnet build GDeflateGUI/GDeflateGUI.csproj --configuration Release --no-restore
2833

29-
- name: Publish application
30-
run: dotnet publish GDeflateGUI/GDeflateGUI.csproj --configuration Release --output ./publish --self-contained true --runtime win-x64
34+
- name: Publish GUI application (Self-contained)
35+
if: matrix.build-type == 'self-contained'
36+
run: dotnet publish GDeflateGUI/GDeflateGUI.csproj --configuration Release --output ./publish-gui --self-contained true --runtime win-x64
3137

32-
- name: Upload executable artifact
33-
uses: actions/upload-artifact@v4
34-
with:
35-
name: GDeflate-Compressor-Windows-x64
36-
path: ./publish/
37-
retention-days: 30
38-
39-
- name: Create release build info
38+
- name: Publish GUI application (Framework-dependent)
39+
if: matrix.build-type == 'framework-dependent'
40+
run: dotnet publish GDeflateGUI/GDeflateGUI.csproj --configuration Release --output ./publish-gui --no-build --self-contained false
41+
42+
- name: Create build info
4043
run: |
41-
echo "Build completed successfully!" > ./publish/BUILD_INFO.txt
42-
echo "Build Date: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC')" >> ./publish/BUILD_INFO.txt
43-
echo "Commit SHA: ${{ github.sha }}" >> ./publish/BUILD_INFO.txt
44-
echo "Branch: ${{ github.ref_name }}" >> ./publish/BUILD_INFO.txt
44+
echo "GDeflate GUI Application - ${{ matrix.build-type }}" > ./publish-gui/BUILD_INFO.txt
45+
echo "Build Date: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC')" >> ./publish-gui/BUILD_INFO.txt
46+
echo "Commit SHA: ${{ github.sha }}" >> ./publish-gui/BUILD_INFO.txt
47+
echo "Branch: ${{ github.ref_name }}" >> ./publish-gui/BUILD_INFO.txt
48+
echo "Build Type: ${{ matrix.build-type }}" >> ./publish-gui/BUILD_INFO.txt
49+
echo "Platform: Windows x64" >> ./publish-gui/BUILD_INFO.txt
4550
shell: pwsh
4651

47-
build-framework-dependent:
48-
runs-on: windows-latest
52+
- name: Upload GUI artifact
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: GDeflate-GUI-Windows-${{ matrix.build-type }}
56+
path: ./publish-gui/
57+
retention-days: 30
58+
59+
build-console:
60+
name: Build Console Application
61+
runs-on: ${{ matrix.os }}
62+
63+
strategy:
64+
matrix:
65+
include:
66+
- os: windows-latest
67+
runtime: win-x64
68+
name: Windows
69+
- os: ubuntu-latest
70+
runtime: linux-x64
71+
name: Linux
72+
- os: macos-latest
73+
runtime: osx-x64
74+
name: macOS
4975

5076
steps:
5177
- name: Checkout code
@@ -57,17 +83,74 @@ jobs:
5783
dotnet-version: '9.0.x'
5884

5985
- name: Restore dependencies
60-
run: dotnet restore GDeflateGUI/GDeflateGUI.csproj
86+
run: dotnet restore GDeflateConsole/GDeflateConsole.csproj --runtime ${{ matrix.runtime }}
6187

62-
- name: Build application
63-
run: dotnet build GDeflateGUI/GDeflateGUI.csproj --configuration Release --no-restore
88+
- name: Build console application
89+
run: dotnet build GDeflateConsole/GDeflateConsole.csproj --configuration Release --no-restore
90+
91+
- name: Test console application
92+
run: dotnet run --project GDeflateConsole --configuration Release test
93+
94+
- name: Publish console application (Self-contained)
95+
run: dotnet publish GDeflateConsole/GDeflateConsole.csproj --configuration Release --output ./publish-console --self-contained true --runtime ${{ matrix.runtime }}
96+
97+
- name: Create build info (Windows)
98+
if: matrix.os == 'windows-latest'
99+
run: |
100+
echo "GDeflate Console Application - Self-contained" > ./publish-console/BUILD_INFO.txt
101+
echo "Build Date: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC')" >> ./publish-console/BUILD_INFO.txt
102+
echo "Commit SHA: ${{ github.sha }}" >> ./publish-console/BUILD_INFO.txt
103+
echo "Branch: ${{ github.ref_name }}" >> ./publish-console/BUILD_INFO.txt
104+
echo "Platform: ${{ matrix.name }} (${{ matrix.runtime }})" >> ./publish-console/BUILD_INFO.txt
105+
echo "GPU Support: Available on Windows with CUDA/nvCOMP" >> ./publish-console/BUILD_INFO.txt
106+
echo "Fallback Mode: Simulation mode on systems without GPU" >> ./publish-console/BUILD_INFO.txt
107+
shell: pwsh
64108

65-
- name: Publish framework-dependent application
66-
run: dotnet publish GDeflateGUI/GDeflateGUI.csproj --configuration Release --output ./publish-fd --no-build --self-contained false
109+
- name: Create build info (Unix)
110+
if: matrix.os != 'windows-latest'
111+
run: |
112+
echo "GDeflate Console Application - Self-contained" > ./publish-console/BUILD_INFO.txt
113+
echo "Build Date: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> ./publish-console/BUILD_INFO.txt
114+
echo "Commit SHA: ${{ github.sha }}" >> ./publish-console/BUILD_INFO.txt
115+
echo "Branch: ${{ github.ref_name }}" >> ./publish-console/BUILD_INFO.txt
116+
echo "Platform: ${{ matrix.name }} (${{ matrix.runtime }})" >> ./publish-console/BUILD_INFO.txt
117+
echo "GPU Support: Simulation mode (CUDA not available on this platform)" >> ./publish-console/BUILD_INFO.txt
118+
echo "Fallback Mode: Full functionality in simulation mode" >> ./publish-console/BUILD_INFO.txt
67119
68-
- name: Upload framework-dependent artifact
120+
- name: Upload console artifact
69121
uses: actions/upload-artifact@v4
70122
with:
71-
name: GDeflate-Compressor-Framework-Dependent
72-
path: ./publish-fd/
73-
retention-days: 30
123+
name: GDeflate-Console-${{ matrix.name }}-${{ matrix.runtime }}
124+
path: ./publish-console/
125+
retention-days: 30
126+
127+
build-summary:
128+
name: Build Summary
129+
runs-on: ubuntu-latest
130+
needs: [build-gui, build-console]
131+
if: always()
132+
133+
steps:
134+
- name: Create build summary
135+
run: |
136+
echo "# GDeflate Compressor Build Summary" >> $GITHUB_STEP_SUMMARY
137+
echo "" >> $GITHUB_STEP_SUMMARY
138+
echo "## Build Status" >> $GITHUB_STEP_SUMMARY
139+
echo "- **GUI Application**: ${{ needs.build-gui.result }}" >> $GITHUB_STEP_SUMMARY
140+
echo "- **Console Application**: ${{ needs.build-console.result }}" >> $GITHUB_STEP_SUMMARY
141+
echo "" >> $GITHUB_STEP_SUMMARY
142+
echo "## Artifacts Generated" >> $GITHUB_STEP_SUMMARY
143+
echo "### GUI Application (Windows only)" >> $GITHUB_STEP_SUMMARY
144+
echo "- GDeflate-GUI-Windows-self-contained" >> $GITHUB_STEP_SUMMARY
145+
echo "- GDeflate-GUI-Windows-framework-dependent" >> $GITHUB_STEP_SUMMARY
146+
echo "" >> $GITHUB_STEP_SUMMARY
147+
echo "### Console Application (Cross-platform)" >> $GITHUB_STEP_SUMMARY
148+
echo "- GDeflate-Console-Windows-win-x64" >> $GITHUB_STEP_SUMMARY
149+
echo "- GDeflate-Console-Linux-linux-x64" >> $GITHUB_STEP_SUMMARY
150+
echo "- GDeflate-Console-macOS-osx-x64" >> $GITHUB_STEP_SUMMARY
151+
echo "" >> $GITHUB_STEP_SUMMARY
152+
echo "## Features" >> $GITHUB_STEP_SUMMARY
153+
echo "- **GPU Acceleration**: Available on Windows with CUDA/nvCOMP" >> $GITHUB_STEP_SUMMARY
154+
echo "- **Simulation Mode**: Automatic fallback for testing and non-GPU systems" >> $GITHUB_STEP_SUMMARY
155+
echo "- **Cross-platform**: Console app runs on Windows, Linux, and macOS" >> $GITHUB_STEP_SUMMARY
156+
echo "- **Built-in Testing**: Comprehensive test suite included" >> $GITHUB_STEP_SUMMARY

GDeflateConsole/CudaRuntimeApi.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace GDeflateConsole
5+
{
6+
internal static class CudaRuntimeApi
7+
{
8+
// The name of the CUDA Runtime DLL. This may be version-specific
9+
// (e.g., "cudart64_110.dll", "cudart64_12.dll").
10+
// It must be in the system's PATH or alongside the executable.
11+
private const string CudaRuntimeDll = "cudart64_12.dll";
12+
13+
internal enum CudaMemcpyKind
14+
{
15+
HostToHost = 0,
16+
HostToDevice = 1,
17+
DeviceToHost = 2,
18+
DeviceToDevice = 3,
19+
Default = 4
20+
}
21+
22+
[DllImport(CudaRuntimeDll, SetLastError = true)]
23+
internal static extern int cudaMalloc(out IntPtr devPtr, UIntPtr size);
24+
25+
[DllImport(CudaRuntimeDll, SetLastError = true)]
26+
internal static extern int cudaMemcpy(IntPtr dst, IntPtr src, UIntPtr count, CudaMemcpyKind kind);
27+
28+
[DllImport(CudaRuntimeDll, SetLastError = true)]
29+
internal static extern int cudaFree(IntPtr devPtr);
30+
31+
[DllImport(CudaRuntimeDll, SetLastError = true)]
32+
internal static extern int cudaStreamCreate(out IntPtr pStream);
33+
34+
[DllImport(CudaRuntimeDll, SetLastError = true)]
35+
internal static extern int cudaStreamDestroy(IntPtr stream);
36+
37+
[DllImport(CudaRuntimeDll, SetLastError = true)]
38+
internal static extern int cudaStreamSynchronize(IntPtr stream);
39+
40+
[DllImport(CudaRuntimeDll, SetLastError = true)]
41+
internal static extern IntPtr cudaGetErrorString(int error);
42+
43+
[DllImport(CudaRuntimeDll, SetLastError = true)]
44+
internal static extern int cudaGetDeviceCount(out int count);
45+
46+
// Helper method to check if CUDA is available
47+
internal static bool IsCudaAvailable()
48+
{
49+
try
50+
{
51+
int deviceCount;
52+
int result = cudaGetDeviceCount(out deviceCount);
53+
return result == 0 && deviceCount > 0;
54+
}
55+
catch (DllNotFoundException)
56+
{
57+
return false;
58+
}
59+
catch (EntryPointNotFoundException)
60+
{
61+
return false;
62+
}
63+
catch
64+
{
65+
return false;
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)