How to set CUDA compiler flags in Visual Studio 2010? - visual-studio-2010

After persistently getting error : identifier "atomicAdd" is undefined, I've found the solution to be to compile with -arch sm_20 flag. But how to pass this compiler flag in VS 2010? I have tried like so under Project > Properties:
But this apparently has had no effect and the error persists - what am I doing wrong?
Many thanks.

You can select the options for the GPU Code Generation in this dialog:
In this case "compute_20" means that i am compiling for the virtual compute architecture 2.0 - virtual architecture influences the PTX generation stage.
The second part that comes after the coma is "sm_21".This influences the CUBIN generation stage. It defines the real GPU architecture i want to compile the PTX to.
You can find detailed description of the nvcc command line parameters that control the code generation here.

Go to the "Device" section under "CUDA C/C++". There, within "Code Generation" you can specify your sm_20. No need for the -arch.

Be aware that there's separate properties for both the project and .cu files. Apparently they get merged before compilation.
I'd gotten caught by this trying to specify GPUs for compute 3.0 & greater, but .cu properties had some leftover specifications for 1.0 & 2.0

Related

Visual 2013 / CUDA: C2061 syntax error Identifier texture, surface

I am trying to test some code that has recently passed into my responsibilities. While the CUDA projects passed onto me work, I can't seem to get a [new Project] inside the VS13 [Solution] to work.
I've created a CUDA 6.5 runtime project. I've also added the dependencies needed for my own code.
Upon compiling, I receive several [error C2061: Syntax error : Identifier 'surface'] or 'texture'.
I'm currently at a loss as to what I am missing. I would guess there is some dependency I need to add to the project, but it is hard to find any relevant resources online when looking for this error message. I've already added "compute_30,sm_30" in the correct place (i.e. the same place as in the projects that compile).
EDIT: Relevant is that the file throwing errors is #included in someClass.h which is included in the main function.
As is pointed out below, the problem is that CUDA-specific files are included in the visual compiler.
As discussed in the cross-posting here, the root cause of this problem is that the code that involves surface and texture keywords is in a .h file that is ultimately being included in a .cpp file
In a VS CUDA project, by default, .cpp files get compiled by cl.exe, the windows host code compiler. .cu files get compiled by nvcc, the NVIDIA GPU compiler/driver.
cl.exe does not understand the surface or texture keywords, and so throws the mentioned syntax errors.
The only solution is to arrange your project such that those constructs only appear in, or get included in, files that will be process by nvcc, which is the compiler that understands surface and texture (and other CUDA) keywords.
For reference, there are various CUDA sample codes (such as this one) that use surface and texture constructs, and also have project code partitioned between .cpp and .cu files. You can study these if you wish for examples of how such projects might be organized.

What causes linker warning "MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG"?

Some projects in my solution produce this linker warning:
MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
I'm using Visual Studio 2013 Update 3. I haven't yet been able to identify anything particular to those projects that could cause this.
What is it about those projects that produces this?
I've looked at this: http://msdn.microsoft.com/en-us/library/k669k83h.aspx
but I'm not aware we are using any CLR, managed code, /LN or /NOASSEMBLY.
I had the same problem, so I did some research.
According to https://msdn.microsoft.com/en-us/library/0zza0de8.aspx :
If you compile your program with /GL and /c, you should use the /LTCG
linker option to create the output file.
So the message can be a bit misleading - the problem is not the MSIL .netmodule, but modules compiled with /GL
When using /GL, you tell the compiler to delay the generation of some code namely around function bounderies, in order to optimise them. LTCG instruct the linker to generate (and optimise) the missing code. Otherwise, the program will not run as expected.
Basically, the two switches should be used together (when used). They apply to different parts of the build: one for compilation and the other one for link.
For completeness:
/GLis controlled from Configuration Properties > C/C++ > Optimization > Whole Program Optimization
/LTCG is controlled from Configuration Properties > Linker > Optimization > Whole Program Optimization
On later versions,
/LTCG is controlled from Configuration Properties > Linker > Optimization > Link Time Code Generation / Use Link Time Code Generation (/LTCG)
I have encountered the same error and spent quite a lot of time trying to fix it. Finally, I figured out that it appeared due to the use of "Whole Program Optimization" option in one of my dependency libraries.
By default, this option is set to "Yes" in newly created projects. When I changed it to "No" and recompiled all dependencies, the warning disappeared. I have purely native C++ solution without any managed code.
To fix, open project settings of all dependency projects and check setting:
Configuration Properties > C/C++ > Optimization > Whole Program Optimization
Make sure it is set to "No" everywhere.
I find the same error goes away by telling the linker about /GL setting you have used:
Set ...
Configuration Properties/Linker/Optimization/Link Time Code Generation
To ...
One of the non-Default settings
Maybe https://msdn.microsoft.com/en-us/library/xbf3tbeh.aspx is of some use?
Neil
This message shows a lot, which is really raising suspicion. I use a property sheet which tells both /GL and /LTCG. The project isn't using any external libraries. And I get this message, which doesn't make any sense. It disappears, if I go to the project properties and specify "Use Link Time Code Generation" again from there. It doesn't change the command line or anything, but just makes VC happy...

NVIDIA Visual Profiler, Debug and Release modes in Visual Studio 2010

