Skip to content

Implement cuBLASter: CUDA-accelerated lattice reduction library#1

Closed
cxzhong with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-8deb1782-1fb2-44ee-a082-f5a684f06f9b
Closed

Implement cuBLASter: CUDA-accelerated lattice reduction library#1
cxzhong with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-8deb1782-1fb2-44ee-a082-f5a684f06f9b

Conversation

Copilot AI commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

This PR implements cuBLASter, a CUDA-accelerated version of the BLASter lattice reduction library. The implementation provides GPU-accelerated matrix operations using NVIDIA's cuBLAS library while maintaining compatibility with CPU-only environments through an automatic fallback system.

Key Features

CUDA/cuBLAS Integration: Implements GPU-accelerated matrix multiplication operations using cuBLAS for high-performance linear algebra operations on NVIDIA GPUs.

Automatic Fallback System: The build system automatically detects CUDA availability at compile time and seamlessly falls back to CPU implementations when CUDA is not available, ensuring the library works in all environments.

Robust Build System: Custom setuptools extension that handles both CUDA compilation (using nvcc) and standard C++ compilation, with proper error handling and dependency management.

Python Integration: Complete Cython-based Python bindings with proper memory management, error handling, and GPU memory reporting capabilities.

Implementation Details

The core matrix operations have been ported from Eigen3 (CPU) to cuBLAS (GPU):

  • cuda_matmul: General matrix multiplication C = A × B
  • cuda_left_matmul: In-place left multiplication B = A × B
  • cuda_right_matmul: In-place right multiplication A = A × B

All operations handle proper GPU memory allocation/deallocation and provide identical interfaces to the original BLASter operations.

Usage

import cublaster_core
import numpy as np

# Initialize (automatically detects CUDA or uses CPU fallback)
cublaster_core.init_cuda(0)

# Perform GPU-accelerated matrix multiplication
A = np.array([[1, 2], [3, 4]], dtype=np.int64)
B = np.array([[5, 6], [7, 8]], dtype=np.int64)
C = cublaster_core.matmul(A, B)  # Uses GPU if available, CPU otherwise

# Check memory usage
mem_info = cublaster_core.get_memory_info()
print(f"GPU Memory: {mem_info['used_mb']}MB / {mem_info['total_mb']}MB")

Build System

The implementation includes a sophisticated build system that:

  • Automatically detects CUDA installation
  • Compiles .cu files with nvcc when CUDA is available
  • Falls back to CPU implementations when CUDA is not found
  • Handles all necessary library linking (cudart, cublas)
  • Provides proper error messages and build guidance

Testing

Comprehensive tests verify that all matrix operations produce identical results to NumPy/Eigen3 implementations, ensuring mathematical correctness across both GPU and CPU execution paths.

This implementation provides the foundation for GPU-accelerated lattice reduction algorithms while maintaining full compatibility with the original BLASter interface and behavior.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@cxzhong cxzhong closed this Sep 15, 2025
@cxzhong cxzhong deleted the copilot/fix-8deb1782-1fb2-44ee-a082-f5a684f06f9b branch September 15, 2025 15:43
Copilot AI changed the title [WIP] like my last repo cxzhong/BLASter, we just use cuda to implement Implement cuBLASter: CUDA-accelerated lattice reduction library Sep 15, 2025
Copilot AI requested a review from cxzhong September 15, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants