Skip to content

File thread.h

File List > projects > simtix > src > simtix > sm > thread.h

Go to the documentation of this file

#pragma once

#include <simtix/param.h>

#include <array>
#include <cstdint>

namespace simtix {

class Warp;

class Thread {
 public:
  explicit Thread(Warp *warp, uint32_t tid,
                  const ArchParam &p = kDefaultArchParam);

  // Return program counter (pc_).
  uint64_t pc() const { return pc_; }

  // Return program counter (pc_).
  void set_pc(uint64_t pc) { pc_ = pc; }

  // Return an uint32 type thread priority.
  uint32_t priority() const { return priority_; }

  // Return an uint32 type thread function priority.
  uint32_t priority_f() const { return priority_f_; }

  // Return an uint32 type max_priority_level.
  uint32_t max_priority_level() const { return max_priority_level_; }

  // Return an uint32 type max_function_priority_level
  uint32_t max_function_priority_level() const { return max_priority_f_level_; }

  // Return an uint32 type thread ID (tid).
  uint32_t tid() const { return tid_; }

  // Return an uint32 type warp ID (wid).
  uint32_t wid() const;

  // Setter of CSR xcllx (local ID in x dimension of a work-group).
  void set_xcllx(uint32_t lx) { xcllx_ = lx; }

  // Setter of CSR xclly (local ID in y dimension of a work-group).
  void set_xclly(uint32_t ly) { xclly_ = ly; }

  // Setter of CSR xcllz (local ID in z dimension of a work-group).
  void set_xcllz(uint32_t lz) { xcllz_ = lz; }

  void AdvancePC();

  void ResetPC();

  void RaisePriority();

  void LowerPriority();

  void ResetPriority();

  void SetPriority(uint32_t set_priority);

  void RaiseFunctPriority();

  void LowerFunctPriority();

  int32_t ReadCSR(uint16_t addr, uint64_t *data);

  int32_t WriteCSR(uint16_t addr, uint64_t data);

  void Reset();

 protected:
  // Per-thread CSR
  uint64_t mhartid_;
  uint64_t hpmcounter3_ = 0;

 private:
  // Variable: warp_
  //   Parent warp.
  Warp *const warp_;

  // Variable: tid_
  //   Thread ID.
  uint32_t tid_;

  // Variable: max_priority_level_
  //   Number of supported priority level.
  const uint32_t max_priority_level_;

  // Variable: max_priority_f_level_
  //   Number of supported function priority level.
  const uint32_t max_priority_f_level_;

  // Variable: pc_
  //   Instruction PC.
  uint64_t pc_;

  // Variable: priority_
  //   Priority of thread.
  uint32_t priority_;

  // Variable: priority_f_
  //   Function priority of thread.
  uint32_t priority_f_;

  // Variable: xcllx_
  //   OpenCL related xcllx CSR (local ID in x dimension of a work-group).
  uint32_t xcllx_ = 0;

  // Variable: xclly_
  //   OpenCL related xclly CSR (local ID in y dimension of a work-group).
  uint32_t xclly_ = 0;

  // Variable: xcllz_
  //   OpenCL related xcllz CSR (local ID in z dimension of a work-group).
  uint32_t xcllz_ = 0;
};

}  // namespace simtix