[Openmp-commits] [PATCH] D156996: [OpenMP][AMDGPU] Add Envar for controlling HSA busy queue tracking

Kevin Sala via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Aug 4 06:50:56 PDT 2023


kevinsala added a comment.

I would keep it simple:

  inline Error assignNextQueue(AMDGPUStreamTy *Stream) {
    uint32_t SelectedIndex = 0;
  
    if (OMPX_QueueTracking) {
      // Find the least used queue.
      for (uint32_t I = 0; I < MaxNumQueues; ++I) {
        // Early exit when an initialized queue is idle
        if (Queues[I].isInitialized() && Queues[I].getUserCount() == 0) {
          SelectedIndex = I;
          break;
        }
        
        // Update the least contested queue
        if (Queues[SelectedIndex].getUserCount() > Queues[I].getUserCount())
          SelectedIndex = I;
      }
    } else {
      // Round-robin policy.
      SelectedIndex = NextQueue++ % MaxNumQueues;
    }
    
    // Make sure we assign an initialized queue, then add user & assign
    if (auto Err = Queues[SelectedIndex].init(Agent, QueueSize))
      return Err;
    Queues[SelectedIndex].addUser();
    Stream->Queue = &Queues[SelectedIndex];
    
    return Plugin::success();
  }

This variant is based on your last snippet. `NextQueue` is not used at all when queue tracking is enabled; it's only used when working in round-robin policy. In queue tracking mode, we start from the first queue. It features the early exit you wrote. Although it doesn't skip any iteration, but I don't think it'll impact the performance.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156996/new/

https://reviews.llvm.org/D156996



More information about the Openmp-commits mailing list