| 84 | } |
| 85 | |
| 86 | Status ProgramCache::AddSerializedCache( |
| 87 | const CLContext& context, const CLDevice& device, |
| 88 | absl::Span<const uint8_t> serialized_cache) { |
| 89 | flatbuffers::Verifier verifier(serialized_cache.data(), |
| 90 | serialized_cache.size()); |
| 91 | if (!data::VerifyCompiledCacheBuffer(verifier)) { |
| 92 | return InvalidArgumentError("Serialized model is corrupted."); |
| 93 | } |
| 94 | |
| 95 | auto model = data::GetCompiledCache(serialized_cache.data()); |
| 96 | std::string platform_version(model->driver_version()->c_str(), |
| 97 | model->driver_version()->size()); |
| 98 | |
| 99 | if (device.GetPlatformVersion() != platform_version) { |
| 100 | return InvalidArgumentError( |
| 101 | "OpenCL driver changed, cache invalid, should be regenerated"); |
| 102 | } |
| 103 | |
| 104 | use_fingerprints_ = true; |
| 105 | |
| 106 | for (auto serialized_program : *model->programs()) { |
| 107 | ProgramDescriptor desc(serialized_program->fingerprint()); |
| 108 | CLProgram program; |
| 109 | RETURN_IF_ERROR(CreateCLProgramFromBinary( |
| 110 | context, device, |
| 111 | absl::MakeSpan(serialized_program->binary()->data(), |
| 112 | serialized_program->binary()->size()), |
| 113 | &program)); |
| 114 | auto it = programs_.find(desc); |
| 115 | if (it == programs_.end()) { |
| 116 | programs_.insert(std::make_pair(std::move(desc), std::move(program))); |
| 117 | } |
| 118 | } |
| 119 | return OkStatus(); |
| 120 | } |
| 121 | |
| 122 | Status ProgramCache::GetSerializedCache( |
| 123 | const CLDevice& device, std::vector<uint8_t>* serialized_cache) const { |
no test coverage detected