TaoLv commented on a change in pull request #12746: Add env flag to disable
MKLDNN cache (MXNET_MKLDNN_CACHE_ENABLED)
URL: https://github.com/apache/incubator-mxnet/pull/12746#discussion_r225399427
##########
File path: src/operator/nn/mkldnn/mkldnn_base-inl.h
##########
@@ -147,6 +147,23 @@ static inline bool MKLDNNEnvSet() {
return is_mkldnn_enabled;
}
+static inline int GetMKLDNNCacheSize() {
+ static int mkldnn_cache_size = dmlc::GetEnv("MXNET_MKLDNN_CACHE_SIZE", -1);
+ return mkldnn_cache_size;
+}
+
+// TODO(alex): (MXNET-1075) Will remove env variable and calculate cache size
during runtime
+template<typename S, typename I, typename H>
+static typename std::unordered_map<S, I, H>::iterator AddToCache(
+ std::unordered_map<S, I, H>* cache, const S &key, const I &item) {
+ int mkldnn_cache_size = GetMKLDNNCacheSize();
+ if (mkldnn_cache_size != -1 && static_cast<int>(cache.size()) >
mkldnn_cache_size)
+ cache->erase(cache.begin());
Review comment:
This is a little crude to me. Can we have a LRU algorithm here?
https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services