开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 3

xiongying/Halide

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1093)
标签 (17)
main
xtensa-codegen
vksnk/dma-limit-channels
rootjalex/trs-codegen-cross
abadams/fix_7374
abadams/remove_hack_from_gpu_only_aottest
srj/gpu-cache
srj/generator_aot_gpu_multi_context_threaded
srj/xtensa-merge
abadams/vector_scan
abadams/fix_7365
darya-ver/ir-viz
vulkan-phase2-runtime
srj/param-map-deprecation
srj/rt-return-types
srj/main-vs2022
release/15.x
srj/param-map
abadams/ir_builder_unique_ptr
vksnk/restrict
v14.0.0
v13.0.4
v13.0.3
v13.0.2
v13.0.1
v13.0.0
v12.0.1
v12.0.0
v11.0.1
v11.0.0
v10.0.1
v10.0.0
release_2019_08_27
release_8.0.0
v8.0.0
release_2018_02_15
release_2013_11_11
main
分支 (1093)
标签 (17)
main
xtensa-codegen
vksnk/dma-limit-channels
rootjalex/trs-codegen-cross
abadams/fix_7374
abadams/remove_hack_from_gpu_only_aottest
srj/gpu-cache
srj/generator_aot_gpu_multi_context_threaded
srj/xtensa-merge
abadams/vector_scan
abadams/fix_7365
darya-ver/ir-viz
vulkan-phase2-runtime
srj/param-map-deprecation
srj/rt-return-types
srj/main-vs2022
release/15.x
srj/param-map
abadams/ir_builder_unique_ptr
vksnk/restrict
v14.0.0
v13.0.4
v13.0.3
v13.0.2
v13.0.1
v13.0.0
v12.0.1
v12.0.0
v11.0.1
v11.0.0
v10.0.1
v10.0.0
release_2019_08_27
release_8.0.0
v8.0.0
release_2018_02_15
release_2013_11_11
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1093)
标签 (17)
main
xtensa-codegen
vksnk/dma-limit-channels
rootjalex/trs-codegen-cross
abadams/fix_7374
abadams/remove_hack_from_gpu_only_aottest
srj/gpu-cache
srj/generator_aot_gpu_multi_context_threaded
srj/xtensa-merge
abadams/vector_scan
abadams/fix_7365
darya-ver/ir-viz
vulkan-phase2-runtime
srj/param-map-deprecation
srj/rt-return-types
srj/main-vs2022
release/15.x
srj/param-map
abadams/ir_builder_unique_ptr
vksnk/restrict
v14.0.0
v13.0.4
v13.0.3
v13.0.2
v13.0.1
v13.0.0
v12.0.1
v12.0.0
v11.0.1
v11.0.0
v10.0.1
v10.0.0
release_2019_08_27
release_8.0.0
v8.0.0
release_2018_02_15
release_2013_11_11
Halide
/
src
/
runtime
/
cache.cpp
Halide
/
src
/
runtime
/
cache.cpp
cache.cpp 20.68 KB
一键复制 编辑 原始数据 按行查看 历史
Steven Johnson 提交于 2022年12月12日 02:05 +08:00 . Tighten alignment promises for halide_malloc() (#7222)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
#include "HalideRuntime.h"
#include "device_buffer_utils.h"
#include "printer.h"
#include "scoped_mutex_lock.h"
namespace Halide {
namespace Runtime {
namespace Internal {
#define CACHE_DEBUGGING 0
#if CACHE_DEBUGGING
WEAK void debug_print_buffer(void *user_context, const char *buf_name, const halide_buffer_t &buf) {
debug(user_context) << buf_name << ": elem_size " << buf.type.bytes() << " dimensions " << buf.dimensions << ", ";
for (int i = 0; i < buf.dimensions; i++) {
debug(user_context) << "(" << buf.dim[i].min
<< ", " << buf.dim[i].extent
<< ", " << buf.dim[i].stride << ") ";
}
debug(user_context) << "\n";
}
WEAK char to_hex_char(int val) {
if (val < 10) {
return '0' + val;
}
return 'A' + (val - 10);
}
WEAK void debug_print_key(void *user_context, const char *msg, const uint8_t *cache_key, int32_t key_size) {
debug(user_context) << "Key for " << msg << "\n";
char buf[1024];
bool append_ellipses = false;
if ((size_t)key_size > (sizeof(buf) / 2) - 1) { // Each byte in key can take two bytes in output
append_ellipses = true;
key_size = (sizeof(buf) / 2) - 4; // room for NUL and "..."
}
char *buf_ptr = buf;
for (int i = 0; i < key_size; i++) {
if (cache_key[i] >= 32 && cache_key[i] <= '~') {
*buf_ptr++ = cache_key[i];
} else {
*buf_ptr++ = to_hex_char((cache_key[i] >> 4));
*buf_ptr++ = to_hex_char((cache_key[i] & 0xf));
}
}
if (append_ellipses) {
*buf_ptr++ = '.';
*buf_ptr++ = '.';
*buf_ptr++ = '.';
}
*buf_ptr++ = '0円';
debug(user_context) << buf << "\n";
}
#endif
WEAK bool keys_equal(const uint8_t *key1, const uint8_t *key2, size_t key_size) {
return memcmp(key1, key2, key_size) == 0;
}
WEAK bool buffer_has_shape(const halide_buffer_t *buf, const halide_dimension_t *shape) {
for (int i = 0; i < buf->dimensions; i++) {
if (buf->dim[i] != shape[i]) {
return false;
}
}
return true;
}
struct CacheEntry {
CacheEntry *next;
CacheEntry *more_recent;
CacheEntry *less_recent;
uint8_t *metadata_storage;
size_t key_size;
uint8_t *key;
uint32_t hash;
uint32_t in_use_count; // 0 if none returned from halide_cache_lookup
uint32_t tuple_count;
// The shape of the computed data. There may be more data allocated than this.
int32_t dimensions;
halide_dimension_t *computed_bounds;
// The actual stored data.
halide_buffer_t *buf;
uint64_t eviction_key;
bool has_eviction_key;
bool init(const uint8_t *cache_key, size_t cache_key_size,
uint32_t key_hash,
const halide_buffer_t *computed_bounds_buf,
int32_t tuples, halide_buffer_t **tuple_buffers,
bool has_eviction_key, uint64_t eviction_key);
void destroy();
halide_buffer_t &buffer(int32_t i);
};
struct CacheBlockHeader {
CacheEntry *entry;
uint32_t hash;
};
// Each host block has extra space to store a header just before the
// contents. This block must respect the same alignment as
// halide_malloc, because it offsets the return value from
// halide_malloc. The header holds the cache key hash and pointer to
// the hash entry.
WEAK __attribute((always_inline)) size_t header_bytes() {
size_t s = sizeof(CacheBlockHeader);
size_t mask = ::halide_internal_malloc_alignment() - 1;
return (s + mask) & ~mask;
}
WEAK CacheBlockHeader *get_pointer_to_header(uint8_t *host) {
return (CacheBlockHeader *)(host - header_bytes());
}
WEAK bool CacheEntry::init(const uint8_t *cache_key, size_t cache_key_size,
uint32_t key_hash, const halide_buffer_t *computed_bounds_buf,
int32_t tuples, halide_buffer_t **tuple_buffers,
bool has_eviction_key_arg, uint64_t eviction_key_arg) {
next = nullptr;
more_recent = nullptr;
less_recent = nullptr;
key_size = cache_key_size;
hash = key_hash;
in_use_count = 0;
tuple_count = tuples;
dimensions = computed_bounds_buf->dimensions;
// Allocate all the necessary space (or die)
size_t storage_bytes = 0;
// First storage for the tuple halide_buffer_t's
storage_bytes += sizeof(halide_buffer_t) * tuple_count;
// Then storage for the computed shape, and the allocated shape for
// each tuple buffer. These may all be distinct.
size_t shape_offset = storage_bytes;
storage_bytes += sizeof(halide_dimension_t) * dimensions * (tuple_count + 1);
// Then storage for the key
size_t key_offset = storage_bytes;
storage_bytes += key_size;
// Do the single malloc call
metadata_storage = (uint8_t *)halide_malloc(nullptr, storage_bytes);
if (!metadata_storage) {
return false;
}
// Set up the pointers into the allocated metadata space
buf = (halide_buffer_t *)metadata_storage;
computed_bounds = (halide_dimension_t *)(metadata_storage + shape_offset);
key = metadata_storage + key_offset;
// Copy over the key
for (size_t i = 0; i < key_size; i++) {
key[i] = cache_key[i];
}
// Copy over the shape of the computed region
for (int i = 0; i < dimensions; i++) {
computed_bounds[i] = computed_bounds_buf->dim[i];
}
// Copy over the tuple buffers and the shapes of the allocated regions
for (uint32_t i = 0; i < tuple_count; i++) {
buf[i] = *tuple_buffers[i];
buf[i].dim = computed_bounds + (i + 1) * dimensions;
for (int j = 0; j < dimensions; j++) {
buf[i].dim[j] = tuple_buffers[i]->dim[j];
}
}
has_eviction_key = has_eviction_key_arg;
eviction_key = eviction_key_arg;
return true;
}
WEAK void CacheEntry::destroy() {
for (uint32_t i = 0; i < tuple_count; i++) {
if (halide_device_free(nullptr, &buf[i]) != 0) {
// Just log a debug message, there's not much we can do in response here
debug(nullptr) << "CacheEntry::destroy: halide_device_free failed\n";
}
halide_free(nullptr, get_pointer_to_header(buf[i].host));
}
halide_free(nullptr, metadata_storage);
}
WEAK uint32_t djb_hash(const uint8_t *key, size_t key_size) {
uint32_t h = 5381;
for (size_t i = 0; i < key_size; i++) {
h = (h << 5) + h + key[i];
}
return h;
}
WEAK halide_mutex memoization_lock = {{0}};
const size_t kHashTableSize = 256;
WEAK CacheEntry *cache_entries[kHashTableSize];
WEAK CacheEntry *most_recently_used = nullptr;
WEAK CacheEntry *least_recently_used = nullptr;
const uint64_t kDefaultCacheSize = 1 << 20;
WEAK int64_t max_cache_size = kDefaultCacheSize;
WEAK int64_t current_cache_size = 0;
#if CACHE_DEBUGGING
WEAK void validate_cache() {
print(nullptr) << "validating cache, "
<< "current size " << current_cache_size
<< " of maximum " << max_cache_size << "\n";
int entries_in_hash_table = 0;
for (size_t i = 0; i < kHashTableSize; i++) {
CacheEntry *entry = cache_entries[i];
while (entry != nullptr) {
entries_in_hash_table++;
if (entry->more_recent == nullptr && entry != most_recently_used) {
halide_print(nullptr, "cache invalid case 1\n");
__builtin_trap();
}
if (entry->less_recent == nullptr && entry != least_recently_used) {
halide_print(nullptr, "cache invalid case 2\n");
__builtin_trap();
}
entry = entry->next;
}
}
int entries_from_mru = 0;
CacheEntry *mru_chain = most_recently_used;
while (mru_chain != nullptr) {
entries_from_mru++;
mru_chain = mru_chain->less_recent;
}
int entries_from_lru = 0;
CacheEntry *lru_chain = least_recently_used;
while (lru_chain != nullptr) {
entries_from_lru++;
lru_chain = lru_chain->more_recent;
}
print(nullptr) << "hash entries " << entries_in_hash_table
<< ", mru entries " << entries_from_mru
<< ", lru entries " << entries_from_lru << "\n";
if (entries_in_hash_table != entries_from_mru) {
halide_print(nullptr, "cache invalid case 3\n");
__builtin_trap();
}
if (entries_in_hash_table != entries_from_lru) {
halide_print(nullptr, "cache invalid case 4\n");
__builtin_trap();
}
if (current_cache_size < 0) {
halide_print(nullptr, "cache size is negative\n");
__builtin_trap();
}
}
#endif
WEAK void prune_cache() {
#if CACHE_DEBUGGING
validate_cache();
#endif
CacheEntry *prune_candidate = least_recently_used;
while (current_cache_size > max_cache_size &&
prune_candidate != nullptr) {
CacheEntry *more_recent = prune_candidate->more_recent;
if (prune_candidate->in_use_count == 0) {
uint32_t h = prune_candidate->hash;
uint32_t index = h % kHashTableSize;
// Remove from hash table
CacheEntry *prev_hash_entry = cache_entries[index];
if (prev_hash_entry == prune_candidate) {
cache_entries[index] = prune_candidate->next;
} else {
while (prev_hash_entry != nullptr && prev_hash_entry->next != prune_candidate) {
prev_hash_entry = prev_hash_entry->next;
}
halide_abort_if_false(nullptr, prev_hash_entry != nullptr);
prev_hash_entry->next = prune_candidate->next;
}
// Remove from less recent chain.
if (least_recently_used == prune_candidate) {
least_recently_used = more_recent;
}
if (more_recent != nullptr) {
more_recent->less_recent = prune_candidate->less_recent;
}
// Remove from more recent chain.
if (most_recently_used == prune_candidate) {
most_recently_used = prune_candidate->less_recent;
}
if (prune_candidate->less_recent != nullptr) {
prune_candidate->less_recent = more_recent;
}
// Decrease cache used amount.
for (uint32_t i = 0; i < prune_candidate->tuple_count; i++) {
current_cache_size -= prune_candidate->buf[i].size_in_bytes();
}
// Deallocate the entry.
prune_candidate->destroy();
halide_free(nullptr, prune_candidate);
}
prune_candidate = more_recent;
}
#if CACHE_DEBUGGING
validate_cache();
#endif
}
} // namespace Internal
} // namespace Runtime
} // namespace Halide
extern "C" {
WEAK void halide_memoization_cache_set_size(int64_t size) {
if (size == 0) {
size = kDefaultCacheSize;
}
ScopedMutexLock lock(&memoization_lock);
max_cache_size = size;
prune_cache();
}
WEAK int halide_memoization_cache_lookup(void *user_context, const uint8_t *cache_key, int32_t size,
halide_buffer_t *computed_bounds, int32_t tuple_count, halide_buffer_t **tuple_buffers) {
uint32_t h = djb_hash(cache_key, size);
uint32_t index = h % kHashTableSize;
ScopedMutexLock lock(&memoization_lock);
#if CACHE_DEBUGGING
debug_print_key(user_context, "halide_memoization_cache_lookup", cache_key, size);
debug_print_buffer(user_context, "computed_bounds", *computed_bounds);
{
for (int32_t i = 0; i < tuple_count; i++) {
halide_buffer_t *buf = tuple_buffers[i];
debug_print_buffer(user_context, "Allocation bounds", *buf);
}
}
#endif
CacheEntry *entry = cache_entries[index];
while (entry != nullptr) {
if (entry->hash == h && entry->key_size == (size_t)size &&
keys_equal(entry->key, cache_key, size) &&
buffer_has_shape(computed_bounds, entry->computed_bounds) &&
entry->tuple_count == (uint32_t)tuple_count) {
// Check all the tuple buffers have the same bounds (they should).
bool all_bounds_equal = true;
for (int32_t i = 0; all_bounds_equal && i < tuple_count; i++) {
all_bounds_equal = buffer_has_shape(tuple_buffers[i], entry->buf[i].dim);
}
if (all_bounds_equal) {
if (entry != most_recently_used) {
halide_abort_if_false(user_context, entry->more_recent != nullptr);
if (entry->less_recent != nullptr) {
entry->less_recent->more_recent = entry->more_recent;
} else {
halide_abort_if_false(user_context, least_recently_used == entry);
least_recently_used = entry->more_recent;
}
halide_abort_if_false(user_context, entry->more_recent != nullptr);
entry->more_recent->less_recent = entry->less_recent;
entry->more_recent = nullptr;
entry->less_recent = most_recently_used;
if (most_recently_used != nullptr) {
most_recently_used->more_recent = entry;
}
most_recently_used = entry;
}
for (int32_t i = 0; i < tuple_count; i++) {
halide_buffer_t *buf = tuple_buffers[i];
*buf = entry->buf[i];
}
entry->in_use_count += tuple_count;
return 0;
}
}
entry = entry->next;
}
for (int32_t i = 0; i < tuple_count; i++) {
halide_buffer_t *buf = tuple_buffers[i];
buf->host = ((uint8_t *)halide_malloc(user_context, buf->size_in_bytes() + header_bytes()));
if (buf->host == nullptr) {
for (int32_t j = i; j > 0; j--) {
halide_free(user_context, get_pointer_to_header(tuple_buffers[j - 1]->host));
tuple_buffers[j - 1]->host = nullptr;
}
return -1;
}
buf->host += header_bytes();
CacheBlockHeader *header = get_pointer_to_header(buf->host);
header->hash = h;
header->entry = nullptr;
}
#if CACHE_DEBUGGING
validate_cache();
#endif
return 1;
}
WEAK int halide_memoization_cache_store(void *user_context, const uint8_t *cache_key, int32_t size,
halide_buffer_t *computed_bounds,
int32_t tuple_count, halide_buffer_t **tuple_buffers,
bool has_eviction_key, uint64_t eviction_key) {
debug(user_context) << "halide_memoization_cache_store has_eviction_key: " << has_eviction_key << " eviction_key " << eviction_key << " .\n";
uint32_t h = get_pointer_to_header(tuple_buffers[0]->host)->hash;
uint32_t index = h % kHashTableSize;
ScopedMutexLock lock(&memoization_lock);
#if CACHE_DEBUGGING
debug_print_key(user_context, "halide_memoization_cache_store", cache_key, size);
debug_print_buffer(user_context, "computed_bounds", *computed_bounds);
{
for (int32_t i = 0; i < tuple_count; i++) {
halide_buffer_t *buf = tuple_buffers[i];
debug_print_buffer(user_context, "Allocation bounds", *buf);
}
}
#endif
CacheEntry *entry = cache_entries[index];
while (entry != nullptr) {
if (entry->hash == h && entry->key_size == (size_t)size &&
keys_equal(entry->key, cache_key, size) &&
buffer_has_shape(computed_bounds, entry->computed_bounds) &&
entry->tuple_count == (uint32_t)tuple_count) {
bool all_bounds_equal = true;
bool no_host_pointers_equal = true;
{
for (int32_t i = 0; all_bounds_equal && i < tuple_count; i++) {
halide_buffer_t *buf = tuple_buffers[i];
all_bounds_equal = buffer_has_shape(tuple_buffers[i], entry->buf[i].dim);
if (entry->buf[i].host == buf->host) {
no_host_pointers_equal = false;
}
}
}
if (all_bounds_equal) {
halide_abort_if_false(user_context, no_host_pointers_equal);
// This entry is still in use by the caller. Mark it as having no cache entry
// so halide_memoization_cache_release can free the buffer.
for (int32_t i = 0; i < tuple_count; i++) {
get_pointer_to_header(tuple_buffers[i]->host)->entry = nullptr;
}
return 0;
}
}
entry = entry->next;
}
uint64_t added_size = 0;
{
for (int32_t i = 0; i < tuple_count; i++) {
halide_buffer_t *buf = tuple_buffers[i];
added_size += buf->size_in_bytes();
}
}
current_cache_size += added_size;
prune_cache();
CacheEntry *new_entry = (CacheEntry *)halide_malloc(nullptr, sizeof(CacheEntry));
bool inited = false;
if (new_entry) {
inited = new_entry->init(cache_key, size, h, computed_bounds, tuple_count, tuple_buffers,
has_eviction_key, eviction_key);
}
if (!inited) {
current_cache_size -= added_size;
// This entry is still in use by the caller. Mark it as having no cache entry
// so halide_memoization_cache_release can free the buffer.
for (int32_t i = 0; i < tuple_count; i++) {
get_pointer_to_header(tuple_buffers[i]->host)->entry = nullptr;
}
if (new_entry) {
halide_free(user_context, new_entry);
}
return 0;
}
new_entry->next = cache_entries[index];
new_entry->less_recent = most_recently_used;
if (most_recently_used != nullptr) {
most_recently_used->more_recent = new_entry;
}
most_recently_used = new_entry;
if (least_recently_used == nullptr) {
least_recently_used = new_entry;
}
cache_entries[index] = new_entry;
new_entry->in_use_count = tuple_count;
for (int32_t i = 0; i < tuple_count; i++) {
get_pointer_to_header(tuple_buffers[i]->host)->entry = new_entry;
}
#if CACHE_DEBUGGING
validate_cache();
#endif
debug(user_context) << "Exiting halide_memoization_cache_store\n";
return 0;
}
WEAK void halide_memoization_cache_release(void *user_context, void *host) {
CacheBlockHeader *header = get_pointer_to_header((uint8_t *)host);
debug(user_context) << "halide_memoization_cache_release\n";
CacheEntry *entry = header->entry;
if (entry == nullptr) {
halide_free(user_context, header);
} else {
ScopedMutexLock lock(&memoization_lock);
halide_abort_if_false(user_context, entry->in_use_count > 0);
entry->in_use_count--;
#if CACHE_DEBUGGING
validate_cache();
#endif
}
debug(user_context) << "Exited halide_memoization_cache_release.\n";
}
WEAK void halide_memoization_cache_cleanup() {
debug(nullptr) << "halide_memoization_cache_cleanup\n";
for (auto &entry_ref : cache_entries) {
CacheEntry *entry = entry_ref;
entry_ref = nullptr;
while (entry != nullptr) {
CacheEntry *next = entry->next;
entry->destroy();
halide_free(nullptr, entry);
entry = next;
}
}
current_cache_size = 0;
most_recently_used = nullptr;
least_recently_used = nullptr;
}
WEAK void halide_memoization_cache_evict(void *user_context, uint64_t eviction_key) {
ScopedMutexLock lock(&memoization_lock);
for (auto &entry_ref : cache_entries) {
CacheEntry *entry = entry_ref;
if (entry != nullptr) {
CacheEntry **prev = &entry_ref;
while (entry != nullptr) {
CacheEntry *next = entry->next;
if (entry->has_eviction_key && entry->eviction_key == eviction_key) {
*prev = next;
if (entry->more_recent != nullptr) {
entry->more_recent->less_recent = entry->less_recent;
} else {
most_recently_used = entry->less_recent;
}
if (entry->less_recent != nullptr) {
entry->less_recent->more_recent = entry->more_recent;
} else {
least_recently_used = entry->more_recent;
}
entry->destroy();
halide_free(user_context, entry);
} else {
prev = &entry->next;
}
entry = next;
}
}
}
#if CACHE_DEBUGGING
validate_cache();
#endif
}
namespace {
WEAK __attribute__((destructor)) void halide_cache_cleanup() {
halide_memoization_cache_cleanup();
}
} // namespace
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

MIT计算机科学和人工智能实验室的研究人员创造出一种专门设计简化图像处理的程序语言Halide,源代码托管在GitHub上,目前二进制程序只支持Mac OS X和Ubuntu 12
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/VisionDeveloper/Halide.git
git@gitee.com:VisionDeveloper/Halide.git
VisionDeveloper
Halide
Halide
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /