Visual Studio 2012 with CUDA 5.5 - CUDA syntax & definitions not recognized - c

for a lab we're suppose to work on I need to set up Cuda with Visual Studio 2012 and run some tests. What I've done:
Install Cuda 5.5 + Edit build configurations.
Visual Studio 2012 is installed.
In the project, right click -> Build Configurations and choose Cuda 5.5
Project -> Properties -> VC++ directories: Set include/lib directories from Cuda directory.
Now, I was under the impression that after doing all this I should have no need to put "#include cudafiles" in my classes, they should be automatically imported, no?
I'm not getting the following as undefined:
cudaFree
cudaError
HANDLE_NULL
The following as 'device is not a type name'
__device__
And __global__ has no storage class or identifier.
I've spent hours and hours and hours trying to get this to work, following tutorials online, but I just can't get it to run properly. The code I'm using can be found here:
https://bitbucket.org/mrfright/cuda_by_example/src/bd759a6527ffa1b88420fc09acbc52f88c0587d2/appendix_a/?at=default
You can see in those files only 'lock.h' and 'book.h' are being included. I am including both of those.
Also, I am very new to C and VS so I may be leaving out a lot of important info.. please advice me to anything you may need to help assess this!! Thanks!

a few key points extracted from the discussion in the comments:
when installing CUDA on windows, make sure VS is installed first. The CUDA toolkit install modifies VS to make compiling CUDA code easier. If VS is not installed or you install/reinstall later, you won't get these modifications.
follow the instructions in the getting started guide including the running of sample projects followed by the building of sample projects. The first point at which you have trouble will be instructive as to what the actual problem is. If you just jump to the end (i.e. trying to create/build/run your own project), it won't be clear where the problem is.
You can build your own CUDA project either by opening an existing project and modifying it, or else creating a new project using the wizard. When just starting out, it may be easier for new users to try modifying an existing project first.
Be aware that various CUDA programs may require a specific compute capability. This means both that your device must support that compute capability, and that you are compiling correctly for that compute capability. You can determine the compute capability of your device by running the deviceQuery sample. You can change the compute capability that you are compiling for in the VS project CUDA settings.
when writing your own CUDA code, and definitely if you are having trouble, you should always do proper cuda error checking
Also be aware that asking questions about how to get drivers loaded, etc. and sorting out machine configuration issues, will very often be considered off-topic for stack overflow. Many questions like this get close votes for this reason.

Related

LNK2005 and LNK1169 when trying to compile program in Visual Studio 2019

