diff --git a/src/a2a3/runtime/aicpu_build_graph/runtime/pto_ring_buffer.h b/src/a2a3/runtime/aicpu_build_graph/runtime/pto_ring_buffer.h index 0b8836def..2b8141f46 100644 --- a/src/a2a3/runtime/aicpu_build_graph/runtime/pto_ring_buffer.h +++ b/src/a2a3/runtime/aicpu_build_graph/runtime/pto_ring_buffer.h @@ -217,7 +217,7 @@ struct PTO2HeapRing { if (space_at_end >= alloc_size) { new_top = top + alloc_size; result = (char *)base + top; - } else if (tail > alloc_size) { + } else if (tail >= alloc_size) { // Wrap to beginning new_top = alloc_size; result = base; @@ -545,7 +545,7 @@ struct PTO2DepListPool { */ PTO2DepListEntry *alloc() { int32_t used = top - tail; - if (used >= capacity) { + if (used >= capacity - 1) { LOG_ERROR("========================================"); LOG_ERROR("FATAL: Dependency Pool Overflow!"); LOG_ERROR("========================================"); @@ -563,7 +563,7 @@ struct PTO2DepListPool { } return nullptr; } - int32_t idx = top % capacity; + int32_t idx = static_cast((static_cast(top) - 1) % (capacity - 1)) + 1; top++; used++; if (used > high_water) high_water = used; diff --git a/src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h b/src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h index a433f5aa3..17311b739 100644 --- a/src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h +++ b/src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h @@ -272,7 +272,7 @@ class PTO2TaskAllocator { if (space_at_end >= alloc_size) { result = static_cast(heap_base_) + top; heap_top_ = top + alloc_size; - } else if (tail > alloc_size) { + } else if (tail >= alloc_size) { result = heap_base_; heap_top_ = alloc_size; } else { @@ -426,7 +426,7 @@ struct PTO2DepListPool { */ PTO2DepListEntry *alloc() { int32_t used = top - tail; - if (used >= capacity) { + if (used >= capacity - 1) { LOG_ERROR("========================================"); LOG_ERROR("FATAL: Dependency Pool Overflow!"); LOG_ERROR("========================================"); @@ -444,7 +444,7 @@ struct PTO2DepListPool { } return nullptr; } - int32_t idx = top % capacity; + int32_t idx = static_cast((static_cast(top) - 1) % (capacity - 1)) + 1; top++; used++; if (used > high_water) high_water = used; diff --git a/src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h b/src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h index a433f5aa3..17311b739 100644 --- a/src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h +++ b/src/a5/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.h @@ -272,7 +272,7 @@ class PTO2TaskAllocator { if (space_at_end >= alloc_size) { result = static_cast(heap_base_) + top; heap_top_ = top + alloc_size; - } else if (tail > alloc_size) { + } else if (tail >= alloc_size) { result = heap_base_; heap_top_ = alloc_size; } else { @@ -426,7 +426,7 @@ struct PTO2DepListPool { */ PTO2DepListEntry *alloc() { int32_t used = top - tail; - if (used >= capacity) { + if (used >= capacity - 1) { LOG_ERROR("========================================"); LOG_ERROR("FATAL: Dependency Pool Overflow!"); LOG_ERROR("========================================"); @@ -444,7 +444,7 @@ struct PTO2DepListPool { } return nullptr; } - int32_t idx = top % capacity; + int32_t idx = static_cast((static_cast(top) - 1) % (capacity - 1)) + 1; top++; used++; if (used > high_water) high_water = used;