小编Ton*_*ony的帖子

在我的机器上操作大型矢量时,CUDA推力变慢

我是一名CUDA初学者并正在阅读一些推力教程.我写了一个简单但非常有组织的代码并试图找出推力的加速度.(这个想法是否正确?).我尝试通过在cpu上添加数组并在gpu上添加device_vector,将两个向量(10000000 int)添加到另一个向量.

这是事情:

#include <iostream>
#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>

#define N 10000000
int main(void)
{
    float time_cpu;
    float time_gpu;
    int *a = new int[N];
    int *b = new int[N];
    int *c = new int[N];
    for(int i=0;i<N;i++)
    {
        a[i]=i;
        b[i]=i*i;
    }
    clock_t start_cpu,stop_cpu;
    start_cpu=clock();
    for(int i=0;i<N;i++)
    {
        c[i]=a[i]+b[i];
    }
    stop_cpu=clock();   
    time_cpu=(double)(stop_cpu-start_cpu)/CLOCKS_PER_SEC*1000;
    std::cout<<"Time to generate (CPU):"<<time_cpu<<std::endl;
    thrust::device_vector<int> X(N);
    thrust::device_vector<int> Y(N);
    thrust::device_vector<int> Z(N);
    for(int i=0;i<N;i++)
    {
        X[i]=i;
        Y[i]=i*i;
    }
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    cudaEventRecord(start,0);       
    thrust::transform(X.begin(), X.end(), …
Run Code Online (Sandbox Code Playgroud)

c c++ cuda thrust

6
推荐指数
1
解决办法
4548
查看次数

如何将 GPU 全局内存中的像素阵列直接显示到屏幕上?

我在 GPU 上做一个路径跟踪器,我在 GPU 全局内存上得到了一些像素数据(这是一个 float3 数组)的跟踪结果,我在屏幕上显示数组的方法是将数组复制到 CPU 内存和调用OpenGL glTexImage2D

glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixelArray);
Run Code Online (Sandbox Code Playgroud)

然后显示纹理。pixelArray是要显示的像素数据数组。由于 GPU 是管理整个渲染过程的设备,有没有一种方法可以pixelArray在不将数据从 GPU 复制到 CPU 的情况下在屏幕上显示?

opengl cuda gpu

5
推荐指数
1
解决办法
1719
查看次数

标签 统计

cuda ×2

c ×1

c++ ×1

gpu ×1

opengl ×1

thrust ×1