diff options
| author | Tor Aamodt <[email protected]> | 2010-08-08 04:16:35 -0800 |
|---|---|---|
| committer | Tor Aamodt <[email protected]> | 2010-08-08 04:16:35 -0800 |
| commit | 06435e77c580bf7737333929ed26d3863949bd15 (patch) | |
| tree | 2aa5881d8b3cffc6e3587007da0e9556c78665b3 | |
| parent | 4d441a9746616b2e45397097e6a7600a67aa973c (diff) | |
add listing function for ptx debugging
print out compilation errors encountered during OpenCL to PTX conversion (still a bit cryptic)
[git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 7162]
| -rw-r--r-- | libopencl/nvopencl_wrapper.cc | 23 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_sim.cc | 10 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_sim.h | 2 | ||||
| -rw-r--r-- | src/debug.cc | 46 |
4 files changed, 68 insertions, 13 deletions
diff --git a/libopencl/nvopencl_wrapper.cc b/libopencl/nvopencl_wrapper.cc index 7c12075..6d446a4 100644 --- a/libopencl/nvopencl_wrapper.cc +++ b/libopencl/nvopencl_wrapper.cc @@ -65,10 +65,12 @@ #include <string.h> #include <stdarg.h> +#define PREAMBLE "GPGPU-Sim nvopencl_wrapper" + void vmyexit(int code, const char *str,va_list ap) { char buffer[1024]; - snprintf(buffer,1024,"GPGPU-Sim API: nvopencl_wrapper ERROR ** %s\n", str); + snprintf(buffer,1024,"%s: ERROR ** %s\n", PREAMBLE, str); vprintf(buffer,ap); fflush(stdout); if( code ) @@ -123,9 +125,12 @@ int main(int argc, const char **argv) if ( errcode != CL_SUCCESS ) myexit(3,"clGetPlatformIDs returned %d",errcode); errcode = clGetPlatformInfo(platforms[0], CL_PLATFORM_NAME, 1024, &buffer, NULL); if ( errcode != CL_SUCCESS ) myexit(3,"clGetPlatformInfo returned %d",errcode); - printf("GPGPU-Sim OpenCL API: Generating PTX using OpenCL platform \'%s\'\n",buffer); + printf("%s: Generating PTX using OpenCL platform \'%s\'\n",PREAMBLE,buffer); + errcode = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices); if ( errcode != CL_SUCCESS ) myexit(4,"clGetDeviceIDs returned %d",errcode); + printf("%s: found %u native OpenCL devices\n",PREAMBLE,num_devices); + cl_device_id *devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id) ); errcode = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, num_devices, devices, NULL); if ( errcode != CL_SUCCESS ) myexit(5,"clGetDeviceIDs returned %d",errcode); @@ -143,7 +148,19 @@ int main(int argc, const char **argv) n+= 2; } errcode = clBuildProgram(pgm, 0, NULL, options, NULL, NULL); - if ( errcode != CL_SUCCESS ) myexit(8,"clBuildProgram returned %d",errcode); + if ( errcode != CL_SUCCESS ) { + printf("%s: clBuildProgram returned %d (error) -- build log:\n\n",PREAMBLE,errcode); + size_t build_log_length=0; + errcode = clGetProgramBuildInfo(pgm,devices[0],CL_PROGRAM_BUILD_LOG,0,NULL,&build_log_length); + if( errcode != CL_SUCCESS ) myexit(8,"clGetProgramBuildInfo returned %d",errcode); + char *build_log = (char*)calloc(1,build_log_length); + errcode = clGetProgramBuildInfo(pgm,devices[0],CL_PROGRAM_BUILD_LOG,build_log_length, + build_log,&build_log_length); + printf("%s",build_log); + printf("\n\n%s: end of build log\n", PREAMBLE); + printf("%s: exiting early because the OpenCL code had errors (see above).\n", PREAMBLE); + exit(8); + } size_t nbytes1=0; errcode = clGetProgramInfo(pgm,CL_PROGRAM_NUM_DEVICES,sizeof(cl_uint),&num_devices,&nbytes1); diff --git a/src/cuda-sim/ptx_sim.cc b/src/cuda-sim/ptx_sim.cc index d7fa510..9a2acf6 100644 --- a/src/cuda-sim/ptx_sim.cc +++ b/src/cuda-sim/ptx_sim.cc @@ -434,6 +434,16 @@ std::string ptx_thread_info::get_location() const return std::string(buf); } +const ptx_instruction *ptx_thread_info::get_inst() const +{ + return m_func_info->get_instruction(m_PC); +} + +const ptx_instruction *ptx_thread_info::get_inst( addr_t pc ) const +{ + return m_func_info->get_instruction(pc); +} + void ptx_thread_info::dump_regs() { printf("Register File Contents:\n"); diff --git a/src/cuda-sim/ptx_sim.h b/src/cuda-sim/ptx_sim.h index 8de4127..c2bb533 100644 --- a/src/cuda-sim/ptx_sim.h +++ b/src/cuda-sim/ptx_sim.h @@ -400,6 +400,8 @@ public: bool callstack_pop(); void dump_callstack() const; std::string get_location() const; + const ptx_instruction *get_inst() const; + const ptx_instruction *get_inst( addr_t pc ) const; bool rpc_updated() const { return m_RPC_updated; } bool last_was_call() const { return m_last_was_call; } unsigned get_rpc() const { return m_RPC; } diff --git a/src/debug.cc b/src/debug.cc index 3e71209..0691d78 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -51,6 +51,8 @@ void gpgpu_debug() done=false; /// check if we've reached a breakpoint + const ptx_thread_info *brk_thd = NULL; + const ptx_instruction *brk_inst = NULL; for( std::map<unsigned,brk_pt>::iterator i=breakpoints.begin(); i!=breakpoints.end(); i++) { unsigned num=i->first; @@ -59,19 +61,19 @@ void gpgpu_debug() unsigned addr = b.get_addr(); unsigned new_value = read_location(addr); if( new_value != b.get_value() ) { - printf( "GPGPU-Sim DBG: watch point %u triggered (old value=%x, new value=%x)\n", + printf( "GPGPU-Sim PTX DBG: watch point %u triggered (old value=%x, new value=%x)\n", num,b.get_value(),new_value ); std::map<unsigned,watchpoint_event>::iterator w=g_watchpoint_hits.find(num); if( w==g_watchpoint_hits.end() ) - printf( "GPGPU-Sim DBG: memory transfer modified value\n"); + printf( "GPGPU-Sim PTX DBG: memory transfer modified value\n"); else { watchpoint_event wa = w->second; - const ptx_thread_info *thd = wa.thread(); - const ptx_instruction *pI = wa.inst(); - printf( "GPGPU-Sim DBG: modified by thread uid=%u, sid=%u, hwtid=%u\n", - thd->get_uid(),thd->get_hw_sid(), thd->get_hw_tid() ); - printf( "GPGPU-Sim DBG: "); - pI->print_insn(stdout); + brk_thd = wa.thread(); + brk_inst = wa.inst(); + printf( "GPGPU-Sim PTX DBG: modified by thread uid=%u, sid=%u, hwtid=%u\n", + brk_thd->get_uid(),brk_thd->get_hw_sid(), brk_thd->get_hw_tid() ); + printf( "GPGPU-Sim PTX DBG: "); + brk_inst->print_insn(stdout); printf( "\n" ); g_watchpoint_hits.erase(w); } @@ -84,8 +86,15 @@ void gpgpu_debug() if( !fvi ) continue; if( thread_at_brkpt(fvi->ptx_thd_info, b) ) { done = false; - printf("GPGPU-Sim DBG: reached breakpoint %u at %s (sm=%u, hwtid=%u)\n", + printf("GPGPU-Sim PTX DBG: reached breakpoint %u at %s (sm=%u, hwtid=%u)\n", num, b.location().c_str(), sid, fvi->hw_thread_id ); + brk_thd = (ptx_thread_info*)fvi->ptx_thd_info; + brk_inst = brk_thd->get_inst(); + printf( "GPGPU-Sim PTX DBG: reached by thread uid=%u, sid=%u, hwtid=%u\n", + brk_thd->get_uid(),brk_thd->get_hw_sid(), brk_thd->get_hw_tid() ); + printf( "GPGPU-Sim PTX DBG: "); + brk_inst->print_insn(stdout); + printf( "\n" ); } } } @@ -97,7 +106,7 @@ void gpgpu_debug() /// enter interactive debugger loop while (!done) { - printf("(gpgpu-sim dbg) "); + printf("(ptx debugger) "); fflush(stdout); char line[1024]; @@ -145,6 +154,22 @@ void gpgpu_debug() unsigned value = read_location(addr); g_global_mem->set_watch(addr,next_brkpt); breakpoints[next_brkpt++] = brk_pt(addr,value); + } else if( !strcmp(tok,"l") ) { + if( brk_thd == NULL ) + printf("no thread selected"); + addr_t pc = brk_thd->get_pc(); + addr_t start_pc = (pc<5)?0:(pc-5); + for( addr_t p=start_pc; p <= pc+5; p++ ) { + const ptx_instruction *i = brk_thd->get_inst(p); + if( i ) { + if( p != pc ) + printf( " " ); + else + printf( "==> " ); + i->print_insn(stdout); + printf( "\n" ); + } + } } else if( !strcmp(tok,"h") ) { printf("commands:\n"); printf(" q - quit GPGPU-Sim\n"); @@ -153,6 +178,7 @@ void gpgpu_debug() printf(" del <n> - delete breakpoint\n"); printf(" s - single step one shader cycle (all cores)\n"); printf(" c - continue simulation without single stepping\n"); + printf(" l - list PTX around current breakpoint\n"); printf(" dp <n> - display pipeline contents on SM <n>\n"); printf(" h - print this message\n"); } else { |
