his section contains step by step
instruction for creating simplest C++ extension for Python containing a call
into Cuda runtime. It is assumed that MS Visual Studio 2008 Professional
Edition is installed and Cuda development environment is setup as described in
the previous section.
The resulting Visual Studio project is saved in OTSProjects/Cuda/Test1. Follow
the Downloads link. The same procedure is reimplemented in the make file
placed in the directory OTSProjects/Cuda/Test1/Make.
Start Visual Studio, go to New/Project/Nvidia/Cuda, select the latest runtime
and finish the vizard. Build the project, run it, make sure it works.
Go to project properties, change "Configuration
properties"/General/"Configuration type" to "Dynamic Library (.dll)".
Change output file name. Go to project properties, change "Configuration
properties"/Linker/General/Output File. Change the extension from .dll to .pyd
Add include directories. Go to Tools/Options/Projects and Solutions/VC++
Directories/"Include files". Include boost root directory, for example,
c:\boost_1_50_0. Include python include directory, for example,
c:\Python26\include. Change "Include files" to "Library files" and include the
python lib directory, for example, c:\Python26\libs.
Add a cpp file. No C++ options will be accessible until you do. Example code
may be found in the project OTSProjects/Cuda/Test1. Rename main() function to
test1() function and export test1 to python using boost::python protocol. This
is done in the example project.
Make sure that c++/Code generation/Runtime library is "Multi-threaded Debug
DLL (/MDd)" or "Multi-threaded DLL (/MDd)" depending on the debugging setting.
If you want to control how boost::python dll is loaded then go to C/C++/
Preprocessor/"Preprocessor Definitions" and include BOOST_ALL_NO_LIB=1. Make
sure that the particular boost::python library is loaded by adding a directory
to Tools/Options/Projects and Solutions/VC++ Directories/"Library files" and
supplying the name of the library into Project
Properties/Linker/Input/"Additional dependencies".
If you get the LNK2005 error then add the offending library to Project
Properties/Configuration properties/Linker/Input/Ignore Library. In this case,
add "LIBCMT.lib". Alternatively, (as a last resort) use /FORCE:MULTIPLE in
linker command line options.
Build, start "Command Prompt", navigate to the Debug directory of the project
and start python. The rest may be seen on the picture.
The
question of debugging is covered in the next two sections.
|