C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cuda-gdb for CUDA C大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

cuda-gdb for CUDA C

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include "book.h"
 4 
 5 __global__ void add(int a,int b,int *c) {
 6   *c = a + b;
 7 }
 8 
 9 __global__ void kernel() {
10   printf("tttt\n");
11 }
12 
13 int main(void) {
14   int c;
15   int *dev_c;
16   HANDLE_ERROR( cudaMalloc((void**)&dev_c,sizeof(int) ) );
17   int count;
18   HANDLE_ERROR( cudaGetDeviceCount(&count) );
19   printf("count: %d\n",count);
20   add<<<1,1>>>(2,7,dev_c);
21   HANDLE_ERROR( cudaMemcpy( &c,dev_c,sizeof(int),22                             cudaMemcpyDeviceToHost ) );
23   printf("2 + 7 = %d\n",c);
24   cudaFree(dev_c);
25   return 0;
26 }
fircuda.cu  nvcc -g -G fircuda.cu

-g 表示将cpu代码(host)编译成可调式版本,-G表示将GPU代码(kernel)编译成可调式版本。

Breakpoint 2,add<<<(1,1,1),(1,1)>>> (a=2,b=7,c=0x7fffc7800000)
    at fircuda.cu:6
6      *c = a + b;

(cuda-gdb) p a
Python Exception <type ‘exceptions.AttributeError‘> ‘gdb.Type‘ object has no attribute ‘name‘:
Python Exception <type ‘exceptions.AttributeError‘> ‘gdb.Type‘ object has no attribute ‘name‘:
$1 = 2

...

(cuda-gdb) p *c

Python Exception <type ‘exceptions.AttributeError‘> ‘gdb.Type‘ object has no attribute ‘name‘: Python Exception <type ‘exceptions.AttributeError‘> ‘gdb.Type‘ object has no attribute ‘name‘: $6 = 9

大佬总结

以上是大佬教程为你收集整理的cuda-gdb for CUDA C全部内容,希望文章能够帮你解决cuda-gdb for CUDA C所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: