Run the first Cuda program in command line mode (win7 environment)

Source: Internet
Author: User
Tags nvcc

Looking at Cuda information for some time, there are also a lot of information on the Cuda environment configuration online, such: visual Studio 2008 + visual assist X's cuda2.3 compiling environment sets up yongge's Cuda vs2005 wizard and so on, mainly for the configuration of vs integrated development environment, but there are few command line methods. I think many people have tried the same thing as me, but they have encountered great difficulties and have to stop them.

The host I use is an integrated graphics card of other brands and does not support Cuda architecture. At that time, the toolkit and SDK of Cuda version 3.1 were installed, and the driver was not installed semi-installed. I had to simulate the operation. After trying for a long time, I found that version 3.1 or later does not support the simulation. Well, another 2.3 version is supported. In the integrated development environment vs, it is okay to set up a simulation mode for running. I think it is not implicit. Can I use command line batch processing or other compilation methods? It took a lot of time to get something from this idea. Specifically, there are mainly the following obstacles:

 

1. Fatal error c1083: cannot open compiler generated file: 'debug/sample. OBJ ': no such file or directory

 

After the environment variables are set, run the following command:

Nvcc.exe-ccbin "D: /Visual Studio 2005/VC/bin "-deviceemu-C-dwin32-d_debug-d_console-xcompiler"/ESCs/W3/nologo/wp64/OD/Zi/rtc1/MTD "- IC: /Cuda/include-O debug/sample. OBJ sample. cu

 

If the problem occurs in step 1, the file sample cannot be found. OBJ. I searched the internet and found out what bugs were mentioned. It was actually a path problem. I directly wrote the debug/sample. change OBJ to sample. in the current OBJ directory, you cannot find it.

 

2. The program cannot be started because mspdb80.dll is lost in the computer. Try to reinstall the program to solve this problem.

 

The previous sentence is the main one, and the latter is misleading. If you cannot find it, you can find mspdb80.dll In the VS/common7/ide directory and copy it to the VS/VC/bin directory.

 

3. Fatal error c1902: Program database manager mismatch; please check your installation

VS is sometimes very strange. Obviously it runs well, but it has encountered problems in some time, and this problem occurs at that time. No problem during nvcc.exe (because mspdb80.dll exists in the bin directory), but problem 3 occurs during Link (not necessarily ), you cannot delete the mspdb80.dll in the bin directory during the link.

 

Sample. Cu:

/*************************************** * *************************** <Br/> *[! Output project_name]. cu <br/> * This is a example of the Cuda program. <br/> ************************************ ********************************/</P> <p> # include <stdio. h> <br/> # include <stdlib. h> <br/> # include <cuda_runtime.h> <br/> # pragma warning (Disable: 4996) </P> <p> /******************************** **************************************** /<br/>/* init Cuda */<br/> /************************ ******* **************************************** */<Br/> bool initcuda (void) <br/>{< br/> int COUNT = 0; <br/> int I = 0; </P> <p> cudagetdevicecount (& COUNT ); <br/> If (COUNT = 0) {<br/> fprintf (stderr, "there is no device. /n "); <br/> return false; <br/>}</P> <p> for (I = 0; I <count; I ++) {<br/> cudadeviceprop prop; <br/> If (cudagetdeviceproperties (& prop, I) = cudasuccess) {<br/> If (prop. major >=1) {<br/> break; <BR/>}< br/> if (I = count) {<br/> fprintf (stderr, "There is no device supporting Cuda 1. x. /n "); <br/> return false; <br/>}< br/> cudasetdevice (I); <br/> return true; <br/>}</P> <p> /*************************** **************************************** * *****/<br/>/* example */<br/> /******************** **************************************** * ***********/<br/>__ global _ static void hellocud A (char * result, int num, clock_t * Time) <br/> {<br/> int I = 0; <br/> char p_hellocuda [] = "Hello Cuda! "; <Br/> clock_t start = clock (); <br/> for (I = 0; I <num; I ++) {<br/> result [I] = p_hellocuda [I]; <br/>}< br/> * time = clock ()-start; <br/>}</P> <p> int main (INT argc, char ** argv) <br/>{< br/> char * device_result = 0; <br/> clock_t * time = 0; </P> <p> charhost_result [12] = {0}; <br/> clock_ttime_used = 0; </P> <p> If (! Initcuda () {<br/> return 0; <br/>}</P> <p> printf ("Cuda initialized. /n "); </P> <p> cudamalloc (void **) & device_result, sizeof (char) * 11 ); <br/> cudamalloc (void **) & time, sizeof (clock_t); </P> <p> hellocuda <1, 1, 0 >>> (device_result, 11, time); </P> <p> cudamemcpy (& host_result, device_result, sizeof (char) * 11, cudamemcpydevicetohost ); <br/> cudamemcpy (& time_used, time, sizeof (clock_t), cudamemcpydevicetohost); <br/> cudafree (device_result); <br/> cudafree (time ); </P> <p> printf ("% s, % d/N", host_result, time_used); </P> <p> return 0; <br/>}< br/>

The command line batch processing format is as follows (Save As **. BAT ):

@ Echo off <br/> set myfun = sample <br/> set Vs = D:/Visual Studio 2005 <br/> set Cu = C: /Cuda </P> <p> set include = % Cu %/include; % vs %/VC/include; % vs %/VC/platformsdk/include <br/> set Lib = % Cu %/LIB; % vs %/VC/LIB; % vs %/VC/platformsdk/lib <br/> set Path = % Cu %/bin; % vs %/VC/platformsdk/bin; % PATH % </P> <p> echo ------------------ === by goldenspider 2010-7-9 ===------------------ <br/> echo on </P> <p> nvcc.exe-ccbin "% V S %/VC/bin "-deviceemu-C-dwin32-d_debug-d_console-xcompiler"/ESCs/W3/nologo/wp64/OD/Zi/MTD "-I % Cu % /include-o "% myfun %. OBJ "% myfun %. cu </P> <p> @ echo off <br/> copy "% vs %/common7/IDE/mspdb80.dll" "% vs %/VC/bin" </P> <p> echo on <br/> link/out: "mycuda.exe"/libpath: "% Cu %/lib"/subsystem: console/machine: x86 % myfun %. OBJ cudart. lib kernel32.lib user32.lib gdi32.lib winspool. lib comdlg32.lib advap I32.lib shell32.lib ole32.lib oleaut32.lib UUID. lib odbc32.lib odbccp32.lib bufferoverflowu. lib </P> <p> @ echo off <br/> Del vc80.pdb <br/> Del % myfun %. OBJ <br/> Del "% vs %/VC/bin/mspdb80.dll" </P> <p> echo good job, compiler success !! Run EXE (y /?) <Br/> pause </P> <p> mycuda.exe </P> <p> pause

The running status is as follows:

 

 

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.