我正在尝试使用 TensorRT C++ API 从 ONNX 模型创建一个tensorrt 引擎。我已经根据文档编写了代码来读取、序列化张量引擎并将其写入磁盘。我已经使用debian 安装说明在 colab 上安装了tensorrt7 。
这是我正在编译的 C++ 代码g++ rnxt.cpp -o rnxt
#include <cuda_runtime_api.h>
#include <NvOnnxParser.h>
#include <NvInfer.h>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
class Logger : public nvinfer1::ILogger
{
void log(Severity severity, const char* msg) override
{
// suppress info-level messages
if (severity != Severity::kINFO)
std::cout << msg << std::endl;
}
} gLogger;
int main(){
int maxBatchSize = 32;
nvinfer1::IBuilder* builder = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Google Colab 上运行 stylegan2,但使用我的 Drive 上的所有文件,并避免使用 !git clone 来自stylegan2的github。这是我在特定单元格上的代码:
%tensorflow_version 1.x
%cd /content/drive/My Drive/stylegan2-master/
!nvcc test_nvcc.cu -o test_nvcc -run
print('Tensorflow version: {}'.format(tf.__version__) )
!nvidia-smi -L
print('GPU Identified at: {}'.format(tf.test.gpu_device_name()))
Run Code Online (Sandbox Code Playgroud)
结果:
/content/drive/My Drive/stylegan2-master CPU 打招呼。cudaErrorNoDevice:未检测到支持 CUDA 的设备 Tensorflow 版本:1.15.2 NVIDIA-SMI 失败,因为它无法与 NVIDIA 驱动程序通信。确保安装并运行了最新的 NVIDIA 驱动程序。
GPU 标识于:
为什么我无法获得 GPU?我是该领域的新手,所以我可能会遗漏一些非常简单的东西,但仍然无法在互联网上找到答案。
我正在研究具有一维信号的 CNN。它适用于 CPU 设备完全正常。但是,当我在 GPU 中训练模型时,发生了 CUDA 错误。我在调用os.environ['CUDA_LAUNCH_BLOCKING'] = "1"后设置命令。这样做时,发生了错误而不是错误。虽然 nvidia 文档怀疑硬件问题,但我可以用图像训练其他 CNN,没有任何错误。下面是我在训练模型中加载数据和设置数据的代码。RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILEDcublasCreate(handle)cublasSgemmcublasCreate
idx = np.arange(len(dataset)) # dataset & label shuffle in once
np.random.shuffle(idx)
dataset = dataset[idx]
sdnn = np.array(sdnn)[idx.astype(int)]
train_data, val_data = dataset[:int(0.8 * len(dataset))], dataset[int(0.8 * len(dataset)):]
train_label, val_label = sdnn[:int(0.8 * len(sdnn))], sdnn[int(0.8 * len(sdnn)):]
train_set = DataLoader(dataset=train_data, batch_size=opt.batch_size, num_workers=opt.workers)
for i, data in enumerate(train_set, 0): # data.shape = [batch_size, 3000(len(signal)), 1(channel)] tensor
x = data.transpose(1, 2)
label …Run Code Online (Sandbox Code Playgroud) 当我在 conda 环境中构建 DCNv2 时,我收到此消息。
我已经通过nvidia-smi检查了cuda:
Tue Apr 6 20:03:13 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.67 Driver Version: 460.67 CUDA Version: 11.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 GeForce RTX 3070 Off | 00000000:01:00.0 On | N/A |
| 0% 45C P8 17W / 220W | 448MiB / 7979MiB | 23% Default |
| …Run Code Online (Sandbox Code Playgroud) 我看到其他人也遇到此错误,我尝试按照步骤解决,但仍然收到此错误。“运行时错误:输入和参数张量不在同一设备上,在 cpu 处找到输入张量,在 cuda:0 处找到参数张量”
我运行 model.to(device) 和 input_seq.to(device)。错误表示它在 CPU 上找到了输入张量,但所有输入数据都应位于具有 input_seq.to(device) 的 GPU 上。下面是填写代码
text = ['hey how are you','good i am fine','have a nice day']
# Join all the sentences together and extract the unique characters from the combined sentences
chars = set(''.join(text))
# Creating a dictionary that maps integers to the characters
int2char = dict(enumerate(chars))
# Creating another dictionary that maps characters to integers
char2int = {char: ind for ind, char in int2char.items()}
# Finding the length …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用tensorflow 2.6 和 CuDNN 运行基于文本的序列到序列模型。
代码正在运行,但花费的时间令人怀疑。当我检查任务管理器时,我看到以下内容:
这对我来说看起来很奇怪,因为所有内存都被占用,但它并没有承受重负载。这是预期的行为吗?
系统:
在代码中我发现了以下GPU设置
def get_gpu_config():
gconfig = tf.compat.v1.ConfigProto()
gconfig.gpu_options.per_process_gpu_memory_fraction = 0.975 # Don't take 100% of the memory
gconfig.allow_soft_placement = True # Does not aggressively take all the GPU memory
gconfig.gpu_options.allow_growth = True # Take more memory when necessary
return gconfig
Run Code Online (Sandbox Code Playgroud)
我的 python 输出告诉我它找到了我的显卡:
我可能缺少配置吗?它所花费的时间与我在 CPU 系统上所花费的时间相似,这对我来说似乎不太合适。
边注:
我尝试运行的代码必须从tensorflow-gpu 1.12迁移,但这“相对”顺利。
上周我一直在尝试在Azure ML studio中创建一个 python 实验。该工作包括使用具有 CUDA 11.6 的自定义环境来训练 PyTorch (1.12.1) 神经网络以实现 GPU 加速。但是,当尝试任何移动操作时,我收到运行时错误:
device = torch.device("cuda")
test_tensor = torch.rand((3, 4), device = "cpu")
test_tensor.to(device)
Run Code Online (Sandbox Code Playgroud)
CUDA error: all CUDA-capable devices are busy or unavailable
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
Run Code Online (Sandbox Code Playgroud)
我尝试设置 CUDA_LAUNCH_BLOCKING=1,但这不会改变结果。
我还尝试检查 CUDA 是否可用:
print(f"Is cuda available? {torch.cuda.is_available()}")
print(f"Which is the current device? {torch.cuda.current_device()}")
print(f"How many devices do we have? …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 pytorch 来进行生成人工智能。如该视频所示: https://www.youtube.com/watch ?v=_pIMdDWK5sc
我导入所有内容,如图所示:
import os
import torch
import torchvision
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torchvision.datasets as datasets
import torchvision.transforms as transforms
from torch.utils.data import DataLoader, random_split
from torchvision.datasets import MNIST
import matplotlib.pyplot as plt
import pytorch_lightning as pl
random_seed = 42
torch.manual_seed(random_seed)
BATCH_SIZE=128
AVAIL_GPUS = min(1, torch.cuda.device_count())
NUM_WORKERS=int(os.cpu_count() / 2)
Run Code Online (Sandbox Code Playgroud)
但是当我运行训练器时:
trainer = pl.Trainer(max_epochs=20, gpus=AVAIL_GPUS)
trainer.fit(model, dm)
Run Code Online (Sandbox Code Playgroud)
它向我显示了错误:
__init__() got an unexpected keyword argument 'gpus'
Run Code Online (Sandbox Code Playgroud) 我注意到我可以使用内存块来表示使用cudamalloc()或cublasalloc()函数分配的矩阵来调用cublas函数.使用cudamalloc()而不是cublasalloc()分配的数组的矩阵传输速率和计算速度较慢,尽管使用cudamalloc()使用数组还有其他优点.为什么会这样?听到一些评论会很高兴.
我有两个大向量,我试图进行某种元素乘法,其中第一个向量中的偶数元素乘以第二个向量中的下一个奇数元素...并且奇数元素的位置第一个向量中的第一个向量乘以第二个向量中的前一个偶数元素.
例如:
向量1是V1(1)V1(2)V1(3)V1(4)
向量2是V2(1)V2(2)V2(3)V2(4)
V1(1)*V2(2)
V1(3) )*V2(4)
V1(2)*V2(1)
V1(4)*V2(3)
我已经编写了Cuda代码来执行此操作(Pds具有共享内存中第一个向量的元素,Nds是第二个向量):
// instead of % 2, checking the first bit to decide if a number
// is odd/even is faster
if ((tx & 0x0001) == 0x0000)
Nds[tx+1] = Pds[tx] * Nds[tx+1];
else
Nds[tx-1] = Pds[tx] * Nds[tx-1];
__syncthreads();
Run Code Online (Sandbox Code Playgroud)
反正是否有进一步加速此代码或避免分歧?
pytorch ×6
gpu ×4
cuda ×3
python ×3
tensorflow ×2
azure-machine-learning-service ×1
c++ ×1
cublas ×1
memory ×1
nvidia ×1
optimization ×1
performance ×1
tensorrt ×1
ubuntu-20.04 ×1