Skip to content

File base.h

File List > projects > simtix > src > simtix > sm > sched > base.h

Go to the documentation of this file

#pragma once

#include <cassert>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "sm/warp.h"

namespace simtix {

namespace pipelined {
class InstrBuffer;
}

class WarpSched {
 public:
  explicit WarpSched(const std::string &name,
                     const std::vector<Warp *> &warp_list,
                     const ArchParam &p = kDefaultArchParam)
      : name_(name),
        stat_(std::make_shared<Stat>(name)),
        num_warps_(p.kWarpsPerCore()),
        num_warps_per_warpgroup_(p.kWarpsPerWarpGroup()),
        leader_warp_list_(warp_list) {}

  virtual ~WarpSched() = default;

  // Select a warp for execution
  // virtual method for WarpSched
  virtual std::pair<Warp *, std::optional<uint32_t>> SelectWarp() = 0;

  // When SM issues an instruction, it should notify the scheduler and scheduler
  // should operate correspondingly.
  virtual void NotifyIssue() = 0;

  uint32_t NumWarps() const { return num_warps_; }

  // When a work-group finishes execution, the SM will reset and call this
  // method, giving the scheduler a hint to reset its internal data structure.
  virtual void Reset() = 0;

  const std::shared_ptr<stat::Group> stat() const { return stat_; }

  void ResetStat() { stat_ = std::make_shared<Stat>(name_); }

 protected:
  const std::string name_;

  struct Stat : stat::Group {
    explicit Stat(const std::string &name)
        : Group(name),
          STAT(issue_ssw_opp,
               "Oppotunity of issue spatial-sub-warp when pipeline is stall "
               "cause no avalible warp",
               "N/A"),
          STAT(warp_sched_stall, "Pipeline stall caused by no can issue warp",
               "N/A"),
          STAT(dual_path_stall, "Both spatial-sub-warps cannot be issued",
               "N/A") {}
    stat::Integer issue_ssw_opp;
    stat::Integer warp_sched_stall;
    stat::Integer dual_path_stall;
  };

  std::shared_ptr<Stat> stat_;

  uint32_t num_warps_;

  uint32_t num_warps_per_warpgroup_;

  // All valid condidate leader warps for scheduling
  const std::vector<Warp *> &leader_warp_list_;
};

}  // namespace simtix