I'm new to Visual Studio 2010, as I was used to compile my CUDA codes with nvcc using Linux as operating system. Incidentally in some posts of this and the NVIDIA Developer Zone forums, I have read warnings on proper compilation in Visual Studio (Debug/Release modes, see link for the difference between the two) to correctly use of the NVIDIA Visual Profiler. In my (poor) understanding, Visual Studio automatically compiles under a "Debug" mode, but for a successful profile the "Release" mode is necessary.
My (simple) questions are:
1) How do I switch from the "Debug" mode to the "Release" mode? Is it enough to use Properties -> Configuration Properties and select "Release" instead of "Active(Debug)"? Also, I noticed that I have to repeat the selection each time I want to Rebuild the project.
2) Is this enough for a correct usage of the Visual Profiler?
Thank you very much in advance.
1) You're switching from Debug to Release in the wrong place. The setting you're using is just for selecting which build settings to view or edit. You should use Build | Configuration Manager or (easier) the Solution Configurations dropdown box in the Standard toolbar. If you don't see the Standard toolbar, right click in the toolbar area by the menu, and select it there. You will find that you don't have to reselect the setting for each build now.
2) The CUDA compiler optimizes aggressively even in Debug mode. I don't know if it matters which configuration you use. Both should work. You can try and see if you get any different results.
See Roger Dahl's answer for how to set the configuration.
There are several forms of profiling.
Performance Profiling
This should definitely be done with optimizations enabled on the CUDA kernel. Disabling optimization and specifying debug information performs more operations than a CPU but it does do other modifications to the code (stack overflow checks) that will impact counters.
Source Level Profiling
This can be done on Debug or Release builds. Nsight 3.0 CUDA Profiler has source level experiments that will show statistics per C source, PTX, or SASS line. The CUDA 5.0 Visual Profiler supports code correlated experiments but will not show the results for every line (only problematic lines). Disabling optimizations will result in significantly more accurate line information for the SASS to PTX to C code mapping. For many analysis cases this is fine. However, if you want to understand the code generation per C line then you should enable full optimizations and heavily look at the SASS code and only use C source and PTX as a guide.
In order to get C source level correlation you need to use the default debug configuration which generates full debug information or use a custom configuration that enable -lineinfo. This option can be enabled using the following steps:
Open Solution Explorer
Right click on your .cu file or project file
Execute the Properties command
In the left pane select the tree node Configuration Properties | CUDA C/C++ | Device
In the right pane change Generate Line Number Information to Yes
In CUDA 5.0 -lineinfo has several small impacts on code generation so it is not advisable to keep this enabled in your Release configuration.

CUDA Texture functions not identified

The CUDA 4.2 SDK example project simpleTexture compiles and runs correctly in vs2008 sp1, but when I attempt to add textures to an ongoing CUDA kernel project, some of the necessary functions to create and use the binding are not recognized:
1>c:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.2/C/src/rohan/Rohan-kernel.cu(67): error: identifier "channelDesc" is undefined
1>c:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.2/C/src/rohan/Rohan-kernel.cu(664): error: identifier "tex2d" is undefined
The texture declaration itself seems okay:
texture<cuDoubleComplex, cudaTextureType2D, cudaReadModeElementType> tex;
I have duplicated all of the #includes from simpleTexture, include paths look the same, and the ongoing project uses the supplied template project/solution files customized as directed.
Everything was working well before adding the texture bits, what gives?
Try to compile with the flag -arch sm_20

PCL Rigid Transformation using IterativeClosestPoint - Error: vector erase iterator outside range

I am currently trying to calculate rigid transformation between two point sets so I tried to use the code given by the tutorial on pointclouds.org:
http://www.pointclouds.org/documentation/tutorials/iterative_closest_point.php#iterative-closest-point
For my case I only changed the part where the data is randomly generated to something that loads the point data I want to analyze. Everything else is exactly like in the tutorial...
(I also tried testing exactly the tutorial code with the random data, in case I had somethign wrong with reading my input data)
Since I work with Qt I integrated the PCL library, Eigen library and FLANN library to my project. It finds all headers and successfully compiles with MSVC 2008...
Unfortunately I always get a runtime error at
icp.setInputTarget(cloud_out);
saying:
Debug Assertion failed! Program:
...MSVC2008_Qt_SDK_Release\release\Project.exe File: c:\Program
Files\Microsoft VIsual Studio 10.0\CV\include\vector Line: 1200
Expression: vector erase iterator outside range
[..] ... check documentation ... [..]
Does anybody know what that means? The input clouds both have the same size and have filled values.
I would be thankful for any help!
UPDATE 1:
The error message shows some file path for MSVC 2010 (10.0) ... So I tried to uninstall Visual Studio 2010 since I don't really need it. But still, if I compile in Debug mode, it shows me an error message, but with Expression: vector iterators incompatible instead... If I now run it in Release mode, it just crashes at runtime (at the same line), but doesn't show that error message.
This seems so be a problem with the library you use. Assuming you have done a clean build, checked your PATH variable and everything and that Visual Studio 2010 is removed, this might be a problem with the library itself. Are you you using the right one?
The current Qt SDK has MSVC2008 in it, so I guess it takes everything from where it needs. But either the compiler in Qt or one of the libraries you use that might want the 2010 version...
Hope it helps!

Resources