Practice Cuda Runtime API (1)-devicemanagementrt

Source: Internet
Author: User

Today I write a simple test to call Cuda runtimeapi.

1 devicemanagement RT

 

1.1 cudagetdevicecount

Cudaerror_t cudagetdevicecount (int * count)

Use this function to get the number of devices with compute capability

 

1.2 cudagetdevice

Cudaerror_t cudagetdevicec (int * Dev)

Use this function to get device number which is currently being used

 

1.3 cudagetdeviceproperties

Cudaerror_t cudagetdeviceproperties (struct cudadeviceprop * prop, int Dev)

Use this function to get the detail properties of Dev device, you will know how large the globalmemory it has, how many register per block, etc.

 

1.4 cudachoosedevice

Cudaerror_t cudachoosedevice (int * Dev, const struct cudadeviceprop * prop)

Returns in * Dev the device which properties best match * prop, if you have created devices, you can choose them by setting * prop, then get the device number.

 

1.5 cudasetdevice

Cudaerror_t cudasetdevice (INT Dev)

After you choose the device you want to use, set the device number and call this function, then the specify one will work for you.

 

At last I post the code which can get all the Cuda device prop in you computer

/* <Br/> * copyright (c) 2009, scut chenhu_lab <br/> * All Rights Reserved. <br/> * filename: cudart_device.cu <br/> * content: Test Runtime API of Cuda <br/> * Current version: 1.0 <br/> * auther: Jiangfeng Peng <br/> * Finish Date: 2009-6-4 <br/> * old version: null <br/> * Ori auther: NULL <br/> * Finish DAA: NULL <br/> */</P> <p> # include <stdio. h> <br/> # include <stdlib. h> <br /># Include <cuda_runtime.h> </P> <p> bool initcuda () <br/>{< br/> int count; <br/> int I, J; <br/> cudadeviceprop prop; </P> <p>/* cudaerror_t cudagetdevicecount (int * count) -- returns the number of compute-capable devices */<br/> cudagetdevicecount (& COUNT); </P> <p> If (COUNT = 0) <br/>{< br/> fprintf (stderr, "there is no device. /n "); <br/> return false; <br/>}< br/> else <br/> {<br/> printf ("/ncudagetdevicecou NT: % d/n ", count); <br/>}</P> <p> for (I = 0, j = 0; I <count; I ++) <br/>{< br/>/* cudaerror_t cudagetdeviceproperties (struct cudadeviceprop * prop, int Dev) <br/> -- returns information on the compute-device */<br/> If (cudagetdeviceproperties (& prop, I) = cudasuccess) <br/>{< br/> printf ("Num % d cudadeviceprop:/N", I ); <br/> printf ("name % s/n totalglobalmem % db = % 1.2fmb/n sharedmemperblock % db = % d KB/n regsperblock % d = % Dk/N "<br/>" warpsize % d/n mempitch % db = % dkb/n maxsperthreadblock % d/n maxthreadsdim: X % d y % d z % d/N "<br/>" maxgridsize: X % d y % d z % d/n totalconstmem % db = % dkb/n major % d/n minor % d/n clockrate % dkhz = % 1.2 fghz/N "< br/> "texturealignment % d/n deviceoverlap % d/n multiprocessorcount % d/n ", <br/> prop. name, Prop. totalglobalmem, (double) prop. totalglobalmem/ 1024/1024, Prop. sharedmemperblock, Prop. sharedmemperblock/1024, Prop. regsperblock, <br/> prop. regsperblock/1024, Prop. warpsize, Prop. mempitch, Prop. mempitch/1024, Prop. maxthreadsperblock, Prop. maxthreadsdim [0], Prop. maxthreadsdim [1], <br/> prop. maxthreadsdim [2], Prop. maxgridsize [0], Prop. maxgridsize [1], Prop. maxgridsize [2], Prop. totalconstmem, Prop. totalconstmem/1024, Prop. major, <br/> prop. minor, Pro P. clockrate, (double) prop. clockrate/1024/1024, Prop. texturealignment, Prop. deviceoverlap, Prop. multiprocessorcount); </P> <p> If (prop. major> = 1) <br/> {<br/> j = 1; <br/>}</P> <p> If (j = 0) <br/>{< br/> fprintf (stderr, "there is no device supporting Cuda 1. x. /n "); <br/> return false; <br/>}</P> <p> cudasetdevice (I); </P> <p> return true; <br/>}</P> <p> int main () <br/> {<br/> If (! Initcuda () <br/>{< br/> return 0; <br/>}</P> <p> printf ("Cuda initialized. /n "); </P> <p> return 0; <br/>}< br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.