Passing the PTX program to the CUDA driver directly

吃可爱长大的小学妹 提交于 2019-11-30 04:49:40

问题


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

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

Is there a way to pass the PTX program to the CUDA driver directly (e.g. as a C string) ?


回答1:


Taken from the ptxjit CUDA example:

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\
 ";

then

 cuModuleLoadDataEx(phModule, myPtx32, 0, 0, 0);

and finally

 cuModuleLoadDataEx(phModule, myPtx, 0, 0, 0);



回答2:


Use the cuModuleLoadDataEx function to load PTX source from a NULL-terminated string.



来源:https://stackoverflow.com/questions/15842507/passing-the-ptx-program-to-the-cuda-driver-directly

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