| 64 | } |
| 65 | |
| 66 | void ClWorkloadFactory::AfterWorkloadsCreated() |
| 67 | { |
| 68 | if(m_ModelContextPtr) |
| 69 | { |
| 70 | auto modelOptions = dynamic_cast<ClBackendModelContext*>(m_ModelContextPtr.get()); |
| 71 | if (modelOptions->SaveCachedNetwork()) |
| 72 | { |
| 73 | ClContextSerializer serializer; |
| 74 | serializer.Serialize(m_CLCompileContext); |
| 75 | auto cachedFd = modelOptions->GetCachedFileDescriptor(); |
| 76 | if (cachedFd != -1) |
| 77 | { |
| 78 | std::vector<uint8_t> compiledContextData; |
| 79 | std::stringstream stream; |
| 80 | bool serialized = serializer.SaveSerializedToStream(stream); |
| 81 | if (serialized) |
| 82 | { |
| 83 | std::string const serializedString{stream.str()}; |
| 84 | std::copy(serializedString.begin(), |
| 85 | serializedString.end(), |
| 86 | std::back_inserter(compiledContextData)); |
| 87 | auto success = write(cachedFd, compiledContextData.data(), compiledContextData.size()); |
| 88 | if (success == -1) |
| 89 | { |
| 90 | ARMNN_LOG(info) << "ClWorkloadFactory:: Could not cache the compiled context!"; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // Save map to a filepath provided in ModelOptions |
| 96 | auto filePath = modelOptions->GetCachedNetworkFilePath(); |
| 97 | if (filePath != "" && fs::exists(filePath) && fs::is_regular_file(filePath)) |
| 98 | { |
| 99 | // Serialize ClContext to the file specified |
| 100 | std::ofstream file(filePath, std::ios::out | std::ios::binary); |
| 101 | serializer.SaveSerializedToStream(file); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | template <typename FloatWorkload, typename Uint8Workload, typename QueueDescriptorType, typename... Args> |
| 108 | std::unique_ptr<IWorkload> ClWorkloadFactory::MakeWorkload(const QueueDescriptorType& descriptor, |
no test coverage detected