I have no experience with C/C++. I do not know how to even open files. I am working with SLN files in Visual Studio 2019 trying to compile a program I took off of GitHub (https://github.com/Marlowe97/Expected-Force).
I get these two errors (LNK2005, 'main already defined in TestExpectedForce.obj, and LNK1169 'one or more multiply defined symbols found') when trying to compile the Expected Force solution. The only changes I've made from the downloaded files are the ones directly stated in the instructions on the GitHub page of the program.
Is there someone who can tell me what to look for in as plain of a way as possible? I know basic Python and R so I understand some terms, but I know nothing about C so no other posted solutions to these errors make any sense to me. I'm already pretty concerned that I'm getting errors after following the step by step instructions from GitHub on what seemed to be a pretty basic task.
It's a strange package...
The functionality is provided as a library, to be compiled into your own project.
There are TWO test source files: TestExpectedForce.cpp and TestExpectedForce.cpp, each of them contains main().
They should be in their own projects (possibly, under the same solution).
To quickly move forward, just remove one of the test files from your solution.

Compiling Windows PostgreSQL 9.5 64bit C-language functions

I want to create native C extensions to PostgreSQL 9.5 64bit on Windows.
I would love to build them with MinGW-w64 if that's possible, to get my build chain as clean as possible. But I am using the EnterpriseDB build of PostgreSQL, and MinGW build crashes it.
It would also be okay if there is another free compiler that I can use in this commercial project.
I know how to get this to work with Visual Studio 2003 Express but that doesn't seem to be a solution because of License issues.
Addition to the Main Answer
In the article linked below, you can read that it is possible to write C modules using Mingw or Cygwin, and some guidelines regarding the same. However I highly discourage doing so, mostly because of the reasons listed below, and also because that page mentions that those Windows configurations have special needs and receive lighter testing than most; expect a greater incidence of build problems
Here is the full excerpt on Unix-like Platform:
Unix-like Platforms
PGXS originated on Unix-like systems, and it is easy to use there. Unpack the extension module archive and run these commands in the resulting directory:
make PG_CONFIG=path_to_postgresql_installation/bin/pg_config
make PG_CONFIG=path_to_postgresql_installation/bin/pg_config install
You may omit the PG_CONFIG overrides if running type pg_config in your shell locates the correct PostgreSQL installation. Subject to the ownership of the existing PostgreSQL installation directories, the second command will often require root privileges. These instructions also apply when building for Windows using the MinGW or Cygwin compilers. However, those Windows configurations have special needs and receive lighter testing than most; expect a greater incidence of build problems.
A common mistake is to specify the PG_CONFIG=... on the command line before the 'make', which does not work as the value is then overridden by the inner workings of makefiles.
It's important to know that different compilers are not compatible with each other. Each of them have different runtime libraries. So it is very risky to compile extensions with a different compiler other than the one used to build the software you are using.
Postgresql's Windows build uses Visual Studio, same with EnterpriseDB (as far as I know). You will need to use the same compiler to build your extensions.
(For more information please refer: Building and Installing PostgreSQL Extension Modules and Postgres Enterprise Manager Installation Guide - EnterpriseDB (PDF))
This should explain why your extensions compiled with Mingw-w64 crash.
Luckily, there are two solutions you could choose:
Use Microsoft Visual Studio Community. It is completely free for individual developers, however there are restrictions for businesses. It should compile proper modules for your Postgresql build.
Rebuild the compleat Postgresql binary with Mingw-w64 or any other compiler of your choice (LLVM/Clang maybe), and then compile extensions with the same.
Doing either of these should help you. And this applies to all platforms, languages, and other softwares too. If you want to build extensions for a software, you need the same compiler, on the same platform used to build the software being used.
So, if you want to build extensions for Postgresql on Linux, you need the same compiler (probably GCC) to build extensions.
Happy coding =)
#Swith give you link to docs how to build PostgreSQL Extension Modules with Visual Studio and as you can read:
These instructions also apply when building for Windows using the MinGW or Cygwin compilers. However, those Windows configurations have special needs and receive lighter testing than most; expect a greater incidence of build problems.
A common mistake is to specify the PG_CONFIG=... on the command line before the 'make', which does not work as the value is then overridden by the inner workings of makefiles.
Did you check this ?
Also you can read other docs Building PostgreSQL With MinGW - maybe this help you more.
It would also be okay if there is another free compiler that I can use in this commercial project.
Did you check C compliers list on wiki - in particular, you can check Cygwin compiler - it's mentioned in docs above and it's free.
I know how to get this to work with Visual Studio 2003 Express but that doesn't seem to be a solution because of License issues.
What kind of issues do you see ?
Maybe check Visual Studio 2015 Community Edition (not Express) like #Simon Mourier suggest.
There is quite different licencing between Express and Community editions - I'm not sure about details, but as far I know Community Edition is more flexible for using in commercial projects:
For organizations:
An unlimited number of users within an organization can use Visual Studio Community for the following scenarios: in a classroom learning environment, for academic research, or for contributing to open source projects.
For all other usage scenarios:
In non-enterprise organizations, up to five users can use Visual Studio Community. In enterprise organizations (meaning those with >250 PCs or >$1 Million US Dollars in annual revenue), no use is permitted beyond the open source, academic research, and classroom learning environment scenarios described above.
For more information, see the Visual Studio Community license terms.

Keeping Visual Studio project files in sync with directory contents?

We have a large C project with development happening on Linux, Mac OS and Windows. Most of our Windows developers use MSVC -- for example, the free edition of Visual C. Oftentimes .c source files are added, renamed or deleted, and we find it very frustrating to keep the Visual C project in sync with these changes to directories.
Developer A might add newfile.c, check it in to Subversion and happily continue work.
Developers B, C, etc. update to the latest revision. Then when they compile in MSVC they get an error (buried somewhere in the huge compile output) saying the linker can't find such-and-such symbol. They then need to look to see what files have changed and manually add that to the project tree in MSVC.
(Developer A might be on Unix where build scripts tend to automatically find the right files to compile, and not realise how much work they've just created for B and C!)
My question is, is there a way to tell MSVC to consider every .c file in a directory as part of the project?
Update We have build scripts that can create initial MSVC project files. But there's a signicifant amount of customisation that gets done after this (pointing to libraries, etc.) which would be blown away each time the scripts were rerun merely to add a new file.
Given how many large projects there are out there, I'm kind of surprised Visual Studio requires such manual work by each developer just to pick up new files added by others.
I'm going to optimistically hold out for a better solution for now...
I don't think Visual Studio can do what you want (but would be glad if I'm proved wrong!).
What works for me is to use cross platform project files. Take a look at CMake, which allows you to define the structure of your project in a platform independent text based format. Then on each platform these project files are processed with a tool that then automatically generates the appropriate thing, which could be Makefiles, Visual Studio solution and project files, etc.
If this is really a serious problem, I would recommend writing a script which updates VS project file accordingly with directory contents.

can't build CUDA project in visual studio 2008

I'm a first year student Computer Science major at the University of Belgrade.My Soft Computing project is to compare a performance of CUDA implementations of different population based algorithms, such as Genetic algorithms, Ant Colony Optimization, Bee Colony, Firefly and PSO. It is not expected from me to write all these codes, since I am a first year student.My assignment is just to try to find codes, run them and measure the performance difference between CPU and GPU implementations.
A few good people sent me a CUDA implementation of Genetic Algorithm that was developed under Linux. Since I am not very familiar with Linux, I am having trouble to build and run CUDA project in visual studio on windows.
Make file is included in project but I think that it is not complete. Make file includes another make file which I do not have. I tried to run it under win 7, but it was unsuccessful, so I installed win xp, visual studio 2008, CUDA SDK 2.3 and matching drivers. Whatever I try, I am always having same problems.
First, I got u_int32_t is undefined (u_int32_t is custom defined type), so I replace it with __int32, and that solves the problem.
After that I get the following errors: rint is not defined and log2 is not defined. I don't know why I get these errors since math_functions.h is included indirectly in project via common_functions.h. Then I put two lines with these function under comments, and give some fixed values to that variables.
And after that I get linker errors. For example:
Error 3 error LNK2019: unresolved external symbol _h_fit referenced in function "public: __thiscallGa::Ga(int *,char * *)
Is there anything that I can do? In addition, I would be very thankful if anyone is willing to send me CUDA implementation of Genetic Algorithm that works. My e-mail address is in my profile.
EDIT:
I set include pats to all h files, link pats to lib files. I also set CUDA build rule. I can build and run other CUDA projects just fine.
Install NSight 1.51. This will get the build rules etc all set up for you.
May sure that the Include Directories property in the projects Configuration Properties | VC++ Directories tab include a path to the SDK's includes. Something like:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\include
Make sure that the Linker | Input tab has cudart.lib as one of the Additional Dependencies
The linker error looks like it can't find methods like Ga(int *,char * *) which I'm assuming is part of your GA algorithm. Are you trying to link a CUDA project to another VS project to use the CUDA GA library? If so you need to make sure that the class that exploses the GA library to other code is marked as
class __declspec(dllexport) {classname}
So that the DLL exports the class and the other VS project needs to include a dependency to the CUDA project. Without seeing how your solution is configured it's hard to say more.
Here are two tutorials on getting started with CUDA and Visual C++ 2010, most of this applies to VS 2008:
http://blog.cuvilib.com/2011/02/24/how-to-run-cuda-in-visual-studio-2010/
http://www.ademiller.com/blogs/tech/2011/03/using-cuda-and-thrust-with-visual-studio-2010/
There's also a post on the NVIDIA forum:
http://forums.nvidia.com/index.php?showtopic=184539
Make sure you have set include path to h files,
link path to lib files,
build event to copy dlls.
(All to correct paths in Toolkit and SDK.)
And also use CUDA's rule file to set up build tool
for cu files.

Build C project automaticly

I'm working on a free software (bsd license) project with others. We're searching for a system that check out our source code (svn) and build it also as test it (unit tests with Check / other tools).
It should have a webbased interface and generate reports.
I hope we don't have to write such a system from null by ourselves...
You surely do not have to code this yourself - there are a lot of continuous integration systems which are able to check out source code from systems such as SVN and they are generally easy to extend with your own tasks, so running custom test scripts/programs should not be a problem.
While these CI systems are probably not written in C, this does not matter, since they just need to be able to access and compile your source code, for which they will use an external compiler anyways.
Just to list some of the well known CI tools:
CruiseControl
Hudson
TeamCity
You might also be interested in other questions on Stack Overflow tagged as continuous-integration. :)
I don't think that there's a buildsystem that is capable of doing all this tasks - but what about combining them?
SCons is a nice buildsystem that runs on every machine that has Python. It can even build directly from SVN. For automatic building you can try Buildbot.
Check out buildbot
My vote would be CruiseControl.NET, it has everything you are asking for. It is open source so the costs are low, and it has a very active user community on google groups to help you with your problems as you grow accustomed to it. Also, although .NET based, using MONO it is very nice on Linux and Mac build servers as well so you have everything covered.

Resources