A GPU-accelerated traffic light management system using HIP (Heterogeneous-compute Interface for Portability) that optimizes traffic flow through intelligent synchronization and real-time adaptation.
This system demonstrates the advantages of HIP development by creating a portable, high-performance traffic light management solution that can run on both AMD and NVIDIA GPUs. The system manages thousands of traffic lights simultaneously, optimizing timing based on real-time traffic data and creating synchronized green waves for better traffic flow.
- Parallel State Updates: Updates all traffic lights simultaneously on GPU
- Traffic Flow Optimization: Calculates optimal green light durations based on traffic density
- Green Wave Synchronization: Creates coordinated green waves along corridors
- Congestion Detection: Real-time identification and response to traffic congestion
- Emergency Vehicle Priority: Clears paths for emergency vehicles
- Real-time Traffic Simulation: Models changing traffic patterns
- Emergency Route Management: Handles ambulance, fire truck, and police vehicle routes
- Performance Metrics: Calculates system-wide traffic statistics
- State Export: JSON export of complete system state
- Comprehensive Reporting: Generates detailed status reports
- Live Grid Display: Real-time visualization of traffic light states
- Interactive Controls: Manual optimization and emergency activation
- Metrics Dashboard: Live system performance monitoring
- Alert System: Real-time notifications for congestion and events
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Web Browser (traffic_visualization_connected.html)โ
โ - Real-time visualization โ
โ - Interactive controls โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ WebSocket + REST API
โ (Socket.IO)
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Flask Web Server (traffic_server.py) โ
โ - REST API endpoints โ
โ - WebSocket broadcasting โ
โ - Real-time updates โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Traffic Management System (traffic_manager.py) โ
โ - Simulation engine โ
โ - Traffic optimization โ
โ - Emergency handling โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
This project was developed in HIP instead of CUDA for hardware portability:
- Cross-Vendor Support: The same code runs on both AMD and NVIDIA GPUs
- Performance Parity: On NVIDIA hardware, HIP code achieves near-identical performance to CUDA
- Future-Proofing: Not locked into a single vendor's ecosystem
- Strategic Flexibility: Can deploy on whatever hardware is available or cost-effective
- HIP-capable GPU (AMD Radeon or NVIDIA with HIP support)
- ROCm 5.0+ (AMD) or CUDA 11.0+ with HIP (NVIDIA)
- CMake 3.16+
- C++14 compatible compiler
- Python 3.7+
- No external dependencies (uses only standard library)
- Modern web browser with JavaScript enabled
# Create build directory
mkdir build && cd build
# Configure with CMake
cmake ..
# Build
make
# Run
./traffic_sync# Make executable
chmod +x traffic_manager.py
# Run simulation
python3 traffic_manager.py# Open in your browser
firefox traffic_visualization.html
# or
google-chrome traffic_visualization.html./traffic_syncOutput:
=== City Traffic Light Synchronization System (HIP) ===
Managing 1024 traffic lights in 32x32 grid
Block size: 256, Grid size: 4
Running simulation for 300 seconds...
[t=0s] Avg flow: 1.23, Max congestion: 0.87
[t=60s] Avg flow: 1.18, Max congestion: 0.82
...
from traffic_manager import TrafficLightManager, EmergencyMode
manager = TrafficLightManager(grid_size=32)
# Create emergency route for ambulance
emergency_route = [(x, 16) for x in range(32)]
manager.handle_emergency_vehicle(emergency_route, EmergencyMode.AMBULANCE)
# Generate report
print(manager.generate_report())# Create coordinated green wave going east on street 16
manager.create_green_wave(start_x=0, start_y=16, direction='east',
avg_speed=15.0, block_distance=200.0)The web visualization provides:
- Optimize All Lights: Recalculates timing for all intersections
- Create Green Wave: Generates a progressive green wave
- Emergency Routes: Simulates ambulance, fire truck, or police routes
- Pause/Resume: Control simulation flow
- Click Lights: View detailed intersection information
- updateTrafficLights: O(N) - one thread per light
- optimizeGreenDurations: O(N) - considers neighbors
- synchronizeGreenWave: O(NรK) - K connected lights
- detectCongestion: O(N) - parallel congestion check
- calculateFlowMetrics: O(N) - parallel reduction
- Tested with 32ร32 grid (1,024 lights)
- Can scale to 100ร100 grid (10,000 lights) or more
- Real-time performance at 10Hz update rate
green_duration = min_time + (max_time - min_time) ร density
where density = 0.7 ร local_density + 0.3 ร neighbor_density
offset = distance / avg_vehicle_speed
timer_adjustment = offset % cycle_time
if traffic_density > threshold:
extend_green_time(+5 seconds)
.
โโโ traffic_sync.hip # Main HIP kernel code
โโโ traffic_manager.py # Python management system
โโโ traffic_visualization.html # Web interface
โโโ README.md # This file
__global__ void updateTrafficLights(TrafficLight* lights, int num_lights, float delta_time) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx >= num_lights) return;
TrafficLight* light = &lights[idx];
light->timer -= delta_time;
if (light->timer <= 0) {
// State transition logic
if (light->state == GREEN) {
light->state = YELLOW;
} // ... etc
}
}def handle_emergency_vehicle(self, route, vehicle_type):
# Set all lights in route to GREEN
for light_id in route_light_ids:
light.state = LightState.GREEN
light.timer = 60.0
# Set perpendicular lights to RED
for neighbor in perpendicular_lights:
neighbor.state = LightState.RED- Machine learning for traffic prediction
- Weather-adaptive timing
- Pedestrian crossing optimization
- Real sensor data integration
- Mobile app for emergency vehicles
- 3D visualization with WebGL
This is a demonstration project showing HIP development advantages. Feel free to:
- Extend the simulation with more realistic traffic models
- Add additional optimization algorithms
- Improve the visualization
- Port to other GPU programming models for comparison
- HIP Programming Guide: https://rocm.docs.amd.com/projects/HIP/
- Traffic Flow Theory: Highway Capacity Manual
- Green Wave Timing: TRANSYT optimization methods
- HIP enables portable GPU code - Write once, run on AMD and NVIDIA
- GPU acceleration is ideal for traffic systems - Thousands of lights updated in parallel
- Real-time optimization is feasible - 10+ Hz update rates with complex calculations
- Visualization enhances understanding - Interactive interface makes complex systems accessible
Built with HIP