gem5  v22.1.0.0
misc.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2017 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef __MISC_HH__
33 #define __MISC_HH__
34 
35 #include <bitset>
36 #include <limits>
37 #include <memory>
38 
39 #include "base/logging.hh"
40 #include "sim/clocked_object.hh"
41 
42 namespace gem5
43 {
44 
45 class GPUDynInst;
46 
47 typedef std::bitset<std::numeric_limits<unsigned long long>::digits>
49 typedef std::shared_ptr<GPUDynInst> GPUDynInstPtr;
50 
51 enum InstMemoryHop : int
52 {
53  Initiate = 0,
56  GMEnqueue = 3,
57  Complete = 4,
59 };
60 
61 enum BlockMemoryHop : int
62 {
63  BlockSend = 0,
64  BlockRecv = 1
65 };
66 
67 class WaitClass
68 {
69  public:
71 
72  WaitClass(ClockedObject *_clockedObject, uint64_t _numStages=0)
73  : nxtAvail(0), lookAheadAvail(0), clockedObject(_clockedObject),
74  numStages(_numStages) { }
75 
76  void init(ClockedObject *_clockedObject, uint64_t _numStages=0)
77  {
78  clockedObject = _clockedObject;
79  numStages = _numStages;
80  }
81 
82  void set(uint64_t i)
83  {
85  "Can't allocate resource because it is busy!!!");
87  }
88  void preset(uint64_t delay)
89  {
90  lookAheadAvail = std::max(lookAheadAvail, delay +
92  }
93  bool rdy(Cycles cycles = Cycles(0)) const
94  {
95  return clockedObject->clockEdge(cycles) >= nxtAvail;
96  }
97  bool prerdy() const
98  {
100  }
101 
102  private:
103  // timestamp indicating when resource will be available
104  uint64_t nxtAvail;
105  // timestamp indicating when resource will be available including
106  // pending uses of the resource (when there is a cycle gap between
107  // rdy() and set()
108  uint64_t lookAheadAvail;
109  // clockedObject for current timestamp
111  // number of stages between checking if a resource is ready and
112  // setting the resource's utilization
113  uint64_t numStages;
114 };
115 
116 class Float16
117 {
118  public:
119  uint16_t val;
120 
121  Float16() { val = 0; }
122 
123  Float16(const Float16 &x) : val(x.val) { }
124 
125  Float16(float x)
126  {
127  uint32_t ai = *(reinterpret_cast<uint32_t *>(&x));
128 
129  uint32_t s = (ai >> 31) & 0x1;
130  uint32_t exp = (ai >> 23) & 0xff;
131  uint32_t mant = (ai >> 0) & 0x7fffff;
132 
133  if (exp == 0 || exp <= 0x70) {
134  exp = 0;
135  mant = 0;
136  } else if (exp == 0xff) {
137  exp = 0x1f;
138  } else if (exp >= 0x8f) {
139  exp = 0x1f;
140  mant = 0;
141  } else {
142  exp = exp - 0x7f + 0x0f;
143  }
144 
145  mant = mant >> 13;
146 
147  val = 0;
148  val |= (s << 15);
149  val |= (exp << 10);
150  val |= (mant << 0);
151  }
152 
153  operator float() const
154  {
155  uint32_t s = (val >> 15) & 0x1;
156  uint32_t exp = (val >> 10) & 0x1f;
157  uint32_t mant = (val >> 0) & 0x3ff;
158 
159  if (!exp) {
160  exp = 0;
161  mant = 0;
162  } else if (exp == 0x1f) {
163  exp = 0xff;
164  } else {
165  exp = exp - 0x0f + 0x7f;
166  }
167 
168  uint32_t val1 = 0;
169  val1 |= (s << 31);
170  val1 |= (exp << 23);
171  val1 |= (mant << 13);
172 
173  return *(reinterpret_cast<float *>(&val1));
174  }
175 };
176 
177 } // namespace gem5
178 
179 #endif // __MISC_HH__
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
Float16(const Float16 &x)
Definition: misc.hh:123
uint16_t val
Definition: misc.hh:119
Float16(float x)
Definition: misc.hh:125
void set(uint64_t i)
Definition: misc.hh:82
uint64_t lookAheadAvail
Definition: misc.hh:108
uint64_t nxtAvail
Definition: misc.hh:104
void init(ClockedObject *_clockedObject, uint64_t _numStages=0)
Definition: misc.hh:76
void preset(uint64_t delay)
Definition: misc.hh:88
bool rdy(Cycles cycles=Cycles(0)) const
Definition: misc.hh:93
uint64_t numStages
Definition: misc.hh:113
bool prerdy() const
Definition: misc.hh:97
ClockedObject * clockedObject
Definition: misc.hh:110
WaitClass(ClockedObject *_clockedObject, uint64_t _numStages=0)
Definition: misc.hh:72
ClockedObject declaration and implementation.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:226
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 4 > x
Definition: pagetable.hh:61
Bitfield< 44 > s
Definition: misc.hh:934
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< GPUDynInst > GPUDynInstPtr
Definition: misc.hh:49
InstMemoryHop
Definition: misc.hh:52
@ CoalsrRecv
Definition: misc.hh:55
@ GMEnqueue
Definition: misc.hh:56
@ Initiate
Definition: misc.hh:53
@ CoalsrSend
Definition: misc.hh:54
@ InstMemoryHopMax
Definition: misc.hh:58
@ Complete
Definition: misc.hh:57
std::bitset< std::numeric_limits< unsigned long long >::digits > VectorMask
Definition: misc.hh:45
BlockMemoryHop
Definition: misc.hh:62
@ BlockRecv
Definition: misc.hh:64
@ BlockSend
Definition: misc.hh:63

Generated on Wed Dec 21 2022 10:22:26 for gem5 by doxygen 1.9.1