您的位置:首页 > 其它

GPU CUDA常量内存使用

2013-10-21 15:23 260 查看
#include <cuda.h>
#include <stdio.h>
int getMulprocessorCount(){
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop,0);
return prop.multiProcessorCount;
}

__constant__ int a[10]={1,2,3,4,5,6,7,8,9};
__global__  void add(int *c){
c[1]=a[2];
}

int main(){
int *c;
int h_c[10];
int mpc = getMulprocessorCount();
cudaMalloc((void **)&c,10*sizeof(int));
add<<<1,1>>>(c);
cudaMemcpy(h_c,c,sizeof(int)*10,cudaMemcpyDeviceToHost);
printf("num is %d",h_c[1]);
}


  常量内存可以在定义的时候初始化,可以直接在核函数中使用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: