我正在研究如何将每行的可变宽度的2D数组复制到GPU中.
int rows = 1000;
int cols;
int** host_matrix = malloc(sizeof(*int)*rows);
int *d_array;
int *length;
...
Run Code Online (Sandbox Code Playgroud)
每个人host_matrix[i]可能都有不同的长度,我知道length[i],问题就出在那里.我想避免复制虚拟数据.有没有更好的方法呢?
根据这个帖子,这不是一个聪明的方法:
cudaMalloc(d_array, rows*sizeof(int*));
for(int i = 0 ; i < rows ; i++) {
cudaMalloc((void **)&d_array[i], length[i] * sizeof(int));
}
Run Code Online (Sandbox Code Playgroud)
但我想不出任何其他方法.有没有其他更聪明的方法呢?可以使用cudaMallocPitch和cudaMemCpy2D进行改进吗?
我是CUDA的初学者.我这里有一个由2个线程执行的内核.所有线程都应将结果保存到共享变量中.三个完成后,结果sum应该是12但我得到6!
__global__ void kernel (..)
{
int i=blockDim.x*blockIdx.x+threadIdx.x;
__shared__ double sum;
...
if(i==0)
sum=0.0;
__syncthreads();
if(i<=1)
sum+= 2.0*3.0;
__syncthreads();
//sum should be 12 here, but I get 6. Why?
}
Run Code Online (Sandbox Code Playgroud)
叫做
test<<<1,2>>>(..);
Run Code Online (Sandbox Code Playgroud) 我正在研究一些将RGBA图像转换为灰度的cuda 教程.但我无法弄清楚为什么改变它blockSize并gridSize进行X33时间的改进.
__global__
void rgba_to_greyscale(const uchar4* const rgbaImage,
unsigned char* const greyImage,
int numRows, int numCols)
{
int i = blockIdx.x*numCols + threadIdx.x;
float channelSum = .299f * rgbaImage[i].x + .587f * rgbaImage[i].y + .114f * rgbaImage[i].z;
greyImage[i]= channelSum;
}
void your_rgba_to_greyscale(const uchar4 * const h_rgbaImage, uchar4 * const d_rgbaImage,
unsigned char* const d_greyImage, size_t numRows, size_t numCols)
{
const dim3 blockSize(numCols, 1, 1);
const dim3 gridSize(numRows, 1 , 1);
rgba_to_greyscale<<<gridSize, blockSize>>>(d_rgbaImage, d_greyImage, numRows, numCols); …Run Code Online (Sandbox Code Playgroud) 我已经编写了一个OpenCL内核,该内核使用opencl-opengl互操作性来读取顶点和索引,但是这可能甚至不重要,因为我只是在做简单的指针加法操作,以便按索引获取特定的顶点。
uint pos = (index + base)*stride;
Run Code Online (Sandbox Code Playgroud)
在这里,我正在计算绝对位置(以字节为单位),在我的示例中pos是28,643,328,步幅为28,索引= 0,基数= 1,022,976。好吧,这似乎是正确的。
不幸的是,我不能vload3直接使用,因为offset参数不是以字节为单位的绝对地址。所以我只添加pos了指针void* vertices_gl
void* new_addr = vertices_gl+pos;
Run Code Online (Sandbox Code Playgroud)
new_addr 在我的示例中= 0x2f90000,这是奇怪部分开始的地方,
vertices_gl = 0x303f000
结果(new_addr)应为0x4B90000(0x303f000 + 28,643,328)
我不明白为什么地址vertices_gl减少了716,800(0xAF000)
我的目标是GPU:AMD Radeon HD5830
附言:对于那些想知道的人,我正在使用printf来获取这些值:)(无法使CodeXL工作)
我在amd平台的opencl程序中观察到我们需要两次构建程序.一旦使用clBuildProgram ...(); 当我们构建整个代码时.为什么我们这样做两次?
有没有人设法获得一个CUDA计划来处理NVidia盾牌?特别是让精彩的NVidia分析工具运行起来?
我是并行计算和OpenCL的新手.我按照OpenCLProgramming指南.在卷积实现部分.
我的main.cpp:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <OpenCL/OpenCL.h>
using namespace std;
const unsigned int inputSignalWidth = 8;
const unsigned int inputSignalHeight = 8;
cl_uint inputSignal[inputSignalWidth][inputSignalHeight] =
{
{3, 1, 1, 4, 8, 2, 1, 3},
{4, 2, 1, 1, 2, 1, 2, 3},
{4, 4, 4, 4, 3, 2, 2, 2},
{9, 8, 3, 8, 9, 0, 0, 0},
{9, 3, 3, 9, 0, 0, 0, 0},
{0, 9, 0, 8, 0, 0, 0, 0},
{3, …Run Code Online (Sandbox Code Playgroud) 我是TensorFlow的新手,按照TensorFlow网站上的说明安装了CUDA-7.5和cudnn-v4.调整TensorFlow配置文件并尝试从网站运行以下示例:
python -m tensorflow.models.image.mnist.convolutional
Run Code Online (Sandbox Code Playgroud)
我很确定TensorFlow正在使用其中一个GPU而不是另一个,但是,我希望它能使用速度更快的GPU.我想知道这个示例代码是否默认使用它找到的第一个GPU.如果是这样,我如何在python中的TensorFlow代码中选择使用哪个GPU?
运行示例代码时得到的消息是:
ldt-tesla:~$ python -m tensorflow.models.image.mnist.convolutional
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties:
name: Tesla K20c
major: 3 minor: 5 memoryClockRate (GHz) 0.7055
pciBusID 0000:03:00.0
Total memory: 4.63GiB …Run Code Online (Sandbox Code Playgroud) 我正在测试对Colaboratory的GPU支持。GPU的内存有限。
name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456 locality { }
incarnation: 14648174833476954761,
name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 356515840
locality { bus_id: 1 }
incarnation: 11566567776783368174
physical_device_desc: "device: 0,
name: Tesla K80,
pci bus id: 0000:00:04.0,
compute capability: 3.7"]
Run Code Online (Sandbox Code Playgroud)
The size of the GPU memory is 356MB, I'm wondering if there is a way to get a paid version to increase the GPU memory? Perhaps this is already part of a paid google product, does anyone know what the product is?