Coding Conventions, Error Handling, and Memory Management
Read this for cuOpt code style: naming, file extensions, include order, error handling, memory management, and test impact.
C++ Naming
| Element | Convention | Example |
|---|---|---|
| Variables | snake_case |
num_locations |
| Functions | snake_case |
solve_problem() |
| Classes | snake_case |
data_model |
| Test cases | PascalCase |
SolverTest |
| Device data | d_ prefix |
d_locations_ |
| Host data | h_ prefix |
h_data_ |
| Template params | _t suffix |
value_t |
| Private members | _ suffix |
n_locations_ |
File Extensions
| Extension | Usage |
|---|---|
.hpp |
C++ headers |
.cpp |
C++ source |
.cu |
CUDA source (nvcc required) |
.cuh |
CUDA headers with device code |
Include Order
- Local headers
- RAPIDS headers
- Related libraries
- Dependencies
- STL
Python Style
- Follow PEP 8
- Use type hints
- Tests use pytest
Error Handling
Runtime Assertions
CUOPT_EXPECTS(condition, "Error message");
CUOPT_FAIL("Unreachable code reached");CUDA Error Checking
RAFT_CUDA_TRY(cudaMemcpy(...));Memory Management
// ❌ WRONG
int* data = new int[100];
// ✅ CORRECT - use RMM
rmm::device_uvector<int> data(100, stream);- All operations should accept
cuda_stream_view - Views (
*_viewsuffix) are non-owning
Read existing code in cpp/src/ for real examples of RMM allocation, stream-ordering, RAFT utilities, and kernel launch patterns.
Test Impact Check
Before any behavioral change, ask:
- What scenarios must be covered?
- What's the expected behavior contract?
- Where should tests live?
- C++ gtests:
cpp/tests/ - Python pytest:
python/.../tests/
- C++ gtests:
Add at least one regression test for new behavior.