I am trying to run CUDA codes on my computer. I dont have a Nvidia graphics card. I just want to try to emulate it to check if my code is correct and then later check the parallelization results.
I installed the CUDA toolkit and the CUDA SDK on my computer.
I am trying to set it up with Visual studio 2010.
But when I run the sample programs in the SDK the following error comes:
C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK
4.0\C\src\eigenvalues\eigenvalues_vs2010.vcxproj : error : The imported project "C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 4.0.props"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk. C:\ProgramData\NVIDIA
Corporation\NVIDIA GPU Computing SDK
4.0\C\src\eigenvalues\eigenvalues_vs2010.vcxproj
C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK
4.0\C\common\cutil_vs2010.vcxproj : error : The imported project "C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 4.0.props"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk. C:\ProgramData\NVIDIA
Corporation\NVIDIA GPU Computing SDK 4.0\C\common\cutil_vs2010.vcxproj
Unable to start program C:\ProgramData\NVIDIA Corporation\NVIDIA GPU
Computing SDK 4.0\shared\lib\Win32\shrUtils32D.lib The specified file
is an unrecognized or unsupported binary format.
Can some one please help me out with this error.
Check these pages:
How to emulate CUDA on windows
GPU Emulator for CUDA programming without the hardware
I myself prefer using openCL.
There are two problems here.
The first two errors that you see are actually the result of Visual Studio not finding the build customization files that your project uses. These build customizations are handy additions to Visual Studio which allow you to easily add CUDA sources to your projects without having to manually set up build rules to call NVCC.
I don't remember if it was the case for CUDA 4.0, but with 4.1 these were automatically installed with the CUDA Toolkit. (I remember in some earlier version I set this up manually, so check your documentation to see if that's necessary) Are you sure you installed this toolkit? (For CUDA 4.0 in your case)
The last error is actually the result of you not trying to run an executable from within Visual Studio, but a static library. Of course this doesn't work, so it will complain about an unrecognized binary format. If you want to run a particular executable from within Visual Studio, make sure its project is set as the startup project. You can do so by right-clicking on the particular project and selecting "Set as startup project".
However, even if you solve these errors, you still won't be able to run these CUDA examples without a Nvidia graphics card. The emulator which was part of pre 3.x CUDA releases is no longer a part of CUDA. A possible solution would be to use Ocelot, but if you're simply starting out, that might be a bit much.
Related
I wanted to get started in GPU programming and since I have an AMD GPU I would like to start with OpenCL.
I have installed on my Windows 10 machine Visual Studio Code 2019 editor and I've also installed this https://github.com/GPUOpen-LibrariesAndSDKs/OCL-SDK. I tried to put those variables inside the settings of VC2019 but nothing happened.
Can somebody help troubleshooting this problem? How did you manage to install OpenCL?
Thanks in advance
When compiling your code, you need to tell the linker where the OpenCL headers and lib file are located. I usually put the headers and lib file inside the project directory:
g++ *.cpp -o Test.exe -I./OpenCL/include -L./OpenCL/lib -lOpenCL
But you can also make the -Ipath/to/OpenCL/include -Lpath/to/OpenCL/lib paths point to the OCL-SDK directory.
For how to setup OpenCL with VS Community, see here: https://stackoverflow.com/a/57017982/9178992
For an easy start with OpenCL, I created a wrapper that vastly simplifies the OpenCL C++ bindings and eliminates the entire code overhead that comes with it. This includes the OpenCL headers and all Visual Studio Community project settings; no additional setup required:
https://github.com/ProjectPhysX/OpenCL-Wrapper
Visual Studio 2017 RC includes much tighter CMake integration, allowing one to skip the intermediate step of generating project/solution files and use CMake effectively as the project file itself. There is sufficient documentation from Microsoft for using these features with regular C++ files, and there is sufficient documentation on this website (example) for making CUDA and Cmake play nicely, when it comes to linking CUDA code to C++ code.
What I can't find information on is how to make CMake, Visual Studio 2017 RC, and CUDA 8.0 all play nicely. This is a difficult problem, because 2017RC has no integration for the CUDA SDK anyways, and I was hoping to use 2017RC so that my C++ interface to the CUDA code could use C++14 and/or C++17. I'm working on the beginning of a large project that will primarily involve writing a static CUDA library that is accessed through C++: so, I'd like to get the CMake to take care of compiling my CUDA sources into a static library, and for it to help with feeding the linking information to Visual Studio. So far, I haven't had any success with using FindCUDA's various features to accomplish this, but I'm assuming that's due to a misunderstanding on my part. I've read through the documentation on separable compilation from Nvidia, but that wasn't helpful for figuring out CMake.
Further, whenever I try to use CMake in VS2017RC, I still end up with the various vcxproj files that CMake likes to spit out. Is this due to an error on my part? How do I edit the build command arguments, or CMakeLists.txt, to get the functionality demonstrated here to work?
The very short (and only at the time of writing) answer is that you can't. CUDA 8 doesn't support VS2017. Only VS2015 is presently supported.
You can always find the compiler/IDE versions which the release version of CUDA supports here
Edit to add that the CUDA 9 release will add official support for VS2017.
All you need to do is set the CUDA_HOST_COMPILER variable to a supported compiler for example the visual studio 2015 compiler.
In my case this is:
C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe
As both runtime libraries are binary compatible you can use the 2015 compiler within CUDA and compile all the rest of the application with the 2017 compiler.
I am new to OpenCL, I have been trying to test run OpenCL code on Nvidia. I have installed the CUDA 6.0 tool kit and I have added the .cu and .cl extensions in visual studio 2010. I have included OpenCL.lib in the Linker tab of project properties. I have included the needed libraries in visual studio 2010. But, when I compile my code I get an error "nvcc : fatal error : Don't know what to do with matvec.cl". Can somebody shed some light on this issue. I have been at it for the past two days. There were previous questions related to this, but there is no reply for one question, here is the link:
Cannot run OpenCL on an NVIDIA Card ( 'CL/cl_platform.h': No such file or directory)
and another the link in the reply does not work for some reason, here is the link:
How to configure OpenCL in visual studio2010 for nvidia's gpu on windows?
If someone can also provide a link for this issue, it would be greatly appreciated. Advance thanks.
It looks like you have configured Visual Studio to compile .cl files with nvcc. This is what you should do for CUDA files (.cu), but OpenCL kernel source code is compiled at runtime, and should not be compiled by anything at application build time. Just remove this configuration option, and you should be good to go.
One thing you might want to do with .cl files is have them automatically copied to the application binary directory, so that the application can find them easily when it wants to load them. This is just a matter of preference.
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!
I have installed cudatoolkit_3.2.16_win_64 and gpucomputingsdk_3.2.16_win_64. When I choose a example of the SDK, I get this error:
The imported project "C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\NvCudaRuntimeApi.targets"
was not found. Confirm that the path
in the declaration is
correct, and that the file exists on
disk. C:\ProgramData\NVIDIA
Corporation\NVIDIA GPU Computing SDK
3.2\C\src\template\template_vc90.vcxproj
And in the Solution Explorer, it shows "template(unavailable)""the project file was unloaded".
How to fix this error?
3.2 now works with the latest bits. Horray! The simplest way to get this working is to install NSight 1.51 and this gets you the build rules installed in the right place for 3.2.
Here are two tutorials on getting started with CUDA and Visual C++ 2010:
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
As far as I know, you can't have v3.2 with VS2010 because it ain't supported yet.
But you could fallback to 3.1 if you would like to keep using VS2010:
CUDA + VS2010 without VS2008