15
15
16
16
#include " common.h"
17
17
18
- struct SCommandBufferTraceInfo
18
+ struct SCommandBufferRecord
19
19
{
20
- std::ostringstream trace;
21
-
22
- void create (
20
+ void recordCreate (
23
21
cl_command_buffer_khr cmdbuf,
24
22
bool isInOrder)
25
23
{
26
24
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 " ;
29
27
}
30
28
31
- void traceCommand (
29
+ void recordCommand (
32
30
cl_command_queue queue,
33
31
const char * cmd,
34
32
const std::string& tag,
35
33
cl_uint num_sync_points_in_wait_list,
36
34
const cl_sync_point_khr* sync_point_wait_list,
37
35
cl_sync_point_khr* sync_point)
38
36
{
39
- SCommandBufferTraceId id =
37
+ SCommandBufferId id =
40
38
sync_point == nullptr ?
41
39
makeInternalId () :
42
40
makeSyncPointId (*sync_point);
43
41
44
- trace << " " << (id.isInternal ? " internal" : " syncpoint" ) << id.id
42
+ dotstring << " " << (id.isInternal ? " internal" : " syncpoint" ) << id.id
45
43
<< " [shape=oval, label=\" " << cmd;
46
44
if ( !tag.empty () )
47
45
{
48
- trace << " ( " << tag << " )" ;
46
+ dotstring << " ( " << tag << " )" ;
49
47
}
50
- trace << " \" ]\n " ;
48
+ dotstring << " \" ]\n " ;
51
49
52
50
for ( cl_uint s = 0 ; s < num_sync_points_in_wait_list; s++ )
53
51
{
54
- trace << " syncpoint" << sync_point_wait_list[s]
52
+ dotstring << " syncpoint" << sync_point_wait_list[s]
55
53
<< " -> "
56
54
<< (id.isInternal ? " internal" : " syncpoint" ) << id.id
57
55
<< " // explicit dependency\n " ;
58
56
}
59
57
60
58
for ( const auto & dep : implicitDeps )
61
59
{
62
- trace << " " << (dep.isInternal ? " internal" : " syncpoint" ) << dep.id
60
+ dotstring << " " << (dep.isInternal ? " internal" : " syncpoint" ) << dep.id
63
61
<< " -> "
64
62
<< (id.isInternal ? " internal" : " syncpoint" ) << id.id
65
63
<< " [style=dashed] // implicit dependency\n " ;
@@ -76,20 +74,20 @@ struct SCommandBufferTraceInfo
76
74
}
77
75
}
78
76
79
- void traceBarrier (
77
+ void recordBarrier (
80
78
cl_command_queue queue,
81
79
const char * cmd,
82
80
cl_uint num_sync_points_in_wait_list,
83
81
const cl_sync_point_khr* sync_point_wait_list,
84
82
cl_sync_point_khr* sync_point)
85
83
{
86
- SCommandBufferTraceId id =
84
+ SCommandBufferId id =
87
85
sync_point == nullptr ?
88
86
makeInternalId () :
89
87
makeSyncPointId (*sync_point);
90
88
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 " ;
93
91
94
92
// If there is a sync point wait list, then the barrier depends on all
95
93
// of the commands in the sync point wait list. Otherwise, the barrier
@@ -98,69 +96,78 @@ struct SCommandBufferTraceInfo
98
96
{
99
97
for ( cl_uint s = 0 ; s < num_sync_points_in_wait_list; s++ )
100
98
{
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 " ;
105
103
}
106
104
}
107
105
else
108
106
{
109
107
for ( const auto & dep : outstandingIds )
110
108
{
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 " ;
115
113
}
116
114
outstandingIds.clear ();
117
115
}
118
116
119
117
// Add the implicit dependencies.
120
118
for ( const auto & dep : implicitDeps )
121
119
{
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 " ;
126
124
}
127
125
128
126
// Now, the only implicit dependency that remains is this barrier.
129
127
implicitDeps.clear ();
130
128
implicitDeps.push_back (id);
131
129
}
132
130
133
- void finalize ()
131
+ void recordFinalize ()
134
132
{
135
- trace << " }\n " ;
133
+ dotstring << " }\n " ;
136
134
}
137
135
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
140
145
{
141
146
bool isInternal = false ;
142
147
uint32_t id = 0 ;
143
148
};
144
149
150
+ std::ostringstream dotstring;
151
+
145
152
std::atomic<uint32_t > nextInternalId;
146
153
147
154
bool queueIsInOrder;
148
155
149
- std::vector<SCommandBufferTraceId > implicitDeps;
150
- std::vector<SCommandBufferTraceId > outstandingIds;
156
+ std::vector<SCommandBufferId > implicitDeps;
157
+ std::vector<SCommandBufferId > outstandingIds;
151
158
152
- SCommandBufferTraceId makeInternalId ()
159
+ SCommandBufferId makeInternalId ()
153
160
{
154
- SCommandBufferTraceId id;
161
+ SCommandBufferId id;
155
162
id.isInternal = true ;
156
163
id.id = nextInternalId.fetch_add (1 , std::memory_order_relaxed);
157
164
return id;
158
165
}
159
166
160
- SCommandBufferTraceId makeSyncPointId (
167
+ SCommandBufferId makeSyncPointId (
161
168
cl_sync_point_khr sync_point)
162
169
{
163
- SCommandBufferTraceId id;
170
+ SCommandBufferId id;
164
171
id.isInternal = false ;
165
172
id.id = sync_point;
166
173
return id;
0 commit comments