Play with cublas (1) -- Hello cublas

Source: Internet
Author: User
Tags cuda toolkit

/* ===================================================== ======================================

* During a vacation, the other half of the land that should have been quite familiar to Qingdao is wandering around the patients

* So I am in the hotel and don't want to go out, listen to songs, writeArticle.

========================================================== ===================================== */

Cublas is a GPU Blas library of NVIDIA. All provided computing functions are executed on the GPU.

This is the first article about the cublas database. This article describes how to configure the environment for using cublas and write a hello cublasProgram.

1.1 platform Configuration

Hardware requirements: GPU supports cuda, and the higher the computing power, the better. As for how to know the GPU computing power, please move here. Of course, the computing power cannot represent the performance of your video card, note This.

Software requirements: the operating system uses Windows 7, because the configuration on Linux is simpler than that on windows, so I choose to use Windows to write here. Visual Studio is required, preferably a version later than 9.0 (vs2008. I use vs10.0 (vs2010) as an example. Cuda toolkit 5.0.

1.2 configure the cublas Environment

Step 1: Create a blank project for the Win32 console application, as shown in 1. Here I add a new cublas01 project.

Figure 1 create an empty project

Step 2: Add a new source program, as shown in Figure 2. Here, the source file is named "cubals00.c" (I have nothing to say about it. I want to start from 0 and write more C ..)

Figure 2 Add a new file

Step 3: add the directory containing the library, that is, the directory containing the cublas header file, so that vs can find the corresponding header file during compilation, as shown in 3. Here IUse macro variablesThis will increase the portability of the program.

Figure 3. Add the include path

Step 4: add the library directory. The directory added in this step contains the static library of cubals. macro variables are also used, as shown in figure 4. Add the dependencies of cublas. lib to the linker.

Figure 4 Add a lib path

Figure 5 add additional dependencies

Step 5: Write pointCodeTest whether the environment is configured successfully.

Paste the following code to the cubals01.c file.

 

/** Test for cublas */# include <stdio. h> # include <stdlib. h> # include "cublas_v2.h" int main (INT argc, char ** argv) {cublashandle_t cubhandle; int version; cublascreate (& cubhandle); cublasgetversion (cubhandle, & version ); printf ("Hello cublas v % d \ n", version); cublasdestroy (cubhandle); Return 0 ;}

 

Project generation. If the generation fails, please leave a message about your problem.

Run the command in either of the following ways: Method 1: Press F5 directly in vs; Method 2: run the command in cmd. I'm not sure about their difference, but it's just in case.

If a DLL is missing during execution, you have two options. In any case, you must find the DLL in your computer. solution 1, copy the DLL to your executable file directory. solution 2: add the dll Directory to the environment variable path.

Everything is OK.

Step 6: view my execution results.

 

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.