行业知识
CUDA学习笔记04:向量之和
2026-11-15 11:56:31
来源:互联网转载
参考资料
CUDA编程模型系列二(向量操作)_哔哩哔哩_bilibili (非常好的学习资料!)
vs2019
随意新建一个空项目,按照之前的环境配置配好项目依赖:
CUDA学习笔记02:测试程序hello world-CSDN博客
代码结构如下:
代码片段,demo_gpu.cu:
#include #include #include #include __global__ void vecAdd(const double* x, const double* y, double* z, int count){ const int index = blockDim.x * blockIdx.x + threadIdx.x; // t00 t01 t02 t10 t11 t12 t20 t21 t22 if (index (d_x, d_y, d_z, N); cudaMemcpy(h_z, d_z, M, cudaMemcpyDeviceToHost); vecAdd_cpu(h_x, h_y, result_cpu, N); bool error = false; for (int i = 0; i (1.0e-10)) { error = true; } } printf("Result: %s\n", error ? "Errors" : "Pass"); free(h_x); free(h_y); free(h_z); free(result_cpu); cudaFree(d_x); cudaFree(d_y); cudaFree(d_z);} 主函数:
#include void test();int main(){ test(); std::cout
上一篇:公司服务器资料怎么查?