• Home
  • Raw
  • Download

Lines Matching full:cache

10 #include <xnnpack/cache.h>
14 static void* cache_end(const xnn_code_cache* cache) { in cache_end() argument
15 …urn reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(cache->cache.code.start) + cache->cache.c… in cache_end()
18 static void write_code(xnn_code_cache* cache, const std::string& str) { in write_code() argument
19 ASSERT_GE(cache->cache.code.capacity - cache->cache.code.size, str.length()); in write_code()
20 std::memcpy(cache_end(cache), str.data(), str.length()); in write_code()
21 cache->cache.code.size += str.length(); in write_code()
27 xnn_code_cache cache; in TEST() local
28 EXPECT_EQ(xnn_status_success, xnn_init_code_cache(&cache)); in TEST()
29 EXPECT_EQ(xnn_status_success, xnn_release_code_cache(&cache)); in TEST()
41 xnn_code_cache cache; in TEST() local
42 EXPECT_EQ(xnn_status_success, xnn_init_code_cache(&cache)); in TEST()
44 write_code(&cache, "1234"); in TEST()
45 ASSERT_EQ(0, xnn_get_or_insert_code_cache(&cache, cache.cache.code.start, 4)); in TEST()
46 ASSERT_EQ(0, cache.cache.hits); in TEST()
47 ASSERT_EQ(1, cache.cache.misses); in TEST()
49 void* span2_code = cache_end(&cache); in TEST()
50 // Simulate a cache hit. in TEST()
51 write_code(&cache, "1234"); in TEST()
52 ASSERT_EQ(0, xnn_get_or_insert_code_cache(&cache, span2_code, 4)); in TEST()
53 ASSERT_EQ(1, cache.cache.hits); in TEST()
54 ASSERT_EQ(1, cache.cache.misses); in TEST()
56 void* span3_code = cache_end(&cache); in TEST()
57 // Simulate a cache miss. in TEST()
58 write_code(&cache, "5678"); in TEST()
59 ASSERT_EQ(4, xnn_get_or_insert_code_cache(&cache, span3_code, 4)); in TEST()
60 ASSERT_EQ(1, cache.cache.hits); in TEST()
61 ASSERT_EQ(2, cache.cache.misses); in TEST()
62 ASSERT_EQ(2, cache.cache.num_entries); in TEST()
64 EXPECT_EQ(xnn_status_success, xnn_release_code_cache(&cache)); in TEST()
69 xnn_code_cache cache; in TEST() local
70 EXPECT_EQ(xnn_status_success, xnn_init_code_cache(&cache)); in TEST()
71 size_t old_num_buckets = cache.cache.num_buckets; in TEST()
73 // Add many entries to force cache to grow. in TEST()
75 // write_code will update cache size, so get the code offset first. in TEST()
76 void* code_ptr = cache_end(&cache); in TEST()
77 write_code(&cache, s); in TEST()
78 ASSERT_EQ(expected_offset, xnn_get_or_insert_code_cache(&cache, code_ptr, s.length())); in TEST()
82 ASSERT_EQ(0, cache.cache.hits); in TEST()
83 ASSERT_EQ(old_num_buckets, cache.cache.num_entries); in TEST()
84 // Check that cache has grown. in TEST()
85 ASSERT_LT(old_num_buckets, cache.cache.num_buckets); in TEST()
86 // Check that all the entries are still in cache. in TEST()
89 // write_code will update cache size, so get the code offset first. in TEST()
90 void* code_ptr = cache_end(&cache); in TEST()
91 write_code(&cache, s); in TEST()
92 ASSERT_EQ(expected_offset, xnn_get_or_insert_code_cache(&cache, code_ptr, s.length())); in TEST()
95 // And now all of the lookups should be cache hits. in TEST()
96 ASSERT_EQ(old_num_buckets, cache.cache.hits); in TEST()
98 EXPECT_EQ(xnn_status_success, xnn_release_code_cache(&cache)); in TEST()