This project is read-only.

AccessViolationException on GPGPUBLAS.GEMM

Apr 15, 2013 at 5:55 AM
Edited Apr 15, 2013 at 5:56 AM
When running this code:
// Prepare sample data
Random rand = new Random();
int n = 10;

float[] cpuMatrixA = new float[n * n];
float[] cpuMatrixB = new float[n * n];
float[] cpuMatrixC = new float[n * n];

for (int i = 0; i < n * n; i++)
{
    cpuMatrixA[i] = rand.Next(100);
    cpuMatrixB[i] = rand.Next(100);
    cpuMatrixC[i] = rand.Next(100);
}

float[] gpuMatrixA = gpu.CopyToDevice(cpuMatrixA);
float[] gpuMatrixB = gpu.CopyToDevice(cpuMatrixB);
float[] gpuMatrixC = gpu.CopyToDevice(cpuMatrixC);

float alpha = 1.0f;
float beta = 1.0f;

blas.GEMM(n, n, n, alpha, gpuMatrixA, gpuMatrixB, beta, gpuMatrixC);
I get an AccessViolationException on the GEMM call. Anyone seen this before?
Apr 15, 2013 at 8:36 AM
Morning

Like most of the examples on here, we must all learn to be more precise when dealing with code, computer science is a precise science, so we must also be precise.

This code will not compile because you have missed most of it out, where is the rest, where is the definition of your gpu and "CudafyModule km"

post the complete code ( make it as simple as possible but still includes the error) and I will try to help, and in future try to post the whole example !
Apr 15, 2013 at 9:23 PM
I could be mistaken, but I have no "Cudafied" code...I am just using the BLAS wrappers that the Cudafy library comes with...so I don't need any "CudafyModule km", correct? Sorry for the incomplete code. Here is the entire method (the only method):
            Action<string> WriteLine = s => System.Console.WriteLine(s);

            WriteLine("Initializing...");
            var gpu = CudafyHost.GetDevice(CudafyModes.Target);
            var blas = GPGPUBLAS.Create(gpu);
            var gpuProps = gpu.GetDeviceProperties(true);
            WriteLine("   GPU Name: " + gpuProps.Name);
            WriteLine("   GPU Clock: " + gpuProps.ClockRate);
            WriteLine("   GPU Memory: " + gpuProps.TotalMemory);
            WriteLine("Initialized.");

            // Prepare sample data
            Random rand = new Random();
            int n = 10;

            float[] cpuMatrixA = new float[n * n];
            float[] cpuMatrixB = new float[n * n];
            float[] cpuMatrixC = new float[n * n];

            for (int i = 0; i < n * n; i++)
            {
                cpuMatrixA[i] = rand.Next(100);
                cpuMatrixB[i] = rand.Next(100);
                cpuMatrixC[i] = rand.Next(100);
            }

            float[] gpuMatrixA = gpu.CopyToDevice(cpuMatrixA);
            float[] gpuMatrixB = gpu.CopyToDevice(cpuMatrixB);
            float[] gpuMatrixC = gpu.CopyToDevice(cpuMatrixC);

            float alpha = 1.0f;
            float beta = 1.0f;

            blas.GEMM(n, n, n, alpha, gpuMatrixA, gpuMatrixB, beta, gpuMatrixC);

            gpu.CopyFromDevice(gpuMatrixC, cpuMatrixC);

            //gpu.FreeAll();

            WriteLine("Done.");
Also, this is basically taken from the code you see here: https://cudafy.codeplex.com/discussions/429463. However, I don't get a NotImplementedException (my project is being built in x64), I am getting an AccessViolationException.

Thanks!
Apr 16, 2013 at 11:09 PM
Anyone have any ideas?
Apr 19, 2013 at 11:18 PM
Bueller?
Apr 24, 2013 at 11:56 PM
Just thought you should know: I tried your sample under a x64 compilation, and it worked just fine.

cheers
Apr 25, 2013 at 5:05 AM
I was afraid someone would say that...maybe it is just my machine?

Thanks, though!
Dec 15, 2013 at 1:59 PM
Edited Dec 15, 2013 at 1:59 PM
I've encountered the same issue.

did you find the cause in the end?
Dec 17, 2013 at 8:03 AM
Edited Dec 17, 2013 at 8:21 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);
i've been hammering away at this for a few days now. does any1 have a clue?

btw, both are compiling on .net framework 4