summaryrefslogtreecommitdiff
path: root/README.md
blob: a8272475c25b5a84069ca7fb3d16e7c6f3011762 (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
# Go CUDA Torus Application

A rotating toroidal (donut) shape made of small cubes with a pulsating green glow effect, implemented in Go with OpenGL and CUDA integration.

## Prerequisites

- [Podman Desktop](https://podman-desktop.io/) for Windows
- NVIDIA GPU with CUDA support
- NVIDIA Container Toolkit (for GPU access in containers)

## Quick Start

The project uses a multi-stage Docker setup with separate containers for building and running:

- **Builder Stage**: Contains Go compiler, GCC, and development tools
- **Runtime Stage**: Lightweight container with only runtime dependencies  
- **Development Stage**: Full development environment with tools and source mounting

### Option 1: Using PowerShell Script (Recommended)

```powershell
# Start development environment (recommended for coding)
.\run-podman.ps1 dev

# Build and run production application
.\run-podman.ps1 run

# Build specific stages
.\run-podman.ps1 build development    # Build dev image
.\run-podman.ps1 build runtime        # Build production image
.\run-podman.ps1 build all            # Build all stages

# Just compile the binary (CI/CD style)
.\run-podman.ps1 build-only

# Use Docker Compose
.\run-podman.ps1 compose-dev          # Development with compose
.\run-podman.ps1 compose-prod         # Production with compose

# Clean up
.\run-podman.ps1 clean
```

### Option 2: Manual Podman Commands

```bash
# Build specific stages
podman build --target development -t go-cuda-torus:dev .
podman build --target runtime -t go-cuda-torus:runtime .
podman build --target builder -t go-cuda-torus:builder .

# Run development container
podman run --rm -it \
  --name go-cuda-torus-dev \
  --device nvidia.com/gpu=all \
  -v "$PWD:/workspace" \
  -p 8080:8080 -p 2345:2345 \
  go-cuda-torus:dev

# Run production container
podman run --rm -it \
  --name go-cuda-torus \
  --device nvidia.com/gpu=all \
  -p 8080:8080 \
  go-cuda-torus:runtime

# Build-only (for CI/CD)
podman run --rm \
  --name go-cuda-torus-builder \
  -v "$PWD:/workspace" \
  go-cuda-torus:builder
```

### Option 3: Docker Compose

```bash
# Development environment
podman-compose up --build torus-dev

# Production environment  
podman-compose up --build torus-app

# Build-only
podman-compose up --build torus-builder
```

## Development

The multi-stage container setup provides:

### Builder Stage
- Go 1.22.10 with CGO enabled
- GCC/G++ compilers for CGO and CUDA
- OpenGL development libraries (Mesa, GLFW, GLEW)
- CUDA 12.2 development toolkit
- Git and build tools

### Runtime Stage (Production)
- Minimal Ubuntu base with CUDA runtime
- Only runtime OpenGL libraries
- Pre-built application binary
- X11/Xvfb for display support
- ~50% smaller than development image

### Development Stage  
- Everything from builder stage
- Additional development tools (vim, nano, gdb, valgrind)
- Source code mounting for live development
- Debugger support (port 2345 for Delve)
- Go module caching for faster rebuilds

### Container Usage

**Development Workflow:**
```bash
# Start development container
.\run-podman.ps1 dev

# Inside container - live development
go build -o torus-app .
/usr/local/bin/run-with-display.sh ./torus-app

# Or rebuild and test quickly
go run .
```

**Production Deployment:**
```bash
# Build optimized runtime image
.\run-podman.ps1 build runtime

# Run production container
.\run-podman.ps1 run
```

**CI/CD Pipeline:**
```bash
# Build-only for testing/artifacts
.\run-podman.ps1 build-only
```

## Project Structure

- `main.go` - Main application with OpenGL setup and render loop
- `shaders.go` - Vertex and fragment shader sources
- `math_utils.go` - Vector/matrix math library
- `cuda_stuff.go` - CUDA integration (placeholder)
- `Dockerfile` - Container definition
- `docker-compose.yml` - Multi-service setup
- `run-podman.ps1` - PowerShell runner script

## Current Status

- ✅ Project structure and Go modules setup
- ✅ Docker containerization with all dependencies
- ✅ Basic OpenGL rendering pipeline (single cube)
- 🔄 Torus geometry generation (pending)
- 🔄 CUDA kernels for pulsating glow effect (pending)
- 🔄 CUDA-OpenGL interoperability (pending)

## Troubleshooting

### GPU Access Issues

Ensure NVIDIA Container Toolkit is installed and configured:
- [NVIDIA Container Toolkit Installation](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html)

### Display Issues

The container uses Xvfb (virtual framebuffer) for headless rendering. For actual display output, you may need to configure X11 forwarding or use VNC.

## Next Steps

1. Implement torus geometry generation
2. Add CUDA kernels for animation effects
3. Set up CUDA-OpenGL interoperability
4. Add web interface for parameter control (port 8080)