Skip to content

Commit 4fcff17

Browse files
committed
libopencl: Implement just enough event for getEventProfilingInfo()
Helps programs report their own simulated time. Signed-off-by: Roy Spliet <[email protected]>
1 parent ae2319e commit 4fcff17

File tree

1 file changed

+94
-11
lines changed

1 file changed

+94
-11
lines changed

libopencl/opencl_runtime_api.cc

+94-11
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ struct _cl_mem {
172172
size_t m_size;
173173
};
174174

175+
struct _cl_event {
176+
private:
177+
cl_ulong start;
178+
cl_ulong cmd_end;
179+
size_t refcount;
180+
public:
181+
_cl_event() : start(0), cmd_end(0), refcount(1) {}
182+
cl_ulong getCmdEnd(void);
183+
void setCmdEnd(cl_ulong);
184+
cl_ulong getStart(void);
185+
void setStart(cl_ulong);
186+
void retain(void);
187+
bool release(void);
188+
};
189+
175190
struct pgm_info {
176191
std::string m_source;
177192
std::string m_asm;
@@ -358,6 +373,36 @@ _cl_mem::_cl_mem(
358373
}
359374
}
360375

376+
cl_ulong _cl_event::getCmdEnd( void )
377+
{
378+
return cmd_end;
379+
}
380+
381+
void _cl_event::setCmdEnd( cl_ulong e )
382+
{
383+
cmd_end = e;
384+
}
385+
386+
cl_ulong _cl_event::getStart( void )
387+
{
388+
return start;
389+
}
390+
391+
void _cl_event::setStart( cl_ulong s )
392+
{
393+
start = s;
394+
}
395+
396+
void _cl_event::retain( void )
397+
{
398+
refcount++;
399+
}
400+
401+
bool _cl_event::release( void )
402+
{
403+
return ((--refcount) <= 0);
404+
}
405+
361406
_cl_context::_cl_context( struct _cl_device_id *gpu )
362407
{
363408
m_uid = sm_context_uid++;
@@ -735,15 +780,6 @@ clCreateProgramWithBinary(cl_context /* context */,
735780
return cl_program();
736781
}
737782

738-
extern CL_API_ENTRY cl_int CL_API_CALL
739-
clGetEventProfilingInfo(cl_event /* event */,
740-
cl_profiling_info /* param_name */,
741-
size_t /* param_value_size */,
742-
void * /* param_value */,
743-
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0{
744-
gpgpusim_opencl_warning(__my_func__,__LINE__, "GPGPUsim - OpenCLFunction is not implemented. Returning CL_SUCCESS");
745-
return CL_SUCCESS;
746-
}
747783
/*******************************************************************************************************/
748784

749785

@@ -956,7 +992,13 @@ clEnqueueNDRangeKernel(cl_command_queue command_queue,
956992
if ( err_val != CL_SUCCESS )
957993
return err_val;
958994

959-
gpgpu_t *gpu = command_queue->get_device()->the_device();
995+
gpgpu_sim *gpu = command_queue->get_device()->the_device();
996+
997+
if ( event ) {
998+
*event = new _cl_event();
999+
event[0]->setStart((gpu_tot_sim_cycle * 1000000) / gpu->shader_clock());
1000+
}
1001+
9601002
if (kernel->get_implementation()->get_ptx_version().ver() <3.0){
9611003
gpgpu_ptx_sim_memcpy_symbol( "%_global_size", _global_size, 3 * sizeof(int), 0, 1, gpu );
9621004
gpgpu_ptx_sim_memcpy_symbol( "%_work_dim", &work_dim, 1 * sizeof(int), 0, 1, gpu );
@@ -980,6 +1022,10 @@ clEnqueueNDRangeKernel(cl_command_queue command_queue,
9801022
gpgpu_opencl_ptx_sim_main_func( grid );
9811023
else
9821024
gpgpu_opencl_ptx_sim_main_perf( grid );
1025+
1026+
if ( event ) {
1027+
event[0]->setCmdEnd((gpu_tot_sim_cycle * 1000000) / gpu->shader_clock());
1028+
}
9831029
return CL_SUCCESS;
9841030
}
9851031

@@ -1243,6 +1289,10 @@ clRetainMemObject(cl_mem memobj) CL_API_SUFFIX__VERSION_1_0
12431289
extern CL_API_ENTRY cl_int CL_API_CALL
12441290
clRetainEvent(cl_event event) CL_API_SUFFIX__VERSION_1_0
12451291
{
1292+
if ( !event )
1293+
return CL_INVALID_EVENT;
1294+
1295+
event->retain();
12461296
return CL_SUCCESS;
12471297
}
12481298

@@ -1258,6 +1308,33 @@ clRetainDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_0
12581308
return CL_SUCCESS;
12591309
}
12601310

1311+
extern CL_API_ENTRY cl_int CL_API_CALL
1312+
clGetEventProfilingInfo(cl_event event,
1313+
cl_profiling_info param_name,
1314+
size_t param_value_size,
1315+
void * param_value,
1316+
size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0{
1317+
if ( !event )
1318+
return CL_INVALID_EVENT;
1319+
1320+
switch (param_name) {
1321+
case CL_PROFILING_COMMAND_QUEUED:
1322+
case CL_PROFILING_COMMAND_SUBMIT:
1323+
case CL_PROFILING_COMMAND_START:
1324+
CL_ULONG_CASE( event->getStart() );
1325+
break;
1326+
case CL_PROFILING_COMMAND_END:
1327+
CL_ULONG_CASE( event->getCmdEnd() );
1328+
break;
1329+
default:
1330+
return CL_INVALID_VALUE;
1331+
break;
1332+
}
1333+
1334+
//gpgpusim_opencl_warning(__my_func__,__LINE__, "GPGPUsim - OpenCLFunction is not implemented. Returning CL_SUCCESS");
1335+
return CL_SUCCESS;
1336+
}
1337+
12611338
extern CL_API_ENTRY cl_int CL_API_CALL
12621339
clGetProgramInfo(cl_program program,
12631340
cl_program_info param_name,
@@ -1407,8 +1484,14 @@ clWaitForEvents(cl_uint /* num_events */,
14071484
}
14081485

14091486
extern CL_API_ENTRY cl_int CL_API_CALL
1410-
clReleaseEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0
1487+
clReleaseEvent(cl_event e) CL_API_SUFFIX__VERSION_1_0
14111488
{
1489+
if ( e == nullptr )
1490+
return CL_INVALID_EVENT;
1491+
1492+
if ( e->release() )
1493+
delete e;
1494+
14121495
return CL_SUCCESS;
14131496
}
14141497

0 commit comments

Comments
 (0)