MicroGPU 1.0
Simple functional model of a GPU for educational purposes
Loading...
Searching...
No Matches
warp.hh
Go to the documentation of this file.
1#ifndef SRC_WARP_WARP_HH_
2#define SRC_WARP_WARP_HH_
3
4#include<iostream>
5#include<string>
6#include<vector>
7#include<array>
8#include<bitset>
9#include "../thread/thread.hh"
10
11// Define the number of threads in a warp
12#define WARP_THREAD_COUNT 32
13
14// Type alias for the active mask of threads in a warp
15using ActiveMask = std::bitset<WARP_THREAD_COUNT>;
16
17
26
30 int dest;
31 int src1;
32 int src2;
34
35 Instruction(InstructionType t, int d, int s1, int s2, bool isBranch = false)
36 : type(t), dest(d), src1(s1), src2(s2), isBranch(isBranch) {}
37 Instruction() : type(ADD), dest(0), src1(0), src2(0), isBranch(false) {}
38
39};
40
41// Reconvergence point structure
48 int pc;
50
51 reconvergencePoint(int pc_, const ActiveMask& mask_)
52 : pc(pc_), mask(mask_) {}
54};
55
65
78
79// Type alias for a group of threads in a warp
80using ThreadGroup = std::array<Thread, WARP_THREAD_COUNT>;
81
90class Warp {
91 int id;
92 int pc; // All threads in the warp share the same program counter
96
101 std::vector<reconvergencePoint> reconvergenceStack;
102
105 bool isBranchDivergent = false; // Flag to indicate if the warp is currently divergent due to a branch instruction
106
107 public:
108 Warp();
109 Warp(int warpId, const ThreadGroup& threadGroup, WarpState warpState = WarpState::READY, PipelineStage pipelineStage = PipelineStage::NOT_STARTED, bool isBranchDivergent = false);
110
111 // Getter and Setter methods
112 int getId() const;
113 int getPc() const;
114 void setPc(int pc_);
115 void setCurrentInstruction(const Instruction& instr);
119 void setActiveMask(const ActiveMask& mask) { activeMask = mask; }
120 std :: string getPipelineStageString() const;
121 const ActiveMask& getActiveMask() const;
122 WarpState getState() const { return state; }
123 bool isDivergent() const { return isBranchDivergent; }
125 // method to execute the instruction of the warp - to be called by ComputeUnit during execution
126 void execute();
127 std::string getInstructionTypeString(Instruction inst) const;
128
129 // Methods to manage reconvergence points
130
137 void addReconvergencePoint(int pc, const ActiveMask& mask);
138
143 void peekReconvergencePoint() const;
144
150
151 // Method to get the size of the reconvergence stack, useful for checking if all reconvergence points have been processed
152 size_t getReconvergenceStackSize() const;
153
158 std::bitset<WARP_THREAD_COUNT> getActiveMaskFromReconvergenceStack() const;
159};
160
161
162#endif // SRC_WARP_WARP_HH_
Represents a GPU warpThe Warp class encapsulates the state and behavior of a GPU warp,...
Definition warp.hh:90
int getId() const
Definition warp.cc:14
void setPc(int pc_)
Definition warp.cc:22
size_t getReconvergenceStackSize() const
Definition warp.cc:129
Warp()
Definition warp.cc:3
bool isBranchDivergent
Definition warp.hh:105
int id
Definition warp.hh:91
std::bitset< WARP_THREAD_COUNT > getActiveMaskFromReconvergenceStack() const
Get the active mask from the top reconvergence point on the stack.
Definition warp.cc:133
void peekReconvergencePoint() const
Peek the top reconvergence point on the stack This method is used for debugging purposes to check the...
Definition warp.cc:112
int pc
Definition warp.hh:92
ThreadGroup threads
Definition warp.hh:93
PipelineStage getPipelineStage() const
Definition warp.hh:117
void setActiveMask(const ActiveMask &mask)
Definition warp.hh:119
const ActiveMask & getActiveMask() const
Definition warp.cc:26
std::vector< reconvergencePoint > reconvergenceStack
Reconvergence stack for handling divergent control flow.
Definition warp.hh:101
int getPc() const
Definition warp.cc:18
void popReconvergencePoint()
Pop the top reconvergence point from the stack This method is called when a reconvergence point is re...
Definition warp.cc:121
void setPipelineStage(PipelineStage stage)
Definition warp.hh:118
void setDivergent()
Definition warp.hh:124
PipelineStage pipelineStage
Definition warp.hh:104
std::string getPipelineStageString() const
Definition warp.cc:38
void addReconvergencePoint(int pc, const ActiveMask &mask)
Add a reconvergence point to the stack.
Definition warp.cc:108
ActiveMask activeMask
Definition warp.hh:94
void setCurrentInstruction(const Instruction &instr)
Definition warp.cc:30
Instruction currentInstruction
Definition warp.hh:95
Instruction getCurrentInstruction() const
Definition warp.cc:34
WarpState getState() const
Definition warp.hh:122
bool isDivergent() const
Definition warp.hh:123
std::string getInstructionTypeString(Instruction inst) const
Definition warp.cc:50
void execute()
Definition warp.cc:60
WarpState state
Definition warp.hh:103
Instruction structure.
Definition warp.hh:28
int dest
Definition warp.hh:30
int src2
Definition warp.hh:32
bool isBranch
Definition warp.hh:33
Instruction(InstructionType t, int d, int s1, int s2, bool isBranch=false)
Definition warp.hh:35
int src1
Definition warp.hh:31
InstructionType type
Definition warp.hh:29
Instruction()
Definition warp.hh:37
Represents a reconvergence point in a warp It has PC value and active mask to indicate which threads ...
Definition warp.hh:47
int pc
Definition warp.hh:48
reconvergencePoint()
Definition warp.hh:53
ActiveMask mask
Definition warp.hh:49
reconvergencePoint(int pc_, const ActiveMask &mask_)
Definition warp.hh:51
std::array< Thread, WARP_THREAD_COUNT > ThreadGroup
Definition warp.hh:80
InstructionType
Instruction types enumeration.
Definition warp.hh:19
@ SUB
Definition warp.hh:21
@ LOAD
Definition warp.hh:22
@ ADD
Definition warp.hh:20
@ BRANCH
Definition warp.hh:24
@ STORE
Definition warp.hh:23
PipelineStage
Pipeline stages for a warp.
Definition warp.hh:70
@ STAGE_1
Definition warp.hh:73
@ STAGE_3
Definition warp.hh:75
@ DONE
Definition warp.hh:76
@ STAGE_2
Definition warp.hh:74
@ NOT_STARTED
Definition warp.hh:71
@ STAGE_0
Definition warp.hh:72
WarpState
Warp states Not using this yet but can be useful in future iterations to manage the state of warps mo...
Definition warp.hh:60
@ RUNNING
Definition warp.hh:62
@ READY
Definition warp.hh:61
@ STALLED
Definition warp.hh:63
std::bitset< WARP_THREAD_COUNT > ActiveMask
Definition warp.hh:15