Giter VIP home page Giter VIP logo

switch-cuda's Issues

Linux commands not working after sourcing this file

When I use the script source-cuda.sh to change the cuda version, the LD_LIBRARY_PATH and other variables are properly set but I am unable to even run nvidia-smi. As a matter of fact, even basic commands are not working. I am wondering what could be the problem. Any help would be appreciated.

Also, will creating a symbolic link to /usr/local/cuda achieve the expected behavior? In my case, I tried creating a symbolic link to cuda 10.0 but nvidia-smi is still showing that the Cuda version is 10.2.

Modify the script to the function.

Hello, I am glad to use this convenient script. I would like to use it by using a function, which I think maybe easy to use. Maybe I can pull a request.

# FROM https://github.com/phohenecker/switch-cuda/blob/master/switch-cuda.sh
cudas() {
    set -e
    
    INSTALL_FOLDER="/usr/local"
    TARGET_VERSION=${1}
    
    if [[ -z ${TARGET_VERSION} ]]; then
        echo "The following CUDA installations have been found (in '${INSTALL_FOLDER}'):"
        ls -l "${INSTALL_FOLDER}" | egrep -o "cuda-[0-9]+\\.[0-9]+$" | while read -r line; do
            echo "* ${line}"
        done
        set +e
        return
        elif [[ ! -d "${INSTALL_FOLDER}/cuda-${TARGET_VERSION}" ]]; then
        echo "No installation of CUDA ${TARGET_VERSION} has been found!"
        set +e
        return
    fi
    
    cuda_path="${INSTALL_FOLDER}/cuda-${TARGET_VERSION}"
    
    path_elements=(${PATH//:/ })
    new_path="${cuda_path}/bin"
    for p in "${path_elements[@]}"; do
        if [[ ! ${p} =~ ^${INSTALL_FOLDER}/cuda ]]; then
            new_path="${new_path}:${p}"
        fi
    done
    
    ld_path_elements=(${LD_LIBRARY_PATH//:/ })
    new_ld_path="${cuda_path}/lib64:${cuda_path}/extras/CUPTI/lib64"
    for p in "${ld_path_elements[@]}"; do
        if [[ ! ${p} =~ ^${INSTALL_FOLDER}/cuda ]]; then
            new_ld_path="${new_ld_path}:${p}"
        fi
    done
    
    export CUDA_HOME="${cuda_path}"
    export CUDA_ROOT="${cuda_path}"
    export LD_LIBRARY_PATH="${new_ld_path}"
    export PATH="${new_path}"
    
    echo "Switched to CUDA ${TARGET_VERSION}."
    
    set +e
}

_cudas_autocomplete() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    
    # Directly place the logic for getting CUDA versions here
    INSTALL_FOLDER="/usr/local"
    opts=$(ls -l "${INSTALL_FOLDER}" | egrep -o "cuda-[0-9]+\\.[0-9]+$" | awk -F- '{print $2}')
    
    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    
    return 0
}

complete -F _cudas_autocomplete cudas

Bug while using terminal zsh

When I use bash, this script will run correctly.

But when I use zsh, the PATH will be misly separated.

Then the terminal will show prompt_status:5:command not found:wc always.

I think I could make a Pull Request to let the script support both bash and zsh terminal.

Need I to do that? Looking forward to your response.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.