本文介绍了直接将PTX程序传递给CUDA驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CUDA驱动程序API提供了从文件系统加载包含PTX代码的文件。通常执行以下操作:
The CUDA driver API provides loading the file containing PTX code from the filesystem. One usually does the following:
CUmodule module;
CUfunction function;
const char* module_file = "my_prg.ptx";
const char* kernel_name = "vector_add";
err = cuModuleLoad(&module, module_file);
err = cuModuleGetFunction(&function, module, kernel_name);
如果在运行时(运行中)生成PTX文件并通过文件IO,似乎是
In case one generates the PTX files during runtime (on the fly) going through file IO seems to be a waste (since the driver has to load it back in again).
有没有办法将PTX程序直接传递给CUDA驱动程序(例如,作为C字符串) )?
Is there a way to pass the PTX program to the CUDA driver directly (e.g. as a C string) ?
推荐答案
取自 ptxjit
CUDA示例:
将PTX程序定义为C字符串
Define the PTX program as a C string as
char myPtx32[] = "\n\
.version 1.4\n\
.target sm_10, map_f64_to_f32\n\
.entry _Z8myKernelPi (\n\.param .u32 __cudaparm__Z8myKernelPi_data)\n\
{\n\
.reg .u16 %rh<4>;\n\
.reg .u32 %r<8>;\n\
// Other stuff
.loc 28 18 0\n\
exit;\n\
}\n\
";
然后
cuModuleLoadDataEx(phModule, myPtx32, 0, 0, 0);
最后
cuModuleLoadDataEx(phModule, myPtx, 0, 0, 0);
这篇关于直接将PTX程序传递给CUDA驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!