Ubuntu下的CUDA编程(六)——原子操…

本文档详细记录了在Ubuntu环境下使用CUDA编程遇到的atomicAdd未定义错误及解决过程。从检查设备计算能力、添加头文件到最终发现缺少的"-arch=sm_12"编译参数,通过一步步排查,成功解决问题并明确了CUDA编程中关于原子操作的注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

test03.cu文件中的代码:

1 #include <stdio.h>
  2 //#include <cuda.h>
  3 #include "cutil.h"
  4 //#include "device_functions.h"
  5 #include "sm_12_atomic_functions.h"
  6 #define SIZE 100 * 1024 * 1024
 
  8 void generateRandomCharArray(unsigned char *, int );
  9 __global__ void histo_kernel(unsigned char *, unsigned int *, int);
 10 
 11 int main()
 12 {
 13         unsigned char *buffer = (unsigned char *)malloc(SIZE * sizeof(char));
 14         generateRandomCharArray(buffer, SIZE);
 15         cudaEvent_t start, stop;
 16         CUDA_SAFE_CALL(cudaEventCreate( &start));
 17         CUDA_SAFE_CALL(cudaEventCreate( &stop));
 18         CUDA_SAFE_CALL(cudaEventRecord(start, 0));
 19         unsigned char *dev_buffer;
 20         unsigned int *dev_histo;
 21         CUDA_SAFE_CALL(cudaMalloc((void **)&dev_buffer, SIZE * sizeof(char)));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值