vs2010 VS vs2012

Dec 17, 2013 at 7:44 AM
the following code works fine on vs2010, but on vs2012 gives me an AccessViolationException reading: {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}
 CudafyModule km = CudafyTranslator.Cudafy();

            var _gpu = (CudaGPU)CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
            _gpu.LoadModule(km);
            _gpu.EnableMultithreading();

            _gpu.SetCurrentContext();
            double[] arr5 = { 1 };
            double[] dev1 = _gpu.Allocate<double>(1);
            _gpu.CopyToDevice(arr5, dev1);
            double[] dev2 = _gpu.Allocate<double>(1);
            _gpu.CopyToDevice(arr5, dev2);

            double[] devResult = _gpu.Allocate<double>(1);

            try
            {
                GPGPUBLAS.Create(_gpu).GEMM(1, 1, 1, 1, dev1, dev2, 0, devResult, Cudafy.Maths.BLAS.Types.cublasOperation.N, Cudafy.Maths.BLAS.Types.cublasOperation.T, 1, 1, 1);
            }
            catch (Exception e)
            {
                int s = 1;
            }
            double temp;
            _gpu.CopyFromDevice<double>(devResult, out temp);
both are compiling on .net framework 4, x64

i've been hammering away at this for a few days now. does anyone have a clue?

i've asked this question on a different thread, but since i narrowed it down to enviroment difference i believe it deserved a seperate thread
Coordinator
Dec 18, 2013 at 8:43 AM
Can you try the Maths unit tests in the source code and see if you get similar issue?
Dec 18, 2013 at 12:29 PM
running the Maths unit tests produced the following results:
         vs2010:  it runs for a few minutes, printing lovely lovely unit test text.
         vs2012:  the first call to GBMV results in AccessViolationException with the same text as before.
i even tried opening the vs2010 project using the more advanced enviroment and got the same result.
Coordinator
Dec 18, 2013 at 12:54 PM
I've just run this on VS2012 Premium in Windows 7 64-bit without issue. You are targeting x64 or Any CPU on your x64 OS?
Do you have optimize code enabled? Does this happen in both Debug and Release? Does it happen if you run exe without VS?
Dec 18, 2013 at 1:44 PM
Edited Dec 18, 2013 at 1:47 PM
OS: Windows Server 2012 standard
Microsoft Visual Studio Professional 2012
targeting: x64
optimize code: disabled (debug)/ enabled (release)
debug/release: same results
does NOT happen if i run the exe without vs.

i repeat: when i run the exe without VS the exception does not happen.
Coordinator
Dec 19, 2013 at 10:25 AM
That's very interesting. Also happening if you do Ctrl+F5?
The long winded way of debugging all this would be to study which libraries VS2012 is loading. I have not tested maths libraries in Windows Server 2012 - I will try to do this soon.
Dec 19, 2013 at 5:41 PM
NickKopp wrote:
Do you have optimize code enabled? Does this happen in both Debug and Release? Does it happen if you run exe without VS?
That was eerily on-the-mark. Well done sir!
Coordinator
Dec 19, 2013 at 6:37 PM
Just doing my job...
I actually ran into another unusual problem of this nature recently. If you call AllocateShared and then do not use the returned variable in the rest of the code (rather silly I know but unit tests and example code is not real world so these things happen), having optimize code enabled causes an nvcc error. Why? Because when .NET optimizes it only makes the call to AllocateShared and does not declare the variable. This causes CUDAfy's translator to not handle the AllocateShared correctly (it becomes a different kind of statement). Now, to give this all a further twist, this only became an issue after a recent Windows update. Great fun was had.
Dec 20, 2013 at 11:15 AM
Yes, the translator does have its quirks. Did you manage to fix that 64-bit shl operator not working?
Dec 22, 2013 at 5:56 AM
NickKopp wrote:
That's very interesting. Also happening if you do Ctrl+F5?
Ctrl+F5 (Start Without Debugging) - no exception is thrown
Dec 26, 2013 at 6:39 AM
I have solved the problem.
Apparently the "visual studio hosting proccess" of vs2012 does not like BLAS functions or at least it doesn't on my system.

to solve the issue go to Project Properties->Debug and disable the "Enable the Visual Studio hosting proccess" checkbox near the bottom of the window.


Thanks to NickKopp for his expert, timely and almost psychic like assistance.
Marked as answer by Hidra2000 on 12/26/2013 at 3:06 AM
Coordinator
Dec 26, 2013 at 10:00 AM
This is really useful information, thanks.
Feb 16, 2014 at 4:31 AM
Edited Feb 16, 2014 at 4:31 AM
Wow this was a hard one for me as well. Disable the "Enable the Visual Studio hosting proccess" checkbox worked.
Windows 8.1 x64 VS 2012 Professional.

Thanks for the help guys!