MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ParseBufferAssignment

Function ParseBufferAssignment

tensorflow/compiler/xla/tools/driver.cc:276–323  ·  view source on GitHub ↗

Parse and populate the buffer table; Example of input: BufferAssignment: allocation 0: 0x27017c46b600, size 32768, parameter 0, shape f32[256,32] at ShapeIndex {}: value: <3 parameter @0> (size=32768,offset=0): f32[256,32]{1,0} allocation 1: 0x27017c46b6b0, size 128, output shape is f32[32], maybe-live-out: value: <5 reduce @0> (size=128,offset=0): f32[32]{0} allocation 2: 0x27017c46b760, size 4

Source from the content-addressed store, hash-verified

274// allocation 5: 0x27017c46b970, size 4, output shape is f32[], thread-local:
275// value: <2 add.1 @0> (size=4,offset=0): f32[]
276BufferAssignment ParseBufferAssignment(const std::string& fname) {
277 BufferAssignment assignment;
278 std::ifstream infile(fname);
279 std::string line;
280 while (std::getline(infile, line)) {
281 std::regex allocation_line_r(
282 "allocation ([0-9]+): .+, size ([0-9]+), (.+)");
283 std::smatch match;
284 if (std::regex_search(line, match, allocation_line_r)) {
285 Log("Matched allocation description: " + line);
286 int allocation_idx = std::stoi(match[1]);
287 int size = std::stoi(match[2]);
288 Log("Allocation size = " + std::to_string(size));
289 const std::string& postfix = match[3];
290 Check(allocation_idx == assignment.buffers_size.size(),
291 "Unordered allocations in input");
292 assignment.buffers_size.push_back(size);
293
294 std::regex output_r("output shape is \\|([^\\|]+)\\|,");
295 std::smatch output_match;
296 if (std::regex_search(postfix, output_match, output_r)) {
297 Log("Matched out parameter: " + postfix);
298 Check(assignment.output_idx == -1, "Multiple out-parameters");
299 assignment.output_idx = allocation_idx;
300 std::string output_shape = output_match[1];
301 Log("output shape = " + output_shape);
302 TupleShape shape = TupleShapeFromString(output_shape);
303 assignment.buffers_shape[allocation_idx] = shape;
304 Log("parsed output shape = " + TupleShapeToString(shape));
305 }
306
307 std::regex parameter_r("parameter ([0-9]+), shape \\|([^\\|]+)\\|");
308 std::smatch param_match;
309 if (std::regex_search(postfix, param_match, parameter_r)) {
310 Log("Matched parameter description: " + postfix);
311 int param_idx = std::stoi(param_match[1]);
312 assignment.param_to_alloc_idx[param_idx] = allocation_idx;
313 std::string param_shape = param_match[2];
314 TupleShape shape = TupleShapeFromString(param_shape);
315 assignment.buffers_shape[allocation_idx] = shape;
316 Log("parsed parameter shape for param " + std::to_string(param_idx) +
317 " = " + TupleShapeToString(shape));
318 }
319 }
320 }
321 Check(assignment.output_idx != -1, "Output not set");
322 return assignment;
323}
324
325int GetNumElements(const ArrayShape& shape) {
326 int num_elements = 1;

Callers 1

mainFunction · 0.85

Calls 7

to_stringFunction · 0.85
TupleShapeFromStringFunction · 0.85
TupleShapeToStringFunction · 0.85
LogFunction · 0.70
CheckFunction · 0.70
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected