pipeline {
    agent {
        dockerfile {
            filename 'ci/Dockerfile'
            args '--gpus 1'
            label 'docker && gpu'
        }
    }
    options {
        timeout(time: 1, unit: 'HOURS')
    }
    environment {
        HOME = "$WORKSPACE"
    }
    stages {
        stage('Build') {
            steps {
                sh 'uv sync -v --extra cuda'
            }
        }
        stage('Test') {
            environment {
                OMP_NUM_THREADS = "$PARALLEL"
            }
            steps {
                sh 'uv run --extra cuda pytest -v'
            }
        }
        stage('Test with CUDA Sanitizer') {
            environment {
                OMP_NUM_THREADS = "$PARALLEL"
           }
            steps {
                sh '''
                    uv sync --extra cuda
                    compute-sanitizer .venv/bin/python -m pytest -sv -k cufinufft --benchmark-skip
                '''
            }
        }
    }
}
