|
| 1 | +# Notes on developing under WSL |
| 2 | + |
| 3 | +This repository can be run under Windows and WSL at the same time. The setup.bat |
| 4 | +and setup.sh scripts will install runtimes and virtual environments into specific |
| 5 | +locations for the given OS. Virtual environments, for example, will live under |
| 6 | +the /bin/windows folder for a module in Windows, and /bin/linux when under Linux. |
| 7 | +This allows the same code and models to be worked on and tested under both |
| 8 | +Operating Systems. |
| 9 | + |
| 10 | +Note that this means you will need VS Code installed in Windows and in the WSL |
| 11 | +hosted Ubuntu (should you choose to use Ubuntu in WSL). This further requires |
| 12 | +that each instance of VS Code has the necessary extensions installed. The |
| 13 | +profile sync mechanism in VS Code makes this seamless. |
| 14 | + |
| 15 | +## VSCode integrated terminals won't load .bashrc, and so $PATH may not be accurate |
| 16 | + |
| 17 | +If you are using VSCode in WSL, the integrated terminal doesn't load the login |
| 18 | +stuff. This means your .bashrc isn't loaded. |
| 19 | + |
| 20 | +If you've installed a CUDA toolkit which has set paths in the `PATH` variable |
| 21 | +and updated the .bashrc file, the `PATH` variable won't have the CUDA paths in |
| 22 | +it, meaning you won't get access to all the CUDA tools (typically just |
| 23 | +`nvidia-smi`, not `nvcc`). |
| 24 | + |
| 25 | +If the install scripts can only see `nvidia-smi` and not `nvcc` then those |
| 26 | +scripts will potentially see an incorrect version of CUDA. `nvidia-smi` reports |
| 27 | +the maximum CUDA version the drivers can support, whereas `nvcc` reports the |
| 28 | +actual CUDA version installed and accessible. |
| 29 | + |
| 30 | +Getting the wrong version of CUDA means potentially the wrong version of Python |
| 31 | +libraries such as PyTorch will be installed, leading to instability or failure. |
| 32 | + |
| 33 | +Install CodeProject.AI on a CUDA under WSL using a terminal window, not the |
| 34 | +integrated VSCode terminal |
| 35 | + |
| 36 | +## Getting a VSCode Integrated terminal to load login profiles under WSL |
| 37 | + |
| 38 | +To get the login profile loaded add this to your settings.json file |
| 39 | + |
| 40 | +```json |
| 41 | +"terminal.integrated.shellArgs.windows": ["-l"], |
| 42 | +"terminal.integrated.shellArgs.linux": ["-l"], |
| 43 | +"terminal.integrated.shellArgs.osx": ["-l"], |
| 44 | +``` |
| 45 | +The settings files are typically located in |
| 46 | + |
| 47 | +| OS | settings location | |
| 48 | +|---------|---------------------------------------------------------------| |
| 49 | +| Windows | `C:\Users\<username>\AppData\Roaming\Code\User\settings.json` | |
| 50 | +| Linux | `$HOME/.config/Code/User/settings.json` | |
| 51 | +| macOS | `$HOME/Library/Application\ Support/Code/User/settings.json` | |
| 52 | + |
| 53 | +You can also set your default profiles to achieve the same result (replace `osx` |
| 54 | +with `Windows` and `Linux` for other OS's) |
| 55 | + |
| 56 | +```json |
| 57 | +"terminal.integrated.profiles.osx": { |
| 58 | + "bash": { |
| 59 | + "path": "bash", |
| 60 | + "args": ["-l"] |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +See this [Stackoverflow discussion](https://stackoverflow.com/questions/51820921/vscode-integrated-terminal-doesnt-load-bashrc-or-bash-profile) for more information. |
| 66 | + |
| 67 | +## Speed considerations |
| 68 | + |
| 69 | +To share the same files and code between WSL (Ubuntu) and Windows, you need to |
| 70 | +have one environment point to files in another. Often this would mean that the |
| 71 | +file system lives in Windows, and the WSL instance accesses the Windows hosted |
| 72 | +files through the magic of WSL. |
| 73 | + |
| 74 | +Crossing the OS boundary will result in poor disk performance for the WSL |
| 75 | +instance. Having a WSL instance of VS Code work on its own copy of this repo, |
| 76 | +separate from the Windows instance, speeds disk access (eg PIP installs) |
| 77 | +dramatically. |
| 78 | + |
| 79 | +If you want speed, have a separate installation of this project in WSL. |
| 80 | + |
| 81 | +## Space considerations |
| 82 | + |
| 83 | +If you choose to run separate copies of the code in WSL and Windows then it means |
| 84 | +you are doubling up on the code, libraries, tools, and compiled executables. If |
| 85 | +you have limited disk space this can be an issue. |
| 86 | + |
| 87 | +If you are low on space, use a shared installation of this project for WSL and |
| 88 | +Windows. |
| 89 | + |
| 90 | +### To free up space |
| 91 | + |
| 92 | +To free up space you can use the clean.bat/clean.sh scripts under |
| 93 | +/src/SDK/Utilities. |
| 94 | + |
| 95 | +For Windows |
| 96 | +```cmd |
| 97 | +cd devops\install |
| 98 | +clean all |
| 99 | +``` |
| 100 | +For Linux/macOS |
| 101 | +```cmd |
| 102 | +cd devops/install |
| 103 | +bash clean.sh all |
| 104 | +``` |
| 105 | + |
| 106 | +Run `clean` without a parameter to see the options for fine-tuning what gets |
| 107 | +cleaned. |
| 108 | + |
| 109 | +To actually realise the freed up space in WSL you will need to compact the VHD |
| 110 | +in which your WSL instance resides. |
| 111 | + |
| 112 | +In a Windows terminal: |
| 113 | + |
| 114 | +```cmd |
| 115 | +wsl --shutdown |
| 116 | +diskpart |
| 117 | +``` |
| 118 | + |
| 119 | +This will shutdown WSL and open a disk partition session in a new window. Locate |
| 120 | +the VHD file for WSL by heading to `%LOCALAPPDATA%\Packages` and looking for a |
| 121 | +folder similar to `CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState` that |
| 122 | +contains a file `ext4.vhd`. |
| 123 | + |
| 124 | +Within the session, enter the following (adjusting the `ext4.vhd` location as needed) |
| 125 | + |
| 126 | +```text |
| 127 | +select vdisk file="%LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx" |
| 128 | +attach vdisk readonly |
| 129 | +compact vdisk |
| 130 | +detach vdisk |
| 131 | +exit |
| 132 | +``` |
| 133 | + |
| 134 | +Your WSL virtual hard drive should be smaller and the space that was used |
| 135 | +reclaimed by Windows. |
0 commit comments