* Given a reference to an INetwork and a target directory, serialize the network to a file * called " _network.armnn" * * @param network The network to serialize. * @param dumpDir The target directory. * @return the full path to the serialized file. */
| 23 | * @return the full path to the serialized file. |
| 24 | */ |
| 25 | std::string SerializeNetwork(const armnn::INetwork& network, const std::string& dumpDir) |
| 26 | { |
| 27 | if (dumpDir.empty()) |
| 28 | { |
| 29 | throw InvalidArgumentException("An output directory must be specified."); |
| 30 | } |
| 31 | fs::path outputDirectory(dumpDir); |
| 32 | if (!exists(outputDirectory)) |
| 33 | { |
| 34 | throw InvalidArgumentException( |
| 35 | fmt::format("The specified directory does not exist: {}", outputDirectory.c_str())); |
| 36 | } |
| 37 | auto serializer(armnnSerializer::ISerializer::Create()); |
| 38 | // Serialize the Network |
| 39 | serializer->Serialize(network); |
| 40 | |
| 41 | fs::path fileName; |
| 42 | fileName += dumpDir; |
| 43 | // used to get a timestamp to name diagnostic files (the ArmNN serialized graph |
| 44 | // and getSupportedOperations.txt files) |
| 45 | timespec ts; |
| 46 | if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts) == 0) |
| 47 | { |
| 48 | std::stringstream ss; |
| 49 | ss << std::to_string(ts.tv_sec) << "_" << std::to_string(ts.tv_nsec) << "_network.armnn"; |
| 50 | fileName += ss.str(); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | // This is incredibly unlikely but just in case. |
| 55 | throw RuntimeException("clock_gettime, CLOCK_MONOTONIC_RAW returned a non zero result."); |
| 56 | } |
| 57 | |
| 58 | // Save serialized network to a file |
| 59 | std::ofstream serializedFile(fileName, std::ios::out | std::ios::binary); |
| 60 | auto serialized = serializer->SaveSerializedToStream(serializedFile); |
| 61 | if (!serialized) |
| 62 | { |
| 63 | throw RuntimeException(fmt::format("An error occurred when serializing to file %s", fileName.c_str())); |
| 64 | } |
| 65 | serializedFile.flush(); |
| 66 | serializedFile.close(); |
| 67 | return fileName; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Given a reference to an optimized network and a target directory, serialize the network in .dot file format to |
no test coverage detected