This is a viewer only at the moment see the article on how this works.
To update the preview hit Ctrl-Alt-R (or ⌘-Alt-R on Mac) or Enter to refresh. The Save icon lets you save the markdown file to disk
This is a preview from the server running through my markdig pipeline
Wednesday, 12 November 2025
警告:这些是“加入”的草稿。
可能很多下面的东西是行不通的; 我制作了这些作为给ME的操作方法, 然后做所有步骤,让样本应用起作用...你一直偷偷摸摸地看到它们!它们很可能在12月中旬就绪。
## 一. 导言 导言 导言 导言 导言 导言 一,导言 导言 导言 导言 导言 导言
欢迎来到第二部分第一部分 第一部分
例如律师如何使用受过判例法培训的LLMs起草文件。
**现在是时候让我们的手和基金会弄脏了:确保您的GPU准备好接受人工智能的工作量。**注:这是我对人工智能(协助起草)和我自己编辑的实验的一部分。
同一个声音,同样的务实;只是更快的手指。关于我的硬件我使用NVIDIA RTX A4000(16GB VRAM)、AMD Ryzen 99950X和96GB DDCP5 RAM。但你不需要这个!如第一部分所述,您可以使用任何带有 8GB+ VRAM 的 NVIDIA GPU, 或甚至只运行 CPU( 较小但功能性) 。
如果你已经熟悉这个部分的话,这个部分可能看起来很基本
graph LR
A[AI Workload] --> B{Type?}
B -->|Matrix Operations| C[GPU: 100x+ faster]
B -->|Sequential Logic| D[CPU: Better]
C --> E[Embedding Generation]
C --> F[LLM Inference]
C --> G[Vector Search]
D --> H[Application Logic]
D --> I[File I/O]
class C gpu
class E,F,G aiTasks
classDef gpu stroke:#333,stroke-width:4px
classDef aiTasks stroke:#333
相信我,我浪费了无数小时 去调试神秘错误 追溯到版本错配、环境变数缺失或错误:
- GPU有成千上万个核心 相对于CPU的几十个矩阵业务
- 人工智能主要是矩阵数学,GPU最擅长内存带宽
- GPUs移动数据的速度要快得多专用硬件
感测核心加速AI型具体行动
真实世界实例制作博客文章的嵌入内容:
(24GB): 最快, ~ 0. 秒/ 秒/ 秒 (24GB): 最快, ~ 0. 秒/ 秒/ 秒/ 秒( 24GB): 最快, ~ 0. 秒/ 秒/ 秒/ 秒/ 秒/ 秒( 24GB): 最快
(12GB):~每个职位0.5 %
6144 CUDA核心核心
RTX 4090 24GB 13B-30B*** RTX 4070 Ti * 12GB * 7B-13B * 最佳选择 ***
***RTX 3060 * 12GB * 7B * 预算友好 * * 12GB * 7B * 预算友好 ***RTX 4060 Ti 16GB 7B-13B 价值
*** A4000(地雷) * 16GB * 7B-13B * 工作站GPU * 16GB * 7B-13B * 工作站 GPU ***:
: NPUs 不支持 CUDA, 此教义使用的 CUDA:
:LLMM项目仍在成熟如果您有 NPU 设备 CPU 的 CPU现在只使用 CPU 模式( 一切工作, 慢一点)
ONNX 运行时间直接洗钱
# PowerShell
wmic path win32_VideoController get name
更新更新更新
Name
NVIDIA RTX A4000
当 NAPU 支持改进时, 未来部分将会注意
VIVDIA 哥达
graph TB
A[Your C# Application] --> B[ONNX Runtime / LLamaSharp]
B --> C[CUDA Toolkit]
C --> D[cuDNN Libraries]
D --> E[NVIDIA Driver]
E --> F[GPU Hardware]
G[TensorRT] -.Optional.-> D
class A,F endpoints
class C,D,E install
classDef endpoints stroke:#333,stroke-width:4px
classDef install stroke:#333,stroke-width:2px
subgraph "What We'll Install"
C
D
E
end
因为它在.NET中是成熟的, 并得到了很好的支持, 但是一旦生态系统赶上, 这些概念就会转化成NPUs!:
CHUNDN CHIN CHIDDN 中, cCDN 中, CDN 中, CDN 中, CDN 中, CDN 中, CDN 中, CDN 中, CDN 中, CDDN 中
graph LR
A[1. NVIDIA Driver] --> B[2. CUDA Toolkit]
B --> C[3. cuDNN]
C --> D[4. Verify Install]
D --> E[5. Test from C#]
class A,B,C,D,E steps
classDef steps stroke:#333,stroke-width:2px
nvidia-smi
您的应用程序应用程序
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 546.33 Driver Version: 546.33 CUDA Version: 12.3 |
|-------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 NVIDIA RTX A4000 WDDM | 00000000:01:00.0 Off | Off |
| 41% 32C P8 10W / 140W | 345MiB / 16376MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
- 我们的C#代码:
Driver Version安装路线图CUDA Version以下是我们安装东西的命令(命令事项! ) :Memory-Usage步骤1:NVIDIA驱动程序开放电源外壳( Open PowerShell) :nvidia-smi您应该看到输出如 :
密钥信息:应该是545.xx或更新
: 这是支持的 MAX CUDA 版本, 而不是安装的版本 。
RTX A4000 RTX A4000
操作系统 :nvidia-smi
(或你的版本)
演播室司机(比游戏准备更稳定)安装并重新启动再次核查
CUDA 工具包档案
Installation Type: Custom (Advanced)
Select Components:
✅ CUDA Toolkit
✅ CUDA Documentation
✅ CUDA Samples
✅ CUDA Visual Studio Integration
❌ GeForce Experience (not needed)
❌ NVIDIA Driver (already installed)
选择CUDA 工具包12.1
选择 :
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1
视窗 x86_64 + 11 + exe (当地)
安装选项
运行安装器。:
$env:CUDA_PATH
# Should show: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1
$env:PATH -split ';' | Select-String CUDA
# Should show CUDA bin and libnvvp paths
提示时 ::
为什么定制?:我们不想降低驾驶员的级别或安装游戏软件。:
This PC默认路径为罚款 :但请注意,我们的环境变数需要它!设置环境变量安装器通常设置这些, 但验证 :
CUDA_PATH = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1CUDA_PATH_V12_1 = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1在 PowerShell 中检查Path如果缺缺, 手动添加
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\libnvvp
开放环境变量
# Check CUDA compiler
nvcc --version
# Should output:
# nvcc: NVIDIA (R) Cuda compiler driver
# Copyright (c) 2005-2023 NVIDIA Corporation
# Built on Tue_Feb__7_19:32:13_Pacific_Standard_Time_2023
# Cuda compilation tools, release 12.1, V12.1.66
# Check path resolves
where.exe nvcc
# Should show: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin\nvcc.exe
下 下
,核查/添加:: 内变量,确保存在这些变量:
重新启动您的终端使修改生效CUDA 核查系统安装**第3步:cudNN(CUDA深神经网络图书馆)**cucDNN为深层学习业务提供最佳实施。
转到
CHUDNN 归档您需要一个 NVIDIA 开发者账户( 免费)
cudnn-windows-x86_64-8.9.7.29_cuda12-archive\
bin\
cudnn64_8.dll
cudnn_adv_infer64_8.dll
cudnn_adv_train64_8.dll
... (more DLLs)
include\
cudnn.h
... (header files)
lib\
x64\
cudnn.lib
... (lib files)
查找 ::
# Assuming you extracted to Downloads and CUDA is in default location
# Run PowerShell as Administrator
$cudnnPath = "$env:USERPROFILE\Downloads\cudnn-windows-x86_64-8.9.7.29_cuda12-archive"
$cudaPath = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1"
# Copy DLLs
Copy-Item "$cudnnPath\bin\*.dll" -Destination "$cudaPath\bin\"
# Copy headers
Copy-Item "$cudnnPath\include\*.h" -Destination "$cudaPath\include\"
# Copy libs
Copy-Item "$cudnnPath\lib\x64\*.lib" -Destination "$cudaPath\lib\x64\"
CUDA 12.x 下载 cuDNN v8.9.7 (12月5日,2023年12月5日):
bin\Windows (Zip) 本地安装器C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin\include\提取并安装 cuDNNC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\include\lib\x64\解开 ZIPC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\lib\x64\# Check DLLs exist
Test-Path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin\cudnn64_8.dll"
# Should return: True
# List all cuDNN DLLs
Get-ChildItem "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin\cudnn*.dll"
或者手工操作
nvidia-smi
至
nvcc --version
至
# All these should return paths
$env:CUDA_PATH
$env:CUDA_PATH_V12_1
# Check PATH includes CUDA bin
$env:PATH -split ';' | Select-String CUDA
核查 cuDNN 安装
步骤4:完成核查:
cd "C:\ProgramData\NVIDIA Corporation\CUDA Samples\v12.1"
让我们确保一切顺利:
cd "1_Utilities\deviceQuery"
硬件检查应该显示您的 GPU 没有错误 。
# If you have VS 2022
"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" deviceQuery_vs2022.vcxproj /p:Configuration=Release /p:Platform=x64
CUDA 检查:
.\x64\Release\deviceQuery.exe
应该显示 CUDA 12.1 (或安装的版本) 。
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "NVIDIA RTX A4000"
CUDA Driver Version / Runtime Version 12.3 / 12.1
CUDA Capability Major/Minor version number: 8.6
Total amount of global memory: 16376 MBytes (17174683648 bytes)
(048) Multiprocessors, (128) CUDA Cores/MP: 6144 CUDA Cores
GPU Max Clock rate: 1560 MHz (1.56 GHz)
Memory Clock rate: 7001 Mhz
Memory Bus Width: 256-bit
L2 Cache Size: 4194304 bytes
...
Result = PASS
系统变量检查: Result = PASS
CUDA 样本测试(备选但建议)
让我们编集和运行一个。
mkdir CudaTest
cd CudaTest
dotnet new console -n CudaTest
cd CudaTest
编成(需要视觉演播室):
dotnet add package Microsoft.ML.OnnxRuntime.Gpu # Latest version
运行它
Microsoft.ML.OnnxRuntime您应该看到输出如 :Microsoft.ML.OnnxRuntime.Gpu关键行步骤5:C#测试Program.cs:
using Microsoft.ML.OnnxRuntime;
using System;
using System.Linq;
namespace CudaTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("=== CUDA Test from C# ===\n");
// Test 1: Can we create a CUDA execution provider?
Console.WriteLine("Test 1: CUDA Execution Provider");
try
{
var cudaProviderOptions = new OrtCUDAProviderOptions();
var sessionOptions = new SessionOptions();
sessionOptions.AppendExecutionProvider_CUDA(cudaProviderOptions);
Console.WriteLine("✅ CUDA execution provider created successfully");
Console.WriteLine($" Device ID: {cudaProviderOptions.DeviceId}");
}
catch (Exception ex)
{
Console.WriteLine($"❌ Failed to create CUDA provider: {ex.Message}");
return;
}
// Test 2: Check available providers
Console.WriteLine("\nTest 2: Available Execution Providers");
var providers = OrtEnv.Instance().GetAvailableProviders();
foreach (var provider in providers)
{
Console.WriteLine($" - {provider}");
}
if (providers.Contains("CUDAExecutionProvider"))
{
Console.WriteLine("✅ CUDA provider is available");
}
else
{
Console.WriteLine("❌ CUDA provider NOT available");
}
// Test 3: Get CUDA device count and info
Console.WriteLine("\nTest 3: CUDA Device Information");
try
{
// ONNX Runtime doesn't expose deviceQuery directly,
// but we can test by trying to create a session
var opts = new SessionOptions();
opts.AppendExecutionProvider_CUDA(0); // Device 0
Console.WriteLine("✅ Successfully configured for CUDA device 0");
Console.WriteLine(" (Full device info requires native CUDA calls)");
}
catch (Exception ex)
{
Console.WriteLine($"❌ CUDA device configuration failed: {ex.Message}");
}
Console.WriteLine("\n=== Test Complete ===");
}
}
}
现在有趣的部分 - 让我们实际使用C#C的CUDA!:
创建测试工程添加 ONNX 使用 CUDA 运行时间
DeviceIdONNX 运行时间为什么是这个包裹?- 只有CPU
创建创建代码分类明细
dotnet run
可以设定内存限值、优化水平等 。:
=== CUDA Test from C# ===
Test 1: CUDA Execution Provider
✅ CUDA execution provider created successfully
Device ID: 0
Test 2: Available Execution Providers
- CUDAExecutionProvider
- CPUExecutionProvider
✅ CUDA provider is available
Test 3: CUDA Device Information
✅ Successfully configured for CUDA device 0
(Full device info requires native CUDA calls)
=== Test Complete ===
如果成功,CUDA正在发挥作用如果它失败了, 堆叠里的东西坏了
Ortenv. Instance (). GetAvaable Providers ():
# Make sure CUDA bin is in PATH
$env:PATH += ";C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin"
# Verify cudnn DLL exists
Test-Path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin\cudnn64_8.dll"
# Try running again
dotnet run
**如果所有设备安装正确, 应该包括“ CUDA 执行 provvider ”**并显示“ CPU 执行 provvider ” 作为后退
运行测试:
dotnet remove package Microsoft.ML.OnnxRuntime
dotnet add package Microsoft.ML.OnnxRuntime.Gpu --version 1.16.3
排除共同错误的麻烦错误 : “ 不退出例外 : 无法装入 DLL 'onnxruntime' ”
原因原因原因原因原因运行时间找不到CUDA DLLs
错误: “ 找不到 CUDA 执行 provider ”
:使用错误的 ONNX 运行时间套件(仅使用CPU) 。
# Download sample model
Invoke-WebRequest -Uri "https://github.com/onnx/models/raw/main/vision/classification/mnist/model/mnist-8.onnx" -OutFile "mnist.onnx"
错误: “ CUDA 错误代码: 35 ( CUDA 驱动程序版本不足) ”Program.cs:
using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using System;
using System.Diagnostics;
using System.Linq;
namespace CudaTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("=== GPU vs CPU Inference Test ===\n");
// Create dummy input (28x28 image flattened to 784 floats)
var inputData = Enumerable.Range(0, 784).Select(i => (float)i / 784).ToArray();
var tensor = new DenseTensor<float>(inputData, new[] { 1, 1, 28, 28 });
var inputs = new List<NamedOnnxValue>
{
NamedOnnxValue.CreateFromTensor("Input3", tensor)
};
// Test 1: CPU Inference
Console.WriteLine("Test 1: CPU Inference");
var cpuTime = TestInference(inputs, useCuda: false, iterations: 100);
Console.WriteLine($" Average time: {cpuTime:F2}ms\n");
// Test 2: GPU Inference
Console.WriteLine("Test 2: GPU Inference");
var gpuTime = TestInference(inputs, useCuda: true, iterations: 100);
Console.WriteLine($" Average time: {gpuTime:F2}ms\n");
// Compare
Console.WriteLine("Comparison:");
Console.WriteLine($" CPU: {cpuTime:F2}ms");
Console.WriteLine($" GPU: {gpuTime:F2}ms");
Console.WriteLine($" Speedup: {cpuTime / gpuTime:F2}x faster on GPU");
}
static double TestInference(List<NamedOnnxValue> inputs, bool useCuda, int iterations)
{
var options = new SessionOptions();
if (useCuda)
{
options.AppendExecutionProvider_CUDA(0);
}
using var session = new InferenceSession("mnist.onnx", options);
// Warmup run (first run is always slower)
session.Run(inputs);
// Timed runs
var sw = Stopwatch.StartNew();
for (int i = 0; i < iterations; i++)
{
using var results = session.Run(inputs);
// Force evaluation
var output = results.First().AsEnumerable<float>().ToArray();
}
sw.Stop();
return sw.Elapsed.TotalMilliseconds / iterations;
}
}
}
原因原因原因原因原因:
**司机太老了,CUDA 12.x。**修整
[1, 1, 28, 28]高级测试: 实际推断**让我们做一些真实的事情 运行一个微小的神经网络 在 GPU 和 CPU 上并比较速度。**下载测试模型
推断试验编码更新更新更新
高频传感器- ONNX 运行时代表多维阵列的方式
dotnet run
=批量_ 大小= 1, 频道= 1, 高度=28, 宽度=28命名为OnnxValue
=== GPU vs CPU Inference Test ===
Test 1: CPU Inference
Average time: 0.42ms
Test 2: GPU Inference
Average time: 0.15ms
Comparison:
CPU: 0.42ms
GPU: 0.15ms
Speedup: 2.80x faster on GPU
- 绑绑输入名称的阵格
时间安排方法 ✅ Driver installed correctly ✅ CUDA Toolkit accessible ✅ cuDNN integrated ✅ ONNX Runtime finds CUDA ✅ C# can run GPU-accelerated inference
预期产出预期产出
sequenceDiagram
participant App as C# Application
participant CPU as CPU Memory
participant GPU as GPU Memory
participant Compute as GPU Cores
App->>CPU: Create input tensor
CPU->>GPU: Transfer input (PCIe)
Note over GPU: Slow! ~16GB/s
GPU->>Compute: Execute model
Note over Compute: Fast! TFLOPS
Compute->>GPU: Write output
GPU->>CPU: Transfer output (PCIe)
Note over GPU: Slow again!
CPU->>App: Return results
(你们的人数会变化)::
graph TD
A[Inference Request] --> B{Model Size}
B -->|< 100MB| C{Batch Size}
B -->|> 100MB| D[Use GPU]
C -->|Single Item| E[Use CPU]
C -->|Batch > 10| D
D --> F[10-100x Faster]
E --> G[Lower Latency for Single]
class D,E choice
classDef choice stroke:#333,stroke-width:2px
内存传输瓶头:
保留 GPU 上的数据
CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU CPU
nvidia-smi- 小型模型、单一请求、延迟临界nvcc博客写作助理:
批次处理 100+块 GPULLM 推断- 大型型号(7B参数)+GPU
矢量搜索
摘要摘要摘要
我们已经成功:
和
我们的开发环境已经准备好接受人工智能的工作量了!
# Check GPU
nvidia-smi
# Check CUDA
nvcc --version
where.exe nvcc
# Check cuDNN
Test-Path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin\cudnn64_8.dll"
# Check environment
$env:CUDA_PATH
$env:PATH -split ';' | Select-String CUDA
# Test from C#
dotnet run
我们将深入潜入嵌入和矢量数据库:
|-------|-------|-----|
| nvidia-smi什么是嵌入式, 它们如何使语义搜索得以进行 ?
| nvcc在 Qdrant、 pgvector 和其他选项之间选择
正在生成本地嵌入 ONNX 运行时间
高效存储和查询数以百万计的矢量Microsoft.ML.OnnxRuntime.Gpu |
建立我们第一个语义搜索原型
排除故障解决参考 |--------------|---------------|--------------|-----------------| 快速诊断命令 共同问题 共同问题 错误 原因 修补
第4部分:建设吸收管道第5部分:视窗客户端第6部分:地方LLM整合
© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.