Mayo commited on
chore(scripts): auto-detect cuda
Browse files- README.md +1 -19
- package.json +5 -0
- scripts/dev.ts +118 -0
README.md
CHANGED
|
@@ -74,28 +74,10 @@ We provide pre-built binaries for Windows, for other platforms, you may need to
|
|
| 74 |
bun install
|
| 75 |
```
|
| 76 |
|
| 77 |
-
### Compile `candle` with CUDA feature
|
| 78 |
-
|
| 79 |
-
The LLM feature heavily relies on [candle](https://github.com/huggingface/candle). To compile `candle-kernel` with CUDA support, you need:
|
| 80 |
-
|
| 81 |
-
1. Download and install [CUDA toolkit 12.9](https://developer.nvidia.com/cuda-12-9-1-download-archive), and follow below steps to set up environment variables:
|
| 82 |
-
|
| 83 |
-
1. Add the CUDA `bin` directory to your `PATH` environment variable (e.g., `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9\bin`).
|
| 84 |
-
2. Set the `CUDA_PATH` environment variable to point to your CUDA installation directory (e.g., `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9`).
|
| 85 |
-
3. Make sure `nvcc` is accessible from the command line by running `nvcc --version`.
|
| 86 |
-
|
| 87 |
-
2. Download and install [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/), during installation, make sure to select the "Desktop development with C++" workload. Then, follow below steps to set up environment variables:
|
| 88 |
-
|
| 89 |
-
1. Open "x64 Native Tools Command Prompt for VS 2022" from the Start menu, and find the path of `cl.exe` by running `where cl`.
|
| 90 |
-
2. Add the directory containing `cl.exe` to your `PATH` environment variable.
|
| 91 |
-
|
| 92 |
### Build
|
| 93 |
|
| 94 |
```bash
|
| 95 |
-
bun
|
| 96 |
-
|
| 97 |
-
# enable CUDA acceleration
|
| 98 |
-
bun tauri build --features cuda
|
| 99 |
```
|
| 100 |
|
| 101 |
### Usage
|
|
|
|
| 74 |
bun install
|
| 75 |
```
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
### Build
|
| 78 |
|
| 79 |
```bash
|
| 80 |
+
bun run build
|
|
|
|
|
|
|
|
|
|
| 81 |
```
|
| 82 |
|
| 83 |
### Usage
|
package.json
CHANGED
|
@@ -1,4 +1,9 @@
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"workspaces": [
|
| 3 |
"ui/"
|
| 4 |
],
|
|
|
|
| 1 |
{
|
| 2 |
+
"scripts": {
|
| 3 |
+
"setup": "bun scripts/dev.ts",
|
| 4 |
+
"dev": "bun run setup tauri dev",
|
| 5 |
+
"build": "bun run setup tauri build"
|
| 6 |
+
},
|
| 7 |
"workspaces": [
|
| 8 |
"ui/"
|
| 9 |
],
|
scripts/dev.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os from 'node:os'
|
| 2 |
+
import path from 'node:path'
|
| 3 |
+
import { readdir, access } from 'node:fs/promises'
|
| 4 |
+
import { exec as execCallback, spawn } from 'node:child_process'
|
| 5 |
+
import { promisify } from 'node:util'
|
| 6 |
+
|
| 7 |
+
const exec = promisify(execCallback)
|
| 8 |
+
|
| 9 |
+
async function pathExists(target: string) {
|
| 10 |
+
try {
|
| 11 |
+
await access(target)
|
| 12 |
+
return true
|
| 13 |
+
} catch {
|
| 14 |
+
return false
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
async function checkNvcc() {
|
| 19 |
+
try {
|
| 20 |
+
await exec('nvcc --version', { env: process.env })
|
| 21 |
+
} catch {
|
| 22 |
+
throw new Error('nvcc not found')
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
async function setupCuda() {
|
| 27 |
+
const cudaPath = process.env.CUDA_PATH
|
| 28 |
+
if (cudaPath) {
|
| 29 |
+
const binPath = path.join(cudaPath, 'bin')
|
| 30 |
+
process.env.PATH = `${binPath}${path.delimiter}${process.env.PATH}`
|
| 31 |
+
return
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const cudaRoot = 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA'
|
| 35 |
+
const versions = await readdir(cudaRoot).catch(() => [])
|
| 36 |
+
|
| 37 |
+
for (const version of versions) {
|
| 38 |
+
if (version.startsWith('v')) {
|
| 39 |
+
const binPath = path.join(cudaRoot, version, 'bin')
|
| 40 |
+
if (await pathExists(binPath)) {
|
| 41 |
+
process.env.PATH = `${binPath}${path.delimiter}${process.env.PATH}`
|
| 42 |
+
process.env.CUDA_PATH = path.join(cudaRoot, version)
|
| 43 |
+
|
| 44 |
+
console.log(`Added CUDA ${version} to PATH: ${binPath}`)
|
| 45 |
+
return
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
throw new Error(
|
| 51 |
+
'NVCC not found. Please install the CUDA Toolkit from https://developer.nvidia.com/cuda-12-9-1-download-archive',
|
| 52 |
+
)
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
async function setupCl() {
|
| 56 |
+
const vsRoot = 'C:/Program Files/Microsoft Visual Studio'
|
| 57 |
+
const vsVersions = await readdir(vsRoot).catch(() => [])
|
| 58 |
+
|
| 59 |
+
for (const vsVersion of vsVersions) {
|
| 60 |
+
const vcPath = path.join(vsRoot, vsVersion, 'Community/VC/Tools/MSVC')
|
| 61 |
+
if (await pathExists(vcPath)) {
|
| 62 |
+
const msvcVersions = await readdir(vcPath)
|
| 63 |
+
for (const msvcVersion of msvcVersions) {
|
| 64 |
+
const binPath = path.join(vcPath, msvcVersion, 'bin/Hostx64/x64')
|
| 65 |
+
if (await pathExists(binPath)) {
|
| 66 |
+
process.env.PATH = `${binPath}${path.delimiter}${process.env.PATH}`
|
| 67 |
+
|
| 68 |
+
console.log(`Added cl.exe to PATH: ${binPath}`)
|
| 69 |
+
return
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
throw new Error(
|
| 76 |
+
'cl.exe not found. Please install Visual Studio with C++ build tools from https://visualstudio.microsoft.com/downloads/',
|
| 77 |
+
)
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
async function dev() {
|
| 81 |
+
if (os.type() === 'Windows_NT') {
|
| 82 |
+
// First, try to check if nvcc is available
|
| 83 |
+
await checkNvcc()
|
| 84 |
+
// If not found, try to set up CUDA paths
|
| 85 |
+
.catch(async () => {
|
| 86 |
+
await setupCuda()
|
| 87 |
+
// Check again after setup
|
| 88 |
+
await checkNvcc()
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
+
// Setup cl.exe path
|
| 92 |
+
await setupCl()
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
const args = process.argv.slice(2)
|
| 96 |
+
if (args.length === 0) {
|
| 97 |
+
throw new Error('No command provided')
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
const proc = spawn(args.join(' '), {
|
| 101 |
+
stdio: 'inherit',
|
| 102 |
+
shell: true,
|
| 103 |
+
env: process.env,
|
| 104 |
+
})
|
| 105 |
+
|
| 106 |
+
proc.on('error', (err) => {
|
| 107 |
+
throw err
|
| 108 |
+
})
|
| 109 |
+
|
| 110 |
+
proc.on('exit', (code) => {
|
| 111 |
+
process.exit(code)
|
| 112 |
+
})
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
dev().catch((err) => {
|
| 116 |
+
process.stderr.write(`Error: ${err.message}`)
|
| 117 |
+
process.exit(1)
|
| 118 |
+
})
|