Skip to content

Commit a4b39a7

Browse files
author
Chris Maunder
committed
Corrections to version sync
1 parent af64cf4 commit a4b39a7

File tree

9 files changed

+162
-68
lines changed

9 files changed

+162
-68
lines changed

docs/WSL-README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Modules": {
3+
4+
"ObjectDetectionYOLOv5-6.2": {
5+
"LaunchSettings": {
6+
"AutoStart": false,
7+
"Runtime": "python3.8"
8+
},
9+
"EnvironmentVariables": {
10+
"MODEL_SIZE": "Tiny", // tiny, small, medium, large
11+
"USE_CUDA": "False"
12+
}
13+
}
14+
}
15+
}

src/SDK/NET/Backend/ModuleWorkerBase.cs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -393,68 +393,6 @@ private ExpandoObject ProcessModuleCommands(BackendRequest request)
393393
}.ToExpando();
394394
}
395395
}
396-
else
397-
response = moduleResponse.ToExpando();
398-
return response;
399-
}
400-
401-
/// <summary>
402-
/// Processes a command sent to a module.
403-
/// </summary>
404-
/// <param name="request">The incoming request</param>
405-
/// <returns>An expando object with the results</returns>
406-
private ExpandoObject ProcessModuleCommands(BackendRequest request)
407-
{
408-
ExpandoObject response;
409-
410-
ModuleResponse moduleResponse = Process(request);
411-
412-
if (!_doNotLogCommands.Contains(request.reqtype))
413-
UpdateStatistics(moduleResponse);
414-
415-
if (moduleResponse.LongProcessMethod is not null)
416-
{
417-
if (_longRunningTask is not null && !_longRunningTask.IsCompleted)
418-
{
419-
response = new
420-
{
421-
Success = false,
422-
CommandId = _longRunningCommandId,
423-
Error = "A long running command is already in progress"
424-
}.ToExpando();
425-
}
426-
else
427-
{
428-
// We have a previous long running process that is now done, but we
429-
// have not stored (nor returned) the result. We can read the result
430-
// now, but we have to start a new process, so...???
431-
// if (_longRunningTask is not null && _longRunningTask.IsCompleted &&
432-
// _lastLongRunningLastOutput is null)
433-
// _lastLongRunningLastOutput = ...
434-
435-
// Store request Id as the command Id for later, reset the last result
436-
string? commandId = request.reqid;
437-
438-
_longRunningCommandId = commandId;
439-
_lastLongRunningOutput = null;
440-
_longRunningTask = null;
441-
442-
// Start the long running process
443-
Console.WriteLine("Starting long process with command ID " + commandId);
444-
445-
_longProcessCancellationTokenSource = new CancellationTokenSource();
446-
CancellationToken cancellationToken = _longProcessCancellationTokenSource.Token;
447-
_longRunningTask = moduleResponse.LongProcessMethod(request, cancellationToken);
448-
449-
response = new
450-
{
451-
Success = true,
452-
CommandId = commandId,
453-
Message = "Command is running in the background",
454-
CommandStatus = "running"
455-
}.ToExpando();
456-
}
457-
}
458396
else
459397
{
460398
response = moduleResponse.ToExpando();

src/SDK/Python/Python.pyproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<InterpreterId>MSBuild|env|$(MSBuildProjectFullPath)</InterpreterId>
1919
<IsWindowsApplication>False</IsWindowsApplication>
2020
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
21+
<SuppressPackageInstallationPrompt>True</SuppressPackageInstallationPrompt>
22+
<SuppressEnvironmentCreationPrompt>True</SuppressEnvironmentCreationPrompt>
2123
</PropertyGroup>
2224

2325
<ItemGroup>

src/server/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ public static async Task Main(string[] args)
9292

9393
// GetProcessStatus a directory for the given platform that allows modules to store persisted data
9494
string programDataDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
95-
string applicationDataDir = programDataDir + "/" + companyName + "/" + productCat;
96-
applicationDataDir = applicationDataDir.Replace('/', Path.DirectorySeparatorChar);
95+
string applicationDataDir = $"{programDataDir}\\{companyName}\\{productCat}".Replace('\\', Path.DirectorySeparatorChar);
9796

9897
// .NET's suggestion for macOS and Linux aren't great. Let's do something different.
9998
if (SystemInfo.IsMacOS)

src/server/appsettings.development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"ModulesDirPath": "%ROOT_PATH%/modules",
2929
"PreInstalledModulesDirPath": "%ROOT_PATH%/preinstalled-modules",
3030
"DemoModulesDirPath": "%ROOT_PATH%/src/demos/modules",
31-
"ExternalModulesDirPath": "",
31+
"ExternalModulesDirPath": "%ROOT_PATH%/../CodeProject.AI-Modules", // ** %EXTERNAL_MODULES_PATH% will expand to this value
3232

3333
"DownloadedModulePackagesDirPath": "%ROOT_PATH%/downloads/modules",
3434
"DownloadedModelsPackagesDirPath": "%ROOT_PATH%/downloads/models",

src/server/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"ModuleListUrl": "https://www.codeproject.com/ai/modules/list", // Location of the JSON list of modules that can be downloaded
9696
"ModelListUrl": "https://www.codeproject.com/ai/models/list", // Location of the JSON list of models that can be downloaded
9797
// "AssetStorageUrl": "https://codeproject-ai.s3.ca-central-1.amazonaws.com/server/assets/",
98+
// "AssetStorageUrl": "https://codeproject-ai-bunny.b-cdn.net/server/assets/",
9899
"AssetStorageUrl": "https://www.codeproject.com/ai/download/server/assets/", // Location of downloadable models
99100

100101
// The location of the AI modules (pre-installed and downloaded/side-loaded)
@@ -107,7 +108,7 @@
107108
"ModulesDirPath": "%ROOT_PATH%/modules", // ** %MODULES_PATH% will expand to this value
108109
"PreInstalledModulesDirPath": "%ROOT_PATH%/preinstalled-modules", // ** %PREINSTALLED_MODULES_PATH% will expand to this value
109110
"DemoModulesDirPath": "%ROOT_PATH%/src/demos/modules", // ** %DEMO_MODULES_PATH% will expand to this value
110-
"ExternalModulesDirPath": "", // ** %EXTERNAL_MODULES_PATH% will expand to this value
111+
"ExternalModulesDirPath": "%ROOT_PATH%/../CodeProject.AI-Modules", // ** %EXTERNAL_MODULES_PATH% will expand to this value
111112

112113
// Downloads for modules and models go here
113114
"DownloadedModulePackagesDirPath": "%ROOT_PATH%/downloads/modules", // Where module packages are downloaded to

src/setup.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ set appRootDirPath=!setupScriptDirPath!
120120

121121
:: The location of large packages that need to be downloaded (eg an AWS S3 bucket
122122
:: name). This will be overwritten using the value from appsettings.json
123-
set assetStorageUrl=https://codeproject-ai.s3.ca-central-1.amazonaws.com/server/assets/
123+
REM set assetStorageUrl=https://codeproject-ai.s3.ca-central-1.amazonaws.com/server/assets/
124+
REM set assetStorageUrl=https://codeproject-ai-bunny.b-cdn.net/server/assets/
125+
set assetStorageUrl=https://www.codeproject.com/ai/download/server/assets/
124126

125127
:: The name of the source directory (in development)
126128
set srcDirName=src

src/setup.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ appRootDirPath="${setupScriptDirPath}"
137137

138138
# The location of large packages that need to be downloaded (eg an AWS S3 bucket
139139
# name). This will be overwritten using the value from appsettings.json
140-
assetStorageUrl='https://codeproject-ai.s3.ca-central-1.amazonaws.com/server/assets/'
140+
# assetStorageUrl='https://codeproject-ai.s3.ca-central-1.amazonaws.com/server/assets/'
141+
# assetStorageUrl='https://codeproject-ai-bunny.b-cdn.net/server/assets/'
142+
assetStorageUrl='https://www.codeproject.com/ai/download/server/assets/'
141143

142144
# The name of the source directory (in development)
143145
srcDirName='src'

0 commit comments

Comments
 (0)