Skip to content

Commit d4a7df4

Browse files
committed
cleanup and renaming
1 parent 5931fcd commit d4a7df4

File tree

5 files changed

+110
-86
lines changed

5 files changed

+110
-86
lines changed

intercept/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ source_group(Resources FILES
6060
set(CLINTERCEPT_SOURCE_FILES
6161
src/chrometracer.h
6262
src/chrometracer.cpp
63+
src/cmdbufrecorder.h
6364
src/clIntercept.def
6465
src/clIntercept.map
6566
src/cli_ext.h

intercept/src/cmdbuftracer.h renamed to intercept/src/cmdbufrecorder.h

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,49 @@
1515

1616
#include "common.h"
1717

18-
struct SCommandBufferTraceInfo
18+
struct SCommandBufferRecord
1919
{
20-
std::ostringstream trace;
21-
22-
void create(
20+
void recordCreate(
2321
cl_command_buffer_khr cmdbuf,
2422
bool isInOrder)
2523
{
2624
queueIsInOrder = isInOrder;
27-
trace << "digraph {\n";
28-
trace << " // " << (queueIsInOrder ? "in-order" : "out-of-order") << " command-buffer\n";
25+
dotstring << "digraph {\n";
26+
dotstring << " // " << (queueIsInOrder ? "in-order" : "out-of-order") << " command-buffer\n";
2927
}
3028

31-
void traceCommand(
29+
void recordCommand(
3230
cl_command_queue queue,
3331
const char* cmd,
3432
const std::string& tag,
3533
cl_uint num_sync_points_in_wait_list,
3634
const cl_sync_point_khr* sync_point_wait_list,
3735
cl_sync_point_khr* sync_point)
3836
{
39-
SCommandBufferTraceId id =
37+
SCommandBufferId id =
4038
sync_point == nullptr ?
4139
makeInternalId() :
4240
makeSyncPointId(*sync_point);
4341

44-
trace << " " << (id.isInternal ? "internal" : "syncpoint") << id.id
42+
dotstring << " " << (id.isInternal ? "internal" : "syncpoint") << id.id
4543
<< " [shape=oval, label=\"" << cmd;
4644
if( !tag.empty() )
4745
{
48-
trace << "( " << tag << " )";
46+
dotstring << "( " << tag << " )";
4947
}
50-
trace << "\"]\n";
48+
dotstring << "\"]\n";
5149

5250
for( cl_uint s = 0; s < num_sync_points_in_wait_list; s++ )
5351
{
54-
trace << " syncpoint" << sync_point_wait_list[s]
52+
dotstring << " syncpoint" << sync_point_wait_list[s]
5553
<< " -> "
5654
<< (id.isInternal ? "internal" : "syncpoint") << id.id
5755
<< " // explicit dependency\n";
5856
}
5957

6058
for( const auto& dep : implicitDeps )
6159
{
62-
trace << " " << (dep.isInternal ? "internal" : "syncpoint") << dep.id
60+
dotstring << " " << (dep.isInternal ? "internal" : "syncpoint") << dep.id
6361
<< " -> "
6462
<< (id.isInternal ? "internal" : "syncpoint") << id.id
6563
<< " [style=dashed] // implicit dependency\n";
@@ -76,20 +74,20 @@ struct SCommandBufferTraceInfo
7674
}
7775
}
7876

79-
void traceBarrier(
77+
void recordBarrier(
8078
cl_command_queue queue,
8179
const char* cmd,
8280
cl_uint num_sync_points_in_wait_list,
8381
const cl_sync_point_khr* sync_point_wait_list,
8482
cl_sync_point_khr* sync_point)
8583
{
86-
SCommandBufferTraceId id =
84+
SCommandBufferId id =
8785
sync_point == nullptr ?
8886
makeInternalId() :
8987
makeSyncPointId(*sync_point);
9088

91-
trace << " " << (id.isInternal ? "internal" : "syncpoint") << id.id
92-
<< " [shape=octagon, label=\"" << cmd << "\"]\n";
89+
dotstring << " " << (id.isInternal ? "internal" : "syncpoint") << id.id
90+
<< " [shape=octagon, label=\"" << cmd << "\"]\n";
9391

9492
// If there is a sync point wait list, then the barrier depends on all
9593
// of the commands in the sync point wait list. Otherwise, the barrier
@@ -98,69 +96,78 @@ struct SCommandBufferTraceInfo
9896
{
9997
for( cl_uint s = 0; s < num_sync_points_in_wait_list; s++ )
10098
{
101-
trace << " syncpoint" << sync_point_wait_list[s]
102-
<< " -> "
103-
<< (id.isInternal ? "internal" : "syncpoint") << id.id
104-
<< " // explicit dependency\n";
99+
dotstring << " syncpoint" << sync_point_wait_list[s]
100+
<< " -> "
101+
<< (id.isInternal ? "internal" : "syncpoint") << id.id
102+
<< " // explicit dependency\n";
105103
}
106104
}
107105
else
108106
{
109107
for( const auto& dep : outstandingIds )
110108
{
111-
trace << " " << (dep.isInternal ? "internal" : "syncpoint") << dep.id
112-
<< " -> "
113-
<< (id.isInternal ? "internal" : "syncpoint") << id.id
114-
<< " [style=dotted] // barrier dependency\n";
109+
dotstring << " " << (dep.isInternal ? "internal" : "syncpoint") << dep.id
110+
<< " -> "
111+
<< (id.isInternal ? "internal" : "syncpoint") << id.id
112+
<< " [style=dotted] // barrier dependency\n";
115113
}
116114
outstandingIds.clear();
117115
}
118116

119117
// Add the implicit dependencies.
120118
for( const auto& dep : implicitDeps )
121119
{
122-
trace << " " << (dep.isInternal ? "internal" : "syncpoint") << dep.id
123-
<< " -> "
124-
<< (id.isInternal ? "internal" : "syncpoint") << id.id
125-
<< " [style=dashed] // implicit dependency\n";
120+
dotstring << " " << (dep.isInternal ? "internal" : "syncpoint") << dep.id
121+
<< " -> "
122+
<< (id.isInternal ? "internal" : "syncpoint") << id.id
123+
<< " [style=dashed] // implicit dependency\n";
126124
}
127125

128126
// Now, the only implicit dependency that remains is this barrier.
129127
implicitDeps.clear();
130128
implicitDeps.push_back(id);
131129
}
132130

133-
void finalize()
131+
void recordFinalize()
134132
{
135-
trace << "}\n";
133+
dotstring << "}\n";
136134
}
137135

138-
private:
139-
struct SCommandBufferTraceId
136+
// Note: this cannot return a reference, because the underlying string is a
137+
// temporary object.
138+
const std::string getRecording() const
139+
{
140+
return dotstring.str();
141+
}
142+
143+
private:
144+
struct SCommandBufferId
140145
{
141146
bool isInternal = false;
142147
uint32_t id = 0;
143148
};
144149

150+
std::ostringstream dotstring;
151+
145152
std::atomic<uint32_t> nextInternalId;
146153

147154
bool queueIsInOrder;
148155

149-
std::vector<SCommandBufferTraceId> implicitDeps;
150-
std::vector<SCommandBufferTraceId> outstandingIds;
156+
std::vector<SCommandBufferId> implicitDeps;
157+
std::vector<SCommandBufferId> outstandingIds;
151158

152-
SCommandBufferTraceId makeInternalId()
159+
SCommandBufferId makeInternalId()
153160
{
154-
SCommandBufferTraceId id;
161+
SCommandBufferId id;
155162
id.isInternal = true;
156163
id.id = nextInternalId.fetch_add(1, std::memory_order_relaxed);
157164
return id;
158165
}
159166

160-
SCommandBufferTraceId makeSyncPointId(
167+
SCommandBufferId makeSyncPointId(
161168
cl_sync_point_khr sync_point)
162169
{
163-
SCommandBufferTraceId id;
170+
SCommandBufferId id;
164171
id.isInternal = false;
165172
id.id = sync_point;
166173
return id;

intercept/src/dispatch.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10469,7 +10469,7 @@ CL_API_ENTRY cl_command_buffer_khr CL_API_CALL clCreateCommandBufferKHR(
1046910469
HOST_PERFORMANCE_TIMING_END();
1047010470
CHECK_ERROR( errcode_ret[0] );
1047110471
ADD_OBJECT_ALLOCATION( retVal );
10472-
TRACE_COMMAND_BUFFER_CREATE( retVal, num_queues, queues );
10472+
RECORD_COMMAND_BUFFER_CREATE( retVal, num_queues, queues );
1047310473
CALL_LOGGING_EXIT( errcode_ret[0], "returned %p", retVal );
1047410474

1047510475
if( retVal != NULL )
@@ -10510,7 +10510,8 @@ CL_API_ENTRY cl_int CL_API_CALL clFinalizeCommandBufferKHR(
1051010510

1051110511
HOST_PERFORMANCE_TIMING_END();
1051210512
CHECK_ERROR( retVal );
10513-
TRACE_COMMAND_BUFFER_FINALIZE( retVal, command_buffer );
10513+
RECORD_COMMAND_BUFFER_FINALIZE( retVal, command_buffer );
10514+
DUMP_COMMAND_BUFFER_RECORDING( retVal, command_buffer );
1051410515
CALL_LOGGING_EXIT( retVal );
1051510516

1051610517
return retVal;
@@ -10717,7 +10718,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandBarrierWithWaitListKHR(
1071710718

1071810719
HOST_PERFORMANCE_TIMING_END();
1071910720
CHECK_ERROR( retVal );
10720-
TRACE_COMMAND_BUFFER_BARRIER(
10721+
RECORD_COMMAND_BUFFER_BARRIER(
1072110722
retVal,
1072210723
command_buffer,
1072310724
num_sync_points_in_wait_list,
@@ -10787,7 +10788,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferKHR(
1078710788

1078810789
HOST_PERFORMANCE_TIMING_END();
1078910790
CHECK_ERROR( retVal );
10790-
TRACE_COMMAND_BUFFER_COMMAND(
10791+
RECORD_COMMAND_BUFFER_COMMAND(
1079110792
retVal,
1079210793
command_buffer,
1079310794
num_sync_points_in_wait_list,
@@ -10865,7 +10866,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferRectKHR(
1086510866

1086610867
HOST_PERFORMANCE_TIMING_END();
1086710868
CHECK_ERROR( retVal );
10868-
TRACE_COMMAND_BUFFER_COMMAND(
10869+
RECORD_COMMAND_BUFFER_COMMAND(
1086910870
retVal,
1087010871
command_buffer,
1087110872
num_sync_points_in_wait_list,
@@ -10935,7 +10936,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferToImageKHR(
1093510936

1093610937
HOST_PERFORMANCE_TIMING_END();
1093710938
CHECK_ERROR( retVal );
10938-
TRACE_COMMAND_BUFFER_COMMAND(
10939+
RECORD_COMMAND_BUFFER_COMMAND(
1093910940
retVal,
1094010941
command_buffer,
1094110942
num_sync_points_in_wait_list,
@@ -11005,7 +11006,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyImageKHR(
1100511006

1100611007
HOST_PERFORMANCE_TIMING_END();
1100711008
CHECK_ERROR( retVal );
11008-
TRACE_COMMAND_BUFFER_COMMAND(
11009+
RECORD_COMMAND_BUFFER_COMMAND(
1100911010
retVal,
1101011011
command_buffer,
1101111012
num_sync_points_in_wait_list,
@@ -11077,7 +11078,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyImageToBufferKHR(
1107711078

1107811079
HOST_PERFORMANCE_TIMING_END();
1107911080
CHECK_ERROR( retVal );
11080-
TRACE_COMMAND_BUFFER_COMMAND(
11081+
RECORD_COMMAND_BUFFER_COMMAND(
1108111082
retVal,
1108211083
command_buffer,
1108311084
num_sync_points_in_wait_list,
@@ -11148,7 +11149,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandFillBufferKHR(
1114811149

1114911150
HOST_PERFORMANCE_TIMING_END();
1115011151
CHECK_ERROR( retVal );
11151-
TRACE_COMMAND_BUFFER_COMMAND(
11152+
RECORD_COMMAND_BUFFER_COMMAND(
1115211153
retVal,
1115311154
command_buffer,
1115411155
num_sync_points_in_wait_list,
@@ -11217,7 +11218,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandFillImageKHR(
1121711218

1121811219
HOST_PERFORMANCE_TIMING_END();
1121911220
CHECK_ERROR( retVal );
11220-
TRACE_COMMAND_BUFFER_COMMAND(
11221+
RECORD_COMMAND_BUFFER_COMMAND(
1122111222
retVal,
1122211223
command_buffer,
1122311224
num_sync_points_in_wait_list,
@@ -11286,7 +11287,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandSVMMemcpyKHR(
1128611287

1128711288
HOST_PERFORMANCE_TIMING_END();
1128811289
CHECK_ERROR( retVal );
11289-
TRACE_COMMAND_BUFFER_COMMAND(
11290+
RECORD_COMMAND_BUFFER_COMMAND(
1129011291
retVal,
1129111292
command_buffer,
1129211293
num_sync_points_in_wait_list,
@@ -11357,7 +11358,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandSVMMemFillKHR(
1135711358

1135811359
HOST_PERFORMANCE_TIMING_END();
1135911360
CHECK_ERROR( retVal );
11360-
TRACE_COMMAND_BUFFER_COMMAND(
11361+
RECORD_COMMAND_BUFFER_COMMAND(
1136111362
retVal,
1136211363
command_buffer,
1136311364
num_sync_points_in_wait_list,
@@ -11449,7 +11450,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandNDRangeKernelKHR(
1144911450

1145011451
HOST_PERFORMANCE_TIMING_END();
1145111452
CHECK_ERROR( retVal );
11452-
TRACE_COMMAND_BUFFER_COMMAND_WITH_TAG(
11453+
RECORD_COMMAND_BUFFER_COMMAND_WITH_TAG(
1145311454
retVal,
1145411455
command_buffer,
1145511456
num_sync_points_in_wait_list,

0 commit comments

Comments
 (0)