cuda初始化代码.doc

上传人:工**** 文档编号:558647716 上传时间:2023-12-17 格式:DOC 页数:7 大小:40KB
返回 下载 相关 举报
cuda初始化代码.doc_第1页
第1页 / 共7页
cuda初始化代码.doc_第2页
第2页 / 共7页
cuda初始化代码.doc_第3页
第3页 / 共7页
cuda初始化代码.doc_第4页
第4页 / 共7页
cuda初始化代码.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《cuda初始化代码.doc》由会员分享,可在线阅读,更多相关《cuda初始化代码.doc(7页珍藏版)》请在金锄头文库上搜索。

1、#include #include bool CUDA_initial(void) int i; int device_count; if( cudaGetDeviceCount(&device_count) ) printf( There is zero device beyond 1.0n); return false; else printf(There is %d device beyond 1.0n,device_count); for(i=0;idevice_count;i+) struct cudaDeviceProp device_prop; if(cudaGetDeviceP

2、roperties(&device_prop,i)=cudaSuccess) printf(device properties is :n t device name is %sn t totalGlobalMem is %dn t sharedMemPerBlock is %dn t regsPerBlock is %dn t warpSize is %dn t memPitch is %dn t maxThreadsPerBlock is %dn t maxThreadsDim 3 is %d X %d X %dn t maxGridSize 3 is %d X %d X %dn t to

3、talConstMem is %dn t device version is major %d ,minor %dn t clockRate is %dn t textureAlignment is %dn t deviceOverlap is %dn t multiProcessorCount is %dn, device_prop.name, device_prop.totalGlobalMem, device_prop.sharedMemPerBlock, device_prop.regsPerBlock, device_prop.warpSize, device_prop.memPit

4、ch, device_prop.maxThreadsPerBlock, device_prop.maxThreadsDim0,device_prop.maxThreadsDim1,device_prop.maxThreadsDim2, device_prop.maxGridSize0,device_prop.maxGridSize1,device_prop.maxGridSize2, device_prop.totalConstMem, device_prop.major,device_prop.minor, device_prop.clockRate, device_prop.texture

5、Alignment, device_prop.deviceOverlap, device_prop.multiProcessorCount); break; if(i=device_count) printf(Get the propertites of device occurred errorn); return false; if(cudaSetDevice(i)=cudaErrorInvalidDevice) printf(Set Device occurred errorn); return false; return true;int main() if(CUDA_initial(

6、)=true) printf(CUDA initial successed!n); return 0;其中遇到的一些函数解释:1.1.1 cudaGetDeviceCount名称cudaGetDeviceCount 返回具有计算能力的设备的数量概要cudaError_t cudaGetDeviceCount( int* count )说明以*count形式返回可用于执行的计算能力大于等于1.0的设备数量。如果不存在此类设备,cudaGetDeviceCount ()将返回1,且设备0仅支持设备模拟模式。由于此设备能够模拟所有硬件特性,因此该设备将报告9999种主要和次要计算能力。返回值相关返回

7、值:cudaSuccess注意,如果之前是异步启动,该函数可能返回错误码。1.1.2 cudaSetDevice名称cudaSetDevice 设置设备以供GPU执行使用 概要cudaError_t cudaSetDevice(int dev) 说明将dev记录为活动主线程将执行设备码的设备。 返回值相关返回值:cudaSuccesscudaErrorInvalidDevice注意,如果之前是异步启动,该函数可能返回错误码。1.1.3 cudaGetDevice名称cudaGetDevice 返回当前使用的设备 概要cudaError_t cudaGetDevice(int *dev) 说明以

8、*dev形式返回活动主线程执行设备码的设备。 返回值相关返回值cudaSuccess注意,如果之前是异步启动,该函数可能返回错误码。1.1.4 cudaGetDeviceProperties名称cudaGetDeviceProperties 返回关于计算设备的信息概要cudaError_t cudaGetDeviceProperties( struct cudaDeviceProp* prop,int dev )说明以*prop形式返回设备dev的属性。cudaDeviceProp结构定义如下:struct cudaDeviceProp char name 256;size_t totalGl

9、obalMem; size_t sharedMemPerBlock; int regsPerBlock;int warpSize;size_t memPitch;int maxThreadsPerBlock; int maxThreadsDim 3; int maxGridSize 3; size_t totalConstMem; int major;int minor;int clockRate;size_t textureAlignment; int deviceOverlap; int multiProcessorCount;其中:name用于标识设备的ASCII字符串;totalGlo

10、balMem设备上可用的全局存储器的总量,以字节为单位;sharedMemPerBlock线程块可以使用的共享存储器的最大值,以字节为单位;多处理器上的所有线程块可以同时共享这些存储器;regsPerBlock线程块可以使用的32位寄存器的最大值;多处理器上的所有线程块可以同时共享这些寄存器;warpSize按线程计算的warp块大小;memPitch允许通过cudaMallocPitch()为包含存储器区域的存储器复制函数分配的最大间距(pitch),以字节为单位;maxThreadsPerBlock每个块中的最大线程数:maxThreadsDim3块各个维度的最大值:maxGridSize

11、3网格各个维度的最大值;totalConstMem设备上可用的不变存储器总量,以字节为单位; major,minor定义设备计算能力的主要修订号和次要修订号;clockRate以千赫为单位的时钟频率;textureAlignment对齐要求;与textureAlignment字节对齐的纹理基址无需对纹理取样应用偏移;deviceOverlap如果设备可在主机和设备之间并发复制存储器,同时又能执行内核,则此值为 1;否则此值为 0;multiProcessorCount设备上多处理器的数量。返回值相关返回值:cudaSuccesscudaErrorInvalidDevice注意,如果之前是异步启动,该函数可能返回错误码。本文来自CSDN博客,转载请标明出处:http:/

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号