Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphics: optimize getNvidiaSmi() #927

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

jhgg
Copy link

@jhgg jhgg commented Aug 17, 2024

narrows down candidate directories smarter, uses stat to check for file existence instead of listing all files in the directory and then checking inside that array, and also avoids calling stat for the same file multiple times.

narrows down candidate directories smarter, uses stat to check for file existence instead of listing all files in the directory and then checking inside that array, and also avoids calling stat for the same file multiple times.
lib/graphics.js Outdated
});
let newestNvidiaSmi = null;
for (const dir of fs.readdirSync(basePath)) {
// nvidia-smi will only be located in directories starting with `nvdm`.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may or may not be true. we may want to broaden this to just look inside all directories that start with nv (case insensitive.)

@apacheli
Copy link

Heloo jhgg,

Thanks for letting my borrow you lamborghini that one day.

@WamWooWam
Copy link

at least on my system, nvidia-smi is just sitting in C:\Windows\system32, would it be an idea to add a fastpath for that case?

@jhgg
Copy link
Author

jhgg commented Aug 18, 2024

at least on my system, nvidia-smi is just sitting in C:\Windows\system32, would it be an idea to add a fastpath for that case?

from my understanding that's a legacy path. can you check the creation time?

@WamWooWam
Copy link

11/07/2024, last time i updated my drivers

@x3rt
Copy link

x3rt commented Aug 18, 2024

11/07/2024, last time i updated my drivers

Mine is also located in C:\Windows\System32

Created: ‎July ‎21, ‎2024
Modified: ‎July ‎11, ‎2024

So I am assuming I installed the driver on the 21st, and it was released on the 11th

@ovinusreal ovinusreal mentioned this pull request Aug 18, 2024
@sylveon
Copy link

sylveon commented Aug 18, 2024

When a driver is installed, it gets staged into the driver store, and then most of its files get a corresponding symlink in System32 (via the CopyFiles directive in the driver's .inf). Thus, we can expect there to be a nvidia-smi.exe in System32 which matches the currently installed driver. If nvidia-smi.exe is missing, there is no Nvidia driver on the system.

PS C:\Users\Sylveon> Get-ChildItem -Path "C:\Windows\System32\nvidia-smi.exe" | ft FullName,LinkType,Target

FullName                           LinkType Target
--------                           -------- ------
C:\Windows\System32\nvidia-smi.exe HardLink {C:\Windows\System32\DriverStore\FileRepository\nvdm.inf_amd64_0d61be38b98be4ce\nvidia-smi.exe}

There is absolutely no need to scan the driver store.

@sylveon
Copy link

sylveon commented Aug 18, 2024

We can be sure nvidia-smi.exe always gets symlinked, because, when looking at a driver's INF file, we can find the following:
image

And every section in the driver INF has a CopyFile directive for that:
image

It's not legacy, as they do not implement the corresponding state for Run From Driver Store

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants