我正在尝试通过 CUDA 代码将现有项目的一部分移植到 GPU。我知道 cmake 有选项(find_cuda...)来单独处理 .cu 文件,但我仍然试图弄清楚如何在现有项目的上下文中使用这个生态系统。
我的问题如下。假设我有一个带有 cmake 配置文件 (CMakeLists) 的现有 C++ 项目。优雅地(如果可能)包含 CUDA 内核的当前做法是什么?能否以某种方式构建 CMakeLists,仅当存在 GPU 时才编译 .cu 文件?
我目前的想法是创建一个单独的文件夹,其中只存在与CUDA相关的代码,然后将其编译为静态库。这是这样做的方式吗?
我正在学习Tensorflow(希望将它与我的聊天机器人集成),并希望运行此处的示例:
https://www.tensorflow.org/tutorials/recurrent
我下载了建议的存储库,安装了tensorflow(现在是cpu-only版本,但是也试过了--gpu)但是我坚持这个:
python ptb_word_lm.py --data_path=simple-examples/data/ --model=small --rnn_mode=basic
2017-09-21 17:38:09.856638: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-21 17:38:09.856685: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
Traceback (most recent call last):
File "ptb_word_lm.py", line 532, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + …Run Code Online (Sandbox Code Playgroud) 我们有一个 Python 代码,其中涉及昂贵的线性代数计算。数据存储在 NumPy 数组中。该代码使用 numpy.dot 以及一些 BLAS 和 LAPACK 函数,当前可通过 scipy.linalg.blas 和 scipy.linalg.lapack 访问这些函数。当前代码是为CPU编写的。我们想要转换代码,以便一些 NumPy、BLAS 和 LAPACK 操作在 GPU 上执行。
我正在尝试确定执行此操作的最佳方法。据我所知,Numba 不支持 GPU 上的 BLAS 和 LAPACK 函数。看来 PyCUDA 可能是最佳途径,但我无法确定 PyCUDA 是否允许同时使用 BLAS 和 LAPACK 函数。
编辑:我们需要将代码移植到不同的 GPU 架构,包括 AMD 和 Nvidia。虽然 PyCUDA 似乎提供了所需的功能,但 CUDA(以及 PyCUDA)无法在 AMD GPU 上运行。
我使用 AWS p3 实例使用 GPU 加速训练以下模型:
x = CuDNNLSTM(128, return_sequences=True)(inputs)
x = Dropout(0.2)(x)
x = CuDNNLSTM(128, return_sequences=False)(x)
x = Dropout(0.2)(x)
predictions = Dense(1, activation='tanh')(x)
model = Model(inputs=inputs, outputs=predictions)
Run Code Online (Sandbox Code Playgroud)
训练后,我用 Keras 的save_model函数保存了模型,并将其移至没有 GPU 的单独生产服务器。
当我尝试在生产服务器上使用该模型进行预测时,它失败并显示以下错误:
没有注册任何 OpKernel 来支持具有这些属性的 Op 'CudnnRNN'。注册设备:[CPU],注册内核:
我猜这是因为生产服务器没有 GPU 支持,但我希望这不会成为问题。有什么办法可以在没有 GPU 的生产服务器上使用这个模型?
我正在尝试开始使用一些OpenCL编码.
我已经在我的计算机上安装了NVidia CUDA OpenCL,并设法构建了一个简单的"Hello World!" 使用Visual Studio 2017的应用程序.
我还安装了英特尔OpenCL SDK(安装警告我,我需要更新我的OpenCL驱动程序,但英特尔更新管理器告诉我一切都是最新的,所以我不确定这是否是一个问题).
现在每当我在PC上查询OpenCL平台时,都是如此:
std::vector< cl::Platform > platformList;
cl::Platform::get(&platformList);
Run Code Online (Sandbox Code Playgroud)
我只回到我的nVidia openCL平台,我的GPU是唯一的设备.我的CPU没有得到任何回报.
有人可以帮忙吗?是否可以在同一个项目中执行CPU和GPU OpenCL计算(在不同的OpenCL上下文中?我将如何进行此操作?
我正在尝试在Gentoo系统上从源代码安装tensorflow(我认为我需要这样做才能使用CUDA 9.1)。
我能够构建tensorflow,然后以以下用户身份安装它:
pip3 install --no-cache-dir --user /tmp/tensorflow_pkg/tensorflow-1.6.0rc1-cp35-cp35m-linux_x86_64.whl
Run Code Online (Sandbox Code Playgroud)
当我尝试导入tensorflow时,我得到:
>RuntimeError Traceback (most recent call last)
>RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
>
>ImportError Traceback (most recent call last)
>ImportError: numpy.core.multiarray failed to import
>
>ImportError Traceback (most recent call last)
>ImportError: numpy.core.umath failed to import
>
>ImportError Traceback (most recent call last)
>ImportError: numpy.core.umath failed to import
Run Code Online (Sandbox Code Playgroud)
所以我的猜测是tensorflow是针对不同于我的系统默认版本(1.13.3)的numpy版本构建的。
问题是如何解决?我对这个过程有很多陌生的知识,因此,如果有以下任何建议,我将不胜感激:
任何帮助表示赞赏!
我一直在使用带有 4 个 NVIDIA GPU 的 Keras 框架来训练 NN 模型。(数据行数:~160,000,列数:5)。现在我想通过使用 GridSearchCV 来优化它的参数。
但是,每当我尝试将 n_jobs 更改为 1 以外的其他值时,我都会遇到几个不同的错误。错误,例如
CUDA OUT OF MEMORY
Can not get device properties error code : 3
Run Code Online (Sandbox Code Playgroud)
然后我阅读了这个网页,“#如果你不使用 GPU,你可以将 n_jobs 设置为 1 以外的值” http://queirozf.com/entries/scikit-learn-pipeline-examples
那么在 GridSearchCV 中使用多个 GPU 是不可能的吗?
【环境】Ubuntu 16.04 Python 3.6.0 Keras / Scikit-Learn
谢谢!
我正在尝试使用 Pytorch 实现字符 LSTM。但是我收到了 cudnn_status_bad_params 错误。这是训练循环。我在 line output = model(input_seq) 上遇到错误。
for epoch in tqdm(range(epochs)):
for i in range(len(seq)//batch_size):
sidx = i*batch_size
eidx = sidx + batch_size
x = seq[sidx:eidx]
x = torch.tensor(x).cuda()
input_seq =torch.nn.utils.rnn.pack_padded_sequence(x,seq_lengths,batch_first = True)
y = out_seq[sidx:eidx]
output = model(input_seq)
loss = criterion(output,y)
loss.backward()
optimizer.step()
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
--> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/rnn.py in forward(self, …Run Code Online (Sandbox Code Playgroud) 我在通过 Pytorch 1.9.0+cu102 训练生成网络时遇到以下错误:
RuntimeError: CUDA error: device-side assert triggered
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)
使用 Google Colaboratory GPU 会话时。该段在以下两行之一上触发:
running_loss += loss.item()
Run Code Online (Sandbox Code Playgroud)
或者
target = target.to(device)
Run Code Online (Sandbox Code Playgroud)
当我第一次运行笔记本时,它会在第一行产生错误,而随后每次尝试运行该块时,它都会在第二行产生错误。第一个错误发生在训练 3 个批次后。第二个错误发生在第一批上。我可以确认该设备是 cuda0,该设备可用,并且target是 pytorch 张量。当然,我尝试接受错误的建议并运行:
!CUDA_LAUNCH_BLOCKING=1
Run Code Online (Sandbox Code Playgroud)
和
os.system('CUDA_LAUNCH_BLOCKING=1')
Run Code Online (Sandbox Code Playgroud)
但是,这两行都不会更改错误消息。根据另一篇文章,这是因为 colab 在子 shell 中运行这些行。在CPU上运行时不会出现该错误,并且我无法访问Colab上除GPU之外的GPU设备。虽然这个问题已经以多种不同的形式被问到,但没有答案对我特别有帮助,因为他们要么建议通过上述行,要么是关于与我自己的情况根本不同的情况(例如用不适当数量的类训练分类器),或者推荐一个我已经尝试过的解决方案,例如重置运行时或切换到CPU。
我希望能够深入了解以下问题:
这里是常见的 pytorch 错误,但我在一种独特的情况下看到它:重新加载模型时,CUDA: Out of Memory即使我尚未将模型放置在 GPU 上,我也会收到错误。
model = model.load_state_dict(torch.load(model_file_path))
optimizer = optimizer.load_state_dict(torch.load(optimizer_file_path))
# Error happens here ^, before I send the model to the device.
model = model.to(device_id)
Run Code Online (Sandbox Code Playgroud)