Skip to content

Commit

Permalink
Properly queue order dealloca.
Browse files Browse the repository at this point in the history
  • Loading branch information
stellaraccident committed Feb 19, 2025
1 parent 91b8a3b commit b57912c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion shortfin/python/lib_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class PyProgramInvocation {
results_failure_(other.results_failure_) {}

// Fields that can be bound.
bool assume_no_alias = false;
bool assume_no_alias = true;
static std::optional<bool> global_assume_no_alias;

void CheckValid() {
Expand Down
13 changes: 10 additions & 3 deletions shortfin/src/shortfin/local/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,25 @@ TimelineResourceDestructor TimelineResource::CreateAsyncBufferDestructor(
iree_hal_device_t *hal_device = scoped_device.raw_device()->hal_device();
auto queue_affinity = scoped_device.affinity().queue_affinity();
SHORTFIN_TRACE_SCOPE_NAMED("TimelineResource::AsyncBufferDestructor");
iree_hal_semaphore_list_t wait_semaphore_list = res.use_barrier();
// TODO: If desiring strict memory reclamation ordering, we want to queue
// order the successors to the deallocation.

// The dealloca needs to wait on the current timepoint+all uses, and it
// needs to signal the next timepoint. Since this is a destructor, we
// now have exclusive control of the TimelineResource and simply record
// the current timepoint in its uses as a (small) optimization for merging
// the wait semaphore list, prior to acquiring a new timepoint
// (to signal).
auto fiber = res.fiber();
auto &account = fiber->scheduler().GetDefaultAccount(scoped_device);
iree_hal_semaphore_t *timeline_sem = account.timeline_sem();
res.use_barrier_insert(timeline_sem, account.timeline_idle_timepoint());
uint64_t signal_timepoint = account.timeline_acquire_timepoint();
iree_hal_semaphore_list_t wait_semaphore_list = res.use_barrier();
iree_hal_semaphore_list_t signal_semaphore_list{
.count = 1,
.semaphores = &timeline_sem,
.payload_values = &signal_timepoint,
};

if (SHORTFIN_SCHED_LOG_ENABLED) {
auto wait_sum = iree::DebugPrintSemaphoreList(wait_semaphore_list);
auto signal_sum = iree::DebugPrintSemaphoreList(signal_semaphore_list);
Expand Down
2 changes: 1 addition & 1 deletion shortfin/src/shortfin/support/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#endif

// Scheduler logging.
#define SHORTFIN_SCHED_LOG_ENABLED 1
#define SHORTFIN_SCHED_LOG_ENABLED 0
#if SHORTFIN_SCHED_LOG_ENABLED
#define SHORTFIN_SCHED_LOG(...) shortfin::logging::info("SCHED: " __VA_ARGS__)
#else
Expand Down

0 comments on commit b57912c

Please sign in to comment.