-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_midgard.sh
More file actions
executable file
·154 lines (132 loc) · 4.6 KB
/
setup_midgard.sh
File metadata and controls
executable file
·154 lines (132 loc) · 4.6 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#
# Copyright(c) 2025 Intel. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
#
#!/bin/bash
source "run/utils/common.sh"
# Setup conda environment
setup_conda_environment() {
log "INFO" "Setting up Python virtual environment $ENV_NAME with conda"
echo "Checking conda installation."
if ! command -v conda &> /dev/null; then
log "ERROR" "conda could not be found, please install it first."
exit 1
fi
# Check if the $ENV_NAME environment exists
if conda env list | grep -q "$ENV_NAME"; then
echo "$ENV_NAMEenvironment already exists."
local regenerate=${1:-false}
if [ "$regenerate" = true ]; then
echo "Regenerating $ENV_NAME environment."
conda remove -n $ENV_NAME --all -y
conda create -n $ENV_NAME python=$PYTHON_VERSION -y
fi
else
echo "$ENV_NAME environment doesn't exist."
echo "Creating the $ENV_NAME environment."
conda create -n $ENV_NAME python=$PYTHON_VERSION -y
fi
echo "Activating $ENV_NAME environment."
activate_env
}
# Install the required python packages
install_required_packages() {
### UPGRADE PIP ###
log "INFO" "Upgrading pip"
pip install --upgrade pip || { log "ERROR" "Failed to upgrade pip"; exit 1; }
### DETECT OPERATING SYSTEM ###
OS_TYPE=$(uname)
log "INFO" "Detected OS: $OS_TYPE"
### DETECT SYSTEM ARCHITECTURE ###
ARCH_TYPE=$(uname -m)
log "INFO" "Detected Architecture: $ARCH_TYPE"
### SELECT REQUIREMENTS FILE BASED ON OS AND ARCHITECTURE ###
if [[ "$OS_TYPE" == "Darwin" ]]; then
if [[ "$ARCH_TYPE" == "arm64" ]]; then
REQUIREMENTS_FILE="requirements_apple.txt"
log "INFO" "Selected requirements file for macOS ARM (Apple Silicon)."
else
log "ERROR" "Unsupported architecture on macOS: $ARCH_TYPE"
exit 1
fi
elif [[ "$OS_TYPE" == "Linux" ]]; then
if [[ "$ARCH_TYPE" == "x86_64" ]]; then
# Further detect if Intel AI silicon is present
if lscpu | grep -i "Intel" &>/dev/null && command -v intel_gpu_top &>/dev/null; then
REQUIREMENTS_FILE="requirements_intel.txt"
# Please check https://dgpu-docs.intel.com/driver/client/overview.html#ubuntu-24.10-24.04
log "INFO" "Selected requirements file for Linux with Intel AI silicon."
else
REQUIREMENTS_FILE="requirements_nvidia.txt"
log "INFO" "Selected requirements file for Linux with CUDA."
fi
else
log "ERROR" "Unsupported architecture on Linux: $ARCH_TYPE"
exit 1
fi
else
log "ERROR" "Unsupported OS: $OS_TYPE"
exit 1
fi
### INSTALL REQUIRED PACKAGES ###
if [ -f "$REQUIREMENTS_FILE" ]; then
log "INFO" "Installing Python packages from $REQUIREMENTS_FILE"
pip install --use-pep517 -r "$REQUIREMENTS_FILE" || { log "ERROR" "Failed to install packages from $REQUIREMENTS_FILE"; exit 1; }
else
log "ERROR" "$REQUIREMENTS_FILE not found."
exit 1
fi
}
build_package() {
log "INFO" "Checking compiler"
local CC
local CXX
CC=$(which gcc)
CXX=$(which g++)
# Check GCC version
$CC --version || { log "ERROR" "Failed to find a suitable C compiler"; exit 1; }
# Check G++ version
$CXX --version || { log "ERROR" "Failed to find a suitable C++ compiler"; exit 1; }
log "INFO" "Building the onet packages"
python setup.py build_ext --inplace
log "INFO" "Installing..."
pip install -e .
}
build_manifold_tools() {
log "INFO" "Checking compiler"
local CXX
CXX=$(which g++)
if [ -z "$CXX" ]; then
log "ERROR" "g++ not found, please install a suitable C++ compiler."
exit 1
fi
# Check G++ version
$CXX --version || { log "ERROR" "Failed to find a suitable C++ compiler"; exit 1; }
log "INFO" "Building the manifold packages"
if [ -d "core/utils/Manifold/build" ]; then
rm -r "core/utils/Manifold/build"
fi
mkdir -p core/utils/Manifold/build
pushd core/utils/Manifold/build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j8
popd
}
# Handle SIGINT
handle_sigint() {
log "WARNING" "SIGINT received, cleaning up..."
exit 1 # Exit the script
}
# Run tests
run_tests() {
log "INFO" "Running Unittests..."
pushd tests
pytest test_torch_env.py || { log "ERROR" "Tests failed"; exit 1; }
popd
}
# Main execution
setup_conda_environment "$1"
install_required_packages
build_manifold_tools
build_package
run_tests
log "INFO" "Done!"