I have been working with CUDA 4.2 for a week now and I have a little problem.
When I write the __syncthreads() function it becomes underlined and looks like it is wrong...
Then if I put the mouse on the function it appears a message writing:
identifier __syncthreads(); is undefined.
but when i compile my project the output form build says:
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
So I am guessing that everything works fine but the fact that Visual Studio underlines the function is confusing me...How can I make Visual studio to know that this function is defined before the compiling process?
NOTE:The same thing happens with the kernel call: kernel<<<...,...>>> where the third "<" is underlined red too...
I know that this probably is a minor problem but i want to solve it...Thanks a lot!
I am using Visual Studio 2010 on win7 with Cuda 4.2 and Nsight 2.2
I added the following few lines to the top of the cu file and it began to recognize these functions. For some reason, Intellisense did not pick up this #define:
#ifndef __CUDACC__
#define __CUDACC__
#endif
I lost some color-coding in the code, but I no longer get strange false positive errors.
I am using CUDA 9.1 and Visual Studio 2017 15.6.4. The following code helps me eliminate the "__syncthreads() is undefined" error.
//for __syncthreads()
#ifndef __CUDACC__
#define __CUDACC__
#endif
#include <device_functions.h>
However, this method is not recommended because it may bring unpredictable side effects. Another method to solve this intellisense warning is:
#ifdef __INTELLISENSE___
// in here put whatever is your favorite flavor of intellisense workarounds
#endif
Reference:
__syncthreads(); is undefined need a help
I have CUDA 8.0 and Visual Studio 2015 and I had the same issue.
The below lines helped me:
After these lines: (already in code)
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
I added these lines:
//for __syncthreads()
#ifndef __CUDACC_RTC__
#define __CUDACC_RTC__
#endif // !(__CUDACC_RTC__)
#include <device_functions.h>
It's based on this link: https://devtalk.nvidia.com/default/topic/1009723/__syncthreads-and-atomicadd-are-undefined-in-visual-studio-2015/
Experienced this when trying to define the body of __global__ functions in .cuh files. Moving the body of the functions into .cu source-file solved it.
However, it means that some of my templated functions can't use essential things like __syncthreads(), because templates might have to be defined in a .cuh header.
So, you might need to abandon function templates and instead stick to several functions, each with a slightly different name.
The other solutions either did not solve the same issue occurring in Eclipse 2021-06 with CMake 3.16.3, or produced the following warning with CUDA Runtime Version = 10.1:
/usr/include/device_functions.h:54:2: warning: #warning "device_functions.h is an internal header file and must not be used directly. This file will be removed in a future CUDA release.
The following gave proper highlighting and code completion in Eclipse, and it didn't produce compile warning:
#ifndef __CUDACC__
#define __CUDACC__
#include <device_functions.h>
#endif
Related
This project is merged from GitHub
this picture can describe the application debug the situation
just like the picture is expressed, program can include some header file,
but there will be a lot of red lines,maybe is not fault,cause I can debug right
can someone explain this situation? any help can be cool
thanks!
The "squiggly lines" are IntelliSense errors, not compilation errors.
The root problem was that the old-school "internal guards" are confusing IntelliSense since this is a header:
#ifndef DRAW_INIT_H
#define DRAW_INIT_H
...
#endif
While Lakos loves, loves, loves these they are a bit of a hack. Basically every modern C++ compiler supports a more efficient solution: #pragma once. Use that instead.
I am using Visual Studio 2013 to write code for AVR. I have been following this tutorial.
Whilst writing the code, I noticed that Visual Studio kept on underlining things like DDRB or PORTB and I keep on getting errors like Error: identifier "PORTB" is undefined, however, the program compiles correctly.
Interestingly enough, upon pressing alt-F12 Visual finds numerous files where they are defined.
Your Makefile runs compiler with an option -mmcu=YOURCHIP. This implicitly defines macro corresponding to your chip. For instance for atmega32u4 the macro is AVR_ATmega32U4. Intellisense is run 'outside' of your compiler so it's not aware of this macro and when parsing standard avr header - like avr/io.hit skips the proper inclusion of header file for your particular MCU. It's something like:
#elif defined (__AVR_ATmega32U4__)
# include <avr/iom32u4.h>
So, if you want to have intellisense support for stuff defined in those headers you might need to define that macro, at the top of your source, like this:
#define __AVR_ATmega32U4__
#include <avr/io.h>
int main() {
char a = PORTB;
}
You may find what macro corresponds to which MCU in the middle of this page
i would suggest to simply use the original IDE as Make-File generator and just call that makefile from the VS2013. This has the overhead for maintaining two different projects (but mostly actions that require changes to makefile are rare) but leaves the comfort of the good VS IDE and leaves you the way back to original IDE for debugging.
you also have to set the include directories in the vs2013 project settings to get the intellisense work.
At the moment CUDA already recognizes a key CUDA C/C++ function such as cudaMalloc, cudaFree, cudaEventCreate, etc.
It also recognizes certain types like dim3 and cudaEvent_t.
However, it doesn't recognize other functions and types such as the texture template, the __syncthreads functions, or the atomicCAS function.
Everything compiles just fine, but I'm tired of seeing red underlinings all over the place and I want to the see the example parameters displayed when you type in any recognizable function.
How do I get VS to catch these functions?
You could create a dummy #include file of the following form:
#pragma once
#ifdef __INTELLISENSE__
void __syncthreads();
...
#endif
This should hide the fake prototypes from the CUDA and Visual C++ compilers, but still make them visible to IntelliSense.
Source for __INTELLISENSE__ macro: http://blogs.msdn.com/b/vcblog/archive/2011/03/29/10146895.aspx
You need to add CUDA-specific keywords like __syncthreads to the usertype.dat file for visual studio. An example usertype.dat file is included with the NVIDIA CUDA SDK. You also need to make sure that visual studio recognizes .cu files as c/c++ files as described in this post:
Note however that where that post uses $(CUDA_INC_PATH), with recent versions of CUDA you should use $(CUDA_PATH)/include.
Also, I would recommend Visual Assist X -- not free, but worth the money -- to improve intellisense. It works well with CUDA if you follow these instructions:
http://www.wholetomato.com/forum/topic.asp?TOPIC_ID=5481
http://forums.nvidia.com/index.php?showtopic=53690
I am writing an application in which I got to lock the computer screen (OS is Windows). My Application is in C++. For this purpose I used the LockWorkStation() API defined on msdn, http://msdn.microsoft.com/en-us/library/aa376875%28VS.85%29.aspx
I have included windows.h as told but still I am getting compilation error:
.\source.cpp(5) : error C3861: 'LockWorkStation': identifier not found
here is a sample code thats giving error.
#include <Windows.h>
int main()
{
LockWorkStation();
return 0;
}
Please tell me what I am missing here :(
I am using MS-Visual studio 2005.
Regards.
That function was not supported until Windows 2000. The header files are versioned to allow you to build for older versions of Windows. You're going to want to tell the compiler which minimum version of Windows you want to support as follows:
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
...
#include <windows.h>
If you open winuser.h, you can see that it is surrounded by #if(_WIN32_WINNT >= 0x0500) ... #endif, meaning that it is not available unless you are targeting Windows 2000 or higher.
See http://msdn.microsoft.com/en-us/library/aa383745(VS.85).aspx for more information on the version macros. There's also the new NTDDI_VERSION define where you can set them all at once.
I usually like to have a lot of warnings enabled when programming. However, some libraries contains code that easily causes warnings (.., python, Qt, ..). When compiling with gcc I can just use -isystem instead of -I to silence that. How can I do the same with the MS compiler? I know of the warning #pragma, but I would like a solution that does not involve compiler specific code all over the place. I also know that I can turn off specific warnings, but that is not what I want either.
BTW: isystem should be a tag of this question, but I was not allowed to do that..
SUMMARY: I want to see all warnings from my code, and no warnings from external code.
As of 2017-08-17 this still seems impossible.
I added a feature request here:
https://developercommunity.visualstudio.com/content/problem/96411/impossible-to-ignore-warnings-from-system-librarie.html
Update 2018:
The issue is now closed as fixed and is available in the standard MS VS installation [source].
A blog post from the MS team goes through the new features [here].
The solution from MS is flexible. You can not only differentiate using paths like you do with --isystem, but for example also by whether you use #include "" or #include <>. The blog post is worth a read to see all the various customization points.
This now exists under /experimental:external /external:I system_include_path /external:W0. See https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/ for many more details.
No clue why MS never picked this up.
We can only try voting on https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/14717934-add-a-cl-exe-option-for-system-headers-like-gcc-s
No, MSVC doesn't have an -isystem equivalent.
look at the output output from cl /? :
/wd disable warning n
/we treat warning n as an error
/wo issue warning n once
/w set warning level 1-4 for n
Note that this disables the warnings for your entire project; I remember when using Qt I'd rather change it's main header with the #pragma warning disable and enable at the end again so I could still see all warnings for my own source.
Edit the author edited his question, updated answer: there is no way to get your code with warnings and Qt code without warnings using compiler flags: how are you going to tell the compiler what is 'your' code?
Note that the above flags can be applied at file level as well, so this would allow you to disable the warnings for only those files in which you include Qt headers, but that still means you cannot see them for your own code in that files.
So I stay with the answer above; it is not quite pretty, but I'm pretty sure it's the only way: use #pragma at the beginning and the end of the Qt header(s). Either change the Qt headers (even more ugly), or choose a less invasive way like this:
//your source/header file
#include "shutuppqt.h"
#include <QString>
#include "enableallwarnings.h"
example "shutuppqt.h"
#ifdef MSVC
#pragma warning ( disable : 4222 ) //or whatever warning Qt emits
#else
//....
#endif
example "enableallwarnings.h"
#ifdef MSVC
#pragma warning ( enable : 4222 ) //or default instead of enable
#else
//....
#endif