2 * Copyright (c) 2011-2015,2018 Advanced Micro Devices, Inc.
5 * For use for simulation and test purposes only
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 * Authors: Brad Beckmann,
38 #ifndef __GPU_DISPATCHER_HH__
39 #define __GPU_DISPATCHER_HH__
44 #include "base/statistics.hh"
45 #include "dev/dma_device.hh"
46 #include "gpu-compute/compute_unit.hh"
47 #include "gpu-compute/ndrange.hh"
48 #include "gpu-compute/qstruct.hh"
49 #include "mem/port.hh"
50 #include "params/GpuDispatcher.hh"
55 class GpuDispatcher : public DmaDevice
58 typedef GpuDispatcherParams Params;
60 MasterID masterId() { return _masterId; }
65 // Base and length of PIO register space
70 HsaQueueEntry curTask;
72 std::unordered_map<int, NDRange> ndRangeMap;
75 // list of kernel_ids to launch
76 std::queue<int> execIds;
77 // list of kernel_ids that have finished
78 std::queue<int> doneIds;
80 uint64_t dispatchCount;
81 // is there a kernel in execution?
87 EventFunctionWrapper tickEvent;
90 static GpuDispatcher *instance;
92 // sycall emulation mode can have only 1 application running(?)
93 // else we have to do some pid based tagging
95 typedef std::unordered_map<uint64_t, uint64_t> TranslationBuffer;
96 TranslationBuffer tlb;
100 Stats::Scalar num_kernelLaunched;
101 GpuDispatcher(const Params *p);
106 virtual void serialize(CheckpointOut &cp) const;
107 virtual void unserialize(CheckpointIn &cp);
108 void notifyWgCompl(Wavefront *w);
109 void scheduleDispatch();
110 void accessUserVar(BaseCPU *cpu, uint64_t addr, int val, int off);
112 // using singleton so that glue code can pass pointer locations
113 // to the dispatcher. when there are multiple dispatchers, we can
114 // call something like getInstance(index)
116 setInstance(GpuDispatcher *_instance)
118 instance = _instance;
121 static GpuDispatcher* getInstance() { return instance; }
123 class TLBPort : public MasterPort
127 TLBPort(const std::string &_name, GpuDispatcher *_dispatcher)
128 : MasterPort(_name, _dispatcher), dispatcher(_dispatcher) { }
131 GpuDispatcher *dispatcher;
133 virtual bool recvTimingResp(PacketPtr pkt) { return true; }
134 virtual Tick recvAtomic(PacketPtr pkt) { return 0; }
135 virtual void recvFunctional(PacketPtr pkt) { }
136 virtual void recvRangeChange() { }
137 virtual void recvReqRetry() { }
143 virtual BaseMasterPort& getMasterPort(const std::string &if_name,
146 AddrRangeList getAddrRanges() const;
147 Tick read(PacketPtr pkt);
148 Tick write(PacketPtr pkt);
150 // helper functions to retrieve/set GPU attributes
153 void setFuncargsSize(int funcargs_size);
155 /** Returns the size of the static hardware context of a wavefront */
156 uint32_t getStaticContextSize() const;
159 #endif // __GPU_DISPATCHER_HH__