I am trying to use CMake for compiling CUDA based application on Windows (Visual Studio 2005). Here is an example stripped down CMake file:
cmake_minimum_required (VERSION 2.6)
project (HELLO)
#Support for CUDA Integration
FIND_PACKAGE(CUDA)
if(CUDA_FOUND)
SET(CUDA_NVCC_FLAGS "-arch;sm_13")
CUDA_ADD_EXECUTABLE(Hello hello.cu)
else(CUDA_FOUND)
message("CUDA is not installed on this system.")
endif()
There are a few issues I wish to understand with this.
When I open the solution file (Hello.sln), I don't see any custom build rule setup for the project (Right click on Project -> Custom build rules)
I do see a "Hello_generated_hello.cu.obj" added to my project in Visual Studio. What is this file and why is it added to the project?
By default CUDA Runtime API section doesn't come in Project properties.
If I enable an appropriate custom build rule (NvCudaRuntimeApi.rules), I can now see CUDA runtime API section. If I now go to GPU subsection, I see the GPU architecture still set to be sm_10.
Even if I use CUDA_INCLUDE_DIRECTORIES() Macro to add some directories for CUDA compilation, I won't see these settings in Project Properties -> CUDA Runtime API -> General -> Additional Include Directories.
I wish to know if FindCUDA() package is very able to properly configure VS 2005 project for CUDA based compilation. May be I need to specify additional options to properly configure the project. I would certainly wish to know that. I wish to make sure that whatever options I have specified through CMakeLists file, I should be able to review them easily in my generated VS 2005 project.
What is appropriate way to configure this?
CMake does not support custom build rules (like the CUDA runtime API .rules file), and therefore you cannot edit the CUDA property sheets that the .rules files provide if you use CMake to configure your project. However you can set any CUDA settings directly in the CMakeLists.txt that generates the project, and rebuilding your project will detect these changes and regenerate and reload the project files automatically.
The additional benefit of FindCUDA (besides being cross-platform) is proper dependency analysis so that you never end up with stale builds like you normally do when using CUDA .cu files in Visual Studio (with or without .rules files).
You can find an examples of using CMake with CUDA in the CUDPP project in the following files:
Top-level CMakeLists for the whole library and sample apps:
http://code.google.com/p/cudpp/source/browse/trunk/CMakeLists.txt
Project-specific CMakeLists file for a library: http://code.google.com/p/cudpp/source/browse/trunk/src/cudpp/CMakeLists.txt
Project-specific CMakeLists file for an executable: http://code.google.com/p/cudpp/source/browse/trunk/apps/simpleCUDPP/CMakeLists.txt
Hope that helps.
Related
How are you?
I am trying to create a video like this:
https://youtu.be/L0JkjIwz2II
or like this:
https://youtu.be/hPCTwxF0qf4
I am trying to getting this code working:
https://github.com/Tubeliar/HAARCascadeVisualization
I am using Visual Studio 2017 on Windows 10.
I have added correctly the include directory and the library directory.
I created it as a console application.
I added the #include "stdafx.h" at the start of the main file.
This are the errors that Microsoft Visual Studio show to me:
Can you help me solve this?
There is anything that I should know for making this work correctly?
Thank you to everyone,
Andrea
Those errors are as has been noted indeed linker errors. If the compiler does not complain that means you have you include paths set up correctly, so you have won half the battle.
For linker errors you can try these things:
Make sure your *.lib files are built for the same target you're building your own project for.
If you use NuGet then you can look in the /packages folder of your project. Browse down to /packages/[package name]/build/native/lib/[architecture]/. There you will find folders like v120 or v140. For Visual Studio 2017 they need to be v141. If they are missing then you can tell VS to target the older platform (project properties -> general -> platform toolset)
If you've built the libraries yourself then maybe you did that similarly targeting a different platform? Try building the OpenCV library again and make sure the target is set to v141 (or whatever you want to use).
Make sure the linker can find your libraries. If you're using NuGet this step isn't necessary but if you built the library yourself or if you downloaded a prebuilt one then go into project settings and:
Go to VC++ directories -> Library Directories, edit that value and make sure the folder that contains the *.lib files is in there.
Go to Linker -> Input -> Additional Dependencies, edit it and put in all the *.lib files. Just their names, not full paths. In your case you'd just put opencv_world331d.lib there.
Be aware that any of the above settings need to be done for each configuration. Usually there is a x86 and x64 architecture combined with debug or release configuration. If you switch any of these you'd have to check the above steps again. This is a bit of a hassle so you're better off defining a property sheet once which you can then reuse every time you do a OpenCV project. There was a tutorial for this in OpenCV 2.4's documentation, and some people have made premade ones.
I am creating a sample project (a Hello, World!) with libevent.
(Just for note: This question has got nothing to do with libevent but with Visual Studio. :-))
I compiled the library separately outside but under Visual Studio environment.
Wanted to test with a sample code and I started with creating a new project in VS2010.
I selected Visual C++ --> General --> Empty Project.
When I selected the project properties to add the 'additional include directories' I do not find
C/C++ node where it is usually added.
This is how it looks:
However, when I select Visual C++ --> Win32 --> Win32 Console Application I will be able to see the C/C++ node and add the additional include directories.
I read this post and understood I can add the required directories in VC++ Directories --> Include Directories. But yet it's not so very advisable to change the default setting.
Is there any other way I can add additional include directories without selecting the C++ --> Win32 --> Win32 Console Application project? Just want to know.
You need to have at least one .cpp file added to the project to be able to see the C/C++ settings. Otherwise, being an empty project, VS does not know what language you are using
You have to have a C++ project. It doesn't need to be a console application; you could also create a static library (.lib) or dynamic library (.dll).
I am trying to use the gloox library (C++) to create a Windows XMPP application. It seems simple enough, except I don't know how to import gloox into Visual Studio 2010 so I can include it in my application project.
I've looked at the instructions provided in the read-me (shown below), but when I try to compile the library, I get this error:
Cannot open source file: 'src\tlsgnutlsserver.cpp': No such file or directory
Instructions provided in the read-me file:
Building gloox on MSVC++
use the included project file or create your own
adjust include + library paths if necessary
to receive any debug output you should use the LogSink facilities (this is not win32-specific)
build
Does anyone have experience using Gloox with VS10? If yes, can you please help me out? Thanks!
I assume you're using the official 1.0 tarball? I had the same problem (missing source file) and had to acquire the source from SVN instead. I used the 1.0 branch.
I encountered a few other build problems, namely
the release build configuration was set to build an Application (.exe) instead of Dynamic library (.dll) (Project->Properties->General->Configuration Type)
I needed to add DLL_EXPORT to the preprocessor definitions (Project->Properties->Configuration Properties->C/C++ ->Properties->Preprocessor)
src\atomicrefcount.cpp needed to be added to the project's source files. (Project->Add Existing Item)
This worked for me in express editions of both VC++ 2010 and VC++ 2008.
Hopefully it helps you as well.
I want to develop gpu computing algorithms using CUDA. I'm using Visual Studio 2010 Ultimate edition. After I install all the computing tools and SDK with samples, I see under project types "NVIDIA->CUDA->CUDA 4.0 Runtime" choice to start a CUDA project.
The problem is that I can't include source files located at ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/Common/inc to work with samples, use header files under GL directory etc. I'm trying to include them using "Additional Include Directories". I'm adding the full path, but it doesn't work. Visual Studio doesn't see those files.
How can I use these files? What should I type in to get these files?
I compiled cutil project under common directory, it solved some error problems while trying to compile samples but it made no use for the issue I stated above.
These are the steps I took to install CUDA into VS2010.
Create a normal project of your choice. (e.g. win32)
Right click the project and choose Build Customizations. If you have installed the tools and SDK correctly you should see a CUDA 4.0 target. (If your project becomes corrupt you may also have to replace the existing ExtensionSetting import in your .vcxproj file)
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 4.0.props"/>
</ImportGroup>
Your include path should already be setup, if it is not then add $(CUDA_INC_PATH) to your VC++ include directory.
Add cudart.lib to your Linker additional libraries ensuring that $(CudaToolkitLibDir) is added to the paths.
Create a file and give it the .cu file extension. Right click the file, go to properties and select the Item Type as "Cuda C/C++".
Once sthis i complete you should be able to compile Cuda in VS2010. I may have forgetten some steps, you may need to fiddle abit, I will edit this post if I recall tomorrow.
Direct Question: How do I create a simple hello world CUDA project within visual studio 2010?
Background: I've written CUDA kernels. I'm intimately familiar with the .vcproj files from Visual Studio 2005 -- tweaked several by hand. In VS 2005, if I want to build a CUDA kernel, I add a custom build rule and then explicitly define the nvcc call to build the files.
I have migrated to Win 7, and VS 2010 because I really want to try out nSight. I have nSight 1.5 installed. But this is where I'm totally lost. If I proceed as before, nvcc reports that it only supports msvc 8.0 & 9.0. But the website clearly states that it supports VS 2010.
I read somewhere else that I need to have VS 2008 (msvc 9.0) also installed -- my word. Doing so now.
But I'm guessing that at least part of my problems stem from the homegrown custom build tool specifications. Several websites talk about adding a *.rules file to the build, but I've gathered that this is only applicable to VS 2008. Under "Build Customizations" I see CUDA 3.1 and 3.2, but when I add kernels to the project they aren't built. Another website proclaims that the key is three files: Cuda.props Cuda.xml Cuda.targets, but it doesn't say how or where to add these files -- or rather I'll gamble that I just don't understand the notes referenced in the website.
So does anyone know how to create a simple project in VS 2010 which builds a CUDA kernel -- using either the nSight 1.5 setup or the NvCudaRuntimeApi.v3.2.rules file which ships with the CUDA 3.2 RC?
Thanks in advance! I'd offer a bounty, but I only have 65 points total.
CUDA TOOLKIT 4.0 and later
The build customisations file (installed into the Program Files\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations directory) "teaches" Visual Studio how to compile and link any .cu files in your project into your application. If you chose to skip installing the customisations, or if you installed VS2010 after CUDA, you can add them later by following the instructions in Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\extras\visual_studio_integration.
Create a new project using the standard MS wizards (e.g. an empty console project)
Implement your host (serial) code in .c or .cpp files
Add the NVIDIA build customisation (right click on the project, Build customizations, tick the relevant CUDA box)
See note 1 if using CUDA 4.0
Implement your wrappers and kernels in .cu files
If you added .cu files before the build customisations, then you'll need to set the type of the .cu files to CUDA C/C++ (right-click on the file, Properties, set Item Type)
Add the CUDA runtime library (right click on the project and choose Properties, then in Linker -> Input add cudart.lib to the Additional Dependencies)
Then just build your project and the .cu files will be compiled to .obj and added to the link automatically
Incidentally I would advocate avoiding cutil if possible, instead roll your own checking. Cutil is not supported by NVIDIA, it's just used to try to keep the examples in the SDK focussed on the actual program and algorithm design and avoid repeating the same things in every example (e.g. command line parsing). If you write your own then you will have much better control and will know what is happening. For example, the cutilSafeCall wrapper calls exit() if the function fails - a real application (as opposed to a sample) should probably handle the failure more elegantly!
NOTE
For CUDA 4.0 only you may need to apply this fix to the build customisations. This patch fixes the following message:
The result "" of evaluating the value "$(CudaBuildTasksPath)" of the "AssemblyFile" attribute in the element is not valid
This answer applies to CUDA 3.2, from 4.0 onwards CUDA supports the VC 10 compiler directly, see other answers for more information
You need either VS 2008 or the 6.1 Windows SDK installed. That's because NSight 1.5 RC or the CUDA 3.2 SDK use the VC 9 compiler under the hood. I've got this working successfully with 2008 installed and am told it should work with the SDK but haven't tried.
With NSight 1.5 and/or the CUDA 3.2 SDK you shouldn't need to muck with any custom build rules. I've been there and it's painful. With the latest builds all that goes away:
Create your VC++ project.
Add a .CU file to it.
Select the project file in the Solution Explorer.
Open Project | Build Customizations...
Check the "CUDA 3.2 (.targets,
.props)" customization.
Select a .CU file in your project and hit Alt-Enter to show it's properties.
Make sure it's Item Type is set to "CUDA C/C++"
It should just build. Let me know if this helps and if you run into problems as this is from memory.
The good news it getting CUDA working with VS 2010 just got much easier.
Ade
BTW: I'll update my blog post.
Another Good tutorial here:
http://www.stevenmarkford.com/installing-nvidia-cuda-with-visual-studio-2010/
if you get an error about '<' note this step (from a previous answer):
If you added .cu files before the build customisations, then you'll need to set the type of the .cu files to CUDA C/C++ (right-click on the file, Properties, set Item Type)
But if you follow their steps, it should work!