cudafy throws an exception while testing

1k Views Asked by At

I'm using VS 2010 on a Windows 7 64x.

I've created a static class Cuda with the following code

namespace Network
{
    public static class Cuda
    {
        static GPGPU gpu= CudafyHost.GetDevice();
        static CudafyHost host = new CudafyHost();
        static GPGPUBLAS blas = GPGPUBLAS.Create(gpu);

        public static void GEMM(int m, int n, int k, float alpha, float[] a, float[] b, float beta, float[] c,Cudafy.Maths.BLAS.Types.cublasOperation Op)
        {
            float[] d_a = gpu.Allocate(a);
            float[] d_b = gpu.Allocate(b);
            float[] d_c = gpu.Allocate(c);

            gpu.CopyToDevice(a, d_a);
            gpu.CopyToDevice(b, d_b);
            gpu.CopyToDevice(c, d_c);

            blas.GEMM(m, n, k, alpha, d_a, d_b, beta, d_c, Op);

            gpu.CopyFromDevice(d_c, c);

            gpu.Free(d_a);
            gpu.Free(d_b);
            gpu.Free(d_c);
        }
    }
}

And I successfully use this GEMM function, but when I try to test my code with the test like this

``
namespace TestProject
{
    [TestClass]
    public class MatrixTest
    {
        /// <summary>
        ///op_Multiply
        ///</summary>
        [TestMethod()]
        public void op_MultiplyTest()
        {


            Matrix a = new Matrix(2,3); 
            a.Data = new float[] { 1, 2, 3, 4, 5, 6 };

            Matrix b = new Matrix (3,4);
            b.Data = new float[] { 1, 0, 2, 3, 1, 2, 0, 4, 2, 1, 1, 0, 3, 0, 1, 1 };

            Matrix expected = new Matrix(2, 4);

            expected.Data = new float[] {11,14,16,22,22,28,4,6};

            Matrix actual;
            actual = (a * b);
            Assert.AreEqual(expected, actual);
        }
    }
}

I get the following exception:

System.TypeInitializationException
Message=Type Initializer "Cudafy.Host.CudafyHost" threw an exception.
Source=Cudafy.NET
TypeName=Cudafy.Host.CudafyHost
StackTrace:
   в Cudafy.Host.CudafyHost.GetDevice(eGPUType type, Int32 deviceId)
   в Network.Cuda..cctor() в C:\Users\Dan\Documents\Visual Studio 2010\Projects\Network\Network\Cuda.cs:строка 14
InnerException: System.InvalidOperationException
   Message=Category does not exist.
   Source=System
   StackTrace:
        в System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
        в System.Diagnostics.PerformanceCounter.InitializeImpl()
        в System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)
        в System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName)
        в Cudafy.Host.EmulatedGPU..ctor(Int32 deviceId)
        в Cudafy.Host.CudafyHost.DoCreateDevice(eGPUType target, Int32 deviceId)
        в Cudafy.Host.CudafyHost.CreateDevice(eGPUType type, Int32 deviceId)
        в Cudafy.Host.CudafyHost.GetDevice(eGPUType type, Int32 deviceId)
        в Cudafy.Host.CudafyHost..cctor()
   InnerException: 

It seems to me that the problem is with attempt of IDE use cudafy DLL twice or init the static class twice...

How can i solve it?

=============== Edit ===============

I tried to use any functions from cudafy dll in my class MatrixTest. Well, it works. But not all. For example, Cudafy.Host.CudaGPU.GetDeviceCount() returns zero, like there is no cuda capable devices found.

And when i try to use smth like CudafyHost.GetDeviceCount(eGPUType.Cuda) or anything else from class CudafyHost, i get the above exception.

1

There are 1 best solutions below

0
On

The exception you see is due to a missing performance category on your system. This is apparently something that goes wrong occasionally with .NET. See this thread for more information. The next CUDAfy release will handle such an error more gracefully.