-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathconfigure
More file actions
77 lines (67 loc) · 2.4 KB
/
configure
File metadata and controls
77 lines (67 loc) · 2.4 KB
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
#!/bin/sh
# configure — auto-detect CUDA for RcppML
#
# This script is run by R CMD INSTALL before compiling the package.
# It detects optional dependencies (CUDA) and generates:
# 1. src/Makevars — compiler flags for the R package build
# 2. inst/build_config — capability summary for R-side runtime detection
#
# The GPU shared library (RcppML_gpu.so) is NOT built here — it requires
# a separate `make -f src/Makefile.gpu` step (see PRODUCTION_STATUS.md §6).
# This script merely records the CUDA location so R can find it.
echo "=== Configuring RcppML ==="
# ---- Detect CUDA ----
CUDA_FOUND="no"
NVCC_PATH=""
CUDA_VERSION=""
CUDA_HOME_DETECTED=""
if [ -n "$CUDA_HOME" ]; then
CUDA_HOME_DETECTED="$CUDA_HOME"
elif command -v nvcc >/dev/null 2>&1; then
CUDA_HOME_DETECTED=$(dirname $(dirname $(command -v nvcc)))
fi
if [ -n "$CUDA_HOME_DETECTED" ] && [ -x "$CUDA_HOME_DETECTED/bin/nvcc" ]; then
CUDA_FOUND="yes"
NVCC_PATH="$CUDA_HOME_DETECTED/bin/nvcc"
CUDA_VERSION=$("$NVCC_PATH" --version 2>/dev/null | grep "release" | sed 's/.*release \([0-9.]*\).*/\1/')
echo " CUDA: found (nvcc: $NVCC_PATH, version: $CUDA_VERSION)"
else
echo " CUDA: not found (GPU features will be unavailable)"
fi
# ---- Detect GPU architecture ----
GPU_ARCH=""
if [ "$CUDA_FOUND" = "yes" ] && command -v nvidia-smi >/dev/null 2>&1; then
GPU_ARCH=$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader 2>/dev/null | head -1 | tr -d '.')
if [ -n "$GPU_ARCH" ]; then
echo " GPU architecture: sm_$GPU_ARCH"
fi
fi
# ---- Detect OpenMP ----
# OpenMP detection is handled by R's $(SHLIB_OPENMP_CXXFLAGS)
# We just record whether it's likely available
OMP_FOUND="unknown"
if [ -n "$SHLIB_OPENMP_CXXFLAGS" ]; then
OMP_FOUND="yes"
fi
# ---- Generate src/Makevars ----
echo " Generating src/Makevars..."
if [ -f src/Makevars.in ]; then
sed \
-e "s|@CUDA_FOUND@|${CUDA_FOUND}|g" \
-e "s|@CUDA_HOME@|${CUDA_HOME_DETECTED}|g" \
src/Makevars.in > src/Makevars
else
echo " Warning: src/Makevars.in not found, using existing src/Makevars"
fi
# ---- Write build config for R runtime ----
mkdir -p inst
cat > inst/build_config << EOF
# Auto-generated by configure — do not edit
cuda_found=${CUDA_FOUND}
cuda_version=${CUDA_VERSION}
cuda_home=${CUDA_HOME_DETECTED}
nvcc_path=${NVCC_PATH}
gpu_arch=${GPU_ARCH}
build_date=$(date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date)
EOF
echo "=== Configuration complete ==="