【问题标题】:How to use CUDA with C to speed up a piece of C code?如何使用 CUDA 和 C 来加速一段 C 代码?
【发布时间】:2019-07-11 21:08:35
【问题描述】:

这是我目前写的设备代码。

__global__ void syndrom(int *d_s, int *d_cx) {
int tid = threadIdx.x + blockDim.x * blockIdx.x + 1;
int t2 = 5460;
int N_BCH = 16383;
if (tid <= t2) {
    d_s[Usetid] = 0;
    for (int j = 0; j < N_BCH; j ++) {
        if (d_cx[j] != 0) {
            d_s[tid] ^= d_alpha_to[(tid * j) % N_BCH];
        }
    }
    d_s[tid] = d_index_of[d_s[tid]];
}

}

我在宿主中调用它

dim3 grid(96);
dim3 block(256);

但是速度不是很好,我想得到帮助。谢谢。

【问题讨论】:

  • 该代码甚至无法编译。 Usetid 是什么?

标签: performance optimization cuda


【解决方案1】:

这不是 Complete and Verifiable Example,您应该在 StackOverflow 上提供它(例如 - 什么 is d_alpha_to?),但我仍然可以提出一些建议:

  1. 使用更多线程,而不是让每个线程进行大量迭代。 GPU 工作并行化的方式使处理器充满了准备好执行更多计算的线程。
  2. 不要重复操作全局内存(同一个地方)。将d_s[tid] 放入一个局部变量(将放置在一个寄存器中),在那里处理它,完成后将其写回。访问全局内存显然比访问寄存器慢得多。
  3. __restrict__ 装饰你的指针(并使d_cx 成为const 指针)。阅读更多关于__restrict__here的信息。

【讨论】:

  • d_alpha_to 和 d_index_of 是一个数组,长度为 16383。
  • @worldhello:给你。
猜你喜欢
  • 2017-07-28
  • 1970-01-01
  • 2020-05-21
  • 1970-01-01
  • 2020-04-24
  • 2012-06-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-28
相关资源
最近更新 更多