[js/node] fix CUDA artifact installation script for Linux/x64 (#22984)

### 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
This commit is contained in:
Yulong Wang 2024-12-03 16:07:43 -08:00 committed by GitHub
parent 5c644d3747
commit d3bc3180d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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() {