标签: gpu

CUDA 合并内存访问速度取决于字长

我有一个 CUDA 程序,其中一个经线需要访问(例如)96 字节的全局内存。

它正确对齐内存位置和通道索引,以便在单个事务中合并并完成访问。

该程序可以使用 12 个通道进行访问,每个通道访问一个 uint8_t。或者,它将使用 6 个通道访问 uint16_t,或使用 3 个通道访问 uint32_t。

这些替代方案之间是否存在性能差异,如果每个线程访问较少量的内存,访问速度是否更快?

当每个 warp 需要访问的内存量不同时,优化它是否有好处,以便线程在可能的情况下访问更小的单元(16 位或 8 位)?

cuda gpu gpgpu nvidia

2
推荐指数
1
解决办法
258
查看次数

tensorflow:找不到 dnn 实现

我正在尝试使用 gpu 在 tensorflow 上运行我的代码 Keras CuDNNGRU,但即使我已经安装了 CUDA 和 CuDNN,它也总是出现错误“找不到 dnn 实现”。

我已经多次重新安装 CUDA 和 CuDNN,并将 CuDNN 版本从 7.2.1 升级到 7.5.0,但它没有解决任何问题。我还尝试在 Jupyter Notebook 和 python 编译器(在终端上)运行我的代码,并且两个结果是相同的。这是我的硬件和软件的详细信息。

  1. 特斯拉 V100 PCIE 16GB
  2. Ubuntu 18.04
  3. NVIDIA-SMI 384.183
  4. CUDA 9.0
  5. CuDNN 7.5.0
  6. 迷你康达 3
  7. 蟒蛇 3.6
  8. TensorFlow 1.12
  9. 凯拉斯 2.1.6

这是我的代码。

encoder_LSTM = tf.keras.layers.CuDNNGRU(hidden_unit,return_sequences=True,return_state=True)
encoder_LSTM_rev=tf.keras.layers.CuDNNGRU(hidden_unit,return_state=True,return_sequences=True,go_backwards=True)

encoder_outputs, state_h = encoder_LSTM(x)
encoder_outputsR, state_hR = encoder_LSTM_rev(x)
Run Code Online (Sandbox Code Playgroud)

这是错误信息。

2019-05-27 19:08:06.814896: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2019-05-27 19:08:06.814956: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge …
Run Code Online (Sandbox Code Playgroud)

python gpu nvidia tensorflow cudnn

2
推荐指数
1
解决办法
6623
查看次数

如何解决在 Windows 10 上安装 lightgbm gpu 的问题?

我正在尝试在 Windows 10 pro x64 上安装 lightgbm gpu。我的 GPU 是 NVIDIA Geforce GTX 950。

我首先尝试遵循本指南:https : //lightgbm.readthedocs.io/en/latest/GPU-Windows.html,我使用 Mingw 进行编译。结果是我可以在python中成功导入LightGBM,但是当我尝试使用参数device='gpu'拟合模型时出现错误:

LightGBMError: GPU Tree Learner was not enabled in this build.
Please recompile with CMake option -DUSE_GPU=1
Run Code Online (Sandbox Code Playgroud)


然后我遵循了该指南:https : //github.com/Microsoft/LightGBM/blob/master/docs/Installation-Guide.rst#build-gpu-version 并且在使用 Visual Studio 2019 成功编译后我无法安装 gpu 版本lightgbm 的:我总是得到与这里完全相同的错误:https : //github.com/Microsoft/LightGBM/issues/1121

我是否只输入并不重要

pip install lightgbm --install-option=--gpu
Run Code Online (Sandbox Code Playgroud)


或者告诉我的 boost 和 cuda 的路径

pip install lightgbm --install-option=--gpu --install-option="--opencl- 
include-dir=C:/Program Files/NVIDIA GPU Computing 
Toolkit/CUDA/v10.1/include" --install-option="--opencl-library=C:/Program 
Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/lib/x64/OpenCL.lib" -- 
install-option="--boost-librarydir= …
Run Code Online (Sandbox Code Playgroud)

python boost gpu cmake lightgbm

2
推荐指数
1
解决办法
2426
查看次数

如何使用 CUDA 将 std::vector<std::string> 复制到 GPU 设备

我正在从文件中读取行,并希望通过 GPU 对每一行执行一些计算。

我面临的问题是,到目前为止,我曾经复制一个常量大小的 int 数组,现在我有一个字符串向量,每个字符串的大小都不同。我正在使用:

std::vector<std::string> lines;
Run Code Online (Sandbox Code Playgroud)

我使用了常量大小来复制数组。就像是:

err = cudaMemcpy(_devArr, tmp, count * sizeof(unsigned int) * 8, cudaMemcpyHostToDevice);
Run Code Online (Sandbox Code Playgroud)

但我不确定我是否完全了解它如何与向量一起工作。如何寻址和复制字符串向量?我可以以某种方式复制它并仍然像使用线程+块索引的数组一样访问它吗?

*使用最新的CUDA 10.2和CUDA RTX 2060显卡

c++ string cuda gpu stdvector

2
推荐指数
1
解决办法
546
查看次数

我的 GPU 加速 opencv 代码比普通 opencv 慢

我从《Hands-On GPU-Accelerated Computer Vision with OpenCV and CUDA》一书中复制了两个例子来比较 CPU 和 GPU 的性能。

