(save_data_dir, runtime)
| 529 | # ---------------------------------------------------------------------------- # |
| 530 | |
| 531 | def SaveOutputsOneByOne(save_data_dir, runtime): |
| 532 | for i in range(runtime.GetOutputCount()): |
| 533 | tensor = runtime.GetOutputTensor(i) |
| 534 | out_file_name = save_data_dir + "/pplnn_output-" + tensor.GetName() + ".dat" |
| 535 | shape = tensor.GetShape() |
| 536 | dims = shape.GetDims() |
| 537 | element_count = CalcElementCount(dims) |
| 538 | if element_count > 0: |
| 539 | dst_data_type = shape.GetDataType() |
| 540 | if dst_data_type == pplcommon.DATATYPE_FLOAT16: # convert fp16 to fp32 when saving to file |
| 541 | dst_data_type = pplcommon.DATATYPE_FLOAT32 |
| 542 | tensor_data = tensor.ConvertToHost(dst_data_type) |
| 543 | if not tensor_data: |
| 544 | logging.error("copy data from tensor[" + tensor.GetName() + "] failed.") |
| 545 | sys.exit(-1) |
| 546 | |
| 547 | out_data = np.array(tensor_data, copy=False) |
| 548 | out_data.tofile(out_file_name) |
| 549 | else: |
| 550 | open(out_file_name, 'a').close() |
| 551 | |
| 552 | # ---------------------------------------------------------------------------- # |
| 553 |
no test coverage detected