Skip to content

Commit 56438cc

Browse files
committed
Honor PTX_SIM_KERNELFILE override on CUDA >= 6.0
The PTX_SIM_USE_PTX_FILE / PTX_SIM_KERNELFILE override, documented in the README for simulating a hand-edited PTX file without recompiling the application, was only implemented in the legacy pre-CUDA-6.0 PTX loading branch of cuobjdumpParseBinary. On CUDA 6.0+ the active #if (CUDART_VERSION >= 6000) branch loads PTX solely from the cuobjdump-extracted filename (which is regenerated on every run), so the override silently had no effect even though the "overriding embedded ptx ... (PTX_SIM_USE_PTX_FILE is set)" message was still printed during initialization. Honor PTX_SIM_KERNELFILE in the CUDART_VERSION >= 6000 loading loop as well, gated on both PTX_SIM_USE_PTX_FILE and PTX_SIM_KERNELFILE being set so default behavior is unchanged. PTXInfo (register/shared-memory usage) is still loaded from the originally extracted file.
1 parent 6c3cf4f commit 56438cc

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

libcuda/cuda_runtime_api.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3802,6 +3802,19 @@ void gpgpu_context::cuobjdumpParseBinary(unsigned int handle) {
38023802
std::set<std::string>::iterator itr_s;
38033803
for (itr_s = itr_m->second.begin(); itr_s != itr_m->second.end(); itr_s++) {
38043804
std::string ptx_filename = *itr_s;
3805+
// Allow overriding the cuobjdump-extracted PTX with a hand-edited file so
3806+
// that custom/experimental PTX can be simulated without recompiling the
3807+
// application. Enabled when both PTX_SIM_USE_PTX_FILE and
3808+
// PTX_SIM_KERNELFILE are set (mirrors the legacy pre-CUDA-6.0 path).
3809+
const char *use_ptx_file = getenv("PTX_SIM_USE_PTX_FILE");
3810+
const char *kernel_file = getenv("PTX_SIM_KERNELFILE");
3811+
if (use_ptx_file && strlen(use_ptx_file) && kernel_file &&
3812+
strlen(kernel_file)) {
3813+
printf("GPGPU-Sim PTX: overriding embedded ptx '%s' with '%s' "
3814+
"(PTX_SIM_KERNELFILE is set)\n",
3815+
ptx_filename.c_str(), kernel_file);
3816+
ptx_filename = kernel_file;
3817+
}
38053818
printf("GPGPU-Sim PTX: Parsing %s\n", ptx_filename.c_str());
38063819
symtab = gpgpu_ptx_sim_load_ptx_from_filename(ptx_filename.c_str());
38073820
}

0 commit comments

Comments
 (0)