summaryrefslogtreecommitdiff
path: root/README-native.md
blob: 91961b882fb2bb1161d75afba80ede675aaaa55e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# Running Go CUDA Torus Natively on Windows

This guide explains how to run the Go CUDA Torus application directly on your Windows machine without Docker/Podman.

## Quick Start

1. **Check system requirements:**
   ```powershell
   .\run-native.ps1 check
   ```

2. **Build and run the application:**
   ```powershell
   .\run-native.ps1 run
   ```

3. **Open your browser to:**
   ```
   http://localhost:8080
   ```

## System Requirements

### Required
- **Go 1.21+** - Download from [golang.org/dl](https://golang.org/dl/)
- **OpenGL drivers** - Usually pre-installed with graphics drivers
- **Internet connection** - For downloading Go modules

### Recommended
- **GCC/MinGW** - For CGO compilation support
  - Install via: `winget install mingw` (if you have winget)
  - Or download from [mingw-w64.org](https://mingw-w64.org/)
- **Git** - For Go module downloads

## Installation Options

### Option 1: PowerShell Script (Recommended)
```powershell
# Check system requirements
.\run-native.ps1 check

# Build and run (handles dependencies automatically)
.\run-native.ps1 run

# Other useful commands
.\run-native.ps1 build          # Build only
.\run-native.ps1 clean          # Clean build artifacts
.\run-native.ps1 rebuild        # Clean and rebuild
.\run-native.ps1 help           # Show all options
```

### Option 2: Batch Script (Simple)
```cmd
# Build and run
run-native.bat

# Other commands
run-native.bat check     # Check requirements
run-native.bat build     # Build only
run-native.bat clean     # Clean artifacts
run-native.bat help      # Show help
```

### Option 3: Manual Commands
```powershell
# Install dependencies
go mod download
go mod tidy

# Build application
$env:CGO_ENABLED = "1"
go build -o torus-app.exe .

# Run application
.\torus-app.exe
```

## Features

### Web Interface
- **URL:** http://localhost:8080
- **Real-time parameter control:** Adjust torus geometry and animation
- **API endpoints:**
  - `GET /api/status` - Get current parameters and CUDA status
  - `POST /api/params` - Update parameters in real-time

### Torus Parameters
- **Major Radius** - Size of the main torus ring
- **Minor Radius** - Thickness of the torus tube
- **Major Segments** - Ring detail (higher = smoother)
- **Minor Segments** - Tube detail (higher = smoother)
- **Rotation Speed X/Y** - Animation speeds

## CUDA Support

### With NVIDIA GPU
If you have:
- NVIDIA GPU with CUDA support
- CUDA Toolkit installed
- Proper NVIDIA drivers

The application will automatically use GPU acceleration for vertex and color computations.

### CPU Fallback
Without CUDA support, the application automatically falls back to CPU computations. Performance is still excellent for real-time visualization.

## Troubleshooting

### Go Not Found
```
Error: Go not found in PATH
```
**Solution:** Install Go from [golang.org/dl](https://golang.org/dl/) and ensure it's added to your PATH.

### CGO Compilation Errors
```
gcc: command not found
```
**Solution:** Install MinGW-w64 or TDM-GCC for CGO support:
- `winget install mingw` (if available)
- Or download from [mingw-w64.org](https://mingw-w64.org/)

### OpenGL Errors
```
Failed to initialize OpenGL
```
**Solution:** Update your graphics drivers. Most modern Windows systems have OpenGL support.

### Port Already in Use
```
Error: listen tcp :8080: bind: address already in use
```
**Solution:** Stop other applications using port 8080, or modify the port in the source code.

### Module Download Failures
```
Error: Failed to download Go modules
```
**Solutions:**
1. Check internet connection
2. Configure Go proxy if behind corporate firewall:
   ```powershell
   $env:GOPROXY = "https://proxy.golang.org,direct"
   ```
3. Disable Go modules verification temporarily:
   ```powershell
   $env:GOSUMDB = "off"
   ```

## Performance Tips

### For Best Performance
1. **Enable hardware acceleration:** Ensure graphics drivers are up to date
2. **Use higher segment counts:** For smoother torus geometry (may impact performance)
3. **CUDA acceleration:** Install CUDA toolkit if you have an NVIDIA GPU

### For Slower Systems
1. **Reduce segment counts:** Lower values for better performance
2. **Slower rotation speeds:** Reduce animation load
3. **Close other applications:** Free up system resources

## Building for Distribution

### Create standalone executable:
```powershell
# Build optimized binary
$env:CGO_ENABLED = "1"
go build -ldflags="-s -w" -o torus-app.exe .
```

### Include dependencies:
The Go binary includes all dependencies. Just distribute the `torus-app.exe` file.

## File Structure

```
GoCUDA/
├── main.go              # Main application with OpenGL rendering
├── web_interface.go     # Web server and HTML interface
├── math_utils.go        # Math utilities for 3D transformations
├── shaders.go          # OpenGL vertex and fragment shaders
├── cuda_stuff.go       # CUDA integration and CGO bindings
├── torus_kernel.cu     # CUDA kernels for GPU acceleration
├── torus_kernel.h      # C interface for CUDA
├── dummy_cuda.c        # Fallback for systems without CUDA
├── run-native.ps1      # PowerShell runner script
├── run-native.bat      # Batch runner script
├── go.mod              # Go module dependencies
└── README-native.md    # This file
```

## Advanced Usage

### Custom Build Options
```powershell
# Build with debug info
go build -o torus-app.exe .

# Build optimized for release
go build -ldflags="-s -w" -o torus-app.exe .

# Build with race detection (development)
go build -race -o torus-app.exe .
```

### Environment Variables
```powershell
# Force CPU mode (disable CUDA)
$env:FORCE_CPU = "1"

# Enable verbose logging
$env:DEBUG = "1"

# Custom port
$env:PORT = "9090"
```

## Support

For issues or questions:
1. Check this README for common solutions
2. Verify system requirements are met
3. Try rebuilding: `.\run-native.ps1 rebuild`
4. Check Go and driver installations