使用Cudafy时避免nvcc编译 [英] Avoiding nvcc compilation when using Cudafy

查看:120
本文介绍了使用Cudafy时避免nvcc编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Cudafy and would like my users to be able to use CUDA without installing the CUDA SDK, but they can use the Cudafy DLL. To avoid nvcc compilation done automatically in CudafyTranslator.Cudafy(types), I'm using the following approach:

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

其中typesSystem.Type s的数组.

问题出在第三行,TryDeserialize总是返回null.我检查了文件是否存在,并且modulePath是正确的并且文件已经存在.有人可以说明这件事吗?

The problem is in the third line, TryDeserialize always returns null. I have checked that the file exists and the modulePath is correct and the file exists. Can someone please shed some light on the matter?

如果不打算重新编写Cudafy模块,我已经准备好改变自己的方法.

I'm ready to change my approach if it doesn't mean re-writing my Cudafy modules.

推荐答案

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

This is my function (which is partially based on your code btw):

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

这篇关于使用Cudafy时避免nvcc编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