1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
7 #include "mkldnn_graph.h"
10 #include <unordered_map>
13 #include <cpp_interfaces/impl/ie_plugin_internal.hpp>
15 namespace MKLDNNPlugin {
17 class SimpleDataHash {
20 for (int i = 0; i < kTableSize; i++) {
22 for (int j = 0; j < 8; j++)
23 c = ((c & 1) ? 0xc96c5795d7870f42 : 0) ^ (c >> 1);
27 // Computes 64-bit "cyclic redundancy check" sum, as specified in ECMA-182
28 uint64_t hash(const unsigned char* data, size_t size) const {
30 for (size_t idx = 0; idx < size; idx++)
31 crc = table[(unsigned char)crc ^ data[idx]] ^ (crc >> 8);
37 static const int kTableSize = 256;
38 uint64_t table[kTableSize];
41 class MKLDNNWeightsSharing {
43 MKLDNNMemoryPtr findOrCreate(const std::string& name_hash,
44 std::function<MKLDNNMemoryPtr(void)> create) {
45 std::unique_lock<std::mutex> lock(guard);
46 auto found = sharedWeights.find(name_hash);
49 if (found == sharedWeights.end() || !(ptr = found->second.lock())) {
51 sharedWeights[name_hash] = ptr;
55 static const SimpleDataHash& GetHashFunc () { return simpleCRC; }
58 std::unordered_map<std::string, std::weak_ptr<MKLDNNMemory>> sharedWeights;
60 static const SimpleDataHash simpleCRC;
63 class Engine : public InferenceEngine::InferencePluginInternal {
66 ~Engine() override = default;
68 InferenceEngine::ExecutableNetworkInternal::Ptr
69 LoadExeNetworkImpl(InferenceEngine::ICNNNetwork &network,
70 const std::map<std::string, std::string> &config) override;
72 void AddExtension(InferenceEngine::IExtensionPtr extension) override;
77 void SetConfig(const std::map<std::string, std::string> &config) override;
80 * @deprecated Use the version with config parameter
82 void QueryNetwork(const InferenceEngine::ICNNNetwork& network, InferenceEngine::QueryNetworkResult& res) const override;
83 void QueryNetwork(const InferenceEngine::ICNNNetwork& network,
84 const std::map<std::string, std::string>& config, InferenceEngine::QueryNetworkResult& res) const override;
86 static MKLDNNWeightsSharing& GetWeightsSharing() { return weightsSharing; }
90 MKLDNNExtensionManager::Ptr extensionManager = std::make_shared<MKLDNNExtensionManager>();
93 static MKLDNNWeightsSharing weightsSharing;
96 } // namespace MKLDNNPlugin