第一个代码:

    cv::Mat src = cv::imread("D:/Pics/Pen.jpg", 0); // Pen.jpg is a 4096 * 4096 GrayScacle picture.
    cv::Mat result_host1, result_host2, result_host3, result_host4, result_host5;

    //Get initial time in miliseconds
    int64 work_begin = getTickCount();
    cv::threshold(src, result_host1, 128.0, 255.0, cv::THRESH_BINARY);
    cv::threshold(src, result_host2, 128.0, 255.0, cv::THRESH_BINARY_INV);
    cv::threshold(src, result_host3, 128.0, 255.0, cv::THRESH_TRUNC);
    cv::threshold(src, result_host4, 128.0, 255.0, cv::THRESH_TOZERO);
    cv::threshold(src, result_host5, 128.0, 255.0, cv::THRESH_TOZERO_INV);

    //Get time after work has finished     
    int64 delta = getTickCount() - work_begin;
    //Frequency …
Run Code Online (Sandbox Code Playgroud)

c++ opencv gpu

2
推荐指数
1
解决办法
585
查看次数

有没有办法将参数传递给 optuna 中的多个作业?

我正在尝试使用 optuna 来搜索超参数空间。

在一个特定场景中,我在具有几个 GPU 的机器上训练模型。模型和批量大小允许我每 1 个 GPU 运行 1 次训练。因此,理想情况下,我希望 optuna 将所有试验分布在可用的 GPU 上,以便在每个 GPU 上始终运行 1 个试验。

在它说的文档中,我应该在一个单独的终端中为每个 GPU 启动一个进程,例如:

CUDA_VISIBLE_DEVICES=0 optuna study optimize foo.py objective --study foo --storage sqlite:///example.db
Run Code Online (Sandbox Code Playgroud)

我想避免这种情况,因为之后整个超参数搜索会在多轮中继续进行。我不想总是为每个 GPU 手动启动一个进程,检查所有进程何时完成,然后开始下一轮。

我看到study.optimizen_jobs争论。乍一看,这似乎是完美的。 例如我可以这样做:

import optuna

def objective(trial):
    # the actual model would be trained here
    # the trainer here would need to know which GPU
    # it should be using
    best_val_loss = trainer(**trial.params)
    return best_val_loss

study = optuna.create_study() …
Run Code Online (Sandbox Code Playgroud)

python multithreading gpu optuna

2
推荐指数
1
解决办法
1302
查看次数

如何将 torch.device('cuda' if torch.cuda.is_available() else 'cpu') 编写为完整的 if else 语句?

我是 Pytorch 的初学者,想将这个语句作为一个整体输入 if else 语句:-

torch.device('cuda' if torch.cuda.is_available() else 'cpu')
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我吗?

python gpu if-statement pytorch

2
推荐指数
1
解决办法
5904
查看次数

如何使用 numba 在 GPU 上推广快速矩阵乘法

最近,我一直在尝试使用 Numba 库在 Python 中进行 GPU 编程。我一直在他们的网站上使用那里的教程阅读它,目前我被困在他们的例子上,可以在这里找到:https : //numba.pydata.org/numba-doc/latest/cuda/examples。 HTML。我试图将快速矩阵乘法的示例概括一下(形式为 A*B=C)。在测试时,我注意到维度不能被每块线程数 (TPB) 完全整除的矩阵不会产生正确的答案。

我从https://numba.pydata.org/numba-doc/latest/cuda/examples.html的示例中复制了以下代码,并创建了一个非常小的测试用例,其中包含 4 x 4 矩阵。如果我选择 TPB=2 一切都很好,但是当我设置 TPB=3 时就出错了。我知道代码超出了矩阵的范围,但我无法防止这种情况发生(我在ty + i * TPBtx + i * TPB上尝试了一些 if 语句,但这些都不起作用。

from numba import cuda, float32
import numpy as np
import math

@cuda.jit
def fast_matmul(A, B, C):
    # Define an array in the shared memory
    # The size and type of the arrays must be known at compile time
    sA = …
Run Code Online (Sandbox Code Playgroud)

python cuda gpu matrix numba

2
推荐指数
1
解决办法
1239
查看次数

为什么 GPU 上的乘法比 CPU 上的慢?

这是我的代码(模拟前馈神经网络):

import torch
import time

print(torch.cuda.is_available())    # True
device = torch.device('cuda:0' )

a = torch.tensor([1,2,3,4,5,6]).float().reshape(-1,1)
w1 = torch.rand(120,6)
w2 = torch.rand(1,120)
b1 = torch.rand(120,1)
b2 = torch.rand(1,1).reshape(1,1)

start = time.time()
for _ in range(100000):
    ans = torch.mm(w2, torch.mm(w1,a)+b1)+b2
end = time.time()
print(end-start)                    # 1.2725720405578613 seconds

a = a.to(device)
w1 = w1.to(device)
w2 = w2.to(device)
b1 = b1.to(device)
b2 = b2.to(device)

start = time.time()
for _ in range(100000):
    ans = torch.mm(w2, torch.mm(w1,a)+b1)+b2
end = time.time()
print(end-start)                    # 5.6569812297821045 seconds
Run Code Online (Sandbox Code Playgroud)

我不知道如果我做了错误的方式还是什么,我怎么可以改变我的代码表明,GPU IS …

python gpu pytorch

2
推荐指数
1
解决办法
418
查看次数

opengl 中的面部剔除是否发生在窗口空间中?

顶点后处理的输出值在窗口空间中,那么我们有图元组装和面部剔除阶段。如果是在窗口空间中进行面部剔除?

opengl graphics gpu opengl-es

2
推荐指数
1
解决办法
61
查看次数