Avoiding nvcc compilation when using Cudafy

此生再无相见时 提交于 2020-01-03 05:20:50

问题


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

Where types is an array of System.Types.

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?

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


回答1:


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

Now calling the function:

MyClassWithCudaKernels classModule = new MyClassWithCudaKernels();
LoadTypeModule(gpu, classModule.GetType());


来源:https://stackoverflow.com/questions/29430655/avoiding-nvcc-compilation-when-using-cudafy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!