gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
brig_object.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2015 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
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.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its contributors
18  * may be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
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.
32  *
33  * Author: Steve Reinhardt, Anthony Gutierrez
34  */
35 
36 #ifndef __BRIG_OBJECT_HH__
37 #define __BRIG_OBJECT_HH__
38 
39 #include <cassert>
40 #include <cstdint>
41 #include <string>
42 #include <vector>
43 
44 #include "arch/hsail/Brig.h"
47 
48 class LabelMap;
49 class StorageMap;
50 
51 /* @class BrigObject
52  * this class implements the BRIG loader object, and
53  * is used when the simulator directly executes HSAIL.
54  * this class is responsible for extracting all
55  * information about kernels contained in BRIG format
56  * and converts them to HsailCode objects that are
57  * usable by the simulator and emulated runtime.
58  */
59 
60 class BrigObject final : public HsaObject
61 {
62  public:
64  {
69  };
70 
71  static const char *sectionNames[];
72 
73  struct SectionInfo
74  {
75  uint8_t *ptr;
76  int size;
77  };
78 
79  static HsaObject* tryFile(const std::string &fname, int len,
80  uint8_t *fileData);
81 
83  const uint8_t *getSectionOffset(enum SectionIndex sec, int offs) const;
84 
87  std::string kern_block_name;
88 
89  void processDirectives(const Brig::BrigBase *dirPtr,
90  const Brig::BrigBase *endPtr,
92 
93  BrigObject(const std::string &fname, int len, uint8_t *fileData);
94  ~BrigObject();
95 
96  // eventually these will need to be per-kernel not per-object-file
99 
100  const char* getString(int offs) const;
101  const Brig::BrigData* getBrigBaseData(int offs) const;
102  const uint8_t* getData(int offs) const;
103  const Brig::BrigBase* getCodeSectionEntry(int offs) const;
104  const Brig::BrigOperand* getOperand(int offs) const;
105  unsigned getOperandPtr(int offs, int index) const;
106  const Brig::BrigInstBase* getInst(int offs) const;
107 
108  HsaCode* getKernel(const std::string &name) const override;
109  HsaCode* getFunction(const std::string &name) const override;
110 
111  int numKernels() const override { return kernels.size(); }
112 
113  HsaCode* getKernel(int i) const override { return kernels[i]; }
114 
115  // pointer to the current kernel/function we're processing, so elements
116  // under construction can reference it. kinda ugly, but easier
117  // than passing it all over for the few places it's needed.
119 };
120 
121 // Utility function to bump Brig item pointer to next element given
122 // item size in bytes. Really just an add but with lots of casting.
123 template<typename T>
124 T*
125 brigNext(T *ptr)
126 {
127  Brig::BrigBase *base_ptr = (Brig::BrigBase*)ptr;
128  int size = base_ptr->byteCount;
129  assert(size);
130 
131  return (T*)((uint8_t*)ptr + size);
132 }
133 
134 #endif // __BRIG_OBJECT_HH__
HsailCode * currentCode
Definition: brig_object.hh:118
Bitfield< 30, 0 > index
std::string kern_block_name
Definition: brig_object.hh:87
const Brig::BrigOperand * getOperand(int offs) const
Definition: brig_object.cc:116
std::vector< HsailCode * > functions
Definition: brig_object.hh:86
int numKernels() const override
Definition: brig_object.hh:111
LabelMap * labelMap
Definition: brig_object.hh:98
Bitfield< 7 > i
Definition: miscregs.hh:1378
const Brig::BrigInstBase * getInst(int offs) const
Definition: brig_object.cc:130
uint16_t byteCount
Definition: Brig.h:1179
StorageMap * storageMap
Definition: brig_object.hh:97
BrigObject(const std::string &fname, int len, uint8_t *fileData)
Definition: brig_object.cc:415
std::vector< HsailCode * > kernels
Definition: brig_object.hh:85
HsaCode * getKernel(int i) const override
Definition: brig_object.hh:113
SectionInfo sectionInfo[NumSectionIndices]
Definition: brig_object.hh:82
const uint8_t * getData(int offs) const
Definition: brig_object.cc:110
const char * getString(int offs) const
Definition: brig_object.cc:92
T * brigNext(T *ptr)
Definition: brig_object.hh:125
static const char * sectionNames[]
Definition: brig_object.hh:71
HsaCode * getFunction(const std::string &name) const override
Definition: brig_object.cc:142
HsaCode * getKernel(const std::string &name) const override
Definition: brig_object.cc:136
static HsaObject * tryFile(const std::string &fname, int len, uint8_t *fileData)
Definition: brig_object.cc:405
const Brig::BrigBase * getCodeSectionEntry(int offs) const
Definition: brig_object.cc:98
void processDirectives(const Brig::BrigBase *dirPtr, const Brig::BrigBase *endPtr, StorageMap *storageMap)
Definition: brig_object.cc:154
unsigned getOperandPtr(int offs, int index) const
Definition: brig_object.cc:122
const std::string & name() const
Definition: hsa_object.hh:65
int size()
Definition: pagetable.hh:146
const Brig::BrigData * getBrigBaseData(int offs) const
Definition: brig_object.cc:104
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
const uint8_t * getSectionOffset(enum SectionIndex sec, int offs) const
Definition: brig_object.cc:83

Generated on Fri Jun 9 2017 13:03:47 for gem5 by doxygen 1.8.6