【问题标题】:cudafy throws an exception while testingcudafy 在测试时抛出异常
【发布时间】:2013-09-08 19:44:48
【问题描述】:

我在 Windows 7 64x 上使用 VS 2010。

我用以下代码创建了一个静态类 Cuda

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);
        }
    }
}

我成功地使用了这个 GEMM 函数,但是当我尝试用这样的测试来测试我的代码时

``
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);
        }
    }
}

我得到以下异常:

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: 

在我看来,问题在于 IDE 尝试使用 cudafy DLL 两次或两次初始化静态类...

我该如何解决?

=============== 编辑================

我尝试在我的类 MatrixTest 中使用来自 cudafy dll 的任何函数。嗯,它有效。 但不是所有的。例如,Cudafy.Host.CudaGPU.GetDeviceCount() 返回零,就像没有找到支持 cuda 的设备一样。

当我尝试使用 CudafyHost.GetDeviceCount(eGPUType.Cuda) 或 CudafyHost 类中的任何其他内容时,我得到了上述异常。

【问题讨论】:

    标签: invalidoperationexception cudafy.net


    【解决方案1】:

    您看到的异常是由于您的系统上缺少性能类别。这显然是 .NET 偶尔会出现的问题。见this thread for more information。下一个 CUDAfy 版本将更优雅地处理此类错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      • 2014-05-10
      • 2023-01-25
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      相关资源
      最近更新 更多