Linking a kernel to a PTX function

2020-04-30 01:50发布

Can I use a PTX function contained in a PTX file as an external device function to link it to another .cu file which should call that function?

This is another question from CUDA - link kernels together where the function itself is not contained in a .cu file but I rather have a PTX function to be linked somehow.

标签: c++ cuda ptx
1条回答
时光不老,我们不散
2楼-- · 2020-04-30 02:30

You can load the file containing PTX code in your own code from the filesystem by cuModuleLoad and cuModuleGetFunction as follows:

CUmodule module;
CUfunction function;

const char* module_file = "my_ptx_file.ptx";
const char* kernel_name = "my_kernel_name";

err = cuModuleLoad(&module, module_file);
err = cuModuleGetFunction(&function, module, kernel_name);

You can also pass the PTX code to the CUDA driver directly as a string, see Passing the PTX program to the CUDA driver directly.

查看更多
登录 后发表回答