Skip to content

Commit c5a35fb

Browse files
committed
fix: auto fix more CUDA compilation issues
1 parent ff25df3 commit c5a35fb

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

docs/guide/CUDA.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,23 @@ const cudaCmakeOptionsTable = data.cudaCmakeOptionsTable;
7979
To build `node-llama-cpp` with any of these options, set an environment variable of an option prefixed with `NODE_LLAMA_CPP_CMAKE_OPTION_`.
8080

8181
### Fix the `Failed to detect a default CUDA architecture` Build Error
82-
To fix this issue you have to set the `CUDACXX` environment variable to the path of the `nvcc` compiler.
82+
To fix this issue you have to set the `CUDACXX` environment variable to the path of the `nvcc` compiler,
83+
and the `CUDA_PATH` environment variable to the path of the CUDA home directory that contains the `nvcc` compiler.
8384

8485
For example, if you have installed CUDA Toolkit 12.4, you have to run a command like this:
8586
::: code-group
8687
```shell [Linux]
8788
export CUDACXX=/usr/local/cuda-12.4/bin/nvcc
89+
export CUDA_PATH=/usr/local/cuda-12.4
8890
```
8991

9092
```cmd [Windows]
9193
set CUDACXX=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin\nvcc.exe
94+
set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4
9295
```
9396
:::
9497

95-
Then run the build command again to check whether setting the `CUDACXX` environment variable fixed the issue.
98+
Then run the build command again to check whether setting the `CUDACXX` and `CUDA_PATH` environment variables fixed the issue.
9699

97100
### Fix the `The CUDA compiler identification is unknown` Build Error
98101
The solution to this error is the same as [the solution to the `Failed to detect a default CUDA architecture` error](#fix-the-failed-to-detect-a-default-cuda-architecture-build-error).

src/bindings/utils/compileLLamaCpp.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,20 @@ export async function compileLlamaCpp(buildOptions: BuildOptions, compileOptions
259259
)
260260
)
261261
)) {
262-
for (const nvccPath of await getCudaNvccPaths()) {
262+
for (const {nvccPath, cudaHomePath} of await getCudaNvccPaths()) {
263263
if (buildOptions.progressLogs)
264264
console.info(
265-
getConsoleLogPrefix(true) + `Trying to compile again with "CUDACXX=${nvccPath}" environment variable`
265+
getConsoleLogPrefix(true) +
266+
`Trying to compile again with "CUDACXX=${nvccPath}" and "CUDA_PATH=${cudaHomePath}" environment variables`
266267
);
267268

268269
try {
269270
return await compileLlamaCpp(buildOptions, {
270271
...compileOptions,
271272
envVars: {
272273
...envVars,
273-
CUDACXX: nvccPath
274+
CUDACXX: nvccPath,
275+
"CUDA_PATH": cudaHomePath
274276
},
275277
ignoreWorkarounds: [...ignoreWorkarounds, "cudaArchitecture"]
276278
});

src/bindings/utils/detectAvailableComputeLayers.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,22 +348,28 @@ export async function getCudaNvccPaths({
348348
const nvccPotentialPaths = cudaInstallationPaths
349349
.map((cudaInstallationPath) => {
350350
if (platform === "win")
351-
return path.join(cudaInstallationPath, "bin", "nvcc.exe");
352-
353-
return path.join(cudaInstallationPath, "bin", "nvcc");
351+
return {
352+
nvccPath: path.join(cudaInstallationPath, "bin", "nvcc.exe"),
353+
cudaHomePath: cudaInstallationPath
354+
};
355+
356+
return {
357+
nvccPath: path.join(cudaInstallationPath, "bin", "nvcc"),
358+
cudaHomePath: cudaInstallationPath
359+
};
354360
});
355361

356362
try {
357-
const resolvedNvccPaths = await Promise.all(
358-
nvccPotentialPaths.map(async (nvccPotentialPath) => {
359-
if (await fs.pathExists(nvccPotentialPath))
360-
return nvccPotentialPath;
363+
const resolvedPaths = await Promise.all(
364+
nvccPotentialPaths.map(async ({nvccPath, cudaHomePath}) => {
365+
if (await fs.pathExists(nvccPath))
366+
return {nvccPath, cudaHomePath};
361367

362368
return null;
363369
})
364370
);
365371

366-
return resolvedNvccPaths.filter((nvccPath): nvccPath is string => nvccPath != null);
372+
return resolvedPaths.filter((resolvedPath) => resolvedPath != null);
367373
} catch (err) {
368374
console.error(getConsoleLogPrefix() + `Failed to search for "nvcc${platform === "win" ? ".exe" : ""}" in CUDA installation paths`, err);
369375
}

0 commit comments

Comments
 (0)