gem5  v22.0.0.1
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>
48  VectorMask;
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,
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__
gem5::GMEnqueue
@ GMEnqueue
Definition: misc.hh:56
gem5::Float16::Float16
Float16()
Definition: misc.hh:121
gem5::Float16::Float16
Float16(float x)
Definition: misc.hh:125
gem5::Complete
@ Complete
Definition: misc.hh:57
gem5::VectorMask
std::bitset< std::numeric_limits< unsigned long long >::digits > VectorMask
Definition: misc.hh:45
gem5::Float16::val
uint16_t val
Definition: misc.hh:119
gem5::WaitClass::WaitClass
WaitClass()
Definition: misc.hh:70
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::WaitClass::prerdy
bool prerdy() const
Definition: misc.hh:97
gem5::WaitClass::clockedObject
ClockedObject * clockedObject
Definition: misc.hh:110
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::WaitClass::lookAheadAvail
uint64_t lookAheadAvail
Definition: misc.hh:108
gem5::Initiate
@ Initiate
Definition: misc.hh:53
gem5::WaitClass::init
void init(ClockedObject *_clockedObject, uint64_t _numStages=0)
Definition: misc.hh:76
gem5::CoalsrRecv
@ CoalsrRecv
Definition: misc.hh:55
gem5::Float16
Definition: misc.hh:116
gem5::VegaISA::x
Bitfield< 4 > x
Definition: pagetable.hh:61
gem5::WaitClass::nxtAvail
uint64_t nxtAvail
Definition: misc.hh:104
gem5::WaitClass
Definition: misc.hh:67
gem5::WaitClass::preset
void preset(uint64_t delay)
Definition: misc.hh:88
gem5::GPUDynInst
Definition: gpu_dyn_inst.hh:116
gem5::WaitClass::WaitClass
WaitClass(ClockedObject *_clockedObject, uint64_t _numStages=0)
Definition: misc.hh:72
gem5::BlockRecv
@ BlockRecv
Definition: misc.hh:64
gem5::CoalsrSend
@ CoalsrSend
Definition: misc.hh:54
gem5::InstMemoryHopMax
@ InstMemoryHopMax
Definition: misc.hh:58
gem5::GPUDynInstPtr
std::shared_ptr< GPUDynInst > GPUDynInstPtr
Definition: misc.hh:49
gem5::ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:234
gem5::Clocked::clockEdge
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...
Definition: clocked_object.hh:177
gem5::WaitClass::set
void set(uint64_t i)
Definition: misc.hh:82
gem5::InstMemoryHop
InstMemoryHop
Definition: misc.hh:51
clocked_object.hh
logging.hh
gem5::WaitClass::numStages
uint64_t numStages
Definition: misc.hh:113
gem5::BlockSend
@ BlockSend
Definition: misc.hh:63
gem5::Float16::Float16
Float16(const Float16 &x)
Definition: misc.hh:123
fatal_if
#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
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::X86ISA::s
Bitfield< 44 > s
Definition: misc.hh:927
gem5::WaitClass::rdy
bool rdy(Cycles cycles=Cycles(0)) const
Definition: misc.hh:93
gem5::BlockMemoryHop
BlockMemoryHop
Definition: misc.hh:61

Generated on Sat Jun 18 2022 08:12:15 for gem5 by doxygen 1.8.17