summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Rogers <[email protected]>2012-08-23 13:44:24 -0800
committerAndrew Boktor <[email protected]>2014-08-14 13:48:54 -0700
commitf77596e6a6a8dc2346e84ab8edc8c279fde4dcfd (patch)
treebd13a93ebd4be9fa09fa58a01e3d75d8d7d62754
parenta4d6731ac208ccb98aeac4e0fe9073abd99dc892 (diff)
Fixing bad memory references in opencl based on some disconnect between what the nvidia opencl wraper expects and what our opencl_runtime_api provides.
This was causing us to print grabage in the dumped ptx files generated by calls to oclPtxLog and valgrind complains about it. [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 13837]
-rw-r--r--libopencl/opencl_runtime_api.cc13
1 files changed, 5 insertions, 8 deletions
diff --git a/libopencl/opencl_runtime_api.cc b/libopencl/opencl_runtime_api.cc
index 8c9a0d1..be2fdd0 100644
--- a/libopencl/opencl_runtime_api.cc
+++ b/libopencl/opencl_runtime_api.cc
@@ -601,18 +601,18 @@ char *_cl_program::get_ptx()
abort();
}
size_t buffer_length= get_ptx_size();
- char *tmp = (char*)calloc(buffer_length,1);
+ char *tmp = (char*)calloc(buffer_length + 1,1);
+ tmp[ buffer_length ] = NULL;
unsigned n=0;
std::map<cl_uint,pgm_info>::iterator p;
for( p=m_pgm.begin(); p != m_pgm.end(); p++ ) {
const char *ptx = p->second.m_asm.c_str();
- unsigned len = strlen( ptx ) + 1;
- assert( (n+len-1) < buffer_length );
+ unsigned len = strlen( ptx );
+ assert( (n+len) <= buffer_length );
memcpy(tmp+n,ptx,len);
n+=len;
}
- assert( n < buffer_length );
- tmp[n]=0;
+ assert( n == buffer_length );
return tmp;
}
@@ -622,9 +622,7 @@ size_t _cl_program::get_ptx_size()
std::map<cl_uint,pgm_info>::iterator p;
for( p=m_pgm.begin(); p != m_pgm.end(); p++ ) {
buffer_length += p->second.m_asm.length();
- buffer_length++;
}
- buffer_length++;
return buffer_length;
}
@@ -1196,7 +1194,6 @@ clGetProgramInfo(cl_program program,
break;
case CL_PROGRAM_BINARIES:
len = program->get_ptx_size();
- if( param_value && param_value_size < NUM_DEVICES * len ) return CL_INVALID_VALUE;
tmp = program->get_ptx();
if( param_value ) memcpy( ((char**)param_value)[0], tmp, len );
if( param_value_size_ret ) *param_value_size_ret = len;