can't build CUDA project in visual studio 2008 - c

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.

Related

Trying to solve WindowError 126 - module not found

Though this is my first question on the StackOverflow, I consider myself a long time member of the community.
Considering myself as a pre-intermediate programmer, I'll try to be as specific as possible.
I'm writing a Python package that uses a C dll to load image files with ctypes. I'm using Python 3.3.5 32bits version on Windows 8 x64. I had to build the dll from the C code. The dll is stb_image.h which is available in GitHub. I used Code::Blocks version 13.12 with the GCC compiler. The dll seems to have built fine.
By my definition, the dll is must be in the same folder as the py code file that wraps its functions, but when ctypes attempts to load the dll an exception is raised: the [in]famous WindowsError: [Error 126] Module not found.
I've found several similar questions and attempted to glean from their solutions by
adding the dll path via os.environ['PATH']
adding the dll path manually in the Path environment variable
changing the current working directory with os.chdir()
using the file module attribute to locate the library
none of these solved the issue
The stb_image library itself has no dependencies so I don't understand why windows can't find it since the dll is where it should be and the path addresses it's exact location. And, of course, there's a lot of other ways to get the job done: PyGame, pySFML (which also uses stb_image), PIL, PyPng, PySDL, you name it, but I'm doing this mostly for learning purposes.
At the writing of this question, something popped up in my head (which may or may not have any relation with the problem): whenever I compile and link programs with GCC and try to run them, I got a message box telling me that some dll (libgcc.dll or something like that) was not found. Could that be the reason Windows can't load stb_image.dll?
I tried everything my experience allowed me to do to solve it but it was not enough. Would you guys, please, give me a light on this?
PS.: Sorry for any bad english. I'm natural from Brazil.

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

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.

C code compilation

i want to compile a 'c' code and create an executable from my application. as of now i do it by specifying the path of my compilation .exe (c++) present in the bin folder of my Dev-Cpp folder.
it works fine but i need to pack the compiler along with the application so i wanted to know what files and folders are needed so that i can compile it directly from the application.
what are the files needed exactly i.e. headers,the compilation application, libs and what else...
any help?
If you're asking how to create and distribute a project which is able to build upon an existing compiler for its functionality, there are packages you can find which are just the compiler portion without the IDE. Minimalist GNU for Windows is such a package:
http://en.wikipedia.org/wiki/MinGW
(In fact, when the people who put together Dev-C++ wrote their integrated development environment, they get the actual compilation functionality from MinGW...which they bundled into their package for good measure. So if you were going to write an IDE of your own, you would start from the MinGW distribution...not by trying to hand-pick files out of Dev-C++.)
One issue to be sensitive to is licensing. While there are not generally any legal issues out of the box regarding distributing executables built with a system like MinGW, when you go as far as to include the compiler in your own "product", it might be tricky. Dev-C++ is under the same license as MinGW (GPL) but I'd imagine there'd be issues if it were not.
If you only need a subset of the full functionality (let's say you only compile C and not C++) there will be a lot of header files and such that you could cut out. But you have to trade off the difficulty of maintaining this sort of optimization vs. just having your program ask users to install MinGW and then tell your program where they installed it. It might take up more space and lead installation to be a two-step process...but frees you from a large number of concerns.
So that's what I would suggest: Have a setting in your program (much like Dev-C++ does) which lets people specify where the MinGW binaries are installed on their system. But let them install it independently.

Multiple Precision for Visual Studio 2010

Can anyone suggest a multiple precision library that comes with pre-built windows binaries. I need to use it use with an existing Visual Studio 2010 project (or where I can get pre-built binaries for win7 64bit for GMP).
I have tried and failed to compile GMP and MPIR and other projects none of them work with various frustrating and ambiguous errors. Unfortunately time pressures are getting to me and what I need to implement is simple if I can get the library built/downloaded.
I need floating point support so a bigint library is not enough.
Thanks,
http://www.cs.nyu.edu/exact/core/gmp/ has the following package with dlls:
dynamic GMP library and header file for Visual C++: gmp-dynamic-vc-4.1.2.zip
They also have the source project files if you want to try recompiling with a different version at some point.
Your best bet is MPIR. I've built MPIR and MPFR using VS 2010 so it is possible. My Windows system is down at the moment but here are some notes I made.
Download MPIR, unpack, and rename directory to just be "mpir" - remove any version numbers.
Find and follow the readme file that documents installing VSYASM.
Run "mpir_config.py" with Python 3.x to create the project files.
Change the number of parallel builds to 1.
Select a particular target (say "lib_mpir_k8") and it should build.
MPIR also includes a couple of batch files so you can do a command line build using configure.bat and make.bat. I find it is easier than the GUI builds.
IIRC, to build MPFR, I had to modify some of the Include directories but my notes are a little too cryptic.
The MPIR mailing list is quite helpful, too.

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.

Resources