Skip to content

Commit

Permalink
[js/node] fix CUDA artifact installation script for Linux/x64 (#22984)
Browse files Browse the repository at this point in the history
### Description

This PR updates installation script to fix it for CUDA v12. However, it
may be difficult for CUDA v11 since the steps are quite complicated to
automate. Added a few lines of instructions instead.

fixes #22877
fs-eire authored Dec 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 5c644d3 commit d3bc318
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions js/node/script/install.js
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ const os = require('os');
const fs = require('fs');
const path = require('path');
const tar = require('tar');
const { execFileSync } = require('child_process');
const { Readable } = require('stream');

// commandline flag:
@@ -58,10 +59,23 @@ if (NO_INSTALL || !shouldInstall) {

// Step.2: Download the required binaries
const artifactUrl = {
11: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-${
ORT_VERSION
}.tgz`,
12: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-cuda12-${
get 11() {
// TODO: support ORT Cuda v11 binaries
throw new Error(`CUDA 11 binaries are not supported by this script yet.
To use ONNX Runtime Node.js binding with CUDA v11 support, please follow the manual steps:
1. Use "--onnxruntime-node-install-cuda=skip" to skip the auto installation.
2. Navigate to https://aiinfra.visualstudio.com/PublicPackages/_artifacts/feed/onnxruntime-cuda-11
3. Download the binaries for your platform and architecture
4. Extract the following binaries to "node_modules/onnxruntime-node/bin/napi-v3/linux/x64:
- libonnxruntime_providers_tensorrt.so
- libonnxruntime_providers_shared.so
- libonnxruntime.so.${ORT_VERSION}
- libonnxruntime_providers_cuda.so
`);
},
12: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-${
ORT_VERSION
}.tgz`,
}[INSTALL_CUDA_FLAG || tryGetCudaVersion()];
@@ -108,9 +122,27 @@ Use "--onnxruntime-node-install-cuda=skip" to skip the installation. You will st
function tryGetCudaVersion() {
// Should only return 11 or 12.

// TODO: try to get the CUDA version from the system ( `nvcc --version` )
// try to get the CUDA version from the system ( `nvcc --version` )
let ver = 12;
try {
const nvccVersion = execFileSync('nvcc', ['--version'], { encoding: 'utf8' });
const match = nvccVersion.match(/release (\d+)/);
if (match) {
ver = parseInt(match[1]);
if (ver !== 11 && ver !== 12) {
throw new Error(`Unsupported CUDA version: ${ver}`);
}
}
} catch (e) {
if (e?.code === 'ENOENT') {
console.warn('`nvcc` not found. Assuming CUDA 12.');
} else {
console.warn('Failed to detect CUDA version from `nvcc --version`:', e.message);
}
}

return 11;
// assume CUDA 12 if failed to detect
return ver;
}

function parseInstallCudaFlag() {

0 comments on commit d3bc318

Please sign in to comment.