1

Closed

Unable to build ManagedCudaSamples

description

Dear managedCUDA developers,

I am trying to build the latest ManagedCudaSamples using MS Visual Studio 2013. Specifically I am first trying to build the vectorAdd part of the samples.

I was trying to create a new project for vectorAdd that mirrored the layout of the samples, but that wasn't working so I started to play around with the downloaded samples project instead.

The executables that come with the samples worked on my system. When I edit the code to force vectorAdd\Program.cs to use the 32-bit .ptx file that VS is actually building, I get the following error.
Unhandled Exception: ManagedCuda.CudaException: ErrorLaunchFailed: An exception occurred on the device while executing a kernel. Common causes include dereferencing an invalid device pointer and accessing out of bounds shared memory. The context cannot be used, so it must be destroyed (and a new one should be created). All existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.
   at ManagedCuda.CudaKernel.Run(Object[] parameters)
   at vectorAdd.Program.Main(String[] args) in c:\Users\twood\Documents\Visual Studio 2013\ManagedCudaSamples\ManagedCudaSamples\vectorAdd\Program.cs:line 79
Then when I edit the properties of the CudaKernels project to tack an _x64 onto the end of the filename and tell it to do a 64-bit build, I get the error:
Unhandled Exception: ManagedCuda.CudaException: ErrorIllegalAddress: While executing a kernel, the device encountered a load or store instruction on an invalid memory address. The context cannot be used, so it must be destroyed (and a new one should be created).

All existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.
   at ManagedCuda.CudaKernel.Run(Object[] parameters)
   at vectorAdd.Program.Main(String[] args) in c:\Users\twood\Documents\Visual Studio 2013\ManagedCudaSamples\ManagedCudaSamples\vectorAdd\Program.cs:line 79
Shouldn't I be able to build such a simple solution with VS2013 if my system is capable of running the kernels with the .ptx files that shipped with the samples?

file attachments

Closed Jan 23, 2015 at 9:14 PM by kunzmi

comments

kunzmi wrote Jan 20, 2015 at 10:12 PM

Could you please provide the project files (for Cuda and C# projects) that you use? I currently don't have access to VS 2013 to test it my self, but maybe the project files can give some insights.
Also the compiled ptx-files would be interesting to see what the difference is, compared to the ones provided in the samples.

odellus wrote Jan 20, 2015 at 10:42 PM

The pre-compiled ptx files (which you certainly already have) and the ptx files I compiled are included in the compressed attachment along with the project files for vectorAdd as well as CudaKernels.

kunzmi wrote Jan 21, 2015 at 7:26 PM

I inspected the ptx file you provided and it turned out that the 64-bit ptx file is actually only 32 bit. You can check this at the third code line in ptx which is “.address_size 32” and not “.address_size 64”. Also the pointer arguments are u32 and not u64.
This basically means that the compilation settings are erroneous: The entire sample solution is setup with settings for all projects steering the 32/64 bit switch for all projects. There shouldn’t be any need to change the projects settings individually by hand. Could you please double check that you are compiling for the right version?

odellus wrote Jan 22, 2015 at 5:09 PM

I triple checked the configuration settings and made sure the CudaKernel was set for 64-bit.

Now that it is giving me the correct configuration when compiling the kernels into PTX files, I added the PTX file to the vectorAdd project, but now I get the following error.

[vectorAdd.exe] starting...
Vector Addition
vectorAdd.vectorAdd_x64.ptx
The current directory is C:\Users\twood\Documents\Visual Studio 2013\group_effort\managedCuda_examples\vectorAdd\bin\Debug

Unhandled Exception: System.ArgumentException: Kernel not found in resources.
at vectorAdd.Program.Main(String[] args) in c:\Users\twood\Documents\Visual Studio 2013\group_effort\managedCuda_examples\vectorAdd\Program.cs:line 57

But don't worry about it on my end. I decided not to use managedCUDA in my project after my experience with the samples. I just hope my input helps you get to a point where the source code for your samples will actually build instead of sending out pre-compiled binaries so it seems like there are functioning examples of managedCUDA when there are not.

kunzmi wrote Jan 22, 2015 at 9:06 PM

This error is due to the missing resource in your C# assembly, meaning your newly compiled kernel is not embedded in the assembly. Either you load the kernel from file or as an embedded resource as shown in the original vectorAdd demo (The samples are setup assuming that one knows how to embed resources in assemblies with Visual Studio). If you take the samples as provided they will compile with VS 2013, too, what I tested and confirmed in the meantime. Here it seems that settings got a little messed up on your side.
As you are the only one reporting these problems, I guess this is only due to your configuration changes and I will close the issue. If you take the original samples, set the project platform to x64, compile kernels and C# code, I'm very confident you will get running samples.
Anyhow, thanks for reporting!