2 * Copyright (c) 2012-2015 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 contributors
18 * may be used to endorse or promote products derived from this software
19 * 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 * Author: Steve Reinhardt, Anthony Gutierrez
36 #ifndef __BRIG_OBJECT_HH__
37 #define __BRIG_OBJECT_HH__
44 #include "arch/hsail/Brig.h"
45 #include "gpu-compute/hsa_object.hh"
46 #include "gpu-compute/hsail_code.hh"
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.
60 class BrigObject final : public HsaObject
71 static const char *sectionNames[];
79 static HsaObject* tryFile(const std::string &fname, int len,
82 SectionInfo sectionInfo[NumSectionIndices];
83 const uint8_t *getSectionOffset(enum SectionIndex sec, int offs) const;
85 std::vector<HsailCode*> kernels;
86 std::vector<HsailCode*> functions;
87 std::string kern_block_name;
89 void processDirectives(const Brig::BrigBase *dirPtr,
90 const Brig::BrigBase *endPtr,
91 StorageMap *storageMap);
93 BrigObject(const std::string &fname, int len, uint8_t *fileData);
96 // eventually these will need to be per-kernel not per-object-file
97 StorageMap *storageMap;
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;
108 HsaCode* getKernel(const std::string &name) const override;
109 HsaCode* getFunction(const std::string &name) const override;
111 int numKernels() const override { return kernels.size(); }
113 HsaCode* getKernel(int i) const override { return kernels[i]; }
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.
118 mutable HsailCode *currentCode;
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.
127 Brig::BrigBase *base_ptr = (Brig::BrigBase*)ptr;
128 int size = base_ptr->byteCount;
131 return (T*)((uint8_t*)ptr + size);
134 #endif // __BRIG_OBJECT_HH__