-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_environment.sh
More file actions
executable file
·120 lines (93 loc) · 2.72 KB
/
setup_environment.sh
File metadata and controls
executable file
·120 lines (93 loc) · 2.72 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
# Function definitions
# print_header() {
# echo "=== $1 ==="
# echo
# }
# print_section() {
# echo ">>> $1"
# }
# print_step() {
# echo ">> $1"
# }
# print_success() {
# echo "✓ $1"
# }
# print_warning() {
# echo "⚠ $1"
# }
# print_error() {
# echo "✗ $1"
# }
# Function to detect GPUs
# Function to create environment file
create_environment_file() {
print_section "Creating Environment File"
# Create environment file
print_step "Creating environment file..."
# Create .mlstack_env file in home directory
cat > $HOME/.mlstack_env << EOF
# ML Stack Environment File
# Created by ML Stack Environment Setup Script
# GPU Selection
export HIP_VISIBLE_DEVICES=$HIP_VISIBLE_DEVICES
export CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES
export PYTORCH_ROCM_DEVICE=$PYTORCH_ROCM_DEVICE
# Performance Settings
export HSA_ENABLE_SDMA=0
export GPU_MAX_HEAP_SIZE=100
export GPU_MAX_ALLOC_PERCENT=100
export HSA_TOOLS_LIB=1
# MIOpen Settings
export MIOPEN_DEBUG_CONV_IMPLICIT_GEMM=1
export MIOPEN_FIND_MODE=3
export MIOPEN_FIND_ENFORCE=3
# PyTorch Settings
export TORCH_CUDA_ARCH_LIST="7.0;8.0;9.0"
export PYTORCH_CUDA_ALLOC_CONF="max_split_size_mb:512"
# MPI Settings
export OMPI_MCA_opal_cuda_support=true
export OMPI_MCA_pml_ucx_opal_cuda_support=true
export OMPI_MCA_btl_openib_allow_ib=true
export OMPI_MCA_btl_openib_warn_no_device_params_found=0
export OMPI_MCA_coll_hcoll_enable=0
export OMPI_MCA_pml=ucx
export OMPI_MCA_osc=ucx
export OMPI_MCA_btl=^openib,uct
# Path Settings
export PATH=\$PATH:/opt/rocm/bin:/opt/rocm/hip/bin
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/opt/rocm/lib:/opt/rocm/hip/lib
EOF
# Add source to .bashrc if not already there
if ! grep -q "source \$HOME/.mlstack_env" $HOME/.bashrc; then
echo -e "\n# Source ML Stack environment" >> $HOME/.bashrc
echo "source \$HOME/.mlstack_env" >> $HOME/.bashrc
fi
# Source the file
source $HOME/.mlstack_env
print_success "Environment file created successfully"
print_step "Environment file: $HOME/.mlstack_env"
print_step "The environment file has been added to your .bashrc file."
print_step "To apply the changes, run: source $HOME/.bashrc"
return 0
}
# Main function
main() {
print_header "ML Stack Environment Setup"
# Detect GPUs
detect_gpus
if [ $? -ne 0 ]; then
print_error "GPU detection failed. Exiting."
exit 1
fi
# Create environment file
create_environment_file
if [ $? -ne 0 ]; then
print_error "Environment file creation failed. Exiting."
exit 1
fi
print_header "ML Stack Environment Setup Complete"
print_step "To apply the changes, run: source $HOME/.bashrc"
return 0
}
# Run main function
main