我在NVIDIA论坛上发布了这个,我想我会多点帮忙.
我在尝试扩展我的代码以执行多个案例时遇到了麻烦.我一直在开发最常见的案例,现在是测试时间,我需要确保它适用于不同的情况.目前我的内核是在一个循环中执行的(有原因我们没有做一个内核调用来完成整个事情.)来计算矩阵行的值.最常见的情况是512列乘512行.我需要考虑尺寸为512 x 512,1024 x 512,512 x 1024和其他组合的基质,但最大的将是1024 x 1024矩阵.我一直在使用一个相当简单的内核调用:
launchKernel<<<1,512>>>(................)
Run Code Online (Sandbox Code Playgroud)
这个内核适用于常见的512x512和512 x 1024(分别为列,行)情况,但不适用于1024 x 512的情况.这种情况需要1024个线程才能执行.在我天真的时候,我一直在尝试不同版本的简单内核调用来启动1024个线程.
launchKernel<<<2,512>>>(................) // 2 blocks with 512 threads each ???
launchKernel<<<1,1024>>>(................) // 1 block with 1024 threads ???
Run Code Online (Sandbox Code Playgroud)
我相信我的问题与我对线程和块的缺乏理解有关
这是deviceQuery的输出,你可以看到我最多可以有1024个线程
C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.1\C\bin\win64\Release\deviceQuery.exe Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Found 2 CUDA Capable device(s)
Device 0: "Tesla C2050"
CUDA Driver Version / Runtime Version 4.2 / 4.1
CUDA Capability Major/Minor version number: 2.0
Total amount of global memory: …Run Code Online (Sandbox Code Playgroud) 下面的代码片段包含哪个头文件来使用cuda事件mathods来测量时间?
cudaEvent_t start,stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
float Elapsed=0,Cycle;
for (int p=1; p<=MSG_NUM; p++)
{
cudaEventRecord(start,0);
add<<<R, (M+R), (M+R)* sizeof(int)>>>( d_msg, d_checkSumArray );
cudaEventRecord(stop,0);
cudaEventSynchronize(stop);
cudaElapsedTime(&Cycle,start,stop);
Elapsed += Cycle;
}
printf("Time = %f",Elapsed);
Run Code Online (Sandbox Code Playgroud)
我的程序显示以下错误,因为没有包含头文件.
错误:标识符"cudaElapsedTime"未定义
有人可以给出解决方案吗?
我在使用这个GUI时遇到了很多麻烦.我将要一个applet,左边是panel1,右边是panel2.这是我的两个问题:1)JTextArea需要占用applet的整个右侧,但我无法做到这一点.2)每当我使JTextArea更长时,JTextField也会变长,即使它在一个完全不同的面板中.这是怎么回事?小程序和一切都在另一个类中创建 - 它编译并运行良好.我只是不能让这部分工作.
private JButton button1;
private JLabel label1;
private JTextField field1;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private JTextArea area1;
int i = 0;
int j = 0;
private JScrollPane pane;
public Class()
{
this.petList = petList;
this.sPanel = sPanel;
panel1 = new JPanel();
panel1.setLayout(new BorderLayout());
button1 = new JButton("Test");
panel1.add(button1,BorderLayout.SOUTH);
field1 = new JTextField();
panel1.add(field1, BorderLayout.EAST);
label1 = new JLabel("Test");
panel1.add(label1, BorderLayout.WEST);
panel2 = new JPanel();
area1 = new JTextArea(10, 20);
panel2.add(area1);
panel3 = new …Run Code Online (Sandbox Code Playgroud) 几天前,我正在比较我的一些代码的性能,我执行一个非常简单的替换和Thrust实现相同的算法.我发现一个数量级(!)的不匹配有利于Thrust,所以我开始让我的调试器"冲浪"到他们的代码中以发现魔法发生的地方.
令人惊讶的是,我发现我的非常直接的实现实际上非常类似于他们的,一旦我摆脱了所有的functor东西并得到了细节.我看到Thrust有一个聪明的方法来决定块_size和grid_size(顺便说一句:确切地说,它是如何工作的?!),所以我只是采取了他们的设置并再次执行我的代码,因为它们非常相似.我增加了几微秒,但情况几乎相同.然后,最后,我不知道为什么,只是"尝试"我删除了我的内核和BINGO之后的cudaThreadSynchronize()!我将差距归零(并且更好),并获得了整个执行时间的数量级.访问我的数组值我发现它们完全符合我的预期,所以正确执行.
现在的问题是:我什么时候可以摆脱cudaThreadSynchronize(et similia)?为什么会造成如此巨大的开销?我看到Thrust本身在最后没有同步(synchronize_if_enabled(const char*message)是一个NOP,如果没有定义宏__THRUST_SYNCHRONOUS而且它不是).细节和代码如下.
// my replace code
template <typename T>
__global__ void replaceSimple(T* dev, const int n, const T oldval, const T newval)
{
const int gridSize = blockDim.x * gridDim.x;
int index = blockIdx.x * blockDim.x + threadIdx.x;
while(index < n)
{
if(dev[index] == oldval)
dev[index] = newval;
index += gridSize;
}
}
// replace invocation - not in main because of cpp - cu separation
template <typename T>
void callReplaceSimple(T* dev, const int n, const T …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行http://docs.thrust.googlecode.com/hg/group__modifying.html中描述的每个示例,但在编译和运行时遇到错误.
我使用以下文件:fe.cu:
#include <thrust/for_each.h>
#include <thrust/device_vector.h>
#include <stdio.h>
struct printf_functor{
__host__ __device__
void operator()(int x){
printf("%d\n");
}
};
int main(){
thrust::device_vector<int> d_vec(3);
d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2;
thrust::for_each(d_vec.begin(), d_vec.end(), printf_functor());
}
Run Code Online (Sandbox Code Playgroud)
我编译nvcc -arch=sm_20 fe.cu.
当我使用./a.out运行时,我得到以下输出:
terminate called after throwing an instance of 'thrust::system::system_error'
what(): unspecified launch failure
Aborted
Run Code Online (Sandbox Code Playgroud)
以下是用于运行代码的GPU上的一些信息:
--- General Information for device 0 ---
Name: Tesla C2075
Compute capability: 2.0
Clock rate: 1147000
Device copy overlap: Enabled
Kernel execution timeout …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译一个 C 程序来尝试并行编程,当我尝试使用 nvcc 编译器(Nvidia)编译它时,它给了我这些错误:
inicis.cu(3): error: attribute "global" does not apply here
inicis.cu(3): error: incomplete type is not allowed
inicis.cu(3): error: identifier "a" is undefined
inicis.cu(3): error: expected a ")"
inicis.cu(4): error: expected a ";"
/usr/include/_locale.h(68): error: expected a declaration
inicis.cu(20): error: type name is not allowed
inicis.cu(21): error: type name is not allowed
inicis.cu(22): error: type name is not allowed
inicis.cu(41): error: identifier "dev_a" is undefined
inicis.cu(42): error: identifier "dev_b" is undefined
inicis.cu(43): error: identifier "dev_c" is undefined …Run Code Online (Sandbox Code Playgroud) 在cudaMemcpy(),源指针和目标指针都可以为空吗?我是CUDA的初学者.所以,任何帮助将不胜感激.
从GPU编程的新手,我求助于你的建议,请注意我对特定的hw解决方案并不感兴趣,所以NVidia/ATI没问题,尽管OpenCL可能更好.但一切都是洁净的!
所以,我有2个系列的64位整数对,比方说list(<top, bottom>),我需要将列表中的每个元素与其他所有元素进行比较.是的,一个简单的N^2算法.详细地说,我要看看,给出l1并l2从列表中l1.top == l2.bottom.如果是,则存储匹配的元素,否则丢弃它们.
而已.
显然,即使在多线程方法中达到列表中的数百万个元素时,这也不会扩展.
我了解了Cuda,并尝试了很少的程序,但每个程序都修改了一些东西.没有像并发向量或列表这样的例子,我现在用它来存储匹配的对.
你能指出我将这个移植到GPU的正确方向吗?
我在robots.txt文件中使用此代码:
User-agent: *
Disallow:
Run Code Online (Sandbox Code Playgroud)
但是,我的竞争对手正在使用
User-agent: *
Disallow: /
Run Code Online (Sandbox Code Playgroud)
他的网站在谷歌和排名第一的表现都很好.但我的网站没有排名.我检查了我网站上的所有内容,没关系.但是我的竞争对手在Google中表现如何?robots.txt文件无关紧要吗?
我试图理解矩阵转置如何从列与行中更快地读取.(例子来自Professional CUDA C Programming)矩阵按行存储,即(0,1),(0,2),(0,3)......(1,1),(1,2)
__global__ void transposeNaiveCol(float *out, float *in, const int nx, const int ny) {
unsigned int ix = blockDim.x * blockIdx.x + threadIdx.x;
unsigned int iy = blockDim.y * blockIdx.y + threadIdx.y;
if (ix < nx && iy < ny) {
out[iy*nx + ix] = in[ix*ny + iy]; //
// out[ix*ny + iy] = in[iy*nx + ix]; // for by row
}
}
Run Code Online (Sandbox Code Playgroud)
这是我不明白的:transposeNaiveCol()的负载吞吐量是642.33 GB/s,tranposeNaiveRow()的负载吞吐量是129.05 GB/s.作者说:
结果表明,使用缓存的跨步读取可以获得最高的负载吞吐量.在高速缓存读取的情况下,每个内存请求都使用128字节高速缓存行进行服务.按列读取数据会导致warp中的每个内存请求重放32次(因为步幅为2048个数据元素),从而导致从许多正在进行的全局内存读取中隐藏的良好延迟,并且一旦字节预先存在,则具有出色的L1缓存命中率进入L1缓存.
我的问题:我认为对齐/合并读取是理想的,但在这里似乎跨步读取提高了性能.
cuda ×7
thrust ×2
c ×1
c++ ×1
caching ×1
concurrency ×1
gcc ×1
gpgpu ×1
java ×1
nvcc ×1
opencl ×1
robots.txt ×1
swing ×1
visual-c++ ×1