Transferring the PTX Program to the CUDA Direct Driver

The CUDA driver API provides for loading a file containing PTX code from the file system. The following is usually done:

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 you generate PTX files at runtime ("on the fly"), viewing the IO file seems unnecessary (since the driver must download it again).

Is there a way to pass a PTX program to a direct CUDA driver (for example, like a C string)?

+5
source share
2 answers

Adapted from the ptxjitCUDA example :

Define the PTX program as string C 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);
+4
source

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

0

All Articles