0

我正在使用 Cudafy,并希望我的用户能够在不安装 CUDA SDK 的情况下使用 CUDA,但他们可以使用 Cudafy DLL。为避免在 中自动完成 nvcc 编译CudafyTranslator.Cudafy(types),我使用以下方法:

string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string modulePath = Path.Combine(directory, myType.Name + ".cdfy");
CudafyModule km = CudafyModule.TryDeserialize(modulePath);
if (ReferenceEquals(km, null) || !km.TryVerifyChecksums())
{
    km = CudafyTranslator.Cudafy(types);
    km.Serialize(modulePath);
}
GPU.LoadModule(km);

typess的数组在哪里System.Type

问题在第三行,TryDeserialize总是返回null。我已检查该文件是否存在且modulePath正确且该文件是否存在。有人可以对此事有所了解吗?

如果这并不意味着重新编写我的 Cudafy 模块,我已经准备好改变我的方法。

4

1 回答 1

0

这是我的功能(部分基于您的代码):

public static void LoadTypeModule(GPGPU gpu, Type typeToCudafy)
{
    Console.WriteLine("Loading module "+typeToCudafy.Name);

    string appFolder = AppDomain.CurrentDomain.BaseDirectory;
    string typeModulePath = Path.Combine(appFolder, typeToCudafy.Name + ".cdfy");

    CudafyModule cudaModule = CudafyModule.TryDeserialize(typeModulePath);
    if (cudaModule == null || !cudaModule.TryVerifyChecksums())
    {
        // if failed to open module:
        // translate the type's code to cuda code
        cudaModule = CudafyTranslator.Cudafy(typeToCudafy);
        cudaModule.Serialize(); // save to file
    }
    // load module to cuda memory, don't unload previous modules
    gpu.LoadModule(cudaModule, false);
}

现在调用函数:

MyClassWithCudaKernels classModule = new MyClassWithCudaKernels();
LoadTypeModule(gpu, classModule.GetType());
于 2015-09-08T09:39:04.830 回答