40 #include <sys/types.h>
50 #include "debug/BRIG.hh"
51 #include "debug/HSAILObject.hh"
52 #include "debug/HSALoader.hh"
86 assert(offs <= sectionInfo[sec].
size);
88 return sectionInfo[sec].ptr + offs;
94 return (
const char*)(getSectionOffset(DataSectionIndex, offs) + 4);
100 return (
const BrigBase*)getSectionOffset(CodeSectionIndex, offs);
106 return (
Brig::BrigData*)(getSectionOffset(DataSectionIndex, offs));
112 return getSectionOffset(DataSectionIndex, offs);
118 return (
const BrigOperand*)getSectionOffset(OperandsSectionIndex, offs);
124 unsigned *op_offs = (
unsigned*)(getData(offs + 4 * (index + 1)));
132 return (
const BrigInstBase*)getSectionOffset(CodeSectionIndex, offs);
144 for (
int i = 0;
i < functions.size(); ++
i) {
157 while (dirPtr < endPtr) {
159 fatal(
"Bad directive size 0\n");
165 DPRINTF(HSAILObject,
"Code section entry kind: #%x, byte count: %d\n",
168 switch (dirPtr->
kind) {
174 DPRINTF(HSAILObject,
"DIRECTIVE_FUNCTION: %s offset: "
175 "%d next: %d\n", getString(
p->name),
176 p->firstCodeBlockEntry,
p->nextModuleEntry);
178 if (
p->firstCodeBlockEntry !=
p->nextModuleEntry) {
182 warn(
"HSA function invocations are unsupported.\n");
184 const char *
name = getString(
p->name);
188 for (
int i = 0;
i < functions.size(); ++
i) {
190 code_obj = functions[
i];
199 functions.push_back(code_obj);
201 panic(
"Multiple definition of Function!!: %s\n",
206 nextDirPtr = getCodeSectionEntry(
p->nextModuleEntry);
215 DPRINTF(HSAILObject,
"DIRECTIVE_KERNEL: %s offset: %d count: "
216 "next: %d\n", getString(p->
name),
219 const char *
name = getString(p->
name);
224 std::string str =
name;
226 int len = str.length();
228 if (str[len - 1] >=
'a' && str[len - 1] <=
'z') {
229 temp =
new char[str.size() + 1];
230 std::copy(str.begin(), str.end() , temp);
231 temp[str.size()] =
'\0';
233 temp =
new char[str.size()];
234 std::copy(str.begin(), str.end() - 1 , temp);
235 temp[str.size() - 1 ] =
'\0';
238 std::string kernel_name = temp;
243 for (
const auto &
kernel : kernels) {
244 if (
kernel->name() == kernel_name) {
252 code_obj =
new HsailCode(kernel_name, p,
this,
255 kernels.push_back(code_obj);
267 uint64_t readonlySize_old =
272 DPRINTF(HSAILObject,
"DIRECTIVE_VARIABLE, symbol %s\n",
277 uint8_t* readonlyData_old = readonlyData;
288 panic(
"Read only data type not supported: %s\n",
293 assert(brigOp->
kind ==
300 assert((operand_data->byteCount / 4) > 0);
302 uint8_t *symbol_data =
307 if (readonlySize_old > 0) {
308 memcpy(readonlyData, readonlyData_old,
312 memcpy(readonlyData + se->
offset, symbol_data,
315 delete[] readonlyData_old;
326 panic(
"Label directives cannot be at the module level: %s\n",
337 DPRINTF(HSAILObject,
"DIRECTIVE_COMMENT: %s\n",
344 DPRINTF(HSAILObject,
"BRIG_DIRECTIVE_LOC\n");
353 DPRINTF(HSAILObject,
"BRIG_DIRECTIVE_MODULE: %s\n",
360 DPRINTF(HSAILObject,
"DIRECTIVE_CONTROL\n");
366 DPRINTF(HSAILObject,
"DIRECTIVE_PRAGMA\n");
372 DPRINTF(HSAILObject,
"DIRECTIVE_EXTENSION\n");
378 DPRINTF(HSAILObject,
"DIRECTIVE_ARG_BLOCK_START\n");
384 DPRINTF(HSAILObject,
"DIRECTIVE_ARG_BLOCK_END\n");
396 warn(
"Unknown Brig directive kind: %d\n", dirPtr->
kind);
407 const char *brig_ident =
"HSA BRIG";
418 const char *brig_ident =
"HSA BRIG";
422 "%s is not a BRIG file\n", fname);
426 fatal(
"%s: BRIG version mismatch, %d.%d != %d.%d\n",
432 "count (%d) != expected value (%d)\n", fname,
439 uint64_t *sec_idx_table = (uint64_t*)(fileData + mod_hdr->
sectionIndex);
440 for (
int sec_idx = 0; sec_idx < mod_hdr->
sectionCount; ++sec_idx) {
441 uint8_t *sec_hdr_byte_ptr = fileData + sec_idx_table[sec_idx];
457 DPRINTF(HSAILObject,
"Code section hdr, count: %d, hdr count: %d, "
468 DPRINTF(HSALoader,
"BRIG object %s loaded.\n", fname);
int getSize(Brig::BrigSegment segment)
const Brig::BrigOperand * getOperand(int offs) const
const std::string & name()
const Brig::BrigInstBase * getInst(int offs) const
int getBrigDataTypeBytes(BrigType16_t t)
StorageElement * addSymbol(const Brig::BrigDirectiveVariable *sym, const BrigObject *obj)
const char * segmentNames[]
BrigOperandOffset32_t init
BrigObject(const std::string &fname, int len, uint8_t *fileData)
SectionInfo sectionInfo[NumSectionIndices]
const uint8_t * getData(int offs) const
const char * getString(int offs) const
static const char * sectionNames[]
HsaCode * getFunction(const std::string &name) const override
HsaCode * getKernel(const std::string &name) const override
static HsaObject * tryFile(const std::string &fname, int len, uint8_t *fileData)
const Brig::BrigBase * getCodeSectionEntry(int offs) const
void processDirectives(const Brig::BrigBase *dirPtr, const Brig::BrigBase *endPtr, StorageMap *storageMap)
static const int NumArgumentRegs M5_VAR_USED
unsigned getOperandPtr(int offs, int index) const
const Brig::BrigData * getBrigBaseData(int offs) const
BrigCodeOffset32_t nextModuleEntry
static std::vector< std::function< HsaObject *(const std::string &, int, uint8_t *)> > tryFileFuncs
BrigDataOffsetString32_t name
fatal_if(p->js_features.size() > 16,"Too many job slot feature registers specified (%i)\n", p->js_features.size())
BrigDataOffsetString32_t name
BrigCodeOffset32_t firstCodeBlockEntry
const uint8_t * getSectionOffset(enum SectionIndex sec, int offs) const