nvcc 中的--default-stream per-thread 编译选项如何正确添加到vs2010中

free_lock 2015-07-27 09:32:19

我参考http://devblogs.nvidia.com/parallelforall/gpu-pro-tip-cuda-7-streams-simplify-concurrency/
希望用并行stream。
在命令行下通过编译可以从3s降低到1s, 但是我依赖的库比较多,我想知道怎么用vs2010编译。

我想把per-thread的编译选项添加到vs2010中,
已经试过了,直接在Command Line的“其他选项”中添加--default-stream per-thread 是不行的。
得到的stream并不是并行的。


从用户手册来看,我还可以用添加宏的方式:
For code that is compiled using the --default-stream per-thread compilation flag
(or that defines the CUDA_API_PER_THREAD_DEFAULT_STREAM macro before including
CUDA headers (cuda.h and cuda_runtime.h)), the default stream is a regular stream
and each host thread has its own default stream.
For code that is compiled using the --default-stream null compilation flag, the
default stream is a special stream called the NULL stream and each device has a single
NULL stream used for all host threads. The NULL stream is special as it causes implicit
synchronization as described in Implicit Synchronization.

不过我试过了依然没有并行,我也不知道要怎么改进了,求高人指点
...全文
3332 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_18668575 2017-12-18
  • 打赏
  • 举报
回复
你好,请问这个问题后来解决了吗?我现在也是遇到和你一样的问题。
skysbjdy 2016-04-16
  • 打赏
  • 举报
回复
最后找打问题所在呢吗??? 怎么解决的??
熊猫视觉 2015-07-29
  • 打赏
  • 举报
回复
楼主,我最近也在想这个问题,可以一起交流下
free_lock 2015-07-27
  • 打赏
  • 举报
回复
补充一点,上面所说的3s到1s是指没有使用pthread的测试代码,如果使用pthread的这段代码

#include <pthread.h>
#include <stdio.h>

const int N = 1 << 20;

__global__ void kernel(float *x, int n)
{
int tid = threadIdx.x + blockIdx.x * blockDim.x;
for (int i = tid; i < n; i += blockDim.x * gridDim.x) {
x[i] = sqrt(pow(3.14159,i));
}
}

void *launch_kernel(void *dummy)
{
float *data;
cudaMalloc(&data, N * sizeof(float));

kernel<<<1, 64>>>(data, N);

cudaStreamSynchronize(0);

return NULL;
}

int main()
{
const int num_threads = 8;

pthread_t threads[num_threads];

for (int i = 0; i < num_threads; i++) {
if (pthread_create(&threads[i], NULL, launch_kernel, 0)) {
fprintf(stderr, "Error creating threadn");
return 1;
}
}

for (int i = 0; i < num_threads; i++) {
if(pthread_join(threads[i], NULL)) {
fprintf(stderr, "Error joining threadn");
return 2;
}
}

cudaDeviceReset();

return 0;
}

那么得到的就是提问中的图。
我随后改变了一下代码中控制流同步的部分:
cudaStreamSynchronize()
改为:
cudaDeviceSynchronize(),
得到新的图为:

有一部分流是并行了,这到底是什么原因呢?为什么我不能让它们全部并行呢?
by the way, 我想请教下在vs2010 命令行下编译的问题:

nvcc --default-stream per-thread -I /includepath test.cu -l pthread.lib -o test
(第一个为大(i),第二个为小(L))
这样的方式错在哪里,为什么与pthread相关的库中的函数无法解析呢?
在工程中通过附加库的形式添加是没有问题的,还望指点迷津。

579

社区成员

发帖
与我相关
我的任务
社区描述
CUDA™是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。 它包含了CUDA指令集架构(ISA)以及GPU内部的并行计算引擎。
社区管理员
  • CUDA编